summaryrefslogtreecommitdiffstats
path: root/tests/auto/opengl/qglthreads
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/auto/opengl/qglthreads
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/auto/opengl/qglthreads')
-rw-r--r--tests/auto/opengl/qglthreads/tst_qglthreads.cpp53
1 files changed, 31 insertions, 22 deletions
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();
}