[Piglit] [PATCH] Add test to switch on/off MSAA in FBO

Anuj Phogat anuj.phogat at gmail.com
Mon Apr 16 09:59:21 PDT 2012


This is the draft version of test case.

Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
I  was developing this test to verify MSAA with FBO. Test output with MSAA
is expected to differ along polygon edges when compared to rendering without
MSAA. But it seems like no MSAA is happening. Did I miss something while
setting up multisample fbo?

GPU Info:
OpenGL vendor string: Advanced Micro Devices, Inc.
OpenGL renderer string: AMD Radeon(TM) HD 6480G
OpenGL version string: 4.2.11554 Compatibility Profile Context
OpenGL shading language version string: 4.20

Software:
Catalyst Version: 12.2

Test output:
./bin/ext_framebuffer_multisample-turn-on-off -auto
GL_SAMPLES = 0, GL_SAMPLE_BUFFERS = 0, MSAA = 0
GL_SAMPLES = 8, GL_SAMPLE_BUFFERS = 1, MSAA = 1
PIGLIT: {'result': 'pass' }

 .../ext_framebuffer_multisample/CMakeLists.gl.txt  |    1 +
 .../spec/ext_framebuffer_multisample/turn-on-off.c |  175 ++++++++++++++++++++
 2 files changed, 176 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/ext_framebuffer_multisample/turn-on-off.c

diff --git a/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt b/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt
index d94b3af..f5d7420 100644
--- a/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt
+++ b/tests/spec/ext_framebuffer_multisample/CMakeLists.gl.txt
@@ -21,3 +21,4 @@ add_executable (ext_framebuffer_multisample-negative-readpixels negative-readpix
 add_executable (ext_framebuffer_multisample-renderbuffer-samples renderbuffer-samples.c)
 add_executable (ext_framebuffer_multisample-renderbufferstorage-samples renderbufferstorage-samples.c)
 add_executable (ext_framebuffer_multisample-samples samples.c)
+add_executable (ext_framebuffer_multisample-turn-on-off turn-on-off.c)
diff --git a/tests/spec/ext_framebuffer_multisample/turn-on-off.c b/tests/spec/ext_framebuffer_multisample/turn-on-off.c
new file mode 100644
index 0000000..d2b639d
--- /dev/null
+++ b/tests/spec/ext_framebuffer_multisample/turn-on-off.c
@@ -0,0 +1,175 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "piglit-util.h"
+/**
+ * @file turn-on-off.c
+ *
+ * This test draws a polygon in FBO with and without multisample render buffer
+ * and compare the two color buffers to verify if MSAA is happening. Pixels in
+ * in multisample renderbuffer should differ on polygon edges.
+ */
+
+int piglit_width = 256;
+int piglit_height = 256;
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA;
+
+static const float texCoords_2d[4][2] = {
+        { 0.0, 0.0 },
+	{ 1.0, 0.0 },
+	{ 1.0, 1.0 },
+	{ 0.0, 1.0 } };
+
+static GLuint rb, fb;
+bool pass = true;
+
+static void
+create_fbo(bool msaa)
+{
+	GLint max_samples, sample_buffers, samples;
+	GLenum status;
+
+	glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
+
+	glGenFramebuffersEXT(1, &fb);
+	glBindFramebufferEXT(GL_FRAMEBUFFER, fb);
+
+	glGenRenderbuffersEXT(1, &rb);
+	glBindRenderbufferEXT(GL_RENDERBUFFER, rb);
+
+	if (msaa)
+		glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER,
+						    max_samples,
+						    GL_RGBA, 256, 256);
+	else
+		glRenderbufferStorage(GL_RENDERBUFFER,
+				      GL_RGBA, 256, 256);
+
+	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER,
+				     GL_COLOR_ATTACHMENT0,
+				     GL_RENDERBUFFER, rb);
+
+	status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
+	if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+		fprintf(stderr, "FBO incomplete\n");
+		piglit_report_result(PIGLIT_FAIL);
+	}
+
+	glGetIntegerv(GL_SAMPLES, &samples);
+	glGetIntegerv(GL_SAMPLE_BUFFERS, &sample_buffers);
+
+	printf("GL_SAMPLES = %d, GL_SAMPLE_BUFFERS = %d, MSAA = %d\n", samples,
+		sample_buffers, msaa);
+}
+
+static void
+destroy_fbo(void)
+{
+	glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
+	glDeleteRenderbuffersEXT(1, &rb);
+	glDeleteFramebuffersEXT(1, &fb);
+	rb = fb = 0;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	GLfloat *pixels = NULL;
+
+	/* Create fbo with single sample render buffer (no multisample buffer) */
+	create_fbo(false);
+
+	/* Set Read and Draw buffer */
+	glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb);
+	glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, fb);
+
+	/* Draw in to fbo */
+	glClearColor(1.0, 0.0, 0.0, 1.0); // Red
+	glClear(GL_COLOR_BUFFER_BIT);
+	glColor4f(0.0, 1.0, 0.0, 1.0); // Green
+	piglit_draw_rect(0, 0, piglit_width - 100, piglit_height - 100);
+	glColor4f(1.0, 1.0, 0.0, 1.0); // Yellow
+	piglit_draw_rect(0, 0, piglit_width - 150, piglit_height - 150);
+
+	/* Read color buffer in to a buffer */
+	pixels = malloc(piglit_width * piglit_height * 4 * sizeof(float));
+	glReadPixels(0, 0, piglit_width, piglit_height, GL_RGBA, GL_FLOAT,
+				 pixels);
+	destroy_fbo();
+
+	/* Create fbo with multisample render buffer */
+	create_fbo(true);
+
+	/* Draw same stuff in to multisample fbo */
+	glClearColor(1.0, 0.0, 0.0, 1.0); // Red
+	glClear(GL_COLOR_BUFFER_BIT);
+	glColor4f(0.0, 1.0, 0.0, 1.0); // Green
+	piglit_draw_rect(0, 0, piglit_width - 100, piglit_height - 100);
+	glColor4f(1.0, 1.0, 0.0, 1.0); // Yellow
+	piglit_draw_rect(0, 0, piglit_width - 150, piglit_height - 150);
+
+	/* Set default framebuffer */
+	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
+
+	/* Set multisample fbo as read buffer and default buffer as and
+	   draw buffer */
+	glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
+	glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, fb);
+
+	/* Clear the default buffer */
+	glClearColor(0.0, 0.0, 1.0, 1.0); // Blue
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	/* Blit the multisampled fbo in to default buffer. As per
+	 * EXT_framebuffer_multisample, glBlitFramebufferEXT automatically
+	 * invokes the multisample to single sample resolution for each pixel.
+	 */
+	glBlitFramebufferEXT(0, 0, 256, 256,
+                             0, 0, 256, 256,
+                             GL_COLOR_BUFFER_BIT, GL_NEAREST);
+
+	/* Now set default buffer as read buffer */
+	glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);
+
+	/* Compare the MSAA image in framebuffer with previously stored
+	   image buffer (without MSAA) */
+	pass = piglit_probe_image_rgba(0, 0, piglit_width,
+				       piglit_height, pixels)
+	       && pass;
+
+	destroy_fbo();
+	piglit_present_results();
+	return (pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_ortho_projection(piglit_width, piglit_height, GL_TRUE);
+	piglit_require_extension("GL_EXT_framebuffer_object");
+	piglit_require_extension("GL_EXT_framebuffer_multisample");
+	piglit_require_extension("GL_EXT_framebuffer_blit");
+
+	/* I don't think this is required to enable MSAA for FBO */
+	//  glEnable(GL_MULTISAMPLE_ARB);
+}
-- 
1.7.7.6



More information about the Piglit mailing list