diff options
author | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-03-03 14:47:27 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-04 15:59:05 +0100 |
commit | 1e18df9c73e5431083ac2983c8899823d5ce259d (patch) | |
tree | 06a5014d1d87b04b7611cf496fd9e082a9e7ed98 /examples | |
parent | 565f39aad1c02fda14f52fdd002eaba52abf8d27 (diff) |
Extend QOpenGLFunctions with GL1 functions
This introduces the ability to indirectly invoke all common GL1-GLES2
functions via QOpenGLFunctions. The GL1 functions are not yet resolved,
since this would not work anyway when linking to an OpenGL implementation
directly. However this may change later but that will be a completely
internal change without affecting any public APIs.
Also migrate some of the opengl examples to use QOpenGLFunctions for
everything. Once dynamic GL loading becomes available on some platforms,
these examples should continue to function without any changes since they
do not anymore invoke any OpenGL functions directly.
Task-number: QTBUG-36483
Change-Id: Ie630029651e5a4863a480aac5306edd67ee36813
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/opengl/contextinfo/renderwindow.cpp | 12 | ||||
-rw-r--r-- | examples/opengl/contextinfo/widget.cpp | 9 | ||||
-rw-r--r-- | examples/opengl/hellowindow/hellowindow.cpp | 22 | ||||
-rw-r--r-- | examples/opengl/textures/glwidget.cpp | 2 | ||||
-rw-r--r-- | examples/opengl/textures/glwidget.h | 3 |
5 files changed, 27 insertions, 21 deletions
diff --git a/examples/opengl/contextinfo/renderwindow.cpp b/examples/opengl/contextinfo/renderwindow.cpp index ab8e89fab8..85fb19bd1a 100644 --- a/examples/opengl/contextinfo/renderwindow.cpp +++ b/examples/opengl/contextinfo/renderwindow.cpp @@ -43,6 +43,7 @@ #include <QMatrix4x4> #include <QOpenGLContext> #include <QOpenGLShaderProgram> +#include <QOpenGLFunctions> RenderWindow::RenderWindow(const QSurfaceFormat &format) : m_context(0), @@ -177,10 +178,11 @@ void RenderWindow::render() return; } + QOpenGLFunctions *f = m_context->functions(); if (!m_initialized) { m_initialized = true; - glEnable(GL_DEPTH_TEST); - glClearColor(0, 0, 0, 1); + f->glEnable(GL_DEPTH_TEST); + f->glClearColor(0, 0, 0, 1); init(); emit ready(); } @@ -189,8 +191,8 @@ void RenderWindow::render() return; const qreal retinaScale = devicePixelRatio(); - glViewport(0, 0, width() * retinaScale, height() * retinaScale); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + f->glViewport(0, 0, width() * retinaScale, height() * retinaScale); + f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_program->bind(); QMatrix4x4 matrix; @@ -204,7 +206,7 @@ void RenderWindow::render() else // no VAO support, set the vertex attribute arrays now setupVertexAttribs(); - glDrawArrays(GL_TRIANGLES, 0, 3); + f->glDrawArrays(GL_TRIANGLES, 0, 3); m_vao.release(); m_program->release(); diff --git a/examples/opengl/contextinfo/widget.cpp b/examples/opengl/contextinfo/widget.cpp index 6d4b97ca8f..ff78639e24 100644 --- a/examples/opengl/contextinfo/widget.cpp +++ b/examples/opengl/contextinfo/widget.cpp @@ -312,13 +312,14 @@ void Widget::renderWindowReady() QString vendor, renderer, version, glslVersion; const GLubyte *p; - if ((p = glGetString(GL_VENDOR))) + QOpenGLFunctions *f = context->functions(); + if ((p = f->glGetString(GL_VENDOR))) vendor = QString::fromLatin1(reinterpret_cast<const char *>(p)); - if ((p = glGetString(GL_RENDERER))) + if ((p = f->glGetString(GL_RENDERER))) renderer = QString::fromLatin1(reinterpret_cast<const char *>(p)); - if ((p = glGetString(GL_VERSION))) + if ((p = f->glGetString(GL_VERSION))) version = QString::fromLatin1(reinterpret_cast<const char *>(p)); - if ((p = glGetString(GL_SHADING_LANGUAGE_VERSION))) + if ((p = f->glGetString(GL_SHADING_LANGUAGE_VERSION))) glslVersion = QString::fromLatin1(reinterpret_cast<const char *>(p)); m_output->append(tr("\nVendor: %1").arg(vendor)); diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp index 2864883f5e..3b5971c0d3 100644 --- a/examples/opengl/hellowindow/hellowindow.cpp +++ b/examples/opengl/hellowindow/hellowindow.cpp @@ -41,6 +41,7 @@ #include "hellowindow.h" #include <QOpenGLContext> +#include <QOpenGLFunctions> #include <qmath.h> Renderer::Renderer(const QSurfaceFormat &format, Renderer *share, QScreen *screen) @@ -142,15 +143,16 @@ void Renderer::render() m_initialized = true; } - glViewport(0, 0, viewSize.width() * surface->devicePixelRatio(), viewSize.height() * surface->devicePixelRatio()); + QOpenGLFunctions *f = m_context->functions(); + f->glViewport(0, 0, viewSize.width() * surface->devicePixelRatio(), viewSize.height() * surface->devicePixelRatio()); - glClearColor(0.1f, 0.1f, 0.2f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + f->glClearColor(0.1f, 0.1f, 0.2f, 1.0f); + f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glFrontFace(GL_CW); - glCullFace(GL_FRONT); - glEnable(GL_CULL_FACE); - glEnable(GL_DEPTH_TEST); + f->glFrontFace(GL_CW); + f->glCullFace(GL_FRONT); + f->glEnable(GL_CULL_FACE); + f->glEnable(GL_DEPTH_TEST); QMatrix4x4 modelview; modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f); @@ -164,8 +166,8 @@ void Renderer::render() paintQtLogo(); m_program->release(); - glDisable(GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); + f->glDisable(GL_DEPTH_TEST); + f->glDisable(GL_CULL_FACE); m_context->swapBuffers(surface); @@ -187,8 +189,6 @@ void Renderer::paintQtLogo() void Renderer::initialize() { - glClearColor(0.1f, 0.1f, 0.2f, 1.0f); - QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this); vshader->compileSourceCode( "attribute highp vec4 vertex;" diff --git a/examples/opengl/textures/glwidget.cpp b/examples/opengl/textures/glwidget.cpp index ac1e7965af..305ca1aa4c 100644 --- a/examples/opengl/textures/glwidget.cpp +++ b/examples/opengl/textures/glwidget.cpp @@ -83,6 +83,8 @@ void GLWidget::setClearColor(const QColor &color) void GLWidget::initializeGL() { + initializeOpenGLFunctions(); + makeObject(); glEnable(GL_DEPTH_TEST); diff --git a/examples/opengl/textures/glwidget.h b/examples/opengl/textures/glwidget.h index fee47b9b48..b210b0fd8f 100644 --- a/examples/opengl/textures/glwidget.h +++ b/examples/opengl/textures/glwidget.h @@ -43,10 +43,11 @@ #include <QtWidgets> #include <QGLWidget> +#include <QOpenGLFunctions> QT_FORWARD_DECLARE_CLASS(QGLShaderProgram); -class GLWidget : public QGLWidget +class GLWidget : public QGLWidget, protected QOpenGLFunctions { Q_OBJECT |