ImFusion SDK 4.3
LineRenderer Class Reference

#include <ImFusion/Core/GL/LineRenderer.h>

Convenience class for a shader implementing thick and stippled line rendering. More...

+ Inheritance diagram for LineRenderer:

Detailed Description

Convenience class for a shader implementing thick and stippled line rendering.

LineRenderer is a stateless object which you can use to render high-quality lines with custom width and stipple pattern. The rendering is configured by passing an Options instance to the render function. The default usage is to call one of renderLines(), renderLineStrip() or renderLineLoop() with a set of vertices in world space:

// renders a 3px wide red line strip consisting of *verticesWorld* using the given view state
GL::LineRenderer::Options(vec4(1, 0, 0), 3),
view.state(),
view.orderIndependentTransparency());
static LineRenderer & cachedInstance()
Definition InstanceManager.h:80
void renderLineStrip(const std::vector< vec3 > &vertices, const Options &options, const ViewState &viewState, const OrderIndependentTransparency *oit=nullptr)
Renders a connected line strip of the given vertices.
Helper struct to encapsulate all supported rendering options.
Definition LineRenderer.h:59

If your geometry is static you can optimize your render loop by calling makeVertexData() once to write the vertex data into a VBO of your choice, and then only call render() inside the render loop.

This class inherits from GL::InstanceManager so that you can request a cached instance of it from any valid OpenGL context to save on resources.

Note
The functionality partially overlaps with FixedFunctionPipeline since both can render thick and stippled lines:
  • FixedFunctionPipeline is general purpose and allows for directly rendering any vertex buffer. However, it requires geometry shader support which is absent in OpenGL ES environments.
  • LineRenderer also works in OpenGL ES contexts as it only uses basic vertex and fragment shaders. However, it therefore requires some preprocessing of the input vertices on the CPU.
See also
GL::VertexBuffer, GL::FixedFunctionPipeline

Classes

struct  Options
 Helper struct to encapsulate all supported rendering options. More...
 

Public Member Functions

void render (const GL::VertexBuffer &vbo, Primitive primitive, const Options &options, const ViewState &viewState, const OrderIndependentTransparency *oit=nullptr)
 Renders a the given vertex buffer as connected line.
 
void renderLines (const std::vector< vec3 > &vertices, const Options &options, const ViewState &viewState, const OrderIndependentTransparency *oit=nullptr)
 Renders a series of individual lines from the given vertices.
 
void renderLineStrip (const std::vector< vec3 > &vertices, const Options &options, const ViewState &viewState, const OrderIndependentTransparency *oit=nullptr)
 Renders a connected line strip of the given vertices.
 
void renderLineLoop (const std::vector< vec3 > &vertices, const Options &options, const ViewState &viewState, const OrderIndependentTransparency *oit=nullptr)
 Renders a connected line loop of the given vertices.
 

Static Public Member Functions

static bool makeVertexData (const std::vector< vec3 > &vertices, Primitive primitive, GL::VertexBuffer &outputVBO)
 Converts the given vertices to a suitable internal representation and uploads them to a VertexBuffer which can then be used with render().
 
static bool makeVertexData (const std::vector< vec3 > &vertices, const std::vector< vec4 > &colors, Primitive primitive, GL::VertexBuffer &outputVBO)
 Converts the given vertices to a suitable internal representation and uploads them to a VertexBuffer which can then be used with render().
 
- Static Public Member Functions inherited from InstanceManager< LineRenderer >
static LineRenderercachedInstance ()
 Returns the cached instance of type T for the currently active OpenGL context.
 

Member Function Documentation

◆ makeVertexData() [1/2]

static bool makeVertexData ( const std::vector< vec3 > & vertices,
Primitive primitive,
GL::VertexBuffer & outputVBO )
static

Converts the given vertices to a suitable internal representation and uploads them to a VertexBuffer which can then be used with render().

Parameters
verticesVertices of the line in world coordinates
primitiveLine type to render, must be Primitive::Lines, Primitive::LineLoop, or Primitive::LineStrip.
outputVBOOutput vertex buffer into which the resulting vertex data should be written
Returns
true if sufficient input vertices were provided; false if vertices does not contain enough data or primitive is invalid, in which case outputVBO will remain untouched.

◆ makeVertexData() [2/2]

static bool makeVertexData ( const std::vector< vec3 > & vertices,
const std::vector< vec4 > & colors,
Primitive primitive,
GL::VertexBuffer & outputVBO )
static

Converts the given vertices to a suitable internal representation and uploads them to a VertexBuffer which can then be used with render().

Parameters
verticesVertices of the line in world coordinates
colorsOptional per-vertex colors of the line to override the static render color in Options. Must either be empty or have the same size as vertices.
primitiveLine type to render, must be Primitive::Lines, Primitive::LineLoop, or Primitive::LineStrip.
outputVBOOutput vertex buffer into which the resulting vertex data should be written
Returns
true if sufficient input vertices were provided; false if vertices does not contain enough data or primitive is invalid, in which case outputVBO will remain untouched.

◆ render()

void render ( const GL::VertexBuffer & vbo,
Primitive primitive,
const Options & options,
const ViewState & viewState,
const OrderIndependentTransparency * oit = nullptr )

Renders a the given vertex buffer as connected line.

Parameters
vboVertex buffer that was previously generated with makeVertexData().
primitiveLine type to render, must be Primitive::Lines, Primitive::LineLoop, or Primitive::LineStrip.
optionsRendering options to use
viewStateView and projection matrix to use
oitOptional order-independent transparency handling instance to use

◆ renderLines()

void renderLines ( const std::vector< vec3 > & vertices,
const Options & options,
const ViewState & viewState,
const OrderIndependentTransparency * oit = nullptr )

Renders a series of individual lines from the given vertices.

Parameters
verticesVertices of the line in world coordinates
optionsRendering options to use
viewStateView and projection matrix to use
oitOptional order-independent transparency handling instance to use GL::Primitive::Lines

◆ renderLineStrip()

void renderLineStrip ( const std::vector< vec3 > & vertices,
const Options & options,
const ViewState & viewState,
const OrderIndependentTransparency * oit = nullptr )

Renders a connected line strip of the given vertices.

Parameters
verticesVertices of the line in world coordinates
optionsRendering options to use
viewStateView and projection matrix to use
oitOptional order-independent transparency handling instance to use
See also
GL::Primitive::LineStrip

◆ renderLineLoop()

void renderLineLoop ( const std::vector< vec3 > & vertices,
const Options & options,
const ViewState & viewState,
const OrderIndependentTransparency * oit = nullptr )

Renders a connected line loop of the given vertices.

Parameters
verticesVertices of the line in world coordinates
optionsRendering options to use
viewStateView and projection matrix to use
oitOptional order-independent transparency handling instance to use
See also
GL::Primitive::LineLoop

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close