[Piglit] [PATCH] Add test to switch on/off MSAA in FBO
Anuj Phogat
anuj.phogat at gmail.com
Tue Apr 17 08:53:21 PDT 2012
This is the draft version of test case.
Note: This patch requires utility function piglit_draw_triangle.
Patch for the same has been posted to mailing list.
Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
Keeping mailing list in CC.
Paul, I changed the rectangles with triangles. I can clearly see aliasing
effect, But I still don't see any MSAA happening on ATI. Could you please
try this on NVIDIA?
.../ext_framebuffer_multisample/CMakeLists.gl.txt | 1 +
.../spec/ext_framebuffer_multisample/turn-on-off.c | 173 ++++++++++++++++++++
2 files changed, 174 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..8031e58
--- /dev/null
+++ b/tests/spec/ext_framebuffer_multisample/turn-on-off.c
@@ -0,0 +1,173 @@
+/*
+ * 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.
+ *
+ * Left image is rendered without multisample render buffer
+ * Right image is with multisample render buffer
+ */
+
+int piglit_width = 512;
+int piglit_height = 256;
+
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA;
+
+static void
+create_fbo(GLuint *fb, GLuint *rb, GLuint width, GLuint height, GLboolean 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, width, height);
+ else
+ glRenderbufferStorage(GL_RENDERBUFFER,
+ GL_RGBA, width, height);
+
+ 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);
+ }
+
+ if(!piglit_automatic) {
+ 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(GLuint *fb, GLuint *rb)
+{
+ glDeleteRenderbuffersEXT(1, rb);
+ glDeleteFramebuffersEXT(1, fb);
+ *rb = *fb = 0;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+ bool pass = true;
+ GLuint w = piglit_width/2, h = piglit_height;
+ GLfloat *pixels = NULL;
+ GLuint fb0, fb1, rb0, rb1;
+
+ /* Create fbo with single sample render buffer (no multisample buffer) */
+ create_fbo(&fb0, &rb0, w, h, false);
+
+ /* Draw in to fbo */
+ glClearColor(0.0, 0.0, 0.0, 1.0); // Black
+ glClear(GL_COLOR_BUFFER_BIT);
+ glColor4f(0.0, 0.0, 1.0, 1.0); // Blue
+ piglit_draw_triangle(50, 0, 206, 0, 128, 256);
+ glColor4f(0.0, 1.0, 0.0, 1.0); // Green
+ piglit_draw_triangle(80, 0, 176, 0, 128, 256);
+ glColor4f(1.0, 1.0, 0.0, 1.0); // Yellow
+ piglit_draw_triangle(100, 0, 156, 0, 128, 256);
+
+ /* Read color buffer in to a buffer */
+ pixels = malloc(w * h * 4 * sizeof(float));
+ glReadPixels(0, 0, w, h, GL_RGBA, GL_FLOAT, pixels);
+
+ glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
+ glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, fb0);
+
+ glBlitFramebufferEXT(0, 0, w, h,
+ 0, 0, piglit_width/2, piglit_height,
+ GL_COLOR_BUFFER_BIT, GL_NEAREST);
+
+ destroy_fbo(&fb0, &rb0);
+
+
+ /* Create fbo with multisample render buffer */
+ create_fbo(&fb1, &rb1, w, h, true);
+
+ /* Draw same stuff in to multisample fbo */
+ glClearColor(0.0, 0.0, 0.0, 1.0); // Black
+ glClear(GL_COLOR_BUFFER_BIT);
+ glColor4f(0.0, 0.0, 1.0, 1.0); // Blue
+ piglit_draw_triangle(50, 0, 206, 0, 128, 256);
+ glColor4f(0.0, 1.0, 0.0, 1.0); // Green
+ piglit_draw_triangle(80, 0, 176, 0, 128, 256);
+ glColor4f(1.0, 1.0, 0.0, 1.0); // Yellow
+ piglit_draw_triangle(100, 0, 156, 0, 128, 256);
+
+ /* Set multisample fbo as read buffer and default buffer as and
+ draw buffer */
+ glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
+ glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, fb1);
+
+ /* 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, w, h,
+ piglit_width/2, 0, piglit_width, piglit_height,
+ 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(piglit_width/2, 0, piglit_width/2,
+ piglit_height, pixels)
+ && pass;
+
+ destroy_fbo(&fb1, &rb1);
+ 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");
+}
--
1.7.7.6
More information about the Piglit
mailing list