[Piglit] [PATCH 3/5] Add utility for EGL OpenGL ES 2.0 and desktop OpenGL
Shuang He
shuang.he at intel.com
Mon Nov 22 19:24:32 PST 2010
---
tests/util/CMakeLists.txt | 14 +
tests/util/piglit-egl-gl-framework.c | 99 ++++++
tests/util/piglit-egl-gl-framework.h | 31 ++
tests/util/piglit-egl-gles2-framework.c | 99 ++++++
tests/util/piglit-egl-gles2-framework.h | 31 ++
tests/util/piglit-gles2-util.c | 564 +++++++++++++++++++++++++++++++
tests/util/piglit-gles2-util.h | 107 ++++++
tests/util/piglit-shared-util.c | 94 -----
tests/util/piglit-util.c | 96 ++++++
9 files changed, 1041 insertions(+), 94 deletions(-)
create mode 100644 tests/util/piglit-egl-gl-framework.c
create mode 100644 tests/util/piglit-egl-gl-framework.h
create mode 100644 tests/util/piglit-egl-gles2-framework.c
create mode 100644 tests/util/piglit-egl-gles2-framework.h
create mode 100644 tests/util/piglit-gles2-util.c
create mode 100644 tests/util/piglit-gles2-util.h
diff --git a/tests/util/CMakeLists.txt b/tests/util/CMakeLists.txt
index 615f137..6ffdaeb 100644
--- a/tests/util/CMakeLists.txt
+++ b/tests/util/CMakeLists.txt
@@ -4,6 +4,7 @@ include_directories(
${OPENGL_INCLUDE_PATH}
${GLUT_INCLUDE_DIR}
${piglit_SOURCE_DIR}/tests/util
+ ${piglit_SOURCE_DIR}/tests/util/glut_egl
${GLEW_INCLUDE_DIR}
)
@@ -38,4 +39,17 @@ add_library (piglitutil
IF(OPENGL_egl_LIBRARY)
add_subdirectory (glut_egl)
+ add_library (piglitegl_gles2util
+ piglit-egl-gles2-framework.c
+ piglit-gles2-util.c
+ piglit-shared-util.c
+ )
+ add_library (piglitegl_glutil
+ fdo-bitmap.c
+ piglit-egl-gl-framework.c
+ piglit-util.c
+ piglit-shared-util.c
+ )
+ target_link_libraries(piglitegl_gles2util ${OPENGL_gles2_LIBRARY} piglitglutegl_x11)
+ target_link_libraries(piglitegl_glutil ${OPENGL_gl_LIBRARY} piglitglutegl_x11)
ENDIF(OPENGL_egl_LIBRARY)
diff --git a/tests/util/piglit-egl-gl-framework.c b/tests/util/piglit-egl-gl-framework.c
new file mode 100644
index 0000000..01cf56d
--- /dev/null
+++ b/tests/util/piglit-egl-gl-framework.c
@@ -0,0 +1,99 @@
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * 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.
+ */
+
+/**
+ * Simple test case framework for runing desktop OpenGL through EGL.
+ *
+ * \author Shuang He <shuang.he at intel.com>
+ */
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include "piglit-gles2-util.h"
+#include "piglit-egl-gl-framework.h"
+#include "glut_egl.h"
+
+int piglit_automatic = 0;
+static int piglit_window;
+static enum piglit_result result;
+
+static void
+display(void)
+{
+ result = piglit_display();
+
+ if (piglit_automatic) {
+ glutDestroyWindow(piglit_window);
+ piglit_report_result(result);
+ }
+}
+
+static void
+reshape(int w, int h)
+{
+ piglit_width = w;
+ piglit_height = h;
+
+ glViewport(0, 0, w, h);
+}
+
+int main(int argc, char *argv[])
+{
+ int j;
+
+ glutInit(argc, argv);
+
+ /* Find/remove "-auto" from the argument vector.
+ */
+ for (j = 1; j < argc; j++) {
+ if (!strcmp(argv[j], "-auto")) {
+ int i;
+
+ piglit_automatic = 1;
+
+ for (i = j + 1; i < argc; i++) {
+ argv[i - 1] = argv[i];
+ }
+ argc--;
+ j--;
+ }
+ }
+ glutInitWindowSize(piglit_width, piglit_height);
+ glut_eglInitAPIMask(GLUT_EGL_OPENGL_BIT);
+ glutCreateWindow(argv[0]);
+
+ glutDisplayFunc(display);
+ glutReshapeFunc(reshape);
+ glutKeyboardFunc((GLUT_EGLkeyboardCB)piglit_escape_exit_key);
+
+ piglit_init(argc, argv);
+
+ glutMainLoop();
+
+ piglit_report_result(result);
+ /* UNREACHED */
+ return 0;
+}
diff --git a/tests/util/piglit-egl-gl-framework.h b/tests/util/piglit-egl-gl-framework.h
new file mode 100644
index 0000000..c3bdde9
--- /dev/null
+++ b/tests/util/piglit-egl-gl-framework.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright © 2009 Intel Corporation
+ *
+ * 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.
+ */
+
+extern int piglit_automatic;
+
+extern int piglit_window_mode;
+extern int piglit_width;
+extern int piglit_height;
+
+extern enum piglit_result piglit_display(void);
+extern void piglit_init(int argc, char **argv);
diff --git a/tests/util/piglit-egl-gles2-framework.c b/tests/util/piglit-egl-gles2-framework.c
new file mode 100644
index 0000000..336c881
--- /dev/null
+++ b/tests/util/piglit-egl-gles2-framework.c
@@ -0,0 +1,99 @@
+/*
+ * Copyright © 2010 Intel Corporation
+ *
+ * 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.
+ */
+
+/**
+ * Simple test case framework for running OpenGL ES 2.0 through EGL.
+ *
+ * \author Shuang He <shuang.he at intel.com>
+ */
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include "piglit-gles2-util.h"
+#include "piglit-egl-gles2-framework.h"
+#include "glut_egl.h"
+
+int piglit_automatic = 0;
+static int piglit_window;
+static enum piglit_result result;
+
+static void
+display(void)
+{
+ result = piglit_display();
+
+ if (piglit_automatic) {
+ glutDestroyWindow(piglit_window);
+ piglit_report_result(result);
+ }
+}
+
+static void
+reshape(int w, int h)
+{
+ piglit_width = w;
+ piglit_height = h;
+
+ glViewport(0, 0, w, h);
+}
+
+int main(int argc, char *argv[])
+{
+ int j;
+
+ glutInit(argc, argv);
+
+ /* Find/remove "-auto" from the argument vector.
+ */
+ for (j = 1; j < argc; j++) {
+ if (!strcmp(argv[j], "-auto")) {
+ int i;
+
+ piglit_automatic = 1;
+
+ for (i = j + 1; i < argc; i++) {
+ argv[i - 1] = argv[i];
+ }
+ argc--;
+ j--;
+ }
+ }
+ glutInitWindowSize(piglit_width, piglit_height);
+ glut_eglInitAPIMask(GLUT_EGL_OPENGL_ES2_BIT);
+ glutCreateWindow(argv[0]);
+
+ glutDisplayFunc(display);
+ glutReshapeFunc(reshape);
+ glutKeyboardFunc((GLUT_EGLkeyboardCB)piglit_escape_exit_key);
+
+ piglit_init(argc, argv);
+
+ glutMainLoop();
+
+ piglit_report_result(result);
+ /* UNREACHED */
+ return 0;
+}
diff --git a/tests/util/piglit-egl-gles2-framework.h b/tests/util/piglit-egl-gles2-framework.h
new file mode 100644
index 0000000..c3bdde9
--- /dev/null
+++ b/tests/util/piglit-egl-gles2-framework.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright © 2009 Intel Corporation
+ *
+ * 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.
+ */
+
+extern int piglit_automatic;
+
+extern int piglit_window_mode;
+extern int piglit_width;
+extern int piglit_height;
+
+extern enum piglit_result piglit_display(void);
+extern void piglit_init(int argc, char **argv);
diff --git a/tests/util/piglit-gles2-util.c b/tests/util/piglit-gles2-util.c
new file mode 100644
index 0000000..1c9c2d0
--- /dev/null
+++ b/tests/util/piglit-gles2-util.c
@@ -0,0 +1,564 @@
+/*
+ * Copyright (c) The Piglit project 2007
+ *
+ * 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
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL
+ * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS 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.
+ */
+
+#if defined(_MSC_VER)
+#include <windows.h>
+#endif
+
+#include <assert.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/stat.h>
+
+#include "piglit-gles2-util.h"
+
+
+int
+piglit_extension_supported(const char *name)
+{
+ static const GLubyte *extensions = NULL;
+ const GLubyte *start;
+ GLubyte *where, *terminator;
+
+ /* Extension names should not have spaces. */
+ where = (GLubyte *) strchr(name, ' ');
+ if (where || *name == '\0')
+ return 0;
+
+ if (!extensions) {
+ extensions = glGetString(GL_EXTENSIONS);
+ }
+ /* It takes a bit of care to be fool-proof about parsing the
+ OpenGL extensions string. Don't be fooled by sub-strings,
+ etc. */
+ start = extensions;
+ for (;;) {
+ /* If your application crashes in the strstr routine below,
+ you are probably calling glutExtensionSupported without
+ having a current window. Calling glGetString without
+ a current OpenGL context has unpredictable results.
+ Please fix your program. */
+ where = (GLubyte *) strstr((const char *) start, name);
+ if (!where)
+ break;
+ terminator = where + strlen(name);
+ if (where == start || *(where - 1) == ' ') {
+ if (*terminator == ' ' || *terminator == '\0') {
+ return 1;
+ }
+ }
+ start = terminator;
+ }
+ return 0;
+}
+
+void piglit_require_extension(const char *name)
+{
+ if (!piglit_extension_supported(name)) {
+ printf("Test requires %s\n", name);
+ piglit_report_result(PIGLIT_SKIP);
+ exit(1);
+ }
+}
+
+void piglit_require_not_extension(const char *name)
+{
+ if (piglit_extension_supported(name)) {
+ piglit_report_result(PIGLIT_SKIP);
+ exit(1);
+ }
+}
+
+static float tolerance[4] = { 0.01, 0.01, 0.01, 0.01 };
+
+void
+piglit_set_tolerance_for_bits(int rbits, int gbits, int bbits, int abits)
+{
+ int bits[4] = {rbits, gbits, bbits, abits};
+ int i;
+
+ for (i = 0; i < 4; i++) {
+ if (bits[i] < 2) {
+ /* Don't try to validate channels when there's only 1
+ * bit of precision (or none).
+ */
+ tolerance[i] = 1.0;
+ } else {
+ tolerance[i] = 3.0 / (1 << bits[i]);
+ }
+ }
+}
+
+/**
+ * Read a pixel from the given location and compare its RGBA value to the
+ * given expected values.
+ *
+ * Print a log message if the color value deviates from the expected value.
+ * \return true if the color values match, false otherwise
+ */
+int piglit_probe_pixel_rgba(int x, int y, const float* expected)
+{
+ GLubyte probe[4];
+ int i;
+ GLboolean pass = GL_TRUE;
+
+ glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, probe);
+
+ for(i = 0; i < 4; ++i) {
+ if (fabs(probe[i]/255.0 - expected[i]) > tolerance[i]) {
+ pass = GL_FALSE;
+ }
+ }
+
+ if (pass)
+ return 1;
+
+ printf("Probe at (%i,%i)\n", x, y);
+ printf(" Expected: %f %f %f %f\n", expected[0], expected[1], expected[2], expected[3]);
+ printf(" Observed: %f %f %f %f\n", probe[0]/255.0, probe[1]/255.0, probe[2]/255.0, probe[3]/255.0);
+
+ return 0;
+}
+
+int
+piglit_probe_rect_rgba(int x, int y, int w, int h, const float *expected)
+{
+ int i, j, p;
+ GLubyte *probe;
+ GLubyte *pixels = malloc(w*h*4*sizeof(GLubyte));
+
+ glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
+
+ for (j = 0; j < h; j++) {
+ for (i = 0; i < w; i++) {
+ probe = &pixels[(j*w+i)*4];
+
+ for (p = 0; p < 4; ++p) {
+ if (fabs(probe[p]/255.0 - expected[p]) >= tolerance[p]) {
+ printf("Probe at (%i,%i)\n", x+i, y+j);
+ printf(" Expected: %f %f %f %f\n",
+ expected[0], expected[1], expected[2], expected[3]);
+ printf(" Observed: %f %f %f %f\n",
+ probe[0]/255.0, probe[1]/255.0, probe[2]/255.0, probe[3]/255.0);
+
+ free(pixels);
+ return 0;
+ }
+ }
+ }
+ }
+
+ free(pixels);
+ return 1;
+}
+
+/**
+ * Read a pixel from the given location and compare its RGB value to the
+ * given expected values.
+ *
+ * Print a log message if the color value deviates from the expected value.
+ * \return true if the color values match, false otherwise
+ */
+int piglit_probe_pixel_rgb(int x, int y, const float* expected)
+{
+ GLubyte probe[3];
+ int i;
+ GLboolean pass = GL_TRUE;
+
+ glReadPixels(x, y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, probe);
+
+
+ for(i = 0; i < 3; ++i) {
+ if (fabs(probe[i]/255.0 - expected[i]) > tolerance[i]) {
+ pass = GL_FALSE;
+ }
+ }
+
+ if (pass)
+ return 1;
+
+ printf("Probe at (%i,%i)\n", x, y);
+ printf(" Expected: %f %f %f\n", expected[0], expected[1], expected[2]);
+ printf(" Observed: %f %f %f\n", probe[0]/255.0, probe[1]/255.0, probe[2]/255.0);
+
+ return 0;
+}
+
+int
+piglit_probe_rect_rgb(int x, int y, int w, int h, const float *expected)
+{
+ int i, j, p;
+ GLubyte *probe;
+ GLubyte *pixels = malloc(w*h*3*sizeof(GLubyte));
+
+ glReadPixels(x, y, w, h, GL_RGB, GL_UNSIGNED_BYTE, pixels);
+
+ for (j = 0; j < h; j++) {
+ for (i = 0; i < w; i++) {
+ probe = &pixels[(j*w+i)*3];
+
+ for (p = 0; p < 3; ++p) {
+ if (fabs(probe[p]/255.0 - expected[p]) >= tolerance[p]) {
+ printf("Probe at (%i,%i)\n", x+i, y+j);
+ printf(" Expected: %f %f %f\n",
+ expected[0], expected[1], expected[2]);
+ printf(" Observed: %f %f %f\n",
+ probe[0]/255.0, probe[1]/255.0, probe[2]/255.0);
+
+ free(pixels);
+ return 0;
+ }
+ }
+ }
+ }
+
+ free(pixels);
+ return 1;
+}
+
+void
+piglit_escape_exit_key(unsigned char key, int x, int y)
+{
+ (void) x;
+ (void) y;
+ switch (key) {
+ case 27:
+ exit(0);
+ break;
+ }
+}
+
+/**
+ * Convenience function to draw an axis-aligned rectangle.
+ */
+GLvoid
+piglit_draw_rect(float x, float y, float w, float h)
+{
+ float verts[4][4];
+
+ verts[0][0] = x;
+ verts[0][1] = y;
+ verts[0][2] = 0.0;
+ verts[0][3] = 1.0;
+ verts[1][0] = x + w;
+ verts[1][1] = y;
+ verts[1][2] = 0.0;
+ verts[1][3] = 1.0;
+ verts[2][0] = x;
+ verts[2][1] = y + h;
+ verts[2][2] = 0.0;
+ verts[2][3] = 1.0;
+ verts[3][0] = x + w;
+ verts[3][1] = y + h;
+ verts[3][2] = 0.0;
+ verts[3][3] = 1.0;
+
+ glVertexAttribPointer(PIGLIT_ATTRIB_POS, 4, GL_FLOAT, GL_FALSE, 0, verts);
+ glEnableVertexAttribArray(PIGLIT_ATTRIB_POS);
+
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ glDisableVertexAttribArray(PIGLIT_ATTRIB_POS);
+}
+
+
+/**
+ * Convenience function to draw an axis-aligned backfaced rectangle.
+ */
+GLvoid
+piglit_draw_rect_back(float x, float y, float w, float h)
+{
+ float verts[4][4];
+
+ verts[0][0] = x + w;
+ verts[0][1] = y + h;
+ verts[0][2] = 0.0;
+ verts[0][3] = 1.0;
+ verts[1][0] = x;
+ verts[1][1] = y + h;
+ verts[1][2] = 0.0;
+ verts[1][3] = 1.0;
+ verts[2][0] = x + w;
+ verts[2][1] = y;
+ verts[2][2] = 0.0;
+ verts[2][3] = 1.0;
+ verts[3][0] = x;
+ verts[3][1] = y;
+ verts[3][2] = 0.0;
+ verts[3][3] = 1.0;
+
+ glVertexAttribPointer(PIGLIT_ATTRIB_POS, 4, GL_FLOAT, GL_FALSE, 0, verts);
+ glEnableVertexAttribArray(PIGLIT_ATTRIB_POS);
+
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ glDisableVertexAttribArray(PIGLIT_ATTRIB_POS);
+}
+
+
+/**
+ * Convenience function to draw an axis-aligned rectangle.
+ */
+GLvoid
+piglit_draw_rect_z(float z, float x, float y, float w, float h)
+{
+ float verts[4][4];
+
+ verts[0][0] = x;
+ verts[0][1] = y;
+ verts[0][2] = z;
+ verts[0][3] = 1.0;
+ verts[1][0] = x + w;
+ verts[1][1] = y;
+ verts[1][2] = z;
+ verts[1][3] = 1.0;
+ verts[2][0] = x;
+ verts[2][1] = y + h;
+ verts[2][2] = z;
+ verts[2][3] = 1.0;
+ verts[3][0] = x + w;
+ verts[3][1] = y + h;
+ verts[3][2] = z;
+ verts[3][3] = 1.0;
+
+ glVertexAttribPointer(PIGLIT_ATTRIB_POS, 4, GL_FLOAT, GL_FALSE, 0, verts);
+ glEnableVertexAttribArray(PIGLIT_ATTRIB_POS);
+
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ glDisableVertexAttribArray(PIGLIT_ATTRIB_POS);
+}
+
+/**
+ * Convenience function to draw an axis-aligned rectangle
+ * with texture coordinates.
+ */
+GLvoid
+piglit_draw_rect_tex(float x, float y, float w, float h,
+ float tx, float ty, float tw, float th)
+{
+ float verts[4][4];
+ float tex[4][2];
+
+ verts[0][0] = x;
+ verts[0][1] = y;
+ verts[0][2] = 0.0;
+ verts[0][3] = 1.0;
+ tex[0][0] = tx;
+ tex[0][1] = ty;
+ verts[1][0] = x + w;
+ verts[1][1] = y;
+ verts[1][2] = 0.0;
+ verts[1][3] = 1.0;
+ tex[1][0] = tx + tw;
+ tex[1][1] = ty;
+ verts[2][0] = x;
+ verts[2][1] = y + h;
+ verts[2][2] = 0.0;
+ verts[2][3] = 1.0;
+ tex[2][0] = tx;
+ tex[2][1] = ty + th;
+ verts[3][0] = x + w;
+ verts[3][1] = y + h;
+ verts[3][2] = 0.0;
+ verts[3][3] = 1.0;
+ tex[3][0] = tx + tw;
+ tex[3][1] = ty + th;
+
+ glVertexAttribPointer(PIGLIT_ATTRIB_POS, 4, GL_FLOAT, GL_FALSE, 0, verts);
+ glVertexAttribPointer(PIGLIT_ATTRIB_TEX, 2, GL_FLOAT, GL_FALSE, 0, tex);
+ glEnableVertexAttribArray(PIGLIT_ATTRIB_POS);
+ glEnableVertexAttribArray(PIGLIT_ATTRIB_TEX);
+
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ glDisableVertexAttribArray(PIGLIT_ATTRIB_POS);
+ glDisableVertexAttribArray(PIGLIT_ATTRIB_TEX);
+}
+
+/**
+ * Generates a texture with the given internalFormat, w, h with a
+ * teximage of r, g, b w quadrants.
+ *
+ * Note that for compressed teximages, where the blocking would be
+ * problematic, we assign the whole layers at w == 4 to red, w == 2 to
+ * green, and w == 1 to blue.
+ */
+GLuint
+piglit_rgbw_texture(GLenum format, int w, int h, GLboolean mip,
+ GLboolean alpha)
+{
+ GLubyte *data;
+ int size, x, y, level;
+ GLuint tex;
+ GLubyte red[4] = {255, 0, 0, 0};
+ GLubyte green[4] = {0, 255, 0, 64};
+ GLubyte blue[4] = {0, 0, 255, 128};
+ GLubyte white[4] = {255, 255, 255, 255};
+
+ if (!alpha) {
+ red[3] = 255;
+ green[3] = 255;
+ blue[3] = 255;
+ white[3] = 255;
+ }
+
+ glGenTextures(1, &tex);
+ glBindTexture(GL_TEXTURE_2D, tex);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ if (mip) {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+ GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+ GL_LINEAR_MIPMAP_NEAREST);
+ } else {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+ GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+ GL_NEAREST);
+ }
+ data = malloc(w * h * 4 * sizeof(GLubyte));
+
+ /* XXX: Do we want non-square textures? Surely some day. */
+ assert(w == h);
+
+ for (level = 0, size = w; size > 0; level++, size >>= 1) {
+ for (y = 0; y < size; y++) {
+ for (x = 0; x < size; x++) {
+ const GLubyte *color;
+
+ if (x < size / 2 && y < size / 2)
+ color = red;
+ else if (y < size / 2)
+ color = green;
+ else if (x < size / 2)
+ color = blue;
+ else
+ color = white;
+
+ memcpy(data + (y * size + x) * 4, color,
+ 4 * sizeof(GLubyte));
+ }
+ }
+ glTexImage2D(GL_TEXTURE_2D, level,
+ format,
+ size, size, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, data);
+
+ if (!mip)
+ break;
+ }
+ free(data);
+ return tex;
+}
+
+
+/**
+ * Generate a checkerboard texture
+ *
+ * \param tex Name of the texture to be used. If \c tex is
+ * zero, a new texture name will be generated.
+ * \param level Mipmap level the checkerboard should be written to
+ * \param width Width of the texture image
+ * \param height Height of the texture image
+ * \param horiz_square_size Size of each checkerboard tile along the X axis
+ * \param vert_square_size Size of each checkerboard tile along the Y axis
+ * \param black RGBA color to be used for "black" tiles
+ * \param white RGBA color to be used for "white" tiles
+ *
+ * A texture with alternating black and white squares in a checkerboard
+ * pattern is generated. The texture data is written to LOD \c level of
+ * the texture \c tex.
+ *
+ * If \c tex is zero, a new texture created. This texture will have several
+ * texture parameters set to non-default values:
+ *
+ * - S and T wrap modes will be set to \c GL_CLAMP_TO_BORDER.
+ * - Border color will be set to { 1.0, 0.0, 0.0, 1.0 }.
+ * - Min and mag filter will be set to \c GL_NEAREST.
+ *
+ * \return
+ * Name of the texture. In addition, this texture will be bound to the
+ * \c GL_TEXTURE_2D target of the currently active texture unit.
+ */
+GLuint
+piglit_checkerboard_texture(GLuint tex, unsigned level,
+ unsigned width, unsigned height,
+ unsigned horiz_square_size,
+ unsigned vert_square_size,
+ const float *black, const float *white)
+{
+ unsigned i;
+ unsigned j;
+
+ GLubyte *const tex_data = malloc(width * height * (4 * sizeof(GLubyte)));
+ GLubyte *texel = tex_data;
+
+ for (i = 0; i < height; i++) {
+ const unsigned row = i / vert_square_size;
+
+ for (j = 0; j < width; j++) {
+ const unsigned col = j / horiz_square_size;
+
+ if ((row ^ col) & 1) {
+ texel[0] = white[0] * 255;
+ texel[1] = white[1] * 255;
+ texel[2] = white[2] * 255;
+ texel[3] = white[3] * 255;
+ } else {
+ texel[0] = black[0] * 255;
+ texel[1] = black[1] * 255;
+ texel[2] = black[2] * 255;
+ texel[3] = black[3] * 255;
+ }
+
+ texel += 4;
+ }
+ }
+
+
+ if (tex == 0) {
+ glGenTextures(1, &tex);
+
+ glBindTexture(GL_TEXTURE_2D, tex);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+ GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+ GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
+ GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
+ GL_CLAMP_TO_EDGE);
+ } else {
+ glBindTexture(GL_TEXTURE_2D, tex);
+ }
+
+ glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, width, height, 0, GL_RGBA,
+ GL_UNSIGNED_BYTE, tex_data);
+
+ return tex;
+}
diff --git a/tests/util/piglit-gles2-util.h b/tests/util/piglit-gles2-util.h
new file mode 100644
index 0000000..a04e281
--- /dev/null
+++ b/tests/util/piglit-gles2-util.h
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) The Piglit project 2007
+ *
+ * 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
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, 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 NON-INFRINGEMENT. IN NO EVENT SHALL
+ * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS 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.
+ */
+
+#if defined(_MSC_VER)
+#include <windows.h>
+
+typedef __int32 int32_t;
+typedef __int64 int64_t;
+typedef unsigned __int8 uint8_t;
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int64 uint64_t;
+#else
+#include <stdint.h>
+#endif
+
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <GLES2/gl2.h>
+
+#if defined(_MSC_VER)
+
+#define snprintf sprintf_s
+
+#define piglit_get_proc_address(x) wglGetProcAddress(x)
+#else
+#define piglit_get_proc_address(x) glutGetProcAddress(x)
+#endif
+
+enum piglit_result {
+ PIGLIT_SUCCESS,
+ PIGLIT_FAILURE,
+ PIGLIT_SKIP,
+ PIGLIT_WARN
+};
+
+enum pigilt_attrib_location {
+ PIGLIT_ATTRIB_POS,
+ PIGLIT_ATTRIB_TEX
+};
+
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
+
+extern const uint8_t fdo_bitmap[];
+extern const unsigned int fdo_bitmap_width;
+extern const unsigned int fdo_bitmap_height;
+
+int FindLine(const char *program, int position);
+void piglit_report_result(enum piglit_result result);
+void piglit_require_extension(const char *name);
+void piglit_require_not_extension(const char *name);
+int piglit_probe_pixel_rgb(int x, int y, const float* expected);
+int piglit_probe_pixel_rgba(int x, int y, const float* expected);
+int piglit_probe_rect_rgb(int x, int y, int w, int h, const float* expected);
+int piglit_probe_rect_rgba(int x, int y, int w, int h, const float* expected);
+
+GLuint piglit_compile_shader(GLenum target, char *filename);
+GLuint piglit_compile_shader_text(GLenum target, const char *text);
+GLboolean piglit_link_check_status(GLint prog);
+GLint piglit_link_simple_program(GLint vs, GLint fs);
+GLvoid piglit_draw_rect(float x, float y, float w, float h);
+GLvoid piglit_draw_rect_back(float x, float y, float w, float h);
+GLvoid piglit_draw_rect_z(float z, float x, float y, float w, float h);
+GLvoid piglit_draw_rect_tex(float x, float y, float w, float h,
+ float tx, float ty, float tw, float th);
+void piglit_escape_exit_key(unsigned char key, int x, int y);
+
+char *piglit_load_text_file(const char *file_name, unsigned *size);
+
+GLuint piglit_checkerboard_texture(GLuint tex, unsigned level,
+ unsigned width, unsigned height,
+ unsigned horiz_square_size, unsigned vert_square_size,
+ const float *black, const float *white);
+GLuint piglit_rgbw_texture(GLenum format, int w, int h, GLboolean mip,
+ GLboolean alpha);
+void piglit_set_tolerance_for_bits(int rbits, int gbits, int bbits, int abits);
+
+extern GLfloat cube_face_texcoords[6][4][3];
+extern const char *cube_face_names[6];
+extern const GLenum cube_face_targets[6];
+
+#ifndef HAVE_STRCHRNUL
+char *strchrnul(const char *s, int c);
+#endif
diff --git a/tests/util/piglit-shared-util.c b/tests/util/piglit-shared-util.c
index 15b63f8..612700e 100644
--- a/tests/util/piglit-shared-util.c
+++ b/tests/util/piglit-shared-util.c
@@ -300,100 +300,6 @@ GLint piglit_link_simple_program(GLint vs, GLint fs)
return prog;
}
-/**
- * Generates a texture with the given internalFormat, w, h with a
- * teximage of r, g, b w quadrants.
- *
- * Note that for compressed teximages, where the blocking would be
- * problematic, we assign the whole layers at w == 4 to red, w == 2 to
- * green, and w == 1 to blue.
- */
-GLuint
-piglit_rgbw_texture(GLenum format, int w, int h, GLboolean mip,
- GLboolean alpha)
-{
- GLfloat *data;
- int size, x, y, level;
- GLuint tex;
- float red[4] = {1.0, 0.0, 0.0, 0.0};
- float green[4] = {0.0, 1.0, 0.0, 0.25};
- float blue[4] = {0.0, 0.0, 1.0, 0.5};
- float white[4] = {1.0, 1.0, 1.0, 1.0};
-
- if (!alpha) {
- red[3] = 1.0;
- green[3] = 1.0;
- blue[3] = 1.0;
- white[3] = 1.0;
- }
-
- glGenTextures(1, &tex);
- glBindTexture(GL_TEXTURE_2D, tex);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- if (mip) {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
- GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
- GL_LINEAR_MIPMAP_NEAREST);
- } else {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
- GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
- GL_NEAREST);
- }
- data = malloc(w * h * 4 * sizeof(GLfloat));
-
- /* XXX: Do we want non-square textures? Surely some day. */
- assert(w == h);
-
- for (level = 0, size = w; size > 0; level++, size >>= 1) {
- for (y = 0; y < size; y++) {
- for (x = 0; x < size; x++) {
- const float *color;
-
- if (x < size / 2 && y < size / 2)
- color = red;
- else if (y < size / 2)
- color = green;
- else if (x < size / 2)
- color = blue;
- else
- color = white;
-
- switch (format) {
- case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
- case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
- case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
- case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
- case GL_COMPRESSED_RGB_FXT1_3DFX:
- case GL_COMPRESSED_RGBA_FXT1_3DFX:
- if (size == 4)
- color = red;
- else if (size == 2)
- color = green;
- else if (size == 1)
- color = blue;
- break;
- default:
- break;
- }
-
- memcpy(data + (y * size + x) * 4, color,
- 4 * sizeof(float));
- }
- }
- glTexImage2D(GL_TEXTURE_2D, level,
- format,
- size, size, 0,
- GL_RGBA, GL_FLOAT, data);
-
- if (!mip)
- break;
- }
- free(data);
- return tex;
-}
GLuint
piglit_depth_texture(GLenum internalformat, int w, int h, GLboolean mip)
diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index f485c35..f63ea9c 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -575,6 +575,102 @@ piglit_ortho_projection(int w, int h, GLboolean push)
}
/**
+ * Generates a texture with the given internalFormat, w, h with a
+ * teximage of r, g, b w quadrants.
+ *
+ * Note that for compressed teximages, where the blocking would be
+ * problematic, we assign the whole layers at w == 4 to red, w == 2 to
+ * green, and w == 1 to blue.
+ */
+GLuint
+piglit_rgbw_texture(GLenum format, int w, int h, GLboolean mip,
+ GLboolean alpha)
+{
+ GLfloat *data;
+ int size, x, y, level;
+ GLuint tex;
+ float red[4] = {1.0, 0.0, 0.0, 0.0};
+ float green[4] = {0.0, 1.0, 0.0, 0.25};
+ float blue[4] = {0.0, 0.0, 1.0, 0.5};
+ float white[4] = {1.0, 1.0, 1.0, 1.0};
+
+ if (!alpha) {
+ red[3] = 1.0;
+ green[3] = 1.0;
+ blue[3] = 1.0;
+ white[3] = 1.0;
+ }
+
+ glGenTextures(1, &tex);
+ glBindTexture(GL_TEXTURE_2D, tex);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ if (mip) {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+ GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+ GL_LINEAR_MIPMAP_NEAREST);
+ } else {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+ GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+ GL_NEAREST);
+ }
+ data = malloc(w * h * 4 * sizeof(GLfloat));
+
+ /* XXX: Do we want non-square textures? Surely some day. */
+ assert(w == h);
+
+ for (level = 0, size = w; size > 0; level++, size >>= 1) {
+ for (y = 0; y < size; y++) {
+ for (x = 0; x < size; x++) {
+ const float *color;
+
+ if (x < size / 2 && y < size / 2)
+ color = red;
+ else if (y < size / 2)
+ color = green;
+ else if (x < size / 2)
+ color = blue;
+ else
+ color = white;
+
+ switch (format) {
+ case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
+ case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
+ case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
+ case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
+ case GL_COMPRESSED_RGB_FXT1_3DFX:
+ case GL_COMPRESSED_RGBA_FXT1_3DFX:
+ if (size == 4)
+ color = red;
+ else if (size == 2)
+ color = green;
+ else if (size == 1)
+ color = blue;
+ break;
+ default:
+ break;
+ }
+
+ memcpy(data + (y * size + x) * 4, color,
+ 4 * sizeof(float));
+ }
+ }
+ glTexImage2D(GL_TEXTURE_2D, level,
+ format,
+ size, size, 0,
+ GL_RGBA, GL_FLOAT, data);
+
+ if (!mip)
+ break;
+ }
+ free(data);
+ return tex;
+}
+
+
+/**
* Generate a checkerboard texture
*
* \param tex Name of the texture to be used. If \c tex is
--
1.7.0.1
More information about the Piglit
mailing list