Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorfclem <foucault.clem@gmail.com>2018-04-26 12:49:47 +0300
committerfclem <foucault.clem@gmail.com>2018-04-26 12:49:47 +0300
commite0c088f8fb5afcb2dd70d7a6c275fd942f6e42a9 (patch)
tree4abf6d3811409b90ce6f0164b11ec6f79bddcd77 /intern
parent7fcdccbb6c42e8d4a2b5804e87698750460caaea (diff)
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.
Diffstat (limited to 'intern')
-rw-r--r--intern/ghost/intern/GHOST_ContextWGL.cpp35
1 files changed, 35 insertions, 0 deletions
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);
}