An interface for specialized brush renderers, which implement brush rendering. More...
#include <kanzi/core.ui/graphics2d/brush_renderer.hpp>
Public Types | |
enum | RenderMode { RenderModeNone, RenderModeContent, RenderModeNoContent } |
Enum signifying currently selected render mode. More... | |
Public Member Functions | |
MaterialSharedPtr | acquireErrorMaterial () |
Acquires an error material for rendering. More... | |
void | attachMaterial (MaterialSharedPtr material) |
Attaches a custom material. More... | |
void | bind (Renderer3D &renderer, PropertyObject *object) |
Binds a brush renderer for rendering. More... | |
void | bind (Renderer3D &renderer) |
Binds a brush renderer for rendering. More... | |
void | draw (Renderer &renderer, const Geometry &quad, const Matrix4x4 &transform) |
Draws a brush using a given quad. More... | |
void | draw (Renderer &renderer, const Geometry &quad, const Matrix3x3 &transform) |
Overload for drawing a brush using a given quad. More... | |
optional< int > | getBlendModeOverride () const |
Gets the blend mode override value. More... | |
int | getBlendModeValue () const |
Gets the last used blend mode value. More... | |
Brush * | getBrush () const |
Gets the brush for which Kanzi created this brush renderer. More... | |
TextureSharedPtr | getContentTexture () const |
Gets the content texture used by the brush renderer. More... | |
MaterialSharedPtr | getMaterial () const |
Gets the currently set material for the renderer. More... | |
Node * | getNode () const |
Gets the attached node. More... | |
bool | getOpaquenessHint () const |
Gets the opaqueness hint value. More... | |
unsigned int | getPropertyChangeCounter () const |
Gets the brush property change counter. More... | |
RenderMode | getRenderMode () const |
Gets the currently selected render mode. More... | |
float | getRenderOpacity () const |
Gets the render opacity. More... | |
GlRenderState & | getRenderState () |
Gets the internal render state. More... | |
void | invalidateRenderValues () |
Invalidates all render values. More... | |
bool | isOpaque () const |
Indicates whether the rendered brush is opaque. More... | |
bool | isRenderable () const |
Indicates whether a brush is in a renderable state. More... | |
void | restoreResources () |
Restores resources after sleep. More... | |
void | setBlendModeOverride (optional< int > blendMode) |
Sets the blend mode override value. More... | |
void | setContentTexture (TextureSharedPtr texture) |
Sets the content texture for the brush renderer. More... | |
void | setOpaquenessHint (bool value) |
Sets the opaqueness hint. More... | |
void | setRenderOpacity (float opacity) |
Sets the render opacity to use for the next attach. More... | |
void | updateRender () |
Prepares a brush for rendering. More... | |
virtual | ~BrushRenderer ()=default |
Destructor. More... | |
Protected Member Functions | |
virtual bool | bindOverride (Renderer3D &renderer, PropertyObject *object) |
BrushRenderer-specific bind implementation. More... | |
BrushRenderer (Brush *brush, Node *node) | |
Constructor. More... | |
virtual void | drawOverride (Renderer &renderer, const Geometry &geometry, const Matrix4x4 &transform)=0 |
Draws geometry using the brush. More... | |
virtual bool | isChangeCounterSame () |
Checks whether the property change counter matches that of the brush. More... | |
virtual void | restoreResourcesOverride () |
BrushRenderer-specific restore resources implementation. More... | |
virtual void | setContentTextureOverride (TextureSharedPtr texture) |
BrushRenderer-specific update of the content texture. More... | |
void | setRenderMode (RenderMode selection) |
Sets the render mode. More... | |
virtual void | updateChangeCounter () |
Updates the property change counter to match the counter value from the brush. More... | |
virtual void | updateRenderOverride ()=0 |
BrushRenderer-specific opacity override implementation. More... | |
Protected Attributes | |
Brush * | m_brush |
Brush attached to. More... | |
unsigned int | m_brushPropertyChangeCounter |
Property change counter to track brush. More... | |
TextureSharedPtr | m_contentTexture |
Content texture provided to the brush renderer from outside. For example, from Node2D. More... | |
GlRenderState::HandleType | m_contentTextureHandle |
Render value handle. More... | |
bool | m_isRenderable |
Indicates whether the last bind() call was successful and the brush can be rendered. More... | |
Node * | m_node |
Node attached to. More... | |
RenderMode | m_renderMode |
Currently used render mode (or none if not selected). More... | |
float | m_renderOpacity |
Render opacity provided to the brush renderer from outside. For example, from Node2D. More... | |
GlRenderState::HandleType | m_renderOpacityHandle |
Render value handle. More... | |
GlRenderState | m_renderState |
Contained render state. More... | |
GlRenderValueBinding | m_renderValueBinding |
Property binding handler. More... | |
An interface for specialized brush renderers, which implement brush rendering.
You can use the BrushRenderer to render a brush manually.
To render a brush manually:
Call setContentTexture() to set the content texture for the brush renderer.
You must do this before you call updateRender().
Call updateRender() to prepare the brush for rendering.
You must call updateRender() once after you set the content texture and before you bind the brush renderer for rendering. You do not need to call this function every time after changing the content texture, unless you change the content texture to or from nullptr.
Call setRenderOpacity() to set the render opacity.
You can do this before or after calling updateRender().
(Optional) If you want to set the blend mode as determined by layouting, call setBlendModeOverride().
This function takes precedence over the blend mode that the renderer reads from the brush.
(Optional) If you want to indicate that a node can be rendered using opaque blend mode, call setOpaquenessHint().
For example, this happens when a node is rendered as the bottom-most element in a framebuffer.
To draw with the brush, call draw().
After you call bind(), you can call draw() multiple times for different geometries and transformations.
For example:
|
virtualdefault |
Destructor.
Constructor.
node | The node to which to attach the renderer. |
brush | The brush to which to attach the renderer. |
|
inline |
Prepares a brush for rendering.
Called from Node2D::updateRender(), which calls NodeVisual2D::updateRender(). Kanzi calls this function during layout.
Call this function after the brush material or attached nodes change. Unlike bind(), you do not need to call updateRender() every frame before draw().
If the render mode of a brush does not change, implementations of this function do nothing.
blendMode
parameter. forceOpaque
parameter. blendMode
and translucencyHint
parameters.
|
inline |
Binds a brush renderer for rendering.
You must call this function before you call draw(). This function sets the renderable flag that you can query with isRenderable().
renderer | The renderer to use. |
object | The object from which to fetch properties. |
|
inline |
Binds a brush renderer for rendering.
You must call this function before you call draw(). This function sets the renderable flag that you can query with isRenderable().
renderer | Renderer to use. |
void kanzi::BrushRenderer::draw | ( | Renderer & | renderer, |
const Geometry & | quad, | ||
const Matrix4x4 & | transform | ||
) |
Draws a brush using a given quad.
renderer | Renderer to use. |
quad | Quad to draw. |
transform | The transform as a 4x4 matrix to use. |
|
inline |
Overload for drawing a brush using a given quad.
renderer | Renderer to use. |
quad | Quad to draw. |
transform | The transform as a 3x3 matrix to use. |
|
inline |
Restores resources after sleep.
|
inline |
Gets the brush for which Kanzi created this brush renderer.
|
inline |
Gets the internal render state.
|
inline |
Invalidates all render values.
MaterialSharedPtr kanzi::BrushRenderer::acquireErrorMaterial | ( | ) |
Acquires an error material for rendering.
Kanzi uses this function internally when the assigned material is not applicable.
|
inline |
Gets the brush property change counter.
|
inline |
Gets the render opacity.
|
inline |
Sets the render opacity to use for the next attach.
opacity | New render opacity. |
|
inline |
Gets the content texture used by the brush renderer.
|
inline |
Sets the content texture for the brush renderer.
texture | The content texture. |
|
inline |
Gets the currently selected render mode.
|
inline |
Indicates whether a brush is in a renderable state.
To set the renderable flag, call bind().
MaterialSharedPtr kanzi::BrushRenderer::getMaterial | ( | ) | const |
Gets the currently set material for the renderer.
int kanzi::BrushRenderer::getBlendModeValue | ( | ) | const |
Gets the last used blend mode value.
This function is intended for tests.
|
inline |
Sets the blend mode override value.
This is the blend mode as determined by layouting. Calling this function has precedence over the blend mode read from brush or material.
blendMode | Blend mode. |
|
inline |
Gets the blend mode override value.
This function is intended for tests.
|
inline |
Sets the opaqueness hint.
This hint indicates whether a node can be rendered using opaque blend mode. For example, this happens when a node is rendered as the bottom-most element in a framebuffer.
value | Opaqueness hint value. |
|
inline |
Gets the opaqueness hint value.
This function is intended for tests.
|
inline |
Indicates whether the rendered brush is opaque.
void kanzi::BrushRenderer::attachMaterial | ( | MaterialSharedPtr | material | ) |
Attaches a custom material.
This function internally calls BrushRenderer::attachMaterial().
material | The material to attach. |
|
protectedpure virtual |
Draws geometry using the brush.
To be implemented by specific brush implementations.
renderer | Renderer to use. |
geometry | Quad to draw. |
transform | Transform to use. |
Implemented in kanzi::TextureBrushRenderer, kanzi::ColorBrushRenderer, kanzi::MaterialBrushRenderer, and kanzi::ContentBrushRenderer.
|
protectedvirtual |
BrushRenderer-specific bind implementation.
renderer | Renderer to use. |
object | The object from which to fetch properties. |
object
. Reimplemented in kanzi::TextureBrushRenderer, kanzi::ColorBrushRenderer, and kanzi::ContentBrushRenderer.
|
protectedpure virtual |
BrushRenderer-specific opacity override implementation.
blendMode
parameter. forceOpaque
parameter. blendMode
and translucencyHint
parameters. Implemented in kanzi::TextureBrushRenderer, kanzi::ColorBrushRenderer, kanzi::MaterialBrushRenderer, and kanzi::ContentBrushRenderer.
|
protectedvirtual |
BrushRenderer-specific restore resources implementation.
|
inlineprotectedvirtual |
BrushRenderer-specific update of the content texture.
texture | New renderer texture. |
|
inlineprotected |
Sets the render mode.
selection | The render mode to set. |
|
protectedvirtual |
Checks whether the property change counter matches that of the brush.
Reimplemented in kanzi::MaterialBrushRenderer.
|
protectedvirtual |
Updates the property change counter to match the counter value from the brush.
Reimplemented in kanzi::MaterialBrushRenderer.
|
protected |
Brush attached to.
|
protected |
Currently used render mode (or none if not selected).
|
protected |
Contained render state.
|
protected |
Property binding handler.
|
protected |
Render value handle.
|
protected |
Render value handle.
|
protected |
Content texture provided to the brush renderer from outside. For example, from Node2D.
|
protected |
Render opacity provided to the brush renderer from outside. For example, from Node2D.
|
protected |
Property change counter to track brush.
|
protected |
Indicates whether the last bind() call was successful and the brush can be rendered.
The return value from bindOverride() is written here.