Class for polygonal meshes. A mesh consisting of four components:
MeshVertexData : The vertices of the mesh stored in local and/or graphics memory
MeshIndexData : The indices of the used vertices stored in local and/or graphics memory
DataStrategy: A strategy that determines where the data is stored and how the mesh is rendered (e.g. as VBO or VertexArray)
Filename: (optional) The filename from which the mesh was loaded.
Create a new mesh:
Mesh*mesh=newMesh;// create a meshMeshIndexData&id=mesh->openMeshIndexData();// get access to index dataid.allocate(numberOfIndices);// allocate memory for indices (using triangles)for(uint32_ti=0;i<numberOfIndices;++i){id[i]=someIndex(...);// access the indices}id.updateIndexRange();// recalculate index rangeMeshVertexData&vd=mesh->openMeshVertexData();// get access to vertex dataVertexDescriptiondesc;// create a vertexDescriptionvd.allocate(numberOfVertices);// allocate memory for verticesuint8_t*binaryMeshVertexData=vd.data();// access the verticescreateMeshVertexData(...);vd.updateBoundingBox();// recalculate bounding box
Note: After an existing mesh has been changed, vd.markAsChanged() and id.markAsChanged() have to be called so that the VBO can be updated. After allocate(…) this is not necessary.
Display the mesh as VBO or VertexArray (determined by current data strategy).
If the mesh uses indices ( isUsingIndexData() ==true),firstElementandelementCountare the first index and the number of indices to be drawn.
If the mesh does not us indices ( isUsingIndexData() ==false),firstElementandelementCountare the first vertex and the number of vertices to be drawn. Calls:> dataStrategy->displayMesh(…)> dataStrategy::doDisplayMesh(…)> vertexData.bind() & indexData.drawElements(…) OR (if no indexData is present) vertexData.drawArray(…)
Note: AttentionThe function has to be called from within the GL-thread!
Note: Except if you know what you are doing, use renderingContext.displayMesh(mesh) instead.
Return the number of primitives stored in this mesh. The number depends on the number of indices, the number of vertices, and the draw mode. To retrieve the type of primitives, call getDrawMode() .
Parameters
numElements
If zero, the number of indices or the number of vertices will be used. If non-zero, use the number of elements to do the calculation.