当前位置: 首页>>代码示例>>C#>>正文


C# GraphicFactory.CreateTexture2D方法代码示例

本文整理汇总了C#中GraphicFactory.CreateTexture2D方法的典型用法代码示例。如果您正苦于以下问题:C# GraphicFactory.CreateTexture2D方法的具体用法?C# GraphicFactory.CreateTexture2D怎么用?C# GraphicFactory.CreateTexture2D使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GraphicFactory的用法示例。


在下文中一共展示了GraphicFactory.CreateTexture2D方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: QuadTerrain

        /// <summary>
        /// Initialises a complete QuadTerrain.
        ///This is the Constructor method. As you might have guessed, it constructs a quad terrain.
        /// Quasar.
        /// </summary>
        /// <param name="factory">The factory.</param>
        /// <param name="heightMap">The Texture2D to use as a heightmap. Must have square dimensions of (2^n)+1, where n is an integer.</param>
        /// <param name="squareSize">The edge size of each individual LOD square. Lower values increase CPU Load, decrease GPU Load, and increase Loading times. Must be (2^n)+1, and larger than 5.</param>
        /// <param name="vertexBufferSize">The size of Vertex buffer to use. Lower Values increase the number of draw calls by splitting the terrain into several Vertex Buffers. Must be (2^n)+1, and larger than squareSize.</param>
        /// <param name="scale">The XZ scale to multiply the terrain by.</param>
        /// <param name="height">The Y scale to multiply the terrain by.</param>
        public QuadTerrain(GraphicFactory factory ,Texture2D heightMap, int squareSize, int vertexBufferSize, float scale, float height)
        {
            this.factory = factory;
            //I'm not entirely sure what this does, but it is used in updateTerrain.
            //I think it is used to prevent the Vertex Buffers being filled during the initialisation UpdateTerrain call.
            first = true;

            LODHeightImpact = 1.0f;                        
             
            

            //Set terrain width and height from heightmap.
            terrainHeight = heightMap.Height;
            terrainWidth = heightMap.Width;

            //Set some obvious public variables
            HeightMap = heightMap;
            SquareSize = squareSize;
            Scale = scale;
            HeightScale = height;
            VBsize = vertexBufferSize;

            //Copy the heightmap from a Texture to an array of colours...
            Color[] heightMapColors = new Color[terrainWidth * terrainHeight];
            heightMap.GetData(heightMapColors);

            //Initialise the HeightStore and 
            heightStore = new float[heightMap.Width, heightMap.Height];
            normStore = new Vector3[heightMap.Width, heightMap.Height];

            //this is the Normal texture for the entire terrain. It is used within the shader to prevent normal popup.
            normalTexture = factory.CreateTexture2D(heightMap.Width, heightMap.Height, true, SurfaceFormat.Color);
            Color[] normalData = new Color[heightMap.Width * heightMap.Height];

            #region depricated
            /*
            int NodeDepth= 0;
            int NodeLevel = (int)Math.Pow(2, (NodeDepth));
            int NodeScale = ((heightMap.Height - 1) / NodeLevel) + 1;
            int stepSize = (NodeScale - 1) / (squareSize - 1);
            */

            ////////////////////////////////////////////////////
            // For:
            // SquareSize = 9
            // Height = 257
            // NodeDepth,   NodeLevel,  NodeScale,  stepSize
            // 0,           1,          257,        64
            // 1,           2,          129,        32
            // 2,           4,          65,         16
            // 3,           8,          33,         8
            // 4,           16,         19,         4
            // 5,           32,         9,          2
            // 6,           64,         5,          1
            ////////////////////////////////////////////////////

            //Get node depth:
            //int NodeScale = stepSize*(squareSize-1)+1;
            //int NodeLevel = (NodeScale - 1) * (heightMap.Height - 1);
            //int maxNodeDepth = (int)Math.Log(NodeLevel, 2);
            //int maxNodeDepth;
            #endregion

            //Determine Maximum Node Depth from Square Size and height of heightmap
            int NodeScale = 1 * (squareSize - 1) + 1;
            int NodeLevel = (heightMap.Height - 1) / (NodeScale - 1);
            maxNodeDepth = (int)Math.Log(NodeLevel, 2);

            //Work out number of vertex arrays needed:
            //Math.Pow(HeightMap.HEIGHT / 512, 2))+1;
            numberOfVBs = (int)Math.Pow((terrainHeight - 1) / (VBsize - 1), 2);
            sqrtNumberOfVBs = (int)Math.Sqrt(numberOfVBs);

            //Initialise the Array of Vertex Arrays, accompanying Array of Vertex Buffers and the Array of Integer Index Arrays.
            allVertices = new VertexPosition[numberOfVBs + 1][];
            allVBs = new VertexBuffer[numberOfVBs + 1];
            allIndices = new int[numberOfVBs + 1][];

            //And as if that wasn't confusing enough...
            //Now I initialise each Array in the Array of Vertex Arrays, each corresponding Buffer in the Array of Vertex Buffers,
            //and each Integer Index Array in the Array of Integer Index Arrays.
            for (int i = 0; i < numberOfVBs + 1; i++)
            {
                allVertices[i] = new VertexPosition[(VBsize + 1) * (VBsize + 1)];
                allVBs[i] = factory.CreateVertexBuffer(VertexPosition.VertexDeclaration, (VBsize + 1) * (VBsize + 1), BufferUsage.WriteOnly);
                allIndices[i] = new int[VBsize * VBsize * 6];
            }
            //Array.

//.........这里部分代码省略.........
开发者ID:brunoduartec,项目名称:port-ploobsengine,代码行数:101,代码来源:QuadTerrain.cs


注:本文中的GraphicFactory.CreateTexture2D方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。