[Piglit] [PATCH 01/13] util: Move draw_arrays to a public location

Ian Romanick idr at freedesktop.org
Tue Aug 27 18:45:44 PDT 2013


From: Ian Romanick <ian.d.romanick at intel.com>

Future commits will re-use this code in desktop OpenGL.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Paul Berry <stereotype441 at gmail.com>
Cc: Matt Turner <mattst88 at gmail.com>
---
 tests/util/piglit-util-gl-common.c | 53 +++++++++++++++++++++++++++++++++
 tests/util/piglit-util-gl-common.h |  1 +
 tests/util/piglit-util-gles.c      | 61 +++-----------------------------------
 3 files changed, 58 insertions(+), 57 deletions(-)

diff --git a/tests/util/piglit-util-gl-common.c b/tests/util/piglit-util-gl-common.c
index 7d21d18..b506805 100644
--- a/tests/util/piglit-util-gl-common.c
+++ b/tests/util/piglit-util-gl-common.c
@@ -588,3 +588,56 @@ required_gl_version_from_glsl_version(unsigned glsl_version)
 	default: return 0;
 	}
 }
+
+/**
+ * Call glDrawArrays.  verts is expected to be
+ *
+ *   float verts[4][4];
+ *
+ * if not NULL; tex is expected to be
+ *
+ *   float tex[4][2];
+ *
+ * if not NULL.
+ */
+void
+piglit_draw_rect_from_arrays(const void *verts, const void *tex)
+{
+#if defined(PIGLIT_USE_OPENGL_ES1) || defined(PIGLIT_USE_OPENGL)
+	if (verts) {
+		glVertexPointer(4, GL_FLOAT, 0, verts);
+		glEnableClientState(GL_VERTEX_ARRAY);
+	}
+
+	if (tex) {
+		glTexCoordPointer(2, GL_FLOAT, 0, tex);
+		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+	}
+
+	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+	if (verts)
+		glDisableClientState(GL_VERTEX_ARRAY);
+	if (tex)
+		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+#elif defined(PIGLIT_USE_OPENGL_ES2) ||defined(PIGLIT_USE_OPENGL_ES3)
+	if (verts) {
+		glVertexAttribPointer(PIGLIT_ATTRIB_POS, 4, GL_FLOAT, GL_FALSE, 0, verts);
+		glEnableVertexAttribArray(PIGLIT_ATTRIB_POS);
+	}
+
+	if (tex) {
+		glVertexAttribPointer(PIGLIT_ATTRIB_TEX, 2, GL_FLOAT, GL_FALSE, 0, tex);
+		glEnableVertexAttribArray(PIGLIT_ATTRIB_TEX);
+	}
+
+	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+	if (verts)
+		glDisableVertexAttribArray(PIGLIT_ATTRIB_POS);
+	if (tex)
+		glDisableVertexAttribArray(PIGLIT_ATTRIB_TEX);
+#else
+#	error "don't know how to draw arrays"
+#endif
+}
diff --git a/tests/util/piglit-util-gl-common.h b/tests/util/piglit-util-gl-common.h
index 0078041..ef87514 100644
--- a/tests/util/piglit-util-gl-common.h
+++ b/tests/util/piglit-util-gl-common.h
@@ -162,6 +162,7 @@ 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);
 
 unsigned short piglit_half_from_float(float val);
 
diff --git a/tests/util/piglit-util-gles.c b/tests/util/piglit-util-gles.c
index 385e65e..57b0aa6 100644
--- a/tests/util/piglit-util-gles.c
+++ b/tests/util/piglit-util-gles.c
@@ -175,59 +175,6 @@ piglit_escape_exit_key(unsigned char key, int x, int y)
 }
 
 /**
- * Call glDrawArrays.  verts is expected to be
- *
- *   float verts[4][4];
- *
- * if not NULL; tex is expected to be
- *
- *   float tex[4][2];
- *
- * if not NULL.
- */
-static void
-draw_arrays(const GLvoid *verts, const GLvoid *tex)
-{
-#if defined(PIGLIT_USE_OPENGL_ES1)
-	if (verts) {
-		glVertexPointer(4, GL_FLOAT, 0, verts);
-		glEnableClientState(GL_VERTEX_ARRAY);
-	}
-
-	if (tex) {
-		glTexCoordPointer(2, GL_FLOAT, 0, tex);
-		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-	}
-
-	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
-	if (verts)
-		glDisableClientState(GL_VERTEX_ARRAY);
-	if (tex)
-		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-#elif defined(PIGLIT_USE_OPENGL_ES2) ||defined(PIGLIT_USE_OPENGL_ES3)
-	if (verts) {
-		glVertexAttribPointer(PIGLIT_ATTRIB_POS, 4, GL_FLOAT, GL_FALSE, 0, verts);
-		glEnableVertexAttribArray(PIGLIT_ATTRIB_POS);
-	}
-
-	if (tex) {
-		glVertexAttribPointer(PIGLIT_ATTRIB_TEX, 2, GL_FLOAT, GL_FALSE, 0, tex);
-		glEnableVertexAttribArray(PIGLIT_ATTRIB_TEX);
-	}
-
-	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
-	if (verts)
-		glDisableVertexAttribArray(PIGLIT_ATTRIB_POS);
-	if (tex)
-		glDisableVertexAttribArray(PIGLIT_ATTRIB_TEX);
-#else
-#	error "don't know how to draw arrays"
-#endif
-}
-
-/**
  * Convenience function to draw an axis-aligned rectangle.
  */
 GLvoid
@@ -252,7 +199,7 @@ piglit_draw_rect(float x, float y, float w, float h)
 	verts[3][2] = 0.0;
 	verts[3][3] = 1.0;
 
-	draw_arrays(verts, NULL);
+	piglit_draw_rect_from_arrays(verts, NULL);
 }
 
 
@@ -281,7 +228,7 @@ piglit_draw_rect_back(float x, float y, float w, float h)
 	verts[3][2] = 0.0;
 	verts[3][3] = 1.0;
 
-	draw_arrays(verts, NULL);
+	piglit_draw_rect_from_arrays(verts, NULL);
 }
 
 
@@ -310,7 +257,7 @@ piglit_draw_rect_z(float z, float x, float y, float w, float h)
 	verts[3][2] = z;
 	verts[3][3] = 1.0;
 
-	draw_arrays(verts, NULL);
+	piglit_draw_rect_from_arrays(verts, NULL);
 }
 
 /**
@@ -349,7 +296,7 @@ piglit_draw_rect_tex(float x, float y, float w, float h,
 	tex[3][0] = tx + tw;
 	tex[3][1] = ty + th;
 
-	draw_arrays(verts, tex);
+	piglit_draw_rect_from_arrays(verts, tex);
 }
 
 /**
-- 
1.8.1.4



More information about the Piglit mailing list