Magnum::GL::MeshView class

Mesh view.

Allows different interpretation of given Mesh data via different vertex or index count and offset. It is then possible to reuse one mesh buffer configuration for different views. Mesh primitive, index type, attribute bindings and attached buffers are reused from original mesh.

The same rules as in Mesh apply, i.e. if the view 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 view is treated as empty and no draw commands are issued when calling draw().

You must ensure that the original mesh remains available for whole view lifetime.

Public static functions

static void draw(AbstractShaderProgram& shader, std::initializer_list<std::reference_wrapper<MeshView>> meshes)
Draw multiple meshes at once.
static void draw(AbstractShaderProgram&& shader, std::initializer_list<std::reference_wrapper<MeshView>> meshes)

Constructors, destructors, conversion operators

MeshView(Mesh& original) explicit
Constructor.
MeshView(const MeshView& other) defaulted
Copy constructor.
MeshView(MeshView&& other) deleted
Movement is not allowed.

Public functions

auto operator=(const MeshView&) -> MeshView& defaulted
Copy assignment.
auto operator=(MeshView&& other) -> MeshView& deleted
Movement is not allowed.
auto mesh() -> Mesh&
Original mesh.
auto mesh() const -> const Mesh&
auto count() const -> Int
Vertex/index count.
auto setCount(Int count) -> MeshView&
Set vertex/index count.
auto baseVertex() const -> Int
Base vertex.
auto setBaseVertex(Int baseVertex) -> MeshView&
Set base vertex.
auto setIndexRange(Int first, UnsignedInt start, UnsignedInt end) -> MeshView&
Set index range.
auto setIndexRange(Int first) -> MeshView&
Set index range.
auto instanceCount() const -> Int
Instance count.
auto setInstanceCount(Int count) -> MeshView&
Set instance count.
auto baseInstance() const -> UnsignedInt
Base instance.
auto setBaseInstance(UnsignedInt baseInstance) -> MeshView&
Set base instance.
auto draw(AbstractShaderProgram& shader) -> MeshView&
Draw the mesh.
auto draw(AbstractShaderProgram&& shader) -> MeshView&
auto draw(AbstractShaderProgram& shader, TransformFeedback& xfb, UnsignedInt stream = 0) -> MeshView&
Draw the mesh with vertices coming out of transform feedback.
auto draw(AbstractShaderProgram&& shader, TransformFeedback& xfb, UnsignedInt stream = 0) -> MeshView&

Function documentation

static void Magnum::GL::MeshView::draw(AbstractShaderProgram& shader, std::initializer_list<std::reference_wrapper<MeshView>> meshes)

Draw multiple meshes at once.

In OpenGL ES, if EXT_multi_draw_arrays is not present, the functionality is emulated using sequence of draw(AbstractShaderProgram&) calls.

If ARB_vertex_array_object (part of OpenGL 3.0), OpenGL ES 3.0, WebGL 2.0, OES_vertex_array_object in OpenGL ES 2.0 or OES_vertex_array_object in WebGL 1.0 is available, the associated vertex array object is bound instead of setting up the mesh from scratch.

static void Magnum::GL::MeshView::draw(AbstractShaderProgram&& shader, std::initializer_list<std::reference_wrapper<MeshView>> meshes)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Magnum::GL::MeshView::MeshView(Mesh& original) explicit

Constructor.

Parameters
original Original, already configured mesh

const Mesh& Magnum::GL::MeshView::mesh() const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

MeshView& Magnum::GL::MeshView::setCount(Int count)

Set vertex/index count.

Returns Reference to self (for method chaining)

Ignored when calling draw(AbstractShaderProgram&, TransformFeedback&, UnsignedInt).

MeshView& Magnum::GL::MeshView::setBaseVertex(Int baseVertex)

Set base vertex.

Returns Reference to self (for method chaining)

Sets number of vertices of which the vertex buffer will be offset when drawing. Ignored when calling draw(AbstractShaderProgram&, TransformFeedback&, UnsignedInt). Default is 0.

MeshView& Magnum::GL::MeshView::setIndexRange(Int first, UnsignedInt start, UnsignedInt end)

Set index range.

Parameters
first First vertex
start Minimum array index contained in the buffer
end Maximum array index contained in the buffer
Returns Reference to self (for method chaining)

The start and end parameters may help to improve memory access performance, as only a portion of vertex buffer needs to be acccessed. On OpenGL ES 2.0 this function behaves the same as setIndexRange(Int), as index range functionality is not available there. Ignored when calling draw(AbstractShaderProgram&, TransformFeedback&, UnsignedInt).

Expects that the original mesh is indexed.

MeshView& Magnum::GL::MeshView::setIndexRange(Int first)

Set index range.

Parameters
first First index
Returns Reference to self (for method chaining)

Prefer to use setIndexRange(Int, UnsignedInt, UnsignedInt) for better performance. Ignored when calling draw(AbstractShaderProgram&, TransformFeedback&, UnsignedInt).

Expects that the original mesh is indexed.

MeshView& Magnum::GL::MeshView::setBaseInstance(UnsignedInt baseInstance)

Set base instance.

Returns Reference to self (for method chaining)

Ignored when calling draw(AbstractShaderProgram&, TransformFeedback&, UnsignedInt). Default is 0.

MeshView& Magnum::GL::MeshView::draw(AbstractShaderProgram& shader)

Draw the mesh.

Returns Reference to self (for method chaining)

See Mesh::draw(AbstractShaderProgram&) for more information.

MeshView& Magnum::GL::MeshView::draw(AbstractShaderProgram&& shader)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

MeshView& Magnum::GL::MeshView::draw(AbstractShaderProgram& shader, TransformFeedback& xfb, UnsignedInt stream = 0)

Draw the mesh with vertices coming out of transform feedback.

Returns Reference to self (for method chaining)

Everything set by setCount(), setBaseInstance(), setBaseVertex(), setIndexRange() and Mesh::setIndexBuffer() is ignored, the mesh is drawn as non-indexed and the vertex count is taken from the xfb object. See Mesh::draw(AbstractShaderProgram&, TransformFeedback&, UnsignedInt) for more information.

MeshView& Magnum::GL::MeshView::draw(AbstractShaderProgram&& shader, TransformFeedback& xfb, UnsignedInt stream = 0)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.