On Mon, Apr 6, 2015 at 8:39 PM, Dave Airlie <[email protected]> wrote: > This is based on ARB_stencil_texturing draw.c except > it only tests stencil texturing. > > It's also forward ported to core profile. > > v2: fix test comment (Chris) > v2.1: don't require things we don't need. (Ilia) > > Signed-off-by: Dave Airlie <[email protected]> > --- > tests/spec/arb_texture_stencil8/CMakeLists.gl.txt | 1 + > tests/spec/arb_texture_stencil8/draw.c | 213 > ++++++++++++++++++++++ > 2 files changed, 214 insertions(+) > create mode 100644 tests/spec/arb_texture_stencil8/draw.c > > diff --git a/tests/spec/arb_texture_stencil8/CMakeLists.gl.txt > b/tests/spec/arb_texture_stencil8/CMakeLists.gl.txt > index bd3fadd..65e6c19 100644 > --- a/tests/spec/arb_texture_stencil8/CMakeLists.gl.txt > +++ b/tests/spec/arb_texture_stencil8/CMakeLists.gl.txt > @@ -10,5 +10,6 @@ link_libraries ( > ) > > piglit_add_executable (arb_texture_stencil8-stencil-texture > stencil-texture.c) > +piglit_add_executable (arb_texture_stencil8-draw draw.c) > > # vim: ft=cmake: > diff --git a/tests/spec/arb_texture_stencil8/draw.c > b/tests/spec/arb_texture_stencil8/draw.c > new file mode 100644 > index 0000000..82c5bc0 > --- /dev/null > +++ b/tests/spec/arb_texture_stencil8/draw.c > @@ -0,0 +1,213 @@ > +/* > + * Copyright © 2014 Intel Corporation > + * Copyright © 2015 Red Hat > + * > + * 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. > + */ > + > +/** > + * \file draw.c > + * > + * A basic drawing test for GL_ARB_texture_stencil8 which ensures that > + * sampling occurs from the right position in the texture. > + * > + * It creates two stencil textures. The first has a horizontal > + * gradient (0 -> 255 for stencil), and the second a > + * vertical gradient. > + * > + * The expected output is two squares, separated by a blue border. > + * The left half of the window is generated by stencil texturing, and drawn > + * in red. > + * > + * Stencil > + * (red) > + * > + * 0 --> 1 > + * -------- > + * 1 > + * ^ > + * | > + * 0 > + */ > + > +#define __STDC_FORMAT_MACROS > +#include <inttypes.h> > +#include "piglit-util-gl.h" > + > +PIGLIT_GL_TEST_CONFIG_BEGIN > + > + config.supports_gl_core_version = 32; > + config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE; > + config.window_width = 256 + 3; > + config.window_height = 256 * 2 + 3; > + > +PIGLIT_GL_TEST_CONFIG_END > + > +float stencil_horiz_expected[256 * 256 * 3]; > +float stencil_vert_expected[256 * 256 * 3]; > + > +GLuint horiz_tex; > +GLuint vert_tex; > + > +/** A program that samples from stencil using usampler2D. */ > +GLint stencil_prog; > + > +GLuint vao; > + > +/******************************************************************************/ > + > +enum piglit_result > +piglit_display(void) > +{ > + bool pass = true; > + > + glClearColor(0.0, 0.0, 1.0, 1.0); > + glClear(GL_COLOR_BUFFER_BIT); > + > + glUseProgram(stencil_prog); > + > + /* Upper left corner: Stencil (black to red, left to right). */ > + glViewport(0, 259, 256, 256); > + glBindTexture(GL_TEXTURE_2D, horiz_tex); > + piglit_draw_rect(-1, -1, 2, 2); > + if (!piglit_probe_image_rgb(0, 259, 256, 256, > stencil_horiz_expected)) { > + printf(" FAIL: stencil (horizontal).\n"); > + pass = false; > + } > + > + > + /* Lower left corner: Stencil (black to red, upwards). */ > + glViewport(0, 0, 256, 256); > + glBindTexture(GL_TEXTURE_2D, vert_tex); > + piglit_draw_rect(-1, -1, 2, 2); > + if (!piglit_probe_image_rgb(0, 0, 256, 256, stencil_vert_expected)) { > + printf(" FAIL: stencil (vertical).\n"); > + pass = false; > + } > + > + piglit_present_results(); > + > + return pass ? PIGLIT_PASS : PIGLIT_FAIL; > +} > + > +/******************************************************************************/ > + > +/* > + * - Stencil ranges from 0 to 255. > + * > + * horiz_tex is left to right (increasing in the +x direction); > + * vert_tex is bottom to top (increasing in the +y direction). > + * > + * Also set up expected values. > + */ > +static void > +setup_textures(void) > +{ > + int i; > + uint8_t horiz_data[256 * 256]; > + uint8_t vert_data[256 * 256]; > + > + for (i = 0; i < ARRAY_SIZE(horiz_data); i++) { > + unsigned x = i % 256; > + unsigned y = i / 256; > + horiz_data[i] = x; > + vert_data[i] = y; > + } > + > + glGenTextures(1, &horiz_tex); > + glBindTexture(GL_TEXTURE_2D, horiz_tex); > + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); > + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); > + glTexImage2D(GL_TEXTURE_2D, 0, GL_STENCIL_INDEX8, > + 256, 256, 0, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, > + horiz_data); > + if (!piglit_check_gl_error(GL_NO_ERROR)) > + piglit_report_result(PIGLIT_FAIL); > + > + glGenTextures(1, &vert_tex); > + glBindTexture(GL_TEXTURE_2D, vert_tex); > + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); > + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); > + glTexImage2D(GL_TEXTURE_2D, 0, GL_STENCIL_INDEX8, > + 256, 256, 0, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, > + vert_data); > + if (!piglit_check_gl_error(GL_NO_ERROR)) > + piglit_report_result(PIGLIT_FAIL); > + > + /* Set up expected values. */ > + memset(stencil_horiz_expected, 0, sizeof(stencil_horiz_expected)); > + memset(stencil_vert_expected, 0, sizeof(stencil_vert_expected)); > + > + for (i = 0; i < 256 * 256; i++) { > + unsigned x = i % 256; > + unsigned y = i / 256; > + stencil_horiz_expected[3*i] = x / 255.0f; > + stencil_vert_expected[3*i] = y / 255.0f; > + } > + > + > +} > + > +/** > + * Compile the shaders used by this program. > + * > + */ > +static void > +setup_shaders(void) > +{ > + int loc; > + > + const char *vs = > + "#version 130\n" > + "in vec4 piglit_vertex;\n" > + "out vec2 texcoords;\n" > + "void main()\n" > + "{\n" > + " gl_Position = piglit_vertex;\n" > + " texcoords = (piglit_vertex.xy + 1.0) / 2.0;\n" > + "}\n"; > + > + const char *fs_stencil = > + "#version 130\n" > + "in vec2 texcoords;\n" > + "uniform usampler2D tex;\n" > + "void main()\n" > + "{\n" > + " uint stencil = texture(tex, texcoords).x;\n" > + " gl_FragColor = vec4(float(stencil) / 255.0, 0, 0, 1);\n" > + "}\n"; > + > + stencil_prog = piglit_build_simple_program(vs, fs_stencil); > + loc = glGetUniformLocation(stencil_prog, "tex"); > + glUseProgram(stencil_prog); > + glUniform1i(loc, 0); > + > +} > + > +void > +piglit_init(int argc, char **argv) > +{ > + piglit_require_extension("GL_ARB_texture_stencil8"); > + > + glGenVertexArrays(1, &vao); > + glBindVertexArray(vao); > + setup_textures(); > + setup_shaders(); > +} > -- > 2.1.0 > > _______________________________________________ > Piglit mailing list > [email protected] > http://lists.freedesktop.org/mailman/listinfo/piglit
Reviewed-by: Anuj Phogat <[email protected]> _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
