From fc41ee4c92ce703f3e4374bf493505a1d847a657 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 8 Jun 2012 09:39:17 +0100 Subject: OpenGL: Use official glext.h and gl2ext.h headers The Khronos group makes the glext.h (Desktop OpenGL) and gl2ext.h (OpenGL ES2) headers officially available nowadays. Most (all?) Linux systems ship this by default. On Windows platforms the glext.h file needs to be downloaded from http://www.opengl.org/registry/api/glext.h and placed alongside the system OpenGL header. Making use of the official header reduces the maintenance overhead for OpenGL support in Qt by removing the need to copy and paste definitions into the Qt sources. As the Khronos-provided headers are standardised and backwards and forwards compatible we can utilise these for all platforms rather than just for Windows. This means that all definitions required by Qt will be present even if the system ships out-dated equivalents. Mac OS X needs special handling in that we should always use the system-provided headers there. This is because Apple controls the OpenGL driver and the headers that go along with it. As such there is no possibility that the driver exposes additional functionality compared with the system-provided OpenGL headers. Apple has also decided to make different decisions about some OpenGL typedefs compared to other implementations. For example, Apple typdefs GLhandleARB to void* whereas other platforms use unsigned int. The alternative, which is to use the system provided glext.h (or gl2ext.h) header means that Qt code would need to check for the availability of such definitions wherever it is not guaranteed to be provided by core OpenGL/ES just to compile. The proposed approach means that Qt can compile regardless of the system's OpenGL extension support. We just need to be rigourous in runtime checking of support for extensions but that is already a requirement (and is missing in a few places, see TODO's added in this commit). The official Khronos headers are added to Qt as qopenglext.h - Desktop OpenGL qopengles2ext.h - OpenGL ES2 They need to be public but not part of QtGui module include, hence the headers have been modified by adding #if 0 #pragma qt_no_master_include #endif to them. This has been tested on: Gentoo Linux with GCC 4.6.3 Windows 7 with MSVC 2010 Mac OSX 10.8 with Apple clang 4.0 (based on LLVM 3.1svn) QNX with qcc (based on GCC 4.4) A small change is needed to QtDeclarative when building for OpenGL ES 2 after applying this commit. See https://codereview.qt-project.org/#change,31794 Change-Id: I4b3d2b1680baf4c78be9a87b4d8de076d23e8f82 Reviewed-by: Gunnar Sletta Reviewed-by: Lars Knoll --- src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 14 +++++++++++++- src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp | 15 ++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'src/opengl/gl2paintengineex') diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 1972035e4a..25f5c31d32 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -86,6 +86,12 @@ #include +// ####TODO Properly #ifdef this class to use #define symbols actually defined +// by OpenGL/ES includes +#ifndef GL_FRAMEBUFFER_SRGB +#define GL_FRAMEBUFFER_SRGB 0x8DB9 +#endif + QT_BEGIN_NAMESPACE @@ -177,6 +183,12 @@ void QGL2PaintEngineExPrivate::useSimpleShader() updateMatrix(); } +// ####TODO Properly #ifdef this class to use #define symbols actually defined +// by OpenGL/ES includes +#ifndef GL_MIRRORED_REPEAT_IBM +#define GL_MIRRORED_REPEAT_IBM 0x8370 +#endif + void QGL2PaintEngineExPrivate::updateBrushTexture() { Q_Q(QGL2PaintEngineEx); @@ -1826,7 +1838,7 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp #endif if (srgbFrameBufferEnabled) - glDisable(FRAMEBUFFER_SRGB_EXT); + glDisable(GL_FRAMEBUFFER_SRGB); } diff --git a/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp b/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp index ed613ab8ba..bf195f8cf3 100644 --- a/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp +++ b/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp @@ -170,7 +170,7 @@ void QGLTextureGlyphCache::resizeTextureData(int width, int height) // ### the QTextureGlyphCache API needs to be reworked to allow // ### resizeTextureData to fail - glBindFramebuffer(GL_FRAMEBUFFER_EXT, m_textureResource->m_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, m_textureResource->m_fbo); GLuint tmp_texture; glGenTextures(1, &tmp_texture); @@ -183,7 +183,7 @@ void QGLTextureGlyphCache::resizeTextureData(int width, int height) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); m_filterMode = Nearest; glBindTexture(GL_TEXTURE_2D, 0); - glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tmp_texture, 0); glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); @@ -258,12 +258,12 @@ void QGLTextureGlyphCache::resizeTextureData(int width, int height) glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, oldWidth, oldHeight); - glFramebufferRenderbuffer(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, - GL_RENDERBUFFER_EXT, 0); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + GL_RENDERBUFFER, 0); glDeleteTextures(1, &tmp_texture); glDeleteTextures(1, &oldTexture); - glBindFramebuffer(GL_FRAMEBUFFER_EXT, ctx->d_ptr->current_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, ctx->d_ptr->current_fbo); if (pex != 0) { glViewport(0, 0, pex->width, pex->height); @@ -321,7 +321,12 @@ void QGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph, QFixed sub glBindTexture(GL_TEXTURE_2D, m_textureResource->m_texture); if (mask.format() == QImage::Format_RGB32) { +#if defined(QT_OPENGL_ES_2) + // ###TODO Ensure extension is actually present on ES2 + glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, GL_BGRA_EXT, GL_UNSIGNED_BYTE, mask.bits()); +#else glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, GL_BGRA, GL_UNSIGNED_BYTE, mask.bits()); +#endif } else { // glTexSubImage2D() might cause some garbage to appear in the texture if the mask width is // not a multiple of four bytes. The bug appeared on a computer with 32-bit Windows Vista -- cgit v1.2.3