[Piglit] [PATCH] [v3] Add test case of render FBO with point coordinate.

Yuanhan Liu yuanhan.liu at linux.intel.com
Thu Feb 9 01:52:15 PST 2012


On Thu, Feb 09, 2012 at 03:51:57PM +0800, Jian Zhao wrote:
> 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."
> 
> v2: To simplify the case, set the point size in the program instead of the
> shader. (per Yuanhan's suggestion)
> 
> v3: Put the case in the fbo directory, move the FBO setup code into
> piglit_init and will not draw it to the screen when run with '-auto'
> option. (per Ian's suggestion)
> 
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=44613
> Signed-off-by: Jian Zhao <jian.j.zhao at intel.com>
> ---
>  tests/all.tests               |    1 +
>  tests/fbo/CMakeLists.gl.txt   |    1 +
>  tests/fbo/fbo-gl_pointcoord.c |  112 +++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 114 insertions(+), 0 deletions(-)
>  create mode 100644 tests/fbo/fbo-gl_pointcoord.c
> 
> diff --git a/tests/all.tests b/tests/all.tests
> index 3424578..38a067b 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -191,6 +191,7 @@ add_plain_test(fbo, 'fbo-generatemipmap-nonsquare')
>  add_plain_test(fbo, 'fbo-generatemipmap-npot')
>  add_plain_test(fbo, 'fbo-generatemipmap-viewport')
>  add_plain_test(fbo, 'fbo-getframebufferattachmentparameter-01')
> +add_plain_test(fbo, 'fbo-gl_pointcoord')
>  add_plain_test(fbo, 'fbo-incomplete-texture-01')
>  add_plain_test(fbo, 'fbo-incomplete-texture-02')
>  add_plain_test(fbo, 'fbo-incomplete-texture-03')
> diff --git a/tests/fbo/CMakeLists.gl.txt b/tests/fbo/CMakeLists.gl.txt
> index 6b5e32c..f355144 100644
> --- a/tests/fbo/CMakeLists.gl.txt
> +++ b/tests/fbo/CMakeLists.gl.txt
> @@ -59,6 +59,7 @@ add_executable (fbo-generatemipmap-nonsquare fbo-generatemipmap-nonsquare.c)
>  add_executable (fbo-generatemipmap-npot fbo-generatemipmap-npot.c)
>  add_executable (fbo-generatemipmap-viewport fbo-generatemipmap-viewport.c)
>  add_executable (fbo-getframebufferattachmentparameter-01 fbo-getframebufferattachmentparameter-01.c)
> +add_executable (fbo-gl_pointcoord fbo-gl_pointcoord.c)
>  add_executable (fbo-incomplete-texture-01 fbo-incomplete-texture-01.c)
>  add_executable (fbo-incomplete-texture-02 fbo-incomplete-texture-02.c)
>  add_executable (fbo-incomplete-texture-03 fbo-incomplete-texture-03.c)
> diff --git a/tests/fbo/fbo-gl_pointcoord.c b/tests/fbo/fbo-gl_pointcoord.c
> new file mode 100644
> index 0000000..8db6ad4
> --- /dev/null
> +++ b/tests/fbo/fbo-gl_pointcoord.c
> @@ -0,0 +1,112 @@
> +/*
> + * 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.
> + *
> + *
> + */
> +
> +/**
> + * \file pointcoord.c
> + * Verify that applications can use point coordinate correctly 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"
> +	"void main()\n"
> +	"{\n"
> +	"gl_Position = gl_Vertex;\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 GLuint fb, rb;
> +
> +static const float green[] = { 0.0, 1.0, 0.0, 1.0 };
> +static const float black[] = { 0.0, 0.0, 0.0, 1.0 };
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +	GLboolean pass = GL_TRUE;
> +
> +	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_READ_FRAMEBUFFER, fb);
> +	pass = piglit_probe_pixel_rgb(0, 0, black) && pass;
> +	pass = piglit_probe_pixel_rgb(18, 18, green) && pass;
> +	pass = piglit_probe_pixel_rgb(18, 81, black) && pass;
> +
> +	/* Draw the point out if want to have a look. */
> +	if (!piglit_automatic){
> +		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
> +		glBlitFramebuffer(0, 0, 100, 100, 0, 0, 100, 100, GL_COLOR_BUFFER_BIT, GL_NEAREST);
> +		glFlush();
You are using double buffer, so it should be glutSwapBuffers().

Besides that, looks good to me, and:

Reviewed-by: Yuanhan Liu <yuanhan.liu at linux.intel.com>


Thanks,
Yuanhan Liu
> +	}
> +
> +
> +	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
> +
> +	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +	GLuint vs, fs;
> +	int PointSize = 64;
> +
> +	piglit_require_extension("GL_ARB_point_sprite");
> +	piglit_require_extension("GL_ARB_framebuffer_object");
> +
> +	glEnable(GL_POINT_SPRITE_ARB);
> +	glPointSize(PointSize);
> +
> +	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_UseProgram(prog);
> +
> +	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);
> +}
> -- 
> 1.7.0.1


More information about the Piglit mailing list