new gles2 sanity 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 <[email protected]> --- tests/all_es2.tests | 4 + tests/gles2/CMakeLists.gles2.txt | 3 + tests/gles2/gles2_simple_triangle.c | 199 +++++++++++++++++++++++++++++++++++ 3 files changed, 206 insertions(+) create mode 100644 tests/gles2/gles2_simple_triangle.c diff --git a/tests/all_es2.tests b/tests/all_es2.tests index ac1b636..61a2329 100644 --- a/tests/all_es2.tests +++ b/tests/all_es2.tests @@ -21,4 +21,8 @@ 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']) + profile.tests['spec'] = spec diff --git a/tests/gles2/CMakeLists.gles2.txt b/tests/gles2/CMakeLists.gles2.txt index a7807d8..633a2ed 100644 --- a/tests/gles2/CMakeLists.gles2.txt +++ b/tests/gles2/CMakeLists.gles2.txt @@ -13,5 +13,8 @@ link_libraries( 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/gles2_simple_triangle.c b/tests/gles2/gles2_simple_triangle.c new file mode 100644 index 0000000..e295b9c --- /dev/null +++ b/tests/gles2/gles2_simple_triangle.c @@ -0,0 +1,199 @@ +/* + * 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 <[email protected]> + */ + +#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; + +char vertex_shader [] = "\ +attribute vec4 vPosition; \ +void main() \ +{ \ + gl_Position = vPosition; \ +}"; + +char fragment_shader [] = "\ +precision mediump float; \ +void main() \ +{ \ + gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); \ +}"; \ + +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_text(GL_VERTEX_SHADER,vertex_shader); + frag=piglit_compile_shader_text(GL_FRAGMENT_SHADER,fragment_shader); + + 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 }; + + /* 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 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
