[Piglit] [PATCH 06/13] shader_runner: add "draw rect patch" to draw rectangles as patches

Marek Olšák maraeo at gmail.com
Mon Apr 6 16:39:55 PDT 2015


From: Marek Olšák <marek.olsak at amd.com>

The only allowed primitive type with tessellation is GL_PATCHES, so this is
the only way to draw rectangles.
---
 tests/shaders/shader_runner.c |  4 ++++
 tests/util/piglit-util-gl.c   | 22 ++++++++++++++++------
 tests/util/piglit-util-gl.h   |  5 ++++-
 3 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c
index 20eb26c..dcb9c3e 100644
--- a/tests/shaders/shader_runner.c
+++ b/tests/shaders/shader_runner.c
@@ -2303,6 +2303,10 @@ piglit_display(void)
 			get_floats(line + 13, c, 8);
 			piglit_draw_rect_tex(c[0], c[1], c[2], c[3],
 					     c[4], c[5], c[6], c[7]);
+		} else if (string_match("draw rect patch", line)) {
+			program_must_be_in_use();
+			get_floats(line + 15, c, 4);
+			piglit_draw_rect_custom(c[0], c[1], c[2], c[3], true);
 		} else if (string_match("draw rect", line)) {
 			program_must_be_in_use();
 			get_floats(line + 9, c, 4);
diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index aae6df0..131f63e 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -656,7 +656,8 @@ required_gl_version_from_glsl_version(unsigned glsl_version)
  * if not NULL.
  */
 void
-piglit_draw_rect_from_arrays(const void *verts, const void *tex)
+piglit_draw_rect_from_arrays(const void *verts, const void *tex,
+			     bool use_patches)
 {
 	bool use_fixed_function_attributes;
 
@@ -754,7 +755,7 @@ piglit_draw_rect_from_arrays(const void *verts, const void *tex)
 			glEnableVertexAttribArray(PIGLIT_ATTRIB_TEX);
 		}
 
-		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+		glDrawArrays(use_patches ? GL_PATCHES : GL_TRIANGLE_STRIP, 0, 4);
 
 		if (verts)
 			glDisableVertexAttribArray(PIGLIT_ATTRIB_POS);
@@ -775,7 +776,7 @@ piglit_draw_rect_from_arrays(const void *verts, const void *tex)
  * Convenience function to draw an axis-aligned rectangle.
  */
 GLvoid
-piglit_draw_rect(float x, float y, float w, float h)
+piglit_draw_rect_custom(float x, float y, float w, float h, bool use_patches)
 {
 	float verts[4][4];
 
@@ -796,7 +797,16 @@ piglit_draw_rect(float x, float y, float w, float h)
 	verts[3][2] = 0.0;
 	verts[3][3] = 1.0;
 
-	piglit_draw_rect_from_arrays(verts, NULL);
+	piglit_draw_rect_from_arrays(verts, NULL, use_patches);
+}
+
+/**
+ * Convenience function to draw an axis-aligned rectangle.
+ */
+GLvoid
+piglit_draw_rect(float x, float y, float w, float h)
+{
+	piglit_draw_rect_custom(x, y, w, h, false);
 }
 
 /**
@@ -824,7 +834,7 @@ piglit_draw_rect_z(float z, float x, float y, float w, float h)
 	verts[3][2] = z;
 	verts[3][3] = 1.0;
 
-	piglit_draw_rect_from_arrays(verts, NULL);
+	piglit_draw_rect_from_arrays(verts, NULL, false);
 }
 
 /**
@@ -863,7 +873,7 @@ piglit_draw_rect_tex(float x, float y, float w, float h,
 	tex[3][0] = tx + tw;
 	tex[3][1] = ty + th;
 
-	piglit_draw_rect_from_arrays(verts, tex);
+	piglit_draw_rect_from_arrays(verts, tex, false);
 }
 
 unsigned
diff --git a/tests/util/piglit-util-gl.h b/tests/util/piglit-util-gl.h
index 0f8eb81..2196e2c 100644
--- a/tests/util/piglit-util-gl.h
+++ b/tests/util/piglit-util-gl.h
@@ -175,12 +175,15 @@ 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_custom(float x, float y, float w, float h,
+			       bool use_patches);
 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,
                             float tx, float ty, float tw, float th);
 GLvoid piglit_draw_rect_back(float x, float y, float w, float h);
-void piglit_draw_rect_from_arrays(const void *verts, const void *tex);
+void piglit_draw_rect_from_arrays(const void *verts, const void *tex,
+				  bool use_patches);
 
 unsigned short piglit_half_from_float(float val);
 
-- 
2.1.0



More information about the Piglit mailing list