2 * Copyright © 2011 Marek Olšák <maraeo@gmail.com>
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
25 * Test for immediate-mode style commands like glNormal, glColor, etc.
26 * with vertex arrays, immediate mode and display lists for GL_NV_half_float
29 * glVertex and the commands taking a pointer (e.g. glColor*v) are not
33 #include "piglit-util-gl.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config
.supports_gl_compat_version
= 10;
39 config
.window_width
= 512;
40 config
.window_height
= 512;
41 config
.window_visual
= PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_RGBA
;
42 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
44 PIGLIT_GL_TEST_CONFIG_END
46 #define ftoh(f) piglit_half_from_float(f)
48 static GLboolean snorm_equation_23
;
70 static const char *mode_to_str
[NUM_MODES
] = {
76 static void draw_quad(unsigned mode
, float *v
,
77 void (*attrib
)(float x
, float y
, float z
, float w
))
79 static const float verts
[] = {
89 attrib(v
[0], v
[1], v
[2], v
[3]);
90 glEnableClientState(GL_VERTEX_ARRAY
);
91 glVertexPointer(2, GL_FLOAT
, 0, verts
);
92 glDrawArrays(GL_QUADS
, 0, 4);
93 glDisableClientState(GL_VERTEX_ARRAY
);
97 for (i
= 0; i
< 4; i
++) {
98 attrib(v
[0], v
[1], v
[2], v
[3]);
99 glVertex2fv(&verts
[i
*2]);
104 glNewList(1, GL_COMPILE
);
106 for (i
= 0; i
< 4; i
++) {
107 attrib(v
[0], v
[1], v
[2], v
[3]);
108 glVertex2fv(&verts
[i
*2]);
119 static GLboolean
test(int x
, int y
, const char *shaderfunc
,
120 unsigned mask
, unsigned type
, unsigned mode
,
121 void (*attrib
)(float x
, float y
, float z
, float w
),
124 static const char *templ
= {
126 "#extension GL_ARB_explicit_attrib_location : require \n"
127 "layout(location = 1) in %s attr; \n"
129 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \n"
130 " gl_FrontColor = (%s) * vec4(1.0, 1.0, 1.0, 0.5); \n"
134 GLboolean pass
= GL_TRUE
;
138 float color
[3][4] = {
139 {0.2, 0.4, 0.6, 0.8},
144 sprintf(vstext
, templ
,
145 type
!= FLOAT_TYPE
? "#version 130" : "",
146 type
== INT_TYPE
? "ivec4" : type
== UINT_TYPE
? "uvec4" : "vec4",
149 /* Create the shader. */
150 vs
= piglit_compile_shader_text(GL_VERTEX_SHADER
, vstext
);
152 piglit_report_result(PIGLIT_FAIL
);
153 prog
= piglit_link_simple_program(vs
, 0);
155 piglit_report_result(PIGLIT_FAIL
);
160 glTranslatef(x
, y
, 0);
162 draw_quad(mode
, color
[0], attrib
);
163 glDrawArrays(GL_QUADS
, 0, 4);
165 glTranslatef(10, 0, 0);
166 draw_quad(mode
, color
[1], attrib
);
168 glTranslatef(10, 0, 0);
169 draw_quad(mode
, color
[2], attrib
);
173 for (i
= 0; i
< 3; i
++)
177 for (i
= 0; i
< 3; i
++)
181 for (i
= 0; i
< 3; i
++)
190 if (strstr(info
, "GL_INT_2_10_10_10_REV-norm")) {
191 if (snorm_equation_23
) {
192 for (i
= 0; i
< 3; i
++) {
198 for (i
= 0; i
< 3; i
++) {
199 if (color
[i
][3] < 0.333)
201 else if (color
[i
][3] < 1)
205 } else if (strstr(info
, "GL_INT_2_10_10_10_REV")) {
206 for (i
= 0; i
< 3; i
++) {
210 } else if (strstr(info
, "GL_UNSIGNED_INT_2_10_10_10_REV")) {
211 for (i
= 0; i
< 3; i
++) {
212 if (color
[i
][3] < 0.333)
214 else if (color
[i
][3] < 0.666)
216 else if (color
[i
][3] < 1)
221 /* We scale alpha in the shader to ensure it's not > 1 when it should be 1. */
222 for (i
= 0; i
< 3; i
++)
226 pass
= piglit_probe_pixel_rgba(x
+5, y
+5, color
[0]) && pass
;
227 pass
= piglit_probe_pixel_rgba(x
+15, y
+5, color
[1]) && pass
;
228 pass
= piglit_probe_pixel_rgba(x
+25, y
+5, color
[2]) && pass
;
232 typedef GLboolean (*test_func
)(int x
, int y
, unsigned mode
);
234 #define DEFINE_TEST(func, funcsuffix, params, shaderfunc, mask, type, info) \
235 static void invoke_##func##funcsuffix(float x, float y, float z, float w) \
240 static GLboolean test_##func##funcsuffix(int x, int y, unsigned mode) \
242 printf("Testing %s, %s\n", #func "(" info ")", mode_to_str[mode]); \
243 return test(x, y, shaderfunc, mask, type, mode, invoke_##func##funcsuffix, info); \
246 DEFINE_TEST(glNormal3hNV
,, (ftoh(x
),ftoh(y
),ftoh(z
)), "vec4(gl_Normal, 1.0)", RGB
, FLOAT_TYPE
, "")
247 DEFINE_TEST(glColor3hNV
,, (ftoh(x
), ftoh(y
), ftoh(z
)), "gl_Color", RGB
, FLOAT_TYPE
, "")
248 DEFINE_TEST(glColor4hNV
,, (ftoh(x
), ftoh(y
), ftoh(z
), ftoh(w
)), "gl_Color", RGBA
, FLOAT_TYPE
, "")
249 DEFINE_TEST(glTexCoord1hNV
,, (ftoh(x
)), "gl_MultiTexCoord0", R
, FLOAT_TYPE
, "")
250 DEFINE_TEST(glTexCoord2hNV
,, (ftoh(x
),ftoh(y
)), "gl_MultiTexCoord0", RG
, FLOAT_TYPE
, "")
251 DEFINE_TEST(glTexCoord3hNV
,, (ftoh(x
),ftoh(y
),ftoh(z
)), "gl_MultiTexCoord0", RGB
, FLOAT_TYPE
, "")
252 DEFINE_TEST(glTexCoord4hNV
,, (ftoh(x
),ftoh(y
),ftoh(z
),ftoh(w
)), "gl_MultiTexCoord0", RGBA
, FLOAT_TYPE
, "")
253 DEFINE_TEST(glMultiTexCoord1hNV
,, (GL_TEXTURE1
, ftoh(x
)), "gl_MultiTexCoord1", R
, FLOAT_TYPE
, "")
254 DEFINE_TEST(glMultiTexCoord2hNV
,, (GL_TEXTURE1
, ftoh(x
),ftoh(y
)), "gl_MultiTexCoord1", RG
, FLOAT_TYPE
, "")
255 DEFINE_TEST(glMultiTexCoord3hNV
,, (GL_TEXTURE1
, ftoh(x
),ftoh(y
),ftoh(z
)), "gl_MultiTexCoord1", RGB
, FLOAT_TYPE
, "")
256 DEFINE_TEST(glMultiTexCoord4hNV
,, (GL_TEXTURE1
, ftoh(x
),ftoh(y
),ftoh(z
),ftoh(w
)), "gl_MultiTexCoord1", RGBA
, FLOAT_TYPE
, "")
257 DEFINE_TEST(glSecondaryColor3hNV
,, (ftoh(x
),ftoh(y
),ftoh(z
)), "gl_SecondaryColor", RGB
, FLOAT_TYPE
, "")
259 static test_func tests
[] = {
267 test_glMultiTexCoord1hNV
,
268 test_glMultiTexCoord2hNV
,
269 test_glMultiTexCoord3hNV
,
270 test_glMultiTexCoord4hNV
,
271 test_glSecondaryColor3hNV
,
274 enum piglit_result
piglit_display(void)
276 GLboolean pass
= GL_TRUE
;
280 glClear(GL_COLOR_BUFFER_BIT
);
282 for (mode
= 0; mode
< NUM_MODES
; mode
++) {
284 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++) {
285 pass
= tests
[i
](x
, y
, mode
) && pass
;
287 if (x
+40 > piglit_width
) {
294 if (!piglit_check_gl_error(GL_NO_ERROR
))
295 piglit_report_result(PIGLIT_FAIL
);
296 piglit_present_results();
298 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
301 void piglit_init(int argc
, char **argv
)
303 piglit_require_gl_version(20);
304 piglit_require_extension("GL_ARB_explicit_attrib_location");
305 piglit_require_extension("GL_NV_half_float");
306 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
308 snorm_equation_23
= piglit_get_gl_version() >= 42;
310 glClearColor(0.2, 0.2, 0.2, 1.0);