Renderer is the core component for assigning lights, meshes, cameras, skin animations etc. to lower level rendering. More...
#include <kanzi/core.ui/platform/graphics_backend/gl/renderer3d.hpp>
Public Types | |
typedef void(* | FramebufferCallback) (unsigned int framebufferHandle) |
Callback prototype for setActiveFramebuffer. More... | |
typedef MaterialSharedPtr(* | OverrideMaterialCallback) (Node *node, MaterialSharedPtr material, size_t cluster, void *userData) |
Callback function for override materials. More... | |
Public Member Functions | |
void | applyCameraMatrix (Matrix4x4 cameraProjectionMatrix, Matrix4x4 cameraViewMatrix, float near, float far) const |
Applies camera matrices to renderer so that they can be applied as uniforms to shaders. More... | |
bool | applyColorMaterial (const Node *node, Material &material, ColorRGBA color) |
Applies the given material with the given emissive color. More... | |
void | applyFixedUniforms (const Material &material, RenderPass *renderPass, Node *node) |
Apply fixed uniforms related to lights. More... | |
void | applyFixedUniforms (const Material &material) |
Apply fixed uniforms related to lights. More... | |
bool | applyMaterial (const Node *node, const Material &material) |
Applies material to renderer, attaches the shader and uniforms. More... | |
bool | applyMaterialStrict (const Node *node, const Material &material) |
Applies material to renderer, attaches the shader and uniforms. Does not allow material which shader has samplers without corresponding texture properties. More... | |
void | applyStencilSettings (bool stencilTestEnabled, unsigned int stencilRef, unsigned int stencilMask, GraphicsCompareFunction stencilFunction, GraphicsStencilOperation stencilOperationStencilFail, GraphicsStencilOperation stencilOperationStencilPassDepthFail, GraphicsStencilOperation stencilOperationStencilPassDepthPass) const |
Applies stencil settings with overrides for rendering. More... | |
void | beginFrame () |
Resets user renderer for frame, that is, clear property stack and core renderer per-frame variables. More... | |
void | disableSubRectangleProjection () |
Disable sub-rectangle of projection. More... | |
void | drawBoxSolidNormal (const Box &box, Matrix4x4 worldTransformation, const Material &material) |
Draws a solid box. More... | |
void | drawBoxSolidNormal (Vector3 backBottomLeft, Vector3 frontTopRight, Material &material, ColorRGBA color, Matrix4x4 worldTransform) |
Draws a solid box given by two opposite corner points. More... | |
void | drawBuffers (Mesh *mesh, Node *baseNode, unsigned int cluster, const Material &material) |
Applies transformation and draws vertex and index buffers with current settings. More... | |
void | drawBuffers (Morph *morph, Node *baseNode, unsigned int cluster, const Material &material) |
void | drawCamera (const Camera *cameraNode, Material &material, Matrix4x4 worldTransformation) |
Draws a wire frame camera symbol. More... | |
void | drawLayerOutlineQuad (float width, float height, Material &material, float textureHeight, float textureOffset, ColorRGBA color, Matrix4x4 worldTransformation) |
void | drawLayerQuad (Vector2 renderOffset, Vector2 renderSize, Vector2 contentOffset, Vector2 contentSize, float depth, Matrix3x3 renderTransform, const Material &material) |
Render a layer quad. More... | |
void | drawLayerQuadWithMaterial (const Material &material, Vector2 renderOffset, Vector2 renderSize, Vector2 contentOffset, Vector2 contentSize, float depth, Matrix3x3 renderTransform) |
Render a layer quad. More... | |
void | drawLineList (const float *lineList, unsigned int lineCount, Matrix4x4 worldTransformation, const Material &material) const |
Draws a line list with current settings. Handles only position data. More... | |
void | drawOrientedBoundingBoxSolidNormal (const OrientedBoundingBox &orientedBoundingBox, const Material &material) |
Draws a solid oriented bounding box. More... | |
void | drawPrimitiveBufferTextured (const float *coordinateBuffer, const float *texCoordBuffer, Matrix4x4 worldTransform, GraphicsPrimitiveType type, unsigned int count, const Material &material) const |
Draw primitive buffer. More... | |
void | drawPrimitiveBufferUntextured (const float *coordinateBuffer, Matrix4x4 worldTransform, GraphicsPrimitiveType type, unsigned int count, const Material &material) const |
Draw primitive buffer. More... | |
void | drawPrimitives (const float *vertexList, unsigned int vertexCount, GraphicsPrimitiveType type, Matrix4x4 worldTransformation, const Material &material) const |
Draws primitives of the given type. More... | |
void | drawPrimitivesNormal (const float *vertexList, const float *normalList, unsigned int vertexCount, GraphicsPrimitiveType type, Matrix4x4 worldTransformation, const Material &material) |
Draws primitives of the given type. More... | |
void | drawQuad (Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Vector2 textureSpan, Material &material, optional< ColorRGBA > color, Matrix4x4 worldTransformation) |
Draws a quad. More... | |
void | drawSelectionIndicator (const Box &boundingBox, Matrix4x4 worldTransformation, Material &material, ColorRGBA color) |
Draws a selection indicator. More... | |
void | drawTrajectory (Trajectory *trajectory, Material &material, Matrix4x4 worldTransformation, Matrix4x4 arrangeTransform, Vector3 scaling) |
Draws a trajectory with wire frame lines. More... | |
void | drawUntexturedLayerQuad (Vector2 renderOffset, Vector2 renderSize, const Material &material, Matrix4x4 worldTransformation) |
As rendering a layer quad, but omit everything concerning texture coordinates. More... | |
void | drawViewportQuadWithTextureSpan (Vector2 offset, Vector2 limits, Material &material, TextureSharedPtr texture) |
Draws viewport quad, fills with given pattern. More... | |
void | drawViewportQuadWithTextureSpan (Vector2 offset, Vector2 limits, Material &material, TextureSharedPtr texture, ColorRGBA color) |
Draws viewport quad, fills with given pattern. More... | |
void | drawViewportQuadWithTextureSpan (Vector2 offset, Vector2 limits, Material &material, Vector2 textureSpan, ColorRGBA color) |
Draws viewport quad, fills with given pattern. More... | |
void | endFrame () |
Ends a frame. More... | |
GLGraphicsOutput * | getActiveGLGraphicsOutput () const |
Gets active GL graphics output from renderer. More... | |
GraphicsOutput * | getActiveGraphicsOutput () const |
Gets active graphics output from renderer. More... | |
optional< ColorRGBA > | getClearColorOverride () const |
Gets clear color override from renderer. Returns true if override enabled. More... | |
CompositionStack & | getCompositionStack () |
Returns the render context stack. More... | |
Renderer * | getCoreRenderer () const |
Returns core renderer from user renderer. More... | |
bool | getCullFaceOverride (GraphicsCullMode *out_overriddenCullMode) const |
Returns cull face override. More... | |
span< float > | getFloatBuffer () |
Returns temporary float buffer from renderer. More... | |
unsigned int | getFrameCount () const |
Gets number of frames rendered by renderer. More... | |
float | getInheritedAspectRatioMultiplier () const |
Get the multiplier to inherited aspect ratio. More... | |
MaterialSharedPtr | getOverrideClusterMaterial (Node *node, MaterialSharedPtr clusterMaterial, size_t clusterIndex) const |
Gets overriding material for given transformed object node and cluster material. More... | |
OverrideMaterialCallback | getOverrideMaterialCallback () const |
Gets override material callback from renderer, 0 if not enabled. More... | |
void * | getOverrideMaterialCallbackUserData () const |
Gets override material callback user data from renderer. More... | |
ResourceManager * | getResourceManager () const |
Gets renderer resource manager. More... | |
bool | isBoundingBoxVisualizationEnabled () const |
Returns if bounding box visualization is enabled. More... | |
bool | isColorWriteDisabled () const |
Returns if color write is disabled. More... | |
bool | isSkeletonVisualizationEnabled () const |
Returns if skeleton visualization is enabled. More... | |
void | printInfo () const |
Ends frame for renderer. More... | |
void | removeClearColorOverride () |
Removes clear color override. More... | |
Renderer3D (ResourceManager *resourceManager, Renderer *renderer) | |
void | reset () |
Resets renderer, that is, puts it to initial state. More... | |
void | setActiveGLGraphicsOutput (GLGraphicsOutput *glGraphicsOutput) |
Sets active GL graphics output for renderer. More... | |
void | setBoundingBoxVisualizationEnabled (bool enabled) |
Sets bounding box visualization enabled / disabled. More... | |
void | setClearColorOverride (ColorRGBA colorRGBA) |
Sets clear color override for rendering. More... | |
void | setCullFaceOverride (bool enabled, GraphicsCullMode overriddenCullMode) |
Sets cull mode override. More... | |
void | setDefaultOrthoProjection () const |
Sets default orthogonal projection and viewport for renderer. More... | |
void | setDisableColorWrite (bool setDisabled) |
Sets color write disabled, overrides render pass settings. More... | |
void | setFramebufferCallback (FramebufferCallback callbackFunction) |
Sets callback function for setActiveFrameBuffer. Called each time engine changes framebuffer. More... | |
void | setLogging (bool logging) |
Enables or disables debug log writing. More... | |
void | setOverrideMaterial (MaterialSharedPtr material) |
Sets current override material, which is used instead of all default materials. Setting material to 0 disables overrides. More... | |
void | setOverrideMaterialCallback (OverrideMaterialCallback callbackFunction, void *userData) |
Set override material callback. Pass 0 to disable. More... | |
void | setSkeletonVisualizationEnabled (bool enabled) |
Sets skeleton visualization enabled / disabled. More... | |
void | setSubRectangleProjection (RectangleFloat subRectangle) |
Turn on sub-rectangle of what would be the normal projection with given relative parameters. More... | |
~Renderer3D ()=default | |
Static Public Member Functions | |
static void | addVertexAndNormalToFloatArrays (Vector3 vertex, Vector3 normal, float *&vertexArray, float *&normalArray) |
Adds a vertex and a normal to their destination arrays. More... | |
static void | addVertexToFloatArray (Vector3 vertex, float *&destinationArray) |
Adds a vertex to the destination array from the given vertex pointer. More... | |
static Vector3 | calculateNormal (Vector3 rightPoint, Vector3 middlePoint, Vector3 upPoint) |
Calculates normal for plane defined by three points. More... | |
Renderer is the core component for assigning lights, meshes, cameras, skin animations etc. to lower level rendering.
typedef MaterialSharedPtr(* kanzi::Renderer3D::OverrideMaterialCallback) (Node *node, MaterialSharedPtr material, size_t cluster, void *userData) |
Callback function for override materials.
typedef void(* kanzi::Renderer3D::FramebufferCallback) (unsigned int framebufferHandle) |
Callback prototype for setActiveFramebuffer.
|
explicit |
|
default |
void kanzi::Renderer3D::setLogging | ( | bool | logging | ) |
Enables or disables debug log writing.
void kanzi::Renderer3D::reset | ( | ) |
Resets renderer, that is, puts it to initial state.
void kanzi::Renderer3D::beginFrame | ( | ) |
Resets user renderer for frame, that is, clear property stack and core renderer per-frame variables.
void kanzi::Renderer3D::endFrame | ( | ) |
Ends a frame.
unsigned int kanzi::Renderer3D::getFrameCount | ( | ) | const |
Gets number of frames rendered by renderer.
void kanzi::Renderer3D::printInfo | ( | ) | const |
Ends frame for renderer.
void kanzi::Renderer3D::drawBuffers | ( | Mesh * | mesh, |
Node * | baseNode, | ||
unsigned int | cluster, | ||
const Material & | material | ||
) |
Applies transformation and draws vertex and index buffers with current settings.
void kanzi::Renderer3D::drawBuffers | ( | Morph * | morph, |
Node * | baseNode, | ||
unsigned int | cluster, | ||
const Material & | material | ||
) |
ResourceManager* kanzi::Renderer3D::getResourceManager | ( | ) | const |
Gets renderer resource manager.
void kanzi::Renderer3D::applyFixedUniforms | ( | const Material & | material, |
RenderPass * | renderPass, | ||
Node * | node | ||
) |
Apply fixed uniforms related to lights.
Called by applyMaterial(). Should be called by user if applying a material manually. If render pass and node are specified, this function will also execute fixed uniform functions and apply transforms.
material | Material to which to apply the fixed uniforms. |
renderPass | Current render pass of the local context. |
node | Current node of the local context. |
|
inline |
Apply fixed uniforms related to lights.
Called by applyMaterial(). Should be called by user if applying a material manually. Render pass or node are not provided, so neither fixed functions for uniforms or transforms are handled.
material | Material to which to apply the fixed uniforms. |
Applies material to renderer, attaches the shader and uniforms.
Applies material to renderer, attaches the shader and uniforms. Does not allow material which shader has samplers without corresponding texture properties.
void kanzi::Renderer3D::setClearColorOverride | ( | ColorRGBA | colorRGBA | ) |
Sets clear color override for rendering.
void kanzi::Renderer3D::removeClearColorOverride | ( | ) |
Removes clear color override.
optional<ColorRGBA> kanzi::Renderer3D::getClearColorOverride | ( | ) | const |
Gets clear color override from renderer. Returns true if override enabled.
void kanzi::Renderer3D::setCullFaceOverride | ( | bool | enabled, |
GraphicsCullMode | overriddenCullMode | ||
) |
Sets cull mode override.
bool kanzi::Renderer3D::getCullFaceOverride | ( | GraphicsCullMode * | out_overriddenCullMode | ) | const |
Returns cull face override.
void kanzi::Renderer3D::setDisableColorWrite | ( | bool | setDisabled | ) |
Sets color write disabled, overrides render pass settings.
bool kanzi::Renderer3D::isColorWriteDisabled | ( | ) | const |
Returns if color write is disabled.
void kanzi::Renderer3D::setOverrideMaterial | ( | MaterialSharedPtr | material | ) |
Sets current override material, which is used instead of all default materials. Setting material to 0 disables overrides.
MaterialSharedPtr kanzi::Renderer3D::getOverrideClusterMaterial | ( | Node * | node, |
MaterialSharedPtr | clusterMaterial, | ||
size_t | clusterIndex | ||
) | const |
Gets overriding material for given transformed object node and cluster material.
node | Node to get overriding material for. |
clusterMaterial | Cluster material that would be used. |
clusterIndex | Cluster index. |
void kanzi::Renderer3D::setActiveGLGraphicsOutput | ( | GLGraphicsOutput * | glGraphicsOutput | ) |
Sets active GL graphics output for renderer.
Also sets active graphics output.
GLGraphicsOutput* kanzi::Renderer3D::getActiveGLGraphicsOutput | ( | ) | const |
Gets active GL graphics output from renderer.
GraphicsOutput* kanzi::Renderer3D::getActiveGraphicsOutput | ( | ) | const |
Gets active graphics output from renderer.
void kanzi::Renderer3D::setSubRectangleProjection | ( | RectangleFloat | subRectangle | ) |
Turn on sub-rectangle of what would be the normal projection with given relative parameters.
void kanzi::Renderer3D::disableSubRectangleProjection | ( | ) |
Disable sub-rectangle of projection.
float kanzi::Renderer3D::getInheritedAspectRatioMultiplier | ( | ) | const |
Get the multiplier to inherited aspect ratio.
Renderer* kanzi::Renderer3D::getCoreRenderer | ( | ) | const |
Returns core renderer from user renderer.
void kanzi::Renderer3D::setBoundingBoxVisualizationEnabled | ( | bool | enabled | ) |
Sets bounding box visualization enabled / disabled.
bool kanzi::Renderer3D::isBoundingBoxVisualizationEnabled | ( | ) | const |
Returns if bounding box visualization is enabled.
void kanzi::Renderer3D::setSkeletonVisualizationEnabled | ( | bool | enabled | ) |
Sets skeleton visualization enabled / disabled.
bool kanzi::Renderer3D::isSkeletonVisualizationEnabled | ( | ) | const |
Returns if skeleton visualization is enabled.
span<float> kanzi::Renderer3D::getFloatBuffer | ( | ) |
Returns temporary float buffer from renderer.
void kanzi::Renderer3D::setOverrideMaterialCallback | ( | OverrideMaterialCallback | callbackFunction, |
void * | userData | ||
) |
Set override material callback. Pass 0 to disable.
OverrideMaterialCallback kanzi::Renderer3D::getOverrideMaterialCallback | ( | ) | const |
Gets override material callback from renderer, 0 if not enabled.
void* kanzi::Renderer3D::getOverrideMaterialCallbackUserData | ( | ) | const |
Gets override material callback user data from renderer.
void kanzi::Renderer3D::setFramebufferCallback | ( | FramebufferCallback | callbackFunction | ) |
Sets callback function for setActiveFrameBuffer. Called each time engine changes framebuffer.
CompositionStack& kanzi::Renderer3D::getCompositionStack | ( | ) |
Returns the render context stack.
void kanzi::Renderer3D::drawLayerOutlineQuad | ( | float | width, |
float | height, | ||
Material & | material, | ||
float | textureHeight, | ||
float | textureOffset, | ||
ColorRGBA | color, | ||
Matrix4x4 | worldTransformation | ||
) |
void kanzi::Renderer3D::drawBoxSolidNormal | ( | const Box & | box, |
Matrix4x4 | worldTransformation, | ||
const Material & | material | ||
) |
Draws a solid box.
This function draws the box with a triangle strip and with vertices that have normals.
box | The box. |
worldTransformation | The transformation of the box. |
material | The material to use to render the box. |
void kanzi::Renderer3D::drawOrientedBoundingBoxSolidNormal | ( | const OrientedBoundingBox & | orientedBoundingBox, |
const Material & | material | ||
) |
Draws a solid oriented bounding box.
This function draws the box with a triangle strip and with vertices that have normals.
orientedBoundingBox | The oriented bounding box. |
material | The material to use to render the box. |
void kanzi::Renderer3D::drawSelectionIndicator | ( | const Box & | boundingBox, |
Matrix4x4 | worldTransformation, | ||
Material & | material, | ||
ColorRGBA | color | ||
) |
Draws a selection indicator.
The selection indicator is a partial wireframe around an object. Kanzi shows the selection indicator as three short lines at each corner of the bounding box.
boundingBox | The bounding box of the selection. |
worldTransformation | The transformation of the selection. |
material | The material to use to render the selection indicator. |
color | The color that this function passes to the material. |
void kanzi::Renderer3D::drawPrimitives | ( | const float * | vertexList, |
unsigned int | vertexCount, | ||
GraphicsPrimitiveType | type, | ||
Matrix4x4 | worldTransformation, | ||
const Material & | material | ||
) | const |
Draws primitives of the given type.
Takes vertex position data as a parameter.
void kanzi::Renderer3D::drawPrimitivesNormal | ( | const float * | vertexList, |
const float * | normalList, | ||
unsigned int | vertexCount, | ||
GraphicsPrimitiveType | type, | ||
Matrix4x4 | worldTransformation, | ||
const Material & | material | ||
) |
Draws primitives of the given type.
Takes vertex position and normal data as parameters.
void kanzi::Renderer3D::drawLineList | ( | const float * | lineList, |
unsigned int | lineCount, | ||
Matrix4x4 | worldTransformation, | ||
const Material & | material | ||
) | const |
Draws a line list with current settings. Handles only position data.
void kanzi::Renderer3D::drawPrimitiveBufferUntextured | ( | const float * | coordinateBuffer, |
Matrix4x4 | worldTransform, | ||
GraphicsPrimitiveType | type, | ||
unsigned int | count, | ||
const Material & | material | ||
) | const |
Draw primitive buffer.
coordinateBuffer | Coordinate buffer to bind. |
worldTransform | World transformation. |
type | Primitive type to render. |
count | Number of vertices to send. |
material | Material that Kanzi uses to render primitive buffer. |
void kanzi::Renderer3D::drawPrimitiveBufferTextured | ( | const float * | coordinateBuffer, |
const float * | texCoordBuffer, | ||
Matrix4x4 | worldTransform, | ||
GraphicsPrimitiveType | type, | ||
unsigned int | count, | ||
const Material & | material | ||
) | const |
void kanzi::Renderer3D::drawQuad | ( | Vector3 | p1, |
Vector3 | p2, | ||
Vector3 | p3, | ||
Vector3 | p4, | ||
Vector2 | textureSpan, | ||
Material & | material, | ||
optional< ColorRGBA > | color, | ||
Matrix4x4 | worldTransformation | ||
) |
Draws a quad.
void kanzi::Renderer3D::drawLayerQuad | ( | Vector2 | renderOffset, |
Vector2 | renderSize, | ||
Vector2 | contentOffset, | ||
Vector2 | contentSize, | ||
float | depth, | ||
Matrix3x3 | renderTransform, | ||
const Material & | material | ||
) |
Render a layer quad.
Material used for rendering the quad must be applied prior to this call, one way or another.
renderOffset | Quad start offset. |
renderSize | Quad start size. |
contentOffset | Texture coordinate start offset. |
contentSize | Texture coordinate size. |
depth | Render depth. |
renderTransform | Render transformation. |
material | Material that Kanzi uses to render the layer quad. |
void kanzi::Renderer3D::drawLayerQuadWithMaterial | ( | const Material & | material, |
Vector2 | renderOffset, | ||
Vector2 | renderSize, | ||
Vector2 | contentOffset, | ||
Vector2 | contentSize, | ||
float | depth, | ||
Matrix3x3 | renderTransform | ||
) |
Render a layer quad.
material | Material to be applied before rendering the quad. |
renderOffset | Quad start offset. |
renderSize | Quad start size. |
contentOffset | Texture coordinate start offset. |
contentSize | Texture coordinate size. |
depth | Render depth. |
renderTransform | Render transformation. |
void kanzi::Renderer3D::drawUntexturedLayerQuad | ( | Vector2 | renderOffset, |
Vector2 | renderSize, | ||
const Material & | material, | ||
Matrix4x4 | worldTransformation | ||
) |
As rendering a layer quad, but omit everything concerning texture coordinates.
void kanzi::Renderer3D::drawViewportQuadWithTextureSpan | ( | Vector2 | offset, |
Vector2 | limits, | ||
Material & | material, | ||
TextureSharedPtr | texture | ||
) |
void kanzi::Renderer3D::drawViewportQuadWithTextureSpan | ( | Vector2 | offset, |
Vector2 | limits, | ||
Material & | material, | ||
TextureSharedPtr | texture, | ||
ColorRGBA | color | ||
) |
void kanzi::Renderer3D::drawViewportQuadWithTextureSpan | ( | Vector2 | offset, |
Vector2 | limits, | ||
Material & | material, | ||
Vector2 | textureSpan, | ||
ColorRGBA | color | ||
) |
Draws viewport quad, fills with given pattern.
Provided texture coordinates are used, specified color is passed to material.
offset | Position of quad. |
limits | Size of quad. |
material | Material to use. |
textureSpan | Area of texture to use. |
color | Color that is passed to the material. |
void kanzi::Renderer3D::applyStencilSettings | ( | bool | stencilTestEnabled, |
unsigned int | stencilRef, | ||
unsigned int | stencilMask, | ||
GraphicsCompareFunction | stencilFunction, | ||
GraphicsStencilOperation | stencilOperationStencilFail, | ||
GraphicsStencilOperation | stencilOperationStencilPassDepthFail, | ||
GraphicsStencilOperation | stencilOperationStencilPassDepthPass | ||
) | const |
Applies stencil settings with overrides for rendering.
void kanzi::Renderer3D::setDefaultOrthoProjection | ( | ) | const |
Sets default orthogonal projection and viewport for renderer.
bool kanzi::Renderer3D::applyColorMaterial | ( | const Node * | node, |
Material & | material, | ||
ColorRGBA | color | ||
) |
Applies the given material with the given emissive color.
void kanzi::Renderer3D::drawCamera | ( | const Camera * | cameraNode, |
Material & | material, | ||
Matrix4x4 | worldTransformation | ||
) |
Draws a wire frame camera symbol.
void kanzi::Renderer3D::drawTrajectory | ( | Trajectory * | trajectory, |
Material & | material, | ||
Matrix4x4 | worldTransformation, | ||
Matrix4x4 | arrangeTransform, | ||
Vector3 | scaling | ||
) |
Draws a trajectory with wire frame lines.
void kanzi::Renderer3D::drawBoxSolidNormal | ( | Vector3 | backBottomLeft, |
Vector3 | frontTopRight, | ||
Material & | material, | ||
ColorRGBA | color, | ||
Matrix4x4 | worldTransform | ||
) |
Draws a solid box given by two opposite corner points.
The corner points are assumed axis-aligned and are transformed with the given transform before drawing. Uses the current rendering settings.
|
inlinestatic |
Calculates normal for plane defined by three points.
|
inlinestatic |
Adds a vertex to the destination array from the given vertex pointer.
|
inlinestatic |
Adds a vertex and a normal to their destination arrays.