summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2014-11-09 19:45:50 +0000
committerSean Harmer <sean.harmer@kdab.com>2014-11-10 14:37:59 +0100
commit66ed6615e0e085d6d33203fb1b9e90ba94e89de4 (patch)
tree27adb77ef76365743f27fa934f5bbf93c2bc4cee
parent103f68b40f74fc0b5e5fd1dcf40a6f162917d522 (diff)
downloadqt3d-66ed6615e0e085d6d33203fb1b9e90ba94e89de4.tar.gz
Refacotr buildRenderStateSet to a free function
Also added some todo's to improve efficiency. Change-Id: Ib982042fee4bd3e3928381456df806babf26734d Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--src/render/backend/jobs/renderviewjobutils.cpp77
-rw-r--r--src/render/backend/jobs/renderviewjobutils_p.h7
-rw-r--r--src/render/backend/renderview.cpp79
-rw-r--r--src/render/backend/renderview_p.h1
4 files changed, 88 insertions, 76 deletions
diff --git a/src/render/backend/jobs/renderviewjobutils.cpp b/src/render/backend/jobs/renderviewjobutils.cpp
index 35f4ccc70..1a4f3bf06 100644
--- a/src/render/backend/jobs/renderviewjobutils.cpp
+++ b/src/render/backend/jobs/renderviewjobutils.cpp
@@ -41,7 +41,18 @@
#include "renderviewjobutils_p.h"
+#include <Qt3DRenderer/qalphacoverage.h>
+#include <Qt3DRenderer/qalphatest.h>
+#include <Qt3DRenderer/qblendequation.h>
+#include <Qt3DRenderer/qblendstate.h>
+#include <Qt3DRenderer/qcullface.h>
+#include <Qt3DRenderer/qdepthmask.h>
+#include <Qt3DRenderer/qdepthtest.h>
+#include <Qt3DRenderer/qdithering.h>
+#include <Qt3DRenderer/qfrontface.h>
#include <Qt3DRenderer/qopenglfilter.h>
+#include <Qt3DRenderer/qscissortest.h>
+#include <Qt3DRenderer/qstenciltest.h>
#include <Qt3DRenderer/sphere.h>
#include <Qt3DRenderer/private/cameraselectornode_p.h>
@@ -50,12 +61,15 @@
#include <Qt3DRenderer/private/managers_p.h>
#include <Qt3DRenderer/private/rendereffect_p.h>
#include <Qt3DRenderer/private/renderpassfilternode_p.h>
+#include <Qt3DRenderer/private/renderstate_p.h>
#include <Qt3DRenderer/private/rendertargetselectornode_p.h>
#include <Qt3DRenderer/private/renderview_p.h>
#include <Qt3DRenderer/private/sortmethod_p.h>
#include <Qt3DRenderer/private/techniquefilternode_p.h>
#include <Qt3DRenderer/private/viewportnode_p.h>
+// TODO: Rename this include to something more descriptive
+#include <Qt3DRenderer/private/blendstate_p.h>
QT_BEGIN_NAMESPACE
@@ -336,6 +350,69 @@ QHash<QString, QVariant> parametersFromMaterialEffectTechnique(ParameterManager
return params;
}
+RenderStateSet *buildRenderStateSet(RenderRenderPass *pass, QFrameAllocator *allocator)
+{
+ if (!pass || pass->renderStates().isEmpty())
+ return Q_NULLPTR;
+
+ RenderStateSet *stateSet = allocator->allocate<RenderStateSet>();
+
+ // TODO: Don't use QObject subclasses as backend storage and replace this if
+ // cascade with a switch
+ Q_FOREACH (QRenderState *renderState, pass->renderStates()) {
+ if (qobject_cast<QAlphaTest *>(renderState) != Q_NULLPTR) {
+ QAlphaTest *alphaTest = qobject_cast<QAlphaTest *>(renderState);
+ stateSet->addState(AlphaFunc::getOrCreate(alphaTest->func(), alphaTest->clamp()));
+ }
+ else if (qobject_cast<QBlendEquation *>(renderState) != Q_NULLPTR) {
+ QBlendEquation *blendEquation = qobject_cast<QBlendEquation *>(renderState);
+ stateSet->addState(BlendEquation::getOrCreate(blendEquation->mode()));
+ }
+ else if (qobject_cast<QBlendState *>(renderState) != Q_NULLPTR) {
+ QBlendState *blendState = qobject_cast<QBlendState *>(renderState);
+ // TO DO : Handle Alpha here as weel
+ stateSet->addState(BlendState::getOrCreate(blendState->srcRGB(), blendState->dstRGB()));
+ }
+ else if (qobject_cast<QCullFace *>(renderState) != Q_NULLPTR) {
+ QCullFace *cullFace = qobject_cast<QCullFace *>(renderState);
+ stateSet->addState(CullFace::getOrCreate(cullFace->mode()));
+ }
+ else if (qobject_cast<QDepthMask *>(renderState) != Q_NULLPTR) {
+ QDepthMask *depthMask = qobject_cast<QDepthMask *>(renderState);
+ stateSet->addState(DepthMask::getOrCreate(depthMask->mask()));
+ }
+ else if (qobject_cast<QDepthTest *>(renderState) != Q_NULLPTR) {
+ QDepthTest *depthTest = qobject_cast<QDepthTest *>(renderState);
+ stateSet->addState(DepthTest::getOrCreate(depthTest->func()));
+ }
+ else if (qobject_cast<QDithering *>(renderState) != Q_NULLPTR) {
+ stateSet->addState(Dithering::getOrCreate());
+ }
+ else if (qobject_cast<QFrontFace *>(renderState) != Q_NULLPTR) {
+ QFrontFace *frontFace = qobject_cast<QFrontFace *>(renderState);
+ stateSet->addState(FrontFace::getOrCreate(frontFace->direction()));
+ }
+ else if (qobject_cast<QScissorTest *>(renderState) != Q_NULLPTR) {
+ QScissorTest *scissorTest = qobject_cast<QScissorTest *>(renderState);
+ stateSet->addState(ScissorTest::getOrCreate(scissorTest->left(),
+ scissorTest->bottom(),
+ scissorTest->width(),
+ scissorTest->height()));
+ }
+ else if (qobject_cast<QStencilTest *>(renderState) != Q_NULLPTR) {
+ QStencilTest *stencilTest = qobject_cast<QStencilTest *>(renderState);
+ stateSet->addState(StencilTest::getOrCreate(stencilTest->mask(),
+ stencilTest->func(),
+ stencilTest->faceMode()));
+ }
+ else if (qobject_cast<QAlphaCoverage *>(renderState) != Q_NULLPTR) {
+ stateSet->addState(AlphaCoverage::getOrCreate());
+ }
+ }
+
+ return stateSet;
+}
+
} // namespace Render
} // namespace Qt3D
diff --git a/src/render/backend/jobs/renderviewjobutils_p.h b/src/render/backend/jobs/renderviewjobutils_p.h
index 762d47fb3..2889b6fde 100644
--- a/src/render/backend/jobs/renderviewjobutils_p.h
+++ b/src/render/backend/jobs/renderviewjobutils_p.h
@@ -50,6 +50,9 @@
QT_BEGIN_NAMESPACE
namespace Qt3D {
+
+class QFrameAllocator;
+
namespace Render {
class FrameGraphNode;
@@ -58,6 +61,7 @@ class RenderEffect;
class RenderEntity;
class RenderMaterial;
class RenderRenderPass;
+class RenderStateSet;
class RenderTechnique;
class RenderView;
class Renderer;
@@ -80,6 +84,9 @@ Q_AUTOTEST_EXPORT QHash<QString, QVariant> parametersFromMaterialEffectTechnique
RenderEffect *effect,
RenderTechnique *technique);
+Q_AUTOTEST_EXPORT RenderStateSet *buildRenderStateSet(RenderRenderPass *pass,
+ QFrameAllocator *allocator);
+
} // namespace Render
} // namespace Qt3D
diff --git a/src/render/backend/renderview.cpp b/src/render/backend/renderview.cpp
index 0c444fabc..990ffc8e9 100644
--- a/src/render/backend/renderview.cpp
+++ b/src/render/backend/renderview.cpp
@@ -62,25 +62,14 @@
#include <Qt3DRenderer/private/renderlight_p.h>
#include <Qt3DRenderer/private/renderpassfilternode_p.h>
#include <Qt3DRenderer/private/renderrenderpass_p.h>
+#include <Qt3DRenderer/private/renderstate_p.h>
#include <Qt3DRenderer/private/techniquefilternode_p.h>
#include <Qt3DRenderer/private/viewportnode_p.h>
#include <Qt3DRenderer/qparametermapping.h>
-#include <Qt3DRenderer/qalphatest.h>
-#include <Qt3DRenderer/qblendequation.h>
-#include <Qt3DRenderer/qblendstate.h>
-#include <Qt3DRenderer/qcullface.h>
-#include <Qt3DRenderer/qdepthmask.h>
-#include <Qt3DRenderer/qdepthtest.h>
-#include <Qt3DRenderer/qdithering.h>
-#include <Qt3DRenderer/qfrontface.h>
-#include <Qt3DRenderer/qscissortest.h>
-#include <Qt3DRenderer/qstenciltest.h>
-#include <Qt3DRenderer/qalphacoverage.h>
// TODO: Move out once this is all refactored
#include <Qt3DRenderer/private/renderviewjobutils_p.h>
-#include <Qt3DRenderer/private/blendstate_p.h>
#include <Qt3DCore/qentity.h>
@@ -360,7 +349,9 @@ void RenderView::buildRenderCommands(RenderEntity *node)
command->m_depth = m_data->m_eyePos.distanceToPoint(node->worldBoundingVolume()->center());
command->m_meshData = mesh->meshData();
command->m_instancesCount = 0;
- command->m_stateSet = buildRenderStateSet(pass);
+
+ // TODO: Build the state set for a render pass only once per-pass. Not once per rendercommand and pass.
+ command->m_stateSet = buildRenderStateSet(pass, m_allocator);
if (command->m_stateSet != Q_NULLPTR)
command->m_changeCost = m_renderer->defaultRenderState()->changeCost(command->m_stateSet);
setShaderAndUniforms(command, pass, parameters, *(node->worldTransform()));
@@ -381,68 +372,6 @@ const AttachmentPack &RenderView::attachmentPack() const
return m_attachmentPack;
}
-// Build a RenderStateSet from the QRenderState stored in the RenderRenderPass
-RenderStateSet *RenderView::buildRenderStateSet(RenderRenderPass *pass)
-{
- if (pass != Q_NULLPTR && pass->renderStates().count() > 0) {
- RenderStateSet *stateSet = m_allocator->allocate<RenderStateSet>();
-
- Q_FOREACH (QRenderState *renderState, pass->renderStates()) {
- if (qobject_cast<QAlphaTest *>(renderState) != Q_NULLPTR) {
- QAlphaTest *alphaTest = qobject_cast<QAlphaTest *>(renderState);
- stateSet->addState(AlphaFunc::getOrCreate(alphaTest->func(), alphaTest->clamp()));
- }
- else if (qobject_cast<QBlendEquation *>(renderState) != Q_NULLPTR) {
- QBlendEquation *blendEquation = qobject_cast<QBlendEquation *>(renderState);
- stateSet->addState(BlendEquation::getOrCreate(blendEquation->mode()));
- }
- else if (qobject_cast<QBlendState *>(renderState) != Q_NULLPTR) {
- QBlendState *blendState = qobject_cast<QBlendState *>(renderState);
- // TO DO : Handle Alpha here as weel
- stateSet->addState(BlendState::getOrCreate(blendState->srcRGB(), blendState->dstRGB()));
- }
- else if (qobject_cast<QCullFace *>(renderState) != Q_NULLPTR) {
- QCullFace *cullFace = qobject_cast<QCullFace *>(renderState);
- stateSet->addState(CullFace::getOrCreate(cullFace->mode()));
- }
- else if (qobject_cast<QDepthMask *>(renderState) != Q_NULLPTR) {
- QDepthMask *depthMask = qobject_cast<QDepthMask *>(renderState);
- stateSet->addState(DepthMask::getOrCreate(depthMask->mask()));
- }
- else if (qobject_cast<QDepthTest *>(renderState) != Q_NULLPTR) {
- QDepthTest *depthTest = qobject_cast<QDepthTest *>(renderState);
- stateSet->addState(DepthTest::getOrCreate(depthTest->func()));
- }
- else if (qobject_cast<QDithering *>(renderState) != Q_NULLPTR) {
- stateSet->addState(Dithering::getOrCreate());
- }
- else if (qobject_cast<QFrontFace *>(renderState) != Q_NULLPTR) {
- QFrontFace *frontFace = qobject_cast<QFrontFace *>(renderState);
- stateSet->addState(FrontFace::getOrCreate(frontFace->direction()));
- }
- else if (qobject_cast<QScissorTest *>(renderState) != Q_NULLPTR) {
- QScissorTest *scissorTest = qobject_cast<QScissorTest *>(renderState);
- stateSet->addState(ScissorTest::getOrCreate(scissorTest->left(),
- scissorTest->bottom(),
- scissorTest->width(),
- scissorTest->height()));
- }
- else if (qobject_cast<QStencilTest *>(renderState) != Q_NULLPTR) {
- QStencilTest *stencilTest = qobject_cast<QStencilTest *>(renderState);
- stateSet->addState(StencilTest::getOrCreate(stencilTest->mask(),
- stencilTest->func(),
- stencilTest->faceMode()));
- }
- else if (qobject_cast<QAlphaCoverage *>(renderState) != Q_NULLPTR) {
- stateSet->addState(AlphaCoverage::getOrCreate());
- }
- }
-
- return stateSet;
- }
- return Q_NULLPTR;
-}
-
void RenderView::setUniformValue(QUniformPack &uniformPack, const QString &name, const QVariant &value)
{
QTexture *tex = Q_NULLPTR;
diff --git a/src/render/backend/renderview_p.h b/src/render/backend/renderview_p.h
index a2ce96a5b..925a2f7c0 100644
--- a/src/render/backend/renderview_p.h
+++ b/src/render/backend/renderview_p.h
@@ -192,7 +192,6 @@ public:
private:
void setShaderAndUniforms(RenderCommand *command, RenderRenderPass *pass, QHash<QString, QVariant> &parameters, const QMatrix4x4 &worldTransform);
- RenderStateSet *buildRenderStateSet(RenderRenderPass *pass);
Renderer *m_renderer;
QFrameAllocator *m_allocator;