Axiom.Components.Terrain.TerrainQuadTreeNode.CreateCpuVertexData C# (CSharp) Method

CreateCpuVertexData() protected method

protected CreateCpuVertexData ( ) : void
return void
        protected void CreateCpuVertexData()
        {
            if (mVertexDataRecord != null)
            {
                DestroyCpuVertexData();

                // create vertex structure, not using GPU for now (these are CPU structures)
                VertexDeclaration dcl = new VertexDeclaration();
                VertexBufferBinding bufbind = new VertexBufferBinding();

                mVertexDataRecord.CpuVertexData = new VertexData();
                mVertexDataRecord.CpuVertexData.vertexBufferBinding = bufbind;
                mVertexDataRecord.CpuVertexData.vertexDeclaration = dcl;
                // Vertex declaration
                // TODO: consider vertex compression
                int offset = 0;
                // POSITION 
                // float3(x, y, z)
                offset += dcl.AddElement((short)POSITION_BUFFER, offset, VertexElementType.Float3, VertexElementSemantic.Position).Size;
                // UV0
                // float2(u, v)
                // TODO - only include this if needing fixed-function
                offset += dcl.AddElement((short)POSITION_BUFFER, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0).Size;
                // UV1 delta information
                // float2(delta, deltaLODthreshold)
                offset = 0;
                offset += dcl.AddElement((short)DELTA_BUFFER, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 1).Size;

                // Calculate number of vertices
                // Base geometry size * size
               
                int baseNumVerts = (int)(mVertexDataRecord.Size * mVertexDataRecord.Size);
                int numVerts = baseNumVerts;
                // Now add space for skirts
                // Skirts will be rendered as copies of the edge vertices translated downwards
                // Some people use one big fan with only 3 vertices at the bottom, 
                // but this requires creating them much bigger that necessary, meaning
                // more unnecessary overdraw, so we'll use more vertices 
                // You need 2^levels + 1 rows of full resolution (max 129) vertex copies, plus
                // the same number of columns. There are common vertices at intersections
                ushort levels = mVertexDataRecord.TreeLevels;
                mVertexDataRecord.NumSkirtRowsCols = (ushort)(System.Math.Pow(2, levels) + 1);
                mVertexDataRecord.SkirtRowColSkip = (ushort)((mVertexDataRecord.Size - 1) / (mVertexDataRecord.NumSkirtRowsCols - 1));
                numVerts += mVertexDataRecord.Size * mVertexDataRecord.NumSkirtRowsCols;
                numVerts += mVertexDataRecord.Size * mVertexDataRecord.NumSkirtRowsCols;

                HardwareVertexBuffer def = HardwareBufferManager.Instance.CreateVertexBuffer(dcl.Clone(POSITION_BUFFER), numVerts, BufferUsage.StaticWriteOnly, false);//new DefaultHardwareVertexBuffer(dcl.GetVertexSize((short)POSITION_BUFFER), numVerts, BufferUsage.StaticWriteOnly);
                //manually create CPU-side buffer
                HardwareVertexBuffer posBuf = def;
                def = HardwareBufferManager.Instance.CreateVertexBuffer(dcl.Clone(DELTA_BUFFER), numVerts, BufferUsage.StaticWriteOnly, false);//new DefaultHardwareVertexBuffer(dcl.GetVertexSize((short)DELTA_BUFFER),
                    //numVerts, BufferUsage.StaticWriteOnly);

                HardwareVertexBuffer deltabuf = def;
                mVertexDataRecord.CpuVertexData.vertexStart = 0;
                mVertexDataRecord.CpuVertexData.vertexCount = numVerts;

                Rectangle updateRect = new Rectangle(mOffsetX, mOffsetY, mBoundaryX, mBoundaryY);
                UpdateVertexBuffer(posBuf, deltabuf, updateRect);
                mVertexDataRecord.IsGpuVertexDataDirty = true;
                bufbind.SetBinding((short)POSITION_BUFFER, posBuf);
                bufbind.SetBinding((short)DELTA_BUFFER, deltabuf);
            }
        }
        /// <summary>