|
|
|
|
@ -43,10 +43,10 @@ namespace Magnum {
|
|
|
|
|
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 addInterleavedVertexBuffer(). You can also |
|
|
|
|
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 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 |
|
|
|
|
@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
|
|
|
|
|
mesh.setPrimitive(Mesh::Primitive::Triangles) |
|
|
|
|
.setVertexCount(30) |
|
|
|
|
.addInterleavedVertexBuffer(vertexBuffer, 0, MyShader::Position()); |
|
|
|
|
.addVertexBuffer(vertexBuffer, 0, MyShader::Position()); |
|
|
|
|
@endcode |
|
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
// has been already set by MeshTools::interleave()
|
|
|
|
|
mesh.setPrimitive(plane.primitive()) |
|
|
|
|
.addInterleavedVertexBuffer(buffer, 0, Shaders::Phong::Position(), Shaders::Phong::Normal()); |
|
|
|
|
.addVertexBuffer(buffer, 0, Shaders::Phong::Position(), Shaders::Phong::Normal()); |
|
|
|
|
@endcode |
|
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
mesh.setPrimitive(Mesh::Primitive::Triangles) |
|
|
|
|
.setIndexCount(75) |
|
|
|
|
.addInterleavedVertexBuffer(vertexBuffer, 0, MyShader::Position()) |
|
|
|
|
.addVertexBuffer(vertexBuffer, 0, MyShader::Position()) |
|
|
|
|
.setIndexBuffer(indexBuffer, 0, Mesh::IndexType::UnsignedByte, 176, 229); |
|
|
|
|
@endcode |
|
|
|
|
|
|
|
|
|
@ -158,7 +158,7 @@ MeshTools::compressIndices(mesh, indexBuffer, Buffer::Usage::StaticDraw,
|
|
|
|
|
// Set primitive and specify layout of interleaved vertex buffer. Index count
|
|
|
|
|
// and index buffer has been already specified by MeshTools::compressIndices().
|
|
|
|
|
mesh.setPrimitive(plane.primitive()) |
|
|
|
|
.addInterleavedVertexBuffer(vertexBuffer, 0, Shaders::Phong::Position(), Shaders::Phong::Normal()); |
|
|
|
|
.addVertexBuffer(vertexBuffer, 0, Shaders::Phong::Position(), Shaders::Phong::Normal()); |
|
|
|
|
@endcode |
|
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
// component will be automatically set to 0
|
|
|
|
|
mesh.addInterleavedVertexBuffer(positionBuffer, 0, |
|
|
|
|
mesh.addVertexBuffer(positionBuffer, 0, |
|
|
|
|
MyShader::Position(MyShader::Position::Components::Two)); |
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
// 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::DataType::UnsignedByte, |
|
|
|
|
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, |
|
|
|
|
DSA functions are used for specifying attribute locations to avoid unnecessary |
|
|
|
|
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 |
|
|
|
|
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) |
|
|
|
|
* |
|
|
|
|
* Default is @ref Primitive::Triangles. |
|
|
|
|
* @see @ref setVertexCount(), @ref addInterleavedVertexBuffer() |
|
|
|
|
* @see @ref setVertexCount(), @ref addVertexBuffer() |
|
|
|
|
*/ |
|
|
|
|
Mesh& setPrimitive(Primitive primitive) { |
|
|
|
|
_primitive = primitive; |
|
|
|
|
@ -393,7 +393,7 @@ class MAGNUM_EXPORT Mesh {
|
|
|
|
|
* @return Reference to self (for method chaining) |
|
|
|
|
* |
|
|
|
|
* Default is zero. |
|
|
|
|
* @see setPrimitive(), addInterleavedVertexBuffer(), MeshTools::interleave() |
|
|
|
|
* @see setPrimitive(), addVertexBuffer(), MeshTools::interleave() |
|
|
|
|
*/ |
|
|
|
|
Mesh& setVertexCount(Int vertexCount) { |
|
|
|
|
_vertexCount = vertexCount; |
|
|
|
|
@ -435,20 +435,20 @@ class MAGNUM_EXPORT Mesh {
|
|
|
|
|
* @code |
|
|
|
|
Buffer buffer; |
|
|
|
|
Mesh mesh; |
|
|
|
|
mesh.addInterleavedVertexBuffer(buffer, 76, // initial array offset
|
|
|
|
|
mesh.addVertexBuffer(buffer, 76, // initial array offset
|
|
|
|
|
4, // skip vertex weight (Float)
|
|
|
|
|
Shaders::Phong::Position(), // vertex position
|
|
|
|
|
8, // skip texture coordinates (Vector2)
|
|
|
|
|
Shaders::Phong::Normal()); // vertex normal
|
|
|
|
|
@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 |
|
|
|
|
* attributes. This can be used for e.g. runtime-dependent |
|
|
|
|
* configuration, as it isn't dependent on the variadic template: |
|
|
|
|
@code |
|
|
|
|
mesh.addInterleavedVertexBuffer(buffer, 76, 4, Shaders::Phong::Position(), 20) |
|
|
|
|
.addInterleavedVertexBuffer(buffer, 76, 24, Shaders::Phong::Normal(), 0); |
|
|
|
|
mesh.addVertexBuffer(buffer, 76, 4, Shaders::Phong::Position(), 20) |
|
|
|
|
.addVertexBuffer(buffer, 76, 24, Shaders::Phong::Normal(), 0); |
|
|
|
|
@endcode |
|
|
|
|
* |
|
|
|
|
* If specifying more than one attribute, the function assumes that |
|
|
|
|
@ -458,8 +458,8 @@ class MAGNUM_EXPORT Mesh {
|
|
|
|
|
* arrays one after another (non-interleaved): |
|
|
|
|
@code |
|
|
|
|
Int vertexCount = 352; |
|
|
|
|
mesh.addInterleavedVertexBuffer(buffer, 76 + 4*vertexCount, Shaders::Phong::Position()) |
|
|
|
|
.addInterleavedVertexBuffer(buffer, 76 + 24*vertexCount, Shaders::Phong::Normal()); |
|
|
|
|
mesh.addVertexBuffer(buffer, 76 + 4*vertexCount, Shaders::Phong::Position()) |
|
|
|
|
.addVertexBuffer(buffer, 76 + 24*vertexCount, Shaders::Phong::Normal()); |
|
|
|
|
@endcode |
|
|
|
|
* |
|
|
|
|
* @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 |
|
|
|
|
* @todoc Add back the *s when Doxygen is sane again |
|
|
|
|
*/ |
|
|
|
|
template<class ...T> inline Mesh& addInterleavedVertexBuffer(Buffer& buffer, GLintptr offset, const T&... attributes) { |
|
|
|
|
addInterleavedVertexBufferInternal(buffer, offset, strideOfInterleaved(attributes...), attributes...); |
|
|
|
|
template<class ...T> inline Mesh& addVertexBuffer(Buffer& buffer, GLintptr offset, const T&... attributes) { |
|
|
|
|
addVertexBufferInternal(buffer, offset, strideOfInterleaved(attributes...), attributes...); |
|
|
|
|
return *this; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -584,17 +584,17 @@ class MAGNUM_EXPORT Mesh {
|
|
|
|
|
inline static GLsizei strideOfInterleaved() { return 0; } |
|
|
|
|
|
|
|
|
|
/* 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); |
|
|
|
|
|
|
|
|
|
/* 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 */ |
|
|
|
|
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) { |
|
|
|
|
for(UnsignedInt i = 0; i != Implementation::Attribute<T>::vectorCount(); ++i) |
|
|
|
|
|