cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / general / draw-arrays-colormaterial.c
blob9864e7a7ac82e9716769275f0dda9176246b9bdb
1 /*
2 * Copyright © 2011 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
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
21 * DEALINGS IN THE SOFTWARE.
26 /**
27 * Test glDrawArrays with glColorMaterial.
28 * This exercises a Mesa bug where glColor() calls didn't effect
29 * the color of lit surfaces when color material mode was used.
33 #include "piglit-util-gl.h"
35 PIGLIT_GL_TEST_CONFIG_BEGIN
37 config.supports_gl_compat_version = 10;
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 #define DX0 -0.6
46 static GLfloat pos0[4][3] =
48 { 0.5 + DX0, -0.5, 0.0 },
49 { 0.5 + DX0, 0.5, 0.0 },
50 { -0.5 + DX0, 0.5, 0.0 },
51 { -0.5 + DX0, -0.5, 0.0 }
54 #define DX1 0.6
56 static GLfloat pos1[4][3] =
58 { 0.5 + DX1, -0.5, 0.0 },
59 { 0.5 + DX1, 0.5, 0.0 },
60 { -0.5 + DX1, 0.5, 0.0 },
61 { -0.5 + DX1, -0.5, 0.0 }
64 static GLfloat norms[4][3] =
66 { 0, 0, 1},
67 { 0, 0, 1},
68 { 0, 0, 1},
69 { 0, 0, 1}
73 enum piglit_result
74 piglit_display(void)
76 static const GLfloat red[3] = {1.0f, 0.0f, 0.0f};
77 static const GLfloat green[3] = {0.0f, 1.0f, 0.0f};
78 GLboolean pass = GL_TRUE;
80 glEnable(GL_LIGHTING);
81 glEnable(GL_LIGHT0);
83 glEnable(GL_COLOR_MATERIAL);
84 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
86 glClearColor(0.3, 0.3, 0.3, 1);
87 glClear(GL_COLOR_BUFFER_BIT);
89 /* red */
90 glColor3f(1, 0, 0);
91 glEnableClientState(GL_VERTEX_ARRAY);
92 glEnableClientState(GL_NORMAL_ARRAY);
93 glVertexPointer(3, GL_FLOAT, 0, pos0);
94 glNormalPointer(GL_FLOAT, 0, norms);
95 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
97 /* green */
98 glColor3f(0, 1, 0);
99 glVertexPointer(3, GL_FLOAT, 0, pos1);
100 glNormalPointer(GL_FLOAT, 0, norms);
101 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
103 glDisableClientState(GL_VERTEX_ARRAY);
104 glDisableClientState(GL_NORMAL_ARRAY);
106 glDisable(GL_LIGHTING);
108 if (!piglit_probe_pixel_rgb(piglit_width * 1 / 3,
109 piglit_height / 2, red)) {
110 pass = GL_FALSE;
113 if (!piglit_probe_pixel_rgb(piglit_width * 2 / 3,
114 piglit_height / 2, green)) {
115 pass = GL_FALSE;
118 piglit_present_results();
120 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
124 void
125 piglit_init(int argc, char **argv)
127 /* nop */