From 658616b44e8d6ff860ab2f58ff6e51f89c212f95 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sun, 17 Feb 2013 12:11:30 +0100 Subject: QOpenGLShaderProgram: insert precision defines based on runtime detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Given that we can create OpenGL/ES contexts even under a Desktop OpenGL implementation, we must check the type of the surface we're renderering on at runtime. Change-Id: I55004ce918889b3fc094702976500fcfc675bd1a Reviewed-by: Samuel Rødal Reviewed-by: Sean Harmer Reviewed-by: Gunnar Sletta --- src/gui/opengl/qopenglshaderprogram.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/gui/opengl/qopenglshaderprogram.cpp b/src/gui/opengl/qopenglshaderprogram.cpp index 4f824f5fb6..e48b922dac 100644 --- a/src/gui/opengl/qopenglshaderprogram.cpp +++ b/src/gui/opengl/qopenglshaderprogram.cpp @@ -49,6 +49,7 @@ #include #include #include +#include #if !defined(QT_OPENGL_ES_2) #include @@ -373,18 +374,12 @@ QOpenGLShader::ShaderType QOpenGLShader::shaderType() const return d->shaderType; } -// The precision qualifiers are useful on OpenGL/ES systems, -// but usually not present on desktop systems. Define the -// keywords to empty strings on desktop systems. -#if !defined(QT_OPENGL_ES) || defined(QT_OPENGL_FORCE_SHADER_DEFINES) -#define QOpenGL_DEFINE_QUALIFIERS 1 static const char qualifierDefines[] = "#define lowp\n" "#define mediump\n" "#define highp\n"; -#else - +#if defined(QT_OPENGL_ES) && !defined(QT_OPENGL_FORCE_SHADER_DEFINES) // The "highp" qualifier doesn't exist in fragment shaders // on all ES platforms. When it doesn't exist, use "mediump". #define QOpenGL_REDEFINE_HIGHP 1 @@ -424,10 +419,19 @@ bool QOpenGLShader::compileSourceCode(const char *source) src.append(source); srclen.append(GLint(headerLen)); } -#ifdef QOpenGL_DEFINE_QUALIFIERS - src.append(qualifierDefines); - srclen.append(GLint(sizeof(qualifierDefines) - 1)); + + // The precision qualifiers are useful on OpenGL/ES systems, + // but usually not present on desktop systems. + const QSurfaceFormat currentSurfaceFormat = QOpenGLContext::currentContext()->format(); + if (currentSurfaceFormat.renderableType() == QSurfaceFormat::OpenGL +#ifdef QT_OPENGL_FORCE_SHADER_DEFINES + || true #endif + ) { + src.append(qualifierDefines); + srclen.append(GLint(sizeof(qualifierDefines) - 1)); + } + #ifdef QOpenGL_REDEFINE_HIGHP if (d->shaderType == Fragment) { src.append(redefineHighp); -- cgit v1.2.3