diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2010-01-18 19:00:43 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2010-01-18 19:00:43 (GMT) |
commit | f62d047bf20cd45f78db14f1ef4f9ba7f7a7b131 (patch) | |
tree | cf7b8d64fbc94504822096314f56a4a16a66bfa1 /src/opengl/qgl_win.cpp | |
parent | 7dee69caea20b189d5f4f8e27179c5abfd73a815 (diff) | |
parent | a764519a658031ce2fb375b659ff889b5241357f (diff) | |
download | Qt-f62d047bf20cd45f78db14f1ef4f9ba7f7a7b131.zip Qt-f62d047bf20cd45f78db14f1ef4f9ba7f7a7b131.tar.gz Qt-f62d047bf20cd45f78db14f1ef4f9ba7f7a7b131.tar.bz2 |
Merge branch '4.6'
Diffstat (limited to 'src/opengl/qgl_win.cpp')
-rw-r--r-- | src/opengl/qgl_win.cpp | 100 |
1 files changed, 45 insertions, 55 deletions
diff --git a/src/opengl/qgl_win.cpp b/src/opengl/qgl_win.cpp index c1132b5..b5f952e 100644 --- a/src/opengl/qgl_win.cpp +++ b/src/opengl/qgl_win.cpp @@ -575,7 +575,7 @@ QGLFormat pfiToQGLFormat(HDC hdc, int pfi) QVarLengthArray<int> iAttributes(40); QVarLengthArray<int> iValues(40); int i = 0; - bool has_sample_buffers = QGLExtensions::glExtensions & QGLExtensions::SampleBuffers; + bool has_sample_buffers = QGLExtensions::glExtensions() & QGLExtensions::SampleBuffers; iAttributes[i++] = WGL_DOUBLE_BUFFER_ARB; // 0 iAttributes[i++] = WGL_DEPTH_BITS_ARB; // 1 @@ -652,52 +652,14 @@ QGLFormat pfiToQGLFormat(HDC hdc, int pfi) /* - Creates a temporary GL context and makes it current - - cleans up when the object is destructed. + QGLTemporaryContext implementation */ Q_GUI_EXPORT const QString qt_getRegisteredWndClass(); -class QGLTempContext +class QGLTemporaryContextPrivate { public: - QGLTempContext(bool directRendering, QWidget *parent = 0) - { - QString windowClassName = qt_getRegisteredWndClass(); - if (parent && !parent->internalWinId()) - parent = parent->nativeParentWidget(); - - dmy_id = CreateWindow((const wchar_t *)windowClassName.utf16(), - 0, 0, 0, 0, 1, 1, - parent ? parent->winId() : 0, 0, qWinAppInst(), 0); - - dmy_pdc = GetDC(dmy_id); - PIXELFORMATDESCRIPTOR dmy_pfd; - memset(&dmy_pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); - dmy_pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); - dmy_pfd.nVersion = 1; - dmy_pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW; - dmy_pfd.iPixelType = PFD_TYPE_RGBA; - if (!directRendering) - dmy_pfd.dwFlags |= PFD_GENERIC_FORMAT; - - int dmy_pf = ChoosePixelFormat(dmy_pdc, &dmy_pfd); - SetPixelFormat(dmy_pdc, dmy_pf, &dmy_pfd); - dmy_rc = wglCreateContext(dmy_pdc); - old_dc = wglGetCurrentDC(); - old_context = wglGetCurrentContext(); - wglMakeCurrent(dmy_pdc, dmy_rc); - } - - ~QGLTempContext() { - wglMakeCurrent(dmy_pdc, 0); - wglDeleteContext(dmy_rc); - ReleaseDC(dmy_id, dmy_pdc); - DestroyWindow(dmy_id); - if (old_dc && old_context) - wglMakeCurrent(old_dc, old_context); - } - HDC dmy_pdc; HGLRC dmy_rc; HDC old_dc; @@ -705,6 +667,45 @@ public: WId dmy_id; }; +QGLTemporaryContext::QGLTemporaryContext(bool directRendering, QWidget *parent) + : d(new QGLTemporaryContextPrivate) +{ + QString windowClassName = qt_getRegisteredWndClass(); + if (parent && !parent->internalWinId()) + parent = parent->nativeParentWidget(); + + d->dmy_id = CreateWindow((const wchar_t *)windowClassName.utf16(), + 0, 0, 0, 0, 1, 1, + parent ? parent->winId() : 0, 0, qWinAppInst(), 0); + + d->dmy_pdc = GetDC(d->dmy_id); + PIXELFORMATDESCRIPTOR dmy_pfd; + memset(&dmy_pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); + dmy_pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); + dmy_pfd.nVersion = 1; + dmy_pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW; + dmy_pfd.iPixelType = PFD_TYPE_RGBA; + if (!directRendering) + dmy_pfd.dwFlags |= PFD_GENERIC_FORMAT; + + int dmy_pf = ChoosePixelFormat(d->dmy_pdc, &dmy_pfd); + SetPixelFormat(d->dmy_pdc, dmy_pf, &dmy_pfd); + d->dmy_rc = wglCreateContext(d->dmy_pdc); + d->old_dc = wglGetCurrentDC(); + d->old_context = wglGetCurrentContext(); + wglMakeCurrent(d->dmy_pdc, d->dmy_rc); +} + +QGLTemporaryContext::~QGLTemporaryContext() +{ + wglMakeCurrent(d->dmy_pdc, 0); + wglDeleteContext(d->dmy_rc); + ReleaseDC(d->dmy_id, d->dmy_pdc); + DestroyWindow(d->dmy_id); + if (d->old_dc && d->old_context) + wglMakeCurrent(d->old_dc, d->old_context); +} + static bool qgl_create_context(HDC hdc, QGLContextPrivate *d, QGLContextPrivate *shareContext) { d->rc = 0; @@ -855,10 +856,10 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) myDc = GetDC(d->win); } - // NB! the QGLTempContext object is needed for the + // NB! the QGLTemporaryContext object is needed for the // wglGetProcAddress() calls to succeed and are absolutely // necessary - don't remove! - QGLTempContext tmp_ctx(d->glFormat.directRendering(), widget); + QGLTemporaryContext tmp_ctx(d->glFormat.directRendering(), widget); if (!myDc) { qWarning("QGLContext::chooseContext(): Paint device cannot be null"); @@ -1087,7 +1088,7 @@ int QGLContext::choosePixelFormat(void* dummyPfd, HDC pdc) iAttributes[i++] = 1; } int si = 0; - bool trySampleBuffers = QGLExtensions::glExtensions & QGLExtensions::SampleBuffers; + bool trySampleBuffers = QGLExtensions::glExtensions() & QGLExtensions::SampleBuffers; if (trySampleBuffers && d->glFormat.sampleBuffers()) { iAttributes[i++] = WGL_SAMPLE_BUFFERS_ARB; iAttributes[i++] = TRUE; @@ -1593,15 +1594,4 @@ void QGLWidget::setColormap(const QGLColormap & c) } } -void QGLExtensions::init() -{ - static bool init_done = false; - - if (init_done) - return; - init_done = true; - QGLTempContext temp_ctx(QGLFormat::defaultFormat().directRendering()); - init_extensions(); -} - QT_END_NAMESPACE |