From 33d0a8d753883e6b33ba8610c52f7fee42d6d9f1 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 23 Apr 2014 09:08:16 +0200 Subject: Remove direct OpenGL calls from QtOpenGL Task-number: QTBUG-36483 Change-Id: I96dea5649c0a49a11cd2ff31da659cd2067e769d Reviewed-by: Friedemann Kleint --- tests/auto/opengl/qglthreads/tst_qglthreads.cpp | 53 +++++++++++++++---------- 1 file changed, 31 insertions(+), 22 deletions(-) (limited to 'tests/auto/opengl/qglthreads') 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 #include "tst_qglthreads.h" +#ifndef QT_OPENGL_ES_2 +#include +#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(); + 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(); } -- cgit v1.2.3