[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58667] branches/soc-2013-viewport_fx/ intern/ghost/intern: Added paranoid check to make sure the context used to load WGL extensions and the context finally selected for rendering are compatible .

Jason Wilkins Jason.A.Wilkins at gmail.com
Sat Jul 27 18:21:07 CEST 2013


Revision: 58667
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58667
Author:   jwilkins
Date:     2013-07-27 16:21:07 +0000 (Sat, 27 Jul 2013)
Log Message:
-----------
Added paranoid check to make sure the context used to load WGL extensions and the context finally selected for rendering are compatible.

Modified Paths:
--------------
    branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextWGL.cpp
    branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextWGL.h

Modified: branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextWGL.cpp
===================================================================
--- branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextWGL.cpp	2013-07-27 15:50:23 UTC (rev 58666)
+++ branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextWGL.cpp	2013-07-27 16:21:07 UTC (rev 58667)
@@ -45,13 +45,12 @@
 int   GHOST_ContextWGL::s_sharedCount = 0;
 
 
+#ifndef NDEBUG
+static const char* extensionRenderer = NULL;
+#endif
 
-bool GHOST_ContextWGL::s_singleContextMode = false;
+static bool singleContextMode = false;
 
-void GHOST_ContextWGL::setSingleContextMode(bool on)
-{
-	s_singleContextMode = on;
-}
 
 
 
@@ -60,9 +59,9 @@
  * But if we just share context for all windows it could work incorrect
  * with multiple videocards configuration. Suppose, that Intel videocards
  * can't be in multiple-devices configuration. */
-static bool is_crappy_intel_card(void)
+static bool is_crappy_intel_card()
 {
-	return strstr((const char *)glGetString(GL_VENDOR), "Intel") != NULL;
+	return strstr((const char*)glGetString(GL_VENDOR), "Intel") != NULL;
 }
 
 
@@ -368,8 +367,15 @@
 		if (wglewInit() == GLEW_OK)
 			wglewInitialized = true;
 
-		GHOST_ContextWGL::setSingleContextMode(is_crappy_intel_card()); // not WGLEW but also needs a context to work
+		// the following are not technially WGLEW, but they also require a context to work
 
+#ifndef NDEBUG
+		if (extensionRenderer == NULL)
+			extensionRenderer = _strdup((const char *)glGetString(GL_RENDERER));
+#endif
+
+		singleContextMode = is_crappy_intel_card();
+
 finalize:
 		WIN32_CHK(::wglMakeCurrent(prevHDC, prevHGLRC));
 
@@ -572,7 +578,7 @@
 
 		iAttributes.push_back(0);
 
-		if (!s_singleContextMode || s_sharedHGLRC == NULL)
+		if (!singleContextMode || s_sharedHGLRC == NULL)
 			m_hGLRC = ::wglCreateContextAttribsARB(m_hDC, NULL, &(iAttributes[0]));
 		else
 			m_hGLRC = s_sharedHGLRC;
@@ -586,7 +592,7 @@
 			goto error;
 		}
 
-		if (!s_singleContextMode || s_sharedHGLRC == NULL)
+		if (!singleContextMode || s_sharedHGLRC == NULL)
 			m_hGLRC = ::wglCreateContext(m_hDC);
 		else
 			m_hGLRC = s_sharedHGLRC;
@@ -602,12 +608,26 @@
 
 	s_sharedCount++;
 
-	if (!s_singleContextMode && s_sharedHGLRC != m_hGLRC && !WIN32_CHK(::wglShareLists(s_sharedHGLRC, m_hGLRC)))
+	if (!singleContextMode && s_sharedHGLRC != m_hGLRC && !WIN32_CHK(::wglShareLists(s_sharedHGLRC, m_hGLRC)))
 		goto error;
 
 	if (!WIN32_CHK(::wglMakeCurrent(m_hDC, m_hGLRC)))
 		goto error;
 
+#ifndef NDEBUG
+	const char* contextRenderer = (const char*)glGetString(GL_RENDERER);
+
+	if (strcmp(extensionRenderer, contextRenderer) != 0) {
+		fprintf(
+			stderr,
+			"WARNING! WGL extension renderer '%s' does not match current context's renderer '%s'\n",
+			extensionRenderer,
+			contextRenderer);
+
+		abort();
+	}
+#endif
+
 	return GHOST_kSuccess;
 
 error:

Modified: branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextWGL.h
===================================================================
--- branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextWGL.h	2013-07-27 15:50:23 UTC (rev 58666)
+++ branches/soc-2013-viewport_fx/intern/ghost/intern/GHOST_ContextWGL.h	2013-07-27 16:21:07 UTC (rev 58667)
@@ -103,8 +103,6 @@
 	static HGLRC s_sharedHGLRC;
 	static HDC   s_sharedHDC;
 	static int   s_sharedCount;
-
-	static bool s_singleContextMode;
 };
 
 




More information about the Bf-blender-cvs mailing list