diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2015-03-27 16:50:28 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2015-05-09 20:07:02 +0000 |
commit | 260ac1d2fd155b6df6fbfdc7019a78882a9c0dce (patch) | |
tree | e091d6e01656a2ae1b16274791269daa4f0ea756 /src | |
parent | e0f623685b0eff1c12c959dbca3b9753c86a0c89 (diff) |
Added QBlendStateSeparate render state
Change-Id: Ifd7254c9a60df3043029229a568de72c0dd4e9fb
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick3d/imports/render/qt3dquick3drenderplugin.cpp | 1 | ||||
-rw-r--r-- | src/render/backend/renderstate.cpp | 5 | ||||
-rw-r--r-- | src/render/backend/states/blendstate.cpp | 21 | ||||
-rw-r--r-- | src/render/backend/states/blendstate_p.h | 15 | ||||
-rw-r--r-- | src/render/frontend/qblendstate.cpp | 14 | ||||
-rw-r--r-- | src/render/frontend/qblendstate.h | 8 | ||||
-rw-r--r-- | src/render/frontend/qrenderstate.h | 1 |
7 files changed, 56 insertions, 9 deletions
diff --git a/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp b/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp index 8d7c2fa04..115ca9e6a 100644 --- a/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp +++ b/src/quick3d/imports/render/qt3dquick3drenderplugin.cpp @@ -220,6 +220,7 @@ void Qt3DQuick3DRenderPlugin::registerTypes(const char *uri) // RenderStates qmlRegisterUncreatableType<Qt3D::QRenderState>(uri, 2, 0, "RenderState", QStringLiteral("QRenderState is a base class")); qmlRegisterType<Qt3D::QBlendState>(uri, 2, 0, "BlendState"); + qmlRegisterType<Qt3D::QBlendStateSeparate>(uri, 2, 0, "BlendStateSeparate"); qmlRegisterType<Qt3D::QBlendEquation>(uri, 2, 0, "BlendEquation"); qmlRegisterType<Qt3D::QAlphaTest>(uri, 2, 0, "AlphaTest"); qmlRegisterType<Qt3D::QDepthTest>(uri, 2, 0, "DepthTest"); diff --git a/src/render/backend/renderstate.cpp b/src/render/backend/renderstate.cpp index 9927c45b1..a940c33e2 100644 --- a/src/render/backend/renderstate.cpp +++ b/src/render/backend/renderstate.cpp @@ -224,9 +224,12 @@ RenderState *RenderState::getOrCreateBackendState(QRenderState *renderState) } case QRenderState::BlendState: { QBlendState *blendState = static_cast<QBlendState *>(renderState); - // TO DO : Handle Alpha here as weel return BlendState::getOrCreate(blendState->srcRGB(), blendState->dstRGB()); } + case QRenderState::BlendStateSeparate: { + QBlendState *blendState = static_cast<QBlendState *>(renderState); + return BlendStateSeparate::getOrCreate(blendState->srcRGB(), blendState->dstRGB(), blendState->srcAlpha(), blendState->dstAlpha()); + } case QRenderState::CullFace: { QCullFace *cullFace = static_cast<QCullFace *>(renderState); return CullFace::getOrCreate(cullFace->mode()); diff --git a/src/render/backend/states/blendstate.cpp b/src/render/backend/states/blendstate.cpp index b9d9ab398..7ccc78d3c 100644 --- a/src/render/backend/states/blendstate.cpp +++ b/src/render/backend/states/blendstate.cpp @@ -66,11 +66,6 @@ void BlendState::apply(QGraphicsContext* gc) const gc->openGLContext()->functions()->glBlendFunc( m_1, m_2 ); } -StateMaskSet BlendState::mask() const -{ - return BlendStateMask; -} - BlendState *BlendState::getOrCreate(GLenum src, GLenum dst) { BlendState bs(src, dst); @@ -268,6 +263,22 @@ ColorMask *ColorMask::getOrCreate(GLboolean red, GLboolean green, GLboolean blue return getOrCreateImpl(ColorMask(red, green, blue, alpha)); } +void BlendStateSeparate::apply(QGraphicsContext *gc) const +{ + gc->openGLContext()->functions()->glEnable(GL_BLEND); + gc->openGLContext()->functions()->glBlendFuncSeparate(m_1, m_2, m_3, m_4); +} + +BlendStateSeparate *BlendStateSeparate::getOrCreate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) +{ + return getOrCreateImpl(BlendStateSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha)); +} + +BlendStateSeparate::BlendStateSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) + : GenericState4<BlendStateSeparate, GLenum, GLenum, GLenum, GLenum>(srcRGB, dstRGB, srcAlpha, dstAlpha) +{ +} + } // Render } // Qt3D diff --git a/src/render/backend/states/blendstate_p.h b/src/render/backend/states/blendstate_p.h index 3488d0d27..dd2d01aeb 100644 --- a/src/render/backend/states/blendstate_p.h +++ b/src/render/backend/states/blendstate_p.h @@ -52,13 +52,26 @@ class Q_AUTOTEST_EXPORT BlendState : public GenericState2<BlendState, GLenum, GL { public: virtual void apply(QGraphicsContext *gc) const Q_DECL_OVERRIDE; - virtual StateMaskSet mask() const Q_DECL_OVERRIDE; + virtual StateMaskSet mask() const Q_DECL_OVERRIDE + { return BlendStateMask; } static BlendState *getOrCreate(GLenum src, GLenum dst); private: BlendState(GLenum src, GLenum dst); }; +class Q_AUTOTEST_EXPORT BlendStateSeparate : public GenericState4<BlendStateSeparate, GLenum, GLenum, GLenum, GLenum> +{ +public: + virtual void apply(QGraphicsContext *gc) const Q_DECL_OVERRIDE; + virtual StateMaskSet mask() const Q_DECL_OVERRIDE + { return BlendStateMask; } + + static BlendStateSeparate *getOrCreate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +private: + BlendStateSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha); +}; + class Q_AUTOTEST_EXPORT BlendEquation : public GenericState1<BlendEquation, GLenum> { public: diff --git a/src/render/frontend/qblendstate.cpp b/src/render/frontend/qblendstate.cpp index 634e730e5..055cd948e 100644 --- a/src/render/frontend/qblendstate.cpp +++ b/src/render/frontend/qblendstate.cpp @@ -47,8 +47,8 @@ namespace Qt3D { class QBlendStatePrivate : public QRenderStatePrivate { public: - QBlendStatePrivate(QBlendState *qq) - : QRenderStatePrivate(qq, QRenderState::BlendState) + QBlendStatePrivate(QBlendState *qq, QRenderState::Type type = QRenderState::BlendState) + : QRenderStatePrivate(qq, type) , m_srcRGB(QBlendState::Zero) , m_srcAlpha(QBlendState::Zero) , m_dstRGB(QBlendState::Zero) @@ -79,6 +79,11 @@ void QBlendState::copy(const QNode *ref) d_func()->m_dstRGB = refState->d_func()->m_dstRGB; } +QBlendState::QBlendState(QRenderState::Type type, QNode *parent) + : QRenderState(*new QBlendStatePrivate(this, type), parent) +{ +} + QBlendState::Blending QBlendState::srcRGB() const { Q_D(const QBlendState); @@ -139,6 +144,11 @@ void QBlendState::setDstAlpha(QBlendState::Blending dstAlpha) } } +QBlendStateSeparate::QBlendStateSeparate(QNode *parent) + : QBlendState(QRenderState::BlendStateSeparate, parent) +{ +} + } // Qt3D QT_END_NAMESPACE diff --git a/src/render/frontend/qblendstate.h b/src/render/frontend/qblendstate.h index 6284e668e..4f5924a3c 100644 --- a/src/render/frontend/qblendstate.h +++ b/src/render/frontend/qblendstate.h @@ -102,12 +102,20 @@ Q_SIGNALS: protected: void copy(const QNode *ref) Q_DECL_OVERRIDE; + QBlendState(QRenderState::Type type, QNode *parent = 0); private: Q_DECLARE_PRIVATE(QBlendState) QT3D_CLONEABLE(QBlendState) }; +class QT3DRENDERERSHARED_EXPORT QBlendStateSeparate : public QBlendState +{ + Q_OBJECT +public: + explicit QBlendStateSeparate(QNode *parent = 0); +}; + } // Qt3D QT_END_NAMESPACE diff --git a/src/render/frontend/qrenderstate.h b/src/render/frontend/qrenderstate.h index 1aef2d643..400507212 100644 --- a/src/render/frontend/qrenderstate.h +++ b/src/render/frontend/qrenderstate.h @@ -57,6 +57,7 @@ public: AlphaTest, BlendEquation, BlendState, + BlendStateSeparate, ColorMask, CullFace, DepthMask, |