Nebula
Loading...
Searching...
No Matches
RmlUi::RmlUiRenderInterface Class Reference

#include <rmluirenderinterface.h>

Detailed Description

Implements the RmlUi render interface on top of CoreGraphics, modelled on RmlUi's GL3 reference renderer.

RmlUi renders into its own offscreen targets in the StaticUI subgraph, outside of any frame script pass, so the renderer can switch targets for layers and filters. Every target shares one stencil buffer, which holds the clip masks. The result is composited onto the color buffer in the StaticUI To Backbuffer subgraph (Present).

The targets are unorm RGBA8 and all blending happens with premultiplied alpha in sRGB space, which is what RmlUi's reference renderers do. Present converts to linear for the sRGB color buffer.

Supported: geometry, textures, scissor, transforms, clip masks, layers, filters (opacity, blur, drop-shadow, color matrices, mask-image), gradient shaders and render-to-texture (box-shadow).

Inherits Rml::RenderInterface.

Classes

struct  Geometry
struct  Texture
struct  RenderTarget
struct  FrameBuffers
struct  DrawParams

Public Member Functions

 RmlUiRenderInterface ()
 constructor
 ~RmlUiRenderInterface () override
 destructor
void Setup ()
 setup GPU resources
void Discard ()
 discard GPU resources
void CreatePresentPipeline (const CoreGraphics::RenderPassId pass)
 (re)create the present pipeline for the frame script pass the UI is composited in
void BeginFrame (const CoreGraphics::CmdBufferId frameCmdBuf, const Math::rectangle< int > &viewport, const IndexT frameBufferIndex)
 start rendering a frame into the UI targets, called outside of any pass
void EndFrame ()
 finish rendering the frame, leaves the UI readable
void Present (const CoreGraphics::CmdBufferId cmdBuf, const Math::rectangle< int > &viewport)
 composite the UI onto the current pass, called inside the frame script pass
Rml::CompiledGeometryHandle CompileGeometry (Rml::Span< const Rml::Vertex > vertices, Rml::Span< const int > indices) override
 Rml::RenderInterface.
void RenderGeometry (Rml::CompiledGeometryHandle geometry, Rml::Vector2f translation, Rml::TextureHandle texture) override
void ReleaseGeometry (Rml::CompiledGeometryHandle geometry) override
Rml::TextureHandle LoadTexture (Rml::Vector2i &textureDimensions, const Rml::String &source) override
 Sources containing a URN of type tex (folder:file:tex) go through the resource server, anything else is read as an image file (png, tga, jpg...).
Rml::TextureHandle GenerateTexture (Rml::Span< const Rml::byte > source, Rml::Vector2i sourceDimensions) override
 RmlUi hands over premultiplied RGBA8 (font atlases, gradients...), which is what the renderer works with.
void ReleaseTexture (Rml::TextureHandle texture) override
void EnableScissorRegion (bool enable) override
void SetScissorRegion (Rml::Rectanglei region) override
void EnableClipMask (bool enable) override
void RenderToClipMask (Rml::ClipMaskOperation operation, Rml::CompiledGeometryHandle geometry, Rml::Vector2f translation) override
 Same scheme as RmlUi's GL3 renderer: Set clears the stencil and writes 1, SetInverse clears to 1 and writes 0, Intersect increments.
void SetTransform (const Rml::Matrix4f *transform) override
 RmlUi matrices are column major with translation in elements 12-14, which is the memory layout of Math::mat4.
Rml::LayerHandle PushLayer () override
void CompositeLayers (Rml::LayerHandle source, Rml::LayerHandle destination, Rml::BlendMode blendMode, Rml::Span< const Rml::CompiledFilterHandle > filters) override
void PopLayer () override
Rml::TextureHandle SaveLayerAsTexture () override
 Copies the scissor region of the top layer into a new texture, used by RmlUi for box-shadow.
Rml::CompiledFilterHandle SaveLayerAsMaskImage () override
Rml::CompiledFilterHandle CompileFilter (const Rml::String &name, const Rml::Dictionary &parameters) override
 Filter parameters as in RmlUi's GL3 renderer.
void ReleaseFilter (Rml::CompiledFilterHandle filter) override
Rml::CompiledShaderHandle CompileShader (const Rml::String &name, const Rml::Dictionary &parameters) override
 Linear, radial and conic gradients (repeating or not).
void RenderShader (Rml::CompiledShaderHandle shader, Rml::CompiledGeometryHandle geometry, Rml::Vector2f translation, Rml::TextureHandle texture) override
void ReleaseShader (Rml::CompiledShaderHandle shader) override

Private Types

enum  Program {
  Program_Draw , Program_DrawClip , Program_Gradient , Program_GradientClip ,
  Program_ClipReplace , Program_ClipIncrement , Program_CopyReplace , Program_CopyBlend ,
  Program_CopyBlendClip , Program_ColorMatrix , Program_BlendMask , Program_Blur ,
  Program_DropShadow , Program_NumPrograms
}

Private Member Functions

void CreateTarget (RenderTarget &target, const char *name)
 create a render target of the current size, with the shared stencil attached
void DestroyTarget (RenderTarget &target)
 destroy a render target
void DestroyTargets ()
 destroy all size dependent resources
void Transition (RenderTarget &target, CoreGraphics::PipelineStage stage)
 move a target to a stage, ends the active pass if a barrier is needed
void BindTarget (RenderTarget &target, bool clear)
 make the target the active render target, clearing it if asked
void EndActivePass ()
 end the active pass, if any
void EnsureTopLayer ()
 bind the top layer if no other target is active
void CopyTarget (RenderTarget &from, RenderTarget &to)
 copy a whole target to another
void ApplyScissor ()
 apply the scissor to the active pass
uint AllocDraw (const Rmlui::RmlUiDraw &draw)
 write per-draw data, returns its index
void Draw (const Rml::Vertex *vertices, SizeT numVertices, const int *indices, SizeT numIndices, Rml::Vector2f translation, const DrawParams &params)
 stream geometry and draw it into the active target
void DrawFullscreen (const DrawParams &params, Rml::Vector2f uvOffset=Rml::Vector2f(0.0f), Rml::Vector2f uvScale=Rml::Vector2f(1.0f))
 draw a quad covering the target, sampling the given uv range
void SetStencil (uint reference)
 set the stencil reference for the next draws
void RenderBlur (float sigma, RenderTarget &sourceDestination, RenderTarget &temp, const Rml::Rectanglei window)
 gaussian blur, sourceDestination keeps the result
Rml::Rectanglei GetScissorOrTarget () const
 the active scissor, or the whole target
void EnsureCapacity (SizeT numVertices, SizeT numIndices)
 grow the current frame buffers to hold at least this many vertices and indices

Static Private Member Functions

static CoreGraphics::BufferId CreateStreamBuffer (const char *name, CoreGraphics::BufferUsage usage, SizeT elementSize, SizeT numElements, byte *&outPtr)
 create a buffer and map it

Private Attributes

CoreGraphics::ShaderId shader
CoreGraphics::ShaderProgramId programs [Program_NumPrograms]
CoreGraphics::ShaderProgramId presentProgram
CoreGraphics::PipelineId presentPipeline
CoreGraphics::VertexLayoutId vertexLayout
Util::FixedArray< FrameBuffers > frames
SizeT width
SizeT height
CoreGraphics::TextureId stencil
CoreGraphics::TextureViewId stencilView
CoreGraphics::PipelineStage stencilStage
Util::Array< RenderTarget * > layers
SizeT numLayers
RenderTarget postprocess [4]
 primary, secondary, tertiary and blend mask
CoreGraphics::CmdBufferId cmdBuf
IndexT bufferIndex
SizeT vertexOffset
SizeT indexOffset
SizeT drawCount
bool frameActive
RenderTarget * activeTarget
Program activeProgram
bool scissorEnabled
Rml::Rectanglei scissor
bool clipMaskEnabled
uint stencilTestValue
Math::mat4 projection
Math::mat4 transform
SizeT presentVertexOffset
SizeT presentIndexOffset
bool presentReady

Member Enumeration Documentation

◆ Program

Enumerator
Program_Draw 
Program_DrawClip 
Program_Gradient 
Program_GradientClip 
Program_ClipReplace 
Program_ClipIncrement 
Program_CopyReplace 
Program_CopyBlend 
Program_CopyBlendClip 
Program_ColorMatrix 
Program_BlendMask 
Program_Blur 
Program_DropShadow 
Program_NumPrograms 

Constructor & Destructor Documentation

◆ RmlUiRenderInterface()

RmlUi::RmlUiRenderInterface::RmlUiRenderInterface ( )

constructor

◆ ~RmlUiRenderInterface()

RmlUi::RmlUiRenderInterface::~RmlUiRenderInterface ( )
override

destructor

Member Function Documentation

◆ AllocDraw()

uint RmlUi::RmlUiRenderInterface::AllocDraw ( const Rmlui::RmlUiDraw & draw)
private

write per-draw data, returns its index

◆ ApplyScissor()

void RmlUi::RmlUiRenderInterface::ApplyScissor ( )
private

apply the scissor to the active pass

◆ BeginFrame()

void RmlUi::RmlUiRenderInterface::BeginFrame ( const CoreGraphics::CmdBufferId frameCmdBuf,
const Math::rectangle< int > & viewport,
const IndexT frameBufferIndex )

start rendering a frame into the UI targets, called outside of any pass

◆ BindTarget()

void RmlUi::RmlUiRenderInterface::BindTarget ( RenderTarget & target,
bool clear )
private

make the target the active render target, clearing it if asked

◆ CompileFilter()

Rml::CompiledFilterHandle RmlUi::RmlUiRenderInterface::CompileFilter ( const Rml::String & name,
const Rml::Dictionary & parameters )
override

Filter parameters as in RmlUi's GL3 renderer.

◆ CompileGeometry()

Rml::CompiledGeometryHandle RmlUi::RmlUiRenderInterface::CompileGeometry ( Rml::Span< const Rml::Vertex > vertices,
Rml::Span< const int > indices )
override

Rml::RenderInterface.

◆ CompileShader()

Rml::CompiledShaderHandle RmlUi::RmlUiRenderInterface::CompileShader ( const Rml::String & name,
const Rml::Dictionary & parameters )
override

Linear, radial and conic gradients (repeating or not).

◆ CompositeLayers()

void RmlUi::RmlUiRenderInterface::CompositeLayers ( Rml::LayerHandle source,
Rml::LayerHandle destination,
Rml::BlendMode blendMode,
Rml::Span< const Rml::CompiledFilterHandle > filters )
override

◆ CopyTarget()

void RmlUi::RmlUiRenderInterface::CopyTarget ( RenderTarget & from,
RenderTarget & to )
private

copy a whole target to another

◆ CreatePresentPipeline()

void RmlUi::RmlUiRenderInterface::CreatePresentPipeline ( const CoreGraphics::RenderPassId pass)

(re)create the present pipeline for the frame script pass the UI is composited in

◆ CreateStreamBuffer()

CoreGraphics::BufferId RmlUi::RmlUiRenderInterface::CreateStreamBuffer ( const char * name,
CoreGraphics::BufferUsage usage,
SizeT elementSize,
SizeT numElements,
byte *& outPtr )
staticprivate

create a buffer and map it

◆ CreateTarget()

void RmlUi::RmlUiRenderInterface::CreateTarget ( RenderTarget & target,
const char * name )
private

create a render target of the current size, with the shared stencil attached

◆ DestroyTarget()

void RmlUi::RmlUiRenderInterface::DestroyTarget ( RenderTarget & target)
private

destroy a render target

◆ DestroyTargets()

void RmlUi::RmlUiRenderInterface::DestroyTargets ( )
private

destroy all size dependent resources

◆ Discard()

void RmlUi::RmlUiRenderInterface::Discard ( )

discard GPU resources

◆ Draw()

void RmlUi::RmlUiRenderInterface::Draw ( const Rml::Vertex * vertices,
SizeT numVertices,
const int * indices,
SizeT numIndices,
Rml::Vector2f translation,
const DrawParams & params )
private

stream geometry and draw it into the active target

◆ DrawFullscreen()

void RmlUi::RmlUiRenderInterface::DrawFullscreen ( const DrawParams & params,
Rml::Vector2f uvOffset = Rml::Vector2f(0.0f),
Rml::Vector2f uvScale = Rml::Vector2f(1.0f) )
private

draw a quad covering the target, sampling the given uv range

◆ EnableClipMask()

void RmlUi::RmlUiRenderInterface::EnableClipMask ( bool enable)
override

◆ EnableScissorRegion()

void RmlUi::RmlUiRenderInterface::EnableScissorRegion ( bool enable)
override

◆ EndActivePass()

void RmlUi::RmlUiRenderInterface::EndActivePass ( )
private

end the active pass, if any

◆ EndFrame()

void RmlUi::RmlUiRenderInterface::EndFrame ( )

finish rendering the frame, leaves the UI readable

◆ EnsureCapacity()

void RmlUi::RmlUiRenderInterface::EnsureCapacity ( SizeT numVertices,
SizeT numIndices )
private

grow the current frame buffers to hold at least this many vertices and indices

Grows the buffers of the current frame.

Draws already recorded keep reading from the old buffers, buffer destruction is delayed until the GPU is done.

◆ EnsureTopLayer()

void RmlUi::RmlUiRenderInterface::EnsureTopLayer ( )
private

bind the top layer if no other target is active

◆ GenerateTexture()

Rml::TextureHandle RmlUi::RmlUiRenderInterface::GenerateTexture ( Rml::Span< const Rml::byte > source,
Rml::Vector2i sourceDimensions )
override

RmlUi hands over premultiplied RGBA8 (font atlases, gradients...), which is what the renderer works with.

◆ GetScissorOrTarget()

Rml::Rectanglei RmlUi::RmlUiRenderInterface::GetScissorOrTarget ( ) const
private

the active scissor, or the whole target

◆ LoadTexture()

Rml::TextureHandle RmlUi::RmlUiRenderInterface::LoadTexture ( Rml::Vector2i & textureDimensions,
const Rml::String & source )
override

Sources containing a URN of type tex (folder:file:tex) go through the resource server, anything else is read as an image file (png, tga, jpg...).

◆ PopLayer()

void RmlUi::RmlUiRenderInterface::PopLayer ( )
override

◆ Present()

void RmlUi::RmlUiRenderInterface::Present ( const CoreGraphics::CmdBufferId cmdBuf,
const Math::rectangle< int > & viewport )

composite the UI onto the current pass, called inside the frame script pass

◆ PushLayer()

Rml::LayerHandle RmlUi::RmlUiRenderInterface::PushLayer ( )
override

◆ ReleaseFilter()

void RmlUi::RmlUiRenderInterface::ReleaseFilter ( Rml::CompiledFilterHandle filter)
override

◆ ReleaseGeometry()

void RmlUi::RmlUiRenderInterface::ReleaseGeometry ( Rml::CompiledGeometryHandle geometry)
override

◆ ReleaseShader()

void RmlUi::RmlUiRenderInterface::ReleaseShader ( Rml::CompiledShaderHandle shader)
override

◆ ReleaseTexture()

void RmlUi::RmlUiRenderInterface::ReleaseTexture ( Rml::TextureHandle texture)
override

◆ RenderBlur()

void RmlUi::RmlUiRenderInterface::RenderBlur ( float sigma,
RenderTarget & sourceDestination,
RenderTarget & temp,
const Rml::Rectanglei window )
private

gaussian blur, sourceDestination keeps the result

Port of RmlUi's GL3 blur: downscale by halving for large sigmas, then a separable gaussian, then upscale back into the window.

◆ RenderGeometry()

void RmlUi::RmlUiRenderInterface::RenderGeometry ( Rml::CompiledGeometryHandle geometry,
Rml::Vector2f translation,
Rml::TextureHandle texture )
override

◆ RenderShader()

void RmlUi::RmlUiRenderInterface::RenderShader ( Rml::CompiledShaderHandle shader,
Rml::CompiledGeometryHandle geometry,
Rml::Vector2f translation,
Rml::TextureHandle texture )
override

◆ RenderToClipMask()

void RmlUi::RmlUiRenderInterface::RenderToClipMask ( Rml::ClipMaskOperation operation,
Rml::CompiledGeometryHandle handle,
Rml::Vector2f translation )
override

Same scheme as RmlUi's GL3 renderer: Set clears the stencil and writes 1, SetInverse clears to 1 and writes 0, Intersect increments.

Draws then test for equality with stencilTestValue.

◆ SaveLayerAsMaskImage()

Rml::CompiledFilterHandle RmlUi::RmlUiRenderInterface::SaveLayerAsMaskImage ( )
override

◆ SaveLayerAsTexture()

Rml::TextureHandle RmlUi::RmlUiRenderInterface::SaveLayerAsTexture ( )
override

Copies the scissor region of the top layer into a new texture, used by RmlUi for box-shadow.

◆ SetScissorRegion()

void RmlUi::RmlUiRenderInterface::SetScissorRegion ( Rml::Rectanglei region)
override

◆ SetStencil()

void RmlUi::RmlUiRenderInterface::SetStencil ( uint reference)
private

set the stencil reference for the next draws

◆ SetTransform()

void RmlUi::RmlUiRenderInterface::SetTransform ( const Rml::Matrix4f * transform)
override

RmlUi matrices are column major with translation in elements 12-14, which is the memory layout of Math::mat4.

◆ Setup()

void RmlUi::RmlUiRenderInterface::Setup ( )

setup GPU resources

◆ Transition()

void RmlUi::RmlUiRenderInterface::Transition ( RenderTarget & target,
CoreGraphics::PipelineStage stage )
private

move a target to a stage, ends the active pass if a barrier is needed

Member Data Documentation

◆ activeProgram

Program RmlUi::RmlUiRenderInterface::activeProgram
private

◆ activeTarget

RenderTarget* RmlUi::RmlUiRenderInterface::activeTarget
private

◆ bufferIndex

IndexT RmlUi::RmlUiRenderInterface::bufferIndex
private

◆ clipMaskEnabled

bool RmlUi::RmlUiRenderInterface::clipMaskEnabled
private

◆ cmdBuf

CoreGraphics::CmdBufferId RmlUi::RmlUiRenderInterface::cmdBuf
private

◆ drawCount

SizeT RmlUi::RmlUiRenderInterface::drawCount
private

◆ frameActive

bool RmlUi::RmlUiRenderInterface::frameActive
private

◆ frames

Util::FixedArray<FrameBuffers> RmlUi::RmlUiRenderInterface::frames
private

◆ height

SizeT RmlUi::RmlUiRenderInterface::height
private

◆ indexOffset

SizeT RmlUi::RmlUiRenderInterface::indexOffset
private

◆ layers

Util::Array<RenderTarget*> RmlUi::RmlUiRenderInterface::layers
private

◆ numLayers

SizeT RmlUi::RmlUiRenderInterface::numLayers
private

◆ postprocess

RenderTarget RmlUi::RmlUiRenderInterface::postprocess[4]
private

primary, secondary, tertiary and blend mask

◆ presentIndexOffset

SizeT RmlUi::RmlUiRenderInterface::presentIndexOffset
private

◆ presentPipeline

CoreGraphics::PipelineId RmlUi::RmlUiRenderInterface::presentPipeline
private

◆ presentProgram

CoreGraphics::ShaderProgramId RmlUi::RmlUiRenderInterface::presentProgram
private

◆ presentReady

bool RmlUi::RmlUiRenderInterface::presentReady
private

◆ presentVertexOffset

SizeT RmlUi::RmlUiRenderInterface::presentVertexOffset
private

◆ programs

CoreGraphics::ShaderProgramId RmlUi::RmlUiRenderInterface::programs[Program_NumPrograms]
private

◆ projection

Math::mat4 RmlUi::RmlUiRenderInterface::projection
private

◆ scissor

Rml::Rectanglei RmlUi::RmlUiRenderInterface::scissor
private

◆ scissorEnabled

bool RmlUi::RmlUiRenderInterface::scissorEnabled
private

◆ shader

CoreGraphics::ShaderId RmlUi::RmlUiRenderInterface::shader
private

◆ stencil

CoreGraphics::TextureId RmlUi::RmlUiRenderInterface::stencil
private

◆ stencilStage

CoreGraphics::PipelineStage RmlUi::RmlUiRenderInterface::stencilStage
private

◆ stencilTestValue

uint RmlUi::RmlUiRenderInterface::stencilTestValue
private

◆ stencilView

CoreGraphics::TextureViewId RmlUi::RmlUiRenderInterface::stencilView
private

◆ transform

Math::mat4 RmlUi::RmlUiRenderInterface::transform
private

◆ vertexLayout

CoreGraphics::VertexLayoutId RmlUi::RmlUiRenderInterface::vertexLayout
private

◆ vertexOffset

SizeT RmlUi::RmlUiRenderInterface::vertexOffset
private

◆ width

SizeT RmlUi::RmlUiRenderInterface::width
private

The documentation for this class was generated from the following files: