From: Samuel Rødal Date: Wed, 7 Sep 2011 06:40:28 +0000 (+0200) Subject: Fixed crash in tst_QGL::multipleFBOInterleavedRendering(). X-Git-Tag: qt-v5.0.0-alpha1~3626^2~60 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c8fcc2929820b5deafc1e84a3bcb719d87028bd6;p=profile%2Fivi%2Fqtbase.git Fixed crash in tst_QGL::multipleFBOInterleavedRendering(). Properly check for the ElementIndexUint extension. Change-Id: I8117aa052f2dd697a2dadeb7ce84a415b5fd24c8 Reviewed-on: http://codereview.qt.nokia.com/4311 Reviewed-by: Qt Sanity Bot Reviewed-by: Gunnar Sletta --- diff --git a/src/gui/opengl/qopenglpaintengine.cpp b/src/gui/opengl/qopenglpaintengine.cpp index 6b9878e..dfb8549 100644 --- a/src/gui/opengl/qopenglpaintengine.cpp +++ b/src/gui/opengl/qopenglpaintengine.cpp @@ -666,6 +666,7 @@ struct QOpenGL2PEVectorPathCache int indexCount; GLenum primitiveType; qreal iscale; + QVertexIndexVector::Type indexType; }; void QOpenGL2PaintEngineExPrivate::cleanupVectorPath(QPaintEngineEx *engine, void *data) @@ -823,13 +824,14 @@ void QOpenGL2PaintEngineExPrivate::fill(const QVectorPath& path) cache->indexCount = polys.indices.size(); cache->primitiveType = GL_TRIANGLES; cache->iscale = inverseScale; + cache->indexType = polys.indices.type(); #ifdef QT_OPENGL_CACHE_AS_VBOS glGenBuffers(1, &cache->vbo); glGenBuffers(1, &cache->ibo); glBindBuffer(GL_ARRAY_BUFFER, cache->vbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cache->ibo); - if (funcs.hasOpenGLExtension(QOpenGLExtensions::ElementIndexUint)) + if (polys.indices.type() == QVertexIndexVector::UnsignedInt) funcs.glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(quint32) * polys.indices.size(), polys.indices.data(), GL_STATIC_DRAW); else funcs.glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(quint16) * polys.indices.size(), polys.indices.data(), GL_STATIC_DRAW); @@ -840,7 +842,7 @@ void QOpenGL2PaintEngineExPrivate::fill(const QVectorPath& path) funcs.glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vertices.size(), vertices.data(), GL_STATIC_DRAW); #else cache->vertices = (float *) qMalloc(sizeof(float) * polys.vertices.size()); - if (funcs.hasOpenGLExtension(QOpenGLExtensions::ElementIndexUint)) { + if (polys.indices.type() == QVertexIndexVector::UnsignedInt) { cache->indices = (quint32 *) qMalloc(sizeof(quint32) * polys.indices.size()); memcpy(cache->indices, polys.indices.data(), sizeof(quint32) * polys.indices.size()); } else { @@ -857,7 +859,7 @@ void QOpenGL2PaintEngineExPrivate::fill(const QVectorPath& path) glBindBuffer(GL_ARRAY_BUFFER, cache->vbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cache->ibo); setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, 0); - if (funcs.hasOpenGLExtension(QOpenGLExtensions::ElementIndexUint)) + if (cache->indexType == QVertexIndexVector::UnsignedInt) glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_INT, 0); else glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_SHORT, 0); @@ -865,7 +867,7 @@ void QOpenGL2PaintEngineExPrivate::fill(const QVectorPath& path) glBindBuffer(GL_ARRAY_BUFFER, 0); #else setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, cache->vertices); - if (funcs.hasOpenGLExtension(QOpenGLExtensions::ElementIndexUint)) + if (cache->indexType == QVertexIndexVector::UnsignedInt) glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_INT, (qint32 *)cache->indices); else glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_SHORT, (qint16 *)cache->indices); diff --git a/src/gui/opengl/qtriangulator.cpp b/src/gui/opengl/qtriangulator.cpp index d66b2ac..67c2a64 100644 --- a/src/gui/opengl/qtriangulator.cpp +++ b/src/gui/opengl/qtriangulator.cpp @@ -55,6 +55,7 @@ #include #include +#include #include #include @@ -2508,12 +2509,19 @@ void QTriangulator::MonotoneToTriangles::decompose() // qTriangulate // //============================================================================// +static bool hasElementIndexUint() +{ + QOpenGLContext *context = QOpenGLContext::currentContext(); + if (!context) + return false; + return static_cast(context->functions())->hasOpenGLExtension(QOpenGLExtensions::ElementIndexUint); +} + Q_GUI_EXPORT QTriangleSet qTriangulate(const qreal *polygon, int count, uint hint, const QTransform &matrix) { QTriangleSet triangleSet; -#if 0 - if (QOpenGLExtensions::glExtensions() & QOpenGLExtensions::ElementIndexUint) { + if (hasElementIndexUint()) { QTriangulator triangulator; triangulator.initialize(polygon, count, hint, matrix); QVertexSet vertexSet = triangulator.triangulate(); @@ -2521,13 +2529,12 @@ Q_GUI_EXPORT QTriangleSet qTriangulate(const qreal *polygon, triangleSet.indices.setDataUint(vertexSet.indices); } else { -#endif QTriangulator triangulator; triangulator.initialize(polygon, count, hint, matrix); QVertexSet vertexSet = triangulator.triangulate(); triangleSet.vertices = vertexSet.vertices; triangleSet.indices.setDataUshort(vertexSet.indices); -// } + } return triangleSet; } @@ -2535,21 +2542,19 @@ Q_GUI_EXPORT QTriangleSet qTriangulate(const QVectorPath &path, const QTransform &matrix, qreal lod) { QTriangleSet triangleSet; -#if 0 - if (QOpenGLExtensions::glExtensions() & QOpenGLExtensions::ElementIndexUint) { + if (hasElementIndexUint()) { QTriangulator triangulator; triangulator.initialize(path, matrix, lod); QVertexSet vertexSet = triangulator.triangulate(); triangleSet.vertices = vertexSet.vertices; triangleSet.indices.setDataUint(vertexSet.indices); } else { -#endif QTriangulator triangulator; triangulator.initialize(path, matrix, lod); QVertexSet vertexSet = triangulator.triangulate(); triangleSet.vertices = vertexSet.vertices; triangleSet.indices.setDataUshort(vertexSet.indices); -// } + } return triangleSet; } @@ -2557,21 +2562,19 @@ QTriangleSet qTriangulate(const QPainterPath &path, const QTransform &matrix, qreal lod) { QTriangleSet triangleSet; -#if 0 - if (QOpenGLExtensions::glExtensions() & QOpenGLExtensions::ElementIndexUint) { + if (hasElementIndexUint()) { QTriangulator triangulator; triangulator.initialize(path, matrix, lod); QVertexSet vertexSet = triangulator.triangulate(); triangleSet.vertices = vertexSet.vertices; triangleSet.indices.setDataUint(vertexSet.indices); } else { -#endif QTriangulator triangulator; triangulator.initialize(path, matrix, lod); QVertexSet vertexSet = triangulator.triangulate(); triangleSet.vertices = vertexSet.vertices; triangleSet.indices.setDataUshort(vertexSet.indices); -// } + } return triangleSet; } @@ -2579,21 +2582,19 @@ QPolylineSet qPolyline(const QVectorPath &path, const QTransform &matrix, qreal lod) { QPolylineSet polyLineSet; -#if 0 - if (QOpenGLExtensions::glExtensions() & QOpenGLExtensions::ElementIndexUint) { + if (hasElementIndexUint()) { QTriangulator triangulator; triangulator.initialize(path, matrix, lod); QVertexSet vertexSet = triangulator.polyline(); polyLineSet.vertices = vertexSet.vertices; polyLineSet.indices.setDataUint(vertexSet.indices); } else { -#endif QTriangulator triangulator; triangulator.initialize(path, matrix, lod); QVertexSet vertexSet = triangulator.polyline(); polyLineSet.vertices = vertexSet.vertices; polyLineSet.indices.setDataUshort(vertexSet.indices); -// } + } return polyLineSet; } @@ -2601,21 +2602,19 @@ QPolylineSet qPolyline(const QPainterPath &path, const QTransform &matrix, qreal lod) { QPolylineSet polyLineSet; -#if 0 - if (QOpenGLExtensions::glExtensions() & QOpenGLExtensions::ElementIndexUint) { + if (hasElementIndexUint()) { QTriangulator triangulator; triangulator.initialize(path, matrix, lod); QVertexSet vertexSet = triangulator.polyline(); polyLineSet.vertices = vertexSet.vertices; polyLineSet.indices.setDataUint(vertexSet.indices); } else { -#endif QTriangulator triangulator; triangulator.initialize(path, matrix, lod); QVertexSet vertexSet = triangulator.polyline(); polyLineSet.vertices = vertexSet.vertices; polyLineSet.indices.setDataUshort(vertexSet.indices); -// } + } return polyLineSet; } diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 854b71a..e6a12cd 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -667,6 +667,7 @@ struct QGL2PEVectorPathCache int indexCount; GLenum primitiveType; qreal iscale; + QVertexIndexVector::Type indexType; }; void QGL2PaintEngineExPrivate::cleanupVectorPath(QPaintEngineEx *engine, void *data) @@ -824,13 +825,14 @@ void QGL2PaintEngineExPrivate::fill(const QVectorPath& path) cache->indexCount = polys.indices.size(); cache->primitiveType = GL_TRIANGLES; cache->iscale = inverseScale; + cache->indexType = polys.indices.type(); #ifdef QT_OPENGL_CACHE_AS_VBOS glGenBuffers(1, &cache->vbo); glGenBuffers(1, &cache->ibo); glBindBuffer(GL_ARRAY_BUFFER, cache->vbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cache->ibo); - if (QGLExtensions::glExtensions() & QGLExtensions::ElementIndexUint) + if (polys.indices.type() == QVertexIndexVector::UnsignedInt) glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(quint32) * polys.indices.size(), polys.indices.data(), GL_STATIC_DRAW); else glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(quint16) * polys.indices.size(), polys.indices.data(), GL_STATIC_DRAW); @@ -841,7 +843,7 @@ void QGL2PaintEngineExPrivate::fill(const QVectorPath& path) glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vertices.size(), vertices.data(), GL_STATIC_DRAW); #else cache->vertices = (float *) qMalloc(sizeof(float) * polys.vertices.size()); - if (QGLExtensions::glExtensions() & QGLExtensions::ElementIndexUint) { + if (polys.indices.type() == QVertexIndexVector::UnsignedInt) { cache->indices = (quint32 *) qMalloc(sizeof(quint32) * polys.indices.size()); memcpy(cache->indices, polys.indices.data(), sizeof(quint32) * polys.indices.size()); } else { @@ -858,7 +860,7 @@ void QGL2PaintEngineExPrivate::fill(const QVectorPath& path) glBindBuffer(GL_ARRAY_BUFFER, cache->vbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cache->ibo); setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, 0); - if (QGLExtensions::glExtensions() & QGLExtensions::ElementIndexUint) + if (cache->indexType == QVertexIndexVector::UnsignedInt) glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_INT, 0); else glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_SHORT, 0); @@ -866,7 +868,7 @@ void QGL2PaintEngineExPrivate::fill(const QVectorPath& path) glBindBuffer(GL_ARRAY_BUFFER, 0); #else setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, cache->vertices); - if (QGLExtensions::glExtensions() & QGLExtensions::ElementIndexUint) + if (cache->indexType == QVertexIndexVector::UnsignedInt) glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_INT, (qint32 *)cache->indices); else glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_SHORT, (qint16 *)cache->indices); @@ -895,7 +897,7 @@ void QGL2PaintEngineExPrivate::fill(const QVectorPath& path) prepareForDraw(currentBrush.isOpaque()); setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, vertices.constData()); - if (QGLExtensions::glExtensions() & QGLExtensions::ElementIndexUint) + if (polys.indices.type() == QVertexIndexVector::UnsignedInt) glDrawElements(GL_TRIANGLES, polys.indices.size(), GL_UNSIGNED_INT, polys.indices.data()); else glDrawElements(GL_TRIANGLES, polys.indices.size(), GL_UNSIGNED_SHORT, polys.indices.data());