summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPauli Nieminen <pauli.nieminen@linux.intel.com>2012-05-29 14:14:17 +0300
committerPauli Nieminen <pauli.nieminen@linux.intel.com>2012-05-31 19:22:31 +0300
commitb62bdf756766c4e82a9cb169f8dd255680f369d5 (patch)
treee8b966455060500b73a31cd8292cebbcdde3d5b3
parent21b5d494f0e4d87793658eb2c9973582ce0c8215 (diff)
khr_gl_texture_image: Test for image creatin from GL textureegl_and_gles_dispatch_v3
Signed-off-by: Pauli Nieminen <pauli.nieminen@linux.intel.com>
-rw-r--r--tests/spec/CMakeLists.txt1
-rw-r--r--tests/spec/khr_gl_texture_image/CMakeLists.gl.txt15
-rw-r--r--tests/spec/khr_gl_texture_image/CMakeLists.gles1.txt15
-rw-r--r--tests/spec/khr_gl_texture_image/CMakeLists.gles2.txt15
-rw-r--r--tests/spec/khr_gl_texture_image/CMakeLists.txt3
-rw-r--r--tests/spec/khr_gl_texture_image/khr_gl_texture_image.c250
6 files changed, 299 insertions, 0 deletions
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index a0186d3c..2907a8e2 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -52,3 +52,4 @@ add_subdirectory (arb_draw_buffers)
add_subdirectory (oes_draw_texture)
add_subdirectory (arb_blend_func_extended)
add_subdirectory (ext_unpack_subimage)
+add_subdirectory (khr_gl_texture_image)
diff --git a/tests/spec/khr_gl_texture_image/CMakeLists.gl.txt b/tests/spec/khr_gl_texture_image/CMakeLists.gl.txt
new file mode 100644
index 00000000..7de22f1a
--- /dev/null
+++ b/tests/spec/khr_gl_texture_image/CMakeLists.gl.txt
@@ -0,0 +1,15 @@
+#add_definitions(-DSOURCE_DIR="${piglit_SOURCE_DIR}/")
+
+include_directories(
+ ${OPENGL_INCLUDE_PATH}
+ )
+
+link_libraries(
+ piglitutil
+ )
+
+piglit_add_executable(khr_gl_texture_image
+ khr_gl_texture_image.c
+ )
+
+# vim: ft=cmake:
diff --git a/tests/spec/khr_gl_texture_image/CMakeLists.gles1.txt b/tests/spec/khr_gl_texture_image/CMakeLists.gles1.txt
new file mode 100644
index 00000000..8f84e902
--- /dev/null
+++ b/tests/spec/khr_gl_texture_image/CMakeLists.gles1.txt
@@ -0,0 +1,15 @@
+#add_definitions(-DSOURCE_DIR="${piglit_SOURCE_DIR}/")
+
+include_directories(
+ ${OPENGL_INCLUDE_PATH}
+ )
+
+link_libraries(
+ piglitutil_gles1
+ )
+
+piglit_add_executable(khr_gl_texture_image_gles1
+ khr_gl_texture_image.c
+ )
+
+# vim: ft=cmake:
diff --git a/tests/spec/khr_gl_texture_image/CMakeLists.gles2.txt b/tests/spec/khr_gl_texture_image/CMakeLists.gles2.txt
new file mode 100644
index 00000000..df5a63bc
--- /dev/null
+++ b/tests/spec/khr_gl_texture_image/CMakeLists.gles2.txt
@@ -0,0 +1,15 @@
+#add_definitions(-DSOURCE_DIR="${piglit_SOURCE_DIR}/")
+
+include_directories(
+ ${OPENGL_INCLUDE_PATH}
+ )
+
+link_libraries(
+ piglitutil_gles2
+ )
+
+piglit_add_executable(khr_gl_texture_image_gles2
+ khr_gl_texture_image.c
+ )
+
+# vim: ft=cmake:
diff --git a/tests/spec/khr_gl_texture_image/CMakeLists.txt b/tests/spec/khr_gl_texture_image/CMakeLists.txt
new file mode 100644
index 00000000..d9d41f22
--- /dev/null
+++ b/tests/spec/khr_gl_texture_image/CMakeLists.txt
@@ -0,0 +1,3 @@
+if(OPENGL_egl_LIBRARY)
+ piglit_include_target_api()
+endif(OPENGL_egl_LIBRARY)
diff --git a/tests/spec/khr_gl_texture_image/khr_gl_texture_image.c b/tests/spec/khr_gl_texture_image/khr_gl_texture_image.c
new file mode 100644
index 00000000..57908f5b
--- /dev/null
+++ b/tests/spec/khr_gl_texture_image/khr_gl_texture_image.c
@@ -0,0 +1,250 @@
+/*
+ * Copyright © 2012 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.
+ *
+ * Author: Pauli Nieminen <pauli.nieminen@linux.intel.com>
+ */
+
+#include "piglit-util.h"
+#include "piglit-util-egl.h"
+
+#include <assert.h>
+#include <libgen.h>
+
+int piglit_width = 100, piglit_height = 100;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
+
+static EGLContext gl_ctx = EGL_NO_CONTEXT;
+
+#define TEXTURE_SIZE 128
+
+static EGLContext
+create_matching_gl_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_NONE,
+ };
+ EGLenum api = eglQueryAPI();
+ 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;
+
+ eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ eglBindAPI(EGL_OPENGL_API);
+
+ 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, "piglit_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;
+ }
+ eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ eglBindAPI(api);
+ 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(GLuint *tex, GLint type, unsigned color)
+{
+ GLenum format = GL_RGBA;
+ EGLImageKHR image;
+ EGLSurface read = eglGetCurrentSurface(EGL_READ);
+ EGLSurface draw = eglGetCurrentSurface(EGL_DRAW);
+ EGLContext ctx = eglGetCurrentContext();
+ EGLDisplay dpy = eglGetCurrentDisplay();
+ EGLenum api = eglQueryAPI();
+ piglit_expect_egl_error(EGL_SUCCESS, PIGLIT_FAIL);
+
+ if (gl_ctx == EGL_NO_CONTEXT) {
+ gl_ctx = create_matching_gl_context(dpy, draw, read);
+ if (gl_ctx == EGL_NO_CONTEXT)
+ return EGL_NO_IMAGE_KHR;
+ }
+
+ /* Make OpenGL context current */
+ eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ eglBindAPI(EGL_OPENGL_API);
+ eglMakeCurrent(dpy, draw, read, gl_ctx);
+ piglit_expect_egl_error(EGL_SUCCESS, PIGLIT_FAIL);
+
+ *tex = piglit_rgbw_texture(format, TEXTURE_SIZE, TEXTURE_SIZE,
+ GL_TRUE, GL_TRUE, GL_UNSIGNED_NORMALIZED);
+
+ piglit_check_gl_error(GL_NO_ERROR);
+
+ 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__);
+
+ /* Return back to test context */
+ eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ eglBindAPI(api);
+ eglMakeCurrent(dpy, draw, read, ctx);
+ piglit_expect_egl_error(EGL_SUCCESS, PIGLIT_FAIL);
+ return image;
+}
+#if 0
+#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_2D, 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;
+}
+#endif
+
+#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_2D, param, val);
+ if (!piglit_check_gl_error(expected)) {
+ r = false;
+ fprintf(stderr, "%s:%d: \n", basename(strdup(file)), line);
+ }
+ return r;
+}
+
+enum piglit_result
+piglit_display(void)
+{
+ static const float red[] = {1.0, 0.0, 0.0, 1.0};
+ static const float green[] = {0.0, 1.0, 0.0, 1.0};
+ static const float blue[] = {0.0, 0.0, 1.0, 1.0};
+ static const float white[] = {1.0, 1.0, 1.0, 1.0};
+
+ GLuint tex, orig_tex;
+ EGLImageKHR image;
+ int pass = 1;
+
+ glGenTextures(1, &tex);
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+ glBindTexture(GL_TEXTURE_2D, tex);
+
+ /* Set nearest filter */
+ pass = try_set_tex_parami(GL_TEXTURE_MAG_FILTER, GL_NEAREST, GL_NO_ERROR) && pass;
+ pass = try_set_tex_parami(GL_TEXTURE_MIN_FILTER, GL_NEAREST, GL_NO_ERROR) && pass;
+
+ image = create_egl_image(&orig_tex, 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_2D, image);
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ /* Test sampling */
+ piglit_use_shader(PIGLIT_SHADER_TEX);
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ glBindTexture(GL_TEXTURE_2D, orig_tex);
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ glClear(GL_COLOR_BUFFER_BIT);
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ piglit_draw_rect_tex(-1, -1, 2, 2,
+ 0, 0, 1.0, 1.0);
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ pass = piglit_probe_pixel_rgba(piglit_width * 1 / 4,
+ piglit_height * 1 / 4,
+ red) && pass;
+ pass = piglit_probe_pixel_rgba(piglit_width * 3 / 4,
+ piglit_height * 1 / 4,
+ green) && pass;
+ pass = piglit_probe_pixel_rgba(piglit_width * 1 / 4,
+ piglit_height * 3 / 4,
+ blue) && pass;
+ pass = piglit_probe_pixel_rgba(piglit_width * 3 / 4,
+ piglit_height * 3 / 4,
+ white) && pass;
+
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+ /* Test modifications to source texture */
+ /* Test modifications to target texture */
+
+ eglDestroyImageKHR(eglGetCurrentDisplay(), image);
+ piglit_expect_egl_error(EGL_SUCCESS, PIGLIT_FAIL);
+ glDeleteTextures(1, &tex);
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+ glDeleteTextures(1, &orig_tex);
+ pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+ piglit_present_results();
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ piglit_require_egl_extension("KHR_gl_texture_2D_image");
+}