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.
26 * Test texture unit state with respect to the different number of
27 * texture coord units, image units, combined units, etc.
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config
.supports_gl_core_version
= 31;
34 config
.supports_gl_compat_version
= 20;
36 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
37 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
39 PIGLIT_GL_TEST_CONFIG_END
43 /** random number for checking state */
44 static GLfloat Random
[MAX_UNITS
][4];
46 static GLint MaxTextureCoordUnits
;
47 static GLint MaxTextureVertexUnits
;
48 static GLint MaxTextureImageUnits
;
49 static GLint MaxTextureCombinedUnits
;
53 generate_random_numbers(void)
56 for (i
= 0; i
< ARRAY_SIZE(Random
); i
++) {
57 for (j
= 0; j
< 4; j
++) {
58 /* values in [0, 1] */
59 Random
[i
][j
] = (rand() % 1000) * .001;
66 equal4v(const GLfloat v1
[4], const GLfloat v2
[4])
68 return (v1
[0] == v2
[0] &&
76 report4v(const GLfloat exp
[4], const GLfloat act
[4])
78 printf("Expected (%g, %g, %g, %g) but found (%g, %g, %g, %g)\n",
79 exp
[0], exp
[1], exp
[2], exp
[3],
80 act
[0], act
[1], act
[2], act
[3]);
85 test_texture_params(void)
87 GLuint tex
[MAX_UNITS
];
91 piglit_reset_gl_error();
93 glCreateTextures(GL_TEXTURE_2D
, MaxTextureCombinedUnits
, tex
);
95 /* set per-unit state */
96 for (i
= 0; i
< MaxTextureCombinedUnits
; i
++) {
97 glBindTextureUnit(i
, tex
[i
]);
98 glTextureParameterfv(tex
[i
], GL_TEXTURE_BORDER_COLOR
, Random
[i
]);
101 /* check per-unit state */
102 for (i
= 0; i
< MaxTextureCombinedUnits
; i
++) {
104 glBindTextureUnit(i
, tex
[i
]);
105 /* any per-unit state will do: */
106 glGetTextureParameterfv(tex
[i
], GL_TEXTURE_BORDER_COLOR
, v
);
107 if (!equal4v(v
, Random
[i
])) {
108 printf("Setting per-unit param state failed for unit %d\n", i
);
109 report4v(Random
[i
], v
);
114 /* there should be no errors at this point */
115 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
119 maxUnit
= MAX2(MaxTextureCombinedUnits
, MaxTextureCoordUnits
);
121 /* This should generate an error. The GL_ARB_direct_state_access extension
122 * isn't explicit about which error should be generated, but the typical
123 * error for a out-of-range int/uint is GL_INVALID_VALUE. That's what
124 * NVIDIA's driver does.
126 if (!piglit_khr_no_error
) {
127 glBindTextureUnit(maxUnit
, tex
[0]);
128 if (!piglit_check_gl_error(GL_INVALID_VALUE
)) {
140 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
141 printf("GL_MAX_TEXTURE_COORDS = %d\n", MaxTextureCoordUnits
);
142 printf("GL_MAX_TEXTURE_IMAGE_UNITS = %d\n", MaxTextureImageUnits
);
143 printf("GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS = %d\n", MaxTextureVertexUnits
);
144 printf("GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS = %d\n", MaxTextureCombinedUnits
);
153 pass
= test_texture_params() && pass
;
155 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
160 piglit_init(int argc
, char *argv
[])
162 piglit_require_extension("GL_ARB_direct_state_access");
164 glGetIntegerv(GL_MAX_TEXTURE_COORDS
, &MaxTextureCoordUnits
);
165 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS
, &MaxTextureImageUnits
);
166 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS
, &MaxTextureVertexUnits
);
167 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS
, &MaxTextureCombinedUnits
);
171 if (MaxTextureCombinedUnits
> MAX_UNITS
) {
172 /* Need to increase the MAX_UNITS limit */
173 piglit_report_result(PIGLIT_WARN
);
176 generate_random_numbers();