[Bf-blender-cvs] [e0c088f8fb5] blender2.8: GHOST: WGL: Make background rendering works on windows.
fclem
noreply at git.blender.org
Thu Apr 26 12:02:14 CEST 2018
Commit: e0c088f8fb5afcb2dd70d7a6c275fd942f6e42a9
Author: fclem
Date: Thu Apr 26 11:49:47 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBe0c088f8fb5afcb2dd70d7a6c275fd942f6e42a9
GHOST: WGL: Make background rendering works on windows.
When creating an offscreen context we need wglCreatePbufferARB to create
a drawable. In non-background mode wglCreatePbufferARB would have been set
by the main window creation code. But in background mode this is not the
case so we need to create a dummy context using the screen window to init
wglew properly.
===================================================================
M intern/ghost/intern/GHOST_ContextWGL.cpp
===================================================================
diff --git a/intern/ghost/intern/GHOST_ContextWGL.cpp b/intern/ghost/intern/GHOST_ContextWGL.cpp
index 58ade795e3f..18c7844ad7b 100644
--- a/intern/ghost/intern/GHOST_ContextWGL.cpp
+++ b/intern/ghost/intern/GHOST_ContextWGL.cpp
@@ -323,6 +323,33 @@ static HWND clone_window(HWND hWnd, LPVOID lpParam)
return hwndCloned;
}
+/* It can happen that glew has not been init yet but we need some wgl functions.
+ * This create a dummy context on the screen window and init glew to have correct
+ * functions pointers. */
+static GHOST_TSuccess forceInitWGLEW(int iPixelFormat, PIXELFORMATDESCRIPTOR &chosenPFD)
+{
+ HDC dummyHDC = GetDC(NULL);
+
+ if (!WIN32_CHK(::SetPixelFormat(dummyHDC, iPixelFormat, &chosenPFD)))
+ return GHOST_kFailure;
+
+ HGLRC dummyHGLRC = ::wglCreateContext(dummyHDC);
+
+ if (!WIN32_CHK(dummyHGLRC != NULL))
+ return GHOST_kFailure;
+
+ if (!WIN32_CHK(::wglMakeCurrent(dummyHDC, dummyHGLRC)))
+ return GHOST_kFailure;
+
+ if (GLEW_CHK(glewInit()) != GLEW_OK)
+ return GHOST_kFailure;
+
+ WIN32_CHK(::wglDeleteContext(dummyHGLRC));
+
+ WIN32_CHK(ReleaseDC(NULL, dummyHDC));
+
+ return GHOST_kSuccess;
+}
void GHOST_ContextWGL::initContextWGLEW(PIXELFORMATDESCRIPTOR &preferredPFD)
{
@@ -364,6 +391,14 @@ void GHOST_ContextWGL::initContextWGLEW(PIXELFORMATDESCRIPTOR &preferredPFD)
}
else {
int iAttribList[] = {0};
+
+ if (wglCreatePbufferARB == NULL) {
+ /* This should only happen in background mode when rendering with opengl engine. */
+ if (forceInitWGLEW(iPixelFormat, chosenPFD) != GHOST_kSuccess) {
+ goto finalize;
+ }
+ }
+
dummyhBuffer = wglCreatePbufferARB(m_hDC, iPixelFormat, 1, 1, iAttribList);
dummyHDC = wglGetPbufferDCARB(dummyhBuffer);
}
More information about the Bf-blender-cvs
mailing list