[Piglit] [PATCH 01/12] msaa: Share visualize_image function by moving it to common.cpp

anuj.phogat at gmail.com anuj.phogat at gmail.com
Mon Jul 16 15:47:17 PDT 2012


From: Anuj Phogat <anuj.phogat at gmail.com>

visualize_image function is utilized by multiple msaa test cases.

Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
 tests/spec/ext_framebuffer_multisample/common.cpp  |   84 ++++++++++++++++++++
 tests/spec/ext_framebuffer_multisample/common.h    |    5 +
 tests/spec/ext_framebuffer_multisample/formats.cpp |   77 +++----------------
 3 files changed, 99 insertions(+), 67 deletions(-)

diff --git a/tests/spec/ext_framebuffer_multisample/common.cpp b/tests/spec/ext_framebuffer_multisample/common.cpp
index e1f6127..8bff701 100644
--- a/tests/spec/ext_framebuffer_multisample/common.cpp
+++ b/tests/spec/ext_framebuffer_multisample/common.cpp
@@ -1667,3 +1667,87 @@ create_test(test_type_enum test_type, int n_samples, bool small,
 		   pattern_height, supersample_factor);
 	return test;
 }
+
+/**
+ * Convert the image into a format that can be easily understood by
+ * visual inspection, and display it on the screen.
+ *
+ * Luminance and intensity values are converted to a grayscale value.
+ * Alpha values are visualized by blending the image with a grayscale
+ * checkerboard.
+ *
+ * Pass image_count = 0 to disable drawing multiple images to window
+ * system framebuffer.
+ */
+void
+visualize_image(float *img, GLenum base_internal_format,
+		int image_width, int image_height,
+		int image_count, bool rhs)
+{
+	unsigned components = piglit_num_components(base_internal_format);
+	float *visualization =
+		(float *) malloc(sizeof(float)*3*image_width*image_height);
+	for (int y = 0; y < image_height; ++y) {
+		for (int x = 0; x < image_width; ++x) {
+			float r = 0, g = 0, b = 0, a = 1;
+			float *pixel =
+				&img[(y * image_width + x) * components];
+			switch (base_internal_format) {
+			case GL_ALPHA:
+				a = pixel[0];
+				break;
+			case GL_RGBA:
+				a = pixel[3];
+				/* Fall through */
+			case GL_RGB:
+				b = pixel[2];
+				/* Fall through */
+			case GL_RG:
+				g = pixel[1];
+				/* Fall through */
+			case GL_RED:
+				r = pixel[0];
+				break;
+			case GL_LUMINANCE_ALPHA:
+				a = pixel[1];
+				/* Fall through */
+			case GL_INTENSITY:
+			case GL_LUMINANCE:
+				r = pixel[0];
+				g = pixel[0];
+				b = pixel[0];
+				break;
+			}
+			float checker = ((x ^ y) & 0x10) ? 0.75 : 0.25;
+			r = r * a + checker * (1 - a);
+			g = g * a + checker * (1 - a);
+			b = b * a + checker * (1 - a);
+			visualization[(y * image_width + x) * 3] = r;
+			visualization[(y * image_width + x) * 3 + 1] = g;
+			visualization[(y * image_width + x) * 3 + 2] = b;
+		}
+	}
+	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+	glUseProgram(0);
+
+	/* To simultaneously display multiple images on window system
+	 * framebuffer.
+	 */
+	if(image_count) {
+		glViewport(0, 0, image_width, image_height);
+		/* Use glWindowPos to directly update x, y coordinates of
+		 * current raster position without getting transformed by
+		 * modelview projection matrix and viewport-to-window
+		 * transform.
+		 */
+		glWindowPos2f(rhs ? image_width : 0,
+			      (image_count - 1) * image_height);
+	}
+	else {
+		glViewport(0, 0, piglit_width, piglit_height);
+		glRasterPos2f(rhs ? 0 : -1, -1);
+	}
+	glDrawPixels(image_width, image_height, GL_RGB, GL_FLOAT,
+		     visualization);
+	free(visualization);
+}
diff --git a/tests/spec/ext_framebuffer_multisample/common.h b/tests/spec/ext_framebuffer_multisample/common.h
index d941e96..fda9f26 100644
--- a/tests/spec/ext_framebuffer_multisample/common.h
+++ b/tests/spec/ext_framebuffer_multisample/common.h
@@ -543,3 +543,8 @@ Test *
 create_test(test_type_enum test_type, int n_samples, bool small,
 	    bool combine_depth_stencil, int pattern_width,
 	    int pattern_height, int supersample_factor);
+
+void
+visualize_image(float *img, GLenum base_internal_format,
+		int image_width, int image_height,
+		int draw_buffer_count, bool rhs);
diff --git a/tests/spec/ext_framebuffer_multisample/formats.cpp b/tests/spec/ext_framebuffer_multisample/formats.cpp
index 55542aa..ac2473a 100644
--- a/tests/spec/ext_framebuffer_multisample/formats.cpp
+++ b/tests/spec/ext_framebuffer_multisample/formats.cpp
@@ -350,70 +350,6 @@ PatternRenderer ref_renderer;
 
 
 /**
- * Convert the image into a format that can be easily understood by
- * visual inspection, and display it on the screen.
- *
- * Luminance and intensity values are converted to a grayscale value.
- * Alpha values are visualized by blending the image with a grayscale
- * checkerboard.
- */
-void
-visualize_image(float *img, GLenum base_internal_format, bool rhs)
-{
-	unsigned components = piglit_num_components(base_internal_format);
-	float *visualization =
-		(float *) malloc(sizeof(float)*3*pattern_width*pattern_height);
-	for (int y = 0; y < pattern_height; ++y) {
-		for (int x = 0; x < pattern_width; ++x) {
-			float r = 0, g = 0, b = 0, a = 1;
-			float *pixel =
-				&img[(y * pattern_width + x) * components];
-			switch (base_internal_format) {
-			case GL_ALPHA:
-				a = pixel[0];
-				break;
-			case GL_RGBA:
-				a = pixel[3];
-				/* Fall through */
-			case GL_RGB:
-				b = pixel[2];
-				/* Fall through */
-			case GL_RG:
-				g = pixel[1];
-				/* Fall through */
-			case GL_RED:
-				r = pixel[0];
-				break;
-			case GL_LUMINANCE_ALPHA:
-				a = pixel[1];
-				/* Fall through */
-			case GL_INTENSITY:
-			case GL_LUMINANCE:
-				r = pixel[0];
-				g = pixel[0];
-				b = pixel[0];
-				break;
-			}
-			float checker = ((x ^ y) & 0x10) ? 0.75 : 0.25;
-			r = r * a + checker * (1 - a);
-			g = g * a + checker * (1 - a);
-			b = b * a + checker * (1 - a);
-			visualization[(y * pattern_width + x) * 3] = r;
-			visualization[(y * pattern_width + x) * 3 + 1] = g;
-			visualization[(y * pattern_width + x) * 3 + 2] = b;
-		}
-	}
-	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
-	glViewport(0, 0, piglit_width, piglit_height);
-	glUseProgram(0);
-	glRasterPos2f(rhs ? 0 : -1, -1);
-	glDrawPixels(pattern_width, pattern_height, GL_RGB, GL_FLOAT,
-		     visualization);
-	free(visualization);
-}
-
-
-/**
  * Transform the reference image (which is in GL_RGBA format) to an
  * expected image for a given base internal format, using the the
  * transformation described in the GL 3.0 spec, table 3.15 (Conversion
@@ -537,10 +473,17 @@ test_format(const struct format_desc *format)
 					   expected_image, test_image);
 
 	/* Show both the test and expected images on screen so that
-	 * the user can diagnose problems.
+	 * the user can diagnose problems. Pass image_count = 0 to
+	 * display image without any offset applied to raster position.
 	 */
-	visualize_image(test_image, format->base_internal_format, false);
-	visualize_image(expected_image, format->base_internal_format, true);
+	visualize_image(test_image, format->base_internal_format,
+			pattern_width, pattern_height,
+			0 /* image_count */,
+			false /* rhs */);
+	visualize_image(expected_image, format->base_internal_format,
+			pattern_width, pattern_height,
+			0 /* image_count */,
+			true /* rhs */);
 
 	/* Finally, if any error occurred, count that as a failure. */
 	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
-- 
1.7.7.6



More information about the Piglit mailing list