summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTrond Kjernåsen <trond@trolltech.com>2010-03-12 11:49:38 (GMT)
committerTrond Kjernåsen <trond@trolltech.com>2010-03-12 11:50:22 (GMT)
commit6e8c0095d0410a30ffa06bb0b0cb71f979becfb0 (patch)
tree8564af166867f31f69e818fba7f71825ad1918c2 /src
parent74914d1c8f62212d71feb4d3961a46da65c5af9e (diff)
downloadQt-6e8c0095d0410a30ffa06bb0b0cb71f979becfb0.zip
Qt-6e8c0095d0410a30ffa06bb0b0cb71f979becfb0.tar.gz
Qt-6e8c0095d0410a30ffa06bb0b0cb71f979becfb0.tar.bz2
Made QGLExtensions::glExtensions() thread-safe.
Reviewed-by: Gunnar
Diffstat (limited to 'src')
-rw-r--r--src/opengl/qgl.cpp37
-rw-r--r--src/opengl/qgl_p.h2
2 files changed, 18 insertions, 21 deletions
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp
index 58ac642..e0030ad 100644
--- a/src/opengl/qgl.cpp
+++ b/src/opengl/qgl.cpp
@@ -5060,6 +5060,20 @@ QGLExtensions::Extensions QGLExtensions::currentContextExtensions()
return glExtensions;
}
+
+class QGLDefaultExtensions
+{
+public:
+ QGLDefaultExtensions() {
+ QGLTemporaryContext tempContext;
+ extensions = QGLExtensions::currentContextExtensions();
+ }
+
+ QGLExtensions::Extensions extensions;
+};
+
+Q_GLOBAL_STATIC(QGLDefaultExtensions, qtDefaultExtensions)
+
/*
Returns the GL extensions for the current QGLContext. If there is no
current QGLContext, a default context will be created and the extensions
@@ -5067,34 +5081,19 @@ QGLExtensions::Extensions QGLExtensions::currentContextExtensions()
*/
QGLExtensions::Extensions QGLExtensions::glExtensions()
{
- QGLTemporaryContext *tmpContext = 0;
- static bool cachedDefault = false;
- static Extensions defaultExtensions = 0;
+ Extensions extensionFlags = 0;
QGLContext *currentCtx = const_cast<QGLContext *>(QGLContext::currentContext());
if (currentCtx && currentCtx->d_func()->extension_flags_cached)
return currentCtx->d_func()->extension_flags;
if (!currentCtx) {
- if (cachedDefault) {
- return defaultExtensions;
- } else {
- tmpContext = new QGLTemporaryContext;
- cachedDefault = true;
- }
- }
-
- Extensions extensionFlags = currentContextExtensions();
- if (currentCtx) {
+ extensionFlags = qtDefaultExtensions()->extensions;
+ } else {
+ extensionFlags = currentContextExtensions();
currentCtx->d_func()->extension_flags_cached = true;
currentCtx->d_func()->extension_flags = extensionFlags;
- } else {
- defaultExtensions = extensionFlags;
}
-
- if (tmpContext)
- delete tmpContext;
-
return extensionFlags;
}
diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h
index f66031a..45f8f30 100644
--- a/src/opengl/qgl_p.h
+++ b/src/opengl/qgl_p.h
@@ -278,8 +278,6 @@ public:
Q_DECLARE_FLAGS(Extensions, Extension)
static Extensions glExtensions();
-
-private:
static Extensions currentContextExtensions();
};