diff options
author | Pauli Nieminen <pauli.nieminen@linux.intel.com> | 2012-05-09 23:20:53 +0300 |
---|---|---|
committer | Pauli Nieminen <pauli.nieminen@linux.intel.com> | 2012-05-09 23:20:53 +0300 |
commit | b70e9fb9d6252dca934fcd42c981bcd1b60d01e9 (patch) | |
tree | 9f7ca78f0d5489912fcda0c12f04d087f115ee2d | |
parent | f3c8a67fa54a317482938dc9595e430f8b186c68 (diff) |
Random changes for piglitexternal_image3
-rw-r--r-- | src/glut_waffle/glut_waffle.h | 1 | ||||
-rw-r--r-- | tests/spec/oes_egl_image_external/oes_egl_external_image.c | 239 | ||||
-rw-r--r-- | tests/util/piglit-util-egl.c | 20 | ||||
-rw-r--r-- | tests/util/piglit-util-egl.h | 20 | ||||
-rw-r--r-- | tests/util/piglit-util.c | 1 |
5 files changed, 273 insertions, 8 deletions
diff --git a/src/glut_waffle/glut_waffle.h b/src/glut_waffle/glut_waffle.h index 007f8afa..5dabe58b 100644 --- a/src/glut_waffle/glut_waffle.h +++ b/src/glut_waffle/glut_waffle.h @@ -60,6 +60,7 @@ void glutInitDisplayMode(unsigned int mode); void glutInitWindowPosition(int x, int y); void glutInitWindowSize(int width, int height); void glutInit(int *argcp, char **argv); +void glutInitWithAPI(int *argcp, char **argv, int api_mask); int glutGet(int state); diff --git a/tests/spec/oes_egl_image_external/oes_egl_external_image.c b/tests/spec/oes_egl_image_external/oes_egl_external_image.c index 39fb0c8c..89f6dae0 100644 --- a/tests/spec/oes_egl_image_external/oes_egl_external_image.c +++ b/tests/spec/oes_egl_image_external/oes_egl_external_image.c @@ -24,18 +24,255 @@ */ #include "piglit-util.h" +#include "piglit-util-egl.h" -int piglit_width = 100, piglit_height = 100; +#include <EGL/egl.h> +#include <EGL/eglext.h> + +#include <assert.h> +#include <libgen.h> + +#define eglCreateImageKHR ((PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR")) +#define eglDestroyImageKHR ((PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR")) +#define glEGLImageTargetTexture2DOES ((PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES")) + +int piglit_width = 10, piglit_height = 10; int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE; +static EGLContext gl_ctx = EGL_NO_CONTEXT; + +#define TEXTURE_SIZE 128 + enum piglit_result piglit_display(void) { return PIGLIT_FAIL; } +static EGLContext +create_matching_egl_context(EGLDisplay dpy, EGLSurface draw, EGLSurface read) +{ + EGLContext ctx = EGL_NO_CONTEXT; + EGLint num_configs = 0, num_configs2 = 0, i; + EGLConfig *config; + const EGLint attribs[] = { + EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, + EGL_NONE, + }; + const EGLint ctx_attribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE, + }; + eglChooseConfig(dpy, attribs, NULL, 0, &num_configs); + piglit_expect_egl_error(EGL_SUCCESS, PIGLIT_FAIL); + config = calloc(num_configs, sizeof *config); + eglChooseConfig(dpy, attribs, config, num_configs, + &num_configs2); + piglit_expect_egl_error(EGL_SUCCESS, PIGLIT_FAIL); + if (num_configs2 < num_configs) + num_configs = num_configs2; + for (i = 0; i < num_configs; i++) { + ctx = eglCreateContext(dpy, config[i], + EGL_NO_CONTEXT, ctx_attribs); + piglit_expect_egl_error(EGL_SUCCESS, PIGLIT_FAIL); + + if (eglMakeCurrent(dpy, draw, read, ctx)) + break; + if (eglGetError() == EGL_SUCCESS) { + fprintf(stderr, "eglMakeCurrent failed without" + "error\n"); + piglit_report_result(PIGLIT_FAIL); + } + eglDestroyContext(dpy, ctx); + piglit_expect_egl_error(EGL_SUCCESS, PIGLIT_FAIL); + ctx = EGL_NO_CONTEXT; + } + if (ctx == EGL_NO_CONTEXT) { + fprintf(stderr, "Couldn't find OpenGL capable context " + "matching the surface. Number of " + "configs %d\n", num_configs); + } + free(config); + return ctx; +} + +/* Create EGLImage using GL texture as source */ +static EGLImageKHR +create_egl_image(GLint type, unsigned color) +{ + GLuint tex; + GLenum format = GL_RGBA; + unsigned depth = 0; + char *data; + unsigned mask; + int i; + EGLImageKHR image; + EGLSurface read = eglGetCurrentSurface(EGL_READ); + EGLSurface draw = eglGetCurrentSurface(EGL_DRAW); + EGLContext ctx = eglGetCurrentContext(); + EGLDisplay dpy = eglGetCurrentDisplay(); + piglit_expect_egl_error(EGL_SUCCESS, PIGLIT_FAIL); + + if (gl_ctx == EGL_NO_CONTEXT) { + gl_ctx = create_matching_egl_context(dpy, draw, read); + if (gl_ctx == EGL_NO_CONTEXT) + return EGL_NO_IMAGE_KHR; + } + + /* Make OpenGL context current */ + eglMakeCurrent(dpy, draw, read, gl_ctx); + piglit_expect_egl_error(EGL_SUCCESS, PIGLIT_FAIL); + + + switch (type) { + case GL_UNSIGNED_BYTE: + format = GL_RGBA; + depth = 4; + break; + case GL_UNSIGNED_SHORT_5_6_5: + format = GL_RGB; + depth = 2; + break; + case GL_UNSIGNED_SHORT_4_4_4_4: + format = GL_RGBA; + depth = 2; + break; + case GL_UNSIGNED_SHORT_5_5_5_1: + format = GL_RGBA; + depth = 2; + break; + default: + assert(!"unsupported data type\n"); + } + + data = malloc(TEXTURE_SIZE * TEXTURE_SIZE * depth); + + for (i = 0; i < TEXTURE_SIZE * TEXTURE_SIZE;) { + mask = 0xff; + do { + data[i] = (color & mask) >> (i % depth) * 8; + i++; + mask <<= 8; + } while (i % depth); + } + + glGenTextures(1, &tex); + piglit_check_gl_error(GL_NO_ERROR); + glBindTexture(GL_TEXTURE_2D, tex); + piglit_check_gl_error(GL_NO_ERROR); + glTexImage2D(GL_TEXTURE_2D, 0, format, TEXTURE_SIZE, TEXTURE_SIZE, + 0, format, type, data); + piglit_check_gl_error(GL_NO_ERROR); + + free(data); + image = eglCreateImageKHR(dpy, gl_ctx, EGL_GL_TEXTURE_2D_KHR, + (EGLClientBuffer)(uintptr_t)tex, NULL); + piglit_expect_egl_error(EGL_SUCCESS, PIGLIT_FAIL); + if (image == EGL_NO_IMAGE_KHR) + fprintf(stderr, "%s:%d: No image create\n", + basename(strdup(__FILE__)), __LINE__); + + glDeleteTextures(1, &tex); + piglit_check_gl_error(GL_NO_ERROR); + + /* Return back to test context */ + eglMakeCurrent(dpy, draw, read, ctx); + piglit_expect_egl_error(EGL_SUCCESS, PIGLIT_FAIL); + return image; +} + +#define check_tex_parami(param, expected) \ + _check_tex_parami(param, expected, __FILE__, __LINE__) +static bool +_check_tex_parami(GLenum param, GLint expected, const char *file, + const int line) +{ + GLint val = ~0; + bool r = true; + glGetTexParameteriv(GL_TEXTURE_EXTERNAL_OES, param, &val); + if (val != expected) { + fprintf(stderr, "%s:%d: Texture parameter is %s 0x%x.\n" + "Expected value is %s 0x%x.\n", + file, line, + piglit_get_gl_enum_name(val), val, + piglit_get_gl_enum_name(expected), expected); + r = false; + } + if (!piglit_check_gl_error(GL_NO_ERROR)) + r = false; + return r; +} + +#define try_set_tex_parami(param, val, expected) \ + _try_set_tex_parami(param, val, expected, __FILE__, __LINE__) +static bool +_try_set_tex_parami(GLenum param, GLint val, GLint expected, + const char *file, const int line) +{ + bool r = true; + glTexParameteri(GL_TEXTURE_EXTERNAL_OES, param, val); + if (!piglit_check_gl_error(expected)) { + r = false; + fprintf(stderr, "%s:%d: \n", basename(strdup(file)), line); + } + return r; +} + void piglit_init(int argc, char **argv) { + GLuint tex; + EGLImageKHR image; + int pass = 1; piglit_require_extension("GL_OES_EGL_image_external"); + + /* Test uses GL texture as portable source for image */ + piglit_require_egl_extension(eglGetCurrentDisplay(), "KHR_gl_texture_2D_image"); + + /* Bind image to external texture */ + glGenTextures(1, &tex); + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex); + /* Check for texture parameter defaults */ + + pass = check_tex_parami(GL_TEXTURE_MAG_FILTER, GL_LINEAR) && pass; + pass = check_tex_parami(GL_TEXTURE_MIN_FILTER, GL_LINEAR) && pass; + pass = check_tex_parami(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) && pass; + pass = check_tex_parami(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE) && pass; + + /* Try setting texture parameters */ + pass = try_set_tex_parami(GL_TEXTURE_MAG_FILTER, GL_NEAREST, GL_NO_ERROR) && pass; + pass = try_set_tex_parami(GL_TEXTURE_MAG_FILTER, GL_LINEAR, GL_NO_ERROR) && pass; + pass = try_set_tex_parami(GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST, GL_INVALID_ENUM) && pass; + pass = try_set_tex_parami(GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_LINEAR, GL_INVALID_ENUM) && pass; + pass = try_set_tex_parami(GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST, GL_INVALID_ENUM) && pass; + pass = try_set_tex_parami(GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR, GL_INVALID_ENUM) && pass; + + pass = try_set_tex_parami(GL_TEXTURE_MIN_FILTER, GL_NEAREST, GL_NO_ERROR) && pass; + pass = try_set_tex_parami(GL_TEXTURE_MIN_FILTER, GL_LINEAR, GL_NO_ERROR) && pass; + pass = try_set_tex_parami(GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST, GL_INVALID_ENUM) && pass; + pass = try_set_tex_parami(GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR, GL_INVALID_ENUM) && pass; + pass = try_set_tex_parami(GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST, GL_INVALID_ENUM) && pass; + pass = try_set_tex_parami(GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR, GL_INVALID_ENUM) && pass; + + pass = try_set_tex_parami(GL_TEXTURE_MIN_FILTER, GL_NEAREST, GL_NO_ERROR) && pass; + image = create_egl_image(GL_UNSIGNED_BYTE, 0xFF00FF00); + pass = image != EGL_NO_IMAGE_KHR && pass; + + /* Test delivery data to the image. */ + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, image); + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + /* Test special sampling rules */ + + /* Test that modifications aren't allowed */ + eglDestroyImageKHR(eglGetCurrentDisplay(), image); + piglit_expect_egl_error(EGL_SUCCESS, PIGLIT_FAIL); + glDeleteTextures(1, &tex); + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + if (pass) + piglit_report_result(PIGLIT_PASS); + else + piglit_report_result(PIGLIT_FAIL); } diff --git a/tests/util/piglit-util-egl.c b/tests/util/piglit-util-egl.c index 7725da3e..0fb6051a 100644 --- a/tests/util/piglit-util-egl.c +++ b/tests/util/piglit-util-egl.c @@ -28,6 +28,8 @@ #include <waffle/waffle.h> +#include <libgen.h> + const char* piglit_get_egl_error_name(EGLint error) { #define CASE(x) case x: return #x; switch (error) { @@ -53,35 +55,41 @@ const char* piglit_get_egl_error_name(EGLint error) { #undef CASE } -void piglit_expect_egl_error(EGLint expected_error, enum piglit_result result) +void _piglit_expect_egl_error(EGLint expected_error, enum piglit_result result, + const char *file, const int line) { EGLint actual_error; + char *file_copy; actual_error = eglGetError(); if (actual_error == expected_error) { return; } + file_copy = strdup(file); + /* * If the lookup of the error's name is successful, then print * Unexpected EGL error: NAME 0xHEX * Else, print * Unexpected EGL error: 0xHEX */ - printf("Unexpected EGL error: %s 0x%x\n", + printf("%s:%d: Unexpected EGL error: %s 0x%x\n", + basename(file_copy), line, piglit_get_egl_error_name(actual_error), actual_error); + free(file_copy); /* Print the expected error, but only if an error was really expected. */ if (expected_error != EGL_SUCCESS) { printf("Expected EGL error: %s 0x%x\n", - piglit_get_gl_error_name(expected_error), expected_error); + piglit_get_egl_error_name(expected_error), expected_error); } piglit_report_result(result); } bool -piglit_is_egl_extension_supported(Display *dpy, const char *name) +piglit_is_egl_extension_supported(EGLDisplay dpy, const char *name) { const char *const egl_extension_list = eglQueryString(dpy, EGL_EXTENSIONS); @@ -90,7 +98,7 @@ piglit_is_egl_extension_supported(Display *dpy, const char *name) } void -piglit_require_egl_extension(Display *dpy, const char *name) +piglit_require_egl_extension(EGLDisplay dpy, const char *name) { if (glutGetPlatform() != WAFFLE_PLATFORM_X11_EGL && glutGetPlatform() != WAFFLE_PLATFORM_ANDROID) { @@ -106,7 +114,7 @@ piglit_require_egl_extension(Display *dpy, const char *name) void -piglit_require_egl_version(Display *dpy, int major, int minor) +piglit_require_egl_version(EGLDisplay dpy, int major, int minor) { int eglMajor; int eglMinor; diff --git a/tests/util/piglit-util-egl.h b/tests/util/piglit-util-egl.h index 1fa68e57..a0f1f99e 100644 --- a/tests/util/piglit-util-egl.h +++ b/tests/util/piglit-util-egl.h @@ -48,7 +48,25 @@ const char* piglit_get_egl_error_name(EGLint error); * * If you expect no error, then set \code expected_error = EGL_SUCCESS \endcode. */ -void piglit_expect_egl_error(EGLint expected_error, enum piglit_result result); +#define piglit_expect_egl_error(expected_error, result) \ + _piglit_expect_egl_error(expected_error, result, __FILE__, __LINE__) +void _piglit_expect_egl_error(EGLint expected_error, enum piglit_result result, + const char *func, const int line); + +/** + * \brief Check if a EGL extension is supported. + */ +bool piglit_is_egl_extension_supported(EGLDisplay dpy, const char *name); + +/** + * \brief Require EGL extension for a test. + */ +void piglit_require_egl_extension(EGLDisplay dpy, const char *name); + +/** + * \brief Require EGL version for a test + */ +void piglit_require_egl_version(EGLDisplay dpy, int major, int minor); #ifdef __cplusplus } /* end extern "C" */ diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c index 7c60b34f..fd6bc2c4 100644 --- a/tests/util/piglit-util.c +++ b/tests/util/piglit-util.c @@ -40,6 +40,7 @@ #endif #include "piglit-util.h" +#include "glut_waffle/glut_waffle.h" #if defined(_WIN32) |