[Bf-blender-cvs] [08974c2] master: Fix X11/GLX failing with multi-sample

Campbell Barton noreply at git.blender.org
Fri Nov 14 13:45:34 CET 2014


Commit: 08974c22e45720bfdc6bba18502175cd3100511f
Author: Campbell Barton
Date:   Fri Nov 14 13:43:22 2014 +0100
Branches: master
https://developer.blender.org/rB08974c22e45720bfdc6bba18502175cd3100511f

Fix X11/GLX failing with multi-sample

Caused by D643, in fact we need to get the visualInfo before creating the window.

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

M	intern/ghost/intern/GHOST_ContextGLX.cpp
M	intern/ghost/intern/GHOST_ContextGLX.h
M	intern/ghost/intern/GHOST_SystemX11.cpp
M	intern/ghost/intern/GHOST_WindowX11.cpp
M	intern/ghost/intern/GHOST_WindowX11.h

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

diff --git a/intern/ghost/intern/GHOST_ContextGLX.cpp b/intern/ghost/intern/GHOST_ContextGLX.cpp
index 726614c..c4e1346 100644
--- a/intern/ghost/intern/GHOST_ContextGLX.cpp
+++ b/intern/ghost/intern/GHOST_ContextGLX.cpp
@@ -54,6 +54,7 @@ GHOST_ContextGLX::GHOST_ContextGLX(
         GHOST_TUns16 numOfAASamples,
         Window window,
         Display *display,
+        XVisualInfo *visualInfo,
         int contextProfileMask,
         int contextMajorVersion,
         int contextMinorVersion,
@@ -61,13 +62,13 @@ GHOST_ContextGLX::GHOST_ContextGLX(
         int contextResetNotificationStrategy)
     : GHOST_Context(stereoVisual, numOfAASamples),
       m_display(display),
+      m_visualInfo(visualInfo),
       m_window(window),
       m_contextProfileMask(contextProfileMask),
       m_contextMajorVersion(contextMajorVersion),
       m_contextMinorVersion(contextMinorVersion),
       m_contextFlags(contextFlags),
       m_contextResetNotificationStrategy(contextResetNotificationStrategy),
-      m_visualInfo(NULL),
       m_context(None)
 #ifdef WITH_GLEW_MX
       ,
@@ -104,8 +105,6 @@ GHOST_ContextGLX::~GHOST_ContextGLX()
 		delete m_glxewContext;
 #endif
 	}
-
-	XFree(m_visualInfo);
 }
 
 
@@ -145,121 +144,6 @@ void GHOST_ContextGLX::initContextGLXEW()
 
 GHOST_TSuccess GHOST_ContextGLX::initializeDrawingContext()
 {
-	/* Set up the minimum attributes that we require and see if
-	 * X can find us a visual matching those requirements. */
-
-	std::vector<int> attribs;
-	attribs.reserve(40);
-
-	int glx_major, glx_minor; /* GLX version: major.minor */
-
-	if (!glXQueryVersion(m_display, &glx_major, &glx_minor)) {
-		fprintf(stderr,
-		        "%s:%d: X11 glXQueryVersion() failed, "
-		        "verify working openGL system!\n",
-		        __FILE__, __LINE__);
-
-		/* exit if this is the first window */
-		if (s_sharedContext == NULL) {
-			fprintf(stderr, "initial window could not find the GLX extension, exit!\n");
-			exit(EXIT_FAILURE);
-		}
-
-		return GHOST_kFailure;
-	}
-
-#ifdef GHOST_OPENGL_ALPHA
-	const bool needAlpha = true;
-#else
-	const bool needAlpha = false;
-#endif
-
-#ifdef GHOST_OPENGL_STENCIL
-	const bool needStencil = true;
-#else
-	const bool needStencil = false;
-#endif
-
-	/* Find the display with highest samples, starting at level requested */
-	int actualSamples = m_numOfAASamples;
-	for (;;) {
-		attribs.clear();
-
-		if (m_stereoVisual)
-			attribs.push_back(GLX_STEREO);
-
-		attribs.push_back(GLX_RGBA);
-
-		attribs.push_back(GLX_DOUBLEBUFFER);
-
-		attribs.push_back(GLX_RED_SIZE);
-		attribs.push_back(1);
-
-		attribs.push_back(GLX_BLUE_SIZE);
-		attribs.push_back(1);
-
-		attribs.push_back(GLX_GREEN_SIZE);
-		attribs.push_back(1);
-
-		attribs.push_back(GLX_DEPTH_SIZE);
-		attribs.push_back(1);
-
-		if (needAlpha) {
-			attribs.push_back(GLX_ALPHA_SIZE);
-			attribs.push_back(1);
-		}
-
-		if (needStencil) {
-			attribs.push_back(GLX_STENCIL_SIZE);
-			attribs.push_back(1);
-		}
-
-		/* GLX >= 1.4 required for multi-sample */
-		if (actualSamples > 0 && ((glx_major > 1) || (glx_major == 1 && glx_minor >= 4))) {
-			attribs.push_back(GLX_SAMPLE_BUFFERS);
-			attribs.push_back(1);
-
-			attribs.push_back(GLX_SAMPLES);
-			attribs.push_back(actualSamples);
-		}
-
-		attribs.push_back(None);
-
-		m_visualInfo = glXChooseVisual(m_display, DefaultScreen(m_display), &attribs[0]);
-
-		/* Any sample level or even zero, which means oversampling disabled, is good
-		 * but we need a valid visual to continue */
-		if (m_visualInfo != NULL) {
-			if (actualSamples < m_numOfAASamples) {
-				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);
-			}
-			break;
-		}
-
-		if (actualSamples == 0) {
-			/* All options exhausted, cannot continue */
-			fprintf(stderr,
-			        "%s:%d: X11 glXChooseVisual() failed, "
-			        "verify working openGL system!\n",
-			        __FILE__, __LINE__);
-
-			if (s_sharedContext == None) {
-				fprintf(stderr, "initial window could not find the GLX extension, exit!\n");
-				exit(1);
-			}
-
-			return GHOST_kFailure;
-		}
-		else {
-			--actualSamples;
-		}
-	}
-
-	m_numOfAASamples = actualSamples;
-
 #ifdef WITH_X11_XINPUT
 	/* use our own event handlers to avoid exiting blender,
 	 * this would happen for eg:
diff --git a/intern/ghost/intern/GHOST_ContextGLX.h b/intern/ghost/intern/GHOST_ContextGLX.h
index d32adf3..9bc17d4 100644
--- a/intern/ghost/intern/GHOST_ContextGLX.h
+++ b/intern/ghost/intern/GHOST_ContextGLX.h
@@ -65,6 +65,7 @@ public:
 	        GHOST_TUns16 numOfAASamples,
 	        Window window,
 	        Display *display,
+	        XVisualInfo *visualInfo,
 	        int contextProfileMask,
 	        int contextMajorVersion,
 	        int contextMinorVersion,
@@ -126,6 +127,7 @@ private:
 	void initContextGLXEW();
 
 	Display *m_display;
+	XVisualInfo *m_visualInfo;
 	Window   m_window;
 
 	const int m_contextProfileMask;
@@ -134,8 +136,6 @@ private:
 	const int m_contextFlags;
 	const int m_contextResetNotificationStrategy;
 
-	XVisualInfo *m_visualInfo;
-
 	GLXContext m_context;
 
 #ifdef WITH_GLEW_MX
diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp
index e3baeba..d4693e9 100644
--- a/intern/ghost/intern/GHOST_SystemX11.cpp
+++ b/intern/ghost/intern/GHOST_SystemX11.cpp
@@ -32,6 +32,11 @@
  *  \ingroup GHOST
  */
 
+#include <X11/Xatom.h>
+#include <X11/keysym.h>
+#include <X11/XKBlib.h> /* allow detectable autorepeate */
+#include <X11/Xutil.h>
+
 #include "GHOST_SystemX11.h"
 #include "GHOST_WindowX11.h"
 #include "GHOST_WindowManager.h"
@@ -52,11 +57,6 @@
 
 #include "GHOST_Debug.h"
 
-#include <X11/Xatom.h>
-#include <X11/keysym.h>
-#include <X11/XKBlib.h> /* allow detectable autorepeate */
-#include <X11/Xutil.h>
-
 #ifdef WITH_XF86KEYSYM
 #include <X11/XF86keysym.h>
 #endif
diff --git a/intern/ghost/intern/GHOST_WindowX11.cpp b/intern/ghost/intern/GHOST_WindowX11.cpp
index 97f8ae7..ed8e9db 100644
--- a/intern/ghost/intern/GHOST_WindowX11.cpp
+++ b/intern/ghost/intern/GHOST_WindowX11.cpp
@@ -29,6 +29,10 @@
  *  \ingroup GHOST
  */
 
+/* For standard X11 cursors */
+#include <X11/cursorfont.h>
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
 
 #include "GHOST_WindowX11.h"
 #include "GHOST_SystemX11.h"
@@ -45,11 +49,6 @@
 #  include "GHOST_ContextGLX.h"
 #endif
 
-
-/* For standard X11 cursors */
-#include <X11/cursorfont.h>
-#include <X11/Xatom.h>
-
 #if defined(__sun__) || defined(__sun) || defined(__sparc) || defined(__sparc__) || defined(_AIX)
 #  include <strings.h>
 #endif
@@ -153,7 +152,118 @@ static long BLENDER_ICON_48x48x32[] = {
 	4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303, 4671303,
 };
 
+static XVisualInfo *x11_visualinfo_from_glx(
+        Display *display,
+        bool stereoVisual, GHOST_TUns16 *r_numOfAASamples)
+{
+	XVisualInfo *visualInfo = NULL;
+	GHOST_TUns16 numOfAASamples = *r_numOfAASamples;
+	/* Set up the minimum attributes that we require and see if
+	 * X can find us a visual matching those requirements. */
+
+	std::vector<int> attribs;
+	attribs.reserve(40);
+
+	int glx_major, glx_minor; /* GLX version: major.minor */
 
+	if (!glXQueryVersion(display, &glx_major, &glx_minor)) {
+		fprintf(stderr,
+		        "%s:%d: X11 glXQueryVersion() failed, "
+		        "verify working openGL system!\n",
+		        __FILE__, __LINE__);
+
+		return NULL;
+	}
+
+#ifdef GHOST_OPENGL_ALPHA
+	const bool needAlpha = true;
+#else
+	const bool needAlpha = false;
+#endif
+
+#ifdef GHOST_OPENGL_STENCIL
+	const bool needStencil = true;
+#else
+	const bool needStencil = false;
+#endif
+
+	/* Find the display with highest samples, starting at level requested */
+	GHOST_TUns16 actualSamples = numOfAASamples;
+	for (;;) {
+		attribs.clear();
+
+		if (stereoVisual)
+			attribs.push_back(GLX_STEREO);
+
+		attribs.push_back(GLX_RGBA);
+
+		attribs.push_back(GLX_DOUBLEBUFFER);
+
+		attribs.push_back(GLX_RED_SIZE);
+		attribs.push_back(1);
+
+		attribs.push_back(GLX_BLUE_SIZE);
+		attribs.push_back(1);
+
+		attribs.push_back(GLX_GREEN_SIZE);
+		attribs.push_back(1);
+
+		attribs.push_back(GLX_DEPTH_SIZE);
+		attribs.push_back(1);
+
+		if (needAlpha) {
+			attribs.push_back(GLX_ALPHA_SIZE);
+			attribs.push_back(1);
+		}
+
+		if (needStencil) {
+			attribs.push_back(GLX_STENCIL_SIZE);
+			attribs.push_back(1);
+		}
+
+		/* GLX >= 1.4 required for multi-sample */
+		if (actualSamples > 0 && ((glx_major > 1) || (glx_major == 1 && glx_minor >= 4))) {
+			attribs.push_back(GLX_SAMPLE_BUFFERS);
+			attribs.push_back(1);
+
+			attribs.push_back(GLX_SAMPLES);
+			attribs.push_back(actualSamples);
+		}
+
+		attribs.push_back(None);
+
+		visualInfo = glXChooseVisual(display, DefaultScreen(display), &attribs[0]);
+
+		/* Any sample level or even zero, which means oversampling disabled, is good
+		 * but we need a valid visual to continue */
+		if (visualInfo != NULL) {
+			if (actualSamples < numOfAASamples) {
+				fprintf(stderr,
+				        "Warning! Unable to find a multisample pixel format that supports exactly %d samples. "
+				        "Substituting one that uses %d samples.\n",
+				        numOfAASamples, actualSamples);
+			}
+			break;
+		}
+
+		if (actualSamples == 0) {
+			/* All options exhausted, cannot continue */
+			fprintf(stderr,
+			        "%s:%d: X11 glXChooseVisual() failed, "
+			        "verify working openGL system!\n",
+			        __FILE__, __LINE__);
+
+			return NULL;
+		}
+		else {
+			--actualSamples;
+		}
+	}
+
+	*r_numOfAASamples = actualSamples;
+
+	return visualInfo;
+}
 
 GHOST_WindowX11::
 GHOST_WindowX11(
@@ -172,6 +282,7 @@ GHOST_WindowX11(
         const GHOST_TUns16 numOfAASamples)
     : GHOST_Window(width, height, state, stereoVisual, exclusive, numOfAASamples),

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list