From e5709a59a0e94977fde68cc4872326b7666748e6 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Thu, 12 Jan 2012 20:41:32 +0200 Subject: [PATCH] Use QOpenGLFunctions instead of presuming GL methods exist. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Samuel Rødal --- examples/qwidget-compositor/main.cpp | 21 ++++++++++++--------- examples/qwindow-compositor/qwindowcompositor.cpp | 18 +++++++++++------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/examples/qwidget-compositor/main.cpp b/examples/qwidget-compositor/main.cpp index 89fcad0..be86fcc 100644 --- a/examples/qwidget-compositor/main.cpp +++ b/examples/qwidget-compositor/main.cpp @@ -55,6 +55,7 @@ #include #include #include "textureblitter.h" +#include #endif #include @@ -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; } diff --git a/examples/qwindow-compositor/qwindowcompositor.cpp b/examples/qwindow-compositor/qwindowcompositor.cpp index d0f14e9..310ff19 100644 --- a/examples/qwindow-compositor/qwindowcompositor.cpp +++ b/examples/qwindow-compositor/qwindowcompositor.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -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; } -- 2.7.4