Commit 5bf6514e authored by Shuang He's avatar Shuang He Committed by Kristian Høgsberg

Add utility for EGL OpenGL ES 2.0 and desktop OpenGL

parent c8463767
......@@ -4,6 +4,7 @@ include_directories(
${OPENGL_INCLUDE_PATH}
${GLUT_INCLUDE_DIR}
${piglit_SOURCE_DIR}/tests/util
${piglit_SOURCE_DIR}/tests/util/glut_egl
)
set (UTIL_SOURCES
......@@ -45,4 +46,19 @@ endif(UNIX)
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)
set_target_properties ( piglitegl_gles2util
PROPERTIES COMPILE_DEFINITIONS "PIGLIT_GLES2")
target_link_libraries(piglitegl_glutil ${OPENGL_gl_LIBRARY} piglitglutegl_x11)
ENDIF(OPENGL_egl_LIBRARY)
/*
* 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@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--;
}
}
glutInitDisplayMode(piglit_window_mode);
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;
}
/*
* 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);
/*
* 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@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--;
}
}
glutInitDisplayMode(piglit_window_mode);
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;
}
/*
* 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);
/*
* 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;
verts[0][2] = 0.0;
verts[0][3] = 1.0;
verts[1][0] = x;
verts[1][1] = y;
verts[1][2] = 0.0;
verts[1][3] = 1.0;
verts[2][0] = x + w;
verts[2][1] = y + h;
verts[2][2] = 0.0;
verts[2][3] = 1.0;
verts[3][0] = x;
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);
}
/**