In particular, make sure viewports that extend beyond the surface bounds
are handled correctly. Also, if the FBO surface is stored inverted, this
should detect flipped viewport bugs too.
---
tests/all.tests | 1 +
tests/fbo/CMakeLists.gl.txt | 1 +
tests/fbo/fbo-viewport.c | 194 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 196 insertions(+), 0 deletions(-)
create mode 100644 tests/fbo/fbo-viewport.c
diff --git a/tests/all.tests b/tests/all.tests
index da50ee0..1565e6b 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -230,6 +230,7 @@ add_plain_test(fbo, 'fbo-storage-formats')
add_plain_test(fbo, 'fbo-storage-completeness')
add_plain_test(fbo, 'fbo-sys-blit')
add_plain_test(fbo, 'fbo-sys-sub-blit')
+add_plain_test(fbo, 'fbo-viewport')
add_fbo_rg(fbo, 'GL_RED')
add_fbo_rg(fbo, 'GL_R8')
add_fbo_rg(fbo, 'GL_R16')
diff --git a/tests/fbo/CMakeLists.gl.txt b/tests/fbo/CMakeLists.gl.txt
index 579e623..34ac405 100644
--- a/tests/fbo/CMakeLists.gl.txt
+++ b/tests/fbo/CMakeLists.gl.txt
@@ -86,5 +86,6 @@ piglit_add_executable (fbo-copyteximage fbo-copyteximage.c)
piglit_add_executable (fbo-copyteximage-simple fbo-copyteximage-simple.c)
piglit_add_executable (fbo-cubemap fbo-cubemap.c)
piglit_add_executable (fbo-scissor-bitmap fbo-scissor-bitmap.c)
+piglit_add_executable (fbo-viewport fbo-viewport.c)
# vim: ft=cmake:
diff --git a/tests/fbo/fbo-viewport.c b/tests/fbo/fbo-viewport.c
new file mode 100644
index 0000000..c665ad6
--- /dev/null
+++ b/tests/fbo/fbo-viewport.c
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 2012 VMware, Inc.
+ *
+ * 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.
+ */
+
+/**
+ * Test glViewport w/ FBOs.
+ * In Mesa, on-screen windows and user-created FBOs are stored differently
+ * (inverted). Make sure viewports are handled properly.
+ * Draw a test pattern (with many viewports) into the window, then draw the
+ * same thing into an FBO. Compare the images. They should be the same.
+ */
+
+#include "piglit-util.h"
+#include "piglit-framework.h"
+
+int piglit_width = 500;
+int piglit_height = 500;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
+
+
+/**
+ * Draw some simple quads in a bunch of viewports which tile the window.
+ * Note that viewports extend beyond the edges of the window too.
+ */
+static void
+draw_test_image(void)
+{
+ int vx, vy, vw = 200, vh = 200;
+
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-1, 1, -1, 1, 3, 9.5);
+
+ /* Draw some quads at an odd rotation.
+ * Note that we want near/far frustum clipping.
+ */
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glTranslatef(0, 1, -6.20);
+ glRotatef(-60, 1, 0, 0);
+ glRotatef(30, 0, 0, 1);
+ glScalef(3.5, 3.5, 3.5);
+
+ /* loop over viewports */
+ for (vy = -50; vy < piglit_height; vy += vh+10) {
+ for (vx = -30; vx < piglit_width; vx += vw+10) {
+ glViewport(vx, vy, vw, vh);
+
+ glBegin(GL_QUADS);
+
+ glColor3f(1, 0, 0);
+ glVertex2f(-1, -1);
+ glVertex2f( 0, -1);
+ glVertex2f( 0, 0);
+ glVertex2f(-1, 0);
+
+ glColor3f(0, 1, 0);
+ glVertex2f( 0, -1);
+ glVertex2f( 1, -1);
+ glVertex2f( 1, 0);
+ glVertex2f( 0, 0);
+
+ glColor3f(0, 0, 1);
+ glVertex2f(-1, 0);
+ glVertex2f( 0, 0);
+ glVertex2f( 0, 1);
+ glVertex2f(-1, 1);
+
+ glColor3f(1, 1, 1);
+ glVertex2f( 0, 0);
+ glVertex2f( 1, 0);
+ glVertex2f( 1, 1);
+ glVertex2f( 0, 1);
+
+ glEnd();
+ }
+ }
+
+ glPopMatrix();
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+ GLubyte *win_image, *fbo_image;
+ GLuint fbo, rb;
+ bool pass = true;
+
+ win_image = (GLubyte *) malloc(piglit_width * piglit_height * 3);
+ fbo_image = (GLubyte *) malloc(piglit_width * piglit_height * 3);
+
+ glPixelStorei(GL_PACK_ALIGNMENT, 1);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+ glGenFramebuffers(1, &fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+ glGenRenderbuffers(1, &rb);
+ glBindRenderbuffer(GL_RENDERBUFFER, rb);
+ glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA,
+ piglit_width, piglit_height);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+ GL_RENDERBUFFER, rb);
+
+ assert(glGetError() == 0);
+
+ assert(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) ==
+ GL_FRAMEBUFFER_COMPLETE_EXT);
+
+ /* draw reference image in the window */
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ draw_test_image();
+ glReadPixels(0, 0, piglit_width, piglit_height,
+ GL_RGB, GL_UNSIGNED_BYTE, win_image);
+
+ /* draw test image in fbo */
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+ glReadBuffer(GL_COLOR_ATTACHMENT0);
+ draw_test_image();
+ glReadPixels(0, 0, piglit_width, piglit_height,
+ GL_RGB, GL_UNSIGNED_BYTE, fbo_image);
+
+ /* compare images */
+ if (memcmp(win_image, fbo_image, piglit_width * piglit_height * 3)) {
+#if 0 /* helpful debug code */
+ int i, k;
+ for (i = k = 0; i < piglit_width * piglit_height * 3; i++) {
+ if (win_image[i] != fbo_image[i] && k++ < 40)
+ printf("%d: %d vs. %d\n",
+ i, win_image[i], fbo_image[i]);
+ }
+#endif
+ printf("Image comparison failed!\n");
+ pass = false;
+ }
+ else if (!piglit_automatic) {
+ printf("Image comparison passed.\n");
+ }
+
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+
+#if 0 /* for debug/compare (alternate diplaying Window vs. FBO image) */
+ {
+ int i;
+ glWindowPos2i(0,0);
+ for (i = 0; i < 10; i++) {
+ GLubyte *image = (i & 1) ? fbo_image : win_image;
+ printf("Showing %s image\n", (i & 1) ? "FBO" :
"window");
+ glDrawPixels(piglit_width, piglit_height,
+ GL_RGB, GL_UNSIGNED_BYTE, image);
+ glutSwapBuffers();
+ sleep(1);
+ }
+ }
+#endif
+
+ piglit_present_results();
+
+ glDeleteRenderbuffers(1, &rb);
+ glDeleteFramebuffers(1, &fbo);
+ free(win_image);
+ free(fbo_image);
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+ piglit_require_extension("GL_ARB_framebuffer_object");
+ glClearColor(0.2, 0.2, 0.2, 0.0);
+}
--
1.7.3.4
_______________________________________________
Piglit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/piglit