Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

Commit

Permalink
forwardrenderer test: add 'render into FBO' option, and auto test
Browse files Browse the repository at this point in the history
  • Loading branch information
Wieland Hagen committed Apr 24, 2019
1 parent 4a70893 commit 1b9eca9
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 10 deletions.
30 changes: 30 additions & 0 deletions tests/auto/forwardrenderer/tst_forwardrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,36 @@ private Q_SLOTS:
QCOMPARE(spy.count(), 1);
}

void testChangingRenderTarget()
{
// GIVEN
Kuesa::ForwardRenderer renderer;
qRegisterMetaType<Qt3DRender::QRenderTarget *>("QRenderTarget");
QSignalSpy spy(&renderer, SIGNAL(renderTargetChanged(Qt3DRender::QRenderTarget *)));
QVERIFY(spy.isValid());

// WHEN
Qt3DRender::QRenderTarget newRenderTarget;
renderer.setRenderTarget(&newRenderTarget);

// THEN
QCOMPARE(renderer.renderTarget(), &newRenderTarget);
QCOMPARE(spy.count(), 1);

// WHEN
renderer.setRenderTarget(&newRenderTarget);

// THEN
QCOMPARE(spy.count(), 1);

// WHEN
renderer.setRenderTarget(nullptr);

// THEN
QCOMPARE(renderer.renderTarget(), nullptr);
QCOMPARE(spy.count(), 2);
}

void testChangingClearColor()
{
// GIVEN
Expand Down
73 changes: 73 additions & 0 deletions tests/manual/forwardrenderer_scene/OffscreenEntity.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import Qt3D.Core 2.11
import Qt3D.Render 2.11
import Qt3D.Extras 2.10

Entity {
id: root

property int fboWidth: 1024
property int fboHeight: 1024

property alias layer: offscreenLayer
property alias fbo: renderTarget

Layer {
id: offscreenLayer
}

CuboidMesh {
id: mesh
xExtent: 2.0
yExtent: 2.0
zExtent: 2.0
}

RenderTarget {
id: renderTarget
attachments : [
RenderTargetOutput {
attachmentPoint : RenderTargetOutput.Color0
texture : Texture2D {
id : colorAttachment
width : root.fboWidth
height : root.fboHeight
format : Texture.RGBA8_UNorm
generateMipMaps : false
magnificationFilter : Texture.Linear
minificationFilter : Texture.Linear
wrapMode {
x: WrapMode.ClampToEdge
y: WrapMode.ClampToEdge
}
}
},
RenderTargetOutput {
attachmentPoint : RenderTargetOutput.Depth
texture : Texture2D {
width : root.fboWidth
height : root.fboHeight
format : Texture.D32F
generateMipMaps : false
magnificationFilter : Texture.Linear
minificationFilter : Texture.Linear
wrapMode {
x: WrapMode.ClampToEdge
y: WrapMode.ClampToEdge
}
}
}
]
}

TextureMaterial {
id: material
texture: colorAttachment
}

components: [
offscreenLayer,
mesh,
material
]
}

3 changes: 3 additions & 0 deletions tests/manual/forwardrenderer_scene/controllerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ ControllerWidget::ControllerWidget(SceneController *controller,
connect(ui->alphaBlendingCheckbox, &QCheckBox::toggled,
m_controller, &SceneController::setAlphaBlending);

connect(ui->renderIntoFboCheckBox, &QCheckBox::toggled,
m_controller, &SceneController::setRenderIntoFbo);

connect(ui->frustumCheckBox, &QCheckBox::toggled,
m_controller, &SceneController::setFrustumCulling);

Expand Down
12 changes: 11 additions & 1 deletion tests/manual/forwardrenderer_scene/controllerwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
Expand Down Expand Up @@ -99,6 +99,16 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="renderIntoFboCheckBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Render into FBO</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
3 changes: 2 additions & 1 deletion tests/manual/forwardrenderer_scene/forwardrenderer_scene.pro
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ SOURCES += \
controllerwidget.cpp

OTHER_FILES += \
main.qml
main.qml \
OffscreenEntity.qml

RESOURCES += \
main.qrc
Expand Down
63 changes: 55 additions & 8 deletions tests/manual/forwardrenderer_scene/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,80 @@ import Kuesa.Effects 1.0
Entity {
id: scene

OffscreenEntity {
id: offscreen
enabled: _controller.renderIntoFbo
}

Kuesa.ForwardRenderer {
id: forwardRenderer
camera: mainCamera
backToFrontSorting: _controller.alphaBlending
clearColor: _controller.clearColor
frustumCulling: _controller.frustumCulling
zFilling: _controller.zFill
}

RenderSurfaceSelector {
id: deferredRenderer
// 1st pass: render Kuesa scene into FBO
Kuesa.ForwardRenderer {
id: deferredKuesaRenderer
camera: mainCamera
backToFrontSorting: _controller.alphaBlending
clearColor: _controller.clearColor
frustumCulling: _controller.frustumCulling
zFilling: _controller.zFill
renderTarget: offscreen.fbo
}
// 2nd pass: render quad with scene fbo texture
CameraSelector {
camera: mainCamera
LayerFilter {
layers: [ offscreen.layer ]
filterMode: LayerFilter.AcceptAnyMatchingLayers
ClearBuffers {
buffers: ClearBuffers.ColorDepthBuffer
clearColor: "black"
}
}
}
}

components: [
InputSettings { },
RenderSettings {
Kuesa.ForwardRenderer {
id: renderer
camera: mainCamera
backToFrontSorting: _controller.alphaBlending
clearColor: _controller.clearColor
frustumCulling: _controller.frustumCulling
zFilling: _controller.zFill
}
activeFrameGraph: _controller.renderIntoFbo ? deferredRenderer : forwardRenderer
}
]

function enablePostProcessingEffect(effect, enable) {
var renderer = _controller.renderIntoFbo ? deferredKuesaRenderer : forwardRenderer
if (enable)
renderer.addPostProcessingEffect(effect);
else
renderer.removePostProcessingEffect(effect);
}

function movePostProcessingEffect(oldFG, newFG, effect) {
oldFG.removePostProcessingEffect(effect);
newFG.addPostProcessingEffect(effect);
}

Connections {
target: _controller
onThresholdEffectChanged: enablePostProcessingEffect(thresholdComponent, _controller.thresholdEffect)
onBloomEffectChanged: enablePostProcessingEffect(bloomComponent, _controller.bloomEffect)
onBlurEffectChanged: enablePostProcessingEffect(blurComponent, _controller.blurEffect)
onOpacityMaskEffectChanged: enablePostProcessingEffect(opacityMaskComponent, _controller.opacityMaskEffect)
onRenderIntoFboChanged: {
var oldKuesaRenderer = _controller.renderIntoFbo ? forwardRenderer : deferredKuesaRenderer
var newKuesaRenderer = _controller.renderIntoFbo ? deferredKuesaRenderer : forwardRenderer
if (_controller.thresholdEffect) movePostProcessingEffect(oldKuesaRenderer, newKuesaRenderer, thresholdComponent);
if (_controller.bloomEffect) movePostProcessingEffect(oldKuesaRenderer, newKuesaRenderer, bloomComponent);
if (_controller.blurEffect) movePostProcessingEffect(oldKuesaRenderer, newKuesaRenderer, blurComponent);
if (_controller.opacityMaskEffect) movePostProcessingEffect(oldKuesaRenderer, newKuesaRenderer, opacityMaskComponent);
}
}

ThresholdEffect {
Expand Down
1 change: 1 addition & 0 deletions tests/manual/forwardrenderer_scene/main.qrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>OffscreenEntity.qml</file>
<file>scenes/ThreeSpheres.qml</file>
<file>scenes/BloomTest.qml</file>
<file>opacitymask.png</file>
Expand Down
15 changes: 15 additions & 0 deletions tests/manual/forwardrenderer_scene/scenecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ SceneController::SceneController(QObject *parent)
, m_alphaBlendingEnabled(false)
, m_frustumCullingEnabled(true)
, m_zFillEnabled(false)
, m_renderIntoFboEnabled(false)
, m_bloomFilter(false)
, m_bloomThreshold(0.6f)
, m_bloomExposure(0.0f)
Expand Down Expand Up @@ -125,6 +126,11 @@ bool SceneController::zFill() const
return m_zFillEnabled;
}

bool SceneController::renderIntoFbo() const
{
return m_renderIntoFboEnabled;
}

int SceneController::bloomBlurPassCount() const
{
return m_bloomBlurPassCount;
Expand Down Expand Up @@ -254,6 +260,15 @@ void SceneController::setZFill(bool zFill)
emit zFillChanged(m_zFillEnabled);
}

void SceneController::setRenderIntoFbo(bool renderIntoFbo)
{
if (m_renderIntoFboEnabled == renderIntoFbo)
return;

m_renderIntoFboEnabled = renderIntoFbo;
emit renderIntoFboChanged(m_renderIntoFboEnabled);
}

void SceneController::setBloomBlurPassCount(int bloomBlurPassCount)
{
if (m_bloomBlurPassCount == bloomBlurPassCount)
Expand Down
5 changes: 5 additions & 0 deletions tests/manual/forwardrenderer_scene/scenecontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class SceneController : public QObject
Q_PROPERTY(bool alphaBlending READ alphaBlending WRITE setAlphaBlending NOTIFY alphaBlendingChanged)
Q_PROPERTY(bool frustumCulling READ frustumCulling WRITE setFrustumCulling NOTIFY frustumCullingChanged)
Q_PROPERTY(bool zFill READ zFill WRITE setZFill NOTIFY zFillChanged)
Q_PROPERTY(bool renderIntoFbo READ renderIntoFbo WRITE setRenderIntoFbo NOTIFY renderIntoFboChanged)

Q_PROPERTY(bool bloomEffect READ bloomEffect WRITE setBloomEffect NOTIFY bloomFilterChanged)
Q_PROPERTY(float bloomThreshold READ bloomThreshold WRITE setBloomThreshold NOTIFY bloomThresholdChanged)
Expand Down Expand Up @@ -75,6 +76,7 @@ class SceneController : public QObject
bool opacityMaskEffect() const;
bool opacityMaskPremultipliedAlpha() const;
bool zFill() const;
bool renderIntoFbo() const;

public slots:
void setSceneName(const QString &sceneName);
Expand All @@ -92,6 +94,7 @@ public slots:
void setOpacityMaskEffect(bool opacityMaskEffect);
void setOpacityMaskPremultipliedAlpha(bool premultipliedAlpha);
void setZFill(bool zFill);
void setRenderIntoFbo(bool renderIntoFbo);

signals:
void sceneNameChanged(const QString &sceneName);
Expand All @@ -109,6 +112,7 @@ public slots:
void opacityMaskEffectChanged(bool opacityMaskEffect);
void opacityMaskPremultipliedAlphaChanged(bool premultipliedAlpha);
void zFillChanged(bool zFill);
void renderIntoFboChanged(bool renderIntoFbo);

private:
QStringList m_scenes;
Expand All @@ -118,6 +122,7 @@ public slots:
bool m_alphaBlendingEnabled;
bool m_frustumCullingEnabled;
bool m_zFillEnabled;
bool m_renderIntoFboEnabled;

bool m_bloomFilter;
float m_bloomThreshold;
Expand Down

0 comments on commit 1b9eca9

Please sign in to comment.