Changeset 651 for trunk/src/opengl/qgl.cpp
- Timestamp:
- Mar 8, 2010, 12:52:58 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.6.2 (added) merged: 650 /branches/vendor/nokia/qt/current merged: 649 /branches/vendor/nokia/qt/4.6.1 removed
- Property svn:mergeinfo changed
-
trunk/src/opengl/qgl.cpp
r561 r651 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 20 09Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 125 125 Q_GLOBAL_STATIC(QGLDefaultOverlayFormat, defaultOverlayFormatInstance) 126 126 127 QGLExtensions::Extensions QGLExtensions::glExtensions = 0;128 bool QGLExtensions::nvidiaFboNeedsFinish = false;129 130 127 Q_GLOBAL_STATIC(QGLSignalProxy, theSignalProxy) 131 128 QGLSignalProxy *QGLSignalProxy::instance() … … 155 152 static bool mac_x1600_check_done = false; 156 153 if (!mac_x1600_check_done) { 157 QGLWidget *tmp = 0; 158 if (!QGLContext::currentContext()) { 159 tmp = new QGLWidget(); 160 tmp->makeCurrent(); 161 } 154 QGLTemporaryContext *tmp = 0; 155 if (!QGLContext::currentContext()) 156 tmp = new QGLTemporaryContext(); 162 157 if (strstr((char *) glGetString(GL_RENDERER), "X1600")) 163 158 engineType = QPaintEngine::OpenGL; … … 179 174 // use GL 2.0. 180 175 if ((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_0) 181 && (QGLExtensions::glExtensions & QGLExtensions::FragmentShader)176 && (QGLExtensions::glExtensions() & QGLExtensions::FragmentShader) 182 177 && qgetenv("QT_GL_USE_OPENGL1ENGINE").isEmpty()) 183 178 engineType = QPaintEngine::OpenGL2; … … 1251 1246 static OpenGLVersionFlags defaultVersionFlags = OpenGL_Version_None; 1252 1247 QGLContext *currentCtx = const_cast<QGLContext *>(QGLContext::currentContext()); 1253 QGL Widget *dummy= 0;1248 QGLTemporaryContext *tmpContext = 0; 1254 1249 1255 1250 if (currentCtx && currentCtx->d_func()->version_flags_cached) … … 1262 1257 if (!hasOpenGL()) 1263 1258 return defaultVersionFlags; 1264 dummy = new QGLWidget; 1265 dummy->makeCurrent(); // glGetString() needs a current context 1259 tmpContext = new QGLTemporaryContext; 1266 1260 cachedDefault = true; 1267 1261 } … … 1274 1268 currentCtx->d_func()->version_flags = versionFlags; 1275 1269 } 1276 if ( dummy) {1270 if (tmpContext) { 1277 1271 defaultVersionFlags = versionFlags; 1278 delete dummy;1272 delete tmpContext; 1279 1273 } 1280 1274 … … 1437 1431 } 1438 1432 1433 const QGLContext *qt_gl_transfer_context(const QGLContext *ctx) 1434 { 1435 if (!ctx) 1436 return 0; 1437 QList<const QGLContext *> shares 1438 (QGLContextPrivate::contextGroup(ctx)->shares()); 1439 if (shares.size() >= 2) 1440 return (ctx == shares.at(0)) ? shares.at(1) : shares.at(0); 1441 else 1442 return 0; 1443 } 1444 1439 1445 QGLContextPrivate::~QGLContextPrivate() 1440 1446 { … … 1482 1488 version_flags_cached = false; 1483 1489 version_flags = QGLFormat::OpenGL_Version_None; 1490 extension_flags_cached = false; 1491 extension_flags = 0; 1484 1492 current_fbo = 0; 1485 1493 default_fbo = 0; 1486 1494 active_engine = 0; 1495 for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i) 1496 vertexAttributeArraysEnabledState[i] = false; 1487 1497 } 1488 1498 … … 1542 1552 QImage qt_gl_read_texture(const QSize &size, bool alpha_format, bool include_alpha) 1543 1553 { 1544 QImage img(size, alpha_format ? QImage::Format_ARGB32 : QImage::Format_RGB32);1554 QImage img(size, alpha_format ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32); 1545 1555 int w = size.width(); 1546 1556 int h = size.height(); … … 1581 1591 qt_gl_texture_cache = this; 1582 1592 1583 QImagePixmapCleanupHooks::instance()->addPixmapModificationHook(cleanupTextures); 1584 #ifdef Q_WS_X11 1585 QImagePixmapCleanupHooks::instance()->addPixmapDestructionHook(cleanupPixmapSurfaces); 1586 #endif 1593 QImagePixmapCleanupHooks::instance()->addPixmapDataModificationHook(cleanupTextures); 1594 QImagePixmapCleanupHooks::instance()->addPixmapDataDestructionHook(cleanupBeforePixmapDestruction); 1587 1595 QImagePixmapCleanupHooks::instance()->addImageHook(imageCleanupHook); 1588 1596 } … … 1592 1600 qt_gl_texture_cache = 0; 1593 1601 1594 QImagePixmapCleanupHooks::instance()->removePixmapModificationHook(cleanupTextures); 1595 #ifdef Q_WS_X11 1596 QImagePixmapCleanupHooks::instance()->removePixmapDestructionHook(cleanupPixmapSurfaces); 1597 #endif 1602 QImagePixmapCleanupHooks::instance()->removePixmapDataModificationHook(cleanupTextures); 1603 QImagePixmapCleanupHooks::instance()->removePixmapDataDestructionHook(cleanupBeforePixmapDestruction); 1598 1604 QImagePixmapCleanupHooks::instance()->removeImageHook(imageCleanupHook); 1599 1605 } … … 1663 1669 1664 1670 1665 void QGLTextureCache::cleanupTextures(QPixmap * pixmap)1671 void QGLTextureCache::cleanupTextures(QPixmapData* pmd) 1666 1672 { 1667 1673 // ### remove when the GL texture cache becomes thread-safe 1668 1674 if (qApp->thread() == QThread::currentThread()) { 1669 const qint64 cacheKey = p ixmap->cacheKey();1675 const qint64 cacheKey = pmd->cacheKey(); 1670 1676 QGLTexture *texture = instance()->getTexture(cacheKey); 1671 1677 if (texture && texture->options & QGLContext::MemoryManagedBindOption) … … 1674 1680 } 1675 1681 1682 void QGLTextureCache::cleanupBeforePixmapDestruction(QPixmapData* pmd) 1683 { 1684 // Remove any bound textures first: 1685 cleanupTextures(pmd); 1686 Q_ASSERT(instance()->getTexture(pmd->cacheKey()) == 0); 1687 1676 1688 #if defined(Q_WS_X11) 1677 void QGLTextureCache::cleanupPixmapSurfaces(QPixmap* pixmap) 1678 { 1679 // Remove any bound textures first: 1680 cleanupTextures(pixmap); 1681 1682 QPixmapData *pd = pixmap->data_ptr().data(); 1683 if (pd->classId() == QPixmapData::X11Class) { 1684 Q_ASSERT(pd->ref == 1); // Make sure reference counting isn't broken 1685 QGLContextPrivate::destroyGlSurfaceForPixmap(pd); 1686 } 1687 } 1688 #endif 1689 if (pmd->classId() == QPixmapData::X11Class) { 1690 Q_ASSERT(pmd->ref == 0); // Make sure reference counting isn't broken 1691 QGLContextPrivate::destroyGlSurfaceForPixmap(pmd); 1692 } 1693 #endif 1694 } 1689 1695 1690 1696 void QGLTextureCache::deleteIfEmpty() … … 1730 1736 #endif 1731 1737 1732 Q_GLOBAL_STATIC(QGLShareRegister, _qgl_share_reg)1733 Q_OPENGL_EXPORT QGLShareRegister* qgl_share_reg()1734 {1735 return _qgl_share_reg();1736 }1737 1738 1738 /*! 1739 1739 \class QGLContext … … 1874 1874 { 1875 1875 } 1876 1877 #define ctx q_ptr 1878 void QGLContextPrivate::setVertexAttribArrayEnabled(int arrayIndex, bool enabled) 1879 { 1880 Q_ASSERT(arrayIndex < QT_GL_VERTEX_ARRAY_TRACKED_COUNT); 1881 Q_ASSERT(glEnableVertexAttribArray); 1882 1883 if (vertexAttributeArraysEnabledState[arrayIndex] && !enabled) 1884 glDisableVertexAttribArray(arrayIndex); 1885 1886 if (!vertexAttributeArraysEnabledState[arrayIndex] && enabled) 1887 glEnableVertexAttribArray(arrayIndex); 1888 1889 vertexAttributeArraysEnabledState[arrayIndex] = enabled; 1890 } 1891 1892 void QGLContextPrivate::syncGlState() 1893 { 1894 Q_ASSERT(glEnableVertexAttribArray); 1895 for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i) { 1896 if (vertexAttributeArraysEnabledState[i]) 1897 glEnableVertexAttribArray(i); 1898 else 1899 glDisableVertexAttribArray(i); 1900 } 1901 1902 } 1903 #undef ctx 1904 1876 1905 1877 1906 /*! … … 2111 2140 2112 2141 QImage img = image; 2113 if (!(QGLExtensions::glExtensions & QGLExtensions::NPOTTextures)2142 if (!(QGLExtensions::glExtensions() & QGLExtensions::NPOTTextures) 2114 2143 && !(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_ES_Version_2_0) 2115 2144 && (target == GL_TEXTURE_2D && (tx_w != image.width() || tx_h != image.height()))) … … 2133 2162 #endif 2134 2163 if (glFormat.directRendering() 2135 && (QGLExtensions::glExtensions & QGLExtensions::GenerateMipmap)2164 && (QGLExtensions::glExtensions() & QGLExtensions::GenerateMipmap) 2136 2165 && target == GL_TEXTURE_2D 2137 2166 && (options & QGLContext::MipmapBindOption)) … … 2161 2190 GLenum externalFormat; 2162 2191 GLuint pixel_type; 2163 if (QGLExtensions::glExtensions & QGLExtensions::BGRATextureFormat) {2192 if (QGLExtensions::glExtensions() & QGLExtensions::BGRATextureFormat) { 2164 2193 externalFormat = GL_BGRA; 2165 pixel_type = GL_UNSIGNED_INT_8_8_8_8_REV; 2194 if (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_2) 2195 pixel_type = GL_UNSIGNED_INT_8_8_8_8_REV; 2196 else 2197 pixel_type = GL_UNSIGNED_BYTE; 2166 2198 } else { 2167 2199 externalFormat = GL_RGBA; … … 2242 2274 } 2243 2275 #ifdef QT_OPENGL_ES 2244 // OpenGL/ES requires that the internal and external formats be identical. 2245 // This is typically used to convert GL_RGBA into GL_BGRA. 2246 // Also, we need to use GL_UNSIGNED_BYTE when the format is GL_BGRA. 2276 // OpenGL/ES requires that the internal and external formats be 2277 // identical. 2247 2278 internalFormat = externalFormat; 2248 if (pixel_type == GL_UNSIGNED_INT_8_8_8_8_REV)2249 pixel_type = GL_UNSIGNED_BYTE;2250 2279 #endif 2251 2280 #ifdef QGL_BIND_TEXTURE_DEBUG … … 2955 2984 } 2956 2985 if (d->sharing) // ok, we managed to share 2957 qgl_share_reg()->addShare(this, shareContext);2986 QGLContextGroup::addShare(this, shareContext); 2958 2987 return d->valid; 2959 2988 } … … 4361 4390 text is drawn. 4362 4391 4392 \note This function can only be used inside a 4393 QPainter::beginNativePainting()/QPainter::endNativePainting() block 4394 if the default OpenGL paint engine is QPaintEngine::OpenGL. To make 4395 QPaintEngine::OpenGL the default GL engine, call 4396 QGL::setPreferredPaintEngine(QPaintEngine::OpenGL) before the 4397 QApplication constructor. 4398 4363 4399 \l{Overpainting Example}{Overpaint} with QPainter::drawText() instead. 4364 4400 */ … … 4832 4868 #endif // QT3_SUPPORT 4833 4869 4834 void QGLExtensions::init_extensions() 4870 /* 4871 Returns the GL extensions for the current context. 4872 */ 4873 QGLExtensions::Extensions QGLExtensions::currentContextExtensions() 4835 4874 { 4836 4875 QGLExtensionMatcher extensions(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS))); 4876 Extensions glExtensions; 4837 4877 4838 4878 if (extensions.match("GL_ARB_texture_rectangle")) … … 4895 4935 if (extensions.match("GL_EXT_bgra")) 4896 4936 glExtensions |= BGRATextureFormat; 4937 4938 return glExtensions; 4939 } 4940 4941 /* 4942 Returns the GL extensions for the current QGLContext. If there is no 4943 current QGLContext, a default context will be created and the extensions 4944 for that context will be returned instead. 4945 */ 4946 QGLExtensions::Extensions QGLExtensions::glExtensions() 4947 { 4948 QGLTemporaryContext *tmpContext = 0; 4949 static bool cachedDefault = false; 4950 static Extensions defaultExtensions = 0; 4951 QGLContext *currentCtx = const_cast<QGLContext *>(QGLContext::currentContext()); 4952 4953 if (currentCtx && currentCtx->d_func()->extension_flags_cached) 4954 return currentCtx->d_func()->extension_flags; 4955 4956 if (!currentCtx) { 4957 if (cachedDefault) { 4958 return defaultExtensions; 4959 } else { 4960 tmpContext = new QGLTemporaryContext; 4961 cachedDefault = true; 4962 } 4963 } 4964 4965 Extensions extensionFlags = currentContextExtensions(); 4966 if (currentCtx) { 4967 currentCtx->d_func()->extension_flags_cached = true; 4968 currentCtx->d_func()->extension_flags = extensionFlags; 4969 } else { 4970 defaultExtensions = extensionFlags; 4971 } 4972 4973 if (tmpContext) 4974 delete tmpContext; 4975 4976 return extensionFlags; 4897 4977 } 4898 4978 … … 4906 4986 glDevice.setWidget(q); 4907 4987 4908 QGLExtensions::init();4909 4988 glcx = 0; 4910 4989 autoSwap = true; … … 4916 4995 if (!glcx) 4917 4996 glcx = new QGLContext(QGLFormat::defaultFormat(), q); 4918 4919 q->setAttribute(Qt::WA_NoSystemBackground);4920 4997 } 4921 4998 … … 4941 5018 #endif 4942 5019 4943 void QGL ShareRegister::addShare(const QGLContext *context, const QGLContext *share) {5020 void QGLContextGroup::addShare(const QGLContext *context, const QGLContext *share) { 4944 5021 Q_ASSERT(context && share); 4945 5022 if (context->d_ptr->group == share->d_ptr->group) … … 4962 5039 } 4963 5040 4964 QList<const QGLContext *> QGLShareRegister::shares(const QGLContext *context) { 4965 return context->d_ptr->group->m_shares; 4966 } 4967 4968 void QGLShareRegister::removeShare(const QGLContext *context) { 5041 void QGLContextGroup::removeShare(const QGLContext *context) { 4969 5042 // Remove the context from the group. 4970 5043 QGLContextGroup *group = context->d_ptr->group; … … 5161 5234 #if !defined(QT_OPENGL_ES) 5162 5235 if (!glCompressedTexImage2D) { 5163 if (!(QGLExtensions::glExtensions & QGLExtensions::TextureCompression)) {5236 if (!(QGLExtensions::glExtensions() & QGLExtensions::TextureCompression)) { 5164 5237 qWarning("QGLContext::bindTexture(): The GL implementation does " 5165 5238 "not support texture compression extensions."); … … 5200 5273 5201 5274 // Bail out if the necessary extension is not present. 5202 if (!(QGLExtensions::glExtensions & QGLExtensions::DDSTextureCompression)) {5275 if (!(QGLExtensions::glExtensions() & QGLExtensions::DDSTextureCompression)) { 5203 5276 qWarning("QGLContext::bindTexture(): DDS texture compression is not supported."); 5204 5277 return QSize(); … … 5310 5383 // Bail out if the necessary extension is not present. 5311 5384 if (textureFormat == GL_ETC1_RGB8_OES) { 5312 if (!(QGLExtensions::glExtensions &5385 if (!(QGLExtensions::glExtensions() & 5313 5386 QGLExtensions::ETC1TextureCompression)) { 5314 5387 qWarning("QGLContext::bindTexture(): ETC1 texture compression is not supported."); … … 5316 5389 } 5317 5390 } else { 5318 if (!(QGLExtensions::glExtensions &5391 if (!(QGLExtensions::glExtensions() & 5319 5392 QGLExtensions::PVRTCTextureCompression)) { 5320 5393 qWarning("QGLContext::bindTexture(): PVRTC texture compression is not supported.");
Note:
See TracChangeset
for help on using the changeset viewer.