diff options
author | Jan Holesovsky <kendy@collabora.com> | 2014-11-18 11:45:40 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2014-11-18 15:44:05 +0100 |
commit | 4bf891dbc2ca11c5990a71bcefe771b9ce813074 (patch) | |
tree | 97e4aeced27a46cd6d9d40aed1033eccf2bf1356 /vcl | |
parent | e6592aaa5c9b0f83bf948ce8a2e1ab5029cc3ef5 (diff) |
windows opengl: Share the contexts as we do on Linux.
Change-Id: Ic58cca612cdf8f73170c18573917465bf34a187c
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/opengl/OpenGLContext.cxx | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx index 67e4c5fd0056..d30ac171da83 100644 --- a/vcl/source/opengl/OpenGLContext.cxx +++ b/vcl/source/opengl/OpenGLContext.cxx @@ -29,8 +29,11 @@ using namespace com::sun::star; +// TODO use rtl::Static instead of 'static' #if defined( UNX ) && !defined MACOSX && !defined IOS && !defined ANDROID -static std::vector< GLXContext > vShareList; +static std::vector<GLXContext> vShareList; +#elif defined(WNT) +static std::vector<HGLRC> vShareList; #endif GLWindow::~GLWindow() @@ -58,6 +61,8 @@ OpenGLContext::~OpenGLContext() #if defined( WNT ) if (m_aGLWin.hRC) { + vShareList.erase(std::remove(vShareList.begin(), vShareList.end(), m_aGLWin.hRC)); + wglMakeCurrent( m_aGLWin.hDC, 0 ); wglDeleteContext( m_aGLWin.hRC ); ReleaseDC( m_aGLWin.hWnd, m_aGLWin.hDC ); @@ -655,13 +660,13 @@ bool OpenGLContext::ImplInit() if (best_fbc != -1) { - int nContextAttribs[] = + int pContextAttribs[] = { GLX_CONTEXT_MAJOR_VERSION_ARB, 3, GLX_CONTEXT_MINOR_VERSION_ARB, 2, None }; - m_aGLWin.ctx = glXCreateContextAttribsARB(m_aGLWin.dpy, pFBC[best_fbc], pSharedCtx, GL_TRUE, nContextAttribs); + m_aGLWin.ctx = glXCreateContextAttribsARB(m_aGLWin.dpy, pFBC[best_fbc], pSharedCtx, GL_TRUE, pContextAttribs); SAL_INFO_IF(m_aGLWin.ctx, "vcl.opengl", "created a 3.2 core context"); } else @@ -825,7 +830,7 @@ bool OpenGLContext::ImplInit() return false; } - m_aGLWin.hRC = wglCreateContext(m_aGLWin.hDC); + HGLRC hTempRC = wglCreateContext(m_aGLWin.hDC); if (m_aGLWin.hRC == NULL) { ImplWriteLastError(GetLastError(), "wglCreateContext in OpenGLContext::ImplInit"); @@ -833,19 +838,48 @@ bool OpenGLContext::ImplInit() return false; } - if (!wglMakeCurrent(m_aGLWin.hDC, m_aGLWin.hRC)) + if (!wglMakeCurrent(m_aGLWin.hDC, hTempRC)) { ImplWriteLastError(GetLastError(), "wglMakeCurrent in OpenGLContext::ImplInit"); SAL_WARN("vcl.opengl", "wglMakeCurrent failed"); return false; } + if (!InitGLEW()) + return false; + + HGLRC hSharedCtx = 0; + if (!vShareList.empty()) + hSharedCtx = vShareList.front(); + + // now setup the shared context; this needs a temporary context already + // set up in order to work + m_aGLWin.hRC = wglCreateContextAttribsARB(m_aGLWin.hDC, hSharedCtx, NULL); + if (m_aGLWin.hRC == 0) + { + ImplWriteLastError(GetLastError(), "wglCreateContextAttribsARB in OpenGLContext::ImplInit"); + SAL_WARN("vcl.opengl", "wglCreateContextAttribsARB failed"); + return false; + } + + wglMakeCurrent(NULL, NULL); + wglDeleteContext(hTempRC); + + if (!wglMakeCurrent(m_aGLWin.hDC, m_aGLWin.hRC)) + { + ImplWriteLastError(GetLastError(), "wglMakeCurrent (with shared context) in OpenGLContext::ImplInit"); + SAL_WARN("vcl.opengl", "wglMakeCurrent failed"); + return false; + } + + vShareList.push_back(m_aGLWin.hRC); + RECT clientRect; GetClientRect(WindowFromDC(m_aGLWin.hDC), &clientRect); m_aGLWin.Width = clientRect.right - clientRect.left; m_aGLWin.Height = clientRect.bottom - clientRect.top; - return InitGLEW(); + return true; } #elif defined( MACOSX ) |