diff --git a/src/Magnum/DebugTools/ForceRenderer.cpp b/src/Magnum/DebugTools/ForceRenderer.cpp index e763955a7..dd785c12f 100644 --- a/src/Magnum/DebugTools/ForceRenderer.cpp +++ b/src/Magnum/DebugTools/ForceRenderer.cpp @@ -88,7 +88,7 @@ template ForceRenderer::ForceRenderer(SceneG Mesh* mesh = new Mesh; mesh->setPrimitive(MeshPrimitive::Lines) - .setIndexCount(indices.size()) + .setCount(indices.size()) .addVertexBuffer(*vertexBuffer, 0, typename Shaders::Flat::Position(Shaders::Flat::Position::Components::Two)) .setIndexBuffer(*indexBuffer, 0, Mesh::IndexType::UnsignedByte, 0, positions.size()); diff --git a/src/Magnum/DebugTools/Implementation/AbstractShapeRenderer.cpp b/src/Magnum/DebugTools/Implementation/AbstractShapeRenderer.cpp index 1927770e8..fee897954 100644 --- a/src/Magnum/DebugTools/Implementation/AbstractShapeRenderer.cpp +++ b/src/Magnum/DebugTools/Implementation/AbstractShapeRenderer.cpp @@ -53,7 +53,6 @@ template<> void create<2>(Trade::MeshData2D& data, Resource& meshResource, /* Mesh configuration */ Mesh* mesh = new Mesh; mesh->setPrimitive(data.primitive()) - .setVertexCount(data.positions(0).size()) .addVertexBuffer(*buffer, 0, Shaders::Flat2D::Position()); ResourceManager::instance().set(meshResource.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); @@ -63,7 +62,9 @@ template<> void create<2>(Trade::MeshData2D& data, Resource& meshResource, Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); MeshTools::compressIndices(*mesh, *indexBuffer, BufferUsage::StaticDraw, data.indices()); ResourceManager::instance().set(indexBufferResource.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); - } + + /* The mesh is not indexed, set proper vertex count */ + } else mesh->setCount(data.positions(0).size()); } template<> void create<3>(Trade::MeshData3D& data, Resource& meshResource, Resource& vertexBufferResource, Resource& indexBufferResource) { @@ -75,7 +76,6 @@ template<> void create<3>(Trade::MeshData3D& data, Resource& meshResource, /* Mesh configuration */ Mesh* mesh = new Mesh; mesh->setPrimitive(data.primitive()) - .setVertexCount(data.positions(0).size()) .addVertexBuffer(*vertexBuffer, 0, Shaders::Flat3D::Position()); ResourceManager::instance().set(meshResource.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); @@ -85,7 +85,9 @@ template<> void create<3>(Trade::MeshData3D& data, Resource& meshResource, Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); MeshTools::compressIndices(*mesh, *indexBuffer, BufferUsage::StaticDraw, data.indices()); ResourceManager::instance().set(indexBufferResource.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); - } + + /* The mesh is not indexed, set proper vertex count */ + } else mesh->setCount(data.positions(0).size()); } } diff --git a/src/Magnum/DebugTools/ObjectRenderer.cpp b/src/Magnum/DebugTools/ObjectRenderer.cpp index 669f8806a..b3f1d2b2f 100644 --- a/src/Magnum/DebugTools/ObjectRenderer.cpp +++ b/src/Magnum/DebugTools/ObjectRenderer.cpp @@ -166,7 +166,7 @@ template ObjectRenderer::ObjectRenderer(Scen ResourceManager::instance().set(this->indexBuffer.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); mesh->setPrimitive(MeshPrimitive::Lines) - .setIndexCount(Renderer::indices.size()) + .setCount(Renderer::indices.size()) .addVertexBuffer(*vertexBuffer, 0, typename Shaders::VertexColor::Position(), typename Shaders::VertexColor::Color()) diff --git a/src/Magnum/Mesh.cpp b/src/Magnum/Mesh.cpp index 0ed703735..cc5bbc0ec 100644 --- a/src/Magnum/Mesh.cpp +++ b/src/Magnum/Mesh.cpp @@ -72,7 +72,7 @@ std::size_t Mesh::indexSize(IndexType type) { CORRADE_ASSERT_UNREACHABLE(); } -Mesh::Mesh(MeshPrimitive primitive): _primitive(primitive), _vertexCount(0), _indexCount(0) +Mesh::Mesh(MeshPrimitive primitive): _primitive(primitive), _count(0) #ifndef MAGNUM_TARGET_GLES2 , _indexStart(0), _indexEnd(0) #endif @@ -92,7 +92,7 @@ Mesh::~Mesh() { (this->*Context::current()->state().mesh->destroyImplementation)(); } -Mesh::Mesh(Mesh&& other) noexcept: _id(other._id), _primitive(other._primitive), _vertexCount(other._vertexCount), _indexCount(other._indexCount) +Mesh::Mesh(Mesh&& other) noexcept: _id(other._id), _primitive(other._primitive), _count(other._count) #ifndef MAGNUM_TARGET_GLES2 , _indexStart(other._indexStart), _indexEnd(other._indexEnd) #endif @@ -110,8 +110,7 @@ Mesh::Mesh(Mesh&& other) noexcept: _id(other._id), _primitive(other._primitive), Mesh& Mesh::operator=(Mesh&& other) noexcept { std::swap(_id, other._id); std::swap(_primitive, other._primitive); - std::swap(_vertexCount, other._vertexCount); - std::swap(_indexCount, other._indexCount); + std::swap(_count, other._count); #ifndef MAGNUM_TARGET_GLES2 std::swap(_indexStart, other._indexStart); std::swap(_indexEnd, other._indexEnd); @@ -153,6 +152,7 @@ Mesh& Mesh::setIndexBuffer(Buffer& buffer, GLintptr offset, IndexType type, Unsi "Mesh::setIndexBuffer(): the buffer has unexpected target hint, expected" << Buffer::Target::ElementArray << "but got" << buffer.targetHint(), *this); #endif + _indexBuffer = &buffer; _indexOffset = offset; _indexType = type; #ifndef MAGNUM_TARGET_GLES2 @@ -167,29 +167,29 @@ Mesh& Mesh::setIndexBuffer(Buffer& buffer, GLintptr offset, IndexType type, Unsi } #ifndef MAGNUM_TARGET_GLES2 -void Mesh::drawInternal(Int firstVertex, Int vertexCount, GLintptr indexOffset, Int indexCount, Int indexStart, Int indexEnd) +void Mesh::drawInternal(Int count, Int firstVertex, GLintptr indexOffset, Int indexStart, Int indexEnd) #else -void Mesh::drawInternal(Int firstVertex, Int vertexCount, GLintptr indexOffset, Int indexCount) +void Mesh::drawInternal(Int count, Int firstVertex, GLintptr indexOffset) #endif { /* Nothing to draw */ - if(!vertexCount && !indexCount) return; + if(!count) return; (this->*Context::current()->state().mesh->bindImplementation)(); /* Non-indexed mesh */ - if(!indexCount) - glDrawArrays(GLenum(_primitive), firstVertex, vertexCount); + if(!_indexBuffer) + glDrawArrays(GLenum(_primitive), firstVertex, count); #ifndef MAGNUM_TARGET_GLES2 /* Indexed mesh with specified range */ else if(indexEnd) - glDrawRangeElements(GLenum(_primitive), indexStart, indexEnd, indexCount, GLenum(_indexType), reinterpret_cast(indexOffset)); + glDrawRangeElements(GLenum(_primitive), indexStart, indexEnd, count, GLenum(_indexType), reinterpret_cast(indexOffset)); #endif /* Indexed mesh without specified range */ else - glDrawElements(GLenum(_primitive), indexCount, GLenum(_indexType), reinterpret_cast(indexOffset)); + glDrawElements(GLenum(_primitive), count, GLenum(_indexType), reinterpret_cast(indexOffset)); (this->*Context::current()->state().mesh->unbindImplementation)(); } @@ -329,9 +329,7 @@ void Mesh::attributePointerImplementationDSA(const LongAttribute& attribute) { #endif #endif -void Mesh::bindIndexBufferImplementationDefault(Buffer& buffer) { - _indexBuffer = &buffer; -} +void Mesh::bindIndexBufferImplementationDefault(Buffer&) {} void Mesh::bindIndexBufferImplementationVAO(Buffer& buffer) { bindVAO(_id); @@ -359,7 +357,7 @@ void Mesh::bindImplementationDefault() { #endif /* Bind index buffer, if the mesh is indexed */ - if(_indexCount) _indexBuffer->bind(Buffer::Target::ElementArray); + if(_indexBuffer) _indexBuffer->bind(Buffer::Target::ElementArray); } void Mesh::bindImplementationVAO() { diff --git a/src/Magnum/Mesh.h b/src/Magnum/Mesh.h index 1514e3d9e..c731de8a4 100644 --- a/src/Magnum/Mesh.h +++ b/src/Magnum/Mesh.h @@ -122,29 +122,30 @@ namespace Implementation { struct MeshState; } @section Mesh-configuration Mesh configuration -You have to specify at least primitive and vertex count using @ref setPrimitive() -and @ref setVertexCount(). Then fill your vertex buffers with data, add them to -the mesh and specify @ref AbstractShaderProgram::Attribute "shader attribute" -layout inside the buffers using @ref addVertexBuffer(). You can also -use @ref MeshTools::interleave() conveniently fill interleaved vertex buffer. -The function itself calls @ref setVertexCount(), so you don't have to do it -again, but you still have to specify the layout using @ref addVertexBuffer(). - -If you have indexed mesh, you need to call @ref setIndexCount() instead of -@ref setVertexCount(). Then fill your index buffer with data and specify its +You have to specify at least primitive and vertex/index count using +@ref setPrimitive() and @ref setCount(). Then fill your vertex buffers with +data, add them to the mesh and specify +@ref AbstractShaderProgram::Attribute "shader attribute" layout inside the +buffers using @ref addVertexBuffer(). You can also use +@ref MeshTools::interleave() conveniently fill interleaved vertex buffer. +The function itself calls @ref setCount(), so you don't have to, but you still +have to specify the primitive using @ref setPrimitive() and the layout using +@ref addVertexBuffer(). + +If you want indexed mesh, fill your index buffer with data and specify its layout using @ref setIndexBuffer(). You can also use @ref MeshTools::compressIndices() to conveniently compress the indices, fill the index buffer and configure the -mesh instead of calling @ref setIndexCount() and @ref setIndexBuffer() manually. +mesh. It will call @ref setCount() and @ref setIndexBuffer(), so you don't have +to do anything else. Note that neither vertex buffers nor index buffer is managed (e.g. deleted on destruction) by the mesh, so you have to manage them on your own and ensure that they are available for whole mesh lifetime. On the other hand it allows you to use one buffer for more meshes (each mesh for example configured for -different shader) or store data for more meshes in one buffer. +different usage) or store data for more meshes in one buffer. -If the mesh has non-zero index count, it is treated as indexed mesh, otherwise -it is treated as non-indexed mesh. If both index and vertex count is zero, the -mesh is empty and no draw commands are issued when calling @ref draw(). +If vertex/index count is zero, the mesh is empty and no draw commands are +issued when calling @ref draw(). @subsection Mesh-configuration-examples Example mesh configuration @@ -169,7 +170,7 @@ vertexBuffer.setData(positions, BufferUsage::StaticDraw); // Set primitive and vertex count, add the buffer and specify its layout mesh.setPrimitive(MeshPrimitive::Triangles) - .setVertexCount(30) + .setCount(30) .addVertexBuffer(vertexBuffer, 0, MyShader::Position()); @endcode @@ -218,7 +219,7 @@ indexBuffer.setData(indices, BufferUsage::StaticDraw); // Set primitive, index count, specify the buffers mesh.setPrimitive(MeshPrimitive::Triangles) - .setIndexCount(75) + .setCount(75) .addVertexBuffer(vertexBuffer, 0, MyShader::Position()) .setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte, 176, 229); @endcode @@ -395,7 +396,7 @@ class MAGNUM_EXPORT Mesh: public AbstractObject { * @param primitive Primitive type * * Creates mesh with no vertex buffers and zero vertex count. - * @see @ref setPrimitive(), @ref setVertexCount(), @fn_gl{GenVertexArrays} + * @see @ref setPrimitive(), @ref setCount(), @fn_gl{GenVertexArrays} * (if @extension{APPLE,vertex_array_object} is available) */ explicit Mesh(MeshPrimitive primitive = MeshPrimitive::Triangles); @@ -454,6 +455,13 @@ class MAGNUM_EXPORT Mesh: public AbstractObject { */ Mesh& setLabel(const std::string& label); + /** + * @brief Whether the mesh is indexed + * + * @see @ref setIndexBuffer(), @ref setCount() + */ + bool isIndexed() const { return _indexBuffer; } + /** * @brief Index size * @@ -469,44 +477,63 @@ class MAGNUM_EXPORT Mesh: public AbstractObject { * @return Reference to self (for method chaining) * * Default is @ref MeshPrimitive::Triangles. - * @see @ref setVertexCount(), @ref addVertexBuffer() + * @see @ref setCount() */ Mesh& setPrimitive(MeshPrimitive primitive) { _primitive = primitive; return *this; } - /** @brief Vertex count */ - Int vertexCount() const { return _vertexCount; } + /** @brief Vertex/index count */ + Int count() const { return _count; } /** - * @brief Set vertex count - * @return Reference to self (for method chaining) + * @brief Set vertex/index count * - * Default is zero. - * @see @ref setPrimitive(), @ref addVertexBuffer(), - * @ref MeshTools::interleave() + * If the mesh is indexed, the value is treated as index count, + * otherwise the value is vertex count. Default is `0`. This value is + * set automatically by @ref MeshTools::interleave() and + * @ref MeshTools::compressIndices() functions. + * @see @ref isIndexed() */ - Mesh& setVertexCount(Int vertexCount) { - _vertexCount = vertexCount; + Mesh& setCount(Int count) { + _count = count; return *this; } - /** @brief Index count */ - Int indexCount() const { return _indexCount; } + #ifdef MAGNUM_BUILD_DEPRECATED + /** + * @copybrief count() + * @deprecated Use @ref Magnum::Mesh::count() "count()" instead. + */ + CORRADE_DEPRECATED("use count() instead") Int vertexCount() const { + return isIndexed() ? 0 : count(); + } /** - * @brief Set index count - * @return Reference to self (for method chaining) - * - * Default is zero. - * @see @ref setIndexBuffer(), @ref MeshTools::compressIndices() + * @copybrief setCount() + * @deprecated Use @ref Magnum::Mesh::setCount() "setCount()" instead. */ - Mesh& setIndexCount(Int count) { - _indexCount = count; + CORRADE_DEPRECATED("use setCount() instead") Mesh& setVertexCount(Int count) { + if(!isIndexed()) setCount(count); return *this; } + /** + * @copybrief count() + * @deprecated Use @ref Magnum::Mesh::count() "count()" instead. + */ + CORRADE_DEPRECATED("use count() instead") Int indexCount() const { + return count(); + } + + /** + * @copybrief setCount() + * @deprecated Use @ref Magnum::Mesh::setCount() "setCount()" instead. + */ + CORRADE_DEPRECATED("use setCount() instead") Mesh& setIndexCount(Int count) { return setCount(count); } + #endif + /** * @brief Add buffer with (interleaved) vertex attributes for use with given shader * @return Reference to self (for method chaining) @@ -565,7 +592,7 @@ class MAGNUM_EXPORT Mesh: public AbstractObject { * but doing so may have performance benefits. * * @see @ref maxVertexAttributes(), @ref setPrimitive(), - * @ref setVertexCount(), @fn_gl{BindVertexArray}, + * @ref setCount(), @fn_gl{BindVertexArray}, * @fn_gl{EnableVertexAttribArray}, @fn_gl{BindBuffer}, * @fn_gl{VertexAttribPointer} or * @fn_gl_extension{EnableVertexArrayAttrib,EXT,direct_state_access}, @@ -594,9 +621,10 @@ class MAGNUM_EXPORT Mesh: public AbstractObject { * @ref setIndexBuffer(Buffer&, GLintptr, IndexType), as this * functionality is not available there. * @see @ref maxElementsIndices(), @ref maxElementsVertices(), - * @ref setIndexCount(), @ref MeshTools::compressIndices(), - * @fn_gl{BindVertexArray}, @fn_gl{BindBuffer} (if - * @extension{APPLE,vertex_array_object} is available) + * @ref setCount(), @ref isIndexed(), + * @ref MeshTools::compressIndices(), @fn_gl{BindVertexArray}, + * @fn_gl{BindBuffer} (if @extension{APPLE,vertex_array_object} is + * available) */ Mesh& setIndexBuffer(Buffer& buffer, GLintptr offset, IndexType type, UnsignedInt start, UnsignedInt end); @@ -607,11 +635,9 @@ class MAGNUM_EXPORT Mesh: public AbstractObject { * @param type Index data type * @return Reference to self (for method chaining) * - * Prefer to use @ref setIndexBuffer(Buffer&, GLintptr, IndexType, UnsignedInt, UnsignedInt) - * for better performance. - * @see @ref setIndexCount(), @ref MeshTools::compressIndices(), - * @fn_gl{BindVertexArray}, @fn_gl{BindBuffer} (if - * @extension{APPLE,vertex_array_object} is available) + * Alternative to @ref setIndexBuffer(Buffer&, GLintptr, IndexType, UnsignedInt, UnsignedInt) + * with unspecified index limits, see its documentation for more + * information. Prefer to set index limits for better performance. */ Mesh& setIndexBuffer(Buffer& buffer, GLintptr offset, IndexType type) { return setIndexBuffer(buffer, offset, type, 0, 0); @@ -629,15 +655,15 @@ class MAGNUM_EXPORT Mesh: public AbstractObject { * @fn_gl{BindBuffer}, @fn_gl{VertexAttribPointer}, * @fn_gl{DisableVertexAttribArray} or @fn_gl{BindVertexArray} (if * @extension{APPLE,vertex_array_object} is available), @fn_gl{DrawArrays} - * or @fn_gl{DrawElements}/@fn_gl{DrawRangeElements}. + * or @fn_gl{DrawElements}/@fn_gl{DrawRangeElements} */ void draw(AbstractShaderProgram& shader) { shader.use(); #ifndef MAGNUM_TARGET_GLES2 - drawInternal(0, _vertexCount, _indexOffset, _indexCount, _indexStart, _indexEnd); + drawInternal(_count, 0, _indexOffset, _indexStart, _indexEnd); #else - drawInternal(0, _vertexCount, _indexOffset, _indexCount); + drawInternal(_count, 0, _indexOffset); #endif } @@ -649,11 +675,11 @@ class MAGNUM_EXPORT Mesh: public AbstractObject { * @deprecated Use @ref Magnum::Mesh::draw(AbstractShaderProgram&) "draw(AbstractShaderProgram&)" * instead. */ - void draw() { + CORRADE_DEPRECATED("use draw(AbstractShaderProgram&) instead") void draw() { #ifndef MAGNUM_TARGET_GLES2 - drawInternal(0, _vertexCount, _indexOffset, _indexCount, _indexStart, _indexEnd); + drawInternal(_count, 0, _indexOffset, _indexStart, _indexEnd); #else - drawInternal(0, _vertexCount, _indexOffset, _indexCount); + drawInternal(_count, 0, _indexOffset); #endif } #endif @@ -774,9 +800,9 @@ class MAGNUM_EXPORT Mesh: public AbstractObject { #endif #ifndef MAGNUM_TARGET_GLES2 - void drawInternal(Int firstVertex, Int vertexCount, GLintptr indexOffset, Int indexCount, Int indexStart, Int indexEnd); + void drawInternal(Int count, Int firstVertex, GLintptr indexOffset, Int indexStart, Int indexEnd); #else - void drawInternal(Int firstVertex, Int vertexCount, GLintptr indexOffset, Int indexCount); + void drawInternal(Int count, Int firstVertex, GLintptr indexOffset); #endif void MAGNUM_LOCAL createImplementationDefault(); @@ -805,7 +831,7 @@ class MAGNUM_EXPORT Mesh: public AbstractObject { #endif #endif - void MAGNUM_LOCAL bindIndexBufferImplementationDefault(Buffer& buffer); + void MAGNUM_LOCAL bindIndexBufferImplementationDefault(Buffer&); void MAGNUM_LOCAL bindIndexBufferImplementationVAO(Buffer& buffer); void MAGNUM_LOCAL bindImplementationDefault(); @@ -816,7 +842,7 @@ class MAGNUM_EXPORT Mesh: public AbstractObject { GLuint _id; MeshPrimitive _primitive; - Int _vertexCount, _indexCount; + Int _count; #ifndef MAGNUM_TARGET_GLES2 UnsignedInt _indexStart, _indexEnd; #endif diff --git a/src/Magnum/MeshTools/Compile.cpp b/src/Magnum/MeshTools/Compile.cpp index bc586f77a..3b42aa07b 100644 --- a/src/Magnum/MeshTools/Compile.cpp +++ b/src/Magnum/MeshTools/Compile.cpp @@ -72,17 +72,17 @@ std::tuple, std::unique_ptr> compile(const stride - normalOffset - sizeof(Shaders::Generic2D::TextureCoordinates::Type)); } - /* Fill vertex buffer with interleaved data and finalize mesh - configuration */ + /* Fill vertex buffer with interleaved data */ vertexBuffer->setData(data, BufferUsage::StaticDraw); - mesh.setVertexCount(vertexCount); /* Fill index buffer */ std::unique_ptr indexBuffer; if(meshData.isIndexed()) { indexBuffer.reset(new Buffer{Buffer::Target::ElementArray}); MeshTools::compressIndices(mesh, *indexBuffer, usage, meshData.indices()); - } + + /* Else set proper vertex count */ + } else mesh.setCount(vertexCount); return std::make_tuple(std::move(mesh), std::move(vertexBuffer), std::move(indexBuffer)); } @@ -139,17 +139,17 @@ std::tuple, std::unique_ptr> compile(const stride - textureCoordsOffset - sizeof(Shaders::Generic3D::TextureCoordinates::Type)); } - /* Fill vertex buffer with interleaved data and finalize mesh - configuration */ + /* Fill vertex buffer with interleaved data */ vertexBuffer->setData(data, BufferUsage::StaticDraw); - mesh.setVertexCount(vertexCount); /* Fill index buffer */ std::unique_ptr indexBuffer; if(meshData.isIndexed()) { indexBuffer.reset(new Buffer{Buffer::Target::ElementArray}); MeshTools::compressIndices(mesh, *indexBuffer, usage, meshData.indices()); - } + + /* Else set proper vertex count */ + } mesh.setCount(vertexCount); return std::make_tuple(std::move(mesh), std::move(vertexBuffer), std::move(indexBuffer)); } diff --git a/src/Magnum/MeshTools/CompressIndices.cpp b/src/Magnum/MeshTools/CompressIndices.cpp index 7d4f53074..d8be145d1 100644 --- a/src/Magnum/MeshTools/CompressIndices.cpp +++ b/src/Magnum/MeshTools/CompressIndices.cpp @@ -82,7 +82,7 @@ void compressIndices(Mesh& mesh, Buffer& buffer, BufferUsage usage, const std::v Containers::Array data; std::tie(indexCount, indexType, data) = compressIndicesInternal(indices, *minmax.second); - mesh.setIndexCount(indices.size()) + mesh.setCount(indices.size()) .setIndexBuffer(buffer, 0, indexType, *minmax.first, *minmax.second); buffer.setData(data, usage); } diff --git a/src/Magnum/MeshTools/CompressIndices.h b/src/Magnum/MeshTools/CompressIndices.h index e1e847910..2b3b777f9 100644 --- a/src/Magnum/MeshTools/CompressIndices.h +++ b/src/Magnum/MeshTools/CompressIndices.h @@ -65,9 +65,9 @@ std::tuple> MAGNUM_MESHTOO @param indices Index array The same as @ref compressIndices(const std::vector&), but this -function writes the output to given buffer and calls @ref Mesh::setIndexCount() -and @ref Mesh::setIndexBuffer(), thus you don't need to do anything else for -mesh index configuration. +function writes the output to given buffer and calls @ref Mesh::setCount() and +@ref Mesh::setIndexBuffer(), thus you don't need to do anything else for mesh +index configuration. @see @ref MeshTools::interleave(), @ref MeshTools::compile() */ diff --git a/src/Magnum/MeshTools/FullScreenTriangle.cpp b/src/Magnum/MeshTools/FullScreenTriangle.cpp index 5d3b728bf..b7ce1cc63 100644 --- a/src/Magnum/MeshTools/FullScreenTriangle.cpp +++ b/src/Magnum/MeshTools/FullScreenTriangle.cpp @@ -37,7 +37,7 @@ namespace Magnum { namespace MeshTools { std::pair, Mesh> fullScreenTriangle(Version version) { Mesh mesh; mesh.setPrimitive(MeshPrimitive::Triangles) - .setVertexCount(3); + .setCount(3); std::unique_ptr buffer; #ifndef MAGNUM_TARGET_GLES diff --git a/src/Magnum/MeshTools/Interleave.h b/src/Magnum/MeshTools/Interleave.h index d14913d5d..2c623cbb4 100644 --- a/src/Magnum/MeshTools/Interleave.h +++ b/src/Magnum/MeshTools/Interleave.h @@ -184,9 +184,10 @@ template std::tuple interleaveInt @param usage Vertex buffer usage @param attributes Attribute arrays and gaps -The same as @ref interleave(const T&, const U&...), but this function writes the -output to given array buffer and updates vertex count in the mesh accordingly, -so you don't have to call @ref Mesh::setVertexCount() on your own. +The same as @ref interleave(const T&, const U&...), but this function also +writes the output to given array buffer. If given mesh is not indexed, it also +updates vertex count in the mesh accordingly, so you don't have to call +@ref Mesh::setCount() on your own. @attention You still must call @ref Mesh::setPrimitive() and @ref Mesh::addVertexBuffer() on the mesh afterwards. @@ -199,7 +200,7 @@ template void interleave(Mesh& mesh, Buffer& buffer, BufferUsage usa std::size_t attributeCount; std::tie(attributeCount, std::ignore, data) = interleave(attributes...); - mesh.setVertexCount(attributeCount); + if(!mesh.isIndexed()) mesh.setCount(attributeCount); buffer.setData(data, usage); } @@ -210,11 +211,11 @@ Simplified specialization of the above function for only one attribute array, equivalent to the following: @code buffer.setData(attribute, usage); -mesh.setVertexCount(attribute.size()); +if(!mesh.isIndexed()) mesh.setVertexCount(attribute.size()); @endcode */ template typename std::enable_if::value, void>::type interleave(Mesh& mesh, Buffer& buffer, BufferUsage usage, const T& attribute) { - mesh.setVertexCount(attribute.size()); + if(!mesh.isIndexed()) mesh.setCount(attribute.size()); buffer.setData(attribute, usage); } diff --git a/src/Magnum/MeshView.cpp b/src/Magnum/MeshView.cpp index 893b50c02..fdcfeef32 100644 --- a/src/Magnum/MeshView.cpp +++ b/src/Magnum/MeshView.cpp @@ -36,7 +36,7 @@ MeshView& MeshView::setIndexRange(Int first, Int count, UnsignedInt, UnsignedInt #endif { _indexOffset = _original->_indexOffset + first*_original->indexSize(); - _indexCount = count; + _count = count; #ifndef MAGNUM_TARGET_GLES2 _indexStart = start; _indexEnd = end; @@ -48,18 +48,18 @@ void MeshView::draw(AbstractShaderProgram& shader) { shader.use(); #ifndef MAGNUM_TARGET_GLES2 - _original->drawInternal(_firstVertex, _vertexCount, _indexOffset, _indexCount, _indexStart, _indexEnd); + _original->drawInternal(_count, _firstVertex, _indexOffset, _indexStart, _indexEnd); #else - _original->drawInternal(_firstVertex, _vertexCount, _indexOffset, _indexCount); + _original->drawInternal(_count, _firstVertex, _indexOffset); #endif } #ifdef MAGNUM_BUILD_DEPRECATED void MeshView::draw() { #ifndef MAGNUM_TARGET_GLES2 - _original->drawInternal(_firstVertex, _vertexCount, _indexOffset, _indexCount, _indexStart, _indexEnd); + _original->drawInternal(_count, _firstVertex, _indexOffset, _indexStart, _indexEnd); #else - _original->drawInternal(_firstVertex, _vertexCount, _indexOffset, _indexCount); + _original->drawInternal(_count, _firstVertex, _indexOffset); #endif } #endif diff --git a/src/Magnum/MeshView.h b/src/Magnum/MeshView.h index d283d6410..53e510188 100644 --- a/src/Magnum/MeshView.h +++ b/src/Magnum/MeshView.h @@ -83,7 +83,7 @@ class MAGNUM_EXPORT MeshView { */ MeshView& setVertexRange(Int first, Int count) { _firstVertex = first; - _vertexCount = count; + _count = count; return *this; } @@ -135,14 +135,14 @@ class MAGNUM_EXPORT MeshView { private: Mesh* _original; - Int _firstVertex, _vertexCount, _indexCount; + Int _firstVertex, _count; GLintptr _indexOffset; #ifndef MAGNUM_TARGET_GLES2 UnsignedInt _indexStart, _indexEnd; #endif }; -inline MeshView::MeshView(Mesh& original): _original(&original), _firstVertex(0), _vertexCount(0), _indexCount(0), _indexOffset(0) +inline MeshView::MeshView(Mesh& original): _original(&original), _firstVertex(0), _count(0), _indexOffset(0) #ifndef MAGNUM_TARGET_GLES2 , _indexStart(0), _indexEnd(0) #endif diff --git a/src/Magnum/Test/MeshGLTest.cpp b/src/Magnum/Test/MeshGLTest.cpp index f9a608780..803f0591f 100644 --- a/src/Magnum/Test/MeshGLTest.cpp +++ b/src/Magnum/Test/MeshGLTest.cpp @@ -393,8 +393,8 @@ Checker::Checker(AbstractShaderProgram&& shader, RenderbufferFormat format, Mesh framebuffer.attachRenderbuffer(Framebuffer::ColorAttachment(0), renderbuffer); framebuffer.bind(FramebufferTarget::ReadDraw); - mesh.setVertexCount(2) - .setPrimitive(MeshPrimitive::Points); + mesh.setPrimitive(MeshPrimitive::Points) + .setCount(2); /* Skip first vertex so we test also offsets */ MeshView(mesh).setVertexRange(1, 1).draw(shader); @@ -1147,8 +1147,8 @@ IndexChecker::IndexChecker(Mesh& mesh): framebuffer({{}, Vector2i(1)}) { framebuffer.attachRenderbuffer(Framebuffer::ColorAttachment(0), renderbuffer); framebuffer.bind(FramebufferTarget::ReadDraw); - mesh.setIndexCount(2) - .setPrimitive(MeshPrimitive::Points); + mesh.setPrimitive(MeshPrimitive::Points) + .setCount(2); /* Skip first vertex so we test also offsets */ MeshView(mesh).setIndexRange(1, 1).draw(MultipleShader{}); diff --git a/src/Magnum/Test/PrimitiveQueryGLTest.cpp b/src/Magnum/Test/PrimitiveQueryGLTest.cpp index d2509454e..7099cd0ae 100644 --- a/src/Magnum/Test/PrimitiveQueryGLTest.cpp +++ b/src/Magnum/Test/PrimitiveQueryGLTest.cpp @@ -88,7 +88,7 @@ void PrimitiveQueryGLTest::query() { Mesh mesh; mesh.setPrimitive(MeshPrimitive::Triangles) - .setVertexCount(9) + .setCount(9) .addVertexBuffer(vertices, 0, MyShader::Position()); MAGNUM_VERIFY_NO_ERROR(); diff --git a/src/Magnum/Test/SampleQueryGLTest.cpp b/src/Magnum/Test/SampleQueryGLTest.cpp index 39b6ffdd6..1d5acb6fd 100644 --- a/src/Magnum/Test/SampleQueryGLTest.cpp +++ b/src/Magnum/Test/SampleQueryGLTest.cpp @@ -112,7 +112,7 @@ void SampleQueryGLTest::querySamplesPassed() { Mesh mesh; mesh.setPrimitive(MeshPrimitive::Triangles) - .setVertexCount(3) + .setCount(3) .addVertexBuffer(buffer, 0, AbstractShaderProgram::Attribute<0, Vector2>()); MyShader shader; @@ -161,7 +161,7 @@ void SampleQueryGLTest::conditionalRender() { Mesh mesh; mesh.setPrimitive(MeshPrimitive::Triangles) - .setVertexCount(3) + .setCount(3) .addVertexBuffer(buffer, 0, AbstractShaderProgram::Attribute<0, Vector2>()); MyShader shader; diff --git a/src/Magnum/Text/Renderer.cpp b/src/Magnum/Text/Renderer.cpp index 2256ecd9c..ed767bca0 100644 --- a/src/Magnum/Text/Renderer.cpp +++ b/src/Magnum/Text/Renderer.cpp @@ -215,7 +215,7 @@ std::tuple renderInternal(AbstractFont& font, const GlyphCache& c in subclass) */ Mesh mesh; mesh.setPrimitive(MeshPrimitive::Triangles) - .setIndexCount(indexCount) + .setCount(indexCount) .setIndexBuffer(indexBuffer, 0, indexType, 0, vertices.size()); return std::make_tuple(std::move(mesh), rectangle); @@ -342,7 +342,7 @@ void AbstractRenderer::reserve(const uint32_t glyphCount, const BufferUsage vert #ifdef CORRADE_TARGET_EMSCRIPTEN _vertexBufferData = Containers::Array(vertexCount*sizeof(Vertex)); #endif - _mesh.setVertexCount(0); + _mesh.setCount(0); /* Render indices */ Containers::Array indexData; @@ -354,7 +354,7 @@ void AbstractRenderer::reserve(const uint32_t glyphCount, const BufferUsage vert #ifdef CORRADE_TARGET_EMSCRIPTEN _indexBufferData = Containers::Array(indexData.size()); #endif - _mesh.setIndexCount(0) + _mesh.setCount(0) .setIndexBuffer(_indexBuffer, 0, indexType, 0, vertexCount); /* Prefill index buffer */ @@ -386,7 +386,7 @@ void AbstractRenderer::render(const std::string& text) { bufferUnmapImplementation(_vertexBuffer); /* Update index count */ - _mesh.setIndexCount(indexCount); + _mesh.setCount(indexCount); } #ifndef DOXYGEN_GENERATING_OUTPUT diff --git a/src/Magnum/TextureTools/DistanceField.cpp b/src/Magnum/TextureTools/DistanceField.cpp index ccb2aefd6..1145732bd 100644 --- a/src/Magnum/TextureTools/DistanceField.cpp +++ b/src/Magnum/TextureTools/DistanceField.cpp @@ -179,7 +179,7 @@ void distanceField(Texture2D& input, Texture2D& output, const Range2Di& rectangl Mesh mesh; mesh.setPrimitive(MeshPrimitive::Triangles) - .setVertexCount(3); + .setCount(3); /* Older GLSL doesn't have gl_VertexID, vertices must be supplied explicitly */ Buffer buffer;