diff options
Diffstat (limited to 'src/opengl/qglshaderprogram.cpp')
-rw-r--r-- | src/opengl/qglshaderprogram.cpp | 299 |
1 files changed, 145 insertions, 154 deletions
diff --git a/src/opengl/qglshaderprogram.cpp b/src/opengl/qglshaderprogram.cpp index 537921bdc4..4859df21d6 100644 --- a/src/opengl/qglshaderprogram.cpp +++ b/src/opengl/qglshaderprogram.cpp @@ -40,7 +40,7 @@ ****************************************************************************/ #include "qglshaderprogram.h" -#include "qglextensions_p.h" +#include <private/qopenglextensions_p.h> #include "qgl_p.h" #include <QtCore/private/qobject_p.h> #include <QtCore/qdebug.h> @@ -197,10 +197,11 @@ class QGLShaderPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QGLShader) public: - QGLShaderPrivate(const QGLContext *, QGLShader::ShaderType type) + QGLShaderPrivate(const QGLContext *ctx, QGLShader::ShaderType type) : shaderGuard(0) , shaderType(type) , compiled(false) + , glfuncs(new QOpenGLFunctions(ctx->contextHandle())) { } ~QGLShaderPrivate(); @@ -210,6 +211,8 @@ public: bool compiled; QString log; + QOpenGLFunctions *glfuncs; + bool create(); bool compile(QGLShader *q); void deleteShader(); @@ -218,8 +221,8 @@ public: namespace { void freeShaderFunc(QGLContext *ctx, GLuint id) { - Q_UNUSED(ctx); - glDeleteShader(id); + Q_ASSERT(ctx); + ctx->contextHandle()->functions()->glDeleteShader(id); } } @@ -227,6 +230,7 @@ namespace { QGLShaderPrivate::~QGLShaderPrivate() { + delete glfuncs; if (shaderGuard) shaderGuard->free(); } @@ -236,16 +240,17 @@ bool QGLShaderPrivate::create() QGLContext *context = const_cast<QGLContext *>(QGLContext::currentContext()); if (!context) return false; - if (qt_resolve_glsl_extensions(context)) { + + if (glfuncs->hasOpenGLFeature(QOpenGLFunctions::Shaders)) { GLuint shader; if (shaderType == QGLShader::Vertex) - shader = glCreateShader(GL_VERTEX_SHADER); + shader = glfuncs->glCreateShader(GL_VERTEX_SHADER); #if !defined(QT_OPENGL_ES_2) else if (shaderType == QGLShader::Geometry) - shader = glCreateShader(GL_GEOMETRY_SHADER_EXT); + shader = glfuncs->glCreateShader(GL_GEOMETRY_SHADER_EXT); #endif else - shader = glCreateShader(GL_FRAGMENT_SHADER); + shader = glfuncs->glCreateShader(GL_FRAGMENT_SHADER); if (!shader) { qWarning("%s: Could not create shader of type %d.", Q_FUNC_INFO, int(shaderType)); @@ -263,16 +268,16 @@ bool QGLShaderPrivate::compile(QGLShader *q) GLuint shader = shaderGuard ? shaderGuard->id() : 0; if (!shader) return false; - glCompileShader(shader); + glfuncs->glCompileShader(shader); GLint value = 0; - glGetShaderiv(shader, GL_COMPILE_STATUS, &value); + glfuncs->glGetShaderiv(shader, GL_COMPILE_STATUS, &value); compiled = (value != 0); value = 0; - glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &value); + glfuncs->glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &value); if (!compiled && value > 1) { char *logbuf = new char [value]; GLint len; - glGetShaderInfoLog(shader, value, &len, logbuf); + glfuncs->glGetShaderInfoLog(shader, value, &len, logbuf); log = QString::fromLatin1(logbuf); QString name = q->objectName(); @@ -434,7 +439,7 @@ bool QGLShader::compileSourceCode(const char *source) #endif src.append(source + headerLen); srclen.append(GLint(qstrlen(source + headerLen))); - glShaderSource(d->shaderGuard->id(), src.size(), src.data(), srclen.data()); + d->glfuncs->glShaderSource(d->shaderGuard->id(), src.size(), src.data(), srclen.data()); return d->compile(this); } else { return false; @@ -498,12 +503,12 @@ QByteArray QGLShader::sourceCode() const if (!shader) return QByteArray(); GLint size = 0; - glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &size); + d->glfuncs->glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &size); if (size <= 0) return QByteArray(); GLint len = 0; char *source = new char [size]; - glGetShaderSource(shader, size, &len, source); + d->glfuncs->glGetShaderSource(shader, size, &len, source); QByteArray src(source); delete [] source; return src; @@ -544,6 +549,32 @@ GLuint QGLShader::shaderId() const #undef ctx +class ShaderProgramOpenGLFunctions : public QOpenGLFunctions +{ +public: + ShaderProgramOpenGLFunctions() + : QOpenGLFunctions() + , glProgramParameteri(0) + { + } + + typedef void (QOPENGLF_APIENTRYP type_glProgramParameteri)(GLuint program, GLenum pname, GLint value); + + void initializeGeometryShaderFunctions() + { + QOpenGLContext *context = QOpenGLContext::currentContext(); + glProgramParameteri = (type_glProgramParameteri) + context->getProcAddress("glProgramParameteri"); + + if (!glProgramParameteri) { + glProgramParameteri = (type_glProgramParameteri) + context->getProcAddress("glProgramParameteriEXT"); + } + } + + type_glProgramParameteri glProgramParameteri; +}; + class QGLShaderProgramPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QGLShaderProgram) @@ -556,6 +587,7 @@ public: , geometryVertexCount(64) , geometryInputType(0) , geometryOutputType(0) + , glfuncs(new ShaderProgramOpenGLFunctions) { } ~QGLShaderProgramPrivate(); @@ -573,20 +605,23 @@ public: QList<QGLShader *> shaders; QList<QGLShader *> anonShaders; + ShaderProgramOpenGLFunctions *glfuncs; + bool hasShader(QGLShader::ShaderType type) const; }; namespace { void freeProgramFunc(QGLContext *ctx, GLuint id) { - Q_UNUSED(ctx); - glDeleteProgram(id); + Q_ASSERT(ctx); + ctx->contextHandle()->functions()->glDeleteProgram(id); } } QGLShaderProgramPrivate::~QGLShaderProgramPrivate() { + delete glfuncs; if (programGuard) programGuard->free(); } @@ -644,8 +679,10 @@ bool QGLShaderProgram::init() QGLContext *context = const_cast<QGLContext *>(QGLContext::currentContext()); if (!context) return false; - if (qt_resolve_glsl_extensions(context)) { - GLuint program = glCreateProgram(); + d->glfuncs->initializeOpenGLFunctions(); + d->glfuncs->initializeGeometryShaderFunctions(); + if (d->glfuncs->hasOpenGLFeature(QOpenGLFunctions::Shaders)) { + GLuint program = d->glfuncs->glCreateProgram(); if (!program) { qWarning() << "QGLShaderProgram: could not create shader program"; return false; @@ -686,7 +723,7 @@ bool QGLShaderProgram::addShader(QGLShader *shader) qWarning("QGLShaderProgram::addShader: Program and shader are not associated with same context."); return false; } - glAttachShader(d->programGuard->id(), shader->d_func()->shaderGuard->id()); + d->glfuncs->glAttachShader(d->programGuard->id(), shader->d_func()->shaderGuard->id()); d->linked = false; // Program needs to be relinked. d->shaders.append(shader); connect(shader, SIGNAL(destroyed()), this, SLOT(shaderDestroyed())); @@ -805,7 +842,7 @@ void QGLShaderProgram::removeShader(QGLShader *shader) if (d->programGuard && d->programGuard->id() && shader && shader->d_func()->shaderGuard) { - glDetachShader(d->programGuard->id(), shader->d_func()->shaderGuard->id()); + d->glfuncs->glDetachShader(d->programGuard->id(), shader->d_func()->shaderGuard->id()); } d->linked = false; // Program needs to be relinked. if (shader) { @@ -843,7 +880,7 @@ void QGLShaderProgram::removeAllShaders() if (d->programGuard && d->programGuard->id() && shader && shader->d_func()->shaderGuard) { - glDetachShader(d->programGuard->id(), shader->d_func()->shaderGuard->id()); + d->glfuncs->glDetachShader(d->programGuard->id(), shader->d_func()->shaderGuard->id()); } } foreach (QGLShader *shader, d->anonShaders) { @@ -884,7 +921,7 @@ bool QGLShaderProgram::link() // or otherwise populated the shaders itself. Check to see if the // program is already linked and bail out if so. value = 0; - glGetProgramiv(program, GL_LINK_STATUS, &value); + d->glfuncs->glGetProgramiv(program, GL_LINK_STATUS, &value); d->linked = (value != 0); if (d->linked) return true; @@ -892,14 +929,14 @@ bool QGLShaderProgram::link() #if !defined(QT_OPENGL_ES_2) // Set up the geometry shader parameters - if (glProgramParameteriEXT) { + if (d->glfuncs->glProgramParameteri) { foreach (QGLShader *shader, d->shaders) { if (shader->shaderType() & QGLShader::Geometry) { - glProgramParameteriEXT(program, GL_GEOMETRY_INPUT_TYPE_EXT, + d->glfuncs->glProgramParameteri(program, GL_GEOMETRY_INPUT_TYPE_EXT, d->geometryInputType); - glProgramParameteriEXT(program, GL_GEOMETRY_OUTPUT_TYPE_EXT, + d->glfuncs->glProgramParameteri(program, GL_GEOMETRY_OUTPUT_TYPE_EXT, d->geometryOutputType); - glProgramParameteriEXT(program, GL_GEOMETRY_VERTICES_OUT_EXT, + d->glfuncs->glProgramParameteri(program, GL_GEOMETRY_VERTICES_OUT_EXT, d->geometryVertexCount); break; } @@ -907,17 +944,17 @@ bool QGLShaderProgram::link() } #endif - glLinkProgram(program); + d->glfuncs->glLinkProgram(program); value = 0; - glGetProgramiv(program, GL_LINK_STATUS, &value); + d->glfuncs->glGetProgramiv(program, GL_LINK_STATUS, &value); d->linked = (value != 0); value = 0; - glGetProgramiv(program, GL_INFO_LOG_LENGTH, &value); + d->glfuncs->glGetProgramiv(program, GL_INFO_LOG_LENGTH, &value); d->log = QString(); if (value > 1) { char *logbuf = new char [value]; GLint len; - glGetProgramInfoLog(program, value, &len, logbuf); + d->glfuncs->glGetProgramInfoLog(program, value, &len, logbuf); d->log = QString::fromLatin1(logbuf); QString name = objectName(); if (name.isEmpty()) @@ -976,7 +1013,7 @@ bool QGLShaderProgram::bind() return false; } #endif - glUseProgram(program); + d->glfuncs->glUseProgram(program); return true; } @@ -991,17 +1028,12 @@ bool QGLShaderProgram::bind() */ void QGLShaderProgram::release() { -#ifndef QT_NO_DEBUG Q_D(QGLShaderProgram); +#ifndef QT_NO_DEBUG if (d->programGuard && d->programGuard->group() != QOpenGLContextGroup::currentContextGroup()) qWarning("QGLShaderProgram::release: program is not valid in the current context."); #endif -#if defined(QT_OPENGL_ES_2) - glUseProgram(0); -#else - if (glUseProgram) - glUseProgram(0); -#endif + d->glfuncs->glUseProgram(0); } /*! @@ -1040,7 +1072,7 @@ void QGLShaderProgram::bindAttributeLocation(const char *name, int location) Q_D(QGLShaderProgram); if (!init() || !d->programGuard || !d->programGuard->id()) return; - glBindAttribLocation(d->programGuard->id(), location, name); + d->glfuncs->glBindAttribLocation(d->programGuard->id(), location, name); d->linked = false; // Program needs to be relinked. } @@ -1091,7 +1123,7 @@ int QGLShaderProgram::attributeLocation(const char *name) const { Q_D(const QGLShaderProgram); if (d->linked && d->programGuard && d->programGuard->id()) { - return glGetAttribLocation(d->programGuard->id(), name); + return d->glfuncs->glGetAttribLocation(d->programGuard->id(), name); } else { qWarning() << "QGLShaderProgram::attributeLocation(" << name << "): shader program is not linked"; @@ -1137,7 +1169,7 @@ void QGLShaderProgram::setAttributeValue(int location, GLfloat value) Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) - glVertexAttrib1fv(location, &value); + d->glfuncs->glVertexAttrib1fv(location, &value); } /*! @@ -1164,7 +1196,7 @@ void QGLShaderProgram::setAttributeValue(int location, GLfloat x, GLfloat y) Q_UNUSED(d); if (location != -1) { GLfloat values[2] = {x, y}; - glVertexAttrib2fv(location, values); + d->glfuncs->glVertexAttrib2fv(location, values); } } @@ -1194,7 +1226,7 @@ void QGLShaderProgram::setAttributeValue Q_UNUSED(d); if (location != -1) { GLfloat values[3] = {x, y, z}; - glVertexAttrib3fv(location, values); + d->glfuncs->glVertexAttrib3fv(location, values); } } @@ -1225,7 +1257,7 @@ void QGLShaderProgram::setAttributeValue Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {x, y, z, w}; - glVertexAttrib4fv(location, values); + d->glfuncs->glVertexAttrib4fv(location, values); } } @@ -1253,7 +1285,7 @@ void QGLShaderProgram::setAttributeValue(int location, const QVector2D& value) Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) - glVertexAttrib2fv(location, reinterpret_cast<const GLfloat *>(&value)); + d->glfuncs->glVertexAttrib2fv(location, reinterpret_cast<const GLfloat *>(&value)); } /*! @@ -1278,7 +1310,7 @@ void QGLShaderProgram::setAttributeValue(int location, const QVector3D& value) Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) - glVertexAttrib3fv(location, reinterpret_cast<const GLfloat *>(&value)); + d->glfuncs->glVertexAttrib3fv(location, reinterpret_cast<const GLfloat *>(&value)); } /*! @@ -1303,7 +1335,7 @@ void QGLShaderProgram::setAttributeValue(int location, const QVector4D& value) Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) - glVertexAttrib4fv(location, reinterpret_cast<const GLfloat *>(&value)); + d->glfuncs->glVertexAttrib4fv(location, reinterpret_cast<const GLfloat *>(&value)); } /*! @@ -1330,7 +1362,7 @@ void QGLShaderProgram::setAttributeValue(int location, const QColor& value) if (location != -1) { GLfloat values[4] = {GLfloat(value.redF()), GLfloat(value.greenF()), GLfloat(value.blueF()), GLfloat(value.alphaF())}; - glVertexAttrib4fv(location, values); + d->glfuncs->glVertexAttrib4fv(location, values); } } @@ -1367,13 +1399,13 @@ void QGLShaderProgram::setAttributeValue if (location != -1) { while (columns-- > 0) { if (rows == 1) - glVertexAttrib1fv(location, values); + d->glfuncs->glVertexAttrib1fv(location, values); else if (rows == 2) - glVertexAttrib2fv(location, values); + d->glfuncs->glVertexAttrib2fv(location, values); else if (rows == 3) - glVertexAttrib3fv(location, values); + d->glfuncs->glVertexAttrib3fv(location, values); else - glVertexAttrib4fv(location, values); + d->glfuncs->glVertexAttrib4fv(location, values); values += rows; ++location; } @@ -1417,7 +1449,7 @@ void QGLShaderProgram::setAttributeArray Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) { - glVertexAttribPointer(location, tupleSize, GL_FLOAT, GL_FALSE, + d->glfuncs->glVertexAttribPointer(location, tupleSize, GL_FLOAT, GL_FALSE, stride, values); } } @@ -1441,7 +1473,7 @@ void QGLShaderProgram::setAttributeArray Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) { - glVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE, + d->glfuncs->glVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE, stride, values); } } @@ -1465,7 +1497,7 @@ void QGLShaderProgram::setAttributeArray Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) { - glVertexAttribPointer(location, 3, GL_FLOAT, GL_FALSE, + d->glfuncs->glVertexAttribPointer(location, 3, GL_FLOAT, GL_FALSE, stride, values); } } @@ -1489,7 +1521,7 @@ void QGLShaderProgram::setAttributeArray Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) { - glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, + d->glfuncs->glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, stride, values); } } @@ -1521,7 +1553,7 @@ void QGLShaderProgram::setAttributeArray Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) { - glVertexAttribPointer(location, tupleSize, type, GL_TRUE, + d->glfuncs->glVertexAttribPointer(location, tupleSize, type, GL_TRUE, stride, values); } } @@ -1665,7 +1697,7 @@ void QGLShaderProgram::setAttributeBuffer Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) { - glVertexAttribPointer(location, tupleSize, type, GL_TRUE, stride, + d->glfuncs->glVertexAttribPointer(location, tupleSize, type, GL_TRUE, stride, reinterpret_cast<const void *>(offset)); } } @@ -1710,7 +1742,7 @@ void QGLShaderProgram::enableAttributeArray(int location) Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) - glEnableVertexAttribArray(location); + d->glfuncs->glEnableVertexAttribArray(location); } /*! @@ -1740,7 +1772,7 @@ void QGLShaderProgram::disableAttributeArray(int location) Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) - glDisableVertexAttribArray(location); + d->glfuncs->glDisableVertexAttribArray(location); } /*! @@ -1769,7 +1801,7 @@ int QGLShaderProgram::uniformLocation(const char *name) const Q_D(const QGLShaderProgram); Q_UNUSED(d); if (d->linked && d->programGuard && d->programGuard->id()) { - return glGetUniformLocation(d->programGuard->id(), name); + return d->glfuncs->glGetUniformLocation(d->programGuard->id(), name); } else { qWarning() << "QGLShaderProgram::uniformLocation(" << name << "): shader program is not linked"; @@ -1815,7 +1847,7 @@ void QGLShaderProgram::setUniformValue(int location, GLfloat value) Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) - glUniform1fv(location, 1, &value); + d->glfuncs->glUniform1fv(location, 1, &value); } /*! @@ -1841,7 +1873,7 @@ void QGLShaderProgram::setUniformValue(int location, GLint value) Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) - glUniform1i(location, value); + d->glfuncs->glUniform1i(location, value); } /*! @@ -1868,7 +1900,7 @@ void QGLShaderProgram::setUniformValue(int location, GLuint value) Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) - glUniform1i(location, value); + d->glfuncs->glUniform1i(location, value); } /*! @@ -1896,7 +1928,7 @@ void QGLShaderProgram::setUniformValue(int location, GLfloat x, GLfloat y) Q_UNUSED(d); if (location != -1) { GLfloat values[2] = {x, y}; - glUniform2fv(location, 1, values); + d->glfuncs->glUniform2fv(location, 1, values); } } @@ -1926,7 +1958,7 @@ void QGLShaderProgram::setUniformValue Q_UNUSED(d); if (location != -1) { GLfloat values[3] = {x, y, z}; - glUniform3fv(location, 1, values); + d->glfuncs->glUniform3fv(location, 1, values); } } @@ -1957,7 +1989,7 @@ void QGLShaderProgram::setUniformValue Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {x, y, z, w}; - glUniform4fv(location, 1, values); + d->glfuncs->glUniform4fv(location, 1, values); } } @@ -1985,7 +2017,7 @@ void QGLShaderProgram::setUniformValue(int location, const QVector2D& value) Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) - glUniform2fv(location, 1, reinterpret_cast<const GLfloat *>(&value)); + d->glfuncs->glUniform2fv(location, 1, reinterpret_cast<const GLfloat *>(&value)); } /*! @@ -2011,7 +2043,7 @@ void QGLShaderProgram::setUniformValue(int location, const QVector3D& value) Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) - glUniform3fv(location, 1, reinterpret_cast<const GLfloat *>(&value)); + d->glfuncs->glUniform3fv(location, 1, reinterpret_cast<const GLfloat *>(&value)); } /*! @@ -2037,7 +2069,7 @@ void QGLShaderProgram::setUniformValue(int location, const QVector4D& value) Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) - glUniform4fv(location, 1, reinterpret_cast<const GLfloat *>(&value)); + d->glfuncs->glUniform4fv(location, 1, reinterpret_cast<const GLfloat *>(&value)); } /*! @@ -2066,7 +2098,7 @@ void QGLShaderProgram::setUniformValue(int location, const QColor& color) if (location != -1) { GLfloat values[4] = {GLfloat(color.redF()), GLfloat(color.greenF()), GLfloat(color.blueF()), GLfloat(color.alphaF())}; - glUniform4fv(location, 1, values); + d->glfuncs->glUniform4fv(location, 1, values); } } @@ -2095,7 +2127,7 @@ void QGLShaderProgram::setUniformValue(int location, const QPoint& point) Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {GLfloat(point.x()), GLfloat(point.y())}; - glUniform2fv(location, 1, values); + d->glfuncs->glUniform2fv(location, 1, values); } } @@ -2124,7 +2156,7 @@ void QGLShaderProgram::setUniformValue(int location, const QPointF& point) Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {GLfloat(point.x()), GLfloat(point.y())}; - glUniform2fv(location, 1, values); + d->glfuncs->glUniform2fv(location, 1, values); } } @@ -2153,7 +2185,7 @@ void QGLShaderProgram::setUniformValue(int location, const QSize& size) Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {GLfloat(size.width()), GLfloat(size.height())}; - glUniform2fv(location, 1, values); + d->glfuncs->glUniform2fv(location, 1, values); } } @@ -2182,7 +2214,7 @@ void QGLShaderProgram::setUniformValue(int location, const QSizeF& size) Q_UNUSED(d); if (location != -1) { GLfloat values[4] = {GLfloat(size.width()), GLfloat(size.height())}; - glUniform2fv(location, 1, values); + d->glfuncs->glUniform2fv(location, 1, values); } } @@ -2208,8 +2240,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QSizeF& size) void QGLShaderProgram::setUniformValue(int location, const QMatrix2x2& value) { Q_D(QGLShaderProgram); - Q_UNUSED(d); - glUniformMatrix2fv(location, 1, GL_FALSE, value.constData()); + d->glfuncs->glUniformMatrix2fv(location, 1, GL_FALSE, value.constData()); } /*! @@ -2234,8 +2265,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x2& value void QGLShaderProgram::setUniformValue(int location, const QMatrix2x3& value) { Q_D(QGLShaderProgram); - Q_UNUSED(d); - glUniform3fv(location, 2, value.constData()); + d->glfuncs->glUniform3fv(location, 2, value.constData()); } /*! @@ -2260,8 +2290,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x3& value void QGLShaderProgram::setUniformValue(int location, const QMatrix2x4& value) { Q_D(QGLShaderProgram); - Q_UNUSED(d); - glUniform4fv(location, 2, value.constData()); + d->glfuncs->glUniform4fv(location, 2, value.constData()); } /*! @@ -2286,8 +2315,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix2x4& value void QGLShaderProgram::setUniformValue(int location, const QMatrix3x2& value) { Q_D(QGLShaderProgram); - Q_UNUSED(d); - glUniform2fv(location, 3, value.constData()); + d->glfuncs->glUniform2fv(location, 3, value.constData()); } /*! @@ -2312,8 +2340,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x2& value void QGLShaderProgram::setUniformValue(int location, const QMatrix3x3& value) { Q_D(QGLShaderProgram); - Q_UNUSED(d); - glUniformMatrix3fv(location, 1, GL_FALSE, value.constData()); + d->glfuncs->glUniformMatrix3fv(location, 1, GL_FALSE, value.constData()); } /*! @@ -2338,8 +2365,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x3& value void QGLShaderProgram::setUniformValue(int location, const QMatrix3x4& value) { Q_D(QGLShaderProgram); - Q_UNUSED(d); - glUniform4fv(location, 3, value.constData()); + d->glfuncs->glUniform4fv(location, 3, value.constData()); } /*! @@ -2364,8 +2390,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix3x4& value void QGLShaderProgram::setUniformValue(int location, const QMatrix4x2& value) { Q_D(QGLShaderProgram); - Q_UNUSED(d); - glUniform2fv(location, 4, value.constData()); + d->glfuncs->glUniform2fv(location, 4, value.constData()); } /*! @@ -2390,8 +2415,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix4x2& value void QGLShaderProgram::setUniformValue(int location, const QMatrix4x3& value) { Q_D(QGLShaderProgram); - Q_UNUSED(d); - glUniform3fv(location, 4, value.constData()); + d->glfuncs->glUniform3fv(location, 4, value.constData()); } /*! @@ -2416,8 +2440,7 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix4x3& value void QGLShaderProgram::setUniformValue(int location, const QMatrix4x4& value) { Q_D(QGLShaderProgram); - Q_UNUSED(d); - glUniformMatrix4fv(location, 1, GL_FALSE, value.constData()); + d->glfuncs->glUniformMatrix4fv(location, 1, GL_FALSE, value.constData()); } /*! @@ -2446,9 +2469,8 @@ void QGLShaderProgram::setUniformValue(const char *name, const QMatrix4x4& value void QGLShaderProgram::setUniformValue(int location, const GLfloat value[2][2]) { Q_D(QGLShaderProgram); - Q_UNUSED(d); if (location != -1) - glUniformMatrix2fv(location, 1, GL_FALSE, value[0]); + d->glfuncs->glUniformMatrix2fv(location, 1, GL_FALSE, value[0]); } /*! @@ -2464,9 +2486,8 @@ void QGLShaderProgram::setUniformValue(int location, const GLfloat value[2][2]) void QGLShaderProgram::setUniformValue(int location, const GLfloat value[3][3]) { Q_D(QGLShaderProgram); - Q_UNUSED(d); if (location != -1) - glUniformMatrix3fv(location, 1, GL_FALSE, value[0]); + d->glfuncs->glUniformMatrix3fv(location, 1, GL_FALSE, value[0]); } /*! @@ -2481,9 +2502,8 @@ void QGLShaderProgram::setUniformValue(int location, const GLfloat value[3][3]) void QGLShaderProgram::setUniformValue(int location, const GLfloat value[4][4]) { Q_D(QGLShaderProgram); - Q_UNUSED(d); if (location != -1) - glUniformMatrix4fv(location, 1, GL_FALSE, value[0]); + d->glfuncs->glUniformMatrix4fv(location, 1, GL_FALSE, value[0]); } @@ -2541,14 +2561,13 @@ void QGLShaderProgram::setUniformValue(const char *name, const GLfloat value[4][ void QGLShaderProgram::setUniformValue(int location, const QTransform& value) { Q_D(QGLShaderProgram); - Q_UNUSED(d); if (location != -1) { GLfloat mat[3][3] = { {GLfloat(value.m11()), GLfloat(value.m12()), GLfloat(value.m13())}, {GLfloat(value.m21()), GLfloat(value.m22()), GLfloat(value.m23())}, {GLfloat(value.m31()), GLfloat(value.m32()), GLfloat(value.m33())} }; - glUniformMatrix3fv(location, 1, GL_FALSE, mat[0]); + d->glfuncs->glUniformMatrix3fv(location, 1, GL_FALSE, mat[0]); } } @@ -2576,9 +2595,8 @@ void QGLShaderProgram::setUniformValue void QGLShaderProgram::setUniformValueArray(int location, const GLint *values, int count) { Q_D(QGLShaderProgram); - Q_UNUSED(d); if (location != -1) - glUniform1iv(location, count, values); + d->glfuncs->glUniform1iv(location, count, values); } /*! @@ -2605,9 +2623,8 @@ void QGLShaderProgram::setUniformValueArray void QGLShaderProgram::setUniformValueArray(int location, const GLuint *values, int count) { Q_D(QGLShaderProgram); - Q_UNUSED(d); if (location != -1) - glUniform1iv(location, count, reinterpret_cast<const GLint *>(values)); + d->glfuncs->glUniform1iv(location, count, reinterpret_cast<const GLint *>(values)); } /*! @@ -2635,16 +2652,15 @@ void QGLShaderProgram::setUniformValueArray void QGLShaderProgram::setUniformValueArray(int location, const GLfloat *values, int count, int tupleSize) { Q_D(QGLShaderProgram); - Q_UNUSED(d); if (location != -1) { if (tupleSize == 1) - glUniform1fv(location, count, values); + d->glfuncs->glUniform1fv(location, count, values); else if (tupleSize == 2) - glUniform2fv(location, count, values); + d->glfuncs->glUniform2fv(location, count, values); else if (tupleSize == 3) - glUniform3fv(location, count, values); + d->glfuncs->glUniform3fv(location, count, values); else if (tupleSize == 4) - glUniform4fv(location, count, values); + d->glfuncs->glUniform4fv(location, count, values); else qWarning() << "QGLShaderProgram::setUniformValue: size" << tupleSize << "not supported"; } @@ -2674,9 +2690,8 @@ void QGLShaderProgram::setUniformValueArray void QGLShaderProgram::setUniformValueArray(int location, const QVector2D *values, int count) { Q_D(QGLShaderProgram); - Q_UNUSED(d); if (location != -1) - glUniform2fv(location, count, reinterpret_cast<const GLfloat *>(values)); + d->glfuncs->glUniform2fv(location, count, reinterpret_cast<const GLfloat *>(values)); } /*! @@ -2701,9 +2716,8 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QVector2D *v void QGLShaderProgram::setUniformValueArray(int location, const QVector3D *values, int count) { Q_D(QGLShaderProgram); - Q_UNUSED(d); if (location != -1) - glUniform3fv(location, count, reinterpret_cast<const GLfloat *>(values)); + d->glfuncs->glUniform3fv(location, count, reinterpret_cast<const GLfloat *>(values)); } /*! @@ -2730,7 +2744,7 @@ void QGLShaderProgram::setUniformValueArray(int location, const QVector4D *value Q_D(QGLShaderProgram); Q_UNUSED(d); if (location != -1) - glUniform4fv(location, count, reinterpret_cast<const GLfloat *>(values)); + d->glfuncs->glUniform4fv(location, count, reinterpret_cast<const GLfloat *>(values)); } /*! @@ -2763,32 +2777,7 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QVector4D *v } \ func(location, count, GL_FALSE, temp.constData()); \ } -#if !defined(QT_OPENGL_ES_2) -#define setUniformGenericMatrixArray(func,colfunc,location,values,count,type,cols,rows) \ - if (location == -1 || count <= 0) \ - return; \ - if (sizeof(type) == sizeof(GLfloat) * cols * rows) { \ - const GLfloat *data = reinterpret_cast<const GLfloat *> \ - (values[0].constData()); \ - if (func) \ - func(location, count, GL_FALSE, data); \ - else \ - colfunc(location, count * cols, data); \ - } else { \ - QVarLengthArray<GLfloat> temp(cols * rows * count); \ - for (int index = 0; index < count; ++index) { \ - for (int index2 = 0; index2 < (cols * rows); ++index2) { \ - temp.data()[cols * rows * index + index2] = \ - values[index].constData()[index2]; \ - } \ - } \ - if (func) \ - func(location, count, GL_FALSE, temp.constData()); \ - else \ - colfunc(location, count * cols, temp.constData()); \ - } -#else -#define setUniformGenericMatrixArray(func,colfunc,location,values,count,type,cols,rows) \ +#define setUniformGenericMatrixArray(colfunc,location,values,count,type,cols,rows) \ if (location == -1 || count <= 0) \ return; \ if (sizeof(type) == sizeof(GLfloat) * cols * rows) { \ @@ -2805,7 +2794,6 @@ void QGLShaderProgram::setUniformValueArray(const char *name, const QVector4D *v } \ colfunc(location, count * cols, temp.constData()); \ } -#endif /*! Sets the uniform variable array at \a location in the current @@ -2818,7 +2806,7 @@ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix2x2 *valu Q_D(QGLShaderProgram); Q_UNUSED(d); setUniformMatrixArray - (glUniformMatrix2fv, location, values, count, QMatrix2x2, 2, 2); + (d->glfuncs->glUniformMatrix2fv, location, values, count, QMatrix2x2, 2, 2); } /*! @@ -2845,7 +2833,7 @@ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix2x3 *valu Q_D(QGLShaderProgram); Q_UNUSED(d); setUniformGenericMatrixArray - (glUniformMatrix2x3fv, glUniform3fv, location, values, count, + (d->glfuncs->glUniform3fv, location, values, count, QMatrix2x3, 2, 3); } @@ -2873,7 +2861,7 @@ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix2x4 *valu Q_D(QGLShaderProgram); Q_UNUSED(d); setUniformGenericMatrixArray - (glUniformMatrix2x4fv, glUniform4fv, location, values, count, + (d->glfuncs->glUniform4fv, location, values, count, QMatrix2x4, 2, 4); } @@ -2901,7 +2889,7 @@ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix3x2 *valu Q_D(QGLShaderProgram); Q_UNUSED(d); setUniformGenericMatrixArray - (glUniformMatrix3x2fv, glUniform2fv, location, values, count, + (d->glfuncs->glUniform2fv, location, values, count, QMatrix3x2, 3, 2); } @@ -2929,7 +2917,7 @@ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix3x3 *valu Q_D(QGLShaderProgram); Q_UNUSED(d); setUniformMatrixArray - (glUniformMatrix3fv, location, values, count, QMatrix3x3, 3, 3); + (d->glfuncs->glUniformMatrix3fv, location, values, count, QMatrix3x3, 3, 3); } /*! @@ -2956,7 +2944,7 @@ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix3x4 *valu Q_D(QGLShaderProgram); Q_UNUSED(d); setUniformGenericMatrixArray - (glUniformMatrix3x4fv, glUniform4fv, location, values, count, + (d->glfuncs->glUniform4fv, location, values, count, QMatrix3x4, 3, 4); } @@ -2984,7 +2972,7 @@ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix4x2 *valu Q_D(QGLShaderProgram); Q_UNUSED(d); setUniformGenericMatrixArray - (glUniformMatrix4x2fv, glUniform2fv, location, values, count, + (d->glfuncs->glUniform2fv, location, values, count, QMatrix4x2, 4, 2); } @@ -3012,7 +3000,7 @@ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix4x3 *valu Q_D(QGLShaderProgram); Q_UNUSED(d); setUniformGenericMatrixArray - (glUniformMatrix4x3fv, glUniform3fv, location, values, count, + (d->glfuncs->glUniform3fv, location, values, count, QMatrix4x3, 4, 3); } @@ -3040,7 +3028,7 @@ void QGLShaderProgram::setUniformValueArray(int location, const QMatrix4x4 *valu Q_D(QGLShaderProgram); Q_UNUSED(d); setUniformMatrixArray - (glUniformMatrix4fv, location, values, count, QMatrix4x4, 4, 4); + (d->glfuncs->glUniformMatrix4fv, location, values, count, QMatrix4x4, 4, 4); } /*! @@ -3176,7 +3164,9 @@ bool QGLShaderProgram::hasOpenGLShaderPrograms(const QGLContext *context) context = QGLContext::currentContext(); if (!context) return false; - return qt_resolve_glsl_extensions(const_cast<QGLContext *>(context)); + + QOpenGLFunctions functions(context->contextHandle()); + return functions.hasOpenGLFeature(QOpenGLFunctions::Shaders); #else Q_UNUSED(context); return true; @@ -3217,7 +3207,8 @@ bool QGLShader::hasOpenGLShaders(ShaderType type, const QGLContext *context) if ((type & ~(Geometry | Vertex | Fragment)) || type == 0) return false; - bool resolved = qt_resolve_glsl_extensions(const_cast<QGLContext *>(context)); + QOpenGLFunctions functions(context->contextHandle()); + bool resolved = functions.hasOpenGLFeature(QOpenGLFunctions::Shaders); if (!resolved) return false; |