Compile on OpenGL ES2 when using Khronos headers
authorSean Harmer <sean.harmer@kdab.com>
Mon, 30 Jul 2012 17:33:42 +0000 (18:33 +0100)
committerQt by Nokia <qt-info@nokia.com>
Thu, 16 Aug 2012 20:04:26 +0000 (22:04 +0200)
This change is needed to allow qtdeclarative to build with change
https://codereview.qt-project.org/#change,28334 as OpenGL ES 2 and
the EXT_sRGB do not define the symbol GL_FRAMEBUFFER_SRGB.

Also use symbols defined by OES extensions where needed.

The #defines will be removed in a follow-up commit once 28334 has
been merged.

Change-Id: I1c4e5297c29ecf723463da7fbfe353628c4c35ef
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>

src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
src/quick/scenegraph/util/qsgdepthstencilbuffer.cpp

index 2f1a4ae..6616173 100644 (file)
@@ -128,10 +128,12 @@ void QSGTextMaskMaterialData::activate()
     QSGMaterialShader::activate();
     glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR);
 
+#if !defined(QT_OPENGL_ES_2)
     // 0.25 was found to be acceptable error margin by experimentation. On Mac, the gamma is 2.0,
     // but using sRGB looks okay.
     if (qAbs(fontSmoothingGamma() - 2.2) < 0.25)
         glEnable(GL_FRAMEBUFFER_SRGB);
+#endif
 }
 
 void QSGTextMaskMaterialData::deactivate()
@@ -139,8 +141,10 @@ void QSGTextMaskMaterialData::deactivate()
     QSGMaterialShader::deactivate();
     glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
 
+#if !defined(QT_OPENGL_ES_2)
     if (qAbs(fontSmoothingGamma() - 2.2) < 0.25)
         glDisable(GL_FRAMEBUFFER_SRGB);
+#endif
 }
 
 void QSGTextMaskMaterialData::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
index bca57a3..932da70 100644 (file)
@@ -75,6 +75,16 @@ void QSGDepthStencilBuffer::detach()
                                           GL_RENDERBUFFER, 0);
 }
 
+// ###TODO Remove once using Khronos OpenGL headers
+#if defined(QT_OPENGL_ES_2)
+#ifndef GL_DEPTH24_STENCIL8_OES
+#define GL_DEPTH24_STENCIL8_OES 0x88F0
+#endif
+
+#ifndef GL_DEPTH_COMPONENT24_OES
+#define GL_DEPTH_COMPONENT24_OES 0x81A6
+#endif
+#endif
 
 QSGDefaultDepthStencilBuffer::QSGDefaultDepthStencilBuffer(QOpenGLContext *context, const Format &format)
     : QSGDepthStencilBuffer(context, format)
@@ -88,10 +98,19 @@ QSGDefaultDepthStencilBuffer::QSGDefaultDepthStencilBuffer(QOpenGLContext *conte
         m_functions.glGenRenderbuffers(1, &m_depthBuffer);
         m_functions.glBindRenderbuffer(GL_RENDERBUFFER, m_depthBuffer);
         if (format.samples && m_functions.hasOpenGLExtension(QOpenGLExtensions::FramebufferMultisample)) {
+#if defined(QT_OPENGL_ES_2)
+            m_functions.glRenderbufferStorageMultisample(GL_RENDERBUFFER, format.samples,
+                GL_DEPTH24_STENCIL8_OES, width, height);
+#else
             m_functions.glRenderbufferStorageMultisample(GL_RENDERBUFFER, format.samples,
                 GL_DEPTH24_STENCIL8, width, height);
+#endif
         } else {
+#if defined(QT_OPENGL_ES_2)
+            m_functions.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8_OES, width, height);
+#else
             m_functions.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, width, height);
+#endif
         }
         m_stencilBuffer = m_depthBuffer;
     }
@@ -100,7 +119,7 @@ QSGDefaultDepthStencilBuffer::QSGDefaultDepthStencilBuffer(QOpenGLContext *conte
         m_functions.glBindRenderbuffer(GL_RENDERBUFFER, m_depthBuffer);
 #ifdef QT_OPENGL_ES
         const GLenum internalFormat = m_functions.hasOpenGLExtension(QOpenGLExtensions::Depth24)
-                ? GL_DEPTH_COMPONENT24 : GL_DEPTH_COMPONENT16;
+                ? GL_DEPTH_COMPONENT24_OES : GL_DEPTH_COMPONENT16;
 #else
         const GLenum internalFormat = GL_DEPTH_COMPONENT;
 #endif