From d848afc31f849100b53d3bf8555b39fee3bc2f56 Mon Sep 17 00:00:00 2001 From: Jian Zhao Date: Tue, 10 Jan 2012 15:13:15 +0800 Subject: [PATCH] Add test case of render FBO with point coordinate. Add test case of rendering with point coordinate, it should work with direct rendering, rendering with FBO. As the es spec 2.0.25 says: "the gl-PointCoord fragment shader input defines a per-fragment coordinate space (s; t) where s varies from 0 to 1 across the point horizontally left-to-right, and t ranges from 0 to 1 across the point vertically top-to-bottom." Signed-off-by: Jian Zhao --- tests/bugs/CMakeLists.gl.txt | 1 + tests/bugs/gl-pointcoord.c | 123 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 0 deletions(-) create mode 100644 tests/bugs/gl-pointcoord.c diff --git a/tests/bugs/CMakeLists.gl.txt b/tests/bugs/CMakeLists.gl.txt index bce0532..a373fd6 100644 --- a/tests/bugs/CMakeLists.gl.txt +++ b/tests/bugs/CMakeLists.gl.txt @@ -17,6 +17,7 @@ link_libraries ( add_executable (crash-cubemap-order crash-cubemap-order.c) add_executable (crash-texparameter-before-teximage crash-texparameter-before-teximage.c) add_executable (fdo9833 fdo9833.c) +add_executable (gl-pointcoord gl-pointcoord.c) add_executable (fdo10370 fdo10370.c) add_executable (fdo14575 fdo14575.c) add_executable (r300-readcache r300-readcache.c) diff --git a/tests/bugs/gl-pointcoord.c b/tests/bugs/gl-pointcoord.c new file mode 100644 index 0000000..7bd204b --- /dev/null +++ b/tests/bugs/gl-pointcoord.c @@ -0,0 +1,123 @@ +/* + * Copyright © 2012 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: + * * Jian Zhao + * * + * + */ + +/** + * \file gl-pointcoord.c + * Verify that applications can use point coordinate correctly, + * especailly with FBO. + */ + +#include "piglit-util.h" + +int piglit_width = 100, piglit_height = 100; +int piglit_window_mode = GLUT_RGB | GLUT_SINGLE; + +static const char vs_text[] = + "#version 120 \n" + "attribute vec4 vPosition;\n" + "uniform float uPointSize;\n" + "void main()\n" + "{\n" + "gl_PointSize = uPointSize;\n" + "gl_Position = vPosition;\n" + "}\n" + ; + +static const char fs_text[] = + "#version 120 \n" + "void main() { gl_FragColor = vec4(gl_PointCoord.x, gl_PointCoord.y, 0.0, 1.0); }\n" + ; +static GLuint prog; + +static const float green[] = { 0.0, 1.0, 0.0, 1.0 }; +static const float black[] = { 0.0, 0.0, 0.0, 1.0 }; +static GLenum Origin = GL_UPPER_LEFT; + +enum piglit_result +piglit_display(void) +{ + GLboolean pass = GL_TRUE; + int pointSizeLoc, maxPointSize; + GLuint fb, rb; + + maxPointSize = 64; + glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); +#ifdef GL_ARB_point_sprite + glEnable(GL_POINT_SPRITE_ARB); +#endif + pointSizeLoc = glGetUniformLocation(prog, "uPointSize"); + glUniform1f(pointSizeLoc, maxPointSize); + + glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, Origin); + + glGenRenderbuffers(1, &rb); + glBindRenderbuffer(GL_RENDERBUFFER, rb); + glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, 100, 100); + + glGenFramebuffers(1, &fb); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb); + glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + GL_RENDERBUFFER, rb); + + glClearColor(0.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + glBegin(GL_POINTS); + glVertex2f(0.0, 0.0); + glEnd(); + + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glBindFramebuffer(GL_READ_FRAMEBUFFER, fb); + glBlitFramebuffer(0, 0, 100, 100, 0, 0, 100, 100, GL_COLOR_BUFFER_BIT, GL_NEAREST); + glFlush(); + + pass &= piglit_probe_pixel_rgb(0, 0, black); + pass &= piglit_probe_pixel_rgb(18, 18, green); + + assert(!glGetError()); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + +void +piglit_init(int argc, char **argv) +{ + GLuint vs, fs; + + piglit_require_vertex_shader(); + piglit_require_fragment_shader(); + + fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_text); + vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_text); + prog = piglit_link_simple_program(vs, fs); + + piglit_LinkProgram(prog); + piglit_link_check_status(prog); + + piglit_UseProgram(prog); +} -- 1.6.0.6