cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / general / infinite-spot-light.c
blob5b475e625c8e2ed1586a9d51d204574b2881e265
1 /*
2 * Copyright (C) 2011 Intel Corporation
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 DEALINGS
21 * IN THE SOFTWARE.
23 * Authors:
24 * Yuanhan Liu <yuanhan.liu@linux.intel.com>
27 /** @file infinite-spot-light.c
29 * This is a case that sounds doesn't make sense, but it is allowed by glSpec
30 * (see section 2.14.1 Lightin of glspec 2.1.pdf). While writing this case,
31 * it servers as two purposes:
33 * 1. Test if swrast is OK with this case.
34 * The old mesa code would always compute a zero attenuation, thus always
35 * get a black lighting color.
37 * 2. Test if hardware rendering(only i965 tested) is OK with this patch.
38 * The old mesa code would skip the attenuation and spot computation while
39 * infinite light is met. This is somehow not permitted by glSpec.
42 #include "piglit-util-gl.h"
44 PIGLIT_GL_TEST_CONFIG_BEGIN
46 config.supports_gl_compat_version = 10;
48 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
50 PIGLIT_GL_TEST_CONFIG_END
52 /* Already normalized, and 0.5 would be the expected color */
53 static GLfloat dir[3] = {0.866025404, 0.0, 0.5};
54 static GLfloat pos[4] = {0.0, 0.0, -1.0, 0.0}; /* infinite */
55 static GLfloat light_ambient[3] = {1.0, 0.0, 0.0};
57 enum piglit_result
58 piglit_display(void)
60 GLboolean pass = GL_TRUE;
61 GLfloat expected[4] = {0.5, 0.0, 0.0, 1.0};
63 glClear(GL_COLOR_BUFFER_BIT);
65 glPointSize(10);
66 glBegin(GL_POINTS);
67 glVertex2f(0.5, 0.5);
68 glEnd();
70 pass = piglit_probe_pixel_rgba(0, 0, expected);
72 piglit_present_results();
74 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
78 void
79 piglit_init(int argc, char **argv)
81 GLfloat buf[4] = {0.0, 0.0, 0.0, 1.0};
83 glClearColor(0.0, 0.0, 0.0, 1.0);
85 glEnable(GL_LIGHT0);
86 glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 89.0);
87 glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 1.0);
88 glLightfv(GL_LIGHT0, GL_POSITION, pos);
89 glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, dir);
90 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
92 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, buf);
93 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
95 glMaterialfv(GL_FRONT, GL_DIFFUSE, buf);
96 glMaterialfv(GL_FRONT, GL_SPECULAR, buf);
98 buf[0] = 1.0;
99 buf[1] = 1.0;
100 buf[2] = 1.0;
101 glMaterialfv(GL_FRONT, GL_AMBIENT, buf);
103 glEnable(GL_LIGHTING);
105 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);