diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2013-02-17 12:11:30 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-01 22:10:25 +0100 |
commit | 658616b44e8d6ff860ab2f58ff6e51f89c212f95 (patch) | |
tree | 89288470868019283ed46d66b4485958e646e536 /src | |
parent | d711f98bfbb8ff34279b019094595e02b3c592e4 (diff) |
QOpenGLShaderProgram: insert precision defines based on runtime detection
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 <samuel.rodal@digia.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/opengl/qopenglshaderprogram.cpp | 24 |
1 files 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 <QtCore/qvector.h> #include <QtGui/qtransform.h> #include <QtGui/QColor> +#include <QtGui/QSurfaceFormat> #if !defined(QT_OPENGL_ES_2) #include <QtGui/qopenglfunctions_4_0_core.h> @@ -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); |