[Bf-blender-cvs] [1f565b3] soc-2014-viewport_fx: Separation of desired stereo and multisample parameters from actual values along with some other fixes to GHOST

Jason Wilkins noreply at git.blender.org
Wed Jun 25 23:42:39 CEST 2014


Commit: 1f565b3217c2027208c0d265371074e3f8b6d7b8
Author: Jason Wilkins
Date:   Wed Jun 25 09:13:19 2014 -0500
https://developer.blender.org/rB1f565b3217c2027208c0d265371074e3f8b6d7b8

Separation of desired stereo and multisample parameters from actual values along with some other fixes to GHOST

stereoVisual and numOfAASamples now stored in GHOST_Context
parameters for GHOST_Window renamed to wantStereoVisual and wantNumOfAASamples to reflect that context creation will try to satisfy the request, but not fail if it cannot.
The parameters in GHOST_Context hold the actual values that were initialized
added isValid to base GHOST_Window
added updateDrawingContext to GHOST_Context and GHOST_Window (However, it is only needed by OSX)
fixed typo: WGLEW_WGL_EXT_swap_control -> WGLEW_EXT_swap_control

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

M	intern/ghost/intern/GHOST_Context.h
M	intern/ghost/intern/GHOST_ContextEGL.cpp
M	intern/ghost/intern/GHOST_ContextEGL.h
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_Window.cpp
M	intern/ghost/intern/GHOST_Window.h
M	intern/ghost/intern/GHOST_WindowWin32.cpp
M	intern/ghost/intern/GHOST_WindowWin32.h

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

diff --git a/intern/ghost/intern/GHOST_Context.h b/intern/ghost/intern/GHOST_Context.h
index ef61393..85fc8ed 100644
--- a/intern/ghost/intern/GHOST_Context.h
+++ b/intern/ghost/intern/GHOST_Context.h
@@ -46,9 +46,13 @@ class GHOST_Context
 public:
 	/**
 	 * Constructor.
+	 * \param stereoVisual		Stereo visual for quad buffered stereo.
+	 * \param numOfAASamples	Number of samples used for AA (zero if no AA)
 	 */
-	GHOST_Context()
-		: m_glewContext(NULL)
+	GHOST_Context(bool stereoVisual, GHOST_TUns16 numOfAASamples)
+		: m_stereoVisual  (stereoVisual)
+		, m_numOfAASamples(numOfAASamples)
+		, m_glewContext(NULL)
 	{}
 
 	/**
@@ -72,11 +76,18 @@ public:
 
 	/**
 	 * Call immediately after new to initialize.  If this fails then immediately delete the object.
-	 * \param stereoVisual		Stereo visual for quad buffered stereo.
-	 * \param numOfAASamples	Number of samples used for AA (zero if no AA)
 	 * \return Indication as to whether initialization has succeeded.
 	 */
-	virtual GHOST_TSuccess initializeDrawingContext(bool stereoVisual = false, GHOST_TUns16 numOfAASamples = 0) = 0;
+	virtual GHOST_TSuccess initializeDrawingContext() = 0;
+
+	/**
+	 * Updates the drawing context of this window. Needed
+	 * whenever the window is changed.
+	 * \return Indication of success.
+	 */
+	virtual GHOST_TSuccess updateDrawingContext() {
+		return GHOST_kFailure;
+	}
 
 	/**
 	 * Checks if it is OK for a remove the native display
@@ -101,6 +112,19 @@ public:
 		return 1;
 	}
 
+	/** Stereo visual created. Only necessary for 'real' stereo support,
+	 *  ie quad buffered stereo. This is not always possible, depends on
+	 *  the graphics h/w
+	 */
+	inline bool isStereoVisual() const {
+		return m_stereoVisual;
+	}
+
+	/** Number of samples used in anti-aliasing, set to 0 if no AA **/
+	inline GHOST_TUns16 getNumOfAASamples() const {
+		return m_numOfAASamples;
+	}
+
 protected:
 	void initContextGLEW();
 
@@ -108,8 +132,13 @@ protected:
 		glewSetContext(m_glewContext);
 	}
 
+	bool m_stereoVisual;
+	
+	GHOST_TUns16 m_numOfAASamples;
+
 private:
 	GLEWContext* m_glewContext;
+
 };
 
 
diff --git a/intern/ghost/intern/GHOST_ContextEGL.cpp b/intern/ghost/intern/GHOST_ContextEGL.cpp
index 8455cd9..fcdd7b1 100644
--- a/intern/ghost/intern/GHOST_ContextEGL.cpp
+++ b/intern/ghost/intern/GHOST_ContextEGL.cpp
@@ -238,6 +238,8 @@ T& choose_api(EGLenum api, T& a, T& b, T& c)
 
 
 GHOST_ContextEGL::GHOST_ContextEGL(
+	bool                 stereoVisual,
+	GHOST_TUns16         numOfAASamples,
 	EGLNativeWindowType  nativeWindow,
 	EGLNativeDisplayType nativeDisplay,
 	EGLenum              api,
@@ -247,7 +249,8 @@ GHOST_ContextEGL::GHOST_ContextEGL(
 	EGLint               contextFlags,
 	EGLint               contextResetNotificationStrategy
 )
-	: m_nativeWindow (nativeWindow)
+	: GHOST_Context(stereoVisual, numOfAASamples)
+	, m_nativeWindow (nativeWindow)
 	, m_nativeDisplay(nativeDisplay)
 	, m_api(api)
 	, m_contextProfileMask              (contextProfileMask)
@@ -389,14 +392,16 @@ static const std::string& api_string(EGLenum api)
 	return choose_api(api, a, b, c);
 }
 
-GHOST_TSuccess GHOST_ContextEGL::initializeDrawingContext(bool stereoVisual, GHOST_TUns16 numOfAASamples)
+GHOST_TSuccess GHOST_ContextEGL::initializeDrawingContext()
 {
 	// objects have to be declared here due to the use of goto
 	std::vector<EGLint> attrib_list;
 
-	if (stereoVisual)
+	if (m_stereoVisual)
 		fprintf(stderr, "Warning! Stereo OpenGL ES contexts are not supported.\n");
 
+	m_stereoVisual = false; // It doesn't matter what the Window wants.
+
 #if defined(WITH_ANGLE)
 	// d3dcompiler_XX.dll needs to be loaded before ANGLE will work
 	if (s_d3dcompiler == NULL) {
@@ -496,12 +501,12 @@ GHOST_TSuccess GHOST_ContextEGL::initializeDrawingContext(bool stereoVisual, GHO
 	attrib_list.push_back(8);
 #endif
 
-	if (numOfAASamples > 0) {
+	if (m_numOfAASamples > 0) {
 		attrib_list.push_back(EGL_SAMPLE_BUFFERS);
 		attrib_list.push_back(1);
 
 		attrib_list.push_back(EGL_SAMPLES);
-		attrib_list.push_back(numOfAASamples);
+		attrib_list.push_back(m_numOfAASamples);
 	}
 
 	attrib_list.push_back(EGL_NONE);
@@ -512,10 +517,27 @@ GHOST_TSuccess GHOST_ContextEGL::initializeDrawingContext(bool stereoVisual, GHO
 	if (!EGL_CHK(::eglChooseConfig(m_display, &(attrib_list[0]), &config, 1, &num_config)))
 		goto error;
 
-	// common error is to assume that ChooseConfig worked because it returned EGL_TRUE
+	// A common error is to assume that ChooseConfig worked because it returned EGL_TRUE
 	if (num_config != 1) // num_config should be exactly 1
 		goto error;
 
+	if (m_numOfAASamples > 0) {
+		EGLint actualSamples;
+
+		if (!EGL_CHK(::eglGetConfigAttrib(m_display, config, EGL_SAMPLE_BUFFERS, &actualSamples)))
+			goto error;
+
+		if (m_numOfAASamples != actualSamples) {
+			fprintf(
+				stderr,
+				"Warning! Unable to find a multisample pixel format that supports exactly %d samples. Substituting one that uses %d samples.\n",
+				m_numOfAASamples,
+				actualSamples);
+
+			m_numOfAASamples = (GHOST_TUns16)actualSamples;
+		}
+	}
+
 	m_surface = ::eglCreateWindowSurface(m_display, config, m_nativeWindow, NULL);
 
 	if (!EGL_CHK(m_surface != EGL_NO_SURFACE))
diff --git a/intern/ghost/intern/GHOST_ContextEGL.h b/intern/ghost/intern/GHOST_ContextEGL.h
index 7bcba41..dce1a9b9b 100644
--- a/intern/ghost/intern/GHOST_ContextEGL.h
+++ b/intern/ghost/intern/GHOST_ContextEGL.h
@@ -58,6 +58,8 @@ public:
 	 * Constructor.
 	 */
 	GHOST_ContextEGL(
+		bool                 stereoVisual,
+		GHOST_TUns16         numOfAASamples,
 		EGLNativeWindowType  nativeWindow,
 		EGLNativeDisplayType nativeDisplay,
 		EGLenum              api,
@@ -91,7 +93,7 @@ public:
 	 * \param numOfAASamples	Number of samples used for AA (zero if no AA)
 	 * \return Indication as to whether installation has succeeded.
 	 */
-	virtual GHOST_TSuccess initializeDrawingContext(bool stereoVisual = false, GHOST_TUns16 numOfAASamples = 0);
+	virtual GHOST_TSuccess initializeDrawingContext();
 
 	/**
 	 * Removes references to native handles from this context and then returns
diff --git a/intern/ghost/intern/GHOST_ContextWGL.cpp b/intern/ghost/intern/GHOST_ContextWGL.cpp
index dcbd77e..397687b 100644
--- a/intern/ghost/intern/GHOST_ContextWGL.cpp
+++ b/intern/ghost/intern/GHOST_ContextWGL.cpp
@@ -159,15 +159,18 @@ bool win32_chk(bool result, const char* file = NULL, int line = 0, const char* t
 
 
 GHOST_ContextWGL::GHOST_ContextWGL(
-	HWND hWnd,
-	HDC  hDC,
-	int  contextProfileMask,
-	int  contextMajorVersion,
-	int  contextMinorVersion,
-	int  contextFlags,
-	int  contextResetNotificationStrategy
+	bool         stereoVisual,
+	GHOST_TUns16 numOfAASamples,
+	HWND         hWnd,
+	HDC          hDC,
+	int          contextProfileMask,
+	int          contextMajorVersion,
+	int          contextMinorVersion,
+	int          contextFlags,
+	int          contextResetNotificationStrategy
 )
-	: m_hWnd(hWnd)
+	: GHOST_Context(stereoVisual, numOfAASamples)
+	, m_hWnd(hWnd)
 	, m_hDC (hDC)
 	, m_contextProfileMask              (contextProfileMask)
 	, m_contextMajorVersion             (contextMajorVersion)
@@ -227,7 +230,7 @@ GHOST_TSuccess GHOST_ContextWGL::swapBuffers()
 
 GHOST_TSuccess GHOST_ContextWGL::setSwapInterval(int interval)
 {
-	if (WGLEW_WGL_EXT_swap_control)
+	if (WGLEW_EXT_swap_control)
 		return WIN32_CHK(::wglSwapIntervalEXT(interval)) == TRUE ? GHOST_kSuccess : GHOST_kFailure;
 	else
 		return GHOST_kFailure;
@@ -237,16 +240,20 @@ GHOST_TSuccess GHOST_ContextWGL::setSwapInterval(int interval)
 
 int GHOST_ContextWGL::getSwapInterval()
 {
-	return WGLEW_WGL_EXT_swap_control ? ::wglGetSwapIntervalEXT() : 1;
+	return WGLEW_EXT_swap_control ? ::wglGetSwapIntervalEXT() : 1;
 }
 
 
 
 GHOST_TSuccess GHOST_ContextWGL::activateDrawingContext()
 {
-	activateGLEW();
-
-	return WIN32_CHK(::wglMakeCurrent(m_hDC, m_hGLRC)) ? GHOST_kSuccess : GHOST_kFailure;
+	if (WIN32_CHK(::wglMakeCurrent(m_hDC, m_hGLRC))) {
+		activateGLEW();
+		return GHOST_kSuccess;
+	}
+	else {
+		return GHOST_kFailure;
+	}
 }
 
 
@@ -619,9 +626,11 @@ int GHOST_ContextWGL::_choose_pixel_format_arb_2(
 		if (actualSamples != numOfAASamples) {
 			fprintf(
 				stderr,
-				"Warning! Unable to find a multisample pixel format that supports %d samples. Substituting one that uses %d samples.\n",
+				"Warning! Unable to find a multisample pixel format that supports exactly %d samples. Substituting one that uses %d samples.\n",
 				numOfAASamples,
 				actualSamples);
+
+			m_numOfAASamples = actualSamples; // set context property to actual value
 		}
 	}
 
@@ -640,17 +649,17 @@ int GHOST_ContextWGL::_choose_pixel_format_arb_1(
 {
 	int iPixelFormat;
 
-	swapMethodOut   = WGL_SWAP_COPY_ARB;
-	iPixelFormat = _choose_pixel_format_arb_2(stereoVisual, numOfAASamples, needAlpha, needStencil, sRGB, swapMethodOut);
+	swapMethodOut = WGL_SWAP_COPY_ARB;
+	iPixelFormat  = _choose_pixel_format_arb_2(stereoVisual, numOfAASamples, needAlpha, needStencil, sRGB, swapMethodOut);
 
 	if (iPixelFormat == 0) {
 		swapMethodOut = WGL_SWAP_UNDEFINED_ARB;
-		iPixelFormat = _choose_pixel_format_arb_2(stereoVisual, numOfAASamples, needAlpha, needStencil, sRGB, swapMethodOut);
+		iPixelFormat  = _choose_pixel_format_arb_2(stereoVisual, numOfAASamples, needAlpha, needStencil, sRGB, swapMethodOut);
 	}
 
 	if (iPixelFormat == 0) {
-		swapMethodOut   = WGL_SWAP_EXCHANGE_ARB;
-		iPixelFormat = _choose_pixel_format_arb_2(stereoVisual, numOfAASamples, needAlpha, needStencil, sRGB, swapMethodOut);
+		swapMethodOut = WGL_SWAP_EXCHANGE_ARB;
+		iPixelFormat  = _choose_pixel_format_arb_2(stereoVisual, numOfAASamples, needAlpha, needStencil, sRGB, swapMethodOut);
 	}
 
 	return iPixelFormat;
@@ -688,6 +697,8 @@ int GHOST_ContextWGL::choose_pixel_format_arb(
 				needStencil,
 				sRGB,
 				swapMethodOut);
+
+		m_stereoVisual = false;  // set context property to actual value
 	}
 
 	if (swapMethodOut != WGL_SWAP_COPY_ARB) {
@@ -769,7 +780,7 @@ static void reportContextString(const char* name, const char* dummy, const char*
 
 
 
-GHOST_TSuccess GHOST_ContextWGL::initializeDrawingContext(bool stereoVisual, GHOST_TUns16 numOfAASamples)
+GHOST_TSuccess GHOST_ContextWGL::initializeDrawingContext()
 {
 	SetLastError(NO_ERROR);
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list