[Libreoffice-commits] core.git: Branch 'feature/opengl-vcl2' - include/vcl vcl/source

Jan Holesovsky kendy at collabora.com
Tue Nov 18 05:58:31 PST 2014


 include/vcl/opengl/OpenGLContext.hxx |    1 
 vcl/source/opengl/OpenGLContext.cxx  |   48 +++++++++++++++++++++++++++++------
 2 files changed, 42 insertions(+), 7 deletions(-)

New commits:
commit ba6af6f9d3048673f69fac41a0b61db316d16d03
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Tue Nov 18 11:45:40 2014 +0100

    windows opengl: Share the contexts as we do on Linux.
    
    Change-Id: Ic58cca612cdf8f73170c18573917465bf34a187c

diff --git a/include/vcl/opengl/OpenGLContext.hxx b/include/vcl/opengl/OpenGLContext.hxx
index 5ca9602..058e174 100644
--- a/include/vcl/opengl/OpenGLContext.hxx
+++ b/include/vcl/opengl/OpenGLContext.hxx
@@ -31,6 +31,7 @@
 
 #if defined( _WIN32 )
 #include <GL/glext.h>
+#include <GL/wglew.h>
 #include <GL/wglext.h>
 #elif defined( MACOSX )
 #include <OpenGL/OpenGL.h>
diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx
index cc1264b..d30ac17 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 );
@@ -69,7 +74,7 @@ OpenGLContext::~OpenGLContext()
 #elif defined( UNX )
     if(m_aGLWin.ctx)
     {
-        std::remove( vShareList.begin(), vShareList.end(), m_aGLWin.ctx );
+        vShareList.erase(std::remove( vShareList.begin(), vShareList.end(), m_aGLWin.ctx ));
 
         glXMakeCurrent(m_aGLWin.dpy, None, NULL);
         if( glGetError() != GL_NO_ERROR )
@@ -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 )


More information about the Libreoffice-commits mailing list