2 * Copyright (c) VMware, 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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * Test texture unit state with respect to the different number of
28 * texture coord units, image units, combined units, etc.
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config
.supports_gl_compat_version
= 10;
37 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
39 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
41 PIGLIT_GL_TEST_CONFIG_END
45 /** random number for checking state */
46 static GLfloat Random
[MAX_UNITS
][4];
48 static GLint MaxTextureCoordUnits
;
49 static GLint MaxTextureVertexUnits
;
50 static GLint MaxTextureImageUnits
;
51 static GLint MaxTextureCombinedUnits
;
55 generate_random_numbers(void)
58 for (i
= 0; i
< ARRAY_SIZE(Random
); i
++) {
59 for (j
= 0; j
< 4; j
++) {
60 /* values in [0, 1] */
61 Random
[i
][j
] = (rand() % 1000) * .001;
68 equal4v(const GLfloat v1
[4], const GLfloat v2
[4])
70 return (v1
[0] == v2
[0] &&
78 equal16v(const GLfloat v1
[16], const GLfloat v2
[16])
81 for (i
= 0; i
< 16; i
++) {
90 report4v(const GLfloat exp
[4], const GLfloat act
[4])
92 printf("Expected (%g, %g, %g, %g) but found (%g, %g, %g, %g)\n",
93 exp
[0], exp
[1], exp
[2], exp
[3],
94 act
[0], act
[1], act
[2], act
[3]);
113 /* set current texcoords */
114 for (i
= 0; i
< MaxTextureCoordUnits
; i
++) {
115 glMultiTexCoord4fv(GL_TEXTURE0
+ i
, Random
[i
]);
118 /* query current texcoords */
119 for (i
= 0; i
< MaxTextureCoordUnits
; i
++) {
121 glActiveTexture(GL_TEXTURE0
+ i
);
122 glGetFloatv(GL_CURRENT_TEXTURE_COORDS
, v
);
123 if (!equal4v(Random
[i
], v
)) {
124 printf("Get GL_CURRENT_TEXTURE_COORDS, unit %d failed\n", i
);
125 report4v(Random
[i
], v
);
130 /* set raster pos to update raster tex coords */
133 for (i
= 0; i
< MaxTextureCoordUnits
; i
++) {
135 glActiveTexture(GL_TEXTURE0
+ i
);
136 glGetFloatv(GL_CURRENT_RASTER_TEXTURE_COORDS
, v
);
137 if (!equal4v(Random
[i
], v
)) {
138 printf("Get GL_CURRENT_RASTER_TEXTURE_COORDS, unit %d failed\n", i
);
139 report4v(Random
[i
], v
);
144 /* there should be no errors at this point */
145 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
149 if (!piglit_khr_no_error
) {
150 /* this should generate an error */
152 glActiveTexture(GL_TEXTURE0
+ MaxTextureCoordUnits
);
153 if (MaxTextureCoordUnits
== MaxTextureCombinedUnits
) {
154 /* INVALID_ENUM is expected */
155 if (!piglit_check_gl_error(GL_INVALID_ENUM
)) {
160 /* INVALID_OPERATION is expected */
161 glGetFloatv(GL_CURRENT_RASTER_TEXTURE_COORDS
, v
);
162 if (!piglit_check_gl_error(GL_INVALID_OPERATION
)) {
173 test_texture_matrix(void)
179 /* set tex matrices */
180 for (i
= 0; i
< MaxTextureCoordUnits
; i
++) {
181 glActiveTexture(GL_TEXTURE0
+ i
);
182 glMatrixMode(GL_TEXTURE
);
183 glLoadMatrixf((GLfloat
*) Random
+ (i
* 4) % 124);
187 for (i
= 0; i
< MaxTextureCoordUnits
; i
++) {
189 glActiveTexture(GL_TEXTURE0
+ i
);
190 glGetFloatv(GL_TEXTURE_MATRIX
, m
);
191 if (!equal16v((GLfloat
*) Random
+ (i
* 4) % 124, m
)) {
192 printf("Get texture matrix unit %d failed\n", i
);
197 /* there should be no errors at this point */
198 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
202 if (!piglit_khr_no_error
) {
203 /* this should generate an error */
205 glActiveTexture(GL_TEXTURE0
+ MaxTextureCoordUnits
);
206 if (MaxTextureCoordUnits
== MaxTextureCombinedUnits
) {
207 /* INVALID_ENUM is expected */
208 if (!piglit_check_gl_error(GL_INVALID_ENUM
)) {
213 /* INVALID_OPERATION is expected */
214 glGetFloatv(GL_TEXTURE_MATRIX
, m
);
215 if (!piglit_check_gl_error(GL_INVALID_OPERATION
)) {
226 test_texture_params(void)
228 GLuint tex
[MAX_UNITS
];
234 glGenTextures(MaxTextureCombinedUnits
, tex
);
236 /* set per-unit state */
237 for (i
= 0; i
< MaxTextureCombinedUnits
; i
++) {
238 glActiveTexture(GL_TEXTURE0
+ i
);
239 glBindTexture(GL_TEXTURE_2D
, tex
[i
]);
240 glTexParameterfv(GL_TEXTURE_2D
, GL_TEXTURE_BORDER_COLOR
, Random
[i
]);
243 /* check per-unit state */
244 for (i
= 0; i
< MaxTextureCombinedUnits
; i
++) {
246 glActiveTexture(GL_TEXTURE0
+ i
);
247 glBindTexture(GL_TEXTURE_2D
, tex
[i
]);
248 /* any per-unit state will do: */
249 glGetTexParameterfv(GL_TEXTURE_2D
, GL_TEXTURE_BORDER_COLOR
, v
);
250 if (!equal4v(v
, Random
[i
])) {
251 printf("Setting per-unit param state failed for unit %d\n", i
);
252 report4v(Random
[i
], v
);
257 /* there should be no errors at this point */
258 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
262 if (!piglit_khr_no_error
) {
263 maxUnit
= MAX2(MaxTextureCombinedUnits
, MaxTextureCoordUnits
);
265 /* this should generate an error */
266 glActiveTexture(GL_TEXTURE0
+ maxUnit
);
267 /* INVALID_ENUM is expected */
268 if (!piglit_check_gl_error(GL_INVALID_ENUM
)) {
278 test_texture_env(void)
280 /* Texture Environment state is fixed-function; not used by shaders */
285 /* set per-unit state */
286 for (i
= 0; i
< MaxTextureCoordUnits
; i
++) {
287 glActiveTexture(GL_TEXTURE0
+ i
);
288 glTexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, Random
[i
]);
289 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
294 /* check per-unit state */
295 for (i
= 0; i
< MaxTextureCoordUnits
; i
++) {
297 glActiveTexture(GL_TEXTURE0
+ i
);
298 glGetTexEnvfv(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_COLOR
, v
);
299 if (!equal4v(v
, Random
[i
])) {
300 printf("Setting per-unit env state failed for unit %d\n", i
);
301 report4v(Random
[i
], v
);
306 /* there should be no errors at this point */
307 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
318 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
319 printf("GL_MAX_TEXTURE_COORDS = %d\n", MaxTextureCoordUnits
);
320 printf("GL_MAX_TEXTURE_IMAGE_UNITS = %d\n", MaxTextureImageUnits
);
321 printf("GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS = %d\n", MaxTextureVertexUnits
);
322 printf("GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS = %d\n", MaxTextureCombinedUnits
);
329 GLboolean pass
= GL_TRUE
;
331 pass
= test_rasterpos() && pass
;
332 pass
= test_texture_matrix() && pass
;
333 pass
= test_texture_params() && pass
;
334 pass
= test_texture_env() && pass
;
336 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
343 if (piglit_is_extension_supported("GL_ARB_vertex_shader")) {
344 glGetIntegerv(GL_MAX_TEXTURE_COORDS
, &MaxTextureCoordUnits
);
345 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS
, &MaxTextureImageUnits
);
346 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS
, &MaxTextureVertexUnits
);
347 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS
, &MaxTextureCombinedUnits
);
349 else if (piglit_is_extension_supported("GL_ARB_fragment_shader") ||
350 piglit_is_extension_supported("GL_ARB_fragment_program")) {
351 glGetIntegerv(GL_MAX_TEXTURE_COORDS
, &MaxTextureCoordUnits
);
352 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS
, &MaxTextureImageUnits
);
353 MaxTextureVertexUnits
= 0;
354 MaxTextureCombinedUnits
= MaxTextureImageUnits
;
357 glGetIntegerv(GL_MAX_TEXTURE_UNITS
, &MaxTextureCoordUnits
);
358 MaxTextureImageUnits
=
359 MaxTextureCombinedUnits
= MaxTextureCoordUnits
;
360 MaxTextureVertexUnits
= 0;
365 if (MaxTextureCombinedUnits
> MAX_UNITS
) {
366 /* Need to increase the MAX_UNITS limit */
367 piglit_report_result(PIGLIT_WARN
);
370 generate_random_numbers();
372 glMatrixMode(GL_PROJECTION
);
374 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
375 glMatrixMode(GL_MODELVIEW
);
381 piglit_init(int argc
, char *argv
[])
383 piglit_require_gl_version(13);