Changeset 846 for trunk/src/opengl/qglshaderprogram.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/opengl/qglshaderprogram.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 51 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 /*! … … 144 144 \value Vertex Vertex shader written in the OpenGL Shading Language (GLSL). 145 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 … … 227 229 if (shaderType == QGLShader::Vertex) 228 230 shader = glCreateShader(GL_VERTEX_SHADER); 231 else if (shaderType == QGLShader::Geometry) 232 shader = glCreateShader(GL_GEOMETRY_SHADER_EXT); 229 233 else 230 234 shader = glCreateShader(GL_FRAGMENT_SHADER); … … 510 514 } 511 515 516 517 518 519 512 520 #undef ctx 513 521 #define ctx programGuard.context() … … 522 530 , inited(false) 523 531 , removingShaders(false) 524 , vertexShader(0) 525 , fragmentShader(0) 532 , geometryVertexCount(64) 533 , geometryInputType(0) 534 , geometryOutputType(0) 526 535 { 527 536 } … … 532 541 bool inited; 533 542 bool removingShaders; 543 544 int geometryVertexCount; 545 GLenum geometryInputType; 546 GLenum geometryOutputType; 547 534 548 QString log; 535 549 QList<QGLShader *> shaders; 536 550 QList<QGLShader *> anonShaders; 537 QGLShader *vertexShader;538 QGLShader *fragmentShader;539 551 540 552 bool hasShader(QGLShader::ShaderType type) const; … … 605 617 d->programGuard.setContext(context); 606 618 } 619 607 620 if (!context) 608 621 return false; … … 832 845 if (!program) 833 846 return false; 847 834 848 GLint value; 835 849 if (d->shaders.isEmpty()) { … … 844 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 876 glLinkProgram(program); 847 877 value = 0; … … 1268 1298 Q_UNUSED(d); 1269 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 1302 glVertexAttrib4fv(location, values); 1272 1303 } … … 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_TRUE, 1494 stride, values); 1495 } 1496 } 1497 1498 /*! 1436 1499 \overload 1437 1500 … … 1516 1579 { 1517 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_TRUE, 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 … … 1885 2034 Q_UNUSED(d); 1886 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 2038 glUniform4fv(location, 1, values); 1889 2039 } … … 1914 2064 Q_UNUSED(d); 1915 2065 if (location != -1) { 1916 GLfloat values[4] = { point.x(), point.y()};2066 GLfloat values[4] = {GLfloat(point.x()), GLfloat(point.y())}; 1917 2067 glUniform2fv(location, 1, values); 1918 2068 } … … 1943 2093 Q_UNUSED(d); 1944 2094 if (location != -1) { 1945 GLfloat values[4] = { point.x(), point.y()};2095 GLfloat values[4] = {GLfloat(point.x()), GLfloat(point.y())}; 1946 2096 glUniform2fv(location, 1, values); 1947 2097 } … … 1972 2122 Q_UNUSED(d); 1973 2123 if (location != -1) { 1974 GLfloat values[4] = { size.width(), size.width()};2124 GLfloat values[4] = {GLfloat(size.width()), GLfloat(size.height())}; 1975 2125 glUniform2fv(location, 1, values); 1976 2126 } … … 2001 2151 Q_UNUSED(d); 2002 2152 if (location != -1) { 2003 GLfloat values[4] = { size.width(), size.height()};2153 GLfloat values[4] = {GLfloat(size.width()), GLfloat(size.height())}; 2004 2154 glUniform2fv(location, 1, values); 2005 2155 } … … 2315 2465 2316 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 2503 to a 4x4 matrix \a value. The matrix elements must be specified 2318 2504 in column-major order. … … 2326 2512 if (location != -1) 2327 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 … … 2355 2572 if (location != -1) { 2356 2573 GLfloat mat[3][3] = { 2357 { value.m11(), value.m12(), value.m13()},2358 { value.m21(), value.m22(), value.m23()},2359 { value.m31(), value.m32(), value.m33()}2574 {GLfloat(value.m11()), GLfloat(value.m12()), GLfloat(value.m13())}, 2575 {GLfloat(value.m21()), GLfloat(value.m22()), GLfloat(value.m23())}, 2576 {GLfloat(value.m31()), GLfloat(value.m32()), GLfloat(value.m33())} 2360 2577 }; 2361 2578 glUniformMatrix3fv(location, 1, GL_FALSE, mat[0]); … … 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 3191 Returns true if shader programs written in the OpenGL Shading 2873 3192 Language (GLSL) are supported on this system; false otherwise. … … 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 3257 #ifdef Q_MAC_COMPAT_GL_FUNCTIONS 2904 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 3287 void QGLShaderProgram::setUniformValue(int location, QMacCompatGLint value) 2906 3288 { … … 2951 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 3337 QT_END_NAMESPACE
Note:
See TracChangeset
for help on using the changeset viewer.