From 2871222b86d1bf1d9287678980193c63f04f7165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 21 Oct 2012 23:36:48 +0200 Subject: [PATCH] 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. --- src/IndexedMesh.cpp | 6 ------ src/IndexedMesh.h | 22 +++++----------------- src/Mesh.h | 15 +++++++-------- 3 files changed, 12 insertions(+), 31 deletions(-) diff --git a/src/IndexedMesh.cpp b/src/IndexedMesh.cpp index 061e892df..3bc9c8008 100644 --- a/src/IndexedMesh.cpp +++ b/src/IndexedMesh.cpp @@ -31,12 +31,6 @@ IndexedMesh::IndexedMesh(Mesh::Primitive primitive): Mesh(primitive), _indexCoun (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() { bind(); diff --git a/src/IndexedMesh.h b/src/IndexedMesh.h index 873a6d066..ccb0ae104 100644 --- a/src/IndexedMesh.h +++ b/src/IndexedMesh.h @@ -30,10 +30,9 @@ namespace Magnum { @section IndexedMesh-configuration Indexed mesh configuration 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 -setIndexCount() and setIndexType()). Then fill index buffer or use -MeshTools::compressIndices() to conveniently fill the index buffer and set -index count and type. +have to call also setIndexCount() and setIndexType(). Then fill index buffer +or use MeshTools::compressIndices() to conveniently fill the index buffer and +set index count and type. @section IndexedMesh-drawing Rendering meshes @@ -50,27 +49,16 @@ class MAGNUM_EXPORT IndexedMesh: public Mesh { friend class Context; 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 * @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(), * setIndexType(), @fn_gl{BindVertexArray} (if * @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 */ inline GLsizei indexCount() const { return _indexCount; } diff --git a/src/Mesh.h b/src/Mesh.h index b229cc835..1c8c0467d 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -34,12 +34,11 @@ class Context; @section Mesh-configuration Mesh configuration -To properly configure mesh, you have to set primitive and vertex count, either -in constructor or using setPrimitive() and setVertexCount(). Then create -vertex buffers, fill them with vertex data and assign them to mesh and given -shader locations using addVertexBuffer() or addInterleavedVertexBuffer(). You -can also use MeshTools::interleave() to conveniently set vertex count and -buffer data. +To properly configure mesh, you have to set primitive either in constructor or +using setPrimitive() and call setVertexCount(). Then create vertex buffers, +fill them with vertex data and assign them to mesh and given shader locations +using addVertexBuffer() or addInterleavedVertexBuffer(). You can also use +MeshTools::interleave() to conveniently set vertex count and buffer data. 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 @@ -337,12 +336,12 @@ class MAGNUM_EXPORT Mesh { /** * @brief Constructor * @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 * @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)(); }