From: Mathias Fröhlich <[email protected]> Hi,
This adds clip control to the set of piglit tests. please review Mathias v2: Check for ARB_depth_buffer_float where used. Fix and extend comments. Introduce helper for reading and checking the clip control state. Split state and draw related parts into separate methods. Test for Push/PopAttrib. v3: Add tests to tests/all.py. Signed-off-by: Mathias Froehlich <[email protected]> CC: Ilia Mirkin <[email protected]> CC: Brian Paul <[email protected]> --- registry/gl.xml | 23 +- tests/all.py | 5 + tests/spec/CMakeLists.txt | 1 + tests/spec/arb_clip_control/CMakeLists.gl.txt | 15 ++ tests/spec/arb_clip_control/CMakeLists.txt | 1 + .../clip-control-depth-precision.c | 186 +++++++++++++++ tests/spec/arb_clip_control/clip-control.c | 263 +++++++++++++++++++++ 7 files changed, 493 insertions(+), 1 deletion(-) create mode 100644 tests/spec/arb_clip_control/CMakeLists.gl.txt create mode 100644 tests/spec/arb_clip_control/CMakeLists.txt create mode 100644 tests/spec/arb_clip_control/clip-control-depth-precision.c create mode 100644 tests/spec/arb_clip_control/clip-control.c diff --git a/registry/gl.xml b/registry/gl.xml index 30e8d9f..d432d3d 100644 --- a/registry/gl.xml +++ b/registry/gl.xml @@ -7916,7 +7916,12 @@ typedef unsigned int GLhandleARB; <enum value="0x934A" name="GL_LOCATION_COMPONENT"/> <enum value="0x934B" name="GL_TRANSFORM_FEEDBACK_BUFFER_INDEX"/> <enum value="0x934C" name="GL_TRANSFORM_FEEDBACK_BUFFER_STRIDE"/> - <unused start="0x934D" end="0x9364"/> + <unused start="0x934D" end="0x935B"/> + <enum value="0x935C" name="GL_CLIP_ORIGIN"/> + <enum value="0x935D" name="GL_CLIP_DEPTH_MODE"/> + <enum value="0x935E" name="GL_NEGATIVE_ONE_TO_ONE"/> + <enum value="0x935F" name="GL_ZERO_TO_ONE"/> + <unused start="0x9360" end="0x9364"/> <enum value="0x9365" name="GL_CLEAR_TEXTURE"/> <unused start="0x9366" end="0x937F"/> </enums> @@ -9085,6 +9090,11 @@ typedef unsigned int GLhandleARB; <glx type="render" opcode="2"/> </command> <command> + <proto>void <name>glClipControl</name></proto> + <param><ptype>GLenum</ptype> <name>origin</name></param> + <param><ptype>GLenum</ptype> <name>depth</name></param> + </command> + <command> <proto><ptype>GLenum</ptype> <name>glCheckFramebufferStatus</name></proto> <param group="FramebufferTarget"><ptype>GLenum</ptype> <name>target</name></param> <glx type="vendor" opcode="1427"/> @@ -33515,6 +33525,17 @@ typedef unsigned int GLhandleARB; <command name="glClearTexSubImage"/> </require> </extension> + <extension name="GL_ARB_clip_control" supported="gl"> + <require> + <enum name="GL_LOWER_LEFT"/> + <enum name="GL_UPPER_LEFT"/> + <enum name="GL_NEGATIVE_ONE_TO_ONE"/> + <enum name="GL_ZERO_TO_ONE"/> + <enum name="GL_CLIP_ORIGIN"/> + <enum name="GL_CLIP_DEPTH_MODE"/> + <command name="glClipControl"/> + </require> + </extension> <extension name="GL_ARB_color_buffer_float" supported="gl"> <require> <enum name="GL_RGBA_FLOAT_MODE_ARB"/> diff --git a/tests/all.py b/tests/all.py index ea83695..a629462 100644 --- a/tests/all.py +++ b/tests/all.py @@ -2278,6 +2278,11 @@ add_fbo_generatemipmap_extension(tdfx_texture_compression_fxt1, 'GL_3DFX_texture tdfx_texture_compression_fxt1['invalid formats'] = PiglitGLTest('arb_texture_compression-invalid-formats fxt1', run_concurrent=True) add_plain_test(tdfx_texture_compression_fxt1, 'fxt1-teximage') +arb_clip_control = {} +spec['ARB_clip_control'] = arb_clip_control +add_plain_test(arb_clip_control, 'clip-control') +add_plain_test(arb_clip_control, 'clip-control-depth-precision') + def add_color_buffer_float_test(name, format, p1, p2): arb_color_buffer_float[format + '-' + name + ('-' + p1 if len(p1) else '') + ('-' + p2 if len(p2) else '')] = PiglitGLTest(' '.join(['arb_color_buffer_float-' + name, format, p1, p2]), run_concurrent=True) diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt index b2da115..5a347ae 100644 --- a/tests/spec/CMakeLists.txt +++ b/tests/spec/CMakeLists.txt @@ -3,6 +3,7 @@ add_subdirectory (arb_base_instance) add_subdirectory (arb_buffer_storage) add_subdirectory (arb_clear_buffer_object) add_subdirectory (arb_clear_texture) +add_subdirectory (arb_clip_control) add_subdirectory (arb_color_buffer_float) add_subdirectory (arb_copy_image) add_subdirectory (arb_compute_shader) diff --git a/tests/spec/arb_clip_control/CMakeLists.gl.txt b/tests/spec/arb_clip_control/CMakeLists.gl.txt new file mode 100644 index 0000000..3951bfb --- /dev/null +++ b/tests/spec/arb_clip_control/CMakeLists.gl.txt @@ -0,0 +1,15 @@ +include_directories( + ${GLEXT_INCLUDE_DIR} + ${OPENGL_INCLUDE_PATH} +) + +link_libraries ( + piglitutil_${piglit_target_api} + ${OPENGL_gl_LIBRARY} + ${OPENGL_glu_LIBRARY} +) + +piglit_add_executable (clip-control clip-control.c) +piglit_add_executable (clip-control-depth-precision clip-control-depth-precision.c) + +# vim: ft=cmake: diff --git a/tests/spec/arb_clip_control/CMakeLists.txt b/tests/spec/arb_clip_control/CMakeLists.txt new file mode 100644 index 0000000..144a306 --- /dev/null +++ b/tests/spec/arb_clip_control/CMakeLists.txt @@ -0,0 +1 @@ +piglit_include_target_api() diff --git a/tests/spec/arb_clip_control/clip-control-depth-precision.c b/tests/spec/arb_clip_control/clip-control-depth-precision.c new file mode 100644 index 0000000..3463ca0 --- /dev/null +++ b/tests/spec/arb_clip_control/clip-control-depth-precision.c @@ -0,0 +1,186 @@ +/* + * Copyright Mathias Fröhlich <[email protected]> + * + * 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. + * + * Authors: + * Mathias Fröhlich <[email protected]> + */ + +/** @file clip-control-depth-precision.c + * + * Test for ARB_clip_control. + * This is actually the application level use case making use of the + * close to logarithmic depth buffer precision available with the + * GL_ZERO_TO_ONE depth mode that is newly provided with this extension. + * The ARB_clip_control spec gives a set of web references explaining the + * background greatly. + * In short we set up a projection matrix that maps infinite far away + * points to 0 and the near plane to 1. We use a float depth buffer + * with a well known accuracy behavior. That together gives a depth + * buffer resolution that is about the relative floating point accuracy + * relative to the distance from the eye point. + * This extension avoids adding a constant number even in an intermediate + * step which would destroy the effective depth precision possible with + * the floating point depth buffers. + * Roughtly in numbers: + * Two fragments at 5000001 and 5000000 \about 5000001*(1 - eps) distance + * from the eye point should yield to different values in the depth buffer. + * The same goes for about any fragment distance x that you should be able + * to distinguish this from x*(1 - eps). + * And this is exactly what this test checks. We draw two surfaces + * a big red one at a distance x and a half that big green one at a distance + * x*(1 - 10*eps) to have a security factor of 10 to allow for some roundoff + * errors to accumulate. Due to the depth precision we must not get z fighting + * between these two and see a nested green solid square inside a bigger red + * square really behind it. + */ + +#include "piglit-util-gl.h" + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_compat_version = 20; + + config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE; + +PIGLIT_GL_TEST_CONFIG_END + +void +piglit_init(int argc, char **argv) +{ + GLdouble projection[16] = { 0.0, }; + + piglit_require_extension("GL_ARB_clip_control"); + piglit_require_extension("GL_ARB_depth_buffer_float"); + piglit_require_extension("GL_EXT_framebuffer_object"); + piglit_require_extension("GL_EXT_framebuffer_blit"); + + /* Set up a projection matrix mapping z = -1 to z = 1 + * and z = -inf to z = 0 in projection space. + * Given the clip control setting below, this is just + * written as is into the float depth buffer. + */ + projection[0 + 4*0] = 1; + projection[1 + 4*1] = (GLdouble)piglit_width/piglit_height; + projection[2 + 4*3] = 1; + projection[3 + 4*2] = -1; + + glMatrixMode(GL_PROJECTION); + glLoadMatrixd(projection); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +void +quad(double px, double py, double pz, double size) +{ + glBegin(GL_QUADS); + glVertex3d(px - 0.5*size, py - 0.5*size, pz); + glVertex3d(px + 0.5*size, py - 0.5*size, pz); + glVertex3d(px + 0.5*size, py + 0.5*size, pz); + glVertex3d(px - 0.5*size, py + 0.5*size, pz); + glEnd(); +} + +enum piglit_result +piglit_display(void) +{ + GLfloat red[3] = { 1, 0, 0 }; + GLfloat green[3] = { 0, 1, 0 }; + GLboolean pass = GL_TRUE; + GLuint fb, cb, db; + GLenum status; + int range10; + + glGenRenderbuffers(1, &cb); + glBindRenderbuffer(GL_RENDERBUFFER, cb); + glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, piglit_width, piglit_height); + glBindRenderbuffer(GL_RENDERBUFFER, 0); + + glGenRenderbuffers(1, &db); + glBindRenderbuffer(GL_RENDERBUFFER, db); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32F, piglit_width, piglit_height); + glBindRenderbuffer(GL_RENDERBUFFER, 0); + + glGenFramebuffers(1, &fb); + glBindFramebuffer(GL_FRAMEBUFFER, fb); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, cb); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, db); + + status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) { + printf("FBO incomplete status 0x%X\n", status); + piglit_report_result(PIGLIT_FAIL); + } + + glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); + glClearDepth(0); + glDepthRange(0, 1); + glClearColor(0, 0, 0, 1); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_GREATER); + + for (range10 = 0; range10 < 16; ++range10) { + int width = piglit_width/4; + int height = piglit_height/4; + int tilex = range10 % 4; + int tiley = range10 / 4; + int x = tilex*width; + int y = tiley*height; + double z = pow(10, 1 + range10); + + /* Set up a new viewport for each depth we want to test */ + glViewport(x, y, width, height); + + /* Draw a red surface at given distance z */ + glColor3fv(red); + quad(0, 0, -z, z); + + pass = piglit_probe_pixel_rgb(x + width/2, y + height/2, red) && pass; + + /* And a green one just close in front of that red one */ + glColor3fv(green); + quad(0, 0, (10*FLT_EPSILON - 1)*z, 0.5*z); + quad(0, 0, -z, 0.5*z); + + pass = piglit_probe_pixel_rgb(x + width/2, y + height/2, green) && pass; + } + + + /* set viewport to window size */ + glViewport(0, 0, piglit_width, piglit_height); + + /* copy the result to the back buffer */ + glBindFramebuffer(GL_READ_FRAMEBUFFER, fb); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glBlitFramebuffer(0, 0, piglit_width, piglit_height, 0, 0, piglit_width, piglit_height, GL_COLOR_BUFFER_BIT, GL_NEAREST); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + + glDeleteFramebuffers(1, &fb); + glDeleteRenderbuffers(1, &cb); + glDeleteRenderbuffers(1, &db); + + piglit_present_results(); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} diff --git a/tests/spec/arb_clip_control/clip-control.c b/tests/spec/arb_clip_control/clip-control.c new file mode 100644 index 0000000..b913e40 --- /dev/null +++ b/tests/spec/arb_clip_control/clip-control.c @@ -0,0 +1,263 @@ +/* + * Copyright Mathias Fröhlich <[email protected]> + * + * 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. + * + * Authors: + * Mathias Fröhlich <[email protected]> + */ + +/** @file clip-control.c + * + * Basic test for ARB_clip_contol. + */ + +#include "piglit-util-gl.h" + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_compat_version = 20; + + config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_DEPTH; + +PIGLIT_GL_TEST_CONFIG_END + +void +piglit_init(int argc, char **argv) +{ + piglit_require_extension("GL_ARB_clip_control"); + + piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); +} + +void +quad(float base_x, float base_y, float z) +{ + glBegin(GL_QUADS); + glVertex3f(base_x, base_y, z); + glVertex3f(base_x + 10, base_y, z); + glVertex3f(base_x + 10, base_y + 10, z); + glVertex3f(base_x, base_y + 10, z); + glEnd(); +} + +GLboolean +test_clip_control(GLenum origin, GLenum mode) +{ + GLboolean pass; + GLint value; + + pass = piglit_check_gl_error(GL_NO_ERROR); + + glGetIntegerv(GL_CLIP_ORIGIN, &value); + if (value != origin) { + fprintf(stderr, "glClipControl origin unexpected!\n"); + pass = GL_FALSE; + } + glGetIntegerv(GL_CLIP_DEPTH_MODE, &value); + if (value != mode) { + fprintf(stderr, "glClipControl mode unexpected!\n"); + pass = GL_FALSE; + } + + return pass; +} + +GLboolean +state_test(void) +{ + GLboolean pass = GL_TRUE; + + /* The initial values */ + pass = test_clip_control(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE) && pass; + + glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); + pass = test_clip_control(GL_LOWER_LEFT, GL_ZERO_TO_ONE) && pass; + + glClipControl(GL_UPPER_LEFT, GL_ZERO_TO_ONE); + pass = test_clip_control(GL_UPPER_LEFT, GL_ZERO_TO_ONE) && pass; + + glClipControl(GL_UPPER_LEFT, GL_NEGATIVE_ONE_TO_ONE); + pass = test_clip_control(GL_UPPER_LEFT, GL_NEGATIVE_ONE_TO_ONE) && pass; + + /* Check bailing out on invalid input */ + glClipControl(GL_RGB, GL_NEGATIVE_ONE_TO_ONE); + pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass; + piglit_reset_gl_error(); + pass = test_clip_control(GL_UPPER_LEFT, GL_NEGATIVE_ONE_TO_ONE) && pass; + + glClipControl(GL_LOWER_LEFT, GL_RGB); + pass = piglit_check_gl_error(GL_INVALID_ENUM) && pass; + piglit_reset_gl_error(); + pass = test_clip_control(GL_UPPER_LEFT, GL_NEGATIVE_ONE_TO_ONE) && pass; + + + /* Check push/pop */ + glClipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE); + pass = test_clip_control(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE) && pass; + + glPushAttrib(GL_TRANSFORM_BIT); + + glClipControl(GL_UPPER_LEFT, GL_ZERO_TO_ONE); + pass = test_clip_control(GL_UPPER_LEFT, GL_ZERO_TO_ONE) && pass; + + /* Back to default */ + glPopAttrib(); + pass = test_clip_control(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE) && pass; + + return pass; +} + +GLboolean +draw_test(void) +{ + GLboolean pass = GL_TRUE; + + /* Now prepare the draw buffer */ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glEnable(GL_DEPTH_TEST); + + /* Also test the winding order logic */ + glEnable(GL_CULL_FACE); + glCullFace(GL_BACK); + + /* The clear value - to be sure */ + pass = piglit_probe_pixel_depth(5, 5, 1.0) && pass; + + + + /* Back to default */ + glClipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE); + + /* inside the clip space */ + quad(10, 10, 1.0); + quad(10, 30, 0.5); + quad(10, 50, 0.0); + quad(10, 70, -0.5); + + /* outside the clip space */ + quad(10, 90, 1.5); + quad(10, 110, -1.5); + + /* the written depth value */ + pass = piglit_probe_pixel_depth(15, 15, 0.0) && pass; + pass = piglit_probe_pixel_depth(15, 35, 0.25) && pass; + pass = piglit_probe_pixel_depth(15, 55, 0.5) && pass; + pass = piglit_probe_pixel_depth(15, 75, 0.75) && pass; + + /* still the clear value */ + pass = piglit_probe_pixel_depth(15, 95, 1.0) && pass; + pass = piglit_probe_pixel_depth(15, 115, 1.0) && pass; + + + + glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); + + /* inside the clip space */ + quad(30, 10, 0.0); + quad(30, 30, -0.25); + quad(30, 50, -0.5); + quad(30, 70, -0.75); + + /* outside the clip space */ + quad(30, 90, 0.25); + quad(30, 110, -1.25); + + /* the written depth value */ + pass = piglit_probe_pixel_depth(35, 15, 0.0) && pass; + pass = piglit_probe_pixel_depth(35, 35, 0.25) && pass; + pass = piglit_probe_pixel_depth(35, 55, 0.5) && pass; + pass = piglit_probe_pixel_depth(35, 75, 0.75) && pass; + + /* still the clear value */ + pass = piglit_probe_pixel_depth(35, 95, 1.0) && pass; + pass = piglit_probe_pixel_depth(35, 115, 1.0) && pass; + + + + glClipControl(GL_UPPER_LEFT, GL_NEGATIVE_ONE_TO_ONE); + + /* inside the clip space */ + quad(50, piglit_height - 20, 1.0); + quad(50, piglit_height - 40, 0.5); + quad(50, piglit_height - 60, 0.0); + quad(50, piglit_height - 80, -0.5); + + /* outside the clip space */ + quad(50, piglit_height - 100, 1.5); + quad(50, piglit_height - 120, -1.5); + + /* the written depth value */ + pass = piglit_probe_pixel_depth(55, 15, 0.0) && pass; + pass = piglit_probe_pixel_depth(55, 35, 0.25) && pass; + pass = piglit_probe_pixel_depth(55, 55, 0.5) && pass; + pass = piglit_probe_pixel_depth(55, 75, 0.75) && pass; + + /* still the clear value */ + pass = piglit_probe_pixel_depth(55, 95, 1.0) && pass; + pass = piglit_probe_pixel_depth(55, 115, 1.0) && pass; + + + + glClipControl(GL_UPPER_LEFT, GL_ZERO_TO_ONE); + + /* inside the clip space */ + quad(70, piglit_height - 20, 0.0); + quad(70, piglit_height - 40, -0.25); + quad(70, piglit_height - 60, -0.5); + quad(70, piglit_height - 80, -0.75); + + /* outside the clip space */ + quad(70, piglit_height - 100, 0.25); + quad(70, piglit_height - 120, -1.25); + + /* the written depth value */ + pass = piglit_probe_pixel_depth(75, 15, 0.0) && pass; + pass = piglit_probe_pixel_depth(75, 35, 0.25) && pass; + pass = piglit_probe_pixel_depth(75, 55, 0.5) && pass; + pass = piglit_probe_pixel_depth(75, 75, 0.75) && pass; + + /* still the clear value */ + pass = piglit_probe_pixel_depth(75, 95, 1.0) && pass; + pass = piglit_probe_pixel_depth(75, 115, 1.0) && pass; + + + + /* Back to default */ + glClipControl(GL_LOWER_LEFT, GL_NEGATIVE_ONE_TO_ONE); + + piglit_present_results(); + + return pass; +} + +enum piglit_result +piglit_display(void) +{ + GLboolean pass; + + /* Check for getting and setting the state. */ + pass = state_test(); + + /* Check for correct draws according to the state. */ + pass = draw_test() && pass; + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} -- 1.9.3 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
