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 levels.
28 * Creates texture maps with different solid colors for each level,
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";
47 #ifdef PIGLIT_USE_OPENGL
48 #define GLSL_VERSION "130"
50 #define GLSL_VERSION "310 es"
53 static const char *vs
=
54 "#version " GLSL_VERSION
"\n"
55 "in vec4 piglit_vertex;\n"
56 "in vec2 piglit_texcoord;\n"
57 "out vec2 texcoord;\n"
59 " gl_Position = piglit_vertex;\n"
60 " texcoord = piglit_texcoord;\n"
63 static const char *fs
=
64 "#version " GLSL_VERSION
"\n"
66 "precision highp float;\n"
67 "precision highp sampler2D;\n"
70 "uniform sampler2D tex;\n"
73 " color = texture(tex, texcoord);\n"
78 * Texture views with varying minimum and number of levels, 2D only
81 test_render_levels(void)
84 GLint width
= 4096, height
= 4096, levels
=13;
85 GLuint numLevels
[] = {3,2,2,1};
92 glGenTextures(1, &tex
);
93 glBindTexture(GL_TEXTURE_2D
, tex
);
95 glTexStorage2D(GL_TEXTURE_2D
, levels
, GL_RGBA8
, width
, height
);
96 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
97 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
99 /* load each mipmap with a different color texture */
100 for (l
= 0; l
< levels
; l
++) {
101 GLubyte
*buf
= create_solid_image(width
, height
, 1, 4, l
);
104 glTexSubImage2D(GL_TEXTURE_2D
, l
, 0, 0, width
, height
,
105 GL_RGBA
, GL_UNSIGNED_BYTE
, buf
);
115 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
117 /* create view of texture with restricted levels and draw quad */
118 /* using smallest mip level in the view range which varies every loop */
119 for (l
= 0; l
< ARRAY_SIZE(numLevels
); l
++) {
120 glGenTextures(1, &new_tex
);
121 glTextureView(new_tex
, GL_TEXTURE_2D
, tex
, GL_RGBA8
, l
,
123 glBindTexture(GL_TEXTURE_2D
, new_tex
);
124 glActiveTexture(GL_TEXTURE0
);
125 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, levels
-1);
127 glClear(GL_COLOR_BUFFER_BIT
);
129 piglit_draw_rect_tex(-1.0, -1.0, 2.0/(float) (l
+2),
130 2.0/ (float) (l
+2), 0.0, 0.0, 1.0, 1.0);
132 expectedLevel
= l
+ numLevels
[l
] - 1;
133 expected
[0] = Colors
[expectedLevel
][0] / 255.0;
134 expected
[1] = Colors
[expectedLevel
][1] / 255.0;
135 expected
[2] = Colors
[expectedLevel
][2] / 255.0;
138 p
= piglit_probe_pixel_rgba(piglit_width
/(2*(l
+3)),
139 piglit_height
/(2*(l
+3)), expected
);
141 piglit_present_results();
146 glGetTexParameteriv(GL_TEXTURE_2D
,
147 GL_TEXTURE_BASE_LEVEL
, ¶m
);
148 printf("for view min level=%d base_level=%d exp color=%f %f %f\n",
149 l
, param
, expected
[0], expected
[1], expected
[2]);
150 glGetTexParameteriv(GL_TEXTURE_2D
,
151 GL_TEXTURE_MAX_LEVEL
, ¶m
);
152 printf("max_level=%d\n", param
);
153 glGetTexParameteriv(GL_TEXTURE_2D
,
154 GL_TEXTURE_VIEW_MIN_LEVEL
, ¶m
);
155 printf("view min_level=%d\n", param
);
156 glGetTexParameteriv(GL_TEXTURE_2D
,
157 GL_TEXTURE_VIEW_NUM_LEVELS
, ¶m
);
158 printf("view num_level=%d\n", param
);
159 glGetTexParameteriv(GL_TEXTURE_2D
,
160 GL_TEXTURE_IMMUTABLE_LEVELS
,
162 printf("immutable levels=%d\n", param
);
168 printf("%s: wrong color for view min level %d, expectedLevel %d\n",
169 TestName
, l
, expectedLevel
);
172 glDeleteTextures(1, &new_tex
);
175 glDeleteTextures(1, &tex
);
181 const bool subtest_pass = (f); \
182 piglit_report_subtest_result(subtest_pass \
183 ? PIGLIT_PASS : PIGLIT_FAIL, \
185 pass = pass && subtest_pass; \
192 X(test_render_levels(), "2D levels rendering");
194 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
195 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
199 piglit_init(int argc
, char **argv
)
202 #ifdef PIGLIT_USE_OPENGL
203 piglit_require_extension("GL_ARB_texture_storage");
204 piglit_require_extension("GL_ARB_texture_view");
206 piglit_require_extension("GL_OES_texture_view");
209 prog
= piglit_build_simple_program(vs
, fs
);