arb_copy_image: test copying of different mipmap levels of a texture
[piglit.git] / tests / egl / egl-gl_oes_egl_image.c
bloba1658598c5020962d179e751de22ee44441b32a9
1 /*
2 * Copyright © 2019 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 #include "piglit-util-egl.h"
25 #include "piglit-util-gl.h"
27 /**
28 * @file egl-gl_oes_egl_image.c
31 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config.supports_gl_es_version = 20;
35 PIGLIT_GL_TEST_CONFIG_END
37 /* dummy */
38 enum piglit_result
39 piglit_display(void)
41 return PIGLIT_FAIL;
44 void
45 piglit_init(int argc, char **argv)
47 piglit_require_extension("GL_OES_EGL_image");
49 PFNEGLCREATEIMAGEKHRPROC peglCreateImageKHR = NULL;
50 peglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)
51 eglGetProcAddress("eglCreateImageKHR");
52 if (!peglCreateImageKHR) {
53 fprintf(stderr, "eglCreateImageKHR missing\n");
54 piglit_report_result(PIGLIT_SKIP);
57 PFNEGLDESTROYIMAGEKHRPROC peglDestroyImageKHR = NULL;
58 peglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)
59 eglGetProcAddress("eglDestroyImageKHR");
60 if (!peglDestroyImageKHR) {
61 fprintf(stderr, "eglDestroyImageKHR missing\n");
62 piglit_report_result(PIGLIT_SKIP);
65 /* Require EGL_MESA_platform_surfaceless extension. */
66 const char *exts = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
67 if (!strstr(exts, "EGL_MESA_platform_surfaceless"))
68 piglit_report_result(PIGLIT_SKIP);
70 EGLint major, minor;
71 EGLDisplay dpy;
73 dpy = piglit_egl_get_default_display(EGL_PLATFORM_SURFACELESS_MESA);
75 if (!eglInitialize(dpy, &major, &minor))
76 piglit_report_result(PIGLIT_FAIL);
78 piglit_require_egl_extension(dpy, "EGL_MESA_configless_context");
80 EGLint ctx_attr[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
81 EGLContext ctx =
82 eglCreateContext(dpy, EGL_NO_CONFIG_KHR, EGL_NO_CONTEXT, ctx_attr);
83 if (ctx == EGL_NO_CONTEXT) {
84 fprintf(stderr, "could not create EGL context\n");
85 piglit_report_result(PIGLIT_FAIL);
88 eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
90 /* Create a texture. */
91 GLuint texture_a;
92 glGenTextures(1, &texture_a);
93 glBindTexture(GL_TEXTURE_2D, texture_a);
95 /* Setup 2 miplevels, and max level. */
96 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA,
97 GL_UNSIGNED_BYTE, NULL);
98 glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 128, 128, 0, GL_RGBA,
99 GL_UNSIGNED_BYTE, NULL);
100 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
102 if (!piglit_check_gl_error(GL_NO_ERROR))
103 piglit_report_result(PIGLIT_FAIL);
105 /* Create EGLImage from texture_a miplevel 1. */
106 EGLint attribs[] = { EGL_GL_TEXTURE_LEVEL_KHR, 1, EGL_NONE };
107 EGLImageKHR egl_image;
108 egl_image = peglCreateImageKHR(dpy, ctx, EGL_GL_TEXTURE_2D,
109 (EGLClientBuffer) (intptr_t) texture_a,
110 attribs);
111 if (!egl_image) {
112 fprintf(stderr, "failed to create ImageKHR\n");
113 piglit_report_result(PIGLIT_FAIL);
116 /* Create another texture. */
117 GLuint texture_b;
118 glGenTextures(1, &texture_b);
119 glBindTexture(GL_TEXTURE_2D, texture_b);
120 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
122 GLuint fbo;
123 glGenFramebuffers(1, &fbo);
124 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
125 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture_b, 0);
127 /* Specify texture from EGLImage but use wrong target. */
128 glEGLImageTargetTexture2DOES(GL_TEXTURE_CUBE_MAP_ARRAY, egl_image);
129 if (!piglit_check_gl_error(GL_INVALID_ENUM))
130 piglit_report_result(PIGLIT_FAIL);
132 /* Specify texture from EGLImage properly. */
133 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, egl_image);
135 GLint w, h;
136 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
137 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
139 /* Verify that we got the texture_a miplevel 1 dimensions. */
140 if (w != 128 || h != 128) {
141 fprintf(stderr, "expected 128x128 (miplevel 1), got %dx%d\n",
142 w, h);
143 piglit_report_result(PIGLIT_FAIL);
146 glBindFramebuffer(GL_FRAMEBUFFER, 0);
147 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
149 glBindFramebuffer(GL_FRAMEBUFFER, 0);
150 glDeleteFramebuffers(1, &fbo);
152 glDeleteTextures(1, &texture_a);
153 glDeleteTextures(1, &texture_b);
154 peglDestroyImageKHR(dpy, egl_image);
156 piglit_report_result(PIGLIT_PASS);