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
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
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};
60 GLboolean pass
= GL_TRUE
;
61 GLfloat expected
[4] = {0.5, 0.0, 0.0, 1.0};
63 glClear(GL_COLOR_BUFFER_BIT
);
70 pass
= piglit_probe_pixel_rgba(0, 0, expected
);
72 piglit_present_results();
74 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
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);
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
);
101 glMaterialfv(GL_FRONT
, GL_AMBIENT
, buf
);
103 glEnable(GL_LIGHTING
);
105 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);