diff options
Diffstat (limited to 'tests/spec/gles-2.0/api/glreadpixels-common.c')
-rw-r--r-- | tests/spec/gles-2.0/api/glreadpixels-common.c | 342 |
1 files changed, 342 insertions, 0 deletions
diff --git a/tests/spec/gles-2.0/api/glreadpixels-common.c b/tests/spec/gles-2.0/api/glreadpixels-common.c new file mode 100644 index 00000000..34ffcf8d --- /dev/null +++ b/tests/spec/gles-2.0/api/glreadpixels-common.c @@ -0,0 +1,342 @@ +/* + * 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. + */ + +/** + * Common code for testing 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" + +void +clear_buffer(GLubyte *buffer) +{ + memset(buffer, TEST_PATTERN_BYTE, piglit_width*(piglit_height+50)*4); +} + + +enum piglit_result +check_buffer_RGB(GLubyte *buffer) +{ + pixel_f888 *p888; + int i,j; + + /* check that the rectangle was rendered correctly */ + for (i = piglit_height/4; i < piglit_height/4*3; i++) { + for (j = piglit_width/4; j < piglit_width/4*3; j++) { + p888 = (pixel_f888 *)(buffer + (((i * piglit_width)+ j) * 3)); + if (p888->red != 0xff && p888->green != 0x00 && + p888->blue != 0x00) + return PIGLIT_FAIL; + } + } + + /* check that the remaining area is black */ + for(i = 0; i < piglit_height/4; i++) { + for(j = 0; j < piglit_width; j++) { + p888 = (pixel_f888 *)(buffer + (((i*piglit_width)+ j) * 3)); + if (p888->red != 0x00 && p888->green != 0x00 && + p888->blue != 0x00) + return PIGLIT_FAIL; + } + } + for(i = piglit_height/4*3; i < piglit_height; i++) { + for(j = 0; j < piglit_width; j++) { + p888 = (pixel_f888 *)(buffer + (((i * piglit_width) + j) * 3)); + if (p888->red != 0x00 && p888->green != 0x00 && + p888->blue != 0x00) + return PIGLIT_FAIL; + } + } + for(i = piglit_height/4; i < piglit_height/4*3; i++) { + for(j = 0; j < piglit_width/4; j++) { + p888=(pixel_f888 *)(buffer + (((i * piglit_width) + j) * 3)); + if (p888->red != 0x00 && p888->green != 0x00 && + p888->blue != 0x00) + return PIGLIT_FAIL; + } + } + for(i = piglit_height/4; i < piglit_height/4*3; i++) { + for(j = piglit_width/4*3; j < piglit_width; j++) { + p888 = (pixel_f888 *)(buffer + (((i * piglit_width) + j) * 3)); + if (p888->red != 0x00 && p888->green != 0x00 && + p888->blue != 0x00) + return PIGLIT_FAIL; + } + } + + return PIGLIT_PASS; +} + + +enum piglit_result +check_buffer_RGBA(GLubyte *buffer) +{ + int i,j; + + /* check that the rectangle was rendered correctly */ + for (i = piglit_height/4; i < piglit_height/4*3; i++) { + for (j = piglit_width/4; j < piglit_width/4*3; j++) { + if (*(buffer + (i * j)) != 0xff && + *(buffer + ((i * j) + 1)) != 0x00 && + *(buffer + ((i * j) + 2)) != 0x00 && + *(buffer + ((i * j) + 3)) != 0xff) + return PIGLIT_FAIL; + } + } + /* check that the remaining area is black */ + for(i = 0; i < piglit_height/4; i++) { + for(j = 0; j < piglit_width; j++) { + if (*(buffer + (i * j)) != 0x00 && + *(buffer + ((i * j) + 1)) != 0x00 && + *(buffer + ((i * j) + 2)) != 0x00 && + *(buffer + ((i * j) + 3)) != 0xff) + return PIGLIT_FAIL; + } + } + for(i = (piglit_height/4)*3; i < piglit_height; i++) { + for(j = 0; j < piglit_width; j++) { + if (*(buffer + (i * j)) != 0x00 && + *(buffer + ((i * j) + 1)) != 0x00 && + *(buffer + ((i * j) + 2)) != 0x00 && + *(buffer + ((i * j) + 3)) != 0xff) + return PIGLIT_FAIL; + } + } + for(i = piglit_height/4; i < piglit_height/4*3; i++) { + for(j = 0; j < piglit_width/4; j++) { + if (*(buffer + (i * j)) != 0x00 && + *(buffer + ((i * j) + 1)) != 0x00 && + *(buffer + ((i * j) + 2)) != 0x00 && + *(buffer + ((i * j) + 3)) != 0xff) + return PIGLIT_FAIL; + } + } + for(i = piglit_height/4; i < piglit_height/4*3; i++) { + for(j = 240; j < piglit_width; j++) { + if (*(buffer + (i * j)) != 0x00 && + *(buffer + ((i * j) + 1)) != 0x00 && + *(buffer + ((i * j) + 2)) != 0x00 && + *(buffer + ((i * j) + 3)) != 0xff) + return PIGLIT_FAIL; + } + } + + return PIGLIT_PASS; +} + + +enum piglit_result +check_buffer_ALPHA(GLubyte *buffer) +{ + int i,j; + + for(i = 0; i < piglit_height; i++) { + for(j = 0; j < piglit_width; j++) { + if (*(buffer + (i * piglit_height) + j) != 0xff) + return PIGLIT_FAIL; + } + } + + return PIGLIT_PASS; +} + + +enum piglit_result +check_buffer_is_not_changed(GLubyte *buffer) +{ + int i,j; + + for(i = 0; i < piglit_height; i++) { + for(j = 0; j < (piglit_width + 50); j++) { + if (*(buffer + (i * piglit_height) + j) != TEST_PATTERN_BYTE) + return PIGLIT_FAIL; + } + } + + return PIGLIT_PASS; +} + + +enum piglit_result +check_buffer_RGB_565(GLubyte *buffer) +{ + pixel_f565 *p565; + int i,j; + + /* check that the rectangle was rendered correctly */ + for (i = piglit_height/4; i < piglit_height/4*3; i++) { + for (j = piglit_width/4; j < piglit_width/4*3; j++) { + p565 = (pixel_f565 *)(buffer + (((i * piglit_width) + j) * 2)); + if (p565->red != 0x1f && p565->blue != 0x00 && + p565->green != 0x00) + return PIGLIT_FAIL; + } + } + /* check that the remaining area is black */ + for(i = 0; i < piglit_height/4; i++) { + for(j = 0; j < piglit_width; j++) { + p565 = (pixel_f565 *)(buffer + (((i * piglit_width) + j) * 2)); + if (p565->red != 0x00 && p565->blue != 0x00 && + p565->green != 0x00) + return PIGLIT_FAIL; + } + } + for(i = piglit_height/4*3; i < piglit_height; i++) { + for(j = 0; j < piglit_width; j++) { + p565 = (pixel_f565 *)(buffer + (((i * piglit_width) + j) * 2)); + if (p565->red != 0x00 && p565->blue != 0x00 && + p565->green != 0x00) + return PIGLIT_FAIL; + } + } + for(i = piglit_height/4; i < piglit_height/4*3; i++) { + for(j = 0; j < piglit_width/4; j++) { + p565 = (pixel_f565 *)(buffer + (((i * piglit_width) + j) * 2)); + if (p565->red != 0x00 && p565->green != 0x00 && + p565->blue != 0x00) + return PIGLIT_FAIL; + } + } + for(i = piglit_height/4; i < piglit_height/4*3; i++) { + for(j = piglit_width/4*3; j < piglit_width; j++) { + p565 = (pixel_f565 *)(buffer + (((i * piglit_width) + j) * 2)); + if (p565->red != 0x00 && p565->green != 0x00 && + p565->blue != 0x00) + return PIGLIT_FAIL; + } + } + + return PIGLIT_PASS; +} + + +enum piglit_result +check_buffer_RGBA_5551(GLubyte *buffer) +{ + pixel_f5551 *p5551; + int i,j; + + /* check that the rectangle was rendered correctly */ + for (i = piglit_height/4; i < piglit_height/4*3; i++) { + for (j = piglit_width/4; j < piglit_width/4*3; j++) { + p5551 = (pixel_f5551 *)(buffer + (((i * piglit_width) + j) * 2)); + if (p5551->red != 0x1f && p5551->blue != 0x00 && + p5551->green != 0x00 && p5551->alpha != 0x1) + return PIGLIT_FAIL; + } + } + /* check that the remaining area is black */ + for(i = 0; i < piglit_height/4; i++) { + for(j = 0; j < piglit_width; j++) { + p5551 = (pixel_f5551 *)(buffer + (((i * piglit_width) + j) * 2)); + if (p5551->red!=0x00 && p5551->green!=0x00 && + p5551->blue!=0x00 && p5551->alpha!=0x1) + return PIGLIT_FAIL; + } + } + for(i = piglit_height/4*3; i < piglit_height; i++) { + for(j = 0; j < piglit_width; j++) { + p5551 = (pixel_f5551 *)(buffer + (((i * piglit_width) + j) * 2)); + if (p5551->red != 0x00 && p5551->green != 0x00 && + p5551->blue != 0x00 && p5551->alpha != 0x1) + return PIGLIT_FAIL; + } + } + for(i = piglit_height/4; i < piglit_height/4*3; i++) { + for(j = 0; j < piglit_width/4; j++) { + p5551 = (pixel_f5551 *)(buffer + (((i * piglit_width) + j) * 2)); + if (p5551->red != 0x00 && p5551->green != 0x00 && + p5551->blue != 0x00 && p5551->alpha != 0x1) + return PIGLIT_FAIL; + } + } + for(i = piglit_height/4; i < piglit_height/4*3; i++) { + for(j = piglit_width/4*3; j < piglit_width; j++) { + p5551 = (pixel_f5551 *)(buffer + (((i * piglit_width) + j) * 2)); + if (p5551->red != 0x00 && p5551->green != 0x00 && + p5551->blue != 0x00 && p5551->alpha != 0x1) + return PIGLIT_FAIL; + } + } + + return PIGLIT_PASS; +} + + +enum piglit_result +check_buffer_RGBA_4444(GLubyte *buffer) +{ + pixel_f4444 *p4444; + int i,j; + + /* check that the rectangle was rendered correctly */ + for (i = piglit_height/4; i < piglit_height/4*3; i++) { + for (j = piglit_width/4; j < piglit_width/4*3; j++) { + p4444 = (pixel_f4444 *)(buffer + (((i * piglit_width) + j) * 2)); + if (p4444->red != 0xf && p4444->green != 0x00 && + p4444->blue != 0x00 && p4444->alpha != 0xf) + return PIGLIT_FAIL; + } + } + /* check that the remaining area is black */ + for(i = 0; i < piglit_height/4; i++) { + for(j = 0; j < piglit_width; j++) { + p4444 = (pixel_f4444 *)(buffer + (((i * piglit_width) + j) * 2)); + if (p4444->red != 0x00 && p4444->green != 0x00 && + p4444->blue != 0x00 && p4444->alpha != 0xf) + return PIGLIT_FAIL; + } + } + for(i = piglit_height/4*3; i < piglit_height; i++) { + for(j = 0; j < piglit_width; j++) { + p4444 = (pixel_f4444 *)(buffer + (((i * piglit_width) + j) * 2)); + if (p4444->red != 0x00 && p4444->green != 0x00 && + p4444->blue != 0x00 && p4444->alpha != 0xf) + return PIGLIT_FAIL; + } + } + for(i = piglit_height/4; i < piglit_height/4*3; i++) { + for(j = 0; j<piglit_width/4; j++) { + p4444 = (pixel_f4444 *)(buffer + (((i * piglit_width) + j) * 2)); + if (p4444->red != 0x00 && p4444->green != 0x00 && + p4444->blue != 0x00 && p4444->alpha != 0xf) + return PIGLIT_FAIL; + } + } + for(i=piglit_height/4; i < piglit_height/4*3; i++) { + for(j = piglit_width/4*3; j < piglit_width; j++) { + p4444 = (pixel_f4444 *)(buffer + (((i * piglit_width) + j) * 2)); + if (p4444->red != 0x00 && p4444->green != 0x00 && + p4444->blue != 0x00 && p4444->alpha != 0xf) + return PIGLIT_FAIL; + } + } + + return PIGLIT_PASS; +} |