summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@digia.com>2014-04-23 09:08:16 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-28 18:19:34 +0200
commit33d0a8d753883e6b33ba8610c52f7fee42d6d9f1 (patch)
tree8452d09194c35e0c3c94b7ccd6f16000af0b396b /tests
parent8f443ad0b96af1c3b07ca8faeba139091c7276a8 (diff)
Remove direct OpenGL calls from QtOpenGL
Task-number: QTBUG-36483 Change-Id: I96dea5649c0a49a11cd2ff31da659cd2067e769d Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/qopengl/tst_qopengl.cpp14
-rw-r--r--tests/auto/opengl/qgl/tst_qgl.cpp35
-rw-r--r--tests/auto/opengl/qglfunctions/tst_qglfunctions.cpp20
-rw-r--r--tests/auto/opengl/qglthreads/tst_qglthreads.cpp53
4 files changed, 67 insertions, 55 deletions
diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp
index 07a07210af..c32edd3f71 100644
--- a/tests/auto/gui/qopengl/tst_qopengl.cpp
+++ b/tests/auto/gui/qopengl/tst_qopengl.cpp
@@ -459,9 +459,9 @@ void tst_QOpenGL::fboSimpleRendering()
QVERIFY(fbo->bind());
- glClearColor(1.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
- glFinish();
+ ctx.functions()->glClearColor(1.0, 0.0, 0.0, 1.0);
+ ctx.functions()->glClear(GL_COLOR_BUFFER_BIT);
+ ctx.functions()->glFinish();
const QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32);
QCOMPARE(fb.size(), size);
@@ -505,9 +505,9 @@ void tst_QOpenGL::fboTextureOwnership()
fbo->bind();
QVERIFY(fbo->texture() != 0 && fbo->texture() != texture);
- glClearColor(1.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
- glFinish();
+ ctx.functions()->glClearColor(1.0, 0.0, 0.0, 1.0);
+ ctx.functions()->glClear(GL_COLOR_BUFFER_BIT);
+ ctx.functions()->glFinish();
QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32);
QImage reference(fb.size(), QImage::Format_RGB32);
@@ -515,7 +515,7 @@ void tst_QOpenGL::fboTextureOwnership()
QFUZZY_COMPARE_IMAGES(fb, reference);
- glDeleteTextures(1, &texture);
+ ctx.functions()->glDeleteTextures(1, &texture);
delete fbo;
}
diff --git a/tests/auto/opengl/qgl/tst_qgl.cpp b/tests/auto/opengl/qgl/tst_qgl.cpp
index 5831b33974..02f32adf57 100644
--- a/tests/auto/opengl/qgl/tst_qgl.cpp
+++ b/tests/auto/opengl/qgl/tst_qgl.cpp
@@ -1090,9 +1090,10 @@ void tst_QGL::glFBOSimpleRendering()
fbo->bind();
- glClearColor(1.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
- glFinish();
+ QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
+ funcs->glClearColor(1.0, 0.0, 0.0, 1.0);
+ funcs->glClear(GL_COLOR_BUFFER_BIT);
+ funcs->glFinish();
QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32);
QImage reference(fb.size(), QImage::Format_RGB32);
@@ -1390,11 +1391,11 @@ class RenderPixmapWidget : public QGLWidget
protected:
void initializeGL() {
// Set some gl state:
- glClearColor(1.0, 0.0, 0.0, 1.0);
+ QOpenGLContext::currentContext()->functions()->glClearColor(1.0, 0.0, 0.0, 1.0);
}
void paintGL() {
- glClear(GL_COLOR_BUFFER_BIT);
+ QOpenGLContext::currentContext()->functions()->glClear(GL_COLOR_BUFFER_BIT);
}
};
@@ -1683,11 +1684,12 @@ protected:
void paintEvent(QPaintEvent*)
{
// clear the stencil with junk
- glStencilMask(0xFFFF);
- glClearStencil(0xFFFF);
- glDisable(GL_STENCIL_TEST);
- glDisable(GL_SCISSOR_TEST);
- glClear(GL_STENCIL_BUFFER_BIT);
+ QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
+ funcs->glStencilMask(0xFFFF);
+ funcs->glClearStencil(0xFFFF);
+ funcs->glDisable(GL_STENCIL_TEST);
+ funcs->glDisable(GL_SCISSOR_TEST);
+ funcs->glClear(GL_STENCIL_BUFFER_BIT);
QPainter painter(this);
paint(&painter);
@@ -2029,26 +2031,27 @@ void tst_QGL::qglContextDefaultBindTexture()
QVERIFY(QImagePixmapCleanupHooks::isImageCached(*boundImage));
QVERIFY(QImagePixmapCleanupHooks::isPixmapCached(*boundPixmap));
+ QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
// Make sure the texture IDs returned are valid:
- QCOMPARE((bool)glIsTexture(boundImageTextureId), GL_TRUE);
- QCOMPARE((bool)glIsTexture(boundPixmapTextureId), GL_TRUE);
+ QCOMPARE((bool)funcs->glIsTexture(boundImageTextureId), GL_TRUE);
+ QCOMPARE((bool)funcs->glIsTexture(boundPixmapTextureId), GL_TRUE);
// Make sure the textures are still valid after we delete the image/pixmap:
// Also check that although the textures are left intact, the cache entries are removed:
delete boundImage;
boundImage = 0;
- QCOMPARE((bool)glIsTexture(boundImageTextureId), GL_TRUE);
+ QCOMPARE((bool)funcs->glIsTexture(boundImageTextureId), GL_TRUE);
QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount+1);
delete boundPixmap;
boundPixmap = 0;
- QCOMPARE((bool)glIsTexture(boundPixmapTextureId), GL_TRUE);
+ QCOMPARE((bool)funcs->glIsTexture(boundPixmapTextureId), GL_TRUE);
QCOMPARE(QGLTextureCache::instance()->size(), startCacheItemCount);
// Finally, make sure QGLContext::deleteTexture deletes the texture IDs:
ctx->deleteTexture(boundImageTextureId);
ctx->deleteTexture(boundPixmapTextureId);
- QCOMPARE((bool)glIsTexture(boundImageTextureId), GL_FALSE);
- QCOMPARE((bool)glIsTexture(boundPixmapTextureId), GL_FALSE);
+ QCOMPARE((bool)funcs->glIsTexture(boundImageTextureId), GL_FALSE);
+ QCOMPARE((bool)funcs->glIsTexture(boundPixmapTextureId), GL_FALSE);
}
#endif
diff --git a/tests/auto/opengl/qglfunctions/tst_qglfunctions.cpp b/tests/auto/opengl/qglfunctions/tst_qglfunctions.cpp
index cdd820cf5b..4e0375171a 100644
--- a/tests/auto/opengl/qglfunctions/tst_qglfunctions.cpp
+++ b/tests/auto/opengl/qglfunctions/tst_qglfunctions.cpp
@@ -62,7 +62,7 @@ bool tst_QGLFunctions::hasExtension(const char *name)
{
QString extensions =
QString::fromLatin1
- (reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)));
+ (reinterpret_cast<const char *>(QOpenGLContext::currentContext()->functions()->glGetString(GL_EXTENSIONS)));
return extensions.split(QLatin1Char(' ')).contains
(QString::fromLatin1(name));
}
@@ -194,46 +194,46 @@ void tst_QGLFunctions::features()
// Verify that the multitexture functions appear to resolve and work.
void tst_QGLFunctions::multitexture()
{
- QGLFunctions funcs;
+ QOpenGLFunctions funcs;
QGLWidget glw;
if (!glw.isValid())
QSKIP("Could not create a GL context");
glw.makeCurrent();
- funcs.initializeGLFunctions();
+ funcs.initializeOpenGLFunctions();
- if (!funcs.hasOpenGLFeature(QGLFunctions::Multitexture))
+ if (!funcs.hasOpenGLFeature(QOpenGLFunctions::Multitexture))
QSKIP("Multitexture functions are not supported");
funcs.glActiveTexture(GL_TEXTURE1);
GLint active = 0;
- glGetIntegerv(GL_ACTIVE_TEXTURE, &active);
+ funcs.glGetIntegerv(GL_ACTIVE_TEXTURE, &active);
QVERIFY(active == GL_TEXTURE1);
funcs.glActiveTexture(GL_TEXTURE0);
active = 0;
- glGetIntegerv(GL_ACTIVE_TEXTURE, &active);
+ funcs.glGetIntegerv(GL_ACTIVE_TEXTURE, &active);
QVERIFY(active == GL_TEXTURE0);
}
// Verify that the glBlendColor() function appears to resolve and work.
void tst_QGLFunctions::blendColor()
{
- QGLFunctions funcs;
+ QOpenGLFunctions funcs;
QGLWidget glw;
if (!glw.isValid())
QSKIP("Could not create a GL context");
glw.makeCurrent();
- funcs.initializeGLFunctions();
+ funcs.initializeOpenGLFunctions();
- if (!funcs.hasOpenGLFeature(QGLFunctions::BlendColor))
+ if (!funcs.hasOpenGLFeature(QOpenGLFunctions::BlendColor))
QSKIP("glBlendColor() is not supported");
funcs.glBlendColor(0.0f, 1.0f, 0.0f, 1.0f);
GLfloat colors[4] = {0.5f, 0.5f, 0.5f, 0.5f};
- glGetFloatv(GL_BLEND_COLOR, colors);
+ funcs.glGetFloatv(GL_BLEND_COLOR, colors);
QCOMPARE(colors[0], 0.0f);
QCOMPARE(colors[1], 1.0f);
diff --git a/tests/auto/opengl/qglthreads/tst_qglthreads.cpp b/tests/auto/opengl/qglthreads/tst_qglthreads.cpp
index 999761e3f0..e190af31e4 100644
--- a/tests/auto/opengl/qglthreads/tst_qglthreads.cpp
+++ b/tests/auto/opengl/qglthreads/tst_qglthreads.cpp
@@ -48,6 +48,10 @@
#include <QtOpenGL/QtOpenGL>
#include "tst_qglthreads.h"
+#ifndef QT_OPENGL_ES_2
+#include <QtGui/QOpenGLFunctions_1_0>
+#endif
+
#define RUNNING_TIME 5000
tst_QGLThreads::tst_QGLThreads(QObject *parent)
@@ -339,8 +343,9 @@ static inline float qrandom() { return (rand() % 100) / 100.f; }
void renderAScene(int w, int h)
{
+ QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
+
if (QOpenGLContext::currentContext()->isES()) {
- QGLFunctions funcs(QGLContext::currentContext());
Q_UNUSED(w);
Q_UNUSED(h);
QGLShaderProgram program;
@@ -349,7 +354,7 @@ void renderAScene(int w, int h)
program.bindAttributeLocation("pos", 0);
program.bind();
- funcs.glEnableVertexAttribArray(0);
+ funcs->glEnableVertexAttribArray(0);
for (int i=0; i<1000; ++i) {
GLfloat pos[] = {
@@ -361,30 +366,33 @@ void renderAScene(int w, int h)
(rand() % 100) / 100.f
};
- funcs.glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, pos);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 3);
+ funcs->glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, pos);
+ funcs->glDrawArrays(GL_TRIANGLE_STRIP, 0, 3);
}
} else {
#ifndef QT_OPENGL_ES_2
- glViewport(0, 0, w, h);
+ QOpenGLFunctions_1_0 *gl1funcs = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_1_0>();
+ gl1funcs->initializeOpenGLFunctions();
+
+ gl1funcs->glViewport(0, 0, w, h);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(0, w, h, 0, 1, 100);
- glTranslated(0, 0, -1);
+ gl1funcs->glMatrixMode(GL_PROJECTION);
+ gl1funcs->glLoadIdentity();
+ gl1funcs->glFrustum(0, w, h, 0, 1, 100);
+ gl1funcs->glTranslated(0, 0, -1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
+ gl1funcs->glMatrixMode(GL_MODELVIEW);
+ gl1funcs->glLoadIdentity();
for (int i=0;i<1000; ++i) {
- glBegin(GL_TRIANGLES);
- glColor3f(qrandom(), qrandom(), qrandom());
- glVertex2f(qrandom() * w, qrandom() * h);
- glColor3f(qrandom(), qrandom(), qrandom());
- glVertex2f(qrandom() * w, qrandom() * h);
- glColor3f(qrandom(), qrandom(), qrandom());
- glVertex2f(qrandom() * w, qrandom() * h);
- glEnd();
+ gl1funcs->glBegin(GL_TRIANGLES);
+ gl1funcs->glColor3f(qrandom(), qrandom(), qrandom());
+ gl1funcs->glVertex2f(qrandom() * w, qrandom() * h);
+ gl1funcs->glColor3f(qrandom(), qrandom(), qrandom());
+ gl1funcs->glVertex2f(qrandom() * w, qrandom() * h);
+ gl1funcs->glColor3f(qrandom(), qrandom(), qrandom());
+ gl1funcs->glVertex2f(qrandom() * w, qrandom() * h);
+ gl1funcs->glEnd();
}
#endif
}
@@ -434,8 +442,9 @@ public:
QSize s = m_widget->newSize;
m_widget->mutex.unlock();
+ QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();
if (s != m_size) {
- glViewport(0, 0, s.width(), s.height());
+ funcs->glViewport(0, 0, s.width(), s.height());
}
if (QGLContext::currentContext() != m_widget->context()) {
@@ -443,7 +452,7 @@ public:
break;
}
- glClear(GL_COLOR_BUFFER_BIT);
+ funcs->glClear(GL_COLOR_BUFFER_BIT);
int w = m_widget->width();
int h = m_widget->height();
@@ -451,7 +460,7 @@ public:
renderAScene(w, h);
int color;
- glReadPixels(w / 2, h / 2, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &color);
+ funcs->glReadPixels(w / 2, h / 2, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &color);
m_widget->swapBuffers();
}