[Bf-blender-cvs] [422ffd2] master: Pixel format selection now favours a format with a number of samples closer to the one requested on Windows.

Antony Riakiotakis noreply at git.blender.org
Mon Jul 20 10:59:45 CEST 2015


Commit: 422ffd252ac5f73f27f3c91b75b5d20a0ed7d460
Author: Antony Riakiotakis
Date:   Mon Jul 20 10:59:30 2015 +0200
Branches: master
https://developer.blender.org/rB422ffd252ac5f73f27f3c91b75b5d20a0ed7d460

Pixel format selection now favours a format with a number of samples
closer to the one requested on Windows.

Patch D1384 by Benoit Bolsee.

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

M	intern/ghost/intern/GHOST_ContextWGL.cpp
M	intern/ghost/intern/GHOST_ContextWGL.h

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

diff --git a/intern/ghost/intern/GHOST_ContextWGL.cpp b/intern/ghost/intern/GHOST_ContextWGL.cpp
index 4f4cab7..d2a9eed 100644
--- a/intern/ghost/intern/GHOST_ContextWGL.cpp
+++ b/intern/ghost/intern/GHOST_ContextWGL.cpp
@@ -475,7 +475,7 @@ static void makeAttribList(
 		out.push_back(numOfAASamples);
 
 		out.push_back(WGL_SAMPLE_BUFFERS_ARB);
-		out.push_back(1);
+		out.push_back(GL_TRUE);
 	}
 
 	if (sRGB) {
@@ -489,7 +489,7 @@ static void makeAttribList(
 
 int GHOST_ContextWGL::_choose_pixel_format_arb_2(
         bool stereoVisual,
-        int numOfAASamples,
+        int *numOfAASamples,
         bool needAlpha,
         bool needStencil,
         bool sRGB,
@@ -502,12 +502,12 @@ int GHOST_ContextWGL::_choose_pixel_format_arb_2(
 	int samples;
 
 	// guard against some insanely high number of samples
-	if (numOfAASamples > 64) {
+	if (*numOfAASamples > 64) {
 		fprintf(stderr, "Warning! Clamping number of samples to 64.\n");
 		samples = 64;
 	}
 	else {
-		samples = numOfAASamples;
+		samples = *numOfAASamples;
 	}
 
 	// request a format with as many samples as possible, but not more than requested
@@ -542,46 +542,78 @@ int GHOST_ContextWGL::_choose_pixel_format_arb_2(
 		int actualSamples;
 		wglGetPixelFormatAttribivARB(m_hDC, iPixelFormat, 0, 1, iQuery, &actualSamples);
 
-		if (actualSamples != numOfAASamples) {
+		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);
+			        *numOfAASamples, actualSamples);
 
-			m_numOfAASamples = actualSamples; // set context property to actual value
+			*numOfAASamples = actualSamples; // set context property to actual value
 		}
 	}
-
+	else {
+		*numOfAASamples = 0;
+	}
 	return iPixelFormat;
 }
 
 
-int GHOST_ContextWGL::_choose_pixel_format_arb_1(
-        bool stereoVisual,
+int GHOST_ContextWGL::_choose_pixel_format_arb_1(bool stereoVisual,
         int numOfAASamples,
         bool needAlpha,
         bool needStencil,
         bool sRGB,
-        int &swapMethodOut)
+        int *swapMethodOut)
 {
 	int iPixelFormat;
-
-	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);
+	int copyPixelFormat = 0;
+	int undefPixelFormat = 0;
+	int exchPixelFormat = 0;
+	int copyNumOfAASamples = 0;
+	int undefNumOfAASamples = 0;
+	int exchNumOfAASamples = 0;
+
+	*swapMethodOut = WGL_SWAP_COPY_ARB;
+	copyNumOfAASamples = numOfAASamples;
+	copyPixelFormat  = _choose_pixel_format_arb_2(
+		stereoVisual, &copyNumOfAASamples, needAlpha, needStencil, sRGB, *swapMethodOut);
+
+	if (copyPixelFormat == 0 || copyNumOfAASamples < numOfAASamples) {
+		*swapMethodOut = WGL_SWAP_UNDEFINED_ARB;
+		undefNumOfAASamples = numOfAASamples;
+		undefPixelFormat = _choose_pixel_format_arb_2(
+			stereoVisual, &undefNumOfAASamples, needAlpha, needStencil, sRGB, *swapMethodOut);
+
+		if (undefPixelFormat == 0 || undefNumOfAASamples < numOfAASamples) {
+			*swapMethodOut = WGL_SWAP_EXCHANGE_ARB;
+			exchNumOfAASamples = numOfAASamples;
+			exchPixelFormat = _choose_pixel_format_arb_2(
+				stereoVisual, &exchNumOfAASamples, needAlpha, needStencil, sRGB, *swapMethodOut);
+			if (exchPixelFormat == 0 || exchNumOfAASamples < numOfAASamples) {
+				// the number of AA samples cannot be met, take the highest
+				if (undefPixelFormat != 0 && undefNumOfAASamples >= exchNumOfAASamples) {
+					exchNumOfAASamples = undefNumOfAASamples;
+					exchPixelFormat = undefPixelFormat;
+					*swapMethodOut = WGL_SWAP_UNDEFINED_ARB;
+				}
+				if (copyPixelFormat != 0 && copyNumOfAASamples >= exchNumOfAASamples) {
+					exchNumOfAASamples = copyNumOfAASamples;
+					exchPixelFormat = copyPixelFormat;
+					*swapMethodOut = WGL_SWAP_COPY_ARB;
+				}
+			}
+			iPixelFormat = exchPixelFormat;
+			m_numOfAASamples = exchNumOfAASamples;
+		}
+		else {
+			iPixelFormat = undefPixelFormat;
+			m_numOfAASamples = undefNumOfAASamples;
+		}
 	}
-
-	if (iPixelFormat == 0) {
-		swapMethodOut = WGL_SWAP_EXCHANGE_ARB;
-		iPixelFormat  = _choose_pixel_format_arb_2(
-		        stereoVisual, numOfAASamples, needAlpha, needStencil, sRGB, swapMethodOut);
+	else {
+		iPixelFormat = copyPixelFormat;
+		m_numOfAASamples = copyNumOfAASamples;
 	}
-
 	return iPixelFormat;
 }
 
@@ -602,7 +634,7 @@ int GHOST_ContextWGL::choose_pixel_format_arb(
 	        needAlpha,
 	        needStencil,
 	        sRGB,
-	        swapMethodOut);
+	        &swapMethodOut);
 
 	if (iPixelFormat == 0 && stereoVisual) {
 		fprintf(stderr, "Warning! Unable to find a stereo pixel format.\n");
@@ -613,7 +645,7 @@ int GHOST_ContextWGL::choose_pixel_format_arb(
 		        needAlpha,
 		        needStencil,
 		        sRGB,
-		        swapMethodOut);
+		        &swapMethodOut);
 
 		m_stereoVisual = false;  // set context property to actual value
 	}
diff --git a/intern/ghost/intern/GHOST_ContextWGL.h b/intern/ghost/intern/GHOST_ContextWGL.h
index 9f4f6fa..c457dda 100644
--- a/intern/ghost/intern/GHOST_ContextWGL.h
+++ b/intern/ghost/intern/GHOST_ContextWGL.h
@@ -148,11 +148,10 @@ private:
 	        bool needAlpha,
 	        bool needStencil,
 	        bool sRGB,
-	        int &swapMethodOut);
+	        int *swapMethodOut);
 
-	int _choose_pixel_format_arb_2(
-	        bool stereoVisual,
-	        int numOfAASamples,
+	int _choose_pixel_format_arb_2(bool stereoVisual,
+	        int *numOfAASamples,
 	        bool needAlpha,
 	        bool needStencil,
 	        bool sRGB,




More information about the Bf-blender-cvs mailing list