[Piglit] [PATCH 2/3] glsl-1.30: Add test for clip distance

Chad Versace chad at chad-versace.us
Fri Jun 17 18:09:33 PDT 2011


On Sun, 12 Jun 2011 10:43:26 -0700, Paul Berry <stereotype441 at gmail.com> wrote:
> Test all 6 elements of gl_ClipDistance[] by creating custom clip
> planes that chop a rectangle into a hexagon, and then probe to verify
> the hexagon's shape.
> ---
>  .../execution/vs-clip-distance-01.shader_test      |   54 ++++++++++++++++++++
>  1 files changed, 54 insertions(+), 0 deletions(-)
>  create mode 100644 tests/spec/glsl-1.30/execution/vs-clip-distance-01.shader_test
> 
> diff --git a/tests/spec/glsl-1.30/execution/vs-clip-distance-01.shader_test b/tests/spec/glsl-1.30/execution/vs-clip-distance-01.shader_test
> new file mode 100644
> index 0000000..2bc30b2
> --- /dev/null
> +++ b/tests/spec/glsl-1.30/execution/vs-clip-distance-01.shader_test
> @@ -0,0 +1,54 @@
> +# [description]
> +# Use all 6 gl_ClipDistance values to clip a rectangle to a hexagon shape.
> +
> +[require]
> +GLSL >= 1.30
> +
> +[vertex shader]
> +#version 130
> +void main(void)
> +{
> +  // Default coordinate system runs from (-1,-1) to (1,1).  Translate
> +  // to a coordinate system that runs from (0,0) to (1,1) to conform
> +  // with the behavior of "relative probe".
> +  gl_Position = gl_Vertex - vec4(0.5, 0.5, 0, 0.5);

The transformation doesn't do what the comments say. The transformation
performs this, modulo the homogeneous coordinate:

[-1, -1,  0,  1] => [-3, -3,  0,  1]
[ 0,  0,  0,  1] => [-1, -1,  0,  1]
[ 1,  1,  0,  1] => [ 1,  1,  0,  1]

I think you want this:
const mat4 mvp = mat4(0.5, 0.0, 0.0, 0.5,
                      0.0, 0.5, 0.0, 0.5,
                      0.0, 0.0, 1.0, 0.0,
                      0.0, 0.0, 0.0, 1.0);
gl_Position = mvp * gl_Vertex;


Rather than doing the transformation explicitly in the shader, the best
way to do this is to let 'ortho' be the first command in the [test]
section, and set 'gl_Position = gl_ModelViewProjectionMatrix *
gl_Vertex'.

Oh, and a formatting nitpick. Piglit uses 8-tab indent. Not all of
Piglit conforms to that, but we should at least try to make all new
additions do so. (I despise tabs myself, and have been guilty of using
4-space indents in Piglit in the past \o/ ).

> +
> +  gl_ClipDistance[0] = gl_Vertex.y - 0.25;
> +  gl_ClipDistance[1] = gl_Vertex.y - gl_Vertex.x + 0.4;
> +  gl_ClipDistance[2] = 1.4 - gl_Vertex.x - gl_Vertex.y;
> +  gl_ClipDistance[3] = 0.75 - gl_Vertex.y;
> +  gl_ClipDistance[4] = gl_Vertex.x - gl_Vertex.y + 0.4;
> +  gl_ClipDistance[5] = gl_Vertex.x + gl_Vertex.y - 0.6;
> +}
> +
> +[fragment shader]
> +#version 130
> +void main(void)
> +{
> +  gl_FragColor = vec4(1, 1, 1, 1);
> +}
> +
> +[test]
> +enable GL_CLIP_PLANE0
> +enable GL_CLIP_PLANE1
> +enable GL_CLIP_PLANE2
> +enable GL_CLIP_PLANE3
> +enable GL_CLIP_PLANE4
> +enable GL_CLIP_PLANE5
> +draw rect 0.1 0.1 0.8 0.8
> +
> +# Test points inside each hexagon edge
> +relative probe rgba (0.3, 0.4) (1.0, 1.0, 1.0, 1.0)
> +relative probe rgba (0.5, 0.3) (1.0, 1.0, 1.0, 1.0)
> +relative probe rgba (0.7, 0.4) (1.0, 1.0, 1.0, 1.0)
> +relative probe rgba (0.7, 0.6) (1.0, 1.0, 1.0, 1.0)
> +relative probe rgba (0.5, 0.7) (1.0, 1.0, 1.0, 1.0)
> +relative probe rgba (0.3, 0.6) (1.0, 1.0, 1.0, 1.0)
> +
> +# Test points outside each hexagon edge
> +relative probe rgba (0.2, 0.3) (0.0, 0.0, 0.0, 0.0)
> +relative probe rgba (0.5, 0.2) (0.0, 0.0, 0.0, 0.0)
> +relative probe rgba (0.8, 0.3) (0.0, 0.0, 0.0, 0.0)
> +relative probe rgba (0.8, 0.7) (0.0, 0.0, 0.0, 0.0)
> +relative probe rgba (0.5, 0.8) (0.0, 0.0, 0.0, 0.0)
> +relative probe rgba (0.2, 0.7) (0.0, 0.0, 0.0, 0.0)
> -- 
> 1.7.5.2
> 
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit


More information about the Piglit mailing list