[Piglit] [PATCH 1/1] gles2: new test to render triangle and validate via glReadPixels

Tom Gall tom.gall at linaro.org
Fri Nov 23 13:59:34 PST 2012


new gles2 test which very simply renders a triangle and validates
  it was rendered correctly via reading from glReadPixels
  and checking the returned buffer for values of alpha, red,
  green and blue.

Signed-off-by: Tom Gall <tom.gall at linaro.org>
---
 tests/all_es2.tests                           |    5 +
 tests/gles2/CMakeLists.gles2.txt              |    5 +
 tests/gles2/data/shaders/simple_triangle.frag |    6 +
 tests/gles2/data/shaders/simple_triangle.vert |    5 +
 tests/gles2/gles2_simple_triangle.c           |  190 +++++++++++++++++++++++++
 5 files changed, 211 insertions(+)
 create mode 100644 tests/gles2/data/shaders/simple_triangle.frag
 create mode 100644 tests/gles2/data/shaders/simple_triangle.vert
 create mode 100644 tests/gles2/gles2_simple_triangle.c

diff --git a/tests/all_es2.tests b/tests/all_es2.tests
index ac1b636..0f5c5f2 100644
--- a/tests/all_es2.tests
+++ b/tests/all_es2.tests
@@ -21,4 +21,9 @@ oes_compressed_etc1_rgb8_texture = Group()
 spec['OES_compressed_ETC1_RGB8_texture'] = oes_compressed_etc1_rgb8_texture
 oes_compressed_etc1_rgb8_texture['miptree'] = PlainExecTest(['oes_compressed_etc1_rgb8_texture-miptree', '-auto'])
 
+gles2_tests = Group()
+spec['gles2_tests'] = gles2_tests
+gles2_tests['gles2_simple_triangle'] =  PlainExecTest(['gles2_simple_triangle', '-auto'])
+gles2_tests['gles2_simple_triangle'].runConcurrent = False
+
 profile.tests['spec'] = spec
diff --git a/tests/gles2/CMakeLists.gles2.txt b/tests/gles2/CMakeLists.gles2.txt
index a7807d8..64c69c2 100644
--- a/tests/gles2/CMakeLists.gles2.txt
+++ b/tests/gles2/CMakeLists.gles2.txt
@@ -10,8 +10,13 @@ link_libraries(
 	piglitutil_gles2
 	)
 
+add_definitions (-DGLES2_DATA_PATH="${piglit_SOURCE_DIR}/tests/gles2/data")
+
 piglit_add_executable(gles2_shader_runner
 	gles2_shader_runner.c
 	)
+piglit_add_executable(gles2_simple_triangle
+	gles2_simple_triangle.c
+	)
 
 # vim: ft=cmake:
diff --git a/tests/gles2/data/shaders/simple_triangle.frag b/tests/gles2/data/shaders/simple_triangle.frag
new file mode 100644
index 0000000..e2321fb
--- /dev/null
+++ b/tests/gles2/data/shaders/simple_triangle.frag
@@ -0,0 +1,6 @@
+precision mediump float;
+
+void main()
+{
+    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+}
diff --git a/tests/gles2/data/shaders/simple_triangle.vert b/tests/gles2/data/shaders/simple_triangle.vert
new file mode 100644
index 0000000..62bfe59
--- /dev/null
+++ b/tests/gles2/data/shaders/simple_triangle.vert
@@ -0,0 +1,5 @@
+attribute vec4 vPosition;
+void main()
+{
+    gl_Position = vPosition;
+}
diff --git a/tests/gles2/gles2_simple_triangle.c b/tests/gles2/gles2_simple_triangle.c
new file mode 100644
index 0000000..2024895
--- /dev/null
+++ b/tests/gles2/gles2_simple_triangle.c
@@ -0,0 +1,190 @@
+/*
+ * 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.
+ */
+
+/**
+ * A simple triange test for OpenGL ES 2.0.
+ *
+ * \author Tom Gall <tom.gall at linaro.org>
+ */
+
+#define _GNU_SOURCE
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "piglit-util-gl-common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+    config.supports_gl_es2 = true;
+    config.requires_displayed_window = true;
+
+    config.window_width = 320;
+    config.window_height = 200;
+    config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DEPTH;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+GLuint prog;
+GLuint frag;
+GLuint vert;
+
+enum piglit_result
+validate_results()
+{
+	int i,j, linestart,lineend;
+	GLubyte buffer[200][320][4];
+
+	glReadPixels(0,0,320,200,GL_RGBA, GL_UNSIGNED_BYTE, &buffer);
+
+	// check that the triangle was rendered correctly
+	for (i=148;i>49;i--) {
+		linestart=159;
+		lineend=160;
+		for(j=linestart;j<=lineend;j++) {
+			if (buffer[i][j][0]!=0xff && buffer[i][j][1]!=0x00 &&
+                buffer[i][j][2]!=0x00 && buffer[i][j][3]!=0xff)
+				return PIGLIT_FAIL;
+		}
+	linestart--;
+	lineend++;
+	}
+	// check that the remaining area is black
+	for(i=0;i<50;i++) {
+		for(j=0;j<320;j++) {
+			if (buffer[i][j][0]!=0x00 && buffer[i][j][1]!=0x00 &&
+                buffer[i][j][2]!=0x00 && buffer[i][j][3]!=0xff)
+				return PIGLIT_FAIL;
+		}
+	}
+	for(i=149;i<200;i++) {
+		for(j=0;j<320;j++) {
+			if (buffer[i][j][0]!=0x00 && buffer[i][j][1]!=0x00 &&
+                buffer[i][j][2]!=0x00 && buffer[i][j][3]!=0xff)
+				return PIGLIT_FAIL;
+		}
+	}
+	lineend=158;
+	for (i=148;i>49;i--) {
+		linestart=0;
+		for(j=linestart;j<=lineend;j++) {
+			if (buffer[i][j][0]!=0x00 && buffer[i][j][1]!=0x00 &&
+                buffer[i][j][2]!=0x00 && buffer[i][j][3]!=0xff)
+				return PIGLIT_FAIL;
+		}
+	lineend--;
+	}
+	linestart=161;
+	for (i=148;i>49;i--) {
+		lineend=320;
+		for(j=linestart;j<lineend;j++) {
+			if (buffer[i][j][0]!=0x00 && buffer[i][j][1]!=0x00 &&
+                buffer[i][j][2]!=0x00 && buffer[i][j][3]!=0xff)
+				return PIGLIT_FAIL;
+		}
+	linestart++;
+	}
+			
+	return PIGLIT_PASS;
+}
+
+bool
+check_for_glError(char *message)
+{
+    GLenum err;
+
+    err = glGetError();
+    if (err) {
+        GLchar *info;
+        GLint size;
+
+        printf("%s: 0x%04x\n",message, err);
+
+        glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size);
+        info = malloc(size);
+
+        glGetProgramInfoLog(prog, size, NULL, info);
+        fprintf(stderr, "Info log: %s\n", info);
+
+        piglit_report_result(PIGLIT_FAIL);
+		return true;
+    }
+	return false;
+}
+
+void
+link_and_use_shaders(void)
+{
+	prog = glCreateProgram();
+
+	vert=piglit_compile_shader(GL_VERTEX_SHADER,"gles2/data/shaders/simple_triangle.vert");
+	frag=piglit_compile_shader(GL_FRAGMENT_SHADER,"gles2/data/shaders/simple_triangle.frag");
+
+	glAttachShader(prog, vert);
+	glAttachShader(prog, frag);
+
+	glLinkProgram(prog);
+	if (!(piglit_link_check_status(prog))) {
+        piglit_report_result(PIGLIT_FAIL);
+		return;
+	}	
+
+	glDeleteShader(vert);
+	glDeleteShader(frag);
+
+    glUseProgram(prog);
+	if (check_for_glError("GL error after linking program")) {
+        piglit_report_result(PIGLIT_FAIL);
+		return;
+	}	
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	GLfloat vVertices[] = {  0.0f,  0.5f, 0.0f,
+                           -0.5f, -0.5f, 0.0f,
+                            0.5f, -0.5f, 0.0f };
+
+//	// Set the viewport
+//   glViewport ( 0, 0, 320, 200 );
+
+	// Clear the color buffer
+	glClear ( GL_COLOR_BUFFER_BIT );
+
+	// Load the vertex data
+	glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, 0, vVertices );
+	glEnableVertexAttribArray ( 0 );
+
+	glDrawArrays ( GL_TRIANGLES, 0, 3 );
+
+	piglit_swap_buffers();
+
+	return validate_results();	
+}
+
+void
+piglit_init(int argc, char *argv[])
+{
+	link_and_use_shaders();
+}
+
-- 
1.7.10.4



More information about the Piglit mailing list