Browse Source

Don't differentiate between vertex and index count in Mesh.

Only one value from these two was used in the end, wasting precious
bytes. Also these two values were used to differentiate between indexed
and non-indexed mesh (instead of relying on actual index buffer being
bound), which was very confusing. This approach looks more clean. The
MeshView class is not yet updated, as the change would expose some
features that aren't possible in current implementation (base vertex
specification).

Merged Mesh::setVertexCount() and Mesh::setIndexCount() into one
Mesh::setCount(), the two original functions are now guarded aliases to
the new one, are marked as deprecated and will be removed in future
release, similarly for the getters.

In particular, if the mesh is indexed, setVertexCount() does nothing and
vertexCount() returns 0. The setIndexCount() and indexCount() do and
return the same regardless of whether the mesh is indexed or not.
pull/51/head
Vladimír Vondruš 12 years ago
parent
commit
bfa2a42638
  1. 2
      src/Magnum/DebugTools/ForceRenderer.cpp
  2. 10
      src/Magnum/DebugTools/Implementation/AbstractShapeRenderer.cpp
  3. 2
      src/Magnum/DebugTools/ObjectRenderer.cpp
  4. 28
      src/Magnum/Mesh.cpp
  5. 138
      src/Magnum/Mesh.h
  6. 16
      src/Magnum/MeshTools/Compile.cpp
  7. 2
      src/Magnum/MeshTools/CompressIndices.cpp
  8. 6
      src/Magnum/MeshTools/CompressIndices.h
  9. 2
      src/Magnum/MeshTools/FullScreenTriangle.cpp
  10. 13
      src/Magnum/MeshTools/Interleave.h
  11. 10
      src/Magnum/MeshView.cpp
  12. 6
      src/Magnum/MeshView.h
  13. 8
      src/Magnum/Test/MeshGLTest.cpp
  14. 2
      src/Magnum/Test/PrimitiveQueryGLTest.cpp
  15. 4
      src/Magnum/Test/SampleQueryGLTest.cpp
  16. 8
      src/Magnum/Text/Renderer.cpp
  17. 2
      src/Magnum/TextureTools/DistanceField.cpp

2
src/Magnum/DebugTools/ForceRenderer.cpp

@ -88,7 +88,7 @@ template<UnsignedInt dimensions> ForceRenderer<dimensions>::ForceRenderer(SceneG
Mesh* mesh = new Mesh;
mesh->setPrimitive(MeshPrimitive::Lines)
.setIndexCount(indices.size())
.setCount(indices.size())
.addVertexBuffer(*vertexBuffer, 0,
typename Shaders::Flat<dimensions>::Position(Shaders::Flat<dimensions>::Position::Components::Two))
.setIndexBuffer(*indexBuffer, 0, Mesh::IndexType::UnsignedByte, 0, positions.size());

10
src/Magnum/DebugTools/Implementation/AbstractShapeRenderer.cpp

@ -53,7 +53,6 @@ template<> void create<2>(Trade::MeshData2D& data, Resource<Mesh>& 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<Mesh>& 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<Mesh>& meshResource, Resource<Buffer>& vertexBufferResource, Resource<Buffer>& indexBufferResource) {
@ -75,7 +76,6 @@ template<> void create<3>(Trade::MeshData3D& data, Resource<Mesh>& 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<Mesh>& 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());
}
}

2
src/Magnum/DebugTools/ObjectRenderer.cpp

@ -166,7 +166,7 @@ template<UnsignedInt dimensions> ObjectRenderer<dimensions>::ObjectRenderer(Scen
ResourceManager::instance().set(this->indexBuffer.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual);
mesh->setPrimitive(MeshPrimitive::Lines)
.setIndexCount(Renderer<dimensions>::indices.size())
.setCount(Renderer<dimensions>::indices.size())
.addVertexBuffer(*vertexBuffer, 0,
typename Shaders::VertexColor<dimensions>::Position(),
typename Shaders::VertexColor<dimensions>::Color())

28
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<GLvoid*>(indexOffset));
glDrawRangeElements(GLenum(_primitive), indexStart, indexEnd, count, GLenum(_indexType), reinterpret_cast<GLvoid*>(indexOffset));
#endif
/* Indexed mesh without specified range */
else
glDrawElements(GLenum(_primitive), indexCount, GLenum(_indexType), reinterpret_cast<GLvoid*>(indexOffset));
glDrawElements(GLenum(_primitive), count, GLenum(_indexType), reinterpret_cast<GLvoid*>(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() {

138
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

16
src/Magnum/MeshTools/Compile.cpp

@ -72,17 +72,17 @@ std::tuple<Mesh, std::unique_ptr<Buffer>, std::unique_ptr<Buffer>> 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<Buffer> 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<Mesh, std::unique_ptr<Buffer>, std::unique_ptr<Buffer>> 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<Buffer> 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));
}

2
src/Magnum/MeshTools/CompressIndices.cpp

@ -82,7 +82,7 @@ void compressIndices(Mesh& mesh, Buffer& buffer, BufferUsage usage, const std::v
Containers::Array<char> 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);
}

6
src/Magnum/MeshTools/CompressIndices.h

@ -65,9 +65,9 @@ std::tuple<std::size_t, Mesh::IndexType, Containers::Array<char>> MAGNUM_MESHTOO
@param indices Index array
The same as @ref compressIndices(const std::vector<UnsignedInt>&), 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()
*/

2
src/Magnum/MeshTools/FullScreenTriangle.cpp

@ -37,7 +37,7 @@ namespace Magnum { namespace MeshTools {
std::pair<std::unique_ptr<Buffer>, Mesh> fullScreenTriangle(Version version) {
Mesh mesh;
mesh.setPrimitive(MeshPrimitive::Triangles)
.setVertexCount(3);
.setCount(3);
std::unique_ptr<Buffer> buffer;
#ifndef MAGNUM_TARGET_GLES

13
src/Magnum/MeshTools/Interleave.h

@ -184,9 +184,10 @@ template<class T, class ...U> std::tuple<std::size_t, std::size_t> 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<class ...T> 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<class T> typename std::enable_if<!std::is_convertible<T, std::size_t>::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);
}

10
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

6
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

8
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{});

2
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();

4
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;

8
src/Magnum/Text/Renderer.cpp

@ -215,7 +215,7 @@ std::tuple<Mesh, Range2D> 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<UnsignedByte>(vertexCount*sizeof(Vertex));
#endif
_mesh.setVertexCount(0);
_mesh.setCount(0);
/* Render indices */
Containers::Array<unsigned char> indexData;
@ -354,7 +354,7 @@ void AbstractRenderer::reserve(const uint32_t glyphCount, const BufferUsage vert
#ifdef CORRADE_TARGET_EMSCRIPTEN
_indexBufferData = Containers::Array<UnsignedByte>(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

2
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;

Loading…
Cancel
Save