[Piglit] [PATCH] Add utility function piglit_draw_triangle
Brian Paul
brianp at vmware.com
Wed Apr 18 07:24:09 PDT 2012
On 04/18/2012 02:25 AM, Anuj Phogat wrote:
> These utility functions to draw triangle would help in testing antialiasing
> and depth related issues.
>
> v2: Defined piglit_draw_triangle in terms of piglit_draw_triangle_z. Modified
> the comments
>
> Signed-off-by: Anuj Phogat<anuj.phogat at gmail.com>
> ---
> tests/util/piglit-util-gl.c | 40 ++++++++++++++++++++++++++++++++++++++++
> tests/util/piglit-util.h | 4 ++++
> 2 files changed, 44 insertions(+), 0 deletions(-)
>
> diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
> index 4270cd6..69366ad 100644
> --- a/tests/util/piglit-util-gl.c
> +++ b/tests/util/piglit-util-gl.c
> @@ -708,6 +708,46 @@ piglit_escape_exit_key(unsigned char key, int x, int y)
> }
>
> /**
> + * Convenience function to draw a triangle.
> + */
> +GLvoid
> +piglit_draw_triangle(float x1, float y1, float x2, float y2,
> + float x3, float y3)
> +{
> + piglit_draw_triangle_z(0.0, x1, y1, x2, y2, x3, y3);
> +}
> +
> +/**
> + * Convenience function to draw a triangle at a given depth.
> + */
> +GLvoid
> +piglit_draw_triangle_z(float z, float x1, float y1, float x2, float y2,
> + float x3, float y3)
> +{
> + float verts[3][4];
> +
> + verts[0][0] = x1;
> + verts[0][1] = y1;
> + verts[0][2] = z;
> + verts[0][3] = 1.0;
> + verts[1][0] = x2;
> + verts[1][1] = y2;
> + verts[1][2] = z;
> + verts[1][3] = 1.0;
> + verts[2][0] = x3;
> + verts[2][1] = y3;
> + verts[2][2] = z;
> + verts[2][3] = 1.0;
You could probably use a verts[3][3] array since all your W=1 but it's
not a big deal.
> +
> + glVertexPointer(4, GL_FLOAT, 0, verts);
> + glEnableClientState(GL_VERTEX_ARRAY);
> +
> + glDrawArrays(GL_TRIANGLES, 0, 3);
> +
> + glDisableClientState(GL_VERTEX_ARRAY);
> +}
> +
> +/**
> * Convenience function to draw an axis-aligned rectangle.
> */
> GLvoid
> diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
> index 917d798..8ee37d8 100755
> --- a/tests/util/piglit-util.h
> +++ b/tests/util/piglit-util.h
> @@ -232,6 +232,10 @@ int piglit_use_vertex_program(void);
> void piglit_require_fragment_program(void);
> void piglit_require_vertex_program(void);
> GLuint piglit_compile_program(GLenum target, const char* text);
> +GLvoid piglit_draw_triangle(float x1, float y1, float x2, float y2,
> + float x3, float y3);
> +GLvoid piglit_draw_triangle_z(float z, float x1, float y1, float x2, float y2,
> + float x3, float y3);
> GLvoid piglit_draw_rect(float x, float y, float w, float h);
> GLvoid piglit_draw_rect_z(float z, float x, float y, float w, float h);
> GLvoid piglit_draw_rect_tex(float x, float y, float w, float h,
Reviewed-by: Brian Paul <brianp at vmware.com>
More information about the Piglit
mailing list