diff options
author | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-06-26 15:08:47 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-07-01 14:20:49 +0200 |
commit | 08f9b552c3735e15f9bf58ab5908652b06e47e88 (patch) | |
tree | c36ba328ff34a49af32383dace76be6b4ccd2145 /tests/auto/quick | |
parent | 8adc7bad2281596461cbf9557d2ca071113e095d (diff) |
Avoid direct GL calls in Qt Quick examples and tests
Change-Id: I204a5513708aeff5cae00d06d4f0c27c20a13ace
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
Diffstat (limited to 'tests/auto/quick')
3 files changed, 19 insertions, 11 deletions
diff --git a/tests/auto/quick/qquickframebufferobject/tst_qquickframebufferobject.cpp b/tests/auto/quick/qquickframebufferobject/tst_qquickframebufferobject.cpp index b7b58c6d3d..35a01b33ba 100644 --- a/tests/auto/quick/qquickframebufferobject/tst_qquickframebufferobject.cpp +++ b/tests/auto/quick/qquickframebufferobject/tst_qquickframebufferobject.cpp @@ -45,6 +45,7 @@ #include <QtQuick/qquickview.h> #include <QtGui/qopenglcontext.h> #include <QtGui/qopenglframebufferobject.h> +#include <QtGui/qopenglfunctions.h> #include <QtQuick/QQuickFramebufferObject> @@ -62,7 +63,7 @@ struct FrameInfo { QSize fboSize; } frameInfo; -class ColorRenderer : public QQuickFramebufferObject::Renderer +class ColorRenderer : public QQuickFramebufferObject::Renderer, protected QOpenGLFunctions { public: void render(); @@ -142,6 +143,7 @@ void ColorRenderer::synchronize(QQuickFramebufferObject *item) QOpenGLFramebufferObject *ColorRenderer::createFramebufferObject(const QSize &size) { + initializeOpenGLFunctions(); frameInfo.createFBOCount++; QOpenGLFramebufferObjectFormat format; if (msaa) diff --git a/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp b/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp index b5980929a6..bd7b89b104 100644 --- a/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp +++ b/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp @@ -44,6 +44,7 @@ #include <QtQuick/qquickitem.h> #include <QtQuick/qquickview.h> #include <QtGui/qopenglcontext.h> +#include <QtGui/qopenglfunctions.h> #include "../../shared/util.h" @@ -107,13 +108,13 @@ tst_QQuickItemLayer::tst_QQuickItemLayer() window.create(); context.create(); context.makeCurrent(&window); - const char *vendor = (const char *)glGetString(GL_VENDOR); - const char *renderer = (const char *)glGetString(GL_RENDERER); + const char *vendor = (const char *)context.functions()->glGetString(GL_VENDOR); + const char *renderer = (const char *)context.functions()->glGetString(GL_RENDERER); m_isMesaSoftwareRasterizer = strcmp(vendor, "Mesa Project") == 0 && strcmp(renderer, "Software Rasterizer") == 0; if (m_isMesaSoftwareRasterizer) { // Expects format: <OpenGL version> Mesa <Mesa version>[-devel] [...] - const char *version = (const char *)glGetString(GL_VERSION); + const char *version = (const char *)context.functions()->glGetString(GL_VERSION); QList<QByteArray> list = QByteArray(version).split(' '); if (list.size() >= 3) { list = list.at(2).split('-').at(0).split('.'); diff --git a/tests/auto/quick/rendernode/tst_rendernode.cpp b/tests/auto/quick/rendernode/tst_rendernode.cpp index 98e31329a0..2397392419 100644 --- a/tests/auto/quick/rendernode/tst_rendernode.cpp +++ b/tests/auto/quick/rendernode/tst_rendernode.cpp @@ -44,6 +44,7 @@ #include <QtQuick/qquickitem.h> #include <QtQuick/qquickview.h> #include <QtGui/qopenglcontext.h> +#include <QtGui/qopenglfunctions.h> #include <QtGui/qscreen.h> #include <private/qsgrendernode_p.h> @@ -86,8 +87,8 @@ public: virtual void render(const RenderState &) { // If clip has been set, scissoring will make sure the right area is cleared. - glClearColor(color.redF(), color.greenF(), color.blueF(), 1.0f); - glClear(GL_COLOR_BUFFER_BIT); + QOpenGLContext::currentContext()->functions()->glClearColor(color.redF(), color.greenF(), color.blueF(), 1.0f); + QOpenGLContext::currentContext()->functions()->glClear(GL_COLOR_BUFFER_BIT); } QColor color; @@ -129,9 +130,11 @@ private: QColor m_color; }; -class MessUpNode : public QSGRenderNode +class MessUpNode : public QSGRenderNode, protected QOpenGLFunctions { public: + MessUpNode() : initialized(false) { } + virtual StateFlags changedStates() { return StateFlags(DepthState) | StencilState | ScissorState | ColorState | BlendState @@ -140,17 +143,17 @@ public: virtual void render(const RenderState &) { + if (!initialized) { + initializeOpenGLFunctions(); + initialized = true; + } // Don't draw anything, just mess up the state glViewport(10, 10, 10, 10); glDisable(GL_SCISSOR_TEST); glDepthMask(true); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_EQUAL); -#if defined(QT_OPENGL_ES) glClearDepthf(1); -#else - glClearDepth(1); -#endif glClearStencil(42); glClearColor(1.0f, 0.5f, 1.0f, 0.0f); glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); @@ -163,6 +166,8 @@ public: glFrontFace(frontFace == GL_CW ? GL_CCW : GL_CW); glEnable(GL_CULL_FACE); } + + bool initialized; }; class MessUpItem : public QQuickItem |