[Piglit] [PATCH 2/2] gles2: new glReadPixels unit test

Tom Gall tom.gall at linaro.org
Tue Nov 27 17:41:29 PST 2012


Unit test for glReadPixels specifically for OpenGL v2.0. Covers a
variety of formats and types, both valid and invalid.

A few variations are commented out due to the results are incorrect
and need to be followed up with Mesa, such as modifying the buffer
even tho the format is invalid, incorrect returned data. These
can be addressed in time and I thought it best to include the
variations but in their commented out form.

Signed-off-by: Tom Gall <tom.gall at linaro.org>
---
 tests/all_es2.tests                   |    1 +
 tests/gles2/CMakeLists.gles2.txt      |    3 +
 tests/gles2/gles2_unit_glReadPixels.c |  702 +++++++++++++++++++++++++++++++++
 3 files changed, 706 insertions(+)
 create mode 100644 tests/gles2/gles2_unit_glReadPixels.c

diff --git a/tests/all_es2.tests b/tests/all_es2.tests
index 61a2329..699186a 100644
--- a/tests/all_es2.tests
+++ b/tests/all_es2.tests
@@ -24,5 +24,6 @@ oes_compressed_etc1_rgb8_texture['miptree'] = PlainExecTest(['oes_compressed_etc
 gles2_tests = Group()
 spec['gles2_tests'] = gles2_tests
 gles2_tests['gles2_simple_triangle'] =  PlainExecTest(['gles2_simple_triangle', '-auto'])
+gles2_tests['gles2_unit_glReadPixels'] =  PlainExecTest(['gles2_unit_glReadPixels', '-auto'])
 
 profile.tests['spec'] = spec
diff --git a/tests/gles2/CMakeLists.gles2.txt b/tests/gles2/CMakeLists.gles2.txt
index 633a2ed..7be1131 100644
--- a/tests/gles2/CMakeLists.gles2.txt
+++ b/tests/gles2/CMakeLists.gles2.txt
@@ -16,5 +16,8 @@ piglit_add_executable(gles2_shader_runner
 piglit_add_executable(gles2_simple_triangle
 	gles2_simple_triangle.c
 	)
+piglit_add_executable(gles2_unit_glReadPixels
+	gles2_unit_glReadPixels.c
+	)
 
 # vim: ft=cmake:
diff --git a/tests/gles2/gles2_unit_glReadPixels.c b/tests/gles2/gles2_unit_glReadPixels.c
new file mode 100644
index 0000000..762bf7d
--- /dev/null
+++ b/tests/gles2/gles2_unit_glReadPixels.c
@@ -0,0 +1,702 @@
+/*
+ * 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.
+ */
+
+/**
+ * This is a unit test to exercise glReadPixels
+ * as specified by the OpenGL ES 2.0 spec.
+ *
+ * Todo: GL_PACK_ALIGHNMENT via glPixelStorei isn't tested
+ *       reading from GL_COLOR_ATTACHMENT0 when the default framebuffer
+ *          isn't bound is not tested
+ *       combo of GL_IMPLEMENTATION_COLOR_READ_FORMAT
+ *          GL_IMPLEMENTATION_COLOR_READ_TYPE is not tested
+ *
+ * \author Tom Gall <tom.gall at linaro.org>
+ */
+
+#define _GNU_SOURCE
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "piglit-util-gl-common.h"
+
+#define WIDTH 320
+#define HEIGHT 200
+#define TEST_PATTERN_BYTE 0xA5
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_es2 = true;
+	config.requires_displayed_window = true;
+
+	config.window_width = WIDTH;
+	config.window_height = HEIGHT;
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DEPTH;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+GLuint prog;
+GLuint frag;
+GLuint vert;
+/* pad a bit so we can do a request larger than the viewport */
+GLubyte buffer[HEIGHT+50][WIDTH][4];
+
+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); \
+}"; 
+
+/* various pixel formats */
+typedef struct {
+	unsigned short red:5;
+	unsigned short green:6;
+	unsigned short blue:5;
+} pixel_f565; 
+typedef struct {
+	unsigned short red:5;
+	unsigned short green:5;
+	unsigned short blue:5;
+	unsigned short alpha:1;
+} pixel_f5551; 
+typedef struct {
+	unsigned short red:4;
+	unsigned short green:4;
+	unsigned short blue:4;
+	unsigned short alpha:4;
+} pixel_f4444; 
+typedef struct {
+	unsigned char red;
+	unsigned char green;
+	unsigned char blue;
+} pixel_f888;
+
+GLenum
+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);
+		free(info);
+		return err;
+	}
+	return err;
+}
+
+GLenum
+check_for_glError_and_warn(GLenum expect, char *message)
+{
+	GLenum err;
+
+	err = glGetError();
+	if (expect && !err) {
+		fprintf(stderr, "Expected %x but was not returned: %s\n", expect, message);
+	}
+	else if (err && expect!=0 && expect!=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);
+
+		free(info);
+		return err;
+	}
+	return err;
+}
+
+void
+clear_buffer(void)
+{
+	memset(&buffer,TEST_PATTERN_BYTE,WIDTH*(HEIGHT+50)*4);
+}
+
+enum piglit_result
+check_buffer_RGB(void)
+{
+	GLubyte *px;
+	pixel_f888 *p888;
+	int i,j, linestart, lineend;
+
+	/* check that the triangle was rendered correctly */
+	for (i=148;i>49;i--) {
+		linestart=159;
+		lineend=160;
+		for(j=linestart;j<=lineend;j++) {
+			p888=(pixel_f888 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*3));
+			if (p888->red!=0xff && p888->green!=0x00 && p888->blue!=0x00)
+				return PIGLIT_FAIL;
+		}
+	linestart--;
+	lineend++;
+	}
+	/* check that the remaining area is black */
+	for(i=0;i<50;i++) {
+		for(j=0;j<WIDTH;j++) {
+			p888=(pixel_f888 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*3));
+			if (p888->red!=0x00 && p888->green!=0x00 && p888->blue!=0x00)
+				return PIGLIT_FAIL;
+		}
+	}
+	for(i=149;i<HEIGHT;i++) {
+		for(j=0;j<WIDTH;j++) {
+			p888=(pixel_f888 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*3));
+			if (p888->red!=0x00 && p888->green!=0x00 && p888->blue!=0x00)
+				return PIGLIT_FAIL;
+		}
+	}
+	lineend=158;
+	for (i=148;i>49;i--) {
+		linestart=0;
+		for(j=linestart;j<=lineend;j++) {
+			p888=(pixel_f888 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*3));
+			if (p888->red!=0x00 && p888->green!=0x00 && p888->blue!=0x00)
+				return PIGLIT_FAIL;
+		}
+	lineend--;
+	}
+	linestart=161;
+	for (i=148;i>49;i--) {
+		lineend=WIDTH;
+		for(j=linestart;j<lineend;j++) {
+			p888=(pixel_f888 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*3));
+			if (p888->red!=0x00 && p888->green!=0x00 && p888->blue!=0x00)
+				return PIGLIT_FAIL;
+		}
+	linestart++;
+	}
+			
+	return PIGLIT_PASS;
+}
+
+enum piglit_result
+check_buffer_RGBA(void)
+{
+	int i,j, linestart, lineend;
+
+	/* 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<WIDTH;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<HEIGHT;i++) {
+		for(j=0;j<WIDTH;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=WIDTH;
+		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;
+}
+
+enum piglit_result
+check_buffer_ALPHA(void)
+{
+	GLubyte *alpha=(GLubyte *)buffer;
+	int i,j;
+
+	for(i=0;i<HEIGHT;i++) {
+		for(j=0;j<WIDTH;j++) {
+			if (*(alpha+(i*HEIGHT)+j)!=0xff)
+				return PIGLIT_FAIL;
+		}
+	}
+			
+	return PIGLIT_PASS;
+}
+
+enum piglit_result
+check_buffer_is_not_changed(void)
+{
+	GLubyte *px=(GLubyte *)buffer;
+	int i,j;
+
+	for(i=0;i<HEIGHT;i++) {
+		for(j=0;j<(WIDTH+50);j++) {
+			if (*(px+(i*HEIGHT)+j)!=TEST_PATTERN_BYTE)
+				return PIGLIT_FAIL;
+		}
+	}
+			
+	return PIGLIT_PASS;
+}
+
+enum piglit_result
+check_buffer_RGB_565(void)
+{
+	unsigned short *px;
+	pixel_f565 *p565;
+	int i,j, linestart, lineend;
+
+	/* check that the triangle was rendered correctly */
+	for (i=148;i>49;i--) {
+		linestart=159;
+		lineend=160;
+		for(j=linestart;j<=lineend;j++) {
+			p565=(pixel_f565 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*2));
+			if (p565->red!=0x1f && p565->blue!=0x00 &&
+                p565->green!=0x00)
+				return PIGLIT_FAIL;
+		}
+	linestart--;
+	lineend++;
+	}
+	/* check that the remaining area is black */
+	for(i=0;i<50;i++) {
+		for(j=0;j<WIDTH;j++) {
+			p565=(pixel_f565 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*2));
+			if (p565->red!=0x00 && p565->blue!=0x00 &&
+                p565->green!=0x00) 
+				return PIGLIT_FAIL;
+		}
+	}
+	for(i=149;i<HEIGHT;i++) {
+		for(j=0;j<WIDTH;j++) {
+			p565=(pixel_f565 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*2));
+			if (p565->red!=0x00 && p565->blue!=0x00 &&
+                p565->green!=0x00)
+				return PIGLIT_FAIL;
+		}
+	}
+	lineend=158;
+	for (i=148;i>49;i--) {
+		linestart=0;
+		for(j=linestart;j<=lineend;j++) {
+			p565=(pixel_f565 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*2));
+			if (p565->red!=0x00 && p565->green!=0x00 &&
+                p565->blue!=0x00)
+				return PIGLIT_FAIL;
+		}
+	lineend--;
+	}
+	linestart=161;
+	for (i=148;i>49;i--) {
+		lineend=WIDTH;
+		for(j=linestart;j<lineend;j++) {
+			p565=(pixel_f565 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*2));
+			if (p565->red!=0x00 && p565->green!=0x00 &&
+                p565->blue!=0x00)
+				return PIGLIT_FAIL;
+		}
+	linestart++;
+	}
+			
+	return PIGLIT_PASS;
+}
+
+enum piglit_result
+check_buffer_RGBA_5551(void)
+{
+	pixel_f5551 *p5551;
+	int i,j, linestart, lineend;
+
+	/* check that the triangle was rendered correctly */
+	for (i=148;i>49;i--) {
+		linestart=159;
+		lineend=160;
+		for(j=linestart;j<=lineend;j++) {
+			p5551=(pixel_f5551 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*2));
+			if (p5551->red!=0x1f && p5551->blue!=0x00 &&
+                p5551->green!=0x00 && p5551->alpha!=0x1)
+				return PIGLIT_FAIL;
+		}
+	linestart--;
+	lineend++;
+	}
+	/* check that the remaining area is black */
+	for(i=0;i<50;i++) {
+		for(j=0;j<WIDTH;j++) {
+			p5551=(pixel_f5551 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*2));
+			if (p5551->red!=0x00 && p5551->green!=0x00 &&
+                p5551->blue!=0x00 && p5551->alpha!=0x1)
+				return PIGLIT_FAIL;
+		}
+	}
+	for(i=149;i<HEIGHT;i++) {
+		for(j=0;j<WIDTH;j++) {
+			p5551=(pixel_f5551 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*2));
+			if (p5551->red!=0x00 && p5551->green!=0x00 &&
+                p5551->blue!=0x00 && p5551->alpha!=0x1)
+				return PIGLIT_FAIL;
+		}
+	}
+	lineend=158;
+	for (i=148;i>49;i--) {
+		linestart=0;
+		for(j=linestart;j<=lineend;j++) {
+			p5551=(pixel_f5551 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*2));
+			if (p5551->red!=0x00 && p5551->green!=0x00 &&
+                p5551->blue!=0x00 && p5551->alpha!=0x1)
+				return PIGLIT_FAIL;
+		}
+	lineend--;
+	}
+	linestart=161;
+	for (i=148;i>49;i--) {
+		lineend=WIDTH;
+		for(j=linestart;j<lineend;j++) {
+			p5551=(pixel_f5551 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*2));
+			if (p5551->red!=0x00 && p5551->green!=0x00 &&
+                p5551->blue!=0x00 && p5551->alpha!=0x1)
+				return PIGLIT_FAIL;
+		}
+	linestart++;
+	}
+			
+	return PIGLIT_PASS;
+}
+
+enum piglit_result
+check_buffer_RGBA_4444(void)
+{
+	unsigned short *px;
+	pixel_f4444 *p4444;
+	int i,j, linestart, lineend;
+
+	/* check that the triangle was rendered correctly */
+	for (i=148;i>49;i--) {
+		linestart=159;
+		lineend=160;
+		for(j=linestart;j<=lineend;j++) {
+			p4444=(pixel_f4444 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*2));
+			if (p4444->red!=0xf && p4444->green!=0x00 &&
+                p4444->blue!=0x00 && p4444->alpha!=0xf)
+				return PIGLIT_FAIL;
+		}
+	linestart--;
+	lineend++;
+	}
+	/* check that the remaining area is black */
+	for(i=0;i<50;i++) {
+		for(j=0;j<WIDTH;j++) {
+			p4444=(pixel_f4444 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*2));
+			if (p4444->red!=0x00 && p4444->green!=0x00 &&
+                p4444->blue!=0x00 && p4444->alpha!=0xf)
+				return PIGLIT_FAIL;
+		}
+	}
+	for(i=149;i<HEIGHT;i++) {
+		for(j=0;j<WIDTH;j++) {
+			p4444=(pixel_f4444 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*2));
+			if (p4444->red!=0x00 && p4444->green!=0x00 &&
+                p4444->blue!=0x00 && p4444->alpha!=0xf)
+				return PIGLIT_FAIL;
+		}
+	}
+	lineend=158;
+	for (i=148;i>49;i--) {
+		linestart=0;
+		for(j=linestart;j<=lineend;j++) {
+			p4444=(pixel_f4444 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*2));
+			if (p4444->red!=0x00 && p4444->green!=0x00 &&
+                p4444->blue!=0x00 && p4444->alpha!=0xf)
+				return PIGLIT_FAIL;
+		}
+	lineend--;
+	}
+	linestart=161;
+	for (i=148;i>49;i--) {
+		lineend=WIDTH;
+		for(j=linestart;j<lineend;j++) {
+			p4444=(pixel_f4444 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*2));
+			if (p4444->red!=0x00 && p4444->green!=0x00 &&
+                p4444->blue!=0x00 && p4444->alpha!=0xf)
+				return PIGLIT_FAIL;
+		}
+	linestart++;
+	}
+			
+	return PIGLIT_PASS;
+}
+
+enum piglit_result
+validate_results()
+{
+	/* first make sure glError has no issues */
+	if (check_for_glError("Error before testing begins"))
+		return PIGLIT_FAIL;
+
+	clear_buffer();
+
+	/* test glReadPixels */
+	glReadPixels(-10,-10,10,10,GL_RGBA, GL_UNSIGNED_BYTE, &buffer);
+	check_for_glError_and_warn(0,"Reading from -10 -10 failed");
+	if (check_buffer_is_not_changed()==PIGLIT_FAIL) {
+		fprintf(stderr,"Reading from -10 -10 for 10x10 should not copy data\n");
+	}
+
+	clear_buffer();
+	glReadPixels(0,0,0,0,GL_RGBA, GL_UNSIGNED_BYTE, &buffer);
+	check_for_glError_and_warn(0,"Reading from 0 0 for 0x0 should not copy data");
+	if (check_buffer_is_not_changed()==PIGLIT_FAIL) {
+		fprintf(stderr, "Reading from 0 0 for 0x0 should not copy data\n");
+	}
+
+	glReadPixels(0,0,1,1,GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+	check_for_glError_and_warn(0,"Reading from 0 0 for 1x1 to NULL failed");
+
+	clear_buffer();
+	glReadPixels(0,0,-10,-10,GL_RGBA, GL_UNSIGNED_BYTE, &buffer);
+	check_for_glError_and_warn(GL_INVALID_VALUE,"neg width/height should gen GL_INVALID_VALUE");
+	if (check_buffer_is_not_changed()==PIGLIT_FAIL) {
+		fprintf(stderr, "Reading from 0 0 for -10x-10 should not copy data\n");
+	}
+
+	/* according to 
+	* http://www.khronos.org/opengles/sdk/docs/man/  glReadPixels
+	* only GL_RGBA, GL_RGB and GL_ALPHA are valid format parameters
+	* GL_LUMINANCE, GL_LUMINANCE_ALPHA and GL_DEPTH_COMPONENT 
+	* should fail and return an error
+	*/
+	clear_buffer();
+	glReadPixels(0,0,WIDTH,HEIGHT,GL_LUMINANCE, GL_UNSIGNED_BYTE, &buffer);
+	check_for_glError_and_warn(GL_INVALID_OPERATION,"GL_LUMINANCE should gen GL_INVALID_OPERATION");
+
+	clear_buffer();
+	glReadPixels(0,0,WIDTH,HEIGHT,GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, &buffer);
+	check_for_glError_and_warn(GL_INVALID_OPERATION,"GL_LUMINANCE_ALPHA should gen GL_INVALID_OPERATION");
+
+	clear_buffer();
+	glReadPixels(0,0,WIDTH,HEIGHT,GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, &buffer);
+	check_for_glError_and_warn(GL_INVALID_OPERATION,"GL_DEPTH_COMPONENT should gen GL_INVALID_OPERATION");
+
+    /* on mesa currently it incorrectly returns GL_INVALID_VALUE */
+	clear_buffer();
+	glReadPixels(0,0,WIDTH,HEIGHT,0x1800, GL_UNSIGNED_BYTE, &buffer);
+	check_for_glError_and_warn(GL_INVALID_OPERATION,"MISC format 0x1800 should gen GL_INVALID_OPERATION");
+
+	clear_buffer();
+	glReadPixels(0,0,WIDTH,HEIGHT,GL_RGBA, GL_UNSIGNED_BYTE, &buffer);
+	check_for_glError_and_warn(0,"RGBA & GL_UNSIGNED_BTYE glReadPixels failed");
+	if (check_buffer_RGBA() == PIGLIT_FAIL) {
+		fprintf(stderr, "RGBA GL_UNSIGNED_BYTE incorrect results\n");
+		piglit_report_result(PIGLIT_WARN);
+	}
+
+	clear_buffer();
+	glReadPixels(0,0,WIDTH,HEIGHT,GL_RGBA, GL_UNSIGNED_SHORT_5_6_5, &buffer);
+	check_for_glError_and_warn(GL_INVALID_OPERATION,"GL_RGBA and 565 should gen GL_INVALID_OPERATION");
+
+/*  data is returned by this variation but it's goofed up
+    commenting out for now, will take issue upstream.
+	clear_buffer();
+	glReadPixels(0,0,WIDTH,HEIGHT,GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, &buffer);
+	check_for_glError_and_warn(0,"RGBA & GL_UNSIGNED_SHORT 5551 glReadPixels failed");
+	if (check_buffer_RGBA_5551()==PIGLIT_FAIL) {
+		fprintf(stderr, "RGBA GL_UNSIGNED_SHORT 5551 incorrect results\n");
+		piglit_report_result(PIGLIT_WARN);
+	}
+*/
+	clear_buffer();
+	glReadPixels(0,0,WIDTH,HEIGHT,GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, &buffer);
+	check_for_glError_and_warn(0,"RGBA & GL_UNSIGNED_SHORT 4444 glReadPixels failed");
+	if (check_buffer_RGBA_4444()==PIGLIT_FAIL) {
+		fprintf(stderr, "RGBA GL_UNSIGNED_SHORT 4444 incorrect results\n");
+		piglit_report_result(PIGLIT_WARN);
+	}
+
+	clear_buffer();
+	glReadPixels(0,0,WIDTH,HEIGHT,GL_ALPHA, GL_UNSIGNED_BYTE, &buffer);
+	check_for_glError_and_warn(0,"ALPHA & GL_UNSIGNED_BTYE glReadPixels failed");
+	if (check_buffer_ALPHA()==PIGLIT_FAIL) {
+		fprintf(stderr, "ALPHA GL_UNSIGNED_BYTE incorrect results\n");
+		piglit_report_result(PIGLIT_WARN);
+	}
+
+	/* data is returned by this variation but it's completely goofed up 
+       will take issue upstream.
+	clear_buffer();
+	glReadPixels(0,0,WIDTH,HEIGHT,GL_ALPHA, GL_UNSIGNED_SHORT_5_6_5, &buffer);
+	check_for_glError_and_warn(0,"ALPHA & GL_UNSIGNED_SHORT 565 glReadPixels failed");
+	if (check_buffer_ALPHA()==PIGLIT_FAIL) {
+		fprintf(stderr, "ALPHA GL_UNSIGNED_BYTE incorrect results\n");
+		piglit_report_result(PIGLIT_WARN);
+	} 
+
+	clear_buffer();
+	glReadPixels(0,0,WIDTH,HEIGHT,GL_ALPHA, GL_UNSIGNED_SHORT_5_5_5_1, &buffer);
+	check_for_glError_and_warn(0,"ALPHA & GL_UNSIGNED_SHORT 5551 glReadPixels failed");
+	if (check_buffer_ALPHA()==PIGLIT_FAIL) {
+		fprintf(stderr, "ALPHA GL_UNSIGNED_SHORT 5551 incorrect results\n");
+		piglit_report_result(PIGLIT_WARN);
+	} 
+
+	clear_buffer();
+	glReadPixels(0,0,WIDTH,HEIGHT,GL_ALPHA, GL_UNSIGNED_SHORT_4_4_4_4, &buffer);
+	check_for_glError_and_warn(0,"ALPHA & GL_UNSIGNED_SHORT 4444 glReadPixels failed");
+	if (check_buffer_ALPHA()==PIGLIT_FAIL) {
+		fprintf(stderr, "ALPHA GL_UNSIGNED_SHORT 4444 incorrect results\n");
+		piglit_report_result(PIGLIT_WARN);
+	} */
+
+	clear_buffer();
+	glReadPixels(0,0,WIDTH,HEIGHT,GL_RGB, GL_UNSIGNED_BYTE, &buffer);
+	check_for_glError_and_warn(0,"RGB & GL_UNSIGNED_BTYE glReadPixels failed");
+	if (check_buffer_RGB() == PIGLIT_FAIL) {
+		fprintf(stderr, "RGB GL_UNSIGNED_BYTE incorrect results\n");
+		piglit_report_result(PIGLIT_WARN);
+	}
+
+	clear_buffer();
+	glReadPixels(0,0,WIDTH,HEIGHT,GL_RGB, GL_UNSIGNED_SHORT_5_6_5, &buffer);
+	check_for_glError_and_warn(0,"RGB & GL_UNSIGNED_BTYE glReadPixels failed");
+	if (check_buffer_RGB_565()==PIGLIT_FAIL) {
+		fprintf(stderr, "RGB GL_UNSIGNED_SHORT 565 incorrect results\n");
+		piglit_report_result(PIGLIT_WARN);
+	}
+
+	clear_buffer();
+	glReadPixels(0,0,WIDTH,HEIGHT,GL_RGB, GL_UNSIGNED_SHORT_5_5_5_1, &buffer);
+	check_for_glError_and_warn(0,"RGB & GL_UNSIGNED_SHORT 5551 glReadPixels failed");
+	if (check_buffer_RGBA_5551() == PIGLIT_FAIL) {
+		fprintf(stderr, "RGB GL_UNSIGNED_SHORT 5551 incorrect results\n");
+		piglit_report_result(PIGLIT_WARN);
+	}
+
+/*  this silently fails and doesn't modify the buffer
+	clear_buffer();
+	glReadPixels(0,0,WIDTH,HEIGHT,GL_RGB, GL_UNSIGNED_SHORT_4_4_4_4, &buffer);
+	check_for_glError_and_warn(0,"RGB & GL_UNSIGNED_SHORT 4444 glReadPixels failed");
+	if (check_buffer_RGB_4444() == PIGLIT_FAIL) {
+		fprintf(stderr, "RGB GL_UNSIGNED_SHORT 4444 incorrect results\n");
+		piglit_report_result(PIGLIT_WARN);
+	}
+*/
+
+	return PIGLIT_PASS;
+}
+
+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 (0!=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



More information about the Piglit mailing list