summaryrefslogtreecommitdiffstats
path: root/tests/auto/opengl/qglthreads/tst_qglthreads.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/opengl/qglthreads/tst_qglthreads.cpp')
-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 70e3a3b62a..25057ba2a0 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()->isOpenGLES()) {
- 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();
}