Browse Source

Mesh rework, part 3: don't specify vertex/index count in constructor.

In most cases the constructor is called at a very different place than
where the mesh is configured, leading to mistakes and/or confusion.
pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
2871222b86
  1. 6
      src/IndexedMesh.cpp
  2. 22
      src/IndexedMesh.h
  3. 15
      src/Mesh.h

6
src/IndexedMesh.cpp

@ -31,12 +31,6 @@ IndexedMesh::IndexedMesh(Mesh::Primitive primitive): Mesh(primitive), _indexCoun
(this->*createIndexedImplementation)(); (this->*createIndexedImplementation)();
} }
IndexedMesh::IndexedMesh(Mesh::Primitive primitive, GLsizei vertexCount, GLsizei indexCount, Type indexType): Mesh(primitive, vertexCount), _indexCount(indexCount), _indexType(indexType) {
_indexBuffer.setTargetHint(Buffer::Target::ElementArray);
(this->*createIndexedImplementation)();
}
void IndexedMesh::draw() { void IndexedMesh::draw() {
bind(); bind();

22
src/IndexedMesh.h

@ -30,10 +30,9 @@ namespace Magnum {
@section IndexedMesh-configuration Indexed mesh configuration @section IndexedMesh-configuration Indexed mesh configuration
Next to @ref Mesh-configuration "everything needed for non-indexed mesh" you Next to @ref Mesh-configuration "everything needed for non-indexed mesh" you
have to specify also index count and type (either in constructor or using have to call also setIndexCount() and setIndexType(). Then fill index buffer
setIndexCount() and setIndexType()). Then fill index buffer or use or use MeshTools::compressIndices() to conveniently fill the index buffer and
MeshTools::compressIndices() to conveniently fill the index buffer and set set index count and type.
index count and type.
@section IndexedMesh-drawing Rendering meshes @section IndexedMesh-drawing Rendering meshes
@ -50,27 +49,16 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh {
friend class Context; friend class Context;
public: public:
/**
* @brief Implicit constructor
* @param primitive Primitive type
*
* @see @fn_gl{BindVertexArray} (if @extension{APPLE,vertex_array_object}
* is available)
*/
IndexedMesh(Primitive primitive = Primitive::Triangles);
/** /**
* @brief Constructor * @brief Constructor
* @param primitive Primitive type * @param primitive Primitive type
* @param vertexCount Count of unique vertices
* @param indexCount Count of indices
* @param indexType Type of indices (indexable, see TypeTraits)
* *
* Creates indexed mesh with zero vertex count and zero index count.
* @see setPrimitive(), setVertexCount(), setIndexCount(), * @see setPrimitive(), setVertexCount(), setIndexCount(),
* setIndexType(), @fn_gl{BindVertexArray} (if * setIndexType(), @fn_gl{BindVertexArray} (if
* @extension{APPLE,vertex_array_object} is available) * @extension{APPLE,vertex_array_object} is available)
*/ */
IndexedMesh(Primitive primitive, GLsizei vertexCount, GLsizei indexCount, Type indexType = Type::UnsignedShort); IndexedMesh(Primitive primitive = Primitive::Triangles);
/** @brief Index count */ /** @brief Index count */
inline GLsizei indexCount() const { return _indexCount; } inline GLsizei indexCount() const { return _indexCount; }

15
src/Mesh.h

@ -34,12 +34,11 @@ class Context;
@section Mesh-configuration Mesh configuration @section Mesh-configuration Mesh configuration
To properly configure mesh, you have to set primitive and vertex count, either To properly configure mesh, you have to set primitive either in constructor or
in constructor or using setPrimitive() and setVertexCount(). Then create using setPrimitive() and call setVertexCount(). Then create vertex buffers,
vertex buffers, fill them with vertex data and assign them to mesh and given fill them with vertex data and assign them to mesh and given shader locations
shader locations using addVertexBuffer() or addInterleavedVertexBuffer(). You using addVertexBuffer() or addInterleavedVertexBuffer(). You can also use
can also use MeshTools::interleave() to conveniently set vertex count and MeshTools::interleave() to conveniently set vertex count and buffer data.
buffer data.
Note that the buffer is not managed (e.g. deleted on destruction) by the mesh, Note that the buffer is not managed (e.g. deleted on destruction) by the mesh,
so you have to manage it on your own. On the other hand it allows you to use so you have to manage it on your own. On the other hand it allows you to use
@ -337,12 +336,12 @@ class MAGNUM_EXPORT Mesh {
/** /**
* @brief Constructor * @brief Constructor
* @param primitive Primitive type * @param primitive Primitive type
* @param vertexCount Vertex count
* *
* Creates mesh with no vertex buffers and zero vertex count.
* @see setPrimitive(), setVertexCount(), @fn_gl{GenVertexArrays} (if * @see setPrimitive(), setVertexCount(), @fn_gl{GenVertexArrays} (if
* @extension{APPLE,vertex_array_object} is available) * @extension{APPLE,vertex_array_object} is available)
*/ */
inline Mesh(Primitive primitive = Primitive::Triangles, GLsizei vertexCount = 0): _primitive(primitive), _vertexCount(vertexCount) { inline Mesh(Primitive primitive = Primitive::Triangles): _primitive(primitive), _vertexCount(0) {
(this->*createImplementation)(); (this->*createImplementation)();
} }

Loading…
Cancel
Save