From 8eac28a12839357487a0e4717ca1bf37dca1b6d4 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Tue, 20 Apr 2010 23:32:32 +0100 Subject: [PATCH] Add a test for GL_VERTEX_PROGRAM_POINT_SIZE When GL_VERTEX_PROGRAM_POINT_SIZE is enabled the vertex shader should be able to write to gl_PointSize to change the size of a point. This simple test sets the size to 16 in the shader and verifies that the point is large. --- tests/all.tests | 1 + tests/shaders/CMakeLists.txt | 1 + tests/shaders/glsl-vs-point-size.c | 112 +++++++++++++++++++++++++++++++++ tests/shaders/glsl-vs-point-size.vert | 6 ++ 4 files changed, 120 insertions(+), 0 deletions(-) create mode 100644 tests/shaders/glsl-vs-point-size.c create mode 100644 tests/shaders/glsl-vs-point-size.vert diff --git a/tests/all.tests b/tests/all.tests index a90acfc..fa1a55d 100644 --- a/tests/all.tests +++ b/tests/all.tests @@ -227,6 +227,7 @@ add_plain_test(shaders, 'glsl-lod-bias') add_plain_test(shaders, 'vp-ignore-input') add_plain_test(shaders, 'glsl-empty-vs-no-fs') add_plain_test(shaders, 'glsl-useprogram-displaylist') +add_plain_test(shaders, 'glsl-vs-point-size') fpgeneric = Group() def add_fpgeneric(name): diff --git a/tests/shaders/CMakeLists.txt b/tests/shaders/CMakeLists.txt index ae97829..c8c2b13 100644 --- a/tests/shaders/CMakeLists.txt +++ b/tests/shaders/CMakeLists.txt @@ -96,3 +96,4 @@ add_executable (glsl-empty-vs-no-fs glsl-empty-vs-no-fs.c) add_executable (glsl-useprogram-displaylist glsl-useprogram-displaylist.c) add_executable (glsl-routing glsl-routing.c) add_executable (shader_runner shader_runner.c) +add_executable (glsl-vs-point-size glsl-vs-point-size.c) diff --git a/tests/shaders/glsl-vs-point-size.c b/tests/shaders/glsl-vs-point-size.c new file mode 100644 index 0000000..3e83154 --- /dev/null +++ b/tests/shaders/glsl-vs-point-size.c @@ -0,0 +1,112 @@ +/* + * Copyright © 2010 Intel Corporation + * + * 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: + * Neil Roberts + * + */ + +/** @file glsl-vs-point-size.c + * + * Tests whether a vertex shader can change the point size by writing + * to gl_PointSize. + * + * Bug #27250 + */ + +#include "piglit-util.h" + +int piglit_width = 32, piglit_height = 32; +int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE; + +static GLint prog; + +static const float white[4] = {1, 1, 1, 1}; +static const float black[4] = {0, 0, 0, 0}; + +#define POINT_SIZE 16 + +enum piglit_result +piglit_display(void) +{ + GLboolean pass = GL_TRUE; + float vert[2] = { piglit_width / 2, piglit_height / 2 }; + + /* Clear the window to black */ + glClear(GL_COLOR_BUFFER_BIT); + + /* Draw a single white point at the centre of the window. The + vertex shader should make this larger */ + glColor3fv(white); + glVertexPointer(2, GL_FLOAT, 0, vert); + glEnableClientState(GL_VERTEX_ARRAY); + glDrawArrays(GL_POINTS, 0, 1); + glDisableClientState(GL_VERTEX_ARRAY); + + /* Verify that the point is large by looking at some corner pixels */ + pass &= piglit_probe_pixel_rgb(piglit_width / 2 - POINT_SIZE / 2 + 1, + piglit_height / 2 - POINT_SIZE / 2 + 1, + white); + pass &= piglit_probe_pixel_rgb(piglit_width / 2 + POINT_SIZE / 2 - 1, + piglit_height / 2 + POINT_SIZE / 2 - 1, + white); + /* Sanity check that the corners of the window aren't filled */ + pass &= piglit_probe_pixel_rgb(0, 0, black); + pass &= piglit_probe_pixel_rgb(piglit_width - 1, piglit_height - 1, + black); + + glutSwapBuffers(); + + return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE; +} + +void +piglit_init(int argc, char **argv) +{ + GLint vs; + GLint point_size_range[2]; + + if (!GLEW_VERSION_2_0) { + printf("Requires OpenGL 2.0\n"); + piglit_report_result(PIGLIT_SKIP); + } + /* If the driver doesn't claim to support the point size the + shader is going to set then we should skip the test */ + glGetIntegerv(GL_ALIASED_POINT_SIZE_RANGE, point_size_range); + if (POINT_SIZE < point_size_range[0] || + POINT_SIZE > point_size_range[1]) { + printf("Point size %i not supported\n", POINT_SIZE); + piglit_report_result(PIGLIT_SKIP); + } + + piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); + glClearColor(0.0, 0.0, 0.0, 1.0); + + vs = piglit_compile_shader(GL_VERTEX_SHADER, + "shaders/glsl-vs-point-size.vert"); + + prog = piglit_link_simple_program(vs, 0); + + glUseProgram(prog); + + glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); +} diff --git a/tests/shaders/glsl-vs-point-size.vert b/tests/shaders/glsl-vs-point-size.vert new file mode 100644 index 0000000..d5ed05a --- /dev/null +++ b/tests/shaders/glsl-vs-point-size.vert @@ -0,0 +1,6 @@ +void main() +{ + gl_Position = vec4(0.0, 0.0, 0.0, 1.0); + gl_PointSize = 16.0; + gl_FrontColor = vec4(1.0, 1.0, 1.0, 1.0); +} -- 1.6.5.rc1.46.g4d818