2 * Copyright (c) 2012 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 * 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 glColorMaterial with glMaterial calls in a display list.
26 * Used to test/fix a Mesa bug.
28 * Example: if glColorMaterial(GL_FRONT, GL_AMBIENT) is called and we
29 * set the ambient material with glColor3f(green), then a call to
30 * glMaterialfv(GL_FRONT, GL_AMBIENT, red) (in a display list) should
36 #include "piglit-util-gl.h"
38 PIGLIT_GL_TEST_CONFIG_BEGIN
40 config
.supports_gl_compat_version
= 10;
42 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
44 PIGLIT_GL_TEST_CONFIG_END
47 * Test glMaterial handling in a display list for one of GL_AMBIENT,
48 * GL_DIFFUSE or GL_SPECULAR.
51 test_material_coef(GLenum coef
)
53 static const GLfloat black
[4] = {0, 0, 0, 0};
54 static const GLfloat white
[4] = {1, 1, 1, 1};
55 static const GLfloat red
[4] = {1, 0, 0, 1};
56 static const GLfloat green
[4] = {0, 1, 0, 1};
59 assert(coef
== GL_AMBIENT
||
63 glDisable(GL_COLOR_MATERIAL
);
65 /* set all mat coefs to black */
66 glMaterialfv(GL_FRONT_AND_BACK
, GL_AMBIENT
, black
);
67 glMaterialfv(GL_FRONT_AND_BACK
, GL_DIFFUSE
, black
);
68 glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, black
);
70 /* set all light coefs to black */
71 glLightfv(GL_LIGHT0
, GL_AMBIENT
, black
);
72 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, black
);
73 glLightfv(GL_LIGHT0
, GL_SPECULAR
, black
);
75 /* Now test the coefficient of interest */
76 glLightfv(GL_LIGHT0
, coef
, white
); /* white light */
77 glEnable(GL_COLOR_MATERIAL
);
78 glColorMaterial(GL_FRONT_AND_BACK
, coef
);
80 /* Set the material coef via glColor - this is what we want to see */
83 /* This glMaterial setting should be ignored since glColorMaterial says
84 * that glColor overrides the latched material.
86 glNewList(1, GL_COMPILE
);
87 glMaterialfv(GL_FRONT_AND_BACK
, coef
, red
);
91 /* draw tri (should be green, not red) */
92 glClear(GL_COLOR_BUFFER_BIT
);
93 glBegin(GL_TRIANGLES
);
100 result
= piglit_probe_pixel_rgb(piglit_width
/ 2, piglit_height
/ 2, green
);
102 /* also query the material coef and check it */
105 glGetMaterialfv(GL_FRONT
, coef
, mat
);
106 if (mat
[0] != green
[0] ||
107 mat
[1] != green
[1] ||
108 mat
[2] != green
[2]) {
109 printf("glGetMaterial failed."
110 " Expected (%g, %g, %g, %g) Found (%g, %g, %g, %g)\n",
111 green
[0], green
[1], green
[2], green
[3],
112 mat
[0], mat
[1], mat
[2], mat
[3]);
117 piglit_present_results();
126 if (!test_material_coef(GL_AMBIENT
))
128 if (!test_material_coef(GL_DIFFUSE
))
130 if (!test_material_coef(GL_SPECULAR
))
138 piglit_init(int argc
, char **argv
)
140 glEnable(GL_LIGHTING
);