Magnum::Shaders::MeshVisualizer2D class new in 2020.06

2D mesh visualization shader

Visualizes wireframe, per-vertex/per-instance object ID or primitive ID of 2D meshes. You need to provide the Position attribute in your triangle mesh. Use setTransformationProjectionMatrix(), setColor() and others to configure the shader.

Image
Image

The shader expects that you enable wireframe visualization by passing an appropriate Flag to the constructor — there's no default behavior with nothing enabled. The shader is a 2D variant of MeshVisualizer3D with mostly identical workflow. See its documentation for more information.

Public types

enum (anonymous): UnsignedInt { ColorOutput = Generic2D::ColorOutput }
enum class Flag: UnsignedShort { Wireframe = 1 << 0, NoGeometryShader = 1 << 1, InstancedObjectId = 1 << 2 new in 2020.06, VertexId = 1 << 3 new in 2020.06, PrimitiveId = 1 << 4 new in 2020.06, PrimitiveIdFromVertexId = (1 << 5)|PrimitiveId new in 2020.06 }
Flag.
using Position = Generic2D::Position
Vertex position.
using VertexIndex = GL::Attribute<4, Float>
Vertex index.
using ObjectId = Generic3D::ObjectId new in 2020.06
(Instanced) object ID
using Flags = Containers::EnumSet<Flag>
Flags.

Constructors, destructors, conversion operators

MeshVisualizer2D(Flags flags) explicit
Constructor.
MeshVisualizer2D(NoCreateT) explicit noexcept
Construct without creating the underlying OpenGL object.
MeshVisualizer2D(const MeshVisualizer2D&) deleted
Copying is not allowed.
MeshVisualizer2D(MeshVisualizer2D&&) defaulted noexcept
Move constructor.

Public functions

auto operator=(const MeshVisualizer2D&) -> MeshVisualizer2D& deleted
Copying is not allowed.
auto operator=(MeshVisualizer2D&&) -> MeshVisualizer2D& defaulted noexcept
Move assignment.
auto flags() const -> Flags
Flags.
auto setTransformationProjectionMatrix(const Matrix3& matrix) -> MeshVisualizer2D&
Set transformation and projection matrix.
auto setViewportSize(const Vector2& size) -> MeshVisualizer2D&
Set viewport size.
auto setColor(const Color4& color) -> MeshVisualizer2D&
Set base object color.
auto setWireframeColor(const Color4& color) -> MeshVisualizer2D&
Set wireframe color.
auto setWireframeWidth(Float width) -> MeshVisualizer2D&
Set wireframe width.
auto setColorMapTransformation(Float offset, Float scale) -> MeshVisualizer2D& new in 2020.06
Set color map transformation.
auto bindColorMapTexture(GL::Texture2D& texture) -> MeshVisualizer2D& new in 2020.06
Bind a color map texture.
auto setSmoothness(Float smoothness) -> MeshVisualizer2D&
Set line smoothness.

Enum documentation

enum Magnum::Shaders::MeshVisualizer2D::(anonymous): UnsignedInt

Enumerators
ColorOutput

Color shader output. Generic output, present always. Expects three- or four-component floating-point or normalized buffer attachment.

enum class Magnum::Shaders::MeshVisualizer2D::Flag: UnsignedShort

Flag.

Enumerators
Wireframe

Visualize wireframe. On OpenGL ES 2.0 and WebGL this also enables Flag::NoGeometryShader.

NoGeometryShader

Don't use a geometry shader for wireframe visualization. If enabled, you might need to provide also the VertexIndex attribute in the mesh. On OpenGL ES 2.0 and WebGL enabled alongside Flag::Wireframe.

InstancedObjectId new in 2020.06

Visualize instanced object ID. You need to provide the ObjectId attribute in the mesh. Mutually exclusive with Flag::VertexId and Flag::PrimitiveId.

VertexId new in 2020.06

Visualize vertex ID (gl_VertexID). Useful for visualizing mesh connectivity — primitives sharing vertices will have a smooth color map transition while duplicated vertices will cause a sharp edge. Mutually exclusive with Flag::InstancedObjectId and Flag::PrimitiveId.

PrimitiveId new in 2020.06

Visualize primitive ID (gl_PrimitiveID). Useful for visualizing how well is the mesh optimized for a post-transform vertex cache. Mutually exclusive with Flag::InstancedObjectId and Flag::VertexId. See also Flag::PrimitiveIdFromVertexId.

PrimitiveIdFromVertexId new in 2020.06

Visualize primitive ID on a non-indexed triangle mesh using gl_VertexID/3. Implicitly enables Flag::PrimitiveId, mutually exclusive with Flag::InstancedObjectId. Usable on OpenGL < 3.2, OpenGL ES < 3.2 and WebGL where gl_PrimitiveID is not available.

Typedef documentation

typedef Generic2D::Position Magnum::Shaders::MeshVisualizer2D::Position

Vertex position.

Generic attribute, Vector2.

typedef GL::Attribute<4, Float> Magnum::Shaders::MeshVisualizer2D::VertexIndex

Vertex index.

See MeshVisualizer3D::VertexIndex for more information.

typedef Generic3D::ObjectId Magnum::Shaders::MeshVisualizer2D::ObjectId new in 2020.06

(Instanced) object ID

Generic attribute, Magnum::UnsignedInt. Used only if Flag::InstancedObjectId is set.

Function documentation

Magnum::Shaders::MeshVisualizer2D::MeshVisualizer2D(Flags flags) explicit

Constructor.

Parameters
flags Flags

At least Flag::Wireframe is expected to be enabled.

Magnum::Shaders::MeshVisualizer2D::MeshVisualizer2D(NoCreateT) explicit noexcept

Construct without creating the underlying OpenGL object.

The constructed instance is equivalent to a moved-from state. Useful in cases where you will overwrite the instance later anyway. Move another object over it to make it useful.

This function can be safely used for constructing (and later destructing) objects even without any OpenGL context being active. However note that this is a low-level and a potentially dangerous API, see the documentation of NoCreate for alternatives.

MeshVisualizer2D& Magnum::Shaders::MeshVisualizer2D::setTransformationProjectionMatrix(const Matrix3& matrix)

Set transformation and projection matrix.

Returns Reference to self (for method chaining)

Initial value is an identity matrix.

MeshVisualizer2D& Magnum::Shaders::MeshVisualizer2D::setViewportSize(const Vector2& size)

Set viewport size.

Returns Reference to self (for method chaining)

Has effect only if Flag::Wireframe is enabled and geometry shaders are used, otherwise it does nothing. Initial value is a zero vector.

MeshVisualizer2D& Magnum::Shaders::MeshVisualizer2D::setColor(const Color4& color)

Set base object color.

Returns Reference to self (for method chaining)

Initial value is 0xffffffff_rgbaf. Expects that either Flag::Wireframe or Flag::InstancedObjectId / Flag::PrimitiveId is enabled. In case of the latter, the color is multiplied with the color map coming from bindColorMapTexture().

MeshVisualizer2D& Magnum::Shaders::MeshVisualizer2D::setWireframeColor(const Color4& color)

Set wireframe color.

Returns Reference to self (for method chaining)

Initial value is 0x000000ff_rgbaf. Expects that Flag::Wireframe is enabled.

MeshVisualizer2D& Magnum::Shaders::MeshVisualizer2D::setWireframeWidth(Float width)

Set wireframe width.

Returns Reference to self (for method chaining)

Value is in screen space (depending on setViewportSize()), initial value is 1.0f. Expects that Flag::Wireframe is enabled.

MeshVisualizer2D& Magnum::Shaders::MeshVisualizer2D::setColorMapTransformation(Float offset, Float scale) new in 2020.06

Set color map transformation.

Returns Reference to self (for method chaining)

Offset and scale applied to the input value coming either from the ObjectId attribute or gl_PrimitiveID, resulting value is then used to fetch a color from a color map bound with bindColorMapTexture(). Initial value is 1.0f/512.0f and 1.0/256.0f, meaning that for a 256-entry colormap the first 256 values get an exact color from it and the next values will be either clamped to last color or repeated depending on the color map texture wrapping mode. Expects that either Flag::InstancedObjectId or Flag::PrimitiveId / Flag::PrimitiveIdFromVertexId is enabled.

Note that this shader doesn't directly offer a setObjectId() uniform that's used to offset the per-vertex / per-instance ID. Instead, you need to encode the base offset into the offset parameter.

MeshVisualizer2D& Magnum::Shaders::MeshVisualizer2D::bindColorMapTexture(GL::Texture2D& texture) new in 2020.06

Bind a color map texture.

Returns Reference to self (for method chaining)

See also setColorMapTransformation(). Expects that either Flag::InstancedObjectId or Flag::PrimitiveId / Flag::PrimitiveIdFromVertexId is enabled.

MeshVisualizer2D& Magnum::Shaders::MeshVisualizer2D::setSmoothness(Float smoothness)

Set line smoothness.

Returns Reference to self (for method chaining)

Value is in screen space (depending on setViewportSize()), initial value is 2.0f. Expects that Flag::Wireframe is enabled.

Debug& operator<<(Debug& debug, MeshVisualizer2D::Flag value)

Debug output operator.

Debug& operator<<(Debug& debug, MeshVisualizer2D::Flags value)

Debug output operator.