From 8c4d02ef875518be21f63bd115a0bec813da5a91 Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Fri, 1 Mar 2013 16:32:04 +0000 Subject: [PATCH] OpenGL: Add support for the Compute shader stage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ibb1b79358758c2adf818af8c6fcd5c379efad8c3 Reviewed-by: Samuel Rødal --- src/gui/opengl/qopengl.h | 1 + src/gui/opengl/qopenglshaderprogram.cpp | 15 ++++++++++++++- src/gui/opengl/qopenglshaderprogram.h | 3 ++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/gui/opengl/qopengl.h b/src/gui/opengl/qopengl.h index df63eac1f7..e4e06ba284 100644 --- a/src/gui/opengl/qopengl.h +++ b/src/gui/opengl/qopengl.h @@ -108,6 +108,7 @@ typedef GLfloat GLdouble; # endif #if !defined(Q_OS_MAC) # define QT_OPENGL_4 +# define QT_OPENGL_4_3 #endif #endif diff --git a/src/gui/opengl/qopenglshaderprogram.cpp b/src/gui/opengl/qopenglshaderprogram.cpp index e48b922dac..1cde0cb92d 100644 --- a/src/gui/opengl/qopenglshaderprogram.cpp +++ b/src/gui/opengl/qopenglshaderprogram.cpp @@ -156,6 +156,8 @@ QT_BEGIN_NAMESPACE shading language (GLSL), based on the core feature (requires OpenGL >= 4.0). \value TessellationEvaluation Tessellation evaluation shaders written in the OpenGL shading language (GLSL), based on the core feature (requires OpenGL >= 4.0). + \value Compute Compute shaders written in the OpenGL shading language (GLSL), + based on the core feature (requires OpenGL >= 4.3). */ class QOpenGLShaderPrivate : public QObjectPrivate @@ -235,6 +237,10 @@ bool QOpenGLShaderPrivate::create() shader = glfuncs->glCreateShader(GL_TESS_CONTROL_SHADER); } else if (shaderType == QOpenGLShader::TessellationEvaluation && supportsTessellationShaders) { shader = glfuncs->glCreateShader(GL_TESS_EVALUATION_SHADER); +#endif +#if defined(QT_OPENGL_4_3) + } else if (shaderType == QOpenGLShader::Compute) { + shader = glfuncs->glCreateShader(GL_COMPUTE_SHADER); #endif } else { shader = glfuncs->glCreateShader(GL_FRAGMENT_SHADER); @@ -3230,7 +3236,7 @@ bool QOpenGLShader::hasOpenGLShaders(ShaderType type, QOpenGLContext *context) if (!context) return false; - if ((type & ~(Geometry | Vertex | Fragment | TessellationControl | TessellationEvaluation)) || type == 0) + if ((type & ~(Geometry | Vertex | Fragment | TessellationControl | TessellationEvaluation | Compute)) || type == 0) return false; QSurfaceFormat format = context->format(); @@ -3249,6 +3255,13 @@ bool QOpenGLShader::hasOpenGLShaders(ShaderType type, QOpenGLContext *context) #else // No tessellation shader support in OpenGL ES2 return false; +#endif + } else if (type == Compute) { +#if defined(QT_OPENGL_4_3) + return (format.version() >= qMakePair(4, 3)); +#else + // No compute shader support without OpenGL 4.3 or newer + return false; #endif } diff --git a/src/gui/opengl/qopenglshaderprogram.h b/src/gui/opengl/qopenglshaderprogram.h index 3677779a6a..6c3dd37843 100644 --- a/src/gui/opengl/qopenglshaderprogram.h +++ b/src/gui/opengl/qopenglshaderprogram.h @@ -67,7 +67,8 @@ public: Fragment = 0x0002, Geometry = 0x0004, TessellationControl = 0x0008, - TessellationEvaluation = 0x0010 + TessellationEvaluation = 0x0010, + Compute = 0x0020 }; Q_DECLARE_FLAGS(ShaderType, ShaderTypeBit)