ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / ati_envmap_bumpmap / bump.c
blob6246d83d09a45f61273909a0a3a82acfb54c0ff1
1 /*
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
13 * Software.
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
21 * IN THE SOFTWARE.
24 /** @file bump.c
26 * Test of ATI_envmap_bumpmap texture combiners.
29 #include "piglit-util-gl.h"
31 #define TEXSIZE 32
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;
47 GLvoid
48 draw_rect_multitex(float x, float y, float w, float h,
49 float tx, float ty, float tw, float th)
51 float verts[4][4];
52 float tex[4][2];
54 verts[0][0] = x;
55 verts[0][1] = y;
56 verts[0][2] = 0.0;
57 verts[0][3] = 1.0;
58 tex[0][0] = tx;
59 tex[0][1] = ty;
60 verts[1][0] = x + w;
61 verts[1][1] = y;
62 verts[1][2] = 0.0;
63 verts[1][3] = 1.0;
64 tex[1][0] = tx + tw;
65 tex[1][1] = ty;
66 verts[2][0] = x + w;
67 verts[2][1] = y + h;
68 verts[2][2] = 0.0;
69 verts[2][3] = 1.0;
70 tex[2][0] = tx + tw;
71 tex[2][1] = ty + th;
72 verts[3][0] = x;
73 verts[3][1] = y + h;
74 verts[3][2] = 0.0;
75 verts[3][3] = 1.0;
76 tex[3][0] = tx;
77 tex[3][1] = ty + 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);
101 enum piglit_result
102 piglit_display(void)
104 GLboolean pass = GL_TRUE;
105 GLuint tex, bump;
106 int x, y;
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;
144 } else {
145 bumpdata[y][x][0] = -0.5;
146 bumpdata[y][x][1] = 0.0;
148 } else {
149 if (x < TEXSIZE / 2) {
150 bumpdata[y][x][0] = 0.5;
151 bumpdata[y][x][1] = 0.0;
152 } else {
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,
166 0, 0, 1, 1);
168 pass = pass && piglit_probe_rect_rgba(0,
170 piglit_width / 2,
171 piglit_height / 2,
172 blue);
173 pass = pass && piglit_probe_rect_rgba(piglit_width / 2,
175 piglit_width / 2,
176 piglit_height / 2,
177 red);
178 pass = pass && piglit_probe_rect_rgba(0,
179 piglit_height / 2,
180 piglit_width / 2,
181 piglit_height / 2,
182 white);
183 pass = pass && piglit_probe_rect_rgba(piglit_width / 2,
184 piglit_height / 2,
185 piglit_width / 2,
186 piglit_height / 2,
187 green);
189 piglit_present_results();
191 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
194 void
195 piglit_init(int argc, char **argv)
197 int size, num_units, *units;
198 int i;
199 GLboolean found_unit_1;
201 piglit_require_extension("GL_ATI_envmap_bumpmap");
203 glGetTexBumpParameterivATI(GL_BUMP_ROT_MATRIX_SIZE_ATI, &size);
204 if (size < 4) {
205 printf("GL_BUMP_ROT_MATRIX_SIZE_ATI %d < 4\n", size);
206 piglit_report_result(PIGLIT_FAIL);
208 if (size != 4) {
209 printf("What does GL_BUMP_ROT_MATRIX_SIZE_ATI = %d even mean?\n",
210 size);
211 piglit_report_result(PIGLIT_SKIP);
214 glGetTexBumpParameterivATI(GL_BUMP_NUM_TEX_UNITS_ATI, &num_units);
215 if (num_units < 1) {
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",
226 units[i]);
227 piglit_report_result(PIGLIT_FAIL);
229 if (units[i] == GL_TEXTURE1)
230 found_unit_1 = GL_TRUE;
232 free(units);
234 if (!found_unit_1) {
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;