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
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
24 #include "piglit-util-egl.h"
25 #include "piglit-util-gl.h"
28 * @file egl-ext_egl_image_storage.c
31 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config
.supports_gl_es_version
= 31;
35 PIGLIT_GL_TEST_CONFIG_END
48 glGetTexLevelParameteriv(GL_TEXTURE_2D
, 0, GL_TEXTURE_WIDTH
, &width
);
49 glGetTexLevelParameteriv(GL_TEXTURE_2D
, 0, GL_TEXTURE_HEIGHT
, &height
);
51 float *expect
= piglit_rgbw_image(GL_RGBA
, width
, height
, true,
52 GL_UNSIGNED_NORMALIZED
);
53 unsigned hf
= width
/ 2;
54 unsigned color_stride
= hf
* 4; // one color width in image
55 unsigned box
= color_stride
* hf
; // one color box
58 float *g
= expect
+ color_stride
;
59 float *b
= expect
+ 2 * box
;
60 float *w
= b
+ color_stride
;
64 /* Verify texture contents by probing each color box. */
65 pass
= piglit_probe_texel_rect_rgba(GL_TEXTURE_2D
, 0, 0, 0, hf
, hf
, r
) && pass
;
66 pass
= piglit_probe_texel_rect_rgba(GL_TEXTURE_2D
, 0, hf
, 0, hf
, hf
, g
) && pass
;
67 pass
= piglit_probe_texel_rect_rgba(GL_TEXTURE_2D
, 0, 0, hf
, hf
, hf
, b
) && pass
;
68 pass
= piglit_probe_texel_rect_rgba(GL_TEXTURE_2D
, 0, hf
, hf
, hf
, hf
, w
) && pass
;
75 test_invalid_params(EGLImageKHR egl_image
)
77 const int none_attr
[] = { GL_NONE
};
78 const int some_attr
= GL_ONE
;
80 /* "If <attrib_list> is neither NULL nor a pointer to the value
81 * GL_NONE, the error INVALID_VALUE is generated."
83 glEGLImageTargetTexStorageEXT(GL_TEXTURE_2D
, egl_image
, &some_attr
);
84 if (!piglit_check_gl_error(GL_INVALID_VALUE
)) {
85 piglit_report_result(PIGLIT_FAIL
);
88 /* "If <image> is NULL, the error INVALID_VALUE is generated." */
89 glEGLImageTargetTexStorageEXT(GL_TEXTURE_2D
, 0x0, none_attr
);
90 if (!piglit_check_gl_error(GL_INVALID_VALUE
)) {
91 piglit_report_result(PIGLIT_FAIL
);
94 /* "If the GL is unable to specify a texture object using the supplied
95 * eglImageOES <image> (if, for example, <image> refers to a
96 * multisampled eglImageOES, or <target> is GL_TEXTURE_2D but <image>
97 * contains a cube map), the error INVALID_OPERATION is generated.
99 glEGLImageTargetTexStorageEXT(GL_TEXTURE_3D
, egl_image
, none_attr
);
100 if (!piglit_check_gl_error(GL_INVALID_OPERATION
)) {
101 piglit_report_result(PIGLIT_FAIL
);
106 piglit_init(int argc
, char **argv
)
108 piglit_require_extension("GL_EXT_EGL_image_storage");
110 PFNEGLCREATEIMAGEKHRPROC peglCreateImageKHR
= NULL
;
111 peglCreateImageKHR
= (PFNEGLCREATEIMAGEKHRPROC
)
112 eglGetProcAddress("eglCreateImageKHR");
113 if (!peglCreateImageKHR
) {
114 fprintf(stderr
, "eglCreateImageKHR missing\n");
115 piglit_report_result(PIGLIT_SKIP
);
118 PFNEGLDESTROYIMAGEKHRPROC peglDestroyImageKHR
= NULL
;
119 peglDestroyImageKHR
= (PFNEGLDESTROYIMAGEKHRPROC
)
120 eglGetProcAddress("eglDestroyImageKHR");
121 if (!peglDestroyImageKHR
) {
122 fprintf(stderr
, "eglDestroyImageKHR missing\n");
123 piglit_report_result(PIGLIT_SKIP
);
126 /* Require EGL_MESA_platform_surfaceless extension. */
127 const char *exts
= eglQueryString(EGL_NO_DISPLAY
, EGL_EXTENSIONS
);
128 if (!strstr(exts
, "EGL_MESA_platform_surfaceless"))
129 piglit_report_result(PIGLIT_SKIP
);
134 dpy
= piglit_egl_get_default_display(EGL_PLATFORM_SURFACELESS_MESA
);
136 if (!eglInitialize(dpy
, &major
, &minor
))
137 piglit_report_result(PIGLIT_FAIL
);
139 piglit_require_egl_extension(dpy
, "EGL_MESA_configless_context");
141 EGLint ctx_attr
[] = { EGL_CONTEXT_CLIENT_VERSION
, 2, EGL_NONE
};
143 eglCreateContext(dpy
, EGL_NO_CONFIG_KHR
, EGL_NO_CONTEXT
,
145 if (ctx
== EGL_NO_CONTEXT
) {
146 fprintf(stderr
, "could not create EGL context\n");
147 piglit_report_result(PIGLIT_FAIL
);
150 eglMakeCurrent(dpy
, EGL_NO_SURFACE
, EGL_NO_SURFACE
, ctx
);
152 /* Create a texture. */
153 GLuint texture_a
= piglit_rgbw_texture(GL_RGBA
, 256, 256, true, true,
155 glBindTexture(GL_TEXTURE_2D
, texture_a
);
157 /* Create EGLImage from texture. */
158 EGLint attribs
[] = { EGL_NONE
};
159 EGLImageKHR egl_image
;
160 egl_image
= peglCreateImageKHR(dpy
, ctx
, EGL_GL_TEXTURE_2D
,
161 (EGLClientBuffer
) (intptr_t) texture_a
,
164 fprintf(stderr
, "failed to create ImageKHR\n");
165 piglit_report_result(PIGLIT_FAIL
);
168 /* Create another texture. */
170 glGenTextures(1, &texture_b
);
171 glBindTexture(GL_TEXTURE_2D
, texture_b
);
173 const int none_attr
[] = { GL_NONE
};
175 /* Specify texture from EGLImage, invalid parameters. */
176 test_invalid_params(egl_image
);
178 /* Specify texture from EGLImage, valid params. */
179 glEGLImageTargetTexStorageEXT(GL_TEXTURE_2D
, egl_image
, none_attr
);
180 if (!piglit_check_gl_error(GL_NO_ERROR
))
181 piglit_report_result(PIGLIT_FAIL
);
183 if (!verify_rgbw_texture())
184 piglit_report_result(PIGLIT_FAIL
);
186 /* Expected to be immutable. */
187 GLint immutable_format
;
188 glGetTexParameteriv(GL_TEXTURE_2D
, GL_TEXTURE_IMMUTABLE_FORMAT
,
190 if (immutable_format
!= 1)
191 piglit_report_result(PIGLIT_FAIL
);
193 /* If OES_texture_view supported, attempt to create a view. */
194 if (piglit_is_extension_supported("GL_OES_texture_view")) {
196 glGenTextures(1, &texture_c
);
197 glTextureViewOES(texture_c
, GL_TEXTURE_2D
, texture_b
, GL_RGBA
,
199 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
200 fprintf(stderr
, "failed to create textureview!\n");
201 piglit_report_result(PIGLIT_FAIL
);
204 glDeleteTextures(1, &texture_c
);
207 glDeleteTextures(1, &texture_a
);
208 glDeleteTextures(1, &texture_b
);
209 peglDestroyImageKHR(dpy
, egl_image
);
211 piglit_report_result(PIGLIT_PASS
);