2 * Copyright © 2015 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
21 * DEALINGS IN THE SOFTWARE.
25 * \file generatetexturemipmaps.c
26 * Verify the side-effect-free operation of glGenerateTextureMipmap
28 * After calling glGenerateTextureMipmap, there are 3 things that need to be
31 * 1. The texture bindings have not been modified.
33 * 2. Textures not passed to glGenerateTextureMipmap have not had their data
36 * 3. The texture that was passed to glGenerateTextureMipmap has the correct
37 * data in its mipmaps.
40 #include "piglit-util-gl.h"
42 PIGLIT_GL_TEST_CONFIG_BEGIN
44 config
.supports_gl_core_version
= 31;
45 config
.supports_gl_compat_version
= 20;
47 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
|
48 PIGLIT_GL_VISUAL_DOUBLE
;
49 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
51 PIGLIT_GL_TEST_CONFIG_END
53 /* 2x2 block of red pixels. */
54 static const float red
[2 * 2 * 4] = {
55 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0,
56 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0
59 /* 4x4 block of green pixels. */
60 static const float green
[4 * 4 * 4] = {
61 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
62 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
63 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
64 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
65 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
66 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
67 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
68 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0
71 /* 4x4 block of blue pixels. */
72 static const float blue
[4 * 4 * 4] = {
73 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0,
74 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0,
75 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0,
76 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0,
77 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0,
78 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0,
79 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0,
80 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0
84 piglit_init(int argc
, char **argv
)
91 piglit_require_extension("GL_ARB_direct_state_access");
93 /* Create two textures. Populate both with full mipmap stacks.
94 * Ensure that the data for levels > 0 is not the data that would be
95 * generated by glGenerateMipmap or glGenerateTextureMipmap.
97 glGenTextures(2, tex
);
99 for (i
= 0; i
<= 1; i
++) {
100 const float *const base_color
= (i
== 0) ? blue
: green
;
102 glActiveTexture(GL_TEXTURE0
+ i
);
103 glBindTexture(GL_TEXTURE_2D
, tex
[i
]);
104 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, 4, 4, 0, GL_RGBA
,
105 GL_FLOAT
, base_color
);
106 glTexImage2D(GL_TEXTURE_2D
, 1, GL_RGBA8
, 2, 2, 0, GL_RGBA
,
108 glTexImage2D(GL_TEXTURE_2D
, 2, GL_RGBA8
, 1, 1, 0, GL_RGBA
,
110 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
113 /* Generate the mipmap stack for the texture that is not currently
114 * bound to unit 0 while unit 0 is the active unit.
116 glActiveTexture(GL_TEXTURE0
);
117 glGenerateTextureMipmap(tex
[1]);
118 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
120 /* Verify that the correct textures are still bound to the correct
123 for (i
= 0; i
<= 1; i
++) {
124 glActiveTexture(GL_TEXTURE0
+ i
);
125 glGetIntegerv(GL_TEXTURE_BINDING_2D
, (GLint
*) &bound
);
126 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
128 if (bound
!= tex
[i
]) {
130 "Wrong texture bound to unit %u. Got %d, "
131 "but expected %d (other texture is %d).\n",
132 i
, bound
, tex
[i
], tex
[1 - i
]);
137 /* Verify that each texture has the correct data in levels > 0.
139 * For the texture bound to unit 0 (which was not passed to
140 * glGenerateTextureMipmap), this should be the original red color.
142 * For the texture bound to unit 1 (which was passed to
143 * glGenerateTextureMipmap), this should be green generated from the
146 for (i
= 0; i
<= 1; i
++) {
147 const float *const level_color
= (i
== 0) ? red
: green
;
149 glActiveTexture(GL_TEXTURE0
+ i
);
150 printf("Check level 1 of texture %u...\n", i
);
151 pass
= piglit_probe_texel_rect_rgba(GL_TEXTURE_2D
, 1,
153 level_color
) && pass
;
154 printf("Check level 2 of texture %u...\n", i
);
155 pass
= piglit_probe_texel_rect_rgba(GL_TEXTURE_2D
, 2,
157 level_color
) && pass
;
160 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);