// ------------------------------------ // ------------------------------------ /// <summary> /// Creates a new PatchMesh. /// </summary> /// <remarks> /// As defined in <see cref="MeshManager.CreateBezierPatch" />. /// </remarks> public PatchMesh(string name, System.Array controlPointBuffer, VertexDeclaration declaration, int width, int height, int uMaxSubdivisionLevel, int vMaxSubdivisionLevel, VisibleSide visibleSide, BufferUsage vbUsage, BufferUsage ibUsage, bool vbUseShadow, bool ibUseShadow) : base(name) { vertexBufferUsage = vbUsage; useVertexShadowBuffer = vbUseShadow; indexBufferUsage = ibUsage; useIndexShadowBuffer = ibUseShadow; // Init patch builder // define the surface // NB clone the declaration to make it independent vertexDeclaration = (VertexDeclaration)declaration.Clone(); patchSurface.DefineSurface(controlPointBuffer, vertexDeclaration, width, height, PatchSurfaceType.Bezier, uMaxSubdivisionLevel, vMaxSubdivisionLevel, visibleSide); }
protected void CreateCpuVertexData() { if ( this.mVertexDataRecord != null ) { DestroyCpuVertexData(); // create vertex structure, not using GPU for now (these are CPU structures) var dcl = new VertexDeclaration(); var bufbind = new VertexBufferBinding(); this.mVertexDataRecord.CpuVertexData = new VertexData( dcl, bufbind ); // Vertex declaration // TODO: consider vertex compression int offset = 0; // POSITION // float3(x, y, z) offset += dcl.AddElement( POSITION_BUFFER, offset, VertexElementType.Float3, VertexElementSemantic.Position ).Size; // UV0 // float2(u, v) // TODO - only include this if needing fixed-function offset += dcl.AddElement( POSITION_BUFFER, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 0 ).Size; // UV1 delta information // float2(delta, deltaLODthreshold) offset = 0; offset += dcl.AddElement( DELTA_BUFFER, offset, VertexElementType.Float2, VertexElementSemantic.TexCoords, 1 ).Size; // Calculate number of vertices // Base geometry size * size var baseNumVerts = (int)Utility.Sqr( this.mVertexDataRecord.Size ); var 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 var levels = this.mVertexDataRecord.TreeLevels; this.mVertexDataRecord.NumSkirtRowsCols = (ushort)( System.Math.Pow( 2, levels ) + 1 ); this.mVertexDataRecord.SkirtRowColSkip = (ushort)( ( this.mVertexDataRecord.Size - 1 )/( this.mVertexDataRecord.NumSkirtRowsCols - 1 ) ); numVerts += this.mVertexDataRecord.Size*this.mVertexDataRecord.NumSkirtRowsCols; numVerts += this.mVertexDataRecord.Size*this.mVertexDataRecord.NumSkirtRowsCols; //manually create CPU-side buffer var posBuf = HardwareBufferManager.Instance.CreateVertexBuffer( dcl.Clone( POSITION_BUFFER ), numVerts, BufferUsage.StaticWriteOnly, false ); var deltabuf = HardwareBufferManager.Instance.CreateVertexBuffer( dcl.Clone( DELTA_BUFFER ), numVerts, BufferUsage.StaticWriteOnly, false ); this.mVertexDataRecord.CpuVertexData.vertexStart = 0; this.mVertexDataRecord.CpuVertexData.vertexCount = numVerts; var updateRect = new Rectangle( this.mOffsetX, this.mOffsetY, this.mBoundaryX, this.mBoundaryY ); UpdateVertexBuffer( posBuf, deltabuf, updateRect ); this.mVertexDataRecord.IsGpuVertexDataDirty = true; bufbind.SetBinding( POSITION_BUFFER, posBuf ); bufbind.SetBinding( DELTA_BUFFER, deltabuf ); } }
public void Define( Array controlPointArray, VertexDeclaration declaration, int width, int height, int uMaxSubdivisionLevel, int vMaxSubdivisionLevel, VisibleSide visibleSide, BufferUsage vbUsage, BufferUsage ibUsage, bool vbUseShadow, bool ibUseShadow ) { VertexBufferUsage = vbUsage; UseVertexShadowBuffer = vbUseShadow; IndexBufferUsage = ibUsage; UseIndexShadowBuffer = ibUseShadow; // Init patch builder // define the surface // NB clone the declaration to make it independent this.vertexDeclaration = (VertexDeclaration)declaration.Clone(); this.patchSurface.DefineSurface( controlPointArray, this.vertexDeclaration, width, height, PatchSurfaceType.Bezier, uMaxSubdivisionLevel, vMaxSubdivisionLevel, visibleSide ); }