Browse Source

Removing IndexedMesh, part 5: merged documentation, removed IndexedMesh.

pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
dc5a4d83d9
  1. 1
      src/CMakeLists.txt
  2. 3
      src/DebugTools/Implementation/AbstractBoxRenderer.cpp
  3. 9
      src/DebugTools/ObjectRenderer.cpp
  4. 87
      src/IndexedMesh.h
  5. 1
      src/Magnum.h
  6. 150
      src/Mesh.h
  7. 18
      src/MeshTools/CompressIndices.cpp
  8. 17
      src/MeshTools/CompressIndices.h
  9. 22
      src/MeshTools/Test/CompressIndicesTest.cpp
  10. 9
      src/Text/TextRenderer.cpp
  11. 2
      src/Text/TextRenderer.h

1
src/CMakeLists.txt

@ -65,7 +65,6 @@ set(Magnum_HEADERS
Framebuffer.h Framebuffer.h
Image.h Image.h
ImageWrapper.h ImageWrapper.h
IndexedMesh.h
Magnum.h Magnum.h
Mesh.h Mesh.h
Query.h Query.h

3
src/DebugTools/Implementation/AbstractBoxRenderer.cpp

@ -16,7 +16,6 @@
#include "AbstractBoxRenderer.h" #include "AbstractBoxRenderer.h"
#include "Buffer.h" #include "Buffer.h"
#include "IndexedMesh.h"
#include "DebugTools/ResourceManager.h" #include "DebugTools/ResourceManager.h"
#include "MeshTools/CompressIndices.h" #include "MeshTools/CompressIndices.h"
#include "Primitives/Cube.h" #include "Primitives/Cube.h"
@ -66,7 +65,7 @@ AbstractBoxRenderer<3>::AbstractBoxRenderer() {
Primitives::Cube cube; Primitives::Cube cube;
Buffer* vertexBuffer = new Buffer(Buffer::Target::Array); Buffer* vertexBuffer = new Buffer(Buffer::Target::Array);
Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray);
IndexedMesh* mesh = new IndexedMesh; Mesh* mesh = new Mesh;
vertexBuffer->setData(*cube.positions(0), Buffer::Usage::StaticDraw); vertexBuffer->setData(*cube.positions(0), Buffer::Usage::StaticDraw);
ResourceManager::instance()->set(this->vertexBuffer.key(), vertexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); ResourceManager::instance()->set(this->vertexBuffer.key(), vertexBuffer, ResourceDataState::Final, ResourcePolicy::Manual);

9
src/DebugTools/ObjectRenderer.cpp

@ -16,7 +16,6 @@
#include "ObjectRenderer.h" #include "ObjectRenderer.h"
#include "Buffer.h" #include "Buffer.h"
#include "IndexedMesh.h"
#include "DebugTools/ResourceManager.h" #include "DebugTools/ResourceManager.h"
#include "MeshTools/Interleave.h" #include "MeshTools/Interleave.h"
#include "SceneGraph/AbstractCamera.h" #include "SceneGraph/AbstractCamera.h"
@ -149,7 +148,7 @@ template<std::uint8_t dimensions> ObjectRenderer<dimensions>::ObjectRenderer(Sce
/* Create the mesh */ /* Create the mesh */
Buffer* vertexBuffer = new Buffer(Buffer::Target::Array); Buffer* vertexBuffer = new Buffer(Buffer::Target::Array);
Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray); Buffer* indexBuffer = new Buffer(Buffer::Target::ElementArray);
IndexedMesh* mesh = new IndexedMesh; Mesh* mesh = new Mesh;
MeshTools::interleave(mesh, vertexBuffer, Buffer::Usage::StaticDraw, Renderer<dimensions>::positions, Renderer<dimensions>::colors); MeshTools::interleave(mesh, vertexBuffer, Buffer::Usage::StaticDraw, Renderer<dimensions>::positions, Renderer<dimensions>::colors);
ResourceManager::instance()->set(this->vertexBuffer.key(), vertexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); ResourceManager::instance()->set(this->vertexBuffer.key(), vertexBuffer, ResourceDataState::Final, ResourcePolicy::Manual);
@ -158,9 +157,11 @@ template<std::uint8_t dimensions> ObjectRenderer<dimensions>::ObjectRenderer(Sce
ResourceManager::instance()->set(this->indexBuffer.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual); ResourceManager::instance()->set(this->indexBuffer.key(), indexBuffer, ResourceDataState::Final, ResourcePolicy::Manual);
mesh->setPrimitive(Mesh::Primitive::Lines) mesh->setPrimitive(Mesh::Primitive::Lines)
->addInterleavedVertexBuffer(vertexBuffer, 0, typename Shaders::VertexColorShader<dimensions>::Position(), typename Shaders::VertexColorShader<dimensions>::Color())
->setIndexCount(Renderer<dimensions>::indices.size()) ->setIndexCount(Renderer<dimensions>::indices.size())
->setIndexType(IndexedMesh::IndexType::UnsignedByte) ->setIndexType(Mesh::IndexType::UnsignedByte)
->addInterleavedVertexBuffer(vertexBuffer, 0,
typename Shaders::VertexColorShader<dimensions>::Position(),
typename Shaders::VertexColorShader<dimensions>::Color())
->setIndexBuffer(indexBuffer); ->setIndexBuffer(indexBuffer);
ResourceManager::instance()->set<Mesh>(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); ResourceManager::instance()->set<Mesh>(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual);
} }

87
src/IndexedMesh.h

@ -1,87 +0,0 @@
#ifndef Magnum_IndexedMesh_h
#define Magnum_IndexedMesh_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
/** @file
* @brief Class Magnum::IndexedMesh
*/
#include "Mesh.h"
#include "corradeCompatibility.h"
namespace Magnum {
/**
@brief Indexed mesh
@section IndexedMesh-configuration Indexed mesh configuration
Next to @ref Mesh-configuration "everything needed for non-indexed mesh" you
have to call also setIndexCount() and setIndexType(). Then create index buffer
and assign it to the mesh using setIndexBuffer() or use
MeshTools::compressIndices() to conveniently fill the index buffer and set
index count and type.
Similarly as in Mesh itself the index buffer is not managed by the mesh, so
you have to manage it on your own. On the other hand it allows you to use
one index buffer for more meshes (with different vertex data in each mesh, for
example) or store more than only index data in one buffer.
Example usage -- creating a cube mesh, assigning vertex buffer with
interleaved vertex attributes and compressed index buffer for use with
Shaders::PhongShader:
@code
Buffer *vertexBuffer, *indexBuffer;
Mesh* mesh;
Primitives::Cube cube;
MeshTools::interleave(mesh, vertexBuffer, Buffer::Usage::StaticDraw, *cube.positions(0), *cube.normals(0));
MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw, *cube.indices());
mesh->setPrimitive(plane.primitive())
->addInterleavedVertexBuffer(vertexBuffer, 0, Shaders::PhongShader::Position(), Shaders::PhongShader::Normal());
@endcode
@section IndexedMesh-drawing Rendering meshes
From user point-of-view the operation is the same as for
@ref Mesh-drawing "non-indexed meshes".
@section IndexedMesh-performance-optimization Performance optimizations
If @extension{APPLE,vertex_array_object}, OpenGL ES 3.0 or
@es_extension{OES,vertex_array_object} on OpenGL ES 2.0 is supported, next to
@ref Mesh-performance-optimization "optimizations in Mesh itself" the index
buffer is bound on object construction instead of binding it in every draw()
call.
*/
class MAGNUM_EXPORT IndexedMesh: public Mesh {
friend class Context;
public:
/**
* @brief Constructor
* @param primitive Primitive type
*
* Creates indexed mesh with zero vertex count, zero index count and
* no vertex or index buffers.
*/
inline explicit IndexedMesh(Primitive primitive = Primitive::Triangles): Mesh(primitive) {}
};
}
#endif

1
src/Magnum.h

@ -172,7 +172,6 @@ typedef ImageWrapper<1> ImageWrapper1D;
typedef ImageWrapper<2> ImageWrapper2D; typedef ImageWrapper<2> ImageWrapper2D;
typedef ImageWrapper<3> ImageWrapper3D; typedef ImageWrapper<3> ImageWrapper3D;
class IndexedMesh;
class Mesh; class Mesh;
class Query; class Query;
class Renderbuffer; class Renderbuffer;

150
src/Mesh.h

@ -28,75 +28,168 @@
namespace Magnum { namespace Magnum {
/** /**
@brief Non-indexed mesh @brief %Mesh
@section Mesh-configuration Mesh configuration @section Mesh-configuration Mesh configuration
To properly configure mesh, you have to set primitive either in constructor or You have to specify at least primitive and vertex count using setPrimitive()
using setPrimitive() and call setVertexCount(). Then create vertex buffers and and setVertexCount(). Then fill your vertex buffers with data, add them to the
fill them with vertex data. You can also use MeshTools::interleave() to mesh and specify @ref AbstractShaderProgram::Attribute "shader attribute" layout
conveniently set vertex count and buffer data. At last assign them to mesh and inside the buffers using addVertexBuffer(), addInterleavedVertexBuffer() or
@ref AbstractShaderProgram::Attribute "shader attributes" using addVertexBufferStride(). You can also use MeshTools::interleave() in
addVertexBuffer(), addInterleavedVertexBuffer() or addVertexBufferStride(). combination with addInterleavedVertexBuffer() to conveniently fill interleaved
vertex buffer(s). The function itself calls setVertexCount(), so you don't
have to do it again.
Note that the buffer is not managed (e.g. deleted on destruction) by the mesh, If you have indexed mesh, you need to call setIndexCount() instead of
so you have to manage it on your own. On the other hand it allows you to use setVertexCount() and additionaly specify also index type using setIndexType().
one buffer for more meshes (each mesh for example configured for different Then fill your index buffer with data and add it to the mesh using
shader) or store more than only vertex data in one buffer. setIndexBuffer(). You can also use MeshTools::compressIndices() to
conveniently compress the indices, fill the index buffer and configure the
mesh instead of calling setIndexCount(), setIndexType() and setIndexBuffer()
manually.
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. 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.
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 draw().
@subsection Mesh-configuration-examples Example mesh configuration
@subsubsection Mesh-configuration-examples-nonindexed Basic non-indexed mesh
Example usage -- filling buffer with position data, configuring the mesh and
assigning the buffer to mesh to use with custom shader:
@code @code
// Custom shader, needing only position data
class MyShader: public AbstractShaderProgram { class MyShader: public AbstractShaderProgram {
public: public:
typedef Attribute<0, Point3D> Position; typedef Attribute<0, Point3D> Position;
// ... // ...
}; };
Buffer* buffer;
Mesh* mesh; Mesh* mesh;
Buffer* vertexBuffer;
// Fill vertex buffer with position data
static constexpr Point3D positions[30] = { static constexpr Point3D positions[30] = {
// ... // ...
}; };
buffer->setData(positions, Buffer::Usage::StaticDraw); vertexBuffer->setData(positions, Buffer::Usage::StaticDraw);
// Set primitive and vertex count, add the buffer and specify its layout
mesh->setPrimitive(Mesh::Primitive::Triangles) mesh->setPrimitive(Mesh::Primitive::Triangles)
->setVertexCount(30) ->setVertexCount(30)
->addVertexBuffer(buffer, MyShader::Position()); ->addVertexBuffer(vertexBuffer, 0, MyShader::Position());
@endcode @endcode
Example usage -- creating a plane mesh and assigning buffer with interleaved @subsubsection Mesh-configuration-examples-nonindexed-phong Interleaved vertex data
vertex attributes for use with Shaders::PhongShader:
@code @code
Buffer* buffer; // Non-indexed primitive with positions and normals
Primitives::Plane plane;
Mesh* mesh; Mesh* mesh;
Buffer* vertexBuffer;
Primitives::Plane plane; // Fill vertex buffer with interleaved position and normal data
MeshTools::interleave(mesh, buffer, Buffer::Usage::StaticDraw, *plane.positions(0), *plane.normals(0)); MeshTools::interleave(mesh, buffer, Buffer::Usage::StaticDraw,
*plane.positions(0), *plane.normals(0));
// Set primitive and specify layout of interleaved vertex buffer, vertex count
// has been already set by MeshTools::interleave()
mesh->setPrimitive(plane.primitive())
->addInterleavedVertexBuffer(buffer, 0,
Shaders::PhongShader::Position(),
Shaders::PhongShader::Normal());
@endcode
@subsubsection Mesh-configuration-examples-indexed-phong Indexed mesh
@code
// Custom shader
class MyShader: public AbstractShaderProgram {
public:
typedef Attribute<0, Point3D> Position;
// ...
};
Buffer *vertexBuffer, *indexBuffer;
Mesh* mesh;
// Fill vertex buffer with position data
static constexpr Point3D positions[30] = {
// ...
};
vertexBuffer->setData(positions, Buffer::Usage::StaticDraw);
// Fill index buffer with index data
static constexpr GLubyte indices[75] = {
// ...
};
indexBuffer->setData(indices, Buffer::Usage::StaticDraw);
// Set primitive, index count and type, add the buffers
mesh->setPrimitive(Mesh::Primitive::Triangles)
->setIndexCount(75)
->setIndexType(Mesh::IndexType::UnsignedByte)
->addVertexBuffer(vertexBuffer, 0, MyShader::Position())
->setIndexBuffer(indexBuffer);
@endcode
@code
// Indexed primitive
Primitives::Cube cube;
Buffer *vertexBuffer, *indexBuffer;
Mesh* mesh;
// Fill vertex buffer with interleaved position and normal data
MeshTools::interleave(mesh, vertexBuffer, Buffer::Usage::StaticDraw,
*cube.positions(0), *cube.normals(0));
// Fill index buffer with compressed index data
MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw,
*cube.indices());
// Set primitive and specify layout of interleaved vertex buffer. Index count,
// type and index buffer has been already set by MeshTools::compressIndices().
mesh->setPrimitive(plane.primitive()) mesh->setPrimitive(plane.primitive())
->addInterleavedVertexBuffer(buffer, 0, Shaders::PhongShader::Position(), Shaders::PhongShader::Normal()); ->addInterleavedVertexBuffer(vertexBuffer, 0,
Shaders::PhongShader::Position(),
Shaders::PhongShader::Normal());
@endcode @endcode
Example usage -- passing color attribute as normalized unsigned byte with BGRA @subsubsection Mesh-configuration-examples-data-options Specific formats of vertex data
component ordering (e.g. directly from @ref Trade::TgaImporter "TGA file"):
@code @code
// Custom shader with colors specified as four floating-point values
class MyShader: public AbstractShaderProgram { class MyShader: public AbstractShaderProgram {
public: public:
typedef Attribute<1, Color4<>> Color; typedef Attribute<1, Color4<>> Color;
// ... // ...
}; };
Buffer* buffer;
Mesh* mesh; Mesh* mesh;
Buffer* colorBuffer;
// Fill vertex buffer with colors specified as four-byte BGRA (e.g. directly
// from TGA file)
GLubyte colors[4*30] = {
// ...
};
colorBuffer.setData(colors, Buffer::Usage::StaticDraw);
mesh->addVertexBuffer(buffer, MyShader::Color(Type::UsignedByte, MyShader::Color::Normalized|MyShader::Color::BGRA)); // Specify layout of color buffer -- each component is unsigned byte, we want
// to normalize them from [0, 255] to [0.0f, 1.0f] and reorder from BGRA
mesh->addVertexBuffer(colorBuffer, 0,
MyShader::Color(MyShader::Color::DataType::UsignedByte, MyShader::Color::DataOption::Normalized|MyShader::Color::DataOption::BGRA));
@endcode @endcode
@section Mesh-drawing Rendering meshes @section Mesh-drawing Rendering meshes
Basic workflow is: bind specific framebuffer for drawing (if needed), set up Basic workflow is: bind specific framebuffer for drawing (if needed), set up
respective shader and bind required textures (see respective shader, bind required textures (see
@ref AbstractShaderProgram-rendering-workflow "AbstractShaderProgram documentation" @ref AbstractShaderProgram-rendering-workflow "AbstractShaderProgram documentation"
for more infromation) and call Mesh::draw(). for more infromation) and call Mesh::draw().
@ -114,7 +207,6 @@ calls to @fn_gl{BindBuffer} and @fn_gl{BindVertexArray}. See documentation of
addVertexBuffer(), addInterleavedVertexBuffer(), addVertexBufferStride() for addVertexBuffer(), addInterleavedVertexBuffer(), addVertexBufferStride() for
more information. more information.
@see IndexedMesh
@todo Support for indirect draw buffer (OpenGL 4.0, @extension{ARB,draw_indirect}) @todo Support for indirect draw buffer (OpenGL 4.0, @extension{ARB,draw_indirect})
@todo Redo in a way that allows glMultiDrawArrays, glDrawArraysInstanced etc. @todo Redo in a way that allows glMultiDrawArrays, glDrawArraysInstanced etc.
*/ */
@ -849,7 +941,7 @@ template<> struct MAGNUM_EXPORT ConfigurationValue<Magnum::Mesh::IndexType> {
/** /**
* @brief Read enum value as string * @brief Read enum value as string
* *
* If the value is invalid, returns @ref Magnum::IndexedMesh::IndexType "IndexedMesh::IndexType::UnsignedInt". * If the value is invalid, returns @ref Magnum::Mesh::IndexType "Mesh::IndexType::UnsignedInt".
*/ */
static Magnum::Mesh::IndexType fromString(const std::string& stringValue, ConfigurationValueFlags); static Magnum::Mesh::IndexType fromString(const std::string& stringValue, ConfigurationValueFlags);
}; };

18
src/MeshTools/CompressIndices.cpp

@ -25,12 +25,12 @@ namespace Magnum { namespace MeshTools {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
namespace { namespace {
template<class> constexpr IndexedMesh::IndexType indexType(); template<class> constexpr Mesh::IndexType indexType();
template<> inline constexpr IndexedMesh::IndexType indexType<GLubyte>() { return IndexedMesh::IndexType::UnsignedByte; } template<> inline constexpr Mesh::IndexType indexType<GLubyte>() { return Mesh::IndexType::UnsignedByte; }
template<> inline constexpr IndexedMesh::IndexType indexType<GLushort>() { return IndexedMesh::IndexType::UnsignedShort; } template<> inline constexpr Mesh::IndexType indexType<GLushort>() { return Mesh::IndexType::UnsignedShort; }
template<> inline constexpr IndexedMesh::IndexType indexType<GLuint>() { return IndexedMesh::IndexType::UnsignedInt; } template<> inline constexpr Mesh::IndexType indexType<GLuint>() { return Mesh::IndexType::UnsignedInt; }
template<class T> inline std::tuple<std::size_t, IndexedMesh::IndexType, char*> compress(const std::vector<std::uint32_t>& indices) { template<class T> inline std::tuple<std::size_t, Mesh::IndexType, char*> compress(const std::vector<std::uint32_t>& indices) {
char* buffer = new char[indices.size()*sizeof(T)]; char* buffer = new char[indices.size()*sizeof(T)];
for(std::size_t i = 0; i != indices.size(); ++i) { for(std::size_t i = 0; i != indices.size(); ++i) {
T index = static_cast<T>(indices[i]); T index = static_cast<T>(indices[i]);
@ -43,7 +43,7 @@ template<class T> inline std::tuple<std::size_t, IndexedMesh::IndexType, char*>
} }
#endif #endif
std::tuple<std::size_t, IndexedMesh::IndexType, char*> compressIndices(const std::vector<std::uint32_t>& indices) { std::tuple<std::size_t, Mesh::IndexType, char*> compressIndices(const std::vector<std::uint32_t>& indices) {
std::size_t size = *std::max_element(indices.begin(), indices.end()); std::size_t size = *std::max_element(indices.begin(), indices.end());
switch(Math::log(256, size)) { switch(Math::log(256, size)) {
@ -60,16 +60,16 @@ std::tuple<std::size_t, IndexedMesh::IndexType, char*> compressIndices(const std
} }
} }
void compressIndices(IndexedMesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector<std::uint32_t>& indices) { void compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector<std::uint32_t>& indices) {
std::size_t indexCount; std::size_t indexCount;
IndexedMesh::IndexType indexType; Mesh::IndexType indexType;
char* data; char* data;
std::tie(indexCount, indexType, data) = compressIndices(indices); std::tie(indexCount, indexType, data) = compressIndices(indices);
mesh->setIndexBuffer(buffer) mesh->setIndexBuffer(buffer)
->setIndexType(indexType) ->setIndexType(indexType)
->setIndexCount(indices.size()); ->setIndexCount(indices.size());
buffer->setData(indexCount*IndexedMesh::indexSize(indexType), data, usage); buffer->setData(indexCount*Mesh::indexSize(indexType), data, usage);
delete[] data; delete[] data;
} }

17
src/MeshTools/CompressIndices.h

@ -22,7 +22,7 @@
#include <tuple> #include <tuple>
#include "Buffer.h" #include "Buffer.h"
#include "IndexedMesh.h" #include "Mesh.h"
#include "magnumMeshToolsVisibility.h" #include "magnumMeshToolsVisibility.h"
@ -41,18 +41,18 @@ sufficient. Size of the buffer can be computed from index count and type, as
shown below. Example usage: shown below. Example usage:
@code @code
std::size_t indexCount; std::size_t indexCount;
IndexedMesh::IndexType indexType; Mesh::IndexType indexType;
char* data; char* data;
std::tie(indexCount, indexType, data) = MeshTools::compressIndices(indices); std::tie(indexCount, indexType, data) = MeshTools::compressIndices(indices);
std::size_t dataSize = indexCount*IndexedMesh::indexSize(indexType); std::size_t dataSize = indexCount*Mesh::indexSize(indexType);
// ... // ...
delete[] data; delete[] data;
@endcode @endcode
See also compressIndices(IndexedMesh*, Buffer*, Buffer::Usage, const std::vector<std::uint32_t>&), See also compressIndices(Mesh*, Buffer*, Buffer::Usage, const std::vector<std::uint32_t>&),
which writes the compressed data directly into index buffer of given mesh. which writes the compressed data directly into index buffer of given mesh.
*/ */
std::tuple<std::size_t, IndexedMesh::IndexType, char*> MAGNUM_MESHTOOLS_EXPORT compressIndices(const std::vector<std::uint32_t>& indices); std::tuple<std::size_t, Mesh::IndexType, char*> MAGNUM_MESHTOOLS_EXPORT compressIndices(const std::vector<std::uint32_t>& indices);
/** /**
@brief Compress vertex indices and write them to index buffer @brief Compress vertex indices and write them to index buffer
@ -63,13 +63,12 @@ std::tuple<std::size_t, IndexedMesh::IndexType, char*> MAGNUM_MESHTOOLS_EXPORT c
The same as compressIndices(const std::vector<std::uint32_t>&), but this The same as compressIndices(const std::vector<std::uint32_t>&), but this
function writes the output to given index buffer and updates index count and function writes the output to given index buffer and updates index count and
type in the mesh accordingly, so you don't have to call type in the mesh accordingly, so you don't have to call Mesh::setIndexBuffer(),
IndexedMesh::setIndexBuffer(), IndexedMesh::setIndexCount() and Mesh::setIndexCount() and Mesh::setIndexType() on your own.
IndexedMesh::setIndexType() on your own.
@see MeshTools::interleave() @see MeshTools::interleave()
*/ */
void MAGNUM_MESHTOOLS_EXPORT compressIndices(IndexedMesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector<std::uint32_t>& indices); void MAGNUM_MESHTOOLS_EXPORT compressIndices(Mesh* mesh, Buffer* buffer, Buffer::Usage usage, const std::vector<std::uint32_t>& indices);
}} }}

22
src/MeshTools/Test/CompressIndicesTest.cpp

@ -39,14 +39,14 @@ CompressIndicesTest::CompressIndicesTest() {
void CompressIndicesTest::compressChar() { void CompressIndicesTest::compressChar() {
std::size_t indexCount; std::size_t indexCount;
IndexedMesh::IndexType indexType; Mesh::IndexType indexType;
char* data; char* data;
std::tie(indexCount, indexType, data) = MeshTools::compressIndices( std::tie(indexCount, indexType, data) = MeshTools::compressIndices(
std::vector<std::uint32_t>{1, 2, 3, 0, 4}); std::vector<std::uint32_t>{1, 2, 3, 0, 4});
CORRADE_COMPARE(indexCount, 5); CORRADE_COMPARE(indexCount, 5);
CORRADE_VERIFY(indexType == IndexedMesh::IndexType::UnsignedByte); CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedByte);
CORRADE_COMPARE(std::vector<char>(data, data+indexCount*IndexedMesh::indexSize(indexType)), CORRADE_COMPARE(std::vector<char>(data, data+indexCount*Mesh::indexSize(indexType)),
(std::vector<char>{ 0x01, 0x02, 0x03, 0x00, 0x04 })); (std::vector<char>{ 0x01, 0x02, 0x03, 0x00, 0x04 }));
delete[] data; delete[] data;
@ -54,21 +54,21 @@ void CompressIndicesTest::compressChar() {
void CompressIndicesTest::compressShort() { void CompressIndicesTest::compressShort() {
std::size_t indexCount; std::size_t indexCount;
IndexedMesh::IndexType indexType; Mesh::IndexType indexType;
char* data; char* data;
std::tie(indexCount, indexType, data) = MeshTools::compressIndices( std::tie(indexCount, indexType, data) = MeshTools::compressIndices(
std::vector<std::uint32_t>{1, 256, 0, 5}); std::vector<std::uint32_t>{1, 256, 0, 5});
CORRADE_COMPARE(indexCount, 4); CORRADE_COMPARE(indexCount, 4);
CORRADE_VERIFY(indexType == IndexedMesh::IndexType::UnsignedShort); CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedShort);
if(!Endianness::isBigEndian()) { if(!Endianness::isBigEndian()) {
CORRADE_COMPARE(std::vector<char>(data, data+indexCount*IndexedMesh::indexSize(indexType)), CORRADE_COMPARE(std::vector<char>(data, data+indexCount*Mesh::indexSize(indexType)),
(std::vector<char>{ 0x01, 0x00, (std::vector<char>{ 0x01, 0x00,
0x00, 0x01, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x05, 0x00 })); 0x05, 0x00 }));
} else { } else {
CORRADE_COMPARE(std::vector<char>(data, data+indexCount*IndexedMesh::indexSize(indexType)), CORRADE_COMPARE(std::vector<char>(data, data+indexCount*Mesh::indexSize(indexType)),
(std::vector<char>{ 0x00, 0x01, (std::vector<char>{ 0x00, 0x01,
0x01, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00,
@ -80,21 +80,21 @@ void CompressIndicesTest::compressShort() {
void CompressIndicesTest::compressInt() { void CompressIndicesTest::compressInt() {
std::size_t indexCount; std::size_t indexCount;
IndexedMesh::IndexType indexType; Mesh::IndexType indexType;
char* data; char* data;
std::tie(indexCount, indexType, data) = MeshTools::compressIndices( std::tie(indexCount, indexType, data) = MeshTools::compressIndices(
std::vector<std::uint32_t>{65536, 3, 2}); std::vector<std::uint32_t>{65536, 3, 2});
CORRADE_COMPARE(indexCount, 3); CORRADE_COMPARE(indexCount, 3);
CORRADE_VERIFY(indexType == IndexedMesh::IndexType::UnsignedInt); CORRADE_VERIFY(indexType == Mesh::IndexType::UnsignedInt);
if(!Endianness::isBigEndian()) { if(!Endianness::isBigEndian()) {
CORRADE_COMPARE(std::vector<char>(data, data+indexCount*IndexedMesh::indexSize(indexType)), CORRADE_COMPARE(std::vector<char>(data, data+indexCount*Mesh::indexSize(indexType)),
(std::vector<char>{ 0x00, 0x00, 0x01, 0x00, (std::vector<char>{ 0x00, 0x00, 0x01, 0x00,
0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00 })); 0x02, 0x00, 0x00, 0x00 }));
} else { } else {
CORRADE_COMPARE(std::vector<char>(data, data+indexCount*IndexedMesh::indexSize(indexType)), CORRADE_COMPARE(std::vector<char>(data, data+indexCount*Mesh::indexSize(indexType)),
(std::vector<char>{ 0x00, 0x01, 0x00, 0x00, (std::vector<char>{ 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x02 })); 0x00, 0x00, 0x00, 0x02 }));

9
src/Text/TextRenderer.cpp

@ -20,7 +20,6 @@
#include "Math/Point2D.h" #include "Math/Point2D.h"
#include "Math/Point3D.h" #include "Math/Point3D.h"
#include "IndexedMesh.h"
#include "Swizzle.h" #include "Swizzle.h"
#include "MeshTools/CompressIndices.h" #include "MeshTools/CompressIndices.h"
#include "MeshTools/Interleave.h" #include "MeshTools/Interleave.h"
@ -139,8 +138,8 @@ template<std::uint8_t dimensions> std::tuple<std::vector<typename DimensionTrait
return std::make_tuple(std::move(positionsXD), std::move(textureCoordinates), std::move(indices)); return std::make_tuple(std::move(positionsXD), std::move(textureCoordinates), std::move(indices));
} }
template<std::uint8_t dimensions> IndexedMesh TextRenderer<dimensions>::render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) { template<std::uint8_t dimensions> Mesh TextRenderer<dimensions>::render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage) {
IndexedMesh mesh; Mesh mesh;
std::vector<typename DimensionTraits<dimensions>::PointType> positions; std::vector<typename DimensionTraits<dimensions>::PointType> positions;
std::vector<Vector2> textureCoordinates; std::vector<Vector2> textureCoordinates;
@ -150,7 +149,9 @@ template<std::uint8_t dimensions> IndexedMesh TextRenderer<dimensions>::render(F
MeshTools::interleave(&mesh, vertexBuffer, usage, positions, textureCoordinates); MeshTools::interleave(&mesh, vertexBuffer, usage, positions, textureCoordinates);
MeshTools::compressIndices(&mesh, indexBuffer, usage, indices); MeshTools::compressIndices(&mesh, indexBuffer, usage, indices);
mesh.setPrimitive(Mesh::Primitive::Triangles) mesh.setPrimitive(Mesh::Primitive::Triangles)
->addInterleavedVertexBuffer(vertexBuffer, 0, typename Shaders::AbstractTextShader<dimensions>::Position(), typename Shaders::AbstractTextShader<dimensions>::TextureCoordinates()); ->addInterleavedVertexBuffer(vertexBuffer, 0,
typename Shaders::AbstractTextShader<dimensions>::Position(),
typename Shaders::AbstractTextShader<dimensions>::TextureCoordinates());
return mesh; return mesh;
} }

2
src/Text/TextRenderer.h

@ -62,7 +62,7 @@ template<std::uint8_t dimensions> class MAGNUM_TEXT_EXPORT TextRenderer {
* @return Indexed mesh prepared for use with Shaders::AbstractTextShader * @return Indexed mesh prepared for use with Shaders::AbstractTextShader
* subclasses * subclasses
*/ */
static IndexedMesh render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage); static Mesh render(Font& font, GLfloat size, const std::string& text, Buffer* vertexBuffer, Buffer* indexBuffer, Buffer::Usage usage);
private: private:
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT

Loading…
Cancel
Save