diff options
Diffstat (limited to 'tests/spec/gles-2.0/api/glreadpixels-invalid.c')
-rw-r--r-- | tests/spec/gles-2.0/api/glreadpixels-invalid.c | 284 |
1 files changed, 284 insertions, 0 deletions
diff --git a/tests/spec/gles-2.0/api/glreadpixels-invalid.c b/tests/spec/gles-2.0/api/glreadpixels-invalid.c new file mode 100644 index 00000000..f113d2be --- /dev/null +++ b/tests/spec/gles-2.0/api/glreadpixels-invalid.c @@ -0,0 +1,284 @@ +/* + * Copyright © 2013 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. + */ + +/** + * This is test exercises glReadPixels + * as specified by the OpenGL ES 2.0.25 spec. + * + * \author Tom Gall <tom.gall@linaro.org> + */ + +#include <stdlib.h> +#include <stdio.h> +#include "piglit-util-gl-common.h" +#include "glreadpixels-common.h" + + +const char *format_strings [] = { + "GL_DEPTH_COMPONENT", + "GL_ALPHA", + "GL_RGB", + "GL_RGBA", + "GL_LUMINANCE", + "GL_LUMINANCE_ALPHA", + "0x1800" +}; + +const char *type_strings[] = { + "GL_UNSIGNED_BYTE", + "GL_UNSIGNED_SHORT_4444", + "GL_UNSIGNED_SHORT_5551", + "GL_UNSIGNED_SHORT_565" +}; + + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_es_version = 20; + + 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;\n" + "void main()\n" + "{\n" + " gl_Position = vPosition;\n" + "}"; + +char fragment_shader [] = + "precision mediump float;\n" + "void main()\n" + "{\n" + " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n" + "}"; + +static const struct { + GLenum format; + GLenum type; + enum piglit_result (*checkfn)(GLubyte *); + struct { + int x, y, width, height; + } coords; + int expected_error; + char *gl_error_msg; + enum _format_key format_idx; + enum _type_key type_idx; +} targets[] = { + { + GL_RGBA, + GL_UNSIGNED_BYTE, + check_buffer_is_not_changed, + { -10, -10, 10, 10 }, + 0, + "Reading from -10 -10 failed", + _RGBA, + _UNSIGNED_BYTE + }, + { + GL_RGBA, + GL_UNSIGNED_BYTE, + check_buffer_is_not_changed, + { 0, 0, 0, 0 }, + 0, + "Reading from 0 0 for 0 bytes should not copy data", + _RGBA, + _UNSIGNED_BYTE + }, + { + GL_RGBA, + GL_UNSIGNED_BYTE, + NULL, + { 0, 0, 1, 1 }, + 0, + "Reading from 0 0 to 1 1 to NULL failed", + _RGBA, + _UNSIGNED_BYTE + }, + { + GL_RGBA, + GL_UNSIGNED_BYTE, + check_buffer_is_not_changed, + { 0, 0, -10, -10 }, + GL_INVALID_VALUE, + "Neg width/height should generate GL_INVALID_VALUE", + _RGBA, + _UNSIGNED_BYTE + }, + { + GL_LUMINANCE, + GL_UNSIGNED_BYTE, + NULL, + { 0, 0, WIDTH, HEIGHT }, + GL_INVALID_OPERATION, + "GL_LUMINANCE should generate GL_INVALID_OPERATION", + _LUMINANCE, + _UNSIGNED_BYTE + }, + { + GL_LUMINANCE_ALPHA, + GL_UNSIGNED_BYTE, + NULL, + { 0, 0, WIDTH, HEIGHT }, + GL_INVALID_OPERATION, + "GL_LUMINANCE_ALPHA should generate GL_INVALID_OPERATION", + _LUMINANCE_ALPHA, + _UNSIGNED_BYTE + }, + { + GL_DEPTH_COMPONENT, + GL_UNSIGNED_BYTE, + NULL, + { 0, 0, WIDTH, HEIGHT }, + GL_INVALID_OPERATION, + "GL_DEPTH_COMPONENT should generate GL_INVALID_OPERATION", + _DEPTH_COMPONENT, + _UNSIGNED_BYTE + }, + { + 0x1800, + GL_UNSIGNED_BYTE, + NULL, + { 0, 0, WIDTH, HEIGHT }, + GL_INVALID_OPERATION, + "Invalid format value 0x1800 should generate GL_INVALID_OPERATION", + _x1800, + _UNSIGNED_BYTE + }, + { + GL_RGBA, + GL_UNSIGNED_SHORT_5_6_5, + NULL, + { 0, 0, WIDTH, HEIGHT }, + GL_INVALID_OPERATION, + "GL_RGBA & 565 should generated a GL_INVALID_OPERATION", + _RGBA, + _UNSIGNED_SHORT_565 + }, + { + GL_RGB, + GL_UNSIGNED_SHORT_5_6_5, + check_buffer_RGB_565, + { 0, 0, WIDTH, HEIGHT }, + GL_INVALID_OPERATION, + "glReadPixels with GL_RGB & GL_UNSIGNED_SHORT_565 failed.", + _RGB, + _UNSIGNED_SHORT_565 + }, +}; + + +enum piglit_result +validate_results(void) +{ + /* pad a bit so we can do a request larger than the viewport */ + GLubyte buffer[HEIGHT+50][WIDTH][4]; + enum piglit_result final_result = PIGLIT_PASS; + int v; + + /* first make sure glError has no issues */ + if (!piglit_check_gl_error(0)) + return PIGLIT_FAIL; + + for (v = 0; v < ARRAY_SIZE(targets); v++) { + clear_buffer((GLubyte *)&buffer); + glReadPixels(targets[v].coords.x, + targets[v].coords.y, + targets[v].coords.width, + targets[v].coords.height, + targets[v].format, + targets[v].type, + &buffer); + if (!piglit_check_gl_error(targets[v].expected_error)) { + fprintf(stderr, "%s\n",targets[v].gl_error_msg); + final_result = PIGLIT_FAIL; + } + if (targets[v].checkfn) { + if (targets[v].checkfn((GLubyte *)&buffer) == PIGLIT_FAIL) { + fprintf(stderr, "%s & %s, buffer has incorrect results\n",format_strings[targets[v].format_idx], type_strings[targets[v].type_idx]); + final_result = PIGLIT_FAIL; + } + } + } + piglit_report_result(final_result); + + return final_result; +} + +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); + + prog = piglit_link_simple_program(vert, frag); + if (!prog) { + piglit_report_result(PIGLIT_FAIL); + return; + } + + glDeleteShader(vert); + glDeleteShader(frag); + + glUseProgram(prog); + if (!piglit_check_gl_error(0)) { + piglit_report_result(PIGLIT_FAIL); + return; + } +} + +enum piglit_result +piglit_display(void) +{ + GLfloat vertices[] = { + 0.5, -0.5, 0.0, + 0.5, 0.5, 0.0, + -0.5, 0.5, 0.0, + -0.5, -0.5, 0.0 }; + + glClear(GL_COLOR_BUFFER_BIT); + + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertices); + glEnableVertexAttribArray(0); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + return validate_results(); +} + +void +piglit_init(int argc, char *argv[]) +{ + link_and_use_shaders(); +} |