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

Tom Gall tom.gall at linaro.org
Sun Dec 2 04:55:41 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
instead attributes and shader scripts are used.

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

diff --git a/tests/all_es2.tests b/tests/all_es2.tests
index 3ac932b..abeb40f 100644
--- a/tests/all_es2.tests
+++ b/tests/all_es2.tests
@@ -26,5 +26,6 @@ spec['gles2_tests'] = gles2_tests
 gles2_tests['gles2_sanity_test'] = PlainExecTest(['gles2_sanity_test', '-auto'])
 gles2_tests['gles2_unit_glReadPixels'] = PlainExecTest(['gles2_unit_glReadPixels', '-auto'])
 gles2_tests['gles2_clear_varray-2.0'] = PlainExecTest(['gles2_clear_varray-2.0', '-auto'])
+gles2_tests['gles2_draw_arrays_colormaterial'] = PlainExecTest(['gles2_draw_arrays_colormaterial', '-auto'])
 
 profile.tests['spec'] = spec
diff --git a/tests/spec/gles-2.0/CMakeLists.gles2.txt b/tests/spec/gles-2.0/CMakeLists.gles2.txt
index b8999dd..87f96db 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_colormaterial draw-arrays-colormaterial.c)
 
 # vim: ft=cmake:
diff --git a/tests/spec/gles-2.0/draw-arrays-colormaterial.c b/tests/spec/gles-2.0/draw-arrays-colormaterial.c
new file mode 100644
index 0000000..b6c8fdd
--- /dev/null
+++ b/tests/spec/gles-2.0/draw-arrays-colormaterial.c
@@ -0,0 +1,155 @@
+/*
+ * 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 glVertexAttribPointer for both vertex
+ * and color data.
+ *
+ * Adapted for OpenGL ES 2.0 by Tom Gall <tom.gall at linaro.org>
+ */
+
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_es2 = true;
+
+	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