2 * Copyright © 2010 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
26 * Test of ATI_envmap_bumpmap texture combiners.
29 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config
.supports_gl_compat_version
= 10;
37 config
.window_width
= TEXSIZE
*2;
38 config
.window_height
= TEXSIZE
*2;
39 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
40 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
42 PIGLIT_GL_TEST_CONFIG_END
44 static GLenum tex_unit
, bump_unit
;
48 draw_rect_multitex(float x
, float y
, float w
, float h
,
49 float tx
, float ty
, float tw
, float th
)
79 glVertexPointer(4, GL_FLOAT
, 0, verts
);
80 glEnableClientState(GL_VERTEX_ARRAY
);
82 glClientActiveTexture(GL_TEXTURE0
);
83 glTexCoordPointer(2, GL_FLOAT
, 0, tex
);
84 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
86 glClientActiveTexture(GL_TEXTURE1
);
87 glTexCoordPointer(2, GL_FLOAT
, 0, tex
);
88 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
90 glDrawArrays(GL_QUADS
, 0, 4);
92 glDisableClientState(GL_VERTEX_ARRAY
);
94 glClientActiveTexture(GL_TEXTURE0
);
95 glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
97 glClientActiveTexture(GL_TEXTURE1
);
98 glDisableClientState(GL_TEXTURE_COORD_ARRAY
);
104 GLboolean pass
= GL_TRUE
;
107 float bump_matrix
[4] = {1.0, 0.0, 0.0, 1.0};
108 float red
[4] = {1.0, 0.0, 0.0, 1.0};
109 float green
[4] = {0.0, 1.0, 0.0, 1.0};
110 float blue
[4] = {0.0, 0.0, 1.0, 1.0};
111 float white
[4] = {1.0, 1.0, 1.0, 1.0};
112 float bumpdata
[TEXSIZE
][TEXSIZE
][2];
114 /* First: the base texture. */
115 tex
= piglit_rgbw_texture(GL_RGBA
, TEXSIZE
, TEXSIZE
,
116 GL_FALSE
, GL_FALSE
, GL_UNSIGNED_NORMALIZED
);
117 glActiveTexture(tex_unit
);
118 glEnable(GL_TEXTURE_2D
);
119 glBindTexture(GL_TEXTURE_2D
, tex
);
121 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_COMBINE
);
122 glTexEnvf(GL_TEXTURE_ENV
, GL_COMBINE_RGB
, GL_REPLACE
);
123 glTexEnvf(GL_TEXTURE_ENV
, GL_SOURCE0_RGB
, GL_TEXTURE
);
125 /* Second: the bumpmap. */
126 glGenTextures(1, &bump
);
127 glActiveTexture(bump_unit
);
128 glEnable(GL_TEXTURE_2D
);
129 glBindTexture(GL_TEXTURE_2D
, bump
);
131 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
132 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
133 glTexEnvf(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_COMBINE
);
134 glTexEnvf(GL_TEXTURE_ENV
, GL_COMBINE_RGB
, GL_BUMP_ENVMAP_ATI
);
135 glTexEnvf(GL_TEXTURE_ENV
, GL_BUMP_TARGET_ATI
, tex_unit
);
137 /* The bump map we use is going to end up rotating texels CCW. */
138 for (y
= 0; y
< TEXSIZE
; y
++) {
139 for (x
= 0; x
< TEXSIZE
; x
++) {
140 if (y
< TEXSIZE
/ 2) {
141 if (x
< TEXSIZE
/ 2) {
142 bumpdata
[y
][x
][0] = 0.0;
143 bumpdata
[y
][x
][1] = 0.5;
145 bumpdata
[y
][x
][0] = -0.5;
146 bumpdata
[y
][x
][1] = 0.0;
149 if (x
< TEXSIZE
/ 2) {
150 bumpdata
[y
][x
][0] = 0.5;
151 bumpdata
[y
][x
][1] = 0.0;
153 bumpdata
[y
][x
][0] = 0.0;
154 bumpdata
[y
][x
][1] = -0.5;
160 glTexImage2D(GL_TEXTURE_2D
, 0, GL_DU8DV8_ATI
, TEXSIZE
, TEXSIZE
, 0,
161 GL_DUDV_ATI
, GL_FLOAT
, bumpdata
);
163 glTexBumpParameterfvATI(GL_BUMP_ROT_MATRIX_ATI
, bump_matrix
);
165 draw_rect_multitex(-1, -1, 2, 2,
168 pass
= pass
&& piglit_probe_rect_rgba(0,
173 pass
= pass
&& piglit_probe_rect_rgba(piglit_width
/ 2,
178 pass
= pass
&& piglit_probe_rect_rgba(0,
183 pass
= pass
&& piglit_probe_rect_rgba(piglit_width
/ 2,
189 piglit_present_results();
191 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
195 piglit_init(int argc
, char **argv
)
197 int size
, num_units
, *units
;
199 GLboolean found_unit_1
;
201 piglit_require_extension("GL_ATI_envmap_bumpmap");
203 glGetTexBumpParameterivATI(GL_BUMP_ROT_MATRIX_SIZE_ATI
, &size
);
205 printf("GL_BUMP_ROT_MATRIX_SIZE_ATI %d < 4\n", size
);
206 piglit_report_result(PIGLIT_FAIL
);
209 printf("What does GL_BUMP_ROT_MATRIX_SIZE_ATI = %d even mean?\n",
211 piglit_report_result(PIGLIT_SKIP
);
214 glGetTexBumpParameterivATI(GL_BUMP_NUM_TEX_UNITS_ATI
, &num_units
);
216 printf("GL_BUMP_NUM_TEX_UNITS_ATI %d < 4\n", num_units
);
217 piglit_report_result(PIGLIT_FAIL
);
220 units
= malloc(num_units
* sizeof(int));
221 glGetTexBumpParameterivATI(GL_BUMP_TEX_UNITS_ATI
, units
);
222 found_unit_1
= GL_FALSE
;
223 for (i
= 0; i
< num_units
; i
++) {
224 if (units
[i
] < GL_TEXTURE0
) {
225 printf("Bad unit in GL_BUMP_TEX_UNITS_ATI: 0x%x\n",
227 piglit_report_result(PIGLIT_FAIL
);
229 if (units
[i
] == GL_TEXTURE1
)
230 found_unit_1
= GL_TRUE
;
235 printf("Implementation doesn't support bumpmapping unit 1.\n");
236 piglit_report_result(PIGLIT_SKIP
);
239 tex_unit
= GL_TEXTURE0
;
240 bump_unit
= GL_TEXTURE1
;