[Piglit] [PATCH] Add utility function piglit_draw_triangle

Brian Paul brianp at vmware.com
Tue Apr 17 11:40:10 PDT 2012


On 04/17/2012 08:16 AM, Anuj Phogat wrote:
> These utility functions to draw triangle would help in testing antialiasing
> and depth related issues.
>
> Signed-off-by: Anuj Phogat<anuj.phogat at gmail.com>
> ---
>   tests/util/piglit-util-gl.c |   59 +++++++++++++++++++++++++++++++++++++++++++
>   tests/util/piglit-util.h    |    4 +++
>   2 files changed, 63 insertions(+), 0 deletions(-)
>
> diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
> index 4270cd6..5aeacad 100644
> --- a/tests/util/piglit-util-gl.c
> +++ b/tests/util/piglit-util-gl.c
> @@ -708,6 +708,65 @@ piglit_escape_exit_key(unsigned char key, int x, int y)
>   }
>
>   /**
> + * Convenience function to draw an axis aligned triangle.
> + */
> +GLvoid
> +piglit_draw_triangle(float x1, float y1, float x2, float y2,
> +		     float x3, float y3)
> +{

This function could be implemented in terms of the other:

       piglit_draw_triangle(0, x1, y1, x2, y2, x3, y3);


> +	float verts[3][4];
> +
> +	verts[0][0] = x1;
> +	verts[0][1] = y1;
> +	verts[0][2] = 0.0;
> +	verts[0][3] = 1.0;
> +	verts[1][0] = x2;
> +	verts[1][1] = y2;
> +	verts[1][2] = 0.0;
> +	verts[1][3] = 1.0;
> +	verts[2][0] = x3;
> +	verts[2][1] = y3;
> +	verts[2][2] = 0.0;
> +	verts[2][3] = 1.0;
> +
> +	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 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;
> +
> +	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 ea35e64..f6758e3 100755
> --- a/tests/util/piglit-util.h
> +++ b/tests/util/piglit-util.h
> @@ -234,6 +234,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,



More information about the Piglit mailing list