2 * Copyright © 2013 LunarG, Inc.
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
23 * Author: Jon Ashburn <jon@lunarg.com>
27 * Tests GL_ARB_texture_view rendering with various texture targets.
28 * Creates texture maps with different solid colors for each level or layer
29 * reads the framebuffer to ensure the rendered color is correct.
32 #include "piglit-util-gl.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config
.supports_gl_compat_version
= 30;
38 config
.supports_gl_es_version
= 31;
40 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
41 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
43 PIGLIT_GL_TEST_CONFIG_END
45 static const char *TestName
= "arb_texture_view-rendering-target";
46 static int prog3D
, prog2Darray
, prog2D
, prog1D
;
49 * Simple views of textures; test rendering with various texture view targets
52 test_render_with_targets(GLenum target
)
55 GLint width
= 128, height
= 64, depth
= 4, levels
= 8;
59 glGenTextures(1, &tex
);
60 glBindTexture(target
, tex
);
64 glTexStorage1D(target
, levels
, GL_RGBA8
, width
);
69 glTexStorage2D(target
, levels
, GL_RGBA8
, width
, height
);
73 case GL_TEXTURE_2D_ARRAY
:
74 glTexStorage3D(target
, levels
, GL_RGBA8
, width
, height
, depth
);
77 /* only handle subset of legal targets */
78 piglit_report_result(PIGLIT_FAIL
);
79 assert(!"Illegal target for test_render_with_targets()\n");
83 /* load each mipmap with a different color texture */
84 for (l
= 0; l
< levels
; l
++) {
85 GLubyte
*buf
= create_solid_image(width
, height
, depth
, 4, l
);
90 glTexSubImage1D(GL_TEXTURE_1D
, l
, 0, width
,
91 GL_RGBA
, GL_UNSIGNED_BYTE
, buf
);
94 glTexSubImage2D(GL_TEXTURE_2D
, l
, 0, 0, width
,
96 GL_UNSIGNED_BYTE
, buf
);
99 case GL_TEXTURE_2D_ARRAY
:
100 glTexSubImage3D(target
, l
, 0, 0, 0, width
,
101 height
, depth
, GL_RGBA
,
102 GL_UNSIGNED_BYTE
, buf
);
107 piglit_report_result(PIGLIT_FAIL
);
108 assert(!"create_solid_image() failed\n");
115 if (depth
> 1 && target
== GL_TEXTURE_3D
)
119 if (piglit_check_gl_error(GL_NO_ERROR
) == GL_FALSE
) {
120 printf("%s: Found gl errors prior to testing glTextureView\n",
122 glDeleteTextures(1, &tex
);
127 /* create view of texture and bind it to target */
128 glGenTextures(1, &newTex
);
129 glTextureView(newTex
, target
, tex
, GL_RGBA8
, 0, levels
, 0, 1);
130 glDeleteTextures(1, &tex
);
131 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
132 glActiveTexture(GL_TEXTURE0
);
133 glBindTexture(target
, newTex
);
135 /* draw a quad/line using each texture mipmap level */
136 glTexParameteri(target
, GL_TEXTURE_MIN_FILTER
,
137 GL_NEAREST_MIPMAP_NEAREST
);
138 glTexParameteri(target
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
139 for (l
= 0; l
< levels
; l
++) {
143 glTexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, l
);
144 glTexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, l
);
146 glClear(GL_COLOR_BUFFER_BIT
);
150 glUseProgram(prog1D
);
151 piglit_draw_rect_tex(-1.0, -1.0, 2.0, 2.0, 0.0, 0.0,
155 glUseProgram(prog2D
);
156 piglit_draw_rect_tex(-1.0, -1.0, 2.0, 2.0, 0.0, 0.0,
159 case GL_TEXTURE_2D_ARRAY
:
160 glUseProgram(prog2Darray
);
161 draw_3d_depth(-1.0, -1.0, 2.0, 2.0, l
);
164 glUseProgram(prog3D
);
165 draw_3d_depth(-1.0, -1.0, 2.0, 2.0, l
);
169 expected
[0] = Colors
[l
][0] / 255.0;
170 expected
[1] = Colors
[l
][1] / 255.0;
171 expected
[2] = Colors
[l
][2] / 255.0;
174 p
= piglit_probe_pixel_rgba(piglit_width
/2, piglit_height
/2,
177 piglit_present_results();
180 printf("for level=%d, target=%s, expected color=%f %f %f\n",
181 l
, piglit_get_gl_enum_name(target
), expected
[0],
182 expected
[1], expected
[2]);
187 printf("%s: wrong color for mipmap level %d\n",
192 glDeleteTextures(1, &newTex
);
199 const bool subtest_pass = (f); \
200 piglit_report_subtest_result(subtest_pass \
201 ? PIGLIT_PASS : PIGLIT_FAIL, \
203 pass = pass && subtest_pass; \
210 #ifdef PIGLIT_USE_OPENGL
211 X(test_render_with_targets(GL_TEXTURE_1D
), "1D view rendering");
213 X(test_render_with_targets(GL_TEXTURE_2D
), "2D view rendering");
214 X(test_render_with_targets(GL_TEXTURE_3D
), "3D view rendering");
215 X(test_render_with_targets(GL_TEXTURE_2D_ARRAY
),
216 "2D Array view rendering");
218 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
219 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
222 #ifdef PIGLIT_USE_OPENGL
223 #define GLSL_VERSION "130"
225 #define GLSL_VERSION "310 es"
228 static const char *vs
=
229 "#version " GLSL_VERSION
"\n"
230 "in vec4 piglit_vertex;\n"
231 "in vec2 piglit_texcoord;\n"
232 "out vec3 texcoord;\n"
234 " gl_Position = vec4(piglit_vertex.xy, 0.0, 1.0);\n"
235 " texcoord = vec3(piglit_texcoord, piglit_vertex.z);\n"
238 static const char *fs_3d
=
239 "#version " GLSL_VERSION
"\n"
241 "precision highp float;\n"
242 "precision highp sampler3D;\n"
244 "in vec3 texcoord;\n"
245 "uniform sampler3D tex;\n"
248 " color = vec4(texture(tex, texcoord).xyz, 1.0);\n"
251 static const char *fs_2darray
=
252 "#version " GLSL_VERSION
"\n"
254 "precision highp float;\n"
255 "precision highp sampler2DArray;\n"
257 "in vec3 texcoord;\n"
258 "uniform sampler2DArray tex;\n"
261 " color = vec4(texture(tex, texcoord).xyz, 1.0);\n"
264 static const char *fs_2d
=
265 "#version " GLSL_VERSION
"\n"
267 "precision highp float;\n"
268 "precision highp sampler2D;\n"
270 "in vec3 texcoord;\n"
271 "uniform sampler2D tex;\n"
274 " color = vec4(texture(tex, texcoord.xy).xyz, 1.0);\n"
277 #ifdef PIGLIT_USE_OPENGL
278 static const char *fs_1d
=
279 "#version " GLSL_VERSION
"\n"
280 "in vec3 texcoord;\n"
281 "uniform sampler1D tex;\n"
284 " color = vec4(texture(tex, texcoord.x).xyz, 1.0);\n"
289 piglit_init(int argc
, char **argv
)
291 #ifdef PIGLIT_USE_OPENGL
292 piglit_require_extension("GL_ARB_texture_storage");
293 piglit_require_extension("GL_ARB_texture_view");
294 piglit_require_extension("GL_EXT_texture_array");
296 piglit_require_extension("GL_OES_texture_view");
299 prog3D
= piglit_build_simple_program(vs
, fs_3d
);
300 prog2Darray
= piglit_build_simple_program(vs
, fs_2darray
);
301 prog2D
= piglit_build_simple_program(vs
, fs_2d
);
303 #ifdef PIGLIT_USE_OPENGL
304 prog1D
= piglit_build_simple_program(vs
, fs_1d
);