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 layers.
28 * Creates texture maps with different solid colors for each 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-levels";
46 static int tex_loc_2Darray
;
47 static int prog2Darray
;
50 * Views with varying minimum and number of layers 2D_ARRAY only
53 test_render_layers(void)
56 GLint width
= 16, height
= 16, layers
= 8;
58 GLint numLayers
[] = {7, 1, 2, 2};
64 glUseProgram(prog2Darray
);
65 glUniform1i(tex_loc_2Darray
, 0);
67 glGenTextures(1, &tex
);
68 glActiveTexture(GL_TEXTURE0
);
69 glBindTexture(GL_TEXTURE_2D_ARRAY
, tex
);
71 glTexParameteri(GL_TEXTURE_2D_ARRAY
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
72 glTexParameteri(GL_TEXTURE_2D_ARRAY
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
73 glTexParameteri(GL_TEXTURE_2D_ARRAY
, GL_TEXTURE_BASE_LEVEL
, 0);
74 glTexParameteri(GL_TEXTURE_2D_ARRAY
, GL_TEXTURE_MAX_LEVEL
, 0);
75 glTexStorage3D(GL_TEXTURE_2D_ARRAY
, 1, GL_RGBA8
, width
, height
, layers
);
77 /* load each array layer with a different color texture */
78 for (l
= 0; l
< layers
; l
++) {
79 GLubyte
*buf
= create_solid_image(width
, height
, 1, 4, l
);
82 glTexSubImage3D(GL_TEXTURE_2D_ARRAY
, 0, 0, 0, l
,
83 width
, height
, 1, GL_RGBA
,
84 GL_UNSIGNED_BYTE
, buf
);
90 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
92 /* create view of texture with restricted layers and draw quad */
93 /* using a single layer in the view range which varies every loop */
94 for (l
= 0; l
< ARRAY_SIZE(numLayers
); l
++) {
95 glGenTextures(1, &new_tex
);
96 glTextureView(new_tex
, GL_TEXTURE_2D_ARRAY
, tex
, GL_RGBA8
,
97 0, 1, l
, numLayers
[l
]);
99 glActiveTexture(GL_TEXTURE0
);
100 glBindTexture(GL_TEXTURE_2D_ARRAY
, new_tex
);
102 glClear(GL_COLOR_BUFFER_BIT
);
104 expectedLayer
= l
+ numLayers
[l
] - 1;
105 draw_3d_depth(-1.0, -1.0, 2.0, 2.0, expectedLayer
);
107 expected
[0] = Colors
[expectedLayer
][0] / 255.0;
108 expected
[1] = Colors
[expectedLayer
][1] / 255.0;
109 expected
[2] = Colors
[expectedLayer
][2] / 255.0;
112 p
= piglit_probe_pixel_rgba(piglit_width
/2, piglit_height
/2,
115 piglit_present_results();
118 printf("for view min layer=%d expectedLayer=%d expected color=%f %f %f\n",
119 l
, expectedLayer
, expected
[0], expected
[1], expected
[2]);
124 printf("%s: wrong color for view min layer %d, expectedLayer %d\n",
125 TestName
, l
, expectedLayer
);
128 glDeleteTextures(1, &new_tex
);
131 glDeleteTextures(1, &tex
);
137 const bool subtest_pass = (f); \
138 piglit_report_subtest_result(subtest_pass \
139 ? PIGLIT_PASS : PIGLIT_FAIL, \
141 pass = pass && subtest_pass; \
148 X(test_render_layers(), "2D layers rendering");
150 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
151 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
154 #ifdef PIGLIT_USE_OPENGL
155 #define GLSL_VERSION "130"
157 #define GLSL_VERSION "310 es"
160 static const char *vs
=
161 "#version " GLSL_VERSION
"\n"
162 "in vec4 piglit_vertex;\n"
163 "in vec2 piglit_texcoord;\n"
164 "out vec3 texcoord;\n"
166 " gl_Position = vec4(piglit_vertex.xy, 0.0, 1.0);\n"
167 " texcoord = vec3(piglit_texcoord, piglit_vertex.z);\n"
170 static const char *fs
=
171 "#version " GLSL_VERSION
"\n"
173 "precision highp float;\n"
174 "precision highp sampler2DArray;\n"
176 "in vec3 texcoord;\n"
177 "uniform sampler2DArray tex;\n"
180 " color = vec4(texture(tex, texcoord).xyz, 1.0);\n"
184 piglit_init(int argc
, char **argv
)
186 #ifdef PIGLIT_USE_OPENGL
187 piglit_require_extension("GL_ARB_texture_storage");
188 piglit_require_extension("GL_ARB_texture_view");
189 piglit_require_extension("GL_EXT_texture_array");
191 piglit_require_extension("GL_OES_texture_view");
194 prog2Darray
= piglit_build_simple_program(vs
, fs
);
195 tex_loc_2Darray
= glGetUniformLocation(prog2Darray
, "tex");