Skip to content

Kuesa::Qt3D::ForwardRenderer

Module: Kuesa Qt 3D API

Implements a simple forward rendering FrameGraph. More...

#include <forwardrenderer.h>

Inherits from Kuesa::Qt3D::View, Qt3DRender::QFrameGraphNode

Public Slots

Name
void setRenderSurface(QObject * renderSurface)
void setClearBuffers(Qt3DRender::QClearBuffers::BufferType clearBuffers)
void setShowDebugOverlay(bool showDebugOverlay)
void addView(View * view)
void removeView(View * view)
void dump()

Public Signals

Name
void renderSurfaceChanged(QObject * renderSurface)
void clearBuffersChanged(Qt3DRender::QClearBuffers::BufferType clearBuffers)
void showDebugOverlayChanged(bool showDebugOverlay)
void externalRenderTargetSizeChanged(const QSize & renderTargetSize)

Public Functions

Name
ForwardRenderer(Qt3DCore::QNode * parent =nullptr)
~ForwardRenderer()
QObject * renderSurface() const
Qt3DRender::QClearBuffers::BufferType clearBuffers() const
bool showDebugOverlay() const
const std::vector< View * > & views() const

Public Properties

Name
QObject * renderSurface
Qt3DRender::QClearBuffers::BufferType clearBuffers
bool showDebugOverlay

Friends

Name
class ::tst_ForwardRenderer

Additional inherited members

Protected Types inherited from Kuesa::Qt3D::View

Name
enum Feature { BackToFrontSorting, Skinning, FrustumCulling, ZFilling, Particles}

Public Slots inherited from Kuesa::Qt3D::View

Name
void setViewportRect(const QRectF & viewportRect)
void setCamera(Qt3DCore::QEntity * camera)
void setFrustumCulling(bool frustumCulling)
void setSkinning(bool frustumCulling)
void setBackToFrontSorting(bool backToFrontSorting)
void setZFilling(bool zfilling)
void setParticlesEnabled(bool enabled)
void setReflectionTextureSize(const QSize & reflectionTextureSize)
void setClearColor(const QColor & clearColor)
void setGamma(float gamma)
void setExposure(float exposure)
void setToneMappingAlgorithm(ToneMappingAndGammaCorrectionEffect::ToneMapping toneMappingAlgorithm)
void setUsesStencilMask(bool usesStencilMask)
void addPostProcessingEffect(AbstractPostProcessingEffect * effect)
void removePostProcessingEffect(AbstractPostProcessingEffect * effect)
void addLayer(Qt3DRender::QLayer * layer)
void removeLayer(Qt3DRender::QLayer * layer)
void addReflectionPlane(ReflectionPlane * plane)
void removeReflectionPlane(ReflectionPlane * plane)
void setShadowMaps(const QVector< ShadowMapPtr > & activeShadowMaps)

Public Signals inherited from Kuesa::Qt3D::View

Name
void viewportRectChanged(const QRectF & viewportRect)
void cameraChanged(Qt3DCore::QEntity * camera)
void frustumCullingChanged(bool frustumCulling)
void skinningChanged(bool skinning)
void backToFrontSortingChanged(bool backToFrontSorting)
void zFillingChanged(bool zFilling)
void particlesEnabledChanged(bool enabled)
void reflectionTextureChanged(Qt3DRender::QAbstractTexture * reflectionTexture)
void reflectionTextureSizeChanged(const QSize & reflectionTextureSize)
void clearColorChanged(const QColor & clearColor)
void gammaChanged(float gamma)
void shadowMapsChanged(const QVector< ShadowMapPtr > & shadowMaps)
void exposureChanged(float exposure)
void toneMappingAlgorithmChanged(ToneMappingAndGammaCorrectionEffect::ToneMapping toneMappingAlgorithm)
void usesStencilMaskChanged(bool usesStencilMask)
void frameGraphTreeReconfigured()

Public Functions inherited from Kuesa::Qt3D::View

Name
View(Qt3DCore::QNode * parent =nullptr)
~View()
QRectF viewportRect() const
Qt3DCore::QEntity * camera() const
bool frustumCulling() const
bool skinning() const
bool backToFrontSorting() const
bool zFilling() const
bool particlesEnabled() const
Qt3DRender::QAbstractTexture * reflectionTexture() const
QSize reflectionTextureSize() const
QColor clearColor() const
float exposure() const
float gamma() const
ToneMappingAndGammaCorrectionEffect::ToneMapping toneMappingAlgorithm() const
bool usesStencilMask() const
const std::vector< AbstractPostProcessingEffect * > & postProcessingEffects() const
const std::vector< Qt3DRender::QLayer * > & layers() const
const std::vector< ReflectionPlane * > & reflectionPlanes() const
QVector< ShadowMapPtr > shadowMaps() const

Protected Functions inherited from Kuesa::Qt3D::View

Name
void scheduleFGTreeRebuild()
void rebuildFGTree()
virtual void reconfigureStages()
View * rootView() const
AbstractPostProcessingEffect::FrameGraphNodePtr frameGraphSubtreeForPostProcessingEffect(AbstractPostProcessingEffect * effect) const

Public Properties inherited from Kuesa::Qt3D::View

Name
QRectF viewportRect
Qt3DCore::QEntity * camera
bool frustumCulling
bool skinning
bool backToFrontSorting
bool zFilling
bool particlesEnabled
Qt3DRender::QAbstractTexture * reflectionTexture
QSize reflectionTextureSize
ToneMappingAndGammaCorrectionEffect::ToneMapping toneMappingAlgorithm
bool usesStencilMask
float exposure
float gamma
QColor clearColor

Friends inherited from Kuesa::Qt3D::View

Name
class ViewResolver

Detailed Description

1
class Kuesa::Qt3D::ForwardRenderer;

Implements a simple forward rendering FrameGraph.

Since: Kuesa 2.0

This FrameGraph will select all Qt3D Entities that reference a Material with Techniques having a FilterKey with the name "renderingStyle" set to the string value "forward".

The rendering will be made on a main viewport whose dimensions can be set with normalized coordinates by calling ForwardRenderer::setViewportRect.

The screen will be cleared with the color set by calling ForwardRenderer::setClearColor. By default the clear color is black.

Unless a call to ForwardRenderer::setClearBuffers has been made, only the color and depth buffers will be cleared before the rest of the scene is rendered.

The scene will be rendered from the camera set with ForwardRenderer::setCamera on the window or offscreen surface set by calling ForwardRenderer::setRenderSurface. Additionally ForwardRenderer::setExternalRenderTargetSize can be called to specify the size of the rendering surface, when different from the size reported by the surface, this can be the case with high DPI screens.

Frustum culling of Entities will be performed by default to only render entities that are visible within the camera's frustum. This can be disabled by calling ForwardRenderer::setFrustumCulling. Please note frustum culling is not performed on skinned meshes.

By default the rendering is performed so that:

Opaque object are rendered first: Entities having a Material with a compatible RenderPass that has a FilterKey KuesaDrawStage with a value set to Opaque will be rendered.

Transparent objects are rendered second: select all Entities having a Material with a compatible RenderPass that has a FilterKey KuesaDrawStage with a value set to Transparent will be rendered.

Scenes containing materials with transparency need to be drawn from back-to-front in relation to the Camera for the blending to work correctly. This sorting can be expensive and is disabled by default. It can be enabled by calling ForwardRenderer::setBackToFrontSorting.

In some case, an optimization technique known as an early z-filling pass can provide a significant performance gain. This is especially true for large scenes using complex rendering materials. The idea consist in filling the depth buffer with a low complexity shader so that subsequent passes incorporating more detailed rendering techniques only render fragments for the depth previously recorded. The optional z-fill pass can be enabled by calling ForwardRenderer::setZFilling. All Entities having a Material with a compatible RenderPass that has a FilterKey KuesaDrawStage with a value set to ZFill will be rendered. This will take place before the Opaque and Transparent pass. Only Opaque objects should be used to fill the depth buffer.

The pipeline steps, from materials to post processing effects are working in linear color space. This ForwardRenderer adds a final gamma correction to perform the final conversion to sRGB, through the use of the GammaCorrectionEffect, as the last step of this pipeline.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include <Qt3DExtras/Qt3DWindow>
#include <Qt3DRender/QCamera>
#include <ForwardRenderer>
#include <SceneEntity>
#include <BloomEffect>

Qt3DExtras::Qt3DWindow win;
Kuesa::Qt3D::SceneEntity *root = new Kuesa::Qt3D::SceneEntity();
Kuesa::Qt3D::ForwardRenderer *frameGraph = new Kuesa::Qt3D::ForwardRenderer();
Kuesa::Qt3D::BloomEffect *bloomEffect = new Kuesa::Qt3D::BloomEffect();
Qt3DRender::QCamera *camera = new Qt3DRender::QCamera();

frameGraph->setCamera(camera);
frameGraph->setFrustumCulling(true);
frameGraph->setClearColor(QColor(Qt::red));
frameGraph->addPostProcessingEffect(bloomEffect);

win->setRootEntity(root);
win->setActiveFrameGraph(frameGraph);

...

Public Slots Documentation

slot setRenderSurface

1
2
3
void setRenderSurface(
    QObject * renderSurface
)

Sets the surface where rendering will occur to renderSurface. This can be an offscreen surface or a window surface.

slot setClearBuffers

1
2
3
void setClearBuffers(
    Qt3DRender::QClearBuffers::BufferType clearBuffers
)

Sets which clearBuffers will be cleared at the start of each frame.

slot setShowDebugOverlay

1
2
3
void setShowDebugOverlay(
    bool showDebugOverlay
)

slot addView

1
2
3
void addView(
    View * view
)

slot removeView

1
2
3
void removeView(
    View * view
)

slot dump

1
void dump()

Dumps the FrameGraph tree to the console. Can be really convenient for debug or troubleshooting purposes.

Public Signals Documentation

signal renderSurfaceChanged

1
2
3
void renderSurfaceChanged(
    QObject * renderSurface
)

signal clearBuffersChanged

1
2
3
void clearBuffersChanged(
    Qt3DRender::QClearBuffers::BufferType clearBuffers
)

signal showDebugOverlayChanged

1
2
3
void showDebugOverlayChanged(
    bool showDebugOverlay
)

signal externalRenderTargetSizeChanged

1
2
3
void externalRenderTargetSizeChanged(
    const QSize & renderTargetSize
)

Public Functions Documentation

function ForwardRenderer

1
2
3
explicit ForwardRenderer(
    Qt3DCore::QNode * parent =nullptr
)

function ~ForwardRenderer

1
~ForwardRenderer()

function renderSurface

1
QObject * renderSurface() const

Returns the surface where rendering will occur.

function clearBuffers

1
Qt3DRender::QClearBuffers::BufferType clearBuffers() const

Returns which buffers are cleared at the start of each frame.

function showDebugOverlay

1
bool showDebugOverlay() const

function views

1
const std::vector< View * > & views() const

Public Property Documentation

property renderSurface

1
QObject * renderSurface;

Holds the surface where rendering will occur.

property clearBuffers

1
Qt3DRender::QClearBuffers::BufferType clearBuffers;

Holds which buffers will be cleared at the start of each frame.

property showDebugOverlay

1
bool showDebugOverlay;

Friends

friend ::tst_ForwardRenderer

1
2
3
friend class ::tst_ForwardRenderer(
    ::tst_ForwardRenderer 
);

Updated on 2023-07-03 at 11:02:12 +0000