[Piglit] [PATCH 3/4] gles2: port clear-varray-2.0
Tom Gall
tom.gall at linaro.org
Mon Dec 10 07:24:35 PST 2012
Port testcase clear-varray-2.0 from tests/general into
tests/spec/gles-2.0 and update substantially for OpenGL ES 2.0.
Test checks that glClear and vertex attributes via
glVertexAttribPointer work correctly together.
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/clear-varray-2.0.c | 156 ++++++++++++++++++++++++++++++
3 files changed, 158 insertions(+)
create mode 100644 tests/spec/gles-2.0/clear-varray-2.0.c
diff --git a/tests/all.tests b/tests/all.tests
index 7dd3b0a..2a86134 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -2678,6 +2678,7 @@ gles20 = Group()
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'])
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 be4e59f..b8999dd 100644
--- a/tests/spec/gles-2.0/CMakeLists.gles2.txt
+++ b/tests/spec/gles-2.0/CMakeLists.gles2.txt
@@ -12,5 +12,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)
# vim: ft=cmake:
diff --git a/tests/spec/gles-2.0/clear-varray-2.0.c b/tests/spec/gles-2.0/clear-varray-2.0.c
new file mode 100644
index 0000000..2c359bc
--- /dev/null
+++ b/tests/spec/gles-2.0/clear-varray-2.0.c
@@ -0,0 +1,156 @@
+/*
+ * Copyright © 2009 Intel Corporation
+ *
+ * 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.
+ *
+ * Authors:
+ * Eric Anholt <eric at anholt.net>
+ * Modified for OpenGL ES 2.0
+ * Tom Gall <tom.gall at linaro.org>
+ */
+
+/** @file clear-varray-2.0.c
+ *
+ * Tests that enabling 2.0's vertex attributes doesn't interfere with glClear.
+ *
+ * fd.o bug #21638
+ */
+
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_es_version = 20;
+ config.requires_displayed_window = true;
+
+ config.window_width = 200;
+ config.window_height = 100;
+ config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_DEPTH;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+/* apply MVP and set the color to blue. */
+static const GLchar *const vp_code =
+"mat4 projectionMatrix = mat4(1.0/100.0, 0.0, 0.0, -1.0,\n"
+" 0.0, 4.0/200.0, 0.0, -1.0,\n"
+" 0.0, 0.0, -1.0, 0.0,\n"
+" 0.0, 0.0, 0.0, 1.0);\n"
+"attribute vec4 vPosition;\n"
+"void main()\n"
+"{\n"
+" gl_Position = vPosition;\n"
+" gl_Position *= projectionMatrix;\n"
+"}";
+
+static const GLchar *const fp_code =
+"precision mediump float;\n"
+"void main()\n"
+"{\n"
+" gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);\n"
+"}";
+
+enum piglit_result
+piglit_display(void)
+{
+ float vertices[4][4];
+ int i;
+ float green[4] = {0, 1, 0, 0};
+ float blue[4] = {0, 0, 1, 0};
+
+ vertices[0][0] = 10;
+ vertices[0][1] = 10;
+ vertices[0][2] = 0;
+ vertices[0][3] = 1;
+
+ vertices[1][0] = 20;
+ vertices[1][1] = 10;
+ vertices[1][2] = 0;
+ vertices[1][3] = 1;
+
+ vertices[2][0] = 20;
+ vertices[2][1] = 20;
+ vertices[2][2] = 0;
+ vertices[2][3] = 1;
+
+ vertices[3][0] = 10;
+ vertices[3][1] = 20;
+ vertices[3][2] = 0;
+ vertices[3][3] = 1;
+
+ /* Clear red. */
+ glClearColor(1.0, 0.0, 0.0, 0.0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ /* Draw a blue rect at (10,10)-(20,20) */
+ glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float),
+ vertices);
+ glEnableVertexAttribArray(0);
+
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+ /* Clear everything to green. Note that we left the attr enabled*/
+ glClearColor(0.0, 1.0, 0.0, 0.0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ /* Draw a blue rect at (30,10)-(40,20) */
+ for (i = 0; i < 4; i++)
+ vertices[i][0] += 20;
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+ /* The second clear should have made everything green. */
+ if (!piglit_probe_pixel_rgb(30, 30, green))
+ return PIGLIT_FAIL;
+ if (!piglit_probe_pixel_rgb(15, 15, green))
+ return PIGLIT_FAIL;
+ if (!piglit_probe_pixel_rgb(35, 15, blue))
+ return PIGLIT_FAIL;
+
+ return PIGLIT_PASS;
+}
+
+static void reshape(int width, int height)
+{
+ glViewport(0, 0, width, height);
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ GLuint vert_prog, frag_prog, prog;
+
+ prog = glCreateProgram();
+ vert_prog=piglit_compile_shader_text(GL_VERTEX_SHADER,vp_code);
+ frag_prog=piglit_compile_shader_text(GL_FRAGMENT_SHADER,fp_code);
+
+ glAttachShader(prog, vert_prog);
+ glAttachShader(prog, frag_prog);
+
+ glLinkProgram(prog);
+ if (!(piglit_link_check_status(prog))) {
+ piglit_report_result(PIGLIT_FAIL);
+ return;
+ }
+
+ reshape(piglit_width, piglit_height);
+ glDeleteShader(vert_prog);
+ glDeleteShader(frag_prog);
+
+ glUseProgram(prog);
+}
--
1.7.10.4
More information about the Piglit
mailing list