[Piglit] [PATCH] add new test for stencil ref clamping

Chris Forbes chrisf at ijw.co.nz
Wed May 15 02:49:13 PDT 2013


Signed-off-by: Chris Forbes <chrisf at ijw.co.nz>
---
 tests/all.tests                   |   1 +
 tests/general/CMakeLists.gl.txt   |   1 +
 tests/general/stencil-ref-clamp.c | 108 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 110 insertions(+)
 create mode 100644 tests/general/stencil-ref-clamp.c

diff --git a/tests/all.tests b/tests/all.tests
index 0f80e0b..869a9cb 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -631,6 +631,7 @@ add_concurrent_test(gl20, 'attribs')
 add_concurrent_test(gl20, 'gl-2.0-edgeflag')
 add_plain_test(gl20, 'getattriblocation-conventional')
 add_plain_test(gl20, 'clip-flag-behavior')
+add_plain_test(gl20, 'stencil-ref-clamp')
 add_concurrent_test(gl20, 'vertex-program-two-side enabled front back front2 back2')
 add_concurrent_test(gl20, 'vertex-program-two-side enabled front back front2')
 add_concurrent_test(gl20, 'vertex-program-two-side enabled front back back2')
diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
index 98e3271..41408b8 100644
--- a/tests/general/CMakeLists.gl.txt
+++ b/tests/general/CMakeLists.gl.txt
@@ -118,6 +118,7 @@ piglit_add_executable (select select.c)
 piglit_add_executable (stencil-drawpixels stencil-drawpixels.c)
 piglit_add_executable (stencil-twoside stencil-twoside.c)
 piglit_add_executable (stencil-wrap stencil-wrap.c)
+piglit_add_executable (stencil-ref-clamp stencil-ref-clamp.c)
 piglit_add_executable (sync_api sync_api.c)
 piglit_add_executable (texgen texgen.c)
 piglit_add_executable (texunits texunits.c)
diff --git a/tests/general/stencil-ref-clamp.c b/tests/general/stencil-ref-clamp.c
new file mode 100644
index 0000000..e80950e
--- /dev/null
+++ b/tests/general/stencil-ref-clamp.c
@@ -0,0 +1,108 @@
+/*
+ * Copyright © 2013 Chris Forbes <chrisf at ijw.co.nz>
+ *
+ * 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 for correct stencil reference value clamping.
+ *
+ * From the GL 4.3 spec, 17.3.35 "Stencil Test":
+ *
+ *      "Stencil comparison operations and queries of <ref> clamp its value
+ *      to the range [0, 2s − 1], where <s> is the number of bits in the
+ *      stencil buffer attached to the draw framebuffer."
+ *
+ * Until recently, Mesa clamped the value at specification time instead.
+ */
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+    config.supports_gl_compat_version = 20;
+    config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+void
+piglit_init(int argc, char **argv)
+{
+    GLuint fbo;
+    GLuint rb;
+    GLint stencil_bits = 1;
+    GLint stencil_ref;
+
+    glGenFramebuffers(1, &fbo);
+    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+
+    /* ensure we have no stencil bits */
+    glGetIntegerv(GL_STENCIL_BITS, &stencil_bits);
+    if (stencil_bits != 0) {
+        printf("initial stencil bits: expected 0, got %d\n", stencil_bits);
+        piglit_report_result(PIGLIT_FAIL);
+    }
+
+    /* set the reference value. this value requires more than 8 bits
+     * so will be clamped with S8 bound.
+     */
+    glStencilFuncSeparate(GL_FRONT_AND_BACK, GL_EQUAL, 0x200, 0xff);
+
+    /* read back the stencil ref; ensure it is clamped */
+    glGetIntegerv(GL_STENCIL_REF, &stencil_ref);
+    if (stencil_ref != 0) {
+        printf("stencil ref with no stencil attachment: expected 0, got 0x%x\n", stencil_ref);
+        piglit_report_result(PIGLIT_FAIL);
+    }
+
+    /* now add a stencil attachment */
+    glGenRenderbuffers(1, &rb);
+    glBindRenderbuffer(GL_RENDERBUFFER, rb);
+    glRenderbufferStorage(GL_RENDERBUFFER, GL_STENCIL_INDEX8, 64, 64);
+    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb);
+
+    if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
+        printf("framebuffer incomplete, not going to work.\n");
+        piglit_report_result(PIGLIT_FAIL);
+    }
+
+    /* now read back the stencil depth, should be 8. */
+    glGetIntegerv(GL_STENCIL_BITS, &stencil_bits);
+    if (stencil_bits != 8) {
+        printf("stencil depth with S8 renderbuffer bound: expected 8, got %d\n", stencil_bits);
+        piglit_report_result(PIGLIT_FAIL);
+    }
+
+    /* finally read back the stencil ref; should be 0xff (max representable in S8) */
+    glGetIntegerv(GL_STENCIL_REF, &stencil_ref);
+    if (stencil_ref != 0xff) {
+        printf("stencil ref with S8 renderbuffer bound: expected 0xff, got 0x%x\n", stencil_ref);
+        piglit_report_result(PIGLIT_FAIL);
+    }
+
+    piglit_report_result(PIGLIT_PASS);
+
+}
+
+enum piglit_result
+piglit_display(void)
+{
+    return PIGLIT_FAIL;     /* shouldn't get here */
+}
-- 
1.8.2.3



More information about the Piglit mailing list