[Piglit] [PATCH 1/1] Add a small ARB_draw_buffers test.

Henri Verbeet hverbeet at gmail.com
Sat Sep 17 14:20:02 PDT 2011


Signed-off-by: Henri Verbeet <hverbeet at gmail.com>
---
 tests/all.tests                               |    4 +
 tests/spec/CMakeLists.txt                     |    1 +
 tests/spec/arb_draw_buffers/CMakeLists.gl.txt |   17 ++++
 tests/spec/arb_draw_buffers/CMakeLists.txt    |    1 +
 tests/spec/arb_draw_buffers/draw_buffers.c    |  122 +++++++++++++++++++++++++
 5 files changed, 145 insertions(+), 0 deletions(-)
 create mode 100644 tests/spec/arb_draw_buffers/CMakeLists.gl.txt
 create mode 100644 tests/spec/arb_draw_buffers/CMakeLists.txt
 create mode 100644 tests/spec/arb_draw_buffers/draw_buffers.c

diff --git a/tests/all.tests b/tests/all.tests
index 03dcd59..af899d7 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1272,6 +1272,10 @@ arb_vertex_type_2_10_10_10_rev = Group()
 spec['ARB_vertex_type_2_10_10_10_rev'] = arb_vertex_type_2_10_10_10_rev
 add_plain_test(arb_vertex_type_2_10_10_10_rev, 'draw-vertices-2101010')
 
+arb_draw_buffers = Group()
+spec['ARB_draw_buffers'] = arb_draw_buffers
+add_plain_test(arb_draw_buffers, 'arb_draw_buffers')
+
 # group glslparsertest ------------------------------------------------------
 glslparsertest = Group()
 # Add all shader source files in the directories below.
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index fb3b1de..87ec477 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -26,3 +26,4 @@ add_subdirectory (glsl-1.30)
 add_subdirectory (gl-2.0)
 add_subdirectory (arb_vertex_type_2_10_10_10_rev)
 add_subdirectory (ext_texture_integer)
+add_subdirectory (arb_draw_buffers)
diff --git a/tests/spec/arb_draw_buffers/CMakeLists.gl.txt b/tests/spec/arb_draw_buffers/CMakeLists.gl.txt
new file mode 100644
index 0000000..ffcdcf7
--- /dev/null
+++ b/tests/spec/arb_draw_buffers/CMakeLists.gl.txt
@@ -0,0 +1,17 @@
+include_directories(
+	${GLEXT_INCLUDE_DIR}
+	${OPENGL_INCLUDE_PATH}
+	${GLUT_INCLUDE_DIR}
+	${piglit_SOURCE_DIR}/tests/util
+)
+
+link_libraries (
+	piglitutil
+	${OPENGL_gl_LIBRARY}
+	${OPENGL_glu_LIBRARY}
+	${GLUT_glut_LIBRARY}
+)
+
+add_executable (arb_draw_buffers draw_buffers.c)
+
+# vim: ft=cmake:
diff --git a/tests/spec/arb_draw_buffers/CMakeLists.txt b/tests/spec/arb_draw_buffers/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/arb_draw_buffers/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/arb_draw_buffers/draw_buffers.c b/tests/spec/arb_draw_buffers/draw_buffers.c
new file mode 100644
index 0000000..257acc7
--- /dev/null
+++ b/tests/spec/arb_draw_buffers/draw_buffers.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright © 2011 Henri Verbeet <hverbeet at gmail.com>
+ *
+ * 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 switching between various draw buffers. */
+
+#include "piglit-util.h"
+
+int piglit_width = 128;
+int piglit_height = 128;
+int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB;
+
+static void check_fbo_status(void)
+{
+    GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
+    if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
+    {
+        printf("FBO incomplete, status %#x.\n", status);
+        piglit_report_result(PIGLIT_FAIL);
+    }
+}
+
+enum piglit_result piglit_display(void)
+{
+    static GLenum buffers[] = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT};
+    static const float red[] = {1.0f, 0.0f, 0.0f};
+    static const float green[] = {0.0f, 1.0f, 0.0f};
+    static const float blue[] = {0.0f, 0.0f, 1.0f};
+    static const struct
+    {
+        GLsizei buffer_count;
+        const float *clear_color;
+        const float *expected_0;
+        const float *expected_1;
+    }
+    tests[] =
+    {
+        {2, red, red, red},
+        {1, green, green, red},
+        {2, blue, blue, blue},
+    };
+    int w = piglit_width;
+    int h = piglit_height;
+    GLuint fbo, tex[2];
+    unsigned i;
+
+    glGenTextures(2, tex);
+    glBindTexture(GL_TEXTURE_2D, tex[0]);
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h,
+            0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
+    glBindTexture(GL_TEXTURE_2D, tex[1]);
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h,
+            0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
+
+    glGenFramebuffersEXT(1, &fbo);
+    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
+    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex[0], 0);
+    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, tex[1], 0);
+    check_fbo_status();
+    piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);
+
+    for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
+    {
+        glDrawBuffersARB(tests[i].buffer_count, buffers);
+        check_fbo_status();
+
+        glClearColor(tests[i].clear_color[0], tests[i].clear_color[1], tests[i].clear_color[2], 1.0f);
+        glClear(GL_COLOR_BUFFER_BIT);
+
+        glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
+        if (!piglit_probe_pixel_rgb(w / 2, h / 2, tests[i].expected_0))
+        {
+            printf("Probe failed for test %u, attachment 0.\n", i);
+            piglit_report_result(PIGLIT_FAIL);
+        }
+
+        glReadBuffer(GL_COLOR_ATTACHMENT1_EXT);
+        if (!piglit_probe_pixel_rgb(w / 2, h / 2, tests[i].expected_1))
+        {
+            printf("Probe failed for test %u, attachment 1.\n", i);
+            piglit_report_result(PIGLIT_FAIL);
+        }
+    }
+
+    piglit_check_gl_error(GL_NO_ERROR, PIGLIT_FAIL);
+
+    return PIGLIT_PASS;
+}
+
+void piglit_init(int argc, char **argv)
+{
+    GLint i;
+
+    piglit_require_extension("GL_EXT_framebuffer_object");
+    piglit_require_extension("GL_ARB_draw_buffers");
+    glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &i);
+    if (i < 2)
+    {
+        printf("2 draw buffers required, %d reported.\n", i);
+        piglit_report_result(PIGLIT_SKIP);
+    }
+}
-- 
1.7.2.5



More information about the Piglit mailing list