Commit: 800c3c5ca581d5427c4270c60f022c3ccdd8b312
Author: fclem
Date:   Mon Jun 11 13:06:54 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB800c3c5ca581d5427c4270c60f022c3ccdd8b312

GHOST: WGL: Delay context initialization for offscreen contexts.

Same as 128926a41b368e166af63515370d9c9367e3dda2 but for windows.

===================================================================

M       intern/ghost/intern/GHOST_ContextWGL.cpp
M       intern/ghost/intern/GHOST_ContextWGL.h

===================================================================

diff --git a/intern/ghost/intern/GHOST_ContextWGL.cpp 
b/intern/ghost/intern/GHOST_ContextWGL.cpp
index 18c7844ad7b..35ebb2c78af 100644
--- a/intern/ghost/intern/GHOST_ContextWGL.cpp
+++ b/intern/ghost/intern/GHOST_ContextWGL.cpp
@@ -145,6 +145,10 @@ GHOST_TSuccess GHOST_ContextWGL::getSwapInterval(int 
&intervalOut)
 
 GHOST_TSuccess GHOST_ContextWGL::activateDrawingContext()
 {
+       if (m_init == false) {
+               initContext();
+       }
+
        if (WIN32_CHK(::wglMakeCurrent(m_hDC, m_hGLRC))) {
                return GHOST_kSuccess;
        }
@@ -958,8 +962,32 @@ GHOST_TSuccess GHOST_ContextWGL::initializeDrawingContext()
                goto error;
        }
 
+       /* Only init the non-offscreen context directly */
+       if (!create_hDC) {
+               initContext();
+
+               initClearGL();
+               ::SwapBuffers(m_hDC);
+       }
+
+       return GHOST_kSuccess;
+error:
+       if (m_dummyPbuffer) {
+               if (m_hDC != NULL)
+                       WIN32_CHK(::wglReleasePbufferDCARB(m_dummyPbuffer, 
m_hDC));
+
+               WIN32_CHK(::wglDestroyPbufferARB(m_dummyPbuffer));
+       }
+       ::wglMakeCurrent(prevHDC, prevHGLRC);
+       return GHOST_kFailure;
+
+}
+
+
+GHOST_TSuccess GHOST_ContextWGL::initContext()
+{
        if (!WIN32_CHK(::wglMakeCurrent(m_hDC, m_hGLRC))) {
-               goto error;
+               return GHOST_kFailure;
        }
 
        initContextGLEW();
@@ -973,8 +1001,7 @@ GHOST_TSuccess GHOST_ContextWGL::initializeDrawingContext()
                glEnable(GL_POINT_SPRITE);
        }
 
-       initClearGL();
-       ::SwapBuffers(m_hDC);
+       m_init = true;
 
 #ifndef NDEBUG
        const char *vendor = reinterpret_cast<const 
char*>(glGetString(GL_VENDOR));
@@ -989,16 +1016,6 @@ GHOST_TSuccess 
GHOST_ContextWGL::initializeDrawingContext()
 #endif
 
        return GHOST_kSuccess;
-error:
-       if (m_dummyPbuffer) {
-               if (m_hDC != NULL)
-                       WIN32_CHK(::wglReleasePbufferDCARB(m_dummyPbuffer, 
m_hDC));
-
-               WIN32_CHK(::wglDestroyPbufferARB(m_dummyPbuffer));
-       }
-       ::wglMakeCurrent(prevHDC, prevHGLRC);
-       return GHOST_kFailure;
-
 }
 
 
diff --git a/intern/ghost/intern/GHOST_ContextWGL.h 
b/intern/ghost/intern/GHOST_ContextWGL.h
index be9575844c9..b77a50ae23e 100644
--- a/intern/ghost/intern/GHOST_ContextWGL.h
+++ b/intern/ghost/intern/GHOST_ContextWGL.h
@@ -140,6 +140,7 @@ private:
                bool needStencil,
                bool sRGB,
                int  swapMethod);
+       GHOST_TSuccess initContext();
 
        void initContextWGLEW(PIXELFORMATDESCRIPTOR &preferredPFD);
 
@@ -149,6 +150,7 @@ private:
 
        HWND m_hWnd;
        HDC  m_hDC;
+       bool m_init;
 
        const int m_contextProfileMask;
        const int m_contextMajorVersion;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to