[Bf-blender-cvs] [b75c03e5e88] temp-drawcontext: Support for the new GHOST API in Windows
Germano
noreply at git.blender.org
Sat Feb 10 03:07:01 CET 2018
Commit: b75c03e5e88166eab68b32648d5abfddf65447d7
Author: Germano
Date: Sat Feb 10 00:06:48 2018 -0200
Branches: temp-drawcontext
https://developer.blender.org/rBb75c03e5e88166eab68b32648d5abfddf65447d7
Support for the new GHOST API in Windows
===================================================================
M intern/ghost/intern/GHOST_ContextWGL.cpp
M intern/ghost/intern/GHOST_ContextWGL.h
M intern/ghost/intern/GHOST_SystemWin32.cpp
M intern/ghost/intern/GHOST_SystemWin32.h
M intern/ghost/intern/GHOST_WindowWin32.cpp
===================================================================
diff --git a/intern/ghost/intern/GHOST_ContextWGL.cpp b/intern/ghost/intern/GHOST_ContextWGL.cpp
index d2dd38878f7..e6498f1ffa8 100644
--- a/intern/ghost/intern/GHOST_ContextWGL.cpp
+++ b/intern/ghost/intern/GHOST_ContextWGL.cpp
@@ -745,60 +745,57 @@ static void reportContextString(const char *name, const char *dummy, const char
GHOST_TSuccess GHOST_ContextWGL::initializeDrawingContext()
{
- const bool needAlpha = m_alphaBackground;
+ SetLastError(NO_ERROR);
+
+ HGLRC prevHGLRC = ::wglGetCurrentContext();
+ WIN32_CHK(GetLastError() == NO_ERROR);
+
+ HDC prevHDC = ::wglGetCurrentDC();
+ WIN32_CHK(GetLastError() == NO_ERROR);
+
+ if (!WGLEW_ARB_create_context || ::GetPixelFormat(m_hDC) == 0) {
+ const bool needAlpha = m_alphaBackground;
#ifdef GHOST_OPENGL_STENCIL
- const bool needStencil = true;
+ const bool needStencil = true;
#else
- const bool needStencil = false;
+ const bool needStencil = false;
#endif
#ifdef GHOST_OPENGL_SRGB
- const bool sRGB = true;
+ const bool sRGB = true;
#else
- const bool sRGB = false;
+ const bool sRGB = false;
#endif
+ int iPixelFormat;
+ int lastPFD;
- HGLRC prevHGLRC;
- HDC prevHDC;
-
- int iPixelFormat;
- int lastPFD;
-
- PIXELFORMATDESCRIPTOR chosenPFD;
+ PIXELFORMATDESCRIPTOR chosenPFD;
+ iPixelFormat = choose_pixel_format(m_stereoVisual, m_numOfAASamples, needAlpha, needStencil, sRGB);
- SetLastError(NO_ERROR);
-
- prevHGLRC = ::wglGetCurrentContext();
- WIN32_CHK(GetLastError() == NO_ERROR);
-
- prevHDC = ::wglGetCurrentDC();
- WIN32_CHK(GetLastError() == NO_ERROR);
-
- iPixelFormat = choose_pixel_format(m_stereoVisual, m_numOfAASamples, needAlpha, needStencil, sRGB);
-
- if (iPixelFormat == 0) {
- ::wglMakeCurrent(prevHDC, prevHGLRC);
- return GHOST_kFailure;
- }
+ if (iPixelFormat == 0) {
+ ::wglMakeCurrent(prevHDC, prevHGLRC);
+ return GHOST_kFailure;
+ }
- lastPFD = ::DescribePixelFormat(m_hDC, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &chosenPFD);
+ lastPFD = ::DescribePixelFormat(m_hDC, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &chosenPFD);
- if (!WIN32_CHK(lastPFD != 0)) {
- ::wglMakeCurrent(prevHDC, prevHGLRC);
- return GHOST_kFailure;
- }
+ if (!WIN32_CHK(lastPFD != 0)) {
+ ::wglMakeCurrent(prevHDC, prevHGLRC);
+ return GHOST_kFailure;
+ }
- if (needAlpha && chosenPFD.cAlphaBits == 0)
- fprintf(stderr, "Warning! Unable to find a pixel format with an alpha channel.\n");
+ if (needAlpha && chosenPFD.cAlphaBits == 0)
+ fprintf(stderr, "Warning! Unable to find a pixel format with an alpha channel.\n");
- if (needStencil && chosenPFD.cStencilBits == 0)
- fprintf(stderr, "Warning! Unable to find a pixel format with a stencil buffer.\n");
+ if (needStencil && chosenPFD.cStencilBits == 0)
+ fprintf(stderr, "Warning! Unable to find a pixel format with a stencil buffer.\n");
- if (!WIN32_CHK(::SetPixelFormat(m_hDC, iPixelFormat, &chosenPFD))) {
- ::wglMakeCurrent(prevHDC, prevHGLRC);
- return GHOST_kFailure;
+ if (!WIN32_CHK(::SetPixelFormat(m_hDC, iPixelFormat, &chosenPFD))) {
+ ::wglMakeCurrent(prevHDC, prevHGLRC);
+ return GHOST_kFailure;
+ }
}
if (WGLEW_ARB_create_context) {
@@ -909,9 +906,11 @@ GHOST_TSuccess GHOST_ContextWGL::initializeDrawingContext()
const char *version = reinterpret_cast<const char*>(glGetString(GL_VERSION));
#ifndef NDEBUG
- reportContextString("Vendor", m_dummyVendor, vendor);
- reportContextString("Renderer", m_dummyRenderer, renderer);
- reportContextString("Version", m_dummyVersion, version);
+ if (m_dummyVendor != NULL) {
+ reportContextString("Vendor", m_dummyVendor, vendor);
+ reportContextString("Renderer", m_dummyRenderer, renderer);
+ reportContextString("Version", m_dummyVersion, version);
+ }
#endif
return GHOST_kSuccess;
@@ -927,97 +926,3 @@ GHOST_TSuccess GHOST_ContextWGL::releaseNativeHandles()
return success;
}
-
-/**
- * For any given HDC you may call SetPixelFormat once
- *
- * So we better try to get the correct OpenGL version in a new window altogether, in case it fails.
- * (see https://msdn.microsoft.com/en-us/library/windows/desktop/dd369049(v=vs.85).aspx)
- */
-static bool TryOpenGLVersion(
- HWND hwnd,
- bool wantStereoVisual,
- bool wantAlphaBackground,
- GHOST_TUns16 wantNumOfAASamples,
- int contextProfileMask,
- bool debugContext,
- int major, int minor)
-{
- HWND dummyHWND = clone_window(hwnd, NULL);
- if (dummyHWND == NULL) {
- return false;
- }
-
- HDC dummyHDC = GetDC(dummyHWND);
- if (dummyHDC == NULL) {
- return false;
- }
-
- GHOST_ContextWGL * context = new GHOST_ContextWGL(
- wantStereoVisual,
- wantAlphaBackground,
- wantNumOfAASamples,
- dummyHWND,
- dummyHDC,
- contextProfileMask,
- major, minor,
- (debugContext ? WGL_CONTEXT_DEBUG_BIT_ARB : 0),
- GHOST_OPENGL_WGL_RESET_NOTIFICATION_STRATEGY);
-
- bool result = context->initializeDrawingContext();
- delete context;
-
- ReleaseDC(dummyHWND, dummyHDC);
- DestroyWindow(dummyHWND);
-
- return result;
-}
-
-GHOST_TSuccess GHOST_ContextWGL::getMaximumSupportedOpenGLVersion(
- HWND hwnd,
- bool wantStereoVisual,
- bool wantAlphaBackground,
- GHOST_TUns16 wantNumOfAASamples,
- int contextProfileMask,
- bool debugContext,
- GHOST_TUns8 *r_major_version,
- GHOST_TUns8 *r_minor_version)
-{
- /* - AMD and Intel give us exactly this version
- * - NVIDIA gives at least this version <-- desired behavior
- * So we ask for 4.5, 4.4 ... 3.3 in descending order to get the best version on the user's system. */
- for (int minor = 5; minor >= 0; --minor) {
- if (TryOpenGLVersion(
- hwnd,
- wantStereoVisual,
- wantAlphaBackground,
- wantNumOfAASamples,
- contextProfileMask,
- debugContext,
- 4, minor))
- {
- *r_major_version = 4;
- *r_minor_version = minor;
- return GHOST_kSuccess;
- }
- }
-
- /* Fallback to OpenGL 3.3 */
- if (TryOpenGLVersion(
- hwnd,
- wantStereoVisual,
- wantAlphaBackground,
- wantNumOfAASamples,
- contextProfileMask,
- debugContext,
- 3, 3))
- {
- *r_major_version = 3;
- *r_minor_version = 3;
- return GHOST_kSuccess;
- }
-
- *r_major_version = 0;
- *r_minor_version = 0;
- return GHOST_kFailure;
-}
diff --git a/intern/ghost/intern/GHOST_ContextWGL.h b/intern/ghost/intern/GHOST_ContextWGL.h
index 0d9986a0802..a07cc1b6301 100644
--- a/intern/ghost/intern/GHOST_ContextWGL.h
+++ b/intern/ghost/intern/GHOST_ContextWGL.h
@@ -105,20 +105,6 @@ public:
*/
GHOST_TSuccess getSwapInterval(int &intervalOut);
- /**
- * Gets the maximum supported OpenGL context for the user hardware
- * \return Whether major_version and minor_version resulted in a valid context.
- */
- static GHOST_TSuccess getMaximumSupportedOpenGLVersion(
- HWND hwnd,
- bool wantStereoVisual,
- bool wantAlphaBackground,
- GHOST_TUns16 wantNumOfAASamples,
- int contextProfileMask,
- bool debugContext,
- GHOST_TUns8 *r_major_version,
- GHOST_TUns8 *r_minor_version);
-
private:
int choose_pixel_format(
bool stereoVisual,
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index b0dae432643..1f1d1461949 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -56,6 +56,12 @@
#include "GHOST_WindowManager.h"
#include "GHOST_WindowWin32.h"
+#if defined(WITH_GL_EGL)
+# include "GHOST_ContextEGL.h"
+#else
+# include "GHOST_ContextWGL.h"
+#endif
+
#ifdef WITH_INPUT_NDOF
#include "GHOST_NDOFManagerWin32.h"
#endif
@@ -299,6 +305,105 @@ GHOST_IWindow *GHOST_SystemWin32::createWindow(
}
+/**
+ * Create a new offscreen context.
+ * Never explicitly delete the window, use disposeContext() instead.
+ * \return The new context (or 0 if creation failed).
+ */
+GHOST_IContext *GHOST_SystemWin32::createOffscreenContext()
+{
+ GHOST_WindowWin32 *ghost_window = (GHOST_WindowWin32 *)(m_windowManager->getWindows()[0]);
+ HWND hWnd = ghost_window->getHWND();
+ HDC hDC = GetDC(hWnd);
+
+ GHOST_Context *context;
+
+#if defined(WITH_GL_PROFILE_CORE)
+ for (int minor = 5; minor >= 0; --minor) {
+ context = new GHOST_ContextWGL(
+ false,
+ true,
+ 0,
+ hWnd,
+ hDC,
+ WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
+ 4, minor,
+ (false ? WGL_CONTEXT_DEBUG_BIT_ARB : 0),
+ GHOST_OPENGL_WGL_RESET_NOTIFICATION_STRATEGY);
+
+ if (context->initializeDrawingContext()) {
+ return context;
+ }
+ else {
+ delete context;
+ }
+ }
+
+ context = new GHOST_ContextWGL(
+ false,
+ true,
+ 0,
+ hWnd,
+ hDC,
+ WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
+ 3, 3,
+ (false ? WGL_CONTEXT_DEBUG_BIT_ARB : 0),
+ GHOST_OPENGL_WGL_RESET_NOTIFICATION_STRATEGY);
+
+ if (context->initializeDrawingContext()) {
+ return context;
+ }
+ else {
+ MessageBox(
+ hWnd,
+ "Blender requires a graphics driver with at least OpenGL 3.3 support.\n\n"
+ "The program will now close.",
+ "Blender - Unsupported Graphics Driver!",
+ MB_OK | MB_ICONERROR);
+ exit();
+ delete context;
+ }
+
+#elif defined(WITH_GL_PROFILE_COMPAT)
+ // ask for 2.1 context, driver gives any GL version >= 2.1 (hopefully the latest compatibility profile)
+ // 2.1 ignores the profile bit & is incompatible with core profile
+ context = new GHOST_ContextWGL(
+ false,
+ true,
+ 0,
+ hWnd,
+ NULL,
+ 0, // no profile bit
+ 2, 1,
+ (false ? WGL_CONTEXT_DEBUG_BIT_ARB : 0),
+ GHOST_OPENGL_WGL_RESET_NOTIFICATION_STRATEGY);
+
+ if (context->initializeDrawingContext()) {
+ return context;
+ }
+ else {
+ delete context;
+ }
+#else
+# error // must specify either core or compat at build time
+#endif
+
+ return NULL;
+}
+
+/**
+ * Dispose of a context.
+ * \param context Pointer to the context to be disposed.
+ * \return Indication of success.
+ */
+GHOST_TSuccess GHOST_Sys
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list