[Piglit] [PATCH 4/4] gles2: add draw-arrays test

Tom Gall tom.gall at linaro.org
Mon Dec 10 07:24:36 PST 2012


Taken from tests/general and modified for OpenGL ES2, this test
creates two different colored squares using color and vertex
arrays both setup via glVertexAttribPointer. While the old test
used glColorMaterial, that's not available in OpenGL ES2 so
what is tested are attribute arrays and their use via shader
scripts.

Signed-off-by: Tom Gall <tom.gall at linaro.org>
---
 tests/all.tests                          |    1 +
 tests/spec/gles-2.0/CMakeLists.gles2.txt |    1 +
 tests/spec/gles-2.0/draw-arrays.c        |  158 ++++++++++++++++++++++++++++++
 3 files changed, 160 insertions(+)
 create mode 100644 tests/spec/gles-2.0/draw-arrays.c

diff --git a/tests/all.tests b/tests/all.tests
index 2a86134..0d0199d 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -2679,6 +2679,7 @@ spec['!OpenGL ES 2.0'] = gles20
 gles20['gles2_sanity_test'] = PlainExecTest(['gles2_sanity_test', '-auto'])
 gles20['gles2_unit_glReadPixels'] = PlainExecTest(['gles2_unit_glReadPixels', '-auto'])
 gles20['gles2_clear_varray-2.0'] = PlainExecTest(['gles2_clear_varray-2.0', '-auto'])
+gles20['gles2_draw_arrays'] = PlainExecTest(['gles2_draw_arrays', '-auto'])
 
 gles30 = Group()
 spec['!OpenGL ES 3.0'] = gles30
diff --git a/tests/spec/gles-2.0/CMakeLists.gles2.txt b/tests/spec/gles-2.0/CMakeLists.gles2.txt
index b8999dd..d96ebec 100644
--- a/tests/spec/gles-2.0/CMakeLists.gles2.txt
+++ b/tests/spec/gles-2.0/CMakeLists.gles2.txt
@@ -13,5 +13,6 @@ link_libraries(
 piglit_add_executable(gles2_sanity_test gles2_sanity_test.c)
 piglit_add_executable(gles2_unit_glReadPixels gles2_unit_glReadPixels.c)
 piglit_add_executable(gles2_clear_varray-2.0 clear-varray-2.0.c)
+piglit_add_executable(gles2_draw_arrays draw-arrays.c)
 
 # vim: ft=cmake:
diff --git a/tests/spec/gles-2.0/draw-arrays.c b/tests/spec/gles-2.0/draw-arrays.c
new file mode 100644
index 0000000..18e3504
--- /dev/null
+++ b/tests/spec/gles-2.0/draw-arrays.c
@@ -0,0 +1,158 @@
+/*
+ * Copyright © 2011 VMware, Inc.
+ * Copyright 2012 Linaro, Inc
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+
+/**
+ * Test glDrawArrays with glVertexAttribPointers for both vertex
+ * and color data. Test draws two different colored triangle fans
+ * using one attrib array for vertex data and one for color data
+ * passed into the vertex shader, with the color data passed
+ * through as a varying value to the fragment shader.
+ *
+ * Modified for OpenGL ES 2.0 by Tom Gall <tom.gall at linaro.org>
+ * originally from tests/general/draw-arrays-glcolormaterial
+ */
+
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_es_version = 20;
+	config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_ALPHA | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+#define DX0 -0.6
+#define DX1 0.6
+
+static GLfloat vertdata[8][3] =
+{
+	{0.5 + DX0, -0.5, 0.0},
+	{0.5 + DX0, 0.5, 0.0},
+	{-0.5 + DX0, 0.5, 0.0},
+	{-0.5 + DX0, -0.5, 0.0},
+	{0.5 + DX1, -0.5, 0.0},
+	{0.5 + DX1,  0.5, 0.0},
+	{-0.5 + DX1,  0.5, 0.0},
+	{-0.5 + DX1, -0.5, 0.0}
+};
+
+static GLfloat colordata[8][4] =
+{
+	{1.0, 0.0, 0.0, 1.0},
+	{1.0, 0.0, 0.0, 1.0},
+	{1.0, 0.0, 0.0, 1.0},
+	{1.0, 0.0, 0.0, 1.0},
+	{0.0, 1.0, 0.0, 1.0},
+	{0.0, 1.0, 0.0, 1.0},
+	{0.0, 1.0, 0.0, 1.0},
+	{0.0, 1.0, 0.0, 1.0}
+};
+
+static const GLfloat red[3] = {1.0f, 0.0f, 0.0f};
+static const GLfloat green[3] = {0.0f, 1.0f, 0.0f};
+
+GLuint prog;
+GLuint frag;
+GLuint vert;
+GLuint vPosition=0;
+GLuint vColor=1;
+
+char vertex_shader[] =
+"attribute vec4 vPosition;\n"
+"attribute vec4 vColor;\n"
+"varying vec4 vVarColor;\n"
+"void main()\n"
+"{\n"
+"	vVarColor = vColor;\n"
+"	gl_Position = vPosition;\n"
+"}";
+
+char fragment_shader[] =
+"precision mediump float;\n"
+"varying vec4 vVarColor;\n"
+"void main()\n"
+"{\n"
+"	gl_FragColor = vVarColor;\n"
+"}";
+
+enum piglit_result
+piglit_display(void)
+{
+	enum piglit_result pass = PIGLIT_PASS;
+
+	glClearColor(0.3, 0.3, 0.3, 1);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+	glDrawArrays(GL_TRIANGLE_FAN, 4, 4);
+
+	if (!piglit_probe_pixel_rgb(piglit_width * 1 / 3,
+		piglit_height / 2, red)) {
+		fprintf(stderr,"red square isn't rendered correct\n");
+		pass = PIGLIT_FAIL;
+	}
+
+	if (!piglit_probe_pixel_rgb(piglit_width * 2 / 3,
+	    piglit_height / 2, green)) {
+		fprintf(stderr,"green square isn't rendered correct\n");
+		pass = PIGLIT_FAIL;
+	}
+
+	return pass;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	prog = glCreateProgram();
+
+	vert=piglit_compile_shader_text(GL_VERTEX_SHADER,vertex_shader);
+	frag=piglit_compile_shader_text(GL_FRAGMENT_SHADER,fragment_shader);
+
+	glAttachShader(prog, vert);
+	glAttachShader(prog, frag);
+
+	glVertexAttribPointer(vPosition,3, GL_FLOAT, GL_FALSE, 0, vertdata);
+	glVertexAttribPointer(vColor,4, GL_FLOAT, GL_FALSE, 0, colordata);
+
+	glEnableVertexAttribArray(vPosition);
+	glEnableVertexAttribArray(vColor);
+
+	glBindAttribLocation(prog, vPosition, "vPosition");
+	glBindAttribLocation(prog, vColor, "vColor");
+
+	glLinkProgram(prog);
+	if (!(piglit_link_check_status(prog))) {
+		piglit_report_result(PIGLIT_FAIL);
+	return;
+	}
+
+	glDeleteShader(vert);
+	glDeleteShader(frag);
+
+	glUseProgram(prog);
+}
-- 
1.7.10.4



More information about the Piglit mailing list