Browse Source

Renamed Mesh::addInterleavedVertexBuffer() to addVertexBuffer().

Obvious change after previous commit, there is no other function
alternative to distinguish it from.
pull/23/head
Vladimír Vondruš 13 years ago
parent
commit
5ad5ab2c5a
  1. 2
      src/DebugTools/ForceRenderer.cpp
  2. 4
      src/DebugTools/Implementation/AbstractShapeRenderer.cpp
  3. 2
      src/DebugTools/ObjectRenderer.cpp
  4. 48
      src/Mesh.h
  5. 2
      src/MeshTools/FullScreenTriangle.cpp
  6. 4
      src/Text/TextRenderer.cpp
  7. 2
      src/TextureTools/DistanceField.cpp

2
src/DebugTools/ForceRenderer.cpp

@ -88,7 +88,7 @@ template<UnsignedInt dimensions> ForceRenderer<dimensions>::ForceRenderer(SceneG
Mesh* mesh = new Mesh; Mesh* mesh = new Mesh;
mesh->setPrimitive(Mesh::Primitive::Lines) mesh->setPrimitive(Mesh::Primitive::Lines)
.setIndexCount(indices.size()) .setIndexCount(indices.size())
.addInterleavedVertexBuffer(*vertexBuffer, 0, .addVertexBuffer(*vertexBuffer, 0,
typename Shaders::Flat<dimensions>::Position(Shaders::Flat<dimensions>::Position::Components::Two)) typename Shaders::Flat<dimensions>::Position(Shaders::Flat<dimensions>::Position::Components::Two))
.setIndexBuffer(*indexBuffer, 0, Mesh::IndexType::UnsignedByte, 0, positions.size()); .setIndexBuffer(*indexBuffer, 0, Mesh::IndexType::UnsignedByte, 0, positions.size());
ResourceManager::instance().set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); ResourceManager::instance().set(this->mesh.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual);

4
src/DebugTools/Implementation/AbstractShapeRenderer.cpp

@ -53,7 +53,7 @@ template<> void create<2>(Trade::MeshData2D& data, Resource<Mesh>& meshResource,
Mesh* mesh = new Mesh; Mesh* mesh = new Mesh;
mesh->setPrimitive(data.primitive()) mesh->setPrimitive(data.primitive())
.setVertexCount(data.positions(0).size()) .setVertexCount(data.positions(0).size())
.addInterleavedVertexBuffer(*buffer, 0, Shaders::Flat2D::Position()); .addVertexBuffer(*buffer, 0, Shaders::Flat2D::Position());
ResourceManager::instance().set(meshResource.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); ResourceManager::instance().set(meshResource.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual);
/* Index buffer, if needed, if not, resource key doesn't have to be set */ /* Index buffer, if needed, if not, resource key doesn't have to be set */
@ -75,7 +75,7 @@ template<> void create<3>(Trade::MeshData3D& data, Resource<Mesh>& meshResource,
Mesh* mesh = new Mesh; Mesh* mesh = new Mesh;
mesh->setPrimitive(data.primitive()) mesh->setPrimitive(data.primitive())
.setVertexCount(data.positions(0).size()) .setVertexCount(data.positions(0).size())
.addInterleavedVertexBuffer(*vertexBuffer, 0, Shaders::Flat3D::Position()); .addVertexBuffer(*vertexBuffer, 0, Shaders::Flat3D::Position());
ResourceManager::instance().set(meshResource.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual); ResourceManager::instance().set(meshResource.key(), mesh, ResourceDataState::Final, ResourcePolicy::Manual);
/* Index buffer, if needed, if not, resource key doesn't have to be set */ /* Index buffer, if needed, if not, resource key doesn't have to be set */

2
src/DebugTools/ObjectRenderer.cpp

@ -166,7 +166,7 @@ template<UnsignedInt dimensions> ObjectRenderer<dimensions>::ObjectRenderer(Scen
mesh->setPrimitive(Mesh::Primitive::Lines) mesh->setPrimitive(Mesh::Primitive::Lines)
.setIndexCount(Renderer<dimensions>::indices.size()) .setIndexCount(Renderer<dimensions>::indices.size())
.addInterleavedVertexBuffer(*vertexBuffer, 0, .addVertexBuffer(*vertexBuffer, 0,
typename Shaders::VertexColor<dimensions>::Position(), typename Shaders::VertexColor<dimensions>::Position(),
typename Shaders::VertexColor<dimensions>::Color()) typename Shaders::VertexColor<dimensions>::Color())
.setIndexBuffer(*indexBuffer, 0, Mesh::IndexType::UnsignedByte, 0, Renderer<dimensions>::positions.size()); .setIndexBuffer(*indexBuffer, 0, Mesh::IndexType::UnsignedByte, 0, Renderer<dimensions>::positions.size());

48
src/Mesh.h

@ -43,10 +43,10 @@ namespace Magnum {
You have to specify at least primitive and vertex count using @ref setPrimitive() 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 and @ref setVertexCount(). Then fill your vertex buffers with data, add them to
the mesh and specify @ref AbstractShaderProgram::Attribute "shader attribute" the mesh and specify @ref AbstractShaderProgram::Attribute "shader attribute"
layout inside the buffers using @ref addInterleavedVertexBuffer(). You can also layout inside the buffers using @ref addVertexBuffer(). You can also
use @ref MeshTools::interleave() conveniently fill interleaved vertex buffer. use @ref MeshTools::interleave() conveniently fill interleaved vertex buffer.
The function itself calls @ref setVertexCount(), so you don't have to do it 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 addInterleavedVertexBuffer(). 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 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 @ref setVertexCount(). Then fill your index buffer with data and specify its
@ -88,7 +88,7 @@ vertexBuffer.setData(positions, Buffer::Usage::StaticDraw);
// Set primitive and vertex count, add the buffer and specify its layout // 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)
.addInterleavedVertexBuffer(vertexBuffer, 0, MyShader::Position()); .addVertexBuffer(vertexBuffer, 0, MyShader::Position());
@endcode @endcode
@subsubsection Mesh-configuration-examples-nonindexed-phong Interleaved vertex data @subsubsection Mesh-configuration-examples-nonindexed-phong Interleaved vertex data
@ -106,7 +106,7 @@ MeshTools::interleave(mesh, buffer, Buffer::Usage::StaticDraw,
// Set primitive and specify layout of interleaved vertex buffer, vertex count // Set primitive and specify layout of interleaved vertex buffer, vertex count
// has been already set by MeshTools::interleave() // has been already set by MeshTools::interleave()
mesh.setPrimitive(plane.primitive()) mesh.setPrimitive(plane.primitive())
.addInterleavedVertexBuffer(buffer, 0, Shaders::Phong::Position(), Shaders::Phong::Normal()); .addVertexBuffer(buffer, 0, Shaders::Phong::Position(), Shaders::Phong::Normal());
@endcode @endcode
@subsubsection Mesh-configuration-examples-indexed-phong Indexed mesh @subsubsection Mesh-configuration-examples-indexed-phong Indexed mesh
@ -137,7 +137,7 @@ indexBuffer.setData(indices, Buffer::Usage::StaticDraw);
// Set primitive, index count, specify the buffers // Set primitive, index count, specify the buffers
mesh.setPrimitive(Mesh::Primitive::Triangles) mesh.setPrimitive(Mesh::Primitive::Triangles)
.setIndexCount(75) .setIndexCount(75)
.addInterleavedVertexBuffer(vertexBuffer, 0, MyShader::Position()) .addVertexBuffer(vertexBuffer, 0, MyShader::Position())
.setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte, 176, 229); .setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte, 176, 229);
@endcode @endcode
@ -158,7 +158,7 @@ MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw,
// Set primitive and specify layout of interleaved vertex buffer. Index count // Set primitive and specify layout of interleaved vertex buffer. Index count
// and index buffer has been already specified by MeshTools::compressIndices(). // and index buffer has been already specified by MeshTools::compressIndices().
mesh.setPrimitive(plane.primitive()) mesh.setPrimitive(plane.primitive())
.addInterleavedVertexBuffer(vertexBuffer, 0, Shaders::Phong::Position(), Shaders::Phong::Normal()); .addVertexBuffer(vertexBuffer, 0, Shaders::Phong::Position(), Shaders::Phong::Normal());
@endcode @endcode
@subsubsection Mesh-configuration-examples-data-options Specific formats of vertex data @subsubsection Mesh-configuration-examples-data-options Specific formats of vertex data
@ -183,7 +183,7 @@ Vector2 positions[30] = {
// Specify layout of positions buffer -- only two components, unspecified Z // Specify layout of positions buffer -- only two components, unspecified Z
// component will be automatically set to 0 // component will be automatically set to 0
mesh.addInterleavedVertexBuffer(positionBuffer, 0, mesh.addVertexBuffer(positionBuffer, 0,
MyShader::Position(MyShader::Position::Components::Two)); MyShader::Position(MyShader::Position::Components::Two));
// Fill color buffer with colors specified as four-byte BGRA (e.g. directly // Fill color buffer with colors specified as four-byte BGRA (e.g. directly
@ -196,7 +196,7 @@ colorBuffer.setData(colors, Buffer::Usage::StaticDraw);
// Specify layout of color buffer -- BGRA, each component unsigned byte and we // Specify layout of color buffer -- BGRA, each component unsigned byte and we
// want to normalize them from [0, 255] to [0.0f, 1.0f] // want to normalize them from [0, 255] to [0.0f, 1.0f]
mesh.addInterleavedVertexBuffer(colorBuffer, 0, MyShader::Color( mesh.addVertexBuffer(colorBuffer, 0, MyShader::Color(
MyShader::Color::Components::BGRA, MyShader::Color::Components::BGRA,
MyShader::Color::DataType::UnsignedByte, MyShader::Color::DataType::UnsignedByte,
MyShader::Color::DataOption::Normalized)); MyShader::Color::DataOption::Normalized));
@ -220,7 +220,7 @@ unnecessary calls to @fn_gl{BindVertexArray}.
If extension @extension{EXT,direct_state_access} and VAOs are available, If extension @extension{EXT,direct_state_access} and VAOs are available,
DSA functions are used for specifying attribute locations to avoid unnecessary DSA functions are used for specifying attribute locations to avoid unnecessary
calls to @fn_gl{BindBuffer} and @fn_gl{BindVertexArray}. See documentation of calls to @fn_gl{BindBuffer} and @fn_gl{BindVertexArray}. See documentation of
@ref addInterleavedVertexBuffer() for more information. @ref addVertexBuffer() for more information.
If index range is specified in @ref setIndexBuffer(), range-based version of If index range is specified in @ref setIndexBuffer(), range-based version of
drawing commands are used on desktop OpenGL and OpenGL ES 3.0. See also drawing commands are used on desktop OpenGL and OpenGL ES 3.0. See also
@ -378,7 +378,7 @@ class MAGNUM_EXPORT Mesh {
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Default is @ref Primitive::Triangles. * Default is @ref Primitive::Triangles.
* @see @ref setVertexCount(), @ref addInterleavedVertexBuffer() * @see @ref setVertexCount(), @ref addVertexBuffer()
*/ */
Mesh& setPrimitive(Primitive primitive) { Mesh& setPrimitive(Primitive primitive) {
_primitive = primitive; _primitive = primitive;
@ -393,7 +393,7 @@ class MAGNUM_EXPORT Mesh {
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Default is zero. * Default is zero.
* @see setPrimitive(), addInterleavedVertexBuffer(), MeshTools::interleave() * @see setPrimitive(), addVertexBuffer(), MeshTools::interleave()
*/ */
Mesh& setVertexCount(Int vertexCount) { Mesh& setVertexCount(Int vertexCount) {
_vertexCount = vertexCount; _vertexCount = vertexCount;
@ -435,20 +435,20 @@ class MAGNUM_EXPORT Mesh {
* @code * @code
Buffer buffer; Buffer buffer;
Mesh mesh; Mesh mesh;
mesh.addInterleavedVertexBuffer(buffer, 76, // initial array offset mesh.addVertexBuffer(buffer, 76, // initial array offset
4, // skip vertex weight (Float) 4, // skip vertex weight (Float)
Shaders::Phong::Position(), // vertex position Shaders::Phong::Position(), // vertex position
8, // skip texture coordinates (Vector2) 8, // skip texture coordinates (Vector2)
Shaders::Phong::Normal()); // vertex normal Shaders::Phong::Normal()); // vertex normal
@endcode @endcode
* *
* You can also achieve the same effect by calling @ref addInterleavedVertexBuffer() * You can also achieve the same effect by calling @ref addVertexBuffer()
* more times with explicitly specified gaps before and after the * more times with explicitly specified gaps before and after the
* attributes. This can be used for e.g. runtime-dependent * attributes. This can be used for e.g. runtime-dependent
* configuration, as it isn't dependent on the variadic template: * configuration, as it isn't dependent on the variadic template:
@code @code
mesh.addInterleavedVertexBuffer(buffer, 76, 4, Shaders::Phong::Position(), 20) mesh.addVertexBuffer(buffer, 76, 4, Shaders::Phong::Position(), 20)
.addInterleavedVertexBuffer(buffer, 76, 24, Shaders::Phong::Normal(), 0); .addVertexBuffer(buffer, 76, 24, Shaders::Phong::Normal(), 0);
@endcode @endcode
* *
* If specifying more than one attribute, the function assumes that * If specifying more than one attribute, the function assumes that
@ -458,8 +458,8 @@ class MAGNUM_EXPORT Mesh {
* arrays one after another (non-interleaved): * arrays one after another (non-interleaved):
@code @code
Int vertexCount = 352; Int vertexCount = 352;
mesh.addInterleavedVertexBuffer(buffer, 76 + 4*vertexCount, Shaders::Phong::Position()) mesh.addVertexBuffer(buffer, 76 + 4*vertexCount, Shaders::Phong::Position())
.addInterleavedVertexBuffer(buffer, 76 + 24*vertexCount, Shaders::Phong::Normal()); .addVertexBuffer(buffer, 76 + 24*vertexCount, Shaders::Phong::Normal());
@endcode @endcode
* *
* @attention The buffer passed as parameter is not managed by the * @attention The buffer passed as parameter is not managed by the
@ -474,8 +474,8 @@ class MAGNUM_EXPORT Mesh {
* if @extension{APPLE,vertex_array_object} is available * if @extension{APPLE,vertex_array_object} is available
* @todoc Add back the *s when Doxygen is sane again * @todoc Add back the *s when Doxygen is sane again
*/ */
template<class ...T> inline Mesh& addInterleavedVertexBuffer(Buffer& buffer, GLintptr offset, const T&... attributes) { template<class ...T> inline Mesh& addVertexBuffer(Buffer& buffer, GLintptr offset, const T&... attributes) {
addInterleavedVertexBufferInternal(buffer, offset, strideOfInterleaved(attributes...), attributes...); addVertexBufferInternal(buffer, offset, strideOfInterleaved(attributes...), attributes...);
return *this; return *this;
} }
@ -584,17 +584,17 @@ class MAGNUM_EXPORT Mesh {
inline static GLsizei strideOfInterleaved() { return 0; } inline static GLsizei strideOfInterleaved() { return 0; }
/* Adding interleaved vertex attributes */ /* Adding interleaved vertex attributes */
template<UnsignedInt location, class T, class ...U> inline void addInterleavedVertexBufferInternal(Buffer& buffer, GLintptr offset, GLsizei stride, const AbstractShaderProgram::Attribute<location, T>& attribute, const U&... attributes) { template<UnsignedInt location, class T, class ...U> inline void addVertexBufferInternal(Buffer& buffer, GLintptr offset, GLsizei stride, const AbstractShaderProgram::Attribute<location, T>& attribute, const U&... attributes) {
addVertexAttribute(buffer, attribute, offset, stride); addVertexAttribute(buffer, attribute, offset, stride);
/* Add size of this attribute to offset for next attribute */ /* Add size of this attribute to offset for next attribute */
addInterleavedVertexBufferInternal(buffer, offset+attribute.dataSize(), stride, attributes...); addVertexBufferInternal(buffer, offset+attribute.dataSize(), stride, attributes...);
} }
template<class ...T> inline void addInterleavedVertexBufferInternal(Buffer& buffer, GLintptr offset, GLsizei stride, GLintptr gap, const T&... attributes) { template<class ...T> inline void addVertexBufferInternal(Buffer& buffer, GLintptr offset, GLsizei stride, GLintptr gap, const T&... attributes) {
/* Add the gap to offset for next attribute */ /* Add the gap to offset for next attribute */
addInterleavedVertexBufferInternal(buffer, offset+gap, stride, attributes...); addVertexBufferInternal(buffer, offset+gap, stride, attributes...);
} }
inline void addInterleavedVertexBufferInternal(Buffer&, GLsizei, GLintptr) {} inline void addVertexBufferInternal(Buffer&, GLsizei, GLintptr) {}
template<UnsignedInt location, class T> inline void addVertexAttribute(typename std::enable_if<std::is_same<typename Implementation::Attribute<T>::Type, Float>::value, Buffer&>::type buffer, const AbstractShaderProgram::Attribute<location, T>& attribute, GLintptr offset, GLsizei stride) { template<UnsignedInt location, class T> inline void addVertexAttribute(typename std::enable_if<std::is_same<typename Implementation::Attribute<T>::Type, Float>::value, Buffer&>::type buffer, const AbstractShaderProgram::Attribute<location, T>& attribute, GLintptr offset, GLsizei stride) {
for(UnsignedInt i = 0; i != Implementation::Attribute<T>::vectorCount(); ++i) for(UnsignedInt i = 0; i != Implementation::Attribute<T>::vectorCount(); ++i)

2
src/MeshTools/FullScreenTriangle.cpp

@ -53,7 +53,7 @@ std::pair<Buffer*, Mesh> fullScreenTriangle() {
buffer->setData(triangle, Buffer::Usage::StaticDraw); buffer->setData(triangle, Buffer::Usage::StaticDraw);
/** @todo Is it possible to attach moveable buffer here to avoid heap /** @todo Is it possible to attach moveable buffer here to avoid heap
allocation? OTOH this is more effective in most (modern) cases */ allocation? OTOH this is more effective in most (modern) cases */
mesh.addInterleavedVertexBuffer(*buffer, 0, AbstractShaderProgram::Attribute<0, Vector2>()); mesh.addVertexBuffer(*buffer, 0, AbstractShaderProgram::Attribute<0, Vector2>());
} }
return {std::move(buffer), std::move(mesh)}; return {std::move(buffer), std::move(mesh)};

4
src/Text/TextRenderer.cpp

@ -198,7 +198,7 @@ template<UnsignedInt dimensions> std::tuple<Mesh, Rectangle> TextRenderer<dimens
/* Finalize mesh configuration and return the result */ /* Finalize mesh configuration and return the result */
auto r = AbstractTextRenderer::render(font, cache, size, text, vertexBuffer, indexBuffer, usage); auto r = AbstractTextRenderer::render(font, cache, size, text, vertexBuffer, indexBuffer, usage);
Mesh& mesh = std::get<0>(r); Mesh& mesh = std::get<0>(r);
mesh.addInterleavedVertexBuffer(vertexBuffer, 0, mesh.addVertexBuffer(vertexBuffer, 0,
typename Shaders::AbstractVector<dimensions>::Position( typename Shaders::AbstractVector<dimensions>::Position(
Shaders::AbstractVector<dimensions>::Position::Components::Two), Shaders::AbstractVector<dimensions>::Position::Components::Two),
typename Shaders::AbstractVector<dimensions>::TextureCoordinates()); typename Shaders::AbstractVector<dimensions>::TextureCoordinates());
@ -266,7 +266,7 @@ AbstractTextRenderer::~AbstractTextRenderer() {}
template<UnsignedInt dimensions> TextRenderer<dimensions>::TextRenderer(AbstractFont& font, const GlyphCache& cache, const Float size): AbstractTextRenderer(font, cache, size) { template<UnsignedInt dimensions> TextRenderer<dimensions>::TextRenderer(AbstractFont& font, const GlyphCache& cache, const Float size): AbstractTextRenderer(font, cache, size) {
/* Finalize mesh configuration */ /* Finalize mesh configuration */
_mesh.addInterleavedVertexBuffer(_vertexBuffer, 0, _mesh.addVertexBuffer(_vertexBuffer, 0,
typename Shaders::AbstractVector<dimensions>::Position(Shaders::AbstractVector<dimensions>::Position::Components::Two), typename Shaders::AbstractVector<dimensions>::Position(Shaders::AbstractVector<dimensions>::Position::Components::Two),
typename Shaders::AbstractVector<dimensions>::TextureCoordinates()); typename Shaders::AbstractVector<dimensions>::TextureCoordinates());
} }

2
src/TextureTools/DistanceField.cpp

@ -190,7 +190,7 @@ void distanceField(Texture2D& input, Texture2D& output, const Rectanglei& rectan
Vector2( 3.0, 1.0) Vector2( 3.0, 1.0)
}; };
buffer.setData(triangle, Buffer::Usage::StaticDraw); buffer.setData(triangle, Buffer::Usage::StaticDraw);
mesh.addInterleavedVertexBuffer(buffer, 0, DistanceFieldShader::Position()); mesh.addVertexBuffer(buffer, 0, DistanceFieldShader::Position());
} }
/* Draw the mesh */ /* Draw the mesh */

Loading…
Cancel
Save