aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2020-04-07 13:57:05 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2020-04-07 17:09:12 +0200
commite2ac02e9424dd89a3cd53886783115c7a5f111aa (patch)
treea8c3b19f78c6bdcc0732291eb8c701491866e5cf /examples
parentd7a42f580ca776afec95cfa30f7bd67eaaba19a6 (diff)
twotextureproviders example: rip out legacy OpenGL material impl
Leave only the RHI version in. Also add a temporary forcing of the RHI rendering path for now. This will go away when purging the direct OpenGL path in Qt Quick because RHI will be the default anyhow. Now both graph and twotextureproviders follow the same structure and approach, and together serve as a fairly good examples of creating custom materials in the RHI world. Change-Id: I4aafd440f70d13b8033fd4fdf0ecce71798c68d2 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/quick/scenegraph/twotextureproviders/main.cpp2
-rw-r--r--examples/quick/scenegraph/twotextureproviders/xorblender.cpp67
2 files changed, 5 insertions, 64 deletions
diff --git a/examples/quick/scenegraph/twotextureproviders/main.cpp b/examples/quick/scenegraph/twotextureproviders/main.cpp
index df0454ce40..669b42cb40 100644
--- a/examples/quick/scenegraph/twotextureproviders/main.cpp
+++ b/examples/quick/scenegraph/twotextureproviders/main.cpp
@@ -56,6 +56,8 @@
int main(int argc, char **argv)
{
+ qputenv("QSG_RHI", "1"); // ### Qt 6 remove, this will be the default anyway
+
QGuiApplication app(argc, argv);
QQuickView view;
diff --git a/examples/quick/scenegraph/twotextureproviders/xorblender.cpp b/examples/quick/scenegraph/twotextureproviders/xorblender.cpp
index 667b0bf8c7..5471cf733f 100644
--- a/examples/quick/scenegraph/twotextureproviders/xorblender.cpp
+++ b/examples/quick/scenegraph/twotextureproviders/xorblender.cpp
@@ -52,9 +52,6 @@
#include <QtCore/QPointer>
-#include <QOpenGLContext>
-#include <QOpenGLFunctions>
-
#include <QtQuick/QSGMaterial>
#include <QtQuick/QSGTexture>
#include <QtQuick/QSGGeometryNode>
@@ -81,20 +78,7 @@ public:
} state;
};
-class XorBlendShader : public QSGMaterialShader // for when the scenegraph is using OpenGL directly
-{
-public:
- XorBlendShader();
- void initialize() override;
- char const *const *attributeNames() const override;
- void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override;
-
-private:
- int m_matrix_id;
- int m_opacity_id;
-};
-
-class XorBlendRhiShader : public QSGMaterialRhiShader // for when the scenegraph is using QRhi
+class XorBlendRhiShader : public QSGMaterialRhiShader
{
public:
XorBlendRhiShader();
@@ -112,10 +96,8 @@ XorBlendMaterial::XorBlendMaterial()
QSGMaterialShader *XorBlendMaterial::createShader() const
{
- if (flags().testFlag(RhiShaderWanted))
- return new XorBlendRhiShader;
- else
- return new XorBlendShader;
+ Q_ASSERT(flags().testFlag(RhiShaderWanted));
+ return new XorBlendRhiShader;
}
QSGMaterialType *XorBlendMaterial::type() const
@@ -144,49 +126,6 @@ int XorBlendMaterial::compare(const QSGMaterial *o) const
return 0;
}
-XorBlendShader::XorBlendShader()
-{
- setShaderSourceFile(QOpenGLShader::Vertex, QLatin1String(":/scenegraph/twotextureproviders/shaders/xorblender.vert"));
- setShaderSourceFile(QOpenGLShader::Fragment, QLatin1String(":/scenegraph/twotextureproviders/shaders/xorblender.frag"));
-}
-
-void XorBlendShader::initialize()
-{
- m_matrix_id = program()->uniformLocation("qt_Matrix");
- m_opacity_id = program()->uniformLocation("qt_Opacity");
- // The texture units never change, only the textures we bind to them so
- // we set these once and for all here.
- program()->setUniformValue("uSource1", 0); // GL_TEXTURE0
- program()->setUniformValue("uSource2", 1); // GL_TEXTURE1
-}
-
-char const *const *XorBlendShader::attributeNames() const
-{
- static char const *const attr[] = { "aVertex", "aTexCoord", nullptr };
- return attr;
-}
-
-void XorBlendShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *)
-{
- XorBlendMaterial *material = static_cast<XorBlendMaterial *>(newEffect);
-
- if (state.isMatrixDirty())
- program()->setUniformValue(m_matrix_id, state.combinedMatrix());
-
- if (state.isOpacityDirty())
- program()->setUniformValue(m_opacity_id, state.opacity());
-
- QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
- // We bind the textures in inverse order so that we leave the updateState
- // function with GL_TEXTURE0 as the active texture unit. This is maintain
- // the "contract" that updateState should not mess up the GL state beyond
- // what is needed for this material.
- f->glActiveTexture(GL_TEXTURE1);
- material->state.texture2->bind();
- f->glActiveTexture(GL_TEXTURE0);
- material->state.texture1->bind();
-}
-
XorBlendRhiShader::XorBlendRhiShader()
{
setShaderFileName(VertexStage, QLatin1String(":/scenegraph/twotextureproviders/shaders/+qsb/xorblender.vert"));