Use QOpenGLFunctions instead of presuming GL methods exist.
authorRobin Burchell <robin.burchell@collabora.com>
Thu, 12 Jan 2012 18:41:32 +0000 (20:41 +0200)
committerSamuel Rødal <samuel.rodal@nokia.com>
Fri, 13 Jan 2012 10:51:28 +0000 (11:51 +0100)
They may not always exist, especially on desktop GL, so this is incorrect and
won't build in some cases.

Credit to Samuel Rødal for setting me on the path :)

Change-Id: I89296c5ed67f9388cceedb08cd68a7b5560be5e9
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
examples/qwidget-compositor/main.cpp
examples/qwindow-compositor/qwindowcompositor.cpp

index 89fcad0..be86fcc 100644 (file)
@@ -55,6 +55,7 @@
 #include <QGLWidget>
 #include <QtGui/private/qopengltexturecache_p.h>
 #include "textureblitter.h"
+#include <QOpenGLFunctions>
 #endif
 
 #include <QDebug>
@@ -135,24 +136,26 @@ protected:
 #ifdef QT_COMPOSITOR_WAYLAND_GL
     GLuint composeSurface(WaylandSurface *surface) {
         GLuint texture = 0;
+        QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
 
-        if (!m_surfaceCompositorFbo) {
-            glGenFramebuffers(1,&m_surfaceCompositorFbo);
-        }
-        glBindFramebuffer(GL_FRAMEBUFFER, m_surfaceCompositorFbo);
+        if (!m_surfaceCompositorFbo)
+            functions->glGenFramebuffers(1,&m_surfaceCompositorFbo);
+
+        functions->glBindFramebuffer(GL_FRAMEBUFFER, m_surfaceCompositorFbo);
 
         if (surface->type() == WaylandSurface::Shm) {
             texture = m_textureCache->bindTexture(context()->contextHandle(), surface->image());
         } else {
             texture = surface->texture(QOpenGLContext::currentContext());
         }
-        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
-                               GL_TEXTURE_2D, texture, 0);
+
+        functions->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+                                           GL_TEXTURE_2D, texture, 0);
         paintChildren(surface,surface);
-        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
-                               GL_TEXTURE_2D, 0, 0);
+        functions->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+                                           GL_TEXTURE_2D, 0, 0);
 
-        glBindFramebuffer(GL_FRAMEBUFFER, 0);
+        functions->glBindFramebuffer(GL_FRAMEBUFFER, 0);
         return texture;
     }
 
index d0f14e9..310ff19 100644 (file)
@@ -2,6 +2,7 @@
 #include <QMouseEvent>
 #include <QKeyEvent>
 #include <QTouchEvent>
+#include <QOpenGLFunctions>
 
 #include <QtCompositor/waylandinput.h>
 
@@ -24,7 +25,8 @@ QWindowCompositor::QWindowCompositor(QOpenGLWindow *window)
     m_renderScheduler.setSingleShot(true);
     connect(&m_renderScheduler,SIGNAL(timeout()),this,SLOT(render()));
 
-    glGenFramebuffers(1,&m_surface_fbo);
+    QOpenGLFunctions *functions = m_window->context()->functions();
+    functions->glGenFramebuffers(1, &m_surface_fbo);
 
     window->installEventFilter(this);
 
@@ -120,20 +122,22 @@ GLuint QWindowCompositor::composeSurface(WaylandSurface *surface)
 {
     GLuint texture = 0;
 
-    glBindFramebuffer(GL_FRAMEBUFFER, m_surface_fbo);
+    QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
+    functions->glBindFramebuffer(GL_FRAMEBUFFER, m_surface_fbo);
 
     if (surface->type() == WaylandSurface::Shm) {
         texture = m_textureCache->bindTexture(QOpenGLContext::currentContext(),surface->image());
     } else {
         texture = surface->texture(QOpenGLContext::currentContext());
     }
-    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
-                           GL_TEXTURE_2D, texture, 0);
+
+    functions->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+                                       GL_TEXTURE_2D, texture, 0);
     paintChildren(surface,surface);
-    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
-                           GL_TEXTURE_2D,0, 0);
+    functions->glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+                                       GL_TEXTURE_2D,0, 0);
 
-    glBindFramebuffer(GL_FRAMEBUFFER,0);
+    functions->glBindFramebuffer(GL_FRAMEBUFFER, 0);
     return texture;
 }