summaryrefslogtreecommitdiffstats
path: root/src/opengl/qgl_mac.mm
diff options
context:
space:
mode:
authorTrond Kjernåsen <trond@trolltech.com>2010-01-13 14:53:04 (GMT)
committerTrond Kjernåsen <trond@trolltech.com>2010-01-13 14:53:04 (GMT)
commit7bfc32ca6a462b498b9f349454113cd37f64e89f (patch)
treea224c41e1228f1aa7decda1ed8370e2df66814dc /src/opengl/qgl_mac.mm
parent59ee1b9d387468a5a80b5c450aa202d1b33e6bd1 (diff)
downloadQt-7bfc32ca6a462b498b9f349454113cd37f64e89f.zip
Qt-7bfc32ca6a462b498b9f349454113cd37f64e89f.tar.gz
Qt-7bfc32ca6a462b498b9f349454113cd37f64e89f.tar.bz2
Rework how Qt handles GL extensions.
Qt used to store the GL extensions a particular implementation supported in a global cache, which was initialized once and never updated. This could cause problems because different types of context might support different kinds of extensions (e.g. the difference between sw and hw contexts). With this patch, the GL extensions are cached and updated within each QGLContext. It also makes the extension initialization lazy, which saves application initialization costs for embedded platforms. The patch introduces a internal cross platform QGLTemporaryContext class that is used to create a light-weight GL context without going via QGLWidget and friends (QWS and WinCE still have QGLWidget fallbacks for now). Reviewed-by: Kim Reviewed-by: Samuel
Diffstat (limited to 'src/opengl/qgl_mac.mm')
-rw-r--r--src/opengl/qgl_mac.mm110
1 files changed, 62 insertions, 48 deletions
diff --git a/src/opengl/qgl_mac.mm b/src/opengl/qgl_mac.mm
index 6ed07e5..c01575b 100644
--- a/src/opengl/qgl_mac.mm
+++ b/src/opengl/qgl_mac.mm
@@ -116,6 +116,68 @@ extern void qt_mac_dispose_rgn(RgnHandle); //qregion_mac.cpp
extern QRegion qt_mac_convert_mac_region(RgnHandle); //qregion_mac.cpp
extern void qt_mac_to_pascal_string(QString s, Str255 str, TextEncoding encoding=0, int len=-1); //qglobal.cpp
+/*
+ QGLTemporaryContext implementation
+*/
+
+class QGLTemporaryContextPrivate
+{
+public:
+#ifndef QT_MAC_USE_COCOA
+ AGLContext ctx;
+#else
+ NSOpenGLContext *ctx;
+#endif
+};
+
+QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *)
+ : d(new QGLTemporaryContextPrivate)
+{
+ d->ctx = 0;
+#ifndef QT_MAC_USE_COCOA
+ GLint attribs[] = {AGL_RGBA, AGL_NONE};
+ AGLPixelFormat fmt = aglChoosePixelFormat(0, 0, attribs);
+ if (!fmt) {
+ qDebug("QGLTemporaryContext: Couldn't find any RGB visuals");
+ return;
+ }
+ d->ctx = aglCreateContext(fmt, 0);
+ if (!d->ctx)
+ qDebug("QGLTemporaryContext: Unable to create context");
+ else
+ aglSetCurrentContext(d->ctx);
+ aglDestroyPixelFormat(fmt);
+#else
+ QMacCocoaAutoReleasePool pool;
+ NSOpenGLPixelFormatAttribute attribs[] = { 0 };
+ NSOpenGLPixelFormat *fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
+ if (!fmt) {
+ qWarning("QGLTemporaryContext: Cannot find any visuals");
+ return;
+ }
+
+ d->ctx = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:0];
+ if (!d->ctx)
+ qWarning("QGLTemporaryContext: Cannot create context");
+ else
+ [d->ctx makeCurrentContext];
+ [fmt release];
+#endif
+}
+
+QGLTemporaryContext::~QGLTemporaryContext()
+{
+ if (d->ctx) {
+#ifndef QT_MAC_USE_COCOA
+ aglSetCurrentContext(0);
+ aglDestroyContext(d->ctx);
+#else
+ [NSOpenGLContext clearCurrentContext];
+ [d->ctx release];
+#endif
+ }
+}
+
bool QGLFormat::hasOpenGL()
{
return true;
@@ -918,54 +980,6 @@ void QGLWidgetPrivate::updatePaintDevice()
q->update();
}
-
-void QGLExtensions::init()
-{
- static bool init_done = false;
-
- if (init_done)
- return;
- init_done = true;
-
-#ifndef QT_MAC_USE_COCOA
- GLint attribs[] = { AGL_RGBA, AGL_NONE };
- AGLPixelFormat fmt = aglChoosePixelFormat(0, 0, attribs);
- if (!fmt) {
- qDebug("QGLExtensions: Couldn't find any RGB visuals");
- return;
- }
- AGLContext ctx = aglCreateContext(fmt, 0);
- if (!ctx) {
- qDebug("QGLExtensions: Unable to create context");
- } else {
- aglSetCurrentContext(ctx);
- init_extensions();
- aglSetCurrentContext(0);
- aglDestroyContext(ctx);
- }
- aglDestroyPixelFormat(fmt);
-#else
- QMacCocoaAutoReleasePool pool;
- NSOpenGLPixelFormatAttribute attribs[] = { 0 };
- NSOpenGLPixelFormat *fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
- if (!fmt) {
- qWarning("QGLExtensions: Cannot find any visuals");
- return;
- }
-
- NSOpenGLContext *ctx = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:0];
- if (!ctx) {
- qWarning("QGLExtensions: Cannot create context");
- } else {
- [ctx makeCurrentContext];
- init_extensions();
- [NSOpenGLContext clearCurrentContext];
- [ctx release];
- }
- [fmt release];
-#endif
-}
-
#endif
QT_END_NAMESPACE