All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Luminous::RenderContext Class Reference

RenderContext contains the current rendering state. More...

#include <Luminous/RenderContext.hpp>

Inheritance diagram for Luminous::RenderContext:
Luminous::Transformer

Classes

struct  RenderBuilder
 Proxy object for building rendering command. More...
 

Public Types

enum  TextFlags { TextDynamic, TextStatic }
 TextFlags can be used to give performance hint to RenderContext about the layout of the text. More...
 
enum  TextureMappingMode { TEXTURE_MAPPING_FLAT, TEXTURE_MAPPING_TANGENT }
 How are UV coordinates generated for objects. More...
 

Public Member Functions

void addRenderCounter ()
 Adds the render counter by one The render counter is used to track how many objects have been rendered since the counter was last reset. More...
 
void addUnfinishedRenderCounter ()
 Increases the unfinished render counter by one. More...
 
float approximateScaling () const
 Get the approximate scaling factor applied by the transform. More...
 
const Luminous::MultiHead::Areaarea () const
 Returns the current area. More...
 
const ProgrambasicShader () const
 Returns the basic shader used in Luminous. More...
 
void beginArea ()
 Called once for every area before rendering anything in it. More...
 
void beginFrame ()
 Called once for every frame before rendering. For internal implementation.
 
void blit (const Nimble::Recti &src, const Nimble::Recti &dst, ClearMask mask=CLEARMASK_COLOR, Texture::Filter filter=Texture::FILTER_NEAREST)
 Copies pixels from the read frame buffer to the draw frame buffer. More...
 
void clear (ClearMask mask, const Radiant::Color &clearColor=Radiant::Color(0, 0, 0, 0), double clearDepth=1.0, int clearStencil=0)
 Clears the buffers of current frame buffer. More...
 
const Nimble::ClipStackclipStack () const
 Get the active clip stack. More...
 
Nimble::Size contextSize () const
 Returns the size of the window of this RenderContext object. More...
 
template<typename Vertex , typename Uniform >
RenderCommand & createRenderCommand (bool translucent, int indexCount, int vertexCount, unsigned *&mappedIndexBuffer, Vertex *&mappedVertexBuffer, Uniform *&mappedUniformBuffer, float &depth, const Program &program, const std::map< QByteArray, const Texture * > *textures, const std::map< QByteArray, ShaderUniform > *uniforms)
 
size_t currentClipMaskDepth () const
 Get current clip mask recursion depth. More...
 
const FrameBuffercurrentFrameBuffer () const
 Returns the target framebuffer for the current rendering operations. More...
 
const Nimble::RecticurrentScissorArea () const
 Returns current scissor area. More...
 
const Nimble::RecticurrentViewport () const
 Get the current viewport. More...
 
void disableClipPlanes (const QList< int > &planes)
 Disable clipplanes from being used in shaders. More...
 
void drawArc (const Nimble::Vector2f &center, float radius, float fromRadians, float toRadians, const Luminous::Style &style, unsigned int lineSegments=0)
 Draw an arc defined as a segment of circle. More...
 
void drawCircle (const Nimble::Vector2f &center, float radius, const Luminous::Style &style, unsigned int lineSegments=0, float fromRadians=0, float toRadians=Nimble::Math::TWO_PI)
 Draw a possibly filled circle. More...
 
void drawDonut (const Nimble::Vector2f &center, Nimble::Vector2 axis, float otherAxisLength, float width, const Luminous::Style &style, unsigned int linesegments=0, float fromRadians=0, float toRadians=Nimble::Math::TWO_PI, TextureMappingMode textureMappingMode=TEXTURE_MAPPING_FLAT)
 Draws a constant width donut defined as an ellipse and a hole in the center. More...
 
void drawEllipse (Nimble::Vector2f center, Nimble::Vector2f axis, float otherAxisLength, const Luminous::Style &style, unsigned int lineSegments=0, float fromRadians=0, float toRadians=Nimble::Math::TWO_PI)
 Draws an ellipse. More...
 
void drawLine (const Nimble::Vector2f &p1, const Nimble::Vector2f &p2, const Luminous::Style &style)
 Draws a line. More...
 
template<typename InputIterator >
void drawPoints (InputIterator begin, size_t numPoints, const Luminous::Style &style)
 Draws a set of points. More...
 
template<typename InputIterator >
void drawPolyLine (InputIterator begin, size_t numVertices, const Luminous::Style &style)
 Draws a polyline. More...
 
template<typename Vertex , typename UniformBlock >
RenderBuilder< Vertex,
UniformBlock > 
drawPrimitiveT (Luminous::PrimitiveType primType, unsigned int indexCount, unsigned int vertexCount, const Luminous::Program &shader, const Radiant::Color &color, float width, const Luminous::Style &style)
 Returns RenderBuilder for the given drawing query. More...
 
void drawQuad (const Nimble::Vector2 *v, const Nimble::Vector2 *uvs, const Style &style)
 Draws a quad with two triangles. More...
 
void drawRect (const Nimble::Vector2f &min, const Nimble::Vector2f &max, const Style &style)
 Draws a rectangle. More...
 
void drawRect (const Nimble::Vector2f &min, const Nimble::SizeF &size, const Style &style)
 Draws a rectangle. More...
 
template<typename T >
void drawRect (const Nimble::RectT< T > &rect, const Style &style)
 Draws a rectangle. More...
 
template<typename T >
void drawRect (const Nimble::RectT< T > &rect, const Nimble::Rectf &uvs, const Style &style)
 Draws a rectangle. More...
 
void drawRectWithHole (const Nimble::Rectf &area, const Nimble::Rect &hole, const Luminous::Style &style)
 Draws a rectangle with rectangular hole. More...
 
void drawText (const TextLayout &layout, const Nimble::Vector2f &location, const Nimble::Rectf &viewRect, const TextStyle &style, bool ignoreVerticalAlign=false)
 Draws text. More...
 
void drawText (const QString &text, const Nimble::Rectf &rect, const TextStyle &style, TextFlags flags=TextStatic)
 Draws given string. More...
 
void enableClipPlanes (const QList< int > &planes)
 Enable clipplanes for use in shaders. More...
 
void endArea ()
 Called once for every area after rendering it. More...
 
void endFrame ()
 Called once for every frame after rendering. For internal implementation.
 
TextureGLfindHandle (const Texture &texture)
 
void flush ()
 Forces all queued rendering commands to execute. More...
 
unsigned gpuId () const
 Returns a gpu id associated with this render context.
 
ProgramGLhandle (const Program &program)
 Returns the GL resources handle corresponding to given program. More...
 
TextureGLhandle (const Texture &texture)
 Returns the GL resources handle corresponding to given texture. More...
 
FrameBufferGLhandle (const FrameBuffer &target)
 Returns the GL resources handle corresponding to given frame buffer. More...
 
RenderBufferGLhandle (const RenderBuffer &buffer)
 Returns the GL resources handle corresponding to given render buffer. More...
 
BufferGLhandle (const Buffer &buffer)
 Returns the GL resources handle corresponding to given buffer (vertex/index). More...
 
VertexArrayGLhandle (const VertexArray &vertexarray, ProgramGL *program)
 Returns the GL resources handle corresponding to given vertex array. More...
 
bool initialize ()
 Initializes the context. More...
 
bool isClipStackEmpty () const
 Check if the current clip stack is empty. More...
 
bool isVisible (const Nimble::Rectangle &area)
 Checks if the given rectangle is visible (not clipped). More...
 
float opacity () const
 Get the current opacity. More...
 
void popClipMaskStack ()
 Decrement the current clip mask recursion depth.
 
void popClipRect ()
 Pops a clipping rectangle from the context.
 
void popClipStack ()
 Restores the previously saved clipping stack.
 
void popFrameBuffer ()
 Pops the current frame buffer from the stack.
 
void popOpacity ()
 Pop the current opacity from the stack.
 
void popScissorRect ()
 Pop current scissor rectangle from stack.
 
void popViewport ()
 Pop a viewport from the viewport stack Pops the viewport from the top of the viewport stack.
 
void popViewTransform ()
 Pop the current matrix from view transform stack.
 
void pushClipMaskStack (size_t depth)
 Increment the current clip mask recursion depth.
 
void pushClipRect (const Nimble::Rectangle &r)
 Pushes a clipping rectangle to the context.
 
void pushClipStack ()
 Save the current clipping stack and start with a empty one.
 
void pushFrameBuffer (const FrameBuffer &target)
 Pushes new frame buffer to the stack. More...
 
void pushOpacity (float opacity)
 Push the given opacity to render context. More...
 
void pushScissorRect (const Nimble::Recti &scissorArea)
 Push scissor rectangle into scissor stack.
 
void pushViewport (const Nimble::Recti &viewport)
 Push a viewport to the viewport stack Pushes a viewport to the top of the viewport stack. More...
 
void pushViewTransform (const Nimble::Matrix4 &m)
 Push new view transform to the view transform stack. More...
 
size_t recursionLimit () const
 Returns the recursion limit. More...
 
template<typename Vertex , typename UniformBlock >
RenderBuilder< Vertex,
UniformBlock > 
render (bool translucent, Luminous::PrimitiveType type, int offset, int vertexCount, float primitiveSize, const Luminous::VertexArray &vertexArray, const Luminous::Program &program, const std::map< QByteArray, const Texture * > *textures=nullptr, const std::map< QByteArray, ShaderUniform > *uniforms=nullptr)
 Adds rendering command to the rendering queue. More...
 
template<typename Vertex , typename UniformBlock >
RenderBuilder< Vertex,
UniformBlock > 
render (bool translucent, Luminous::PrimitiveType type, int indexCount, int vertexCount, float primitiveSize, const Luminous::Program &program, const std::map< QByteArray, const Texture * > *textures=nullptr, const std::map< QByteArray, ShaderUniform > *uniforms=nullptr)
 Similar to drawPrimitiveT but has less restrictions on the uniform block. More...
 
 RenderContext (Luminous::RenderDriver &driver, const Luminous::MultiHead::Window *window=0, unsigned gpuId=0)
 Constructs a new render context and associates the given resources to it. More...
 
unsigned long renderCounter () const
 
Luminous::RenderDriver & renderDriver ()
 
void setBlendMode (const BlendMode &mode)
 Set the active blendmode. More...
 
void setCullMode (const CullMode &mode)
 Set the active cull mode. More...
 
void setDefaultDrawBuffers ()
 Reset the active draw buffers to the default.
 
void setDefaultState ()
 Reset the OpenGL state to default. More...
 
void setDepthMode (const DepthMode &mode)
 Set the active depthmode. More...
 
void setDrawBuffers (const std::vector< int > &buffers)
 Set the active draw buffers. More...
 
void setFrontFace (enum FaceWinding winding)
 Specify front-facing polygons. More...
 
void setOpacity (float opacity)
 
void setRecursionLimit (size_t limit)
 Sets the rendering recursion limit for the context. More...
 
void setRenderBuffers (bool colorBuffer, bool depthBuffer, bool stencilBuffer)
 Set the active render buffers. More...
 
void setStencilMode (const StencilMode &mode)
 Set the active stencil mode. More...
 
void setWindowArea (const Luminous::MultiHead::Window *window, const Luminous::MultiHead::Area *area)
 Sets the associated area for this context at the moment. More...
 
template<typename T >
std::pair< T
*, RenderContext::SharedBuffer * > 
sharedBuffer (std::size_t maxVertexCount, Buffer::Type type, unsigned int &offset)
 
StencilMode stencilMode () const
 
const ProgramtexShader () const
 Returns the shader used for texturing in Luminous. More...
 
const ProgramtrilinearTexShader () const
 Returns the shader used for trilinear texturing in Luminous. More...
 
unsigned long unfinishedRenderCounter () const
 The unfinished render counter is used to track how many objects didn't finish their rendering because of some resource wasn't ready. More...
 
const Nimble::Matrix4viewTransform () const
 Returns transformation from the world coordinates (pixels) to projected eye coordinates (normalized device coordinates). More...
 
const Luminous::MultiHead::Windowwindow () const
 Returns the window associated to the current area. More...
 
virtual ~RenderContext ()
 Closes this render context. More...
 
- Public Member Functions inherited from Luminous::Transformer
void leftMul (const Nimble::Matrix4 &m)
 Multiply the top matrix from the left with the given matrix The end result is equivalent to: More...
 
void popTransform ()
 Pops the top matrix from the stack.
 
Nimble::Vector2 project (const Nimble::Vector2 &) const
 Apply the current transformation matrix on a 2D vector.
 
void pushTransform ()
 Push a new matrix to the stack, just copying the current top.
 
void pushTransform (const Nimble::Matrix4 &m)
 Push the given matrix to the stack pushTransform(m) has the same effect as: More...
 
void pushTransform (const Nimble::Matrix3 &m)
 
void pushTransformLeftMul (const Nimble::Matrix4 &m)
 Multiply the top matrix from the left with the given matrix and push the result into the stack.
 
void pushTransformLeftMul (const Nimble::Matrix3 &m)
 
void pushTransformRightMul (const Nimble::Matrix4 &m)
 Multiply the top matrix from the right with the given matrix and push the result into the stack.
 
void pushTransformRightMul (const Nimble::Matrix3 &m)
 
void resetTransform ()
 Clears the stack so it only contains an identity matrix.
 
void rightMul (const Nimble::Matrix4 &m)
 Multiply the top matrix from the right with the given matrix The end result is equivalent to: More...
 
void setTransform (const Nimble::Matrix4 &m)
 Replaces the top matrix with the given matrix. More...
 
size_t stackSize () const
 Get the size of the transform stack. More...
 
const Nimble::Matrix4transform () const
 Get the top matrix of the stack.
 
Nimble::Matrix3 transform3 () const
 Get the top matrix of the stack as 3x3-matrix.
 
 Transformer ()
 Creates an empty transformation stack.
 
Nimble::Vector2 unproject (const Nimble::Vector2 &) const
 Apply inverse of the current transformation matrix on a 2D vector.
 
virtual ~Transformer ()
 Deletes the transformation stack.
 

Protected Member Functions

virtual void beforeTransformChange ()
 This function gets called just before the transformation matrix is changed. More...
 

Additional Inherited Members

- Protected Attributes inherited from Luminous::Transformer
std::stack< Nimble::Matrix4,
std::vector< Nimble::Matrix4 > > 
m_stack
 The transformation stack.
 

Detailed Description

Member Enumeration Documentation

TextFlags can be used to give performance hint to RenderContext about the layout of the text.

Enumerator
TextDynamic 

Text layout changes usually every frame.

TextStatic 

Text layout does not change often.

How are UV coordinates generated for objects.

Enumerator
TEXTURE_MAPPING_FLAT 

Flat mapping looks like the texture was projected to the object bounding box, basically clipping the texture to the shape of the rendered object.

TEXTURE_MAPPING_TANGENT 

UV coordinates follow the ellipse tangent and normal.

U-coordinate rotates with the object from 0 to 1 in clockwise direction. V-coordinate is 0 on the internal edge or center and 1 at the outer edge.

Constructor & Destructor Documentation

Luminous::RenderContext::RenderContext ( Luminous::RenderDriver &  driver,
const Luminous::MultiHead::Window window = 0,
unsigned  gpuId = 0 
)

Constructs a new render context and associates the given resources to it.

Parameters
driverrender driver to use
windowwindow to associate this context with
gpuIdNative GPU id this render context is associated with
virtual Luminous::RenderContext::~RenderContext ( )
virtual

Closes this render context.

Invalidates all GL resources tied to this context. However note, that CPU equivalents of GL classes are still valid.

Member Function Documentation

void Luminous::RenderContext::addRenderCounter ( )

Adds the render counter by one The render counter is used to track how many objects have been rendered since the counter was last reset.

This can be useful for checking that object culling works as intended.

void Luminous::RenderContext::addUnfinishedRenderCounter ( )

Increases the unfinished render counter by one.

See Also
unfinishedRenderCounter
float Luminous::RenderContext::approximateScaling ( ) const

Get the approximate scaling factor applied by the transform.

Returns
approximate scaling applied
const Luminous::MultiHead::Area* Luminous::RenderContext::area ( ) const

Returns the current area.

Returns
Pointer to current area
const Program& Luminous::RenderContext::basicShader ( ) const

Returns the basic shader used in Luminous.

This shader program transforms the geometry and paints it with single color. Needs BasicVertex for vertex type and BasicUniformBlock for uniform block type to be able to work.

Returns
Basic shader used in Luminous
virtual void Luminous::RenderContext::beforeTransformChange ( )
protectedvirtual

This function gets called just before the transformation matrix is changed.

Reimplemented from Luminous::Transformer.

void Luminous::RenderContext::beginArea ( )

Called once for every area before rendering anything in it.

Can be called multiple times per frame depending on configuration.

void Luminous::RenderContext::blit ( const Nimble::Recti src,
const Nimble::Recti dst,
ClearMask  mask = CLEARMASK_COLOR,
Texture::Filter  filter = Texture::FILTER_NEAREST 
)

Copies pixels from the read frame buffer to the draw frame buffer.

See Also
FrameBuffer::setTargetBind
Parameters
srcRectangle defining source area in the read frame buffer
dstRectangle defining destination are in the draw frame buffer
maskBuffers to blit
filterFiltering mode for sampling
void Luminous::RenderContext::clear ( ClearMask  mask,
const Radiant::Color clearColor = Radiant::Color(0, 0, 0, 0),
double  clearDepth = 1.0,
int  clearStencil = 0 
)

Clears the buffers of current frame buffer.

Parameters
maskMask to define what buffers to clear
clearColorAll values in color buffer will be initialized to this if it is cleared
clearDepthAll values in depth buffer will be initialized to this if it is cleared
clearStencilAll values in stencil buffer will be initialized to this if it is cleared
Examples:
Widget3DExample.cpp.
const Nimble::ClipStack& Luminous::RenderContext::clipStack ( ) const

Get the active clip stack.

The clip stack is only valid during rendering. Do not call this function if the clip stack is empty.

Returns
current clip stack
See Also
isClipStackEmpty()
Nimble::Size Luminous::RenderContext::contextSize ( ) const

Returns the size of the window of this RenderContext object.

Returns
If the window is null, then Nimble::Size(10,10) is returned.
size_t Luminous::RenderContext::currentClipMaskDepth ( ) const

Get current clip mask recursion depth.

Returns
Current clip mask recursion depth
const FrameBuffer& Luminous::RenderContext::currentFrameBuffer ( ) const

Returns the target framebuffer for the current rendering operations.

Returns
Draw frame buffer
const Nimble::Recti& Luminous::RenderContext::currentScissorArea ( ) const

Returns current scissor area.

Returns
Current scissor area
const Nimble::Recti& Luminous::RenderContext::currentViewport ( ) const

Get the current viewport.

Returns
the viewport from the top of the viewport stack
void Luminous::RenderContext::disableClipPlanes ( const QList< int > &  planes)

Disable clipplanes from being used in shaders.

Parameters
planesa list of planes that will be disabled
void Luminous::RenderContext::drawArc ( const Nimble::Vector2f center,
float  radius,
float  fromRadians,
float  toRadians,
const Luminous::Style style,
unsigned int  lineSegments = 0 
)

Draw an arc defined as a segment of circle.

Parameters
centerCenter of the arc
radiusRadius of the arc
fromRadiansStart angle in radians
toRadiansEnd angle in radians
styleStroke definition of the arc (color, width)
lineSegmentsNumber of steps (precision)
Examples:
CustomRenderWidgetExample.cpp.
void Luminous::RenderContext::drawCircle ( const Nimble::Vector2f center,
float  radius,
const Luminous::Style style,
unsigned int  lineSegments = 0,
float  fromRadians = 0,
float  toRadians = Nimble::Math::TWO_PI 
)

Draw a possibly filled circle.

Parameters
centerCenter of the circle
radiusRadius of the circle
styleStroke and fill definitions of the circle (colors and stroke width)
lineSegmentsNumber of steps (precision)
fromRadiansStart angle in radians
toRadiansEnd angle in radians
Examples:
PenExample.cpp.
void Luminous::RenderContext::drawDonut ( const Nimble::Vector2f center,
Nimble::Vector2  axis,
float  otherAxisLength,
float  width,
const Luminous::Style style,
unsigned int  linesegments = 0,
float  fromRadians = 0,
float  toRadians = Nimble::Math::TWO_PI,
TextureMappingMode  textureMappingMode = TEXTURE_MAPPING_FLAT 
)

Draws a constant width donut defined as an ellipse and a hole in the center.

Parameters
centerCenter of the donut
axisAxis of the ellipse (orientation and size)
otherAxisLengthOther axis legth of the ellipse.
widthThe width of the donut.
styleStroke, fill and texturing definitions.
linesegmentsNumber of steps (precision)
fromRadiansStart angle in radians
toRadiansEnd angle in radians
textureCoordModeHow are the texture coordinates generated
void Luminous::RenderContext::drawEllipse ( Nimble::Vector2f  center,
Nimble::Vector2f  axis,
float  otherAxisLength,
const Luminous::Style style,
unsigned int  lineSegments = 0,
float  fromRadians = 0,
float  toRadians = Nimble::Math::TWO_PI 
)

Draws an ellipse.

Parameters
centerCenter of the ellipse
axisAxis of the ellipse (orientation and size)
otherAxisLengthThe length of the other axis
styleStroke and fill definitions similar to circle
lineSegmentsNumber of steps (precision)
fromRadiansStart angle in radians
toRadiansEnd angle in radians
void Luminous::RenderContext::drawLine ( const Nimble::Vector2f p1,
const Nimble::Vector2f p2,
const Luminous::Style style 
)

Draws a line.

Parameters
p1Start point of the line
p2End point of the line
styleStroke definition of a line.
Examples:
MixedJavaScriptExample.js.
template<typename InputIterator >
void Luminous::RenderContext::drawPoints ( InputIterator  begin,
size_t  numPoints,
const Luminous::Style style 
)

Draws a set of points.

Parameters
beginInitial position of sequence
numPointsNumber of points
styleColor and size passed as stroke parameters
Template Parameters
InputIteratorIterator to vertices. Needs to have operator++ and operator*
template<typename InputIterator >
void Luminous::RenderContext::drawPolyLine ( InputIterator  begin,
size_t  numVertices,
const Luminous::Style style 
)

Draws a polyline.

Parameters
beginInitial position of sequence
numVerticesNumber of vertices (one more than lines in polyline)
styleStroke definition of a line.
Template Parameters
InputIteratorIterator to vertices. Needs to have operator++ and operator*
Examples:
MixedJavaScriptExample.js.
template<typename Vertex , typename UniformBlock >
RenderBuilder<Vertex, UniformBlock> Luminous::RenderContext::drawPrimitiveT ( Luminous::PrimitiveType  primType,
unsigned int  indexCount,
unsigned int  vertexCount,
const Luminous::Program shader,
const Radiant::Color color,
float  width,
const Luminous::Style style 
)

Returns RenderBuilder for the given drawing query.

Call to this function allocates the queried resources from driver and associates those with the given shader and other parameters. After calling this function user needs to feed data through the returned builder object.

// Draw a triangle using drawPrimitiveT
// Call to drawPrimitiveT adds the rendering command to queue
RenderBuilder<BasicVertex, BasicUniformBlock> builder = rc.drawPrimitiveT(Luminous::PRIMITIVE_TRIANGLE,
0, // Do not use indexed drawing
3, // Three vertices
rc.basicShader(), // Use basic shader
0, // This would be width of line or point
style // No need to pass additional parameters
);
// Now fill the data of the builder (vertices of triangle)
builder.vertex[0].location = Nimble::Vector2(0, 0);
builder.vertex[1].location = Nimble::Vector2(1, 0);
builder.vertex[2].location = Nimble::Vector2(.5, 1);
// That is all we needed: request to draw and supported that request with data
Parameters
primTypePrimitives to render
indexCountHow many indices are to be specified. If zero, indices are effectively set to 0,1,...,vertexCount-1
vertexCountHow many vertices are to be specified.
shaderGLSL-program to use.
colorColor for the corresponding uniform.
widthWidth for the rendered primitive. Only for points and lines.
styleStyle for the rendering.
Template Parameters
VertexType of the vertex feed to the shader shader.
UniformBlockType of the uniformblock. Needs at least to include public fields projMatrix (Nimble::Matrix4), modelMatrix (Nimble::Matrix4), color (Nimble::Vector4) and depth (float) (see Luminous::BasicUniformBlock).
Returns
Returns RenderBuilder-object which contains the interface to the rendering resources acquired by call to this function.
Examples:
AdvancedRenderingExample.cpp.
void Luminous::RenderContext::drawQuad ( const Nimble::Vector2 v,
const Nimble::Vector2 uvs,
const Style style 
)

Draws a quad with two triangles.

The vertices of the first triangle are v[0], v[1], v[2]. The second triangle is defined by vertices v[1], v[3] and v[2]. Both of the triangles are assumed to have a counterclockwise orientation.

Parameters
vVertices of a quad
uvsTexture coordinates for the vertices
styleStroke, fill and texturing options
void Luminous::RenderContext::drawRect ( const Nimble::Vector2f min,
const Nimble::Vector2f max,
const Style style 
)

Draws a rectangle.

Parameters
minBottom left corner of a rectangle
maxTop right corner of a rectangle
styleStroke, fill and texturing options
Examples:
MarkerExample.cpp.
void Luminous::RenderContext::drawRect ( const Nimble::Vector2f min,
const Nimble::SizeF size,
const Style style 
)

Draws a rectangle.

Parameters
minBottom left corner of a rectangle
sizeRectangle size
styleStroke, fill and texturing options
template<typename T >
void Luminous::RenderContext::drawRect ( const Nimble::RectT< T > &  rect,
const Style style 
)

Draws a rectangle.

Parameters
rextRectangle to draw
styleStroke, fill and texturing options
template<typename T >
void Luminous::RenderContext::drawRect ( const Nimble::RectT< T > &  rect,
const Nimble::Rectf uvs,
const Style style 
)

Draws a rectangle.

Parameters
rectRectangle to draw
uvsTexture coordinates
styleStroke, fill and texturing options
void Luminous::RenderContext::drawRectWithHole ( const Nimble::Rectf area,
const Nimble::Rect hole,
const Luminous::Style style 
)

Draws a rectangle with rectangular hole.

Parameters
areaOuter rectangle
holeInner rectangle defining the hole
styleStroke, fill and texturing options
void Luminous::RenderContext::drawText ( const TextLayout layout,
const Nimble::Vector2f location,
const Nimble::Rectf viewRect,
const TextStyle style,
bool  ignoreVerticalAlign = false 
)

Draws text.

Parameters
layoutText object to render
locationText location in viewRect. Anything outside will be clipped.
viewRectWhere the text is located
styleText style properties
ignoreVerticalAlignIf true the rendering assumes that vertical alignment is already handled and baked in rendering location. Layout's options about vertical alignment are ignored in that case.
Examples:
MarkerExample.cpp.
void Luminous::RenderContext::drawText ( const QString &  text,
const Nimble::Rectf rect,
const TextStyle style,
TextFlags  flags = TextStatic 
)

Draws given string.

Parameters
textString to render
rectWhere to render, acts also as a clipping rectangle
styleText style properties
flagsWill text layout be dynamic or static
void Luminous::RenderContext::enableClipPlanes ( const QList< int > &  planes)

Enable clipplanes for use in shaders.

Parameters
planesa list of planes that will be enabled
void Luminous::RenderContext::endArea ( )

Called once for every area after rendering it.

Can be called multiple times per frame depending on configuration.

TextureGL* Luminous::RenderContext::findHandle ( const Texture texture)
See Also
RenderDriverGL::findHandle
void Luminous::RenderContext::flush ( )

Forces all queued rendering commands to execute.

Is called internally at the end of frame so under normal conditions there is no need call it manually.

ProgramGL& Luminous::RenderContext::handle ( const Program program)

Returns the GL resources handle corresponding to given program.

Parameters
programCPU side object representing the shader program
Returns
Handle to OpenGL resources of given program
TextureGL& Luminous::RenderContext::handle ( const Texture texture)

Returns the GL resources handle corresponding to given texture.

Parameters
textureCPU side object representing the texture
Returns
Handle to OpenGL resources of given texture
FrameBufferGL& Luminous::RenderContext::handle ( const FrameBuffer target)

Returns the GL resources handle corresponding to given frame buffer.

Parameters
targetCPU side object representing the frame buffer
Returns
Handle to OpenGL resources of given frame buffer
RenderBufferGL& Luminous::RenderContext::handle ( const RenderBuffer buffer)

Returns the GL resources handle corresponding to given render buffer.

Parameters
bufferCPU side object representing the render buffer
Returns
Handle to OpenGL resources of given render buffer
BufferGL& Luminous::RenderContext::handle ( const Buffer buffer)

Returns the GL resources handle corresponding to given buffer (vertex/index).

Parameters
bufferCPU side object representing the buffer
Returns
Handle to OpenGL resources of given buffer
VertexArrayGL& Luminous::RenderContext::handle ( const VertexArray vertexarray,
ProgramGL program 
)

Returns the GL resources handle corresponding to given vertex array.

Parameters
vertexarrayCPU side object representing the vertex array
programHandle to OpenGL program associated with vertexarray
Returns
Handle to OpenGL resources of queried vertex array
bool Luminous::RenderContext::initialize ( )

Initializes the context.

Is called automatically by rendering thread.

Returns
Was the initialization succesful.
bool Luminous::RenderContext::isClipStackEmpty ( ) const

Check if the current clip stack is empty.

Returns
true if the clip stack is empty; otherwise false
bool Luminous::RenderContext::isVisible ( const Nimble::Rectangle area)

Checks if the given rectangle is visible (not clipped).

Parameters
areaArea to check
Returns
Was the area visible
float Luminous::RenderContext::opacity ( ) const

Get the current opacity.

Returns
the current opacity
void Luminous::RenderContext::pushFrameBuffer ( const FrameBuffer target)

Pushes new frame buffer to the stack.

Parameters
targetframe buffer for rendering commands.
void Luminous::RenderContext::pushOpacity ( float  opacity)

Push the given opacity to render context.

The resulting opacity will be the current opacity multiplied by the given value.

Parameters
opacityopacity to push
void Luminous::RenderContext::pushViewport ( const Nimble::Recti viewport)

Push a viewport to the viewport stack Pushes a viewport to the top of the viewport stack.

Parameters
viewportviewport to push
void Luminous::RenderContext::pushViewTransform ( const Nimble::Matrix4 m)

Push new view transform to the view transform stack.

Parameters
mMatrix representing view transform
size_t Luminous::RenderContext::recursionLimit ( ) const

Returns the recursion limit.

Returns
Recursion limit
template<typename Vertex , typename UniformBlock >
RenderBuilder<Vertex, UniformBlock> Luminous::RenderContext::render ( bool  translucent,
Luminous::PrimitiveType  type,
int  offset,
int  vertexCount,
float  primitiveSize,
const Luminous::VertexArray vertexArray,
const Luminous::Program program,
const std::map< QByteArray, const Texture * > *  textures = nullptr,
const std::map< QByteArray, ShaderUniform > *  uniforms = nullptr 
)

Adds rendering command to the rendering queue.

The difference between this and render is that this version enables manual management of vertex data with the vertex array. In addition the used uniform block has free form. User needs to do his/hers own geometry transformations when using this function.

See Also
drawPrimitiveT
Parameters
translucentDoes this rendering command involve transparency
typePrimitives to render
offsetGeometry and index offset in given vertex array
vertexCountNumber of vertices to draw
primitiveSizeSize of the point/line
vertexArrayStorage of the vertex data
programShader program to use in rendering
texturesMapping from names to textures. Each texture is fed with the given name to shader
uniformsMapping from names to uniforms. Each uniform is fed with the given name to shader
Template Parameters
VertexC++ class describing the vertex used in shader program. Doesn't require anything from this class
UniformBlockC++ class corresponding the uniform block used by shader program. Doesn't require anything from this class
Returns
Builder object for this drawing command. One has to fill the uniform block of the builder object.
Examples:
Widget3DExample.cpp.
template<typename Vertex , typename UniformBlock >
RenderBuilder<Vertex, UniformBlock> Luminous::RenderContext::render ( bool  translucent,
Luminous::PrimitiveType  type,
int  indexCount,
int  vertexCount,
float  primitiveSize,
const Luminous::Program program,
const std::map< QByteArray, const Texture * > *  textures = nullptr,
const std::map< QByteArray, ShaderUniform > *  uniforms = nullptr 
)

Similar to drawPrimitiveT but has less restrictions on the uniform block.

It is enough for the uniform block to have fields projMatrix and vievMatrix (both Nimble::Matrix4).

See Also
drawPrimitiveT
Parameters
translucentDoes this rendering command involve transparency
typePrimitives to render
offsetGeometry and index offset in given vertex array
vertexCountNumber of vertices to draw
primitiveSizeSize of the point/line
vertexArrayStorage of the vertex data
programShader program to use in rendering
texturesMapping from names to textures. Each texture is fed with the given name to shader
uniformsMapping from names to uniforms. Each uniform is fed with the given name to shader
Template Parameters
VertexC++ class describing the vertex used in shader program.
UniformBlockC++ class corresponding the uniform block used by shader program. See the applying restrictions above.
Returns
Builder object for this drawing command. User has to fill the uniform and vertex (and possibly index) buffers of the builder object.
void Luminous::RenderContext::setBlendMode ( const BlendMode mode)

Set the active blendmode.

Parameters
modeDescription of new blend mode.
void Luminous::RenderContext::setCullMode ( const CullMode mode)

Set the active cull mode.

Parameters
modeCull mode to use
void Luminous::RenderContext::setDefaultState ( )

Reset the OpenGL state to default.

The usage of this function by manually is not recommended

void Luminous::RenderContext::setDepthMode ( const DepthMode mode)

Set the active depthmode.

Parameters
modeDescription of the new depth mode
void Luminous::RenderContext::setDrawBuffers ( const std::vector< int > &  buffers)

Set the active draw buffers.

Parameters
buffersList of buffers to use The buffers may be one or more of the following: GL_NONE, GL_FRONT_LEFT, GL_FRONT_RIGHT, GL_BACK_LEFT, GL_BACK_RIGHT, GL_COLOR_ATTACHMENTn where n is a numerical value starting at 0
void Luminous::RenderContext::setFrontFace ( enum FaceWinding  winding)

Specify front-facing polygons.

Parameters
windingWinding of the front-facing polygons
void Luminous::RenderContext::setRecursionLimit ( size_t  limit)

Sets the rendering recursion limit for the context.

This is relevant for ViewWidgets which can cause recursive rendering of the scene.

Parameters
limitrecursion depth limit
void Luminous::RenderContext::setRenderBuffers ( bool  colorBuffer,
bool  depthBuffer,
bool  stencilBuffer 
)

Set the active render buffers.

Parameters
colorBufferenables drawing to colorbuffer if set to true
depthBufferenables drawing to depthbuffer if set to true
stencilBufferenables drawing to stencilbuffer if set to true
void Luminous::RenderContext::setStencilMode ( const StencilMode mode)

Set the active stencil mode.

Parameters
modeStencil mode to use
void Luminous::RenderContext::setWindowArea ( const Luminous::MultiHead::Window window,
const Luminous::MultiHead::Area area 
)

Sets the associated area for this context at the moment.

Parameters
areaarea to associate
const Program& Luminous::RenderContext::texShader ( ) const

Returns the shader used for texturing in Luminous.

This shader program does the same as the one returned by basicShader but also textures the geometry. Needs BasicVertexUV for vertex type and BasicUniformBlock for uniform block type to be able to work. The texture used is the one set as fill texture to Luminous::Style (or the one with name "tex"). Final color for the fragment is texture sample modulated with uniform color.

Returns
Shader program used for texturing in Luminous.
const Program& Luminous::RenderContext::trilinearTexShader ( ) const

Returns the shader used for trilinear texturing in Luminous.

Similar to texShader, but needs two textures "tex[0]" and "tex[1]" and works only with TrilinearFilteringUniformBlock. This is mostly used internally by ImageWidget and Widget background image renderer

Returns
Shader program used for trilinear filtering
unsigned long Luminous::RenderContext::unfinishedRenderCounter ( ) const

The unfinished render counter is used to track how many objects didn't finish their rendering because of some resource wasn't ready.

For example ImageWidget increases this counter if the best mipmap level wasn't yet generated and VideoWidget does the same if required video frame wasn't decoded yet. Unfixable permanent errors do not increase this counter. This is useful for example when rendering a scene to FBO and checking if everything was rendered there properly already this frame, or should the rendering be tried again on next frame.

const Nimble::Matrix4& Luminous::RenderContext::viewTransform ( ) const

Returns transformation from the world coordinates (pixels) to projected eye coordinates (normalized device coordinates).

Parameters
Matrixrepresenting current view transform
Examples:
LegacyGLExample.cpp, and Widget3DExample.cpp.
const Luminous::MultiHead::Window* Luminous::RenderContext::window ( ) const

Returns the window associated to the current area.

Returns
Pointer to current window.