[Piglit] [PATCH 1/2] Geometry shaders: Test gl_ClipDistance input (GLSL 1.50)
Fabian Bieler
fabianbieler at fastmail.fm
Wed Jun 12 02:29:04 PDT 2013
On 2013-06-12 01:50, Paul Berry wrote:
> This patch adds piglit tests to ensure that gl_ClipDistance works
> properly as a geometry shader input.
[...]
> +in gl_PerVertex {
> + float gl_ClipDistance[2];
> +} gl_in[];
I'm not sure if it's ok to leave out members when redeclaring built-in interface blocks (gl_Position and gl_PointSize in this case). I didn't find anything on this in the spec but a quick google search indicates it's common practice so it should probably be ok.
[...]
> diff --git a/tests/spec/glsl-1.50/execution/geometry/clip-distance-bulk-copy.shader_test b/tests/spec/glsl-1.50/execution/geometry/clip-distance-bulk-copy.shader_test
> new file mode 100644
> index 0000000..fbdee46
> --- /dev/null
> +++ b/tests/spec/glsl-1.50/execution/geometry/clip-distance-bulk-copy.shader_test
> @@ -0,0 +1,93 @@
> +# This test checks that the geometry shader can perform a bulk copy of
> +# the entire gl_ClipDistance array from input to output.
> +
> +[require]
> +GL >= 2.0
Up to version 3.0 OpenGL only mandates the support of up to 6 user defined clip planes/distances. The version requirement should probably be bumped to 3.1 or only 6 clip distances should be used. This also applies to the same test in the next patch of the series.
> +GLSL >= 1.50
> +
> +[vertex shader]
> +#version 150
> +
> +in vec4 vertex;
> +in float offset;
> +out float offset_to_gs;
> +out float gl_ClipDistance[8];
Shouldn't gl_ClipDistance be redeclared inside the gl_PerVertex interface block? I know the spec allows redeclaring gl_TexCoord at global scope in the compatibility profile but it explicitly states:
"This treatment is a special case for gl_TexCoord[], not a general method for redeclaring members of blocks." (glsl spec v1.5 page 79 (page 85 of the PDF)).
> +
> +void main()
> +{
> + gl_Position = vertex;
> + offset_to_gs = offset;
> + for (int i = 0; i < 8; i++) {
> + gl_ClipDistance[i] = offset + float(i);
> + }
> +}
> +
> +[geometry shader]
> +#version 150
> +
> +layout(triangles) in;
> +layout(triangle_strip, max_vertices = 3) out;
> +
> +in float offset_to_gs[3];
> +in gl_PerVertex {
> + vec4 gl_Position;
> + float gl_ClipDistance[8];
> +} gl_in[];
> +out float offset_to_fs;
> +out gl_PerVertex {
> + vec4 gl_Position;
> + float gl_ClipDistance[8];
> +};
> +
> +void main()
> +{
> + bool ok = true;
> + for (int i = 0; i < 3; i++) {
> + gl_Position = gl_in[i].gl_Position;
> + gl_ClipDistance = gl_in[i].gl_ClipDistance;
> + offset_to_fs = offset_to_gs[i];
> + EmitVertex();
> + }
> +}
> +
> +[fragment shader]
> +#version 150
> +
> +in float gl_ClipDistance[8];
> +in float offset_to_fs;
> +
> +void main()
> +{
> + bool ok = true;
> + for (int i = 0; i < 8; i++) {
> + if (distance(gl_ClipDistance[i], offset_to_fs + float(i)) > 1e-6)
> + ok = false;
> + }
> + if (ok)
> + gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
> + else
> + gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
> +}
> +
> +[vertex data]
> +vertex/float/2 offset/float/1
> +-1.0 -1.0 1.0
> + 1.0 -1.0 2.0
> + 1.0 1.0 3.0
> +-1.0 1.0 4.0
> +
> +[test]
> +# Since the fragment shader's gl_ClipDistance array is only defined
> +# for elements that have clipping enabled, we need to enable all 8
> +# clip planes. Fortunately the values we use for gl_ClipDistance are
> +# always positive, so no pixels are actually clipped.
> +enable GL_CLIP_PLANE0
> +enable GL_CLIP_PLANE1
> +enable GL_CLIP_PLANE2
> +enable GL_CLIP_PLANE3
> +enable GL_CLIP_PLANE4
> +enable GL_CLIP_PLANE5
> +enable GL_CLIP_PLANE6
> +enable GL_CLIP_PLANE7
> +draw arrays GL_TRIANGLE_FAN 0 4
> +probe all rgba 0.0 1.0 0.0 1.0
[...]
Otherwise, the series looks good to me.
Fabian
More information about the Piglit
mailing list