[Piglit] [PATCH 1/4] glsl-1.50 gs: Test two sided triangles.

Fabian Bieler fabianbieler at fastmail.fm
Mon Mar 3 00:38:24 PST 2014


Consider 8 triangles on the screen like so:

    +-+-+
    |/|/|
    +-+-+
    |/|/|
    +-+-+

Draw the left 4 triangles front-facing, the right 4 triangles back-facing.
Flip the top 4 triangles in the geometry shader (swap the first and last
vertex). In the fragment shader write different colors according to
gl_FrontFacing. The result should be a 2x2 checkerboard.

Signed-off-by: Fabian Bieler <fabianbieler at fastmail.fm>
---
 .../execution/geometry/two-side.shader_test        | 86 ++++++++++++++++++++++
 1 file changed, 86 insertions(+)
 create mode 100644 tests/spec/glsl-1.50/execution/geometry/two-side.shader_test

diff --git a/tests/spec/glsl-1.50/execution/geometry/two-side.shader_test b/tests/spec/glsl-1.50/execution/geometry/two-side.shader_test
new file mode 100644
index 0000000..8afd239
--- /dev/null
+++ b/tests/spec/glsl-1.50/execution/geometry/two-side.shader_test
@@ -0,0 +1,86 @@
+# Consider 8 triangles on the screen like so:
+#
+#     +-+-+
+#     |/|/|
+#     +-+-+
+#     |/|/|
+#     +-+-+
+#
+# Draw the left 4 triangles front-facing, the right 4 triangles back-facing.
+# Flip the top 4 triangles in the geometry shader (swap the first and last
+# vertex). In the fragment shader write different colors according to
+# gl_FrontFacing. The result should be a 2x2 checkerboard.
+[require]
+GL >= 3.2
+GLSL >= 1.50
+
+[vertex shader]
+attribute vec4 vertex;
+
+void main()
+{
+	gl_Position = vertex;
+}
+
+[geometry shader]
+layout(triangles) in;
+layout(triangle_strip, max_vertices = 3) out;
+
+void main()
+{
+	float y = gl_in[0].gl_Position.y + gl_in[1].gl_Position.y +
+		  gl_in[2].gl_Position.y;
+	for (int i = 0; i < 3; i++) {
+		/* Flip the triangles in the upper half of the screen. */
+		if (y > 0.0)
+			gl_Position = gl_in[2 - i].gl_Position;
+		else
+			gl_Position = gl_in[i].gl_Position;
+		EmitVertex();
+	}
+}
+
+[fragment shader]
+void main()
+{
+	if (gl_FrontFacing)
+		gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
+	else
+		gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);
+}
+
+[vertex data]
+vertex/float/2
+-1.0 -1.0
+ 0.0 -1.0
+ 0.0  0.0
+-1.0 -1.0
+ 0.0  0.0
+-1.0  0.0
+ 0.0 -1.0
+ 0.0  0.0
+ 1.0  0.0
+ 0.0 -1.0
+ 1.0  0.0
+ 1.0 -1.0
+-1.0  0.0
+ 0.0  0.0
+ 0.0  1.0
+-1.0  0.0
+ 0.0  1.0
+-1.0  1.0
+ 0.0  0.0
+ 0.0  1.0
+ 1.0  1.0
+ 0.0  0.0
+ 1.0  1.0
+ 1.0  0.0
+
+
+[test]
+enable GL_VERTEX_PROGRAM_TWO_SIDE
+draw arrays GL_TRIANGLES 0 24
+relative probe rgba (0.25, 0.25) (0.0, 1.0, 0.0, 1.0)
+relative probe rgba (0.75, 0.25) (0.0, 0.0, 1.0, 1.0)
+relative probe rgba (0.25, 0.75) (0.0, 0.0, 1.0, 1.0)
+relative probe rgba (0.75, 0.75) (0.0, 1.0, 0.0, 1.0)
-- 
1.8.3.2



More information about the Piglit mailing list