src/opengl/qglshaderprogram.cpp
changeset 30 5dc02b23752f
parent 22 79de32ba3296
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
    48 #include <QtCore/qvarlengtharray.h>
    48 #include <QtCore/qvarlengtharray.h>
    49 #include <QtCore/qvector.h>
    49 #include <QtCore/qvector.h>
    50 
    50 
    51 QT_BEGIN_NAMESPACE
    51 QT_BEGIN_NAMESPACE
    52 
    52 
    53 #if !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
    53 #if !defined(QT_OPENGL_ES_1)
    54 
    54 
    55 /*!
    55 /*!
    56     \class QGLShaderProgram
    56     \class QGLShaderProgram
    57     \brief The QGLShaderProgram class allows OpenGL shader programs to be linked and used.
    57     \brief The QGLShaderProgram class allows OpenGL shader programs to be linked and used.
    58     \since 4.6
    58     \since 4.6
   141     \enum QGLShader::ShaderTypeBit
   141     \enum QGLShader::ShaderTypeBit
   142     This enum specifies the type of QGLShader that is being created.
   142     This enum specifies the type of QGLShader that is being created.
   143 
   143 
   144     \value Vertex Vertex shader written in the OpenGL Shading Language (GLSL).
   144     \value Vertex Vertex shader written in the OpenGL Shading Language (GLSL).
   145     \value Fragment Fragment shader written in the OpenGL Shading Language (GLSL).
   145     \value Fragment Fragment shader written in the OpenGL Shading Language (GLSL).
       
   146     \value Geometry Geometry shaders written in the OpenGL Shading
       
   147            Language (GLSL), based on the GL_EXT_geometry_shader4 extension.
   146 */
   148 */
   147 
   149 
   148 #ifndef GL_FRAGMENT_SHADER
   150 #ifndef GL_FRAGMENT_SHADER
   149 #define GL_FRAGMENT_SHADER 0x8B30
   151 #define GL_FRAGMENT_SHADER 0x8B30
   150 #endif
   152 #endif
   224         return false;
   226         return false;
   225     if (qt_resolve_glsl_extensions(const_cast<QGLContext *>(context))) {
   227     if (qt_resolve_glsl_extensions(const_cast<QGLContext *>(context))) {
   226         GLuint shader;
   228         GLuint shader;
   227         if (shaderType == QGLShader::Vertex)
   229         if (shaderType == QGLShader::Vertex)
   228             shader = glCreateShader(GL_VERTEX_SHADER);
   230             shader = glCreateShader(GL_VERTEX_SHADER);
       
   231         else if (shaderType == QGLShader::Geometry)
       
   232             shader = glCreateShader(GL_GEOMETRY_SHADER_EXT);
   229         else
   233         else
   230             shader = glCreateShader(GL_FRAGMENT_SHADER);
   234             shader = glCreateShader(GL_FRAGMENT_SHADER);
   231         if (!shader) {
   235         if (!shader) {
   232             qWarning() << "QGLShader: could not create shader";
   236             qWarning() << "QGLShader: could not create shader";
   233             return false;
   237             return false;
   507 {
   511 {
   508     Q_D(const QGLShader);
   512     Q_D(const QGLShader);
   509     return d->shaderGuard.id();
   513     return d->shaderGuard.id();
   510 }
   514 }
   511 
   515 
       
   516 
       
   517 
       
   518 
       
   519 
   512 #undef ctx
   520 #undef ctx
   513 #define ctx programGuard.context()
   521 #define ctx programGuard.context()
   514 
   522 
   515 class QGLShaderProgramPrivate : public QObjectPrivate
   523 class QGLShaderProgramPrivate : public QObjectPrivate
   516 {
   524 {
   519     QGLShaderProgramPrivate(const QGLContext *context)
   527     QGLShaderProgramPrivate(const QGLContext *context)
   520         : programGuard(context)
   528         : programGuard(context)
   521         , linked(false)
   529         , linked(false)
   522         , inited(false)
   530         , inited(false)
   523         , removingShaders(false)
   531         , removingShaders(false)
   524         , vertexShader(0)
   532         , geometryVertexCount(64)
   525         , fragmentShader(0)
   533         , geometryInputType(0)
       
   534         , geometryOutputType(0)
   526     {
   535     {
   527     }
   536     }
   528     ~QGLShaderProgramPrivate();
   537     ~QGLShaderProgramPrivate();
   529 
   538 
   530     QGLSharedResourceGuard programGuard;
   539     QGLSharedResourceGuard programGuard;
   531     bool linked;
   540     bool linked;
   532     bool inited;
   541     bool inited;
   533     bool removingShaders;
   542     bool removingShaders;
       
   543 
       
   544     int geometryVertexCount;
       
   545     GLenum geometryInputType;
       
   546     GLenum geometryOutputType;
       
   547 
   534     QString log;
   548     QString log;
   535     QList<QGLShader *> shaders;
   549     QList<QGLShader *> shaders;
   536     QList<QGLShader *> anonShaders;
   550     QList<QGLShader *> anonShaders;
   537     QGLShader *vertexShader;
       
   538     QGLShader *fragmentShader;
       
   539 
   551 
   540     bool hasShader(QGLShader::ShaderType type) const;
   552     bool hasShader(QGLShader::ShaderType type) const;
   541 };
   553 };
   542 
   554 
   543 QGLShaderProgramPrivate::~QGLShaderProgramPrivate()
   555 QGLShaderProgramPrivate::~QGLShaderProgramPrivate()
   602     const QGLContext *context = d->programGuard.context();
   614     const QGLContext *context = d->programGuard.context();
   603     if (!context) {
   615     if (!context) {
   604         context = QGLContext::currentContext();
   616         context = QGLContext::currentContext();
   605         d->programGuard.setContext(context);
   617         d->programGuard.setContext(context);
   606     }
   618     }
       
   619 
   607     if (!context)
   620     if (!context)
   608         return false;
   621         return false;
   609     if (qt_resolve_glsl_extensions(const_cast<QGLContext *>(context))) {
   622     if (qt_resolve_glsl_extensions(const_cast<QGLContext *>(context))) {
   610         GLuint program = glCreateProgram();
   623         GLuint program = glCreateProgram();
   611         if (!program) {
   624         if (!program) {
   829 {
   842 {
   830     Q_D(QGLShaderProgram);
   843     Q_D(QGLShaderProgram);
   831     GLuint program = d->programGuard.id();
   844     GLuint program = d->programGuard.id();
   832     if (!program)
   845     if (!program)
   833         return false;
   846         return false;
       
   847 
   834     GLint value;
   848     GLint value;
   835     if (d->shaders.isEmpty()) {
   849     if (d->shaders.isEmpty()) {
   836         // If there are no explicit shaders, then it is possible that the
   850         // If there are no explicit shaders, then it is possible that the
   837         // application added a program binary with glProgramBinaryOES(),
   851         // application added a program binary with glProgramBinaryOES(),
   838         // or otherwise populated the shaders itself.  Check to see if the
   852         // or otherwise populated the shaders itself.  Check to see if the
   841         glGetProgramiv(program, GL_LINK_STATUS, &value);
   855         glGetProgramiv(program, GL_LINK_STATUS, &value);
   842         d->linked = (value != 0);
   856         d->linked = (value != 0);
   843         if (d->linked)
   857         if (d->linked)
   844             return true;
   858             return true;
   845     }
   859     }
       
   860 
       
   861     // Set up the geometry shader parameters
       
   862     if (glProgramParameteriEXT) {
       
   863         foreach (QGLShader *shader, d->shaders) {
       
   864             if (shader->shaderType() & QGLShader::Geometry) {
       
   865                 glProgramParameteriEXT(program, GL_GEOMETRY_INPUT_TYPE_EXT,
       
   866                                        d->geometryInputType);
       
   867                 glProgramParameteriEXT(program, GL_GEOMETRY_OUTPUT_TYPE_EXT,
       
   868                                        d->geometryOutputType);
       
   869                 glProgramParameteriEXT(program, GL_GEOMETRY_VERTICES_OUT_EXT,
       
   870                                        d->geometryVertexCount);
       
   871                 break;
       
   872             }
       
   873         }
       
   874     }
       
   875 
   846     glLinkProgram(program);
   876     glLinkProgram(program);
   847     value = 0;
   877     value = 0;
   848     glGetProgramiv(program, GL_LINK_STATUS, &value);
   878     glGetProgramiv(program, GL_LINK_STATUS, &value);
   849     d->linked = (value != 0);
   879     d->linked = (value != 0);
   850     value = 0;
   880     value = 0;
  1265 void QGLShaderProgram::setAttributeValue(int location, const QColor& value)
  1295 void QGLShaderProgram::setAttributeValue(int location, const QColor& value)
  1266 {
  1296 {
  1267     Q_D(QGLShaderProgram);
  1297     Q_D(QGLShaderProgram);
  1268     Q_UNUSED(d);
  1298     Q_UNUSED(d);
  1269     if (location != -1) {
  1299     if (location != -1) {
  1270         GLfloat values[4] = {value.redF(), value.greenF(), value.blueF(), value.alphaF()};
  1300         GLfloat values[4] = {GLfloat(value.redF()), GLfloat(value.greenF()),
       
  1301                              GLfloat(value.blueF()), GLfloat(value.alphaF())};
  1271         glVertexAttrib4fv(location, values);
  1302         glVertexAttrib4fv(location, values);
  1272     }
  1303     }
  1273 }
  1304 }
  1274 
  1305 
  1275 /*!
  1306 /*!
  1431                               stride, values);
  1462                               stride, values);
  1432     }
  1463     }
  1433 }
  1464 }
  1434 
  1465 
  1435 /*!
  1466 /*!
       
  1467     Sets an array of vertex \a values on the attribute at \a location
       
  1468     in this shader program.  The \a stride indicates the number of bytes
       
  1469     between vertices.  A default \a stride value of zero indicates that
       
  1470     the vertices are densely packed in \a values.
       
  1471 
       
  1472     The \a type indicates the type of elements in the \a values array,
       
  1473     usually \c{GL_FLOAT}, \c{GL_UNSIGNED_BYTE}, etc.  The \a tupleSize
       
  1474     indicates the number of components per vertex: 1, 2, 3, or 4.
       
  1475 
       
  1476     The array will become active when enableAttributeArray() is called
       
  1477     on the \a location.  Otherwise the value specified with
       
  1478     setAttributeValue() for \a location will be used.
       
  1479 
       
  1480     The setAttributeBuffer() function can be used to set the attribute
       
  1481     array to an offset within a vertex buffer.
       
  1482 
       
  1483     \sa setAttributeValue(), setUniformValue(), enableAttributeArray()
       
  1484     \sa disableAttributeArray(), setAttributeBuffer()
       
  1485     \since 4.7
       
  1486 */
       
  1487 void QGLShaderProgram::setAttributeArray
       
  1488     (int location, GLenum type, const void *values, int tupleSize, int stride)
       
  1489 {
       
  1490     Q_D(QGLShaderProgram);
       
  1491     Q_UNUSED(d);
       
  1492     if (location != -1) {
       
  1493         glVertexAttribPointer(location, tupleSize, type, GL_FALSE,
       
  1494                               stride, values);
       
  1495     }
       
  1496 }
       
  1497 
       
  1498 /*!
  1436     \overload
  1499     \overload
  1437 
  1500 
  1438     Sets an array of vertex \a values on the attribute called \a name
  1501     Sets an array of vertex \a values on the attribute called \a name
  1439     in this shader program.  The \a tupleSize indicates the number of
  1502     in this shader program.  The \a tupleSize indicates the number of
  1440     components per vertex (1, 2, 3, or 4), and the \a stride indicates
  1503     components per vertex (1, 2, 3, or 4), and the \a stride indicates
  1513 */
  1576 */
  1514 void QGLShaderProgram::setAttributeArray
  1577 void QGLShaderProgram::setAttributeArray
  1515         (const char *name, const QVector4D *values, int stride)
  1578         (const char *name, const QVector4D *values, int stride)
  1516 {
  1579 {
  1517     setAttributeArray(attributeLocation(name), values, stride);
  1580     setAttributeArray(attributeLocation(name), values, stride);
       
  1581 }
       
  1582 
       
  1583 /*!
       
  1584     \overload
       
  1585 
       
  1586     Sets an array of vertex \a values on the attribute called \a name
       
  1587     in this shader program.  The \a stride indicates the number of bytes
       
  1588     between vertices.  A default \a stride value of zero indicates that
       
  1589     the vertices are densely packed in \a values.
       
  1590 
       
  1591     The \a type indicates the type of elements in the \a values array,
       
  1592     usually \c{GL_FLOAT}, \c{GL_UNSIGNED_BYTE}, etc.  The \a tupleSize
       
  1593     indicates the number of components per vertex: 1, 2, 3, or 4.
       
  1594 
       
  1595     The array will become active when enableAttributeArray() is called
       
  1596     on the \a name.  Otherwise the value specified with
       
  1597     setAttributeValue() for \a name will be used.
       
  1598 
       
  1599     The setAttributeBuffer() function can be used to set the attribute
       
  1600     array to an offset within a vertex buffer.
       
  1601 
       
  1602     \sa setAttributeValue(), setUniformValue(), enableAttributeArray()
       
  1603     \sa disableAttributeArray(), setAttributeBuffer()
       
  1604     \since 4.7
       
  1605 */
       
  1606 void QGLShaderProgram::setAttributeArray
       
  1607     (const char *name, GLenum type, const void *values, int tupleSize, int stride)
       
  1608 {
       
  1609     setAttributeArray(attributeLocation(name), type, values, tupleSize, stride);
       
  1610 }
       
  1611 
       
  1612 /*!
       
  1613     Sets an array of vertex values on the attribute at \a location in
       
  1614     this shader program, starting at a specific \a offset in the
       
  1615     currently bound vertex buffer.  The \a stride indicates the number
       
  1616     of bytes between vertices.  A default \a stride value of zero
       
  1617     indicates that the vertices are densely packed in the value array.
       
  1618 
       
  1619     The \a type indicates the type of elements in the vertex value
       
  1620     array, usually \c{GL_FLOAT}, \c{GL_UNSIGNED_BYTE}, etc.  The \a
       
  1621     tupleSize indicates the number of components per vertex: 1, 2, 3,
       
  1622     or 4.
       
  1623 
       
  1624     The array will become active when enableAttributeArray() is called
       
  1625     on the \a location.  Otherwise the value specified with
       
  1626     setAttributeValue() for \a location will be used.
       
  1627 
       
  1628     \sa setAttributeArray()
       
  1629     \since 4.7
       
  1630 */
       
  1631 void QGLShaderProgram::setAttributeBuffer
       
  1632     (int location, GLenum type, int offset, int tupleSize, int stride)
       
  1633 {
       
  1634     Q_D(QGLShaderProgram);
       
  1635     Q_UNUSED(d);
       
  1636     if (location != -1) {
       
  1637         glVertexAttribPointer(location, tupleSize, type, GL_FALSE, stride,
       
  1638                               reinterpret_cast<const void *>(offset));
       
  1639     }
       
  1640 }
       
  1641 
       
  1642 /*!
       
  1643     \overload
       
  1644 
       
  1645     Sets an array of vertex values on the attribute called \a name
       
  1646     in this shader program, starting at a specific \a offset in the
       
  1647     currently bound vertex buffer.  The \a stride indicates the number
       
  1648     of bytes between vertices.  A default \a stride value of zero
       
  1649     indicates that the vertices are densely packed in the value array.
       
  1650 
       
  1651     The \a type indicates the type of elements in the vertex value
       
  1652     array, usually \c{GL_FLOAT}, \c{GL_UNSIGNED_BYTE}, etc.  The \a
       
  1653     tupleSize indicates the number of components per vertex: 1, 2, 3,
       
  1654     or 4.
       
  1655 
       
  1656     The array will become active when enableAttributeArray() is called
       
  1657     on the \a name.  Otherwise the value specified with
       
  1658     setAttributeValue() for \a name will be used.
       
  1659 
       
  1660     \sa setAttributeArray()
       
  1661     \since 4.7
       
  1662 */
       
  1663 void QGLShaderProgram::setAttributeBuffer
       
  1664     (const char *name, GLenum type, int offset, int tupleSize, int stride)
       
  1665 {
       
  1666     setAttributeBuffer(attributeLocation(name), type, offset, tupleSize, stride);
  1518 }
  1667 }
  1519 
  1668 
  1520 /*!
  1669 /*!
  1521     Enables the vertex array at \a location in this shader program
  1670     Enables the vertex array at \a location in this shader program
  1522     so that the value set by setAttributeArray() on \a location
  1671     so that the value set by setAttributeArray() on \a location
  1882 void QGLShaderProgram::setUniformValue(int location, const QColor& color)
  2031 void QGLShaderProgram::setUniformValue(int location, const QColor& color)
  1883 {
  2032 {
  1884     Q_D(QGLShaderProgram);
  2033     Q_D(QGLShaderProgram);
  1885     Q_UNUSED(d);
  2034     Q_UNUSED(d);
  1886     if (location != -1) {
  2035     if (location != -1) {
  1887         GLfloat values[4] = {color.redF(), color.greenF(), color.blueF(), color.alphaF()};
  2036         GLfloat values[4] = {GLfloat(color.redF()), GLfloat(color.greenF()),
       
  2037                              GLfloat(color.blueF()), GLfloat(color.alphaF())};
  1888         glUniform4fv(location, 1, values);
  2038         glUniform4fv(location, 1, values);
  1889     }
  2039     }
  1890 }
  2040 }
  1891 
  2041 
  1892 /*!
  2042 /*!
  1911 void QGLShaderProgram::setUniformValue(int location, const QPoint& point)
  2061 void QGLShaderProgram::setUniformValue(int location, const QPoint& point)
  1912 {
  2062 {
  1913     Q_D(QGLShaderProgram);
  2063     Q_D(QGLShaderProgram);
  1914     Q_UNUSED(d);
  2064     Q_UNUSED(d);
  1915     if (location != -1) {
  2065     if (location != -1) {
  1916         GLfloat values[4] = {point.x(), point.y()};
  2066         GLfloat values[4] = {GLfloat(point.x()), GLfloat(point.y())};
  1917         glUniform2fv(location, 1, values);
  2067         glUniform2fv(location, 1, values);
  1918     }
  2068     }
  1919 }
  2069 }
  1920 
  2070 
  1921 /*!
  2071 /*!
  1940 void QGLShaderProgram::setUniformValue(int location, const QPointF& point)
  2090 void QGLShaderProgram::setUniformValue(int location, const QPointF& point)
  1941 {
  2091 {
  1942     Q_D(QGLShaderProgram);
  2092     Q_D(QGLShaderProgram);
  1943     Q_UNUSED(d);
  2093     Q_UNUSED(d);
  1944     if (location != -1) {
  2094     if (location != -1) {
  1945         GLfloat values[4] = {point.x(), point.y()};
  2095         GLfloat values[4] = {GLfloat(point.x()), GLfloat(point.y())};
  1946         glUniform2fv(location, 1, values);
  2096         glUniform2fv(location, 1, values);
  1947     }
  2097     }
  1948 }
  2098 }
  1949 
  2099 
  1950 /*!
  2100 /*!
  1969 void QGLShaderProgram::setUniformValue(int location, const QSize& size)
  2119 void QGLShaderProgram::setUniformValue(int location, const QSize& size)
  1970 {
  2120 {
  1971     Q_D(QGLShaderProgram);
  2121     Q_D(QGLShaderProgram);
  1972     Q_UNUSED(d);
  2122     Q_UNUSED(d);
  1973     if (location != -1) {
  2123     if (location != -1) {
  1974         GLfloat values[4] = {size.width(), size.width()};
  2124         GLfloat values[4] = {GLfloat(size.width()), GLfloat(size.width())};
  1975         glUniform2fv(location, 1, values);
  2125         glUniform2fv(location, 1, values);
  1976     }
  2126     }
  1977 }
  2127 }
  1978 
  2128 
  1979 /*!
  2129 /*!
  1998 void QGLShaderProgram::setUniformValue(int location, const QSizeF& size)
  2148 void QGLShaderProgram::setUniformValue(int location, const QSizeF& size)
  1999 {
  2149 {
  2000     Q_D(QGLShaderProgram);
  2150     Q_D(QGLShaderProgram);
  2001     Q_UNUSED(d);
  2151     Q_UNUSED(d);
  2002     if (location != -1) {
  2152     if (location != -1) {
  2003         GLfloat values[4] = {size.width(), size.height()};
  2153         GLfloat values[4] = {GLfloat(size.width()), GLfloat(size.height())};
  2004         glUniform2fv(location, 1, values);
  2154         glUniform2fv(location, 1, values);
  2005     }
  2155     }
  2006 }
  2156 }
  2007 
  2157 
  2008 /*!
  2158 /*!
  2312 
  2462 
  2313 /*!
  2463 /*!
  2314     \overload
  2464     \overload
  2315 
  2465 
  2316     Sets the uniform variable at \a location in the current context
  2466     Sets the uniform variable at \a location in the current context
       
  2467     to a 2x2 matrix \a value.  The matrix elements must be specified
       
  2468     in column-major order.
       
  2469 
       
  2470     \sa setAttributeValue()
       
  2471     \since 4.7
       
  2472 */
       
  2473 void QGLShaderProgram::setUniformValue(int location, const GLfloat value[2][2])
       
  2474 {
       
  2475     Q_D(QGLShaderProgram);
       
  2476     Q_UNUSED(d);
       
  2477     if (location != -1)
       
  2478         glUniformMatrix2fv(location, 1, GL_FALSE, value[0]);
       
  2479 }
       
  2480 
       
  2481 /*!
       
  2482     \overload
       
  2483 
       
  2484     Sets the uniform variable at \a location in the current context
       
  2485     to a 3x3 matrix \a value.  The matrix elements must be specified
       
  2486     in column-major order.
       
  2487 
       
  2488     \sa setAttributeValue()
       
  2489     \since 4.7
       
  2490 */
       
  2491 void QGLShaderProgram::setUniformValue(int location, const GLfloat value[3][3])
       
  2492 {
       
  2493     Q_D(QGLShaderProgram);
       
  2494     Q_UNUSED(d);
       
  2495     if (location != -1)
       
  2496         glUniformMatrix3fv(location, 1, GL_FALSE, value[0]);
       
  2497 }
       
  2498 
       
  2499 /*!
       
  2500     \overload
       
  2501 
       
  2502     Sets the uniform variable at \a location in the current context
  2317     to a 4x4 matrix \a value.  The matrix elements must be specified
  2503     to a 4x4 matrix \a value.  The matrix elements must be specified
  2318     in column-major order.
  2504     in column-major order.
  2319 
  2505 
  2320     \sa setAttributeValue()
  2506     \sa setAttributeValue()
  2321 */
  2507 */
  2323 {
  2509 {
  2324     Q_D(QGLShaderProgram);
  2510     Q_D(QGLShaderProgram);
  2325     Q_UNUSED(d);
  2511     Q_UNUSED(d);
  2326     if (location != -1)
  2512     if (location != -1)
  2327         glUniformMatrix4fv(location, 1, GL_FALSE, value[0]);
  2513         glUniformMatrix4fv(location, 1, GL_FALSE, value[0]);
       
  2514 }
       
  2515 
       
  2516 
       
  2517 /*!
       
  2518     \overload
       
  2519 
       
  2520     Sets the uniform variable called \a name in the current context
       
  2521     to a 2x2 matrix \a value.  The matrix elements must be specified
       
  2522     in column-major order.
       
  2523 
       
  2524     \sa setAttributeValue()
       
  2525     \since 4.7
       
  2526 */
       
  2527 void QGLShaderProgram::setUniformValue(const char *name, const GLfloat value[2][2])
       
  2528 {
       
  2529     setUniformValue(uniformLocation(name), value);
       
  2530 }
       
  2531 
       
  2532 /*!
       
  2533     \overload
       
  2534 
       
  2535     Sets the uniform variable called \a name in the current context
       
  2536     to a 3x3 matrix \a value.  The matrix elements must be specified
       
  2537     in column-major order.
       
  2538 
       
  2539     \sa setAttributeValue()
       
  2540     \since 4.7
       
  2541 */
       
  2542 void QGLShaderProgram::setUniformValue(const char *name, const GLfloat value[3][3])
       
  2543 {
       
  2544     setUniformValue(uniformLocation(name), value);
  2328 }
  2545 }
  2329 
  2546 
  2330 /*!
  2547 /*!
  2331     \overload
  2548     \overload
  2332 
  2549 
  2352 {
  2569 {
  2353     Q_D(QGLShaderProgram);
  2570     Q_D(QGLShaderProgram);
  2354     Q_UNUSED(d);
  2571     Q_UNUSED(d);
  2355     if (location != -1) {
  2572     if (location != -1) {
  2356         GLfloat mat[3][3] = {
  2573         GLfloat mat[3][3] = {
  2357             {value.m11(), value.m12(), value.m13()},
  2574             {GLfloat(value.m11()), GLfloat(value.m12()), GLfloat(value.m13())},
  2358             {value.m21(), value.m22(), value.m23()},
  2575             {GLfloat(value.m21()), GLfloat(value.m22()), GLfloat(value.m23())},
  2359             {value.m31(), value.m32(), value.m33()}
  2576             {GLfloat(value.m31()), GLfloat(value.m32()), GLfloat(value.m33())}
  2360         };
  2577         };
  2361         glUniformMatrix3fv(location, 1, GL_FALSE, mat[0]);
  2578         glUniformMatrix3fv(location, 1, GL_FALSE, mat[0]);
  2362     }
  2579     }
  2363 }
  2580 }
  2364 
  2581 
  2867 }
  3084 }
  2868 
  3085 
  2869 #undef ctx
  3086 #undef ctx
  2870 
  3087 
  2871 /*!
  3088 /*!
       
  3089     Returns the hardware limit for how many vertices a geometry shader
       
  3090     can output.
       
  3091 
       
  3092     \since 4.7
       
  3093 
       
  3094     \sa setGeometryOutputVertexCount()
       
  3095 */
       
  3096 int QGLShaderProgram::maxGeometryOutputVertices() const
       
  3097 {
       
  3098     GLint n;
       
  3099     glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT, &n);
       
  3100     return n;
       
  3101 }
       
  3102 
       
  3103 /*!
       
  3104     Sets the maximum number of vertices the current geometry shader
       
  3105     program will produce, if active, to \a count.
       
  3106 
       
  3107     \since 4.7
       
  3108 
       
  3109     This parameter takes effect the next time the program is linked.
       
  3110 */
       
  3111 void QGLShaderProgram::setGeometryOutputVertexCount(int count)
       
  3112 {
       
  3113 #ifndef QT_NO_DEBUG
       
  3114     int max = maxGeometryOutputVertices();
       
  3115     if (count > max) {
       
  3116         qWarning("QGLShaderProgram::setGeometryOutputVertexCount: count: %d higher than maximum: %d",
       
  3117                  count, max);
       
  3118     }
       
  3119 #endif
       
  3120     d_func()->geometryVertexCount = count;
       
  3121 }
       
  3122 
       
  3123 
       
  3124 /*!
       
  3125     Returns the maximum number of vertices the current geometry shader
       
  3126     program will produce, if active.
       
  3127 
       
  3128     \since 4.7
       
  3129 
       
  3130     This parameter takes effect the ntext time the program is linked.
       
  3131 */
       
  3132 int QGLShaderProgram::geometryOutputVertexCount() const
       
  3133 {
       
  3134     return d_func()->geometryVertexCount;
       
  3135 }
       
  3136 
       
  3137 
       
  3138 /*!
       
  3139     Sets the input type from \a inputType.
       
  3140 
       
  3141     This parameter takes effect the next time the program is linked.
       
  3142 */
       
  3143 void QGLShaderProgram::setGeometryInputType(GLenum inputType)
       
  3144 {
       
  3145     d_func()->geometryInputType = inputType;
       
  3146 }
       
  3147 
       
  3148 
       
  3149 /*!
       
  3150     Returns the geometry shader input type, if active.
       
  3151 
       
  3152     This parameter takes effect the next time the program is linked.
       
  3153 
       
  3154     \since 4.7
       
  3155  */
       
  3156 
       
  3157 GLenum QGLShaderProgram::geometryInputType() const
       
  3158 {
       
  3159     return d_func()->geometryInputType;
       
  3160 }
       
  3161 
       
  3162 
       
  3163 /*!
       
  3164     Sets the output type from the geometry shader, if active, to
       
  3165     \a outputType.
       
  3166 
       
  3167     This parameter takes effect the next time the program is linked.
       
  3168 
       
  3169     \since 4.7
       
  3170 */
       
  3171 void QGLShaderProgram::setGeometryOutputType(GLenum outputType)
       
  3172 {
       
  3173     d_func()->geometryOutputType = outputType;
       
  3174 }
       
  3175 
       
  3176 
       
  3177 /*!
       
  3178     Returns the geometry shader output type, if active.
       
  3179 
       
  3180     This parameter takes effect the next time the program is linked.
       
  3181 
       
  3182     \since 4.7
       
  3183  */
       
  3184 GLenum QGLShaderProgram::geometryOutputType() const
       
  3185 {
       
  3186     return d_func()->geometryOutputType;
       
  3187 }
       
  3188 
       
  3189 
       
  3190 /*!
  2872     Returns true if shader programs written in the OpenGL Shading
  3191     Returns true if shader programs written in the OpenGL Shading
  2873     Language (GLSL) are supported on this system; false otherwise.
  3192     Language (GLSL) are supported on this system; false otherwise.
  2874 
  3193 
  2875     The \a context is used to resolve the GLSL extensions.
  3194     The \a context is used to resolve the GLSL extensions.
  2876     If \a context is null, then QGLContext::currentContext() is used.
  3195     If \a context is null, then QGLContext::currentContext() is used.
  2898     QGLShader *shader = qobject_cast<QGLShader *>(sender());
  3217     QGLShader *shader = qobject_cast<QGLShader *>(sender());
  2899     if (shader && !d->removingShaders)
  3218     if (shader && !d->removingShaders)
  2900         removeShader(shader);
  3219         removeShader(shader);
  2901 }
  3220 }
  2902 
  3221 
       
  3222 
       
  3223 #undef ctx
       
  3224 #undef context
       
  3225 
       
  3226 /*!
       
  3227     Returns true if shader programs of type \a type are supported on
       
  3228     this system; false otherwise.
       
  3229 
       
  3230     The \a context is used to resolve the GLSL extensions.
       
  3231     If \a context is null, then QGLContext::currentContext() is used.
       
  3232 
       
  3233     \since 4.7
       
  3234 */
       
  3235 bool QGLShader::hasOpenGLShaders(ShaderType type, const QGLContext *context)
       
  3236 {
       
  3237     if (!context)
       
  3238         context = QGLContext::currentContext();
       
  3239     if (!context)
       
  3240         return false;
       
  3241 
       
  3242     if ((type & ~(Geometry | Vertex | Fragment)) || type == 0)
       
  3243         return false;
       
  3244 
       
  3245     bool resolved = qt_resolve_glsl_extensions(const_cast<QGLContext *>(context));
       
  3246     if (!resolved)
       
  3247         return false;
       
  3248 
       
  3249     if ((type & Geometry) && !QByteArray((const char *) glGetString(GL_EXTENSIONS)).contains("GL_EXT_geometry_shader4"))
       
  3250         return false;
       
  3251 
       
  3252     return true;
       
  3253 }
       
  3254 
       
  3255 
       
  3256 
  2903 #ifdef Q_MAC_COMPAT_GL_FUNCTIONS
  3257 #ifdef Q_MAC_COMPAT_GL_FUNCTIONS
  2904 /*! \internal */
  3258 /*! \internal */
       
  3259 void QGLShaderProgram::setAttributeArray
       
  3260     (int location, QMacCompatGLenum type, const void *values, int tupleSize, int stride)
       
  3261 {
       
  3262     setAttributeArray(location, GLenum(type), values, tupleSize, stride);
       
  3263 }
       
  3264 
       
  3265 /*! \internal */
       
  3266 void QGLShaderProgram::setAttributeArray
       
  3267     (const char *name, QMacCompatGLenum type, const void *values, int tupleSize, int stride)
       
  3268 {
       
  3269     setAttributeArray(name, GLenum(type), values, tupleSize, stride);
       
  3270 }
       
  3271 
       
  3272 /*! \internal */
       
  3273 void QGLShaderProgram::setAttributeBuffer
       
  3274     (int location, QMacCompatGLenum type, int offset, int tupleSize, int stride)
       
  3275 {
       
  3276     setAttributeBuffer(location, GLenum(type), offset, tupleSize, stride);
       
  3277 }
       
  3278 
       
  3279 /*! \internal */
       
  3280 void QGLShaderProgram::setAttributeBuffer
       
  3281     (const char *name, QMacCompatGLenum type, int offset, int tupleSize, int stride)
       
  3282 {
       
  3283     setAttributeBuffer(name, GLenum(type), offset, tupleSize, stride);
       
  3284 }
       
  3285 
       
  3286 /*! \internal */
  2905 void QGLShaderProgram::setUniformValue(int location, QMacCompatGLint value)
  3287 void QGLShaderProgram::setUniformValue(int location, QMacCompatGLint value)
  2906 {
  3288 {
  2907     setUniformValue(location, GLint(value));
  3289     setUniformValue(location, GLint(value));
  2908 }
  3290 }
  2909 
  3291 
  2948 {
  3330 {
  2949     setUniformValueArray(name, (const GLuint *)values, count);
  3331     setUniformValueArray(name, (const GLuint *)values, count);
  2950 }
  3332 }
  2951 #endif
  3333 #endif
  2952 
  3334 
  2953 #endif // !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
  3335 #endif // !defined(QT_OPENGL_ES_1)
  2954 
  3336 
  2955 QT_END_NAMESPACE
  3337 QT_END_NAMESPACE