2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #include "simple_list.h"
35 #include "math/m_matrix.h"
39 _mesa_ShadeModel( GLenum mode
)
41 GET_CURRENT_CONTEXT(ctx
);
42 ASSERT_OUTSIDE_BEGIN_END(ctx
);
44 if (MESA_VERBOSE
& VERBOSE_API
)
45 _mesa_debug(ctx
, "glShadeModel %s\n", _mesa_lookup_enum_by_nr(mode
));
47 if (mode
!= GL_FLAT
&& mode
!= GL_SMOOTH
) {
48 _mesa_error(ctx
, GL_INVALID_ENUM
, "glShadeModel");
52 if (ctx
->Light
.ShadeModel
== mode
)
55 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
56 ctx
->Light
.ShadeModel
= mode
;
58 ctx
->_TriangleCaps
|= DD_FLATSHADE
;
60 ctx
->_TriangleCaps
&= ~DD_FLATSHADE
;
62 if (ctx
->Driver
.ShadeModel
)
63 ctx
->Driver
.ShadeModel( ctx
, mode
);
67 * Helper function called by _mesa_Lightfv and _mesa_PopAttrib to set
69 * For GL_POSITION and GL_SPOT_DIRECTION the params position/direction
70 * will have already been transformed by the modelview matrix!
71 * Also, all error checking should have already been done.
74 _mesa_light(struct gl_context
*ctx
, GLuint lnum
, GLenum pname
, const GLfloat
*params
)
76 struct gl_light
*light
;
78 ASSERT(lnum
< MAX_LIGHTS
);
79 light
= &ctx
->Light
.Light
[lnum
];
83 if (TEST_EQ_4V(light
->Ambient
, params
))
85 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
86 COPY_4V( light
->Ambient
, params
);
89 if (TEST_EQ_4V(light
->Diffuse
, params
))
91 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
92 COPY_4V( light
->Diffuse
, params
);
95 if (TEST_EQ_4V(light
->Specular
, params
))
97 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
98 COPY_4V( light
->Specular
, params
);
101 /* NOTE: position has already been transformed by ModelView! */
102 if (TEST_EQ_4V(light
->EyePosition
, params
))
104 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
105 COPY_4V(light
->EyePosition
, params
);
106 if (light
->EyePosition
[3] != 0.0F
)
107 light
->_Flags
|= LIGHT_POSITIONAL
;
109 light
->_Flags
&= ~LIGHT_POSITIONAL
;
111 case GL_SPOT_DIRECTION
:
112 /* NOTE: Direction already transformed by inverse ModelView! */
113 if (TEST_EQ_3V(light
->SpotDirection
, params
))
115 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
116 COPY_3V(light
->SpotDirection
, params
);
118 case GL_SPOT_EXPONENT
:
119 ASSERT(params
[0] >= 0.0);
120 ASSERT(params
[0] <= ctx
->Const
.MaxSpotExponent
);
121 if (light
->SpotExponent
== params
[0])
123 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
124 light
->SpotExponent
= params
[0];
125 _mesa_invalidate_spot_exp_table(light
);
128 ASSERT(params
[0] == 180.0 || (params
[0] >= 0.0 && params
[0] <= 90.0));
129 if (light
->SpotCutoff
== params
[0])
131 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
132 light
->SpotCutoff
= params
[0];
133 light
->_CosCutoffNeg
= (GLfloat
) (cos(light
->SpotCutoff
* DEG2RAD
));
134 if (light
->_CosCutoffNeg
< 0)
135 light
->_CosCutoff
= 0;
137 light
->_CosCutoff
= light
->_CosCutoffNeg
;
138 if (light
->SpotCutoff
!= 180.0F
)
139 light
->_Flags
|= LIGHT_SPOT
;
141 light
->_Flags
&= ~LIGHT_SPOT
;
143 case GL_CONSTANT_ATTENUATION
:
144 ASSERT(params
[0] >= 0.0);
145 if (light
->ConstantAttenuation
== params
[0])
147 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
148 light
->ConstantAttenuation
= params
[0];
150 case GL_LINEAR_ATTENUATION
:
151 ASSERT(params
[0] >= 0.0);
152 if (light
->LinearAttenuation
== params
[0])
154 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
155 light
->LinearAttenuation
= params
[0];
157 case GL_QUADRATIC_ATTENUATION
:
158 ASSERT(params
[0] >= 0.0);
159 if (light
->QuadraticAttenuation
== params
[0])
161 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
162 light
->QuadraticAttenuation
= params
[0];
165 _mesa_problem(ctx
, "Unexpected pname in _mesa_light()");
169 if (ctx
->Driver
.Lightfv
)
170 ctx
->Driver
.Lightfv( ctx
, GL_LIGHT0
+ lnum
, pname
, params
);
175 _mesa_Lightf( GLenum light
, GLenum pname
, GLfloat param
)
179 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
180 _mesa_Lightfv( light
, pname
, fparam
);
185 _mesa_Lightfv( GLenum light
, GLenum pname
, const GLfloat
*params
)
187 GET_CURRENT_CONTEXT(ctx
);
188 GLint i
= (GLint
) (light
- GL_LIGHT0
);
190 ASSERT_OUTSIDE_BEGIN_END(ctx
);
192 if (i
< 0 || i
>= (GLint
) ctx
->Const
.MaxLights
) {
193 _mesa_error( ctx
, GL_INVALID_ENUM
, "glLight(light=0x%x)", light
);
197 /* do particular error checks, transformations */
205 /* transform position by ModelView matrix */
206 TRANSFORM_POINT(temp
, ctx
->ModelviewMatrixStack
.Top
->m
, params
);
209 case GL_SPOT_DIRECTION
:
210 /* transform direction by inverse modelview */
211 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
212 _math_matrix_analyse(ctx
->ModelviewMatrixStack
.Top
);
214 TRANSFORM_DIRECTION(temp
, params
, ctx
->ModelviewMatrixStack
.Top
->m
);
217 case GL_SPOT_EXPONENT
:
218 if (params
[0] < 0.0 || params
[0] > ctx
->Const
.MaxSpotExponent
) {
219 _mesa_error(ctx
, GL_INVALID_VALUE
, "glLight");
224 if ((params
[0] < 0.0 || params
[0] > 90.0) && params
[0] != 180.0) {
225 _mesa_error(ctx
, GL_INVALID_VALUE
, "glLight");
229 case GL_CONSTANT_ATTENUATION
:
230 if (params
[0] < 0.0) {
231 _mesa_error(ctx
, GL_INVALID_VALUE
, "glLight");
235 case GL_LINEAR_ATTENUATION
:
236 if (params
[0] < 0.0) {
237 _mesa_error(ctx
, GL_INVALID_VALUE
, "glLight");
241 case GL_QUADRATIC_ATTENUATION
:
242 if (params
[0] < 0.0) {
243 _mesa_error(ctx
, GL_INVALID_VALUE
, "glLight");
248 _mesa_error(ctx
, GL_INVALID_ENUM
, "glLight(pname=0x%x)", pname
);
252 _mesa_light(ctx
, i
, pname
, params
);
257 _mesa_Lighti( GLenum light
, GLenum pname
, GLint param
)
261 iparam
[1] = iparam
[2] = iparam
[3] = 0;
262 _mesa_Lightiv( light
, pname
, iparam
);
267 _mesa_Lightiv( GLenum light
, GLenum pname
, const GLint
*params
)
275 fparam
[0] = INT_TO_FLOAT( params
[0] );
276 fparam
[1] = INT_TO_FLOAT( params
[1] );
277 fparam
[2] = INT_TO_FLOAT( params
[2] );
278 fparam
[3] = INT_TO_FLOAT( params
[3] );
281 fparam
[0] = (GLfloat
) params
[0];
282 fparam
[1] = (GLfloat
) params
[1];
283 fparam
[2] = (GLfloat
) params
[2];
284 fparam
[3] = (GLfloat
) params
[3];
286 case GL_SPOT_DIRECTION
:
287 fparam
[0] = (GLfloat
) params
[0];
288 fparam
[1] = (GLfloat
) params
[1];
289 fparam
[2] = (GLfloat
) params
[2];
291 case GL_SPOT_EXPONENT
:
293 case GL_CONSTANT_ATTENUATION
:
294 case GL_LINEAR_ATTENUATION
:
295 case GL_QUADRATIC_ATTENUATION
:
296 fparam
[0] = (GLfloat
) params
[0];
299 /* error will be caught later in gl_Lightfv */
303 _mesa_Lightfv( light
, pname
, fparam
);
309 _mesa_GetLightfv( GLenum light
, GLenum pname
, GLfloat
*params
)
311 GET_CURRENT_CONTEXT(ctx
);
312 GLint l
= (GLint
) (light
- GL_LIGHT0
);
313 ASSERT_OUTSIDE_BEGIN_END(ctx
);
315 if (l
< 0 || l
>= (GLint
) ctx
->Const
.MaxLights
) {
316 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetLightfv" );
322 COPY_4V( params
, ctx
->Light
.Light
[l
].Ambient
);
325 COPY_4V( params
, ctx
->Light
.Light
[l
].Diffuse
);
328 COPY_4V( params
, ctx
->Light
.Light
[l
].Specular
);
331 COPY_4V( params
, ctx
->Light
.Light
[l
].EyePosition
);
333 case GL_SPOT_DIRECTION
:
334 COPY_3V( params
, ctx
->Light
.Light
[l
].SpotDirection
);
336 case GL_SPOT_EXPONENT
:
337 params
[0] = ctx
->Light
.Light
[l
].SpotExponent
;
340 params
[0] = ctx
->Light
.Light
[l
].SpotCutoff
;
342 case GL_CONSTANT_ATTENUATION
:
343 params
[0] = ctx
->Light
.Light
[l
].ConstantAttenuation
;
345 case GL_LINEAR_ATTENUATION
:
346 params
[0] = ctx
->Light
.Light
[l
].LinearAttenuation
;
348 case GL_QUADRATIC_ATTENUATION
:
349 params
[0] = ctx
->Light
.Light
[l
].QuadraticAttenuation
;
352 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetLightfv" );
359 _mesa_GetLightiv( GLenum light
, GLenum pname
, GLint
*params
)
361 GET_CURRENT_CONTEXT(ctx
);
362 GLint l
= (GLint
) (light
- GL_LIGHT0
);
363 ASSERT_OUTSIDE_BEGIN_END(ctx
);
365 if (l
< 0 || l
>= (GLint
) ctx
->Const
.MaxLights
) {
366 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetLightiv" );
372 params
[0] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Ambient
[0]);
373 params
[1] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Ambient
[1]);
374 params
[2] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Ambient
[2]);
375 params
[3] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Ambient
[3]);
378 params
[0] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Diffuse
[0]);
379 params
[1] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Diffuse
[1]);
380 params
[2] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Diffuse
[2]);
381 params
[3] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Diffuse
[3]);
384 params
[0] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Specular
[0]);
385 params
[1] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Specular
[1]);
386 params
[2] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Specular
[2]);
387 params
[3] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Specular
[3]);
390 params
[0] = (GLint
) ctx
->Light
.Light
[l
].EyePosition
[0];
391 params
[1] = (GLint
) ctx
->Light
.Light
[l
].EyePosition
[1];
392 params
[2] = (GLint
) ctx
->Light
.Light
[l
].EyePosition
[2];
393 params
[3] = (GLint
) ctx
->Light
.Light
[l
].EyePosition
[3];
395 case GL_SPOT_DIRECTION
:
396 params
[0] = (GLint
) ctx
->Light
.Light
[l
].SpotDirection
[0];
397 params
[1] = (GLint
) ctx
->Light
.Light
[l
].SpotDirection
[1];
398 params
[2] = (GLint
) ctx
->Light
.Light
[l
].SpotDirection
[2];
400 case GL_SPOT_EXPONENT
:
401 params
[0] = (GLint
) ctx
->Light
.Light
[l
].SpotExponent
;
404 params
[0] = (GLint
) ctx
->Light
.Light
[l
].SpotCutoff
;
406 case GL_CONSTANT_ATTENUATION
:
407 params
[0] = (GLint
) ctx
->Light
.Light
[l
].ConstantAttenuation
;
409 case GL_LINEAR_ATTENUATION
:
410 params
[0] = (GLint
) ctx
->Light
.Light
[l
].LinearAttenuation
;
412 case GL_QUADRATIC_ATTENUATION
:
413 params
[0] = (GLint
) ctx
->Light
.Light
[l
].QuadraticAttenuation
;
416 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetLightiv" );
423 /**********************************************************************/
424 /*** Light Model ***/
425 /**********************************************************************/
429 _mesa_LightModelfv( GLenum pname
, const GLfloat
*params
)
433 GET_CURRENT_CONTEXT(ctx
);
434 ASSERT_OUTSIDE_BEGIN_END(ctx
);
437 case GL_LIGHT_MODEL_AMBIENT
:
438 if (TEST_EQ_4V( ctx
->Light
.Model
.Ambient
, params
))
440 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
441 COPY_4V( ctx
->Light
.Model
.Ambient
, params
);
443 case GL_LIGHT_MODEL_LOCAL_VIEWER
:
444 newbool
= (params
[0]!=0.0);
445 if (ctx
->Light
.Model
.LocalViewer
== newbool
)
447 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
448 ctx
->Light
.Model
.LocalViewer
= newbool
;
450 case GL_LIGHT_MODEL_TWO_SIDE
:
451 newbool
= (params
[0]!=0.0);
452 if (ctx
->Light
.Model
.TwoSide
== newbool
)
454 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
455 ctx
->Light
.Model
.TwoSide
= newbool
;
456 if (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
)
457 ctx
->_TriangleCaps
|= DD_TRI_LIGHT_TWOSIDE
;
459 ctx
->_TriangleCaps
&= ~DD_TRI_LIGHT_TWOSIDE
;
461 case GL_LIGHT_MODEL_COLOR_CONTROL
:
462 if (params
[0] == (GLfloat
) GL_SINGLE_COLOR
)
463 newenum
= GL_SINGLE_COLOR
;
464 else if (params
[0] == (GLfloat
) GL_SEPARATE_SPECULAR_COLOR
)
465 newenum
= GL_SEPARATE_SPECULAR_COLOR
;
467 _mesa_error( ctx
, GL_INVALID_ENUM
, "glLightModel(param=0x0%x)",
471 if (ctx
->Light
.Model
.ColorControl
== newenum
)
473 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
474 ctx
->Light
.Model
.ColorControl
= newenum
;
477 _mesa_error( ctx
, GL_INVALID_ENUM
, "glLightModel(pname=0x%x)", pname
);
481 if (ctx
->Driver
.LightModelfv
)
482 ctx
->Driver
.LightModelfv( ctx
, pname
, params
);
487 _mesa_LightModeliv( GLenum pname
, const GLint
*params
)
492 case GL_LIGHT_MODEL_AMBIENT
:
493 fparam
[0] = INT_TO_FLOAT( params
[0] );
494 fparam
[1] = INT_TO_FLOAT( params
[1] );
495 fparam
[2] = INT_TO_FLOAT( params
[2] );
496 fparam
[3] = INT_TO_FLOAT( params
[3] );
498 case GL_LIGHT_MODEL_LOCAL_VIEWER
:
499 case GL_LIGHT_MODEL_TWO_SIDE
:
500 case GL_LIGHT_MODEL_COLOR_CONTROL
:
501 fparam
[0] = (GLfloat
) params
[0];
504 /* Error will be caught later in gl_LightModelfv */
505 ASSIGN_4V(fparam
, 0.0F
, 0.0F
, 0.0F
, 0.0F
);
507 _mesa_LightModelfv( pname
, fparam
);
512 _mesa_LightModeli( GLenum pname
, GLint param
)
516 iparam
[1] = iparam
[2] = iparam
[3] = 0;
517 _mesa_LightModeliv( pname
, iparam
);
522 _mesa_LightModelf( GLenum pname
, GLfloat param
)
526 fparam
[1] = fparam
[2] = fparam
[3] = 0.0F
;
527 _mesa_LightModelfv( pname
, fparam
);
532 /********** MATERIAL **********/
536 * Given a face and pname value (ala glColorMaterial), compute a bitmask
537 * of the targeted material values.
540 _mesa_material_bitmask( struct gl_context
*ctx
, GLenum face
, GLenum pname
,
541 GLuint legal
, const char *where
)
545 /* Make a bitmask indicating what material attribute(s) we're updating */
548 bitmask
|= MAT_BIT_FRONT_EMISSION
| MAT_BIT_BACK_EMISSION
;
551 bitmask
|= MAT_BIT_FRONT_AMBIENT
| MAT_BIT_BACK_AMBIENT
;
554 bitmask
|= MAT_BIT_FRONT_DIFFUSE
| MAT_BIT_BACK_DIFFUSE
;
557 bitmask
|= MAT_BIT_FRONT_SPECULAR
| MAT_BIT_BACK_SPECULAR
;
560 bitmask
|= MAT_BIT_FRONT_SHININESS
| MAT_BIT_BACK_SHININESS
;
562 case GL_AMBIENT_AND_DIFFUSE
:
563 bitmask
|= MAT_BIT_FRONT_AMBIENT
| MAT_BIT_BACK_AMBIENT
;
564 bitmask
|= MAT_BIT_FRONT_DIFFUSE
| MAT_BIT_BACK_DIFFUSE
;
566 case GL_COLOR_INDEXES
:
567 bitmask
|= MAT_BIT_FRONT_INDEXES
| MAT_BIT_BACK_INDEXES
;
570 _mesa_error( ctx
, GL_INVALID_ENUM
, "%s", where
);
574 if (face
==GL_FRONT
) {
575 bitmask
&= FRONT_MATERIAL_BITS
;
577 else if (face
==GL_BACK
) {
578 bitmask
&= BACK_MATERIAL_BITS
;
580 else if (face
!= GL_FRONT_AND_BACK
) {
581 _mesa_error( ctx
, GL_INVALID_ENUM
, "%s", where
);
585 if (bitmask
& ~legal
) {
586 _mesa_error( ctx
, GL_INVALID_ENUM
, "%s", where
);
595 /* Update derived values following a change in ctx->Light.Material
598 _mesa_update_material( struct gl_context
*ctx
, GLuint bitmask
)
600 struct gl_light
*light
, *list
= &ctx
->Light
.EnabledList
;
601 GLfloat (*mat
)[4] = ctx
->Light
.Material
.Attrib
;
603 if (MESA_VERBOSE
& VERBOSE_MATERIAL
)
604 _mesa_debug(ctx
, "_mesa_update_material, mask 0x%x\n", bitmask
);
609 /* update material ambience */
610 if (bitmask
& MAT_BIT_FRONT_AMBIENT
) {
611 foreach (light
, list
) {
612 SCALE_3V( light
->_MatAmbient
[0], light
->Ambient
,
613 mat
[MAT_ATTRIB_FRONT_AMBIENT
]);
617 if (bitmask
& MAT_BIT_BACK_AMBIENT
) {
618 foreach (light
, list
) {
619 SCALE_3V( light
->_MatAmbient
[1], light
->Ambient
,
620 mat
[MAT_ATTRIB_BACK_AMBIENT
]);
624 /* update BaseColor = emission + scene's ambience * material's ambience */
625 if (bitmask
& (MAT_BIT_FRONT_EMISSION
| MAT_BIT_FRONT_AMBIENT
)) {
626 COPY_3V( ctx
->Light
._BaseColor
[0], mat
[MAT_ATTRIB_FRONT_EMISSION
] );
627 ACC_SCALE_3V( ctx
->Light
._BaseColor
[0], mat
[MAT_ATTRIB_FRONT_AMBIENT
],
628 ctx
->Light
.Model
.Ambient
);
631 if (bitmask
& (MAT_BIT_BACK_EMISSION
| MAT_BIT_BACK_AMBIENT
)) {
632 COPY_3V( ctx
->Light
._BaseColor
[1], mat
[MAT_ATTRIB_BACK_EMISSION
] );
633 ACC_SCALE_3V( ctx
->Light
._BaseColor
[1], mat
[MAT_ATTRIB_BACK_AMBIENT
],
634 ctx
->Light
.Model
.Ambient
);
637 /* update material diffuse values */
638 if (bitmask
& MAT_BIT_FRONT_DIFFUSE
) {
639 foreach (light
, list
) {
640 SCALE_3V( light
->_MatDiffuse
[0], light
->Diffuse
,
641 mat
[MAT_ATTRIB_FRONT_DIFFUSE
] );
645 if (bitmask
& MAT_BIT_BACK_DIFFUSE
) {
646 foreach (light
, list
) {
647 SCALE_3V( light
->_MatDiffuse
[1], light
->Diffuse
,
648 mat
[MAT_ATTRIB_BACK_DIFFUSE
] );
652 /* update material specular values */
653 if (bitmask
& MAT_BIT_FRONT_SPECULAR
) {
654 foreach (light
, list
) {
655 SCALE_3V( light
->_MatSpecular
[0], light
->Specular
,
656 mat
[MAT_ATTRIB_FRONT_SPECULAR
]);
660 if (bitmask
& MAT_BIT_BACK_SPECULAR
) {
661 foreach (light
, list
) {
662 SCALE_3V( light
->_MatSpecular
[1], light
->Specular
,
663 mat
[MAT_ATTRIB_BACK_SPECULAR
]);
667 if (bitmask
& MAT_BIT_FRONT_SHININESS
) {
668 _mesa_invalidate_shine_table( ctx
, 0 );
671 if (bitmask
& MAT_BIT_BACK_SHININESS
) {
672 _mesa_invalidate_shine_table( ctx
, 1 );
678 * Update the current materials from the given rgba color
679 * according to the bitmask in ColorMaterialBitmask, which is
680 * set by glColorMaterial().
683 _mesa_update_color_material( struct gl_context
*ctx
, const GLfloat color
[4] )
685 GLuint bitmask
= ctx
->Light
.ColorMaterialBitmask
;
686 struct gl_material
*mat
= &ctx
->Light
.Material
;
689 for (i
= 0 ; i
< MAT_ATTRIB_MAX
; i
++)
690 if (bitmask
& (1<<i
))
691 COPY_4FV( mat
->Attrib
[i
], color
);
693 _mesa_update_material( ctx
, bitmask
);
698 _mesa_ColorMaterial( GLenum face
, GLenum mode
)
700 GET_CURRENT_CONTEXT(ctx
);
702 GLuint legal
= (MAT_BIT_FRONT_EMISSION
| MAT_BIT_BACK_EMISSION
|
703 MAT_BIT_FRONT_SPECULAR
| MAT_BIT_BACK_SPECULAR
|
704 MAT_BIT_FRONT_DIFFUSE
| MAT_BIT_BACK_DIFFUSE
|
705 MAT_BIT_FRONT_AMBIENT
| MAT_BIT_BACK_AMBIENT
);
706 ASSERT_OUTSIDE_BEGIN_END(ctx
);
708 if (MESA_VERBOSE
&VERBOSE_API
)
709 _mesa_debug(ctx
, "glColorMaterial %s %s\n",
710 _mesa_lookup_enum_by_nr(face
),
711 _mesa_lookup_enum_by_nr(mode
));
713 bitmask
= _mesa_material_bitmask(ctx
, face
, mode
, legal
, "glColorMaterial");
715 return; /* error was recorded */
717 if (ctx
->Light
.ColorMaterialBitmask
== bitmask
&&
718 ctx
->Light
.ColorMaterialFace
== face
&&
719 ctx
->Light
.ColorMaterialMode
== mode
)
722 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
723 ctx
->Light
.ColorMaterialBitmask
= bitmask
;
724 ctx
->Light
.ColorMaterialFace
= face
;
725 ctx
->Light
.ColorMaterialMode
= mode
;
727 if (ctx
->Light
.ColorMaterialEnabled
) {
728 FLUSH_CURRENT( ctx
, 0 );
729 _mesa_update_color_material(ctx
,ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
]);
732 if (ctx
->Driver
.ColorMaterial
)
733 ctx
->Driver
.ColorMaterial( ctx
, face
, mode
);
738 _mesa_GetMaterialfv( GLenum face
, GLenum pname
, GLfloat
*params
)
740 GET_CURRENT_CONTEXT(ctx
);
742 GLfloat (*mat
)[4] = ctx
->Light
.Material
.Attrib
;
743 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
); /* update materials */
745 FLUSH_CURRENT(ctx
, 0); /* update ctx->Light.Material from vertex buffer */
747 if (face
==GL_FRONT
) {
750 else if (face
==GL_BACK
) {
754 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMaterialfv(face)" );
760 COPY_4FV( params
, mat
[MAT_ATTRIB_AMBIENT(f
)] );
763 COPY_4FV( params
, mat
[MAT_ATTRIB_DIFFUSE(f
)] );
766 COPY_4FV( params
, mat
[MAT_ATTRIB_SPECULAR(f
)] );
769 COPY_4FV( params
, mat
[MAT_ATTRIB_EMISSION(f
)] );
772 *params
= mat
[MAT_ATTRIB_SHININESS(f
)][0];
774 case GL_COLOR_INDEXES
:
775 params
[0] = mat
[MAT_ATTRIB_INDEXES(f
)][0];
776 params
[1] = mat
[MAT_ATTRIB_INDEXES(f
)][1];
777 params
[2] = mat
[MAT_ATTRIB_INDEXES(f
)][2];
780 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMaterialfv(pname)" );
786 _mesa_GetMaterialiv( GLenum face
, GLenum pname
, GLint
*params
)
788 GET_CURRENT_CONTEXT(ctx
);
790 GLfloat (*mat
)[4] = ctx
->Light
.Material
.Attrib
;
791 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
); /* update materials */
793 FLUSH_CURRENT(ctx
, 0); /* update ctx->Light.Material from vertex buffer */
795 if (face
==GL_FRONT
) {
798 else if (face
==GL_BACK
) {
802 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMaterialiv(face)" );
807 params
[0] = FLOAT_TO_INT( mat
[MAT_ATTRIB_AMBIENT(f
)][0] );
808 params
[1] = FLOAT_TO_INT( mat
[MAT_ATTRIB_AMBIENT(f
)][1] );
809 params
[2] = FLOAT_TO_INT( mat
[MAT_ATTRIB_AMBIENT(f
)][2] );
810 params
[3] = FLOAT_TO_INT( mat
[MAT_ATTRIB_AMBIENT(f
)][3] );
813 params
[0] = FLOAT_TO_INT( mat
[MAT_ATTRIB_DIFFUSE(f
)][0] );
814 params
[1] = FLOAT_TO_INT( mat
[MAT_ATTRIB_DIFFUSE(f
)][1] );
815 params
[2] = FLOAT_TO_INT( mat
[MAT_ATTRIB_DIFFUSE(f
)][2] );
816 params
[3] = FLOAT_TO_INT( mat
[MAT_ATTRIB_DIFFUSE(f
)][3] );
819 params
[0] = FLOAT_TO_INT( mat
[MAT_ATTRIB_SPECULAR(f
)][0] );
820 params
[1] = FLOAT_TO_INT( mat
[MAT_ATTRIB_SPECULAR(f
)][1] );
821 params
[2] = FLOAT_TO_INT( mat
[MAT_ATTRIB_SPECULAR(f
)][2] );
822 params
[3] = FLOAT_TO_INT( mat
[MAT_ATTRIB_SPECULAR(f
)][3] );
825 params
[0] = FLOAT_TO_INT( mat
[MAT_ATTRIB_EMISSION(f
)][0] );
826 params
[1] = FLOAT_TO_INT( mat
[MAT_ATTRIB_EMISSION(f
)][1] );
827 params
[2] = FLOAT_TO_INT( mat
[MAT_ATTRIB_EMISSION(f
)][2] );
828 params
[3] = FLOAT_TO_INT( mat
[MAT_ATTRIB_EMISSION(f
)][3] );
831 *params
= IROUND( mat
[MAT_ATTRIB_SHININESS(f
)][0] );
833 case GL_COLOR_INDEXES
:
834 params
[0] = IROUND( mat
[MAT_ATTRIB_INDEXES(f
)][0] );
835 params
[1] = IROUND( mat
[MAT_ATTRIB_INDEXES(f
)][1] );
836 params
[2] = IROUND( mat
[MAT_ATTRIB_INDEXES(f
)][2] );
839 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMaterialfv(pname)" );
845 /**********************************************************************/
846 /***** Lighting computation *****/
847 /**********************************************************************/
852 * When two-sided lighting is enabled we compute the color (or index)
853 * for both the front and back side of the primitive. Then, when the
854 * orientation of the facet is later learned, we can determine which
855 * color (or index) to use for rendering.
857 * KW: We now know orientation in advance and only shade for
858 * the side or sides which are actually required.
862 * V = vertex position
863 * P = light source position
868 * // light at infinity
869 * IF local_viewer THEN
870 * _VP_inf_norm = unit vector from V to P // Precompute
873 * _h_inf_norm = Normalize( VP + <0,0,1> ) // Precompute
878 * Normalize( v ) = normalized vector v
879 * Magnitude( v ) = length of vector v
885 * Whenever the spotlight exponent for a light changes we must call
886 * this function to recompute the exponent lookup table.
889 _mesa_invalidate_spot_exp_table( struct gl_light
*l
)
891 l
->_SpotExpTable
[0][0] = -1;
896 validate_spot_exp_table( struct gl_light
*l
)
899 GLdouble exponent
= l
->SpotExponent
;
903 l
->_SpotExpTable
[0][0] = 0.0;
905 for (i
= EXP_TABLE_SIZE
- 1; i
> 0 ;i
--) {
907 tmp
= pow(i
/ (GLdouble
) (EXP_TABLE_SIZE
- 1), exponent
);
908 if (tmp
< FLT_MIN
* 100.0) {
913 l
->_SpotExpTable
[i
][0] = (GLfloat
) tmp
;
915 for (i
= 0; i
< EXP_TABLE_SIZE
- 1; i
++) {
916 l
->_SpotExpTable
[i
][1] = (l
->_SpotExpTable
[i
+1][0] -
917 l
->_SpotExpTable
[i
][0]);
919 l
->_SpotExpTable
[EXP_TABLE_SIZE
-1][1] = 0.0;
924 /* Calculate a new shine table. Doing this here saves a branch in
925 * lighting, and the cost of doing it early may be partially offset
926 * by keeping a MRU cache of shine tables for various shine values.
929 _mesa_invalidate_shine_table( struct gl_context
*ctx
, GLuint side
)
932 if (ctx
->_ShineTable
[side
])
933 ctx
->_ShineTable
[side
]->refcount
--;
934 ctx
->_ShineTable
[side
] = NULL
;
939 validate_shine_table( struct gl_context
*ctx
, GLuint side
, GLfloat shininess
)
941 struct gl_shine_tab
*list
= ctx
->_ShineTabList
;
942 struct gl_shine_tab
*s
;
947 if ( s
->shininess
== shininess
)
955 if (s
->refcount
== 0)
960 if (shininess
== 0.0) {
961 for (j
= 1 ; j
<= SHINE_TABLE_SIZE
; j
++)
965 for (j
= 1 ; j
< SHINE_TABLE_SIZE
; j
++) {
966 GLdouble t
, x
= j
/ (GLfloat
) (SHINE_TABLE_SIZE
- 1);
967 if (x
< 0.005) /* underflow check */
969 t
= pow(x
, shininess
);
975 m
[SHINE_TABLE_SIZE
] = 1.0;
978 s
->shininess
= shininess
;
981 if (ctx
->_ShineTable
[side
])
982 ctx
->_ShineTable
[side
]->refcount
--;
984 ctx
->_ShineTable
[side
] = s
;
985 move_to_tail( list
, s
);
991 _mesa_validate_all_lighting_tables( struct gl_context
*ctx
)
996 shininess
= ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_SHININESS
][0];
997 if (!ctx
->_ShineTable
[0] || ctx
->_ShineTable
[0]->shininess
!= shininess
)
998 validate_shine_table( ctx
, 0, shininess
);
1000 shininess
= ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_BACK_SHININESS
][0];
1001 if (!ctx
->_ShineTable
[1] || ctx
->_ShineTable
[1]->shininess
!= shininess
)
1002 validate_shine_table( ctx
, 1, shininess
);
1004 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++)
1005 if (ctx
->Light
.Light
[i
]._SpotExpTable
[0][0] == -1)
1006 validate_spot_exp_table( &ctx
->Light
.Light
[i
] );
1011 * Examine current lighting parameters to determine if the optimized lighting
1012 * function can be used.
1013 * Also, precompute some lighting values such as the products of light
1014 * source and material ambient, diffuse and specular coefficients.
1017 _mesa_update_lighting( struct gl_context
*ctx
)
1019 struct gl_light
*light
;
1020 ctx
->Light
._NeedEyeCoords
= GL_FALSE
;
1021 ctx
->Light
._Flags
= 0;
1023 if (!ctx
->Light
.Enabled
)
1026 foreach(light
, &ctx
->Light
.EnabledList
) {
1027 ctx
->Light
._Flags
|= light
->_Flags
;
1030 ctx
->Light
._NeedVertices
=
1031 ((ctx
->Light
._Flags
& (LIGHT_POSITIONAL
|LIGHT_SPOT
)) ||
1032 ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
||
1033 ctx
->Light
.Model
.LocalViewer
);
1035 ctx
->Light
._NeedEyeCoords
= ((ctx
->Light
._Flags
& LIGHT_POSITIONAL
) ||
1036 ctx
->Light
.Model
.LocalViewer
);
1038 /* XXX: This test is overkill & needs to be fixed both for software and
1039 * hardware t&l drivers. The above should be sufficient & should
1040 * be tested to verify this.
1042 if (ctx
->Light
._NeedVertices
)
1043 ctx
->Light
._NeedEyeCoords
= GL_TRUE
;
1045 /* Precompute some shading values. Although we reference
1046 * Light.Material here, we can get away without flushing
1047 * FLUSH_UPDATE_CURRENT, as when any outstanding material changes
1048 * are flushed, they will update the derived state at that time.
1050 if (ctx
->Light
.Model
.TwoSide
)
1051 _mesa_update_material(ctx
,
1052 MAT_BIT_FRONT_EMISSION
|
1053 MAT_BIT_FRONT_AMBIENT
|
1054 MAT_BIT_FRONT_DIFFUSE
|
1055 MAT_BIT_FRONT_SPECULAR
|
1056 MAT_BIT_BACK_EMISSION
|
1057 MAT_BIT_BACK_AMBIENT
|
1058 MAT_BIT_BACK_DIFFUSE
|
1059 MAT_BIT_BACK_SPECULAR
);
1061 _mesa_update_material(ctx
,
1062 MAT_BIT_FRONT_EMISSION
|
1063 MAT_BIT_FRONT_AMBIENT
|
1064 MAT_BIT_FRONT_DIFFUSE
|
1065 MAT_BIT_FRONT_SPECULAR
);
1070 * Update state derived from light position, spot direction.
1074 * _TNL_NEW_NEED_EYE_COORDS
1076 * Update on (_NEW_MODELVIEW | _NEW_LIGHT) when lighting is enabled.
1077 * Also update on lighting space changes.
1080 compute_light_positions( struct gl_context
*ctx
)
1082 struct gl_light
*light
;
1083 static const GLfloat eye_z
[3] = { 0, 0, 1 };
1085 if (!ctx
->Light
.Enabled
)
1088 if (ctx
->_NeedEyeCoords
) {
1089 COPY_3V( ctx
->_EyeZDir
, eye_z
);
1092 TRANSFORM_NORMAL( ctx
->_EyeZDir
, eye_z
, ctx
->ModelviewMatrixStack
.Top
->m
);
1095 /* Make sure all the light tables are updated before the computation */
1096 _mesa_validate_all_lighting_tables(ctx
);
1098 foreach (light
, &ctx
->Light
.EnabledList
) {
1100 if (ctx
->_NeedEyeCoords
) {
1101 /* _Position is in eye coordinate space */
1102 COPY_4FV( light
->_Position
, light
->EyePosition
);
1105 /* _Position is in object coordinate space */
1106 TRANSFORM_POINT( light
->_Position
, ctx
->ModelviewMatrixStack
.Top
->inv
,
1107 light
->EyePosition
);
1110 if (!(light
->_Flags
& LIGHT_POSITIONAL
)) {
1111 /* VP (VP) = Normalize( Position ) */
1112 COPY_3V( light
->_VP_inf_norm
, light
->_Position
);
1113 NORMALIZE_3FV( light
->_VP_inf_norm
);
1115 if (!ctx
->Light
.Model
.LocalViewer
) {
1116 /* _h_inf_norm = Normalize( V_to_P + <0,0,1> ) */
1117 ADD_3V( light
->_h_inf_norm
, light
->_VP_inf_norm
, ctx
->_EyeZDir
);
1118 NORMALIZE_3FV( light
->_h_inf_norm
);
1120 light
->_VP_inf_spot_attenuation
= 1.0;
1123 /* positional light w/ homogeneous coordinate, divide by W */
1124 GLfloat wInv
= (GLfloat
)1.0 / light
->_Position
[3];
1125 light
->_Position
[0] *= wInv
;
1126 light
->_Position
[1] *= wInv
;
1127 light
->_Position
[2] *= wInv
;
1130 if (light
->_Flags
& LIGHT_SPOT
) {
1131 /* Note: we normalize the spot direction now */
1133 if (ctx
->_NeedEyeCoords
) {
1134 COPY_3V( light
->_NormSpotDirection
, light
->SpotDirection
);
1135 NORMALIZE_3FV( light
->_NormSpotDirection
);
1139 COPY_3V(spotDir
, light
->SpotDirection
);
1140 NORMALIZE_3FV(spotDir
);
1141 TRANSFORM_NORMAL( light
->_NormSpotDirection
,
1143 ctx
->ModelviewMatrixStack
.Top
->m
);
1146 NORMALIZE_3FV( light
->_NormSpotDirection
);
1148 if (!(light
->_Flags
& LIGHT_POSITIONAL
)) {
1149 GLfloat PV_dot_dir
= - DOT3(light
->_VP_inf_norm
,
1150 light
->_NormSpotDirection
);
1152 if (PV_dot_dir
> light
->_CosCutoff
) {
1153 double x
= PV_dot_dir
* (EXP_TABLE_SIZE
-1);
1155 light
->_VP_inf_spot_attenuation
=
1156 (GLfloat
) (light
->_SpotExpTable
[k
][0] +
1157 (x
-k
)*light
->_SpotExpTable
[k
][1]);
1160 light
->_VP_inf_spot_attenuation
= 0;
1170 update_modelview_scale( struct gl_context
*ctx
)
1172 ctx
->_ModelViewInvScale
= 1.0F
;
1173 if (!_math_matrix_is_length_preserving(ctx
->ModelviewMatrixStack
.Top
)) {
1174 const GLfloat
*m
= ctx
->ModelviewMatrixStack
.Top
->inv
;
1175 GLfloat f
= m
[2] * m
[2] + m
[6] * m
[6] + m
[10] * m
[10];
1176 if (f
< 1e-12) f
= 1.0;
1177 if (ctx
->_NeedEyeCoords
)
1178 ctx
->_ModelViewInvScale
= (GLfloat
) INV_SQRTF(f
);
1180 ctx
->_ModelViewInvScale
= (GLfloat
) SQRTF(f
);
1186 * Bring up to date any state that relies on _NeedEyeCoords.
1189 _mesa_update_tnl_spaces( struct gl_context
*ctx
, GLuint new_state
)
1191 const GLuint oldneedeyecoords
= ctx
->_NeedEyeCoords
;
1194 ctx
->_NeedEyeCoords
= GL_FALSE
;
1196 if (ctx
->_ForceEyeCoords
||
1197 (ctx
->Texture
._GenFlags
& TEXGEN_NEED_EYE_COORD
) ||
1198 ctx
->Point
._Attenuated
||
1199 ctx
->Light
._NeedEyeCoords
)
1200 ctx
->_NeedEyeCoords
= GL_TRUE
;
1202 if (ctx
->Light
.Enabled
&&
1203 !_math_matrix_is_length_preserving(ctx
->ModelviewMatrixStack
.Top
))
1204 ctx
->_NeedEyeCoords
= GL_TRUE
;
1206 /* Check if the truth-value interpretations of the bitfields have
1209 if (oldneedeyecoords
!= ctx
->_NeedEyeCoords
) {
1210 /* Recalculate all state that depends on _NeedEyeCoords.
1212 update_modelview_scale(ctx
);
1213 compute_light_positions( ctx
);
1215 if (ctx
->Driver
.LightingSpaceChange
)
1216 ctx
->Driver
.LightingSpaceChange( ctx
);
1219 GLuint new_state2
= ctx
->NewState
;
1221 /* Recalculate that same state only if it has been invalidated
1222 * by other statechanges.
1224 if (new_state2
& _NEW_MODELVIEW
)
1225 update_modelview_scale(ctx
);
1227 if (new_state2
& (_NEW_LIGHT
|_NEW_MODELVIEW
))
1228 compute_light_positions( ctx
);
1234 * Drivers may need this if the hardware tnl unit doesn't support the
1235 * light-in-modelspace optimization. It's also useful for debugging.
1238 _mesa_allow_light_in_model( struct gl_context
*ctx
, GLboolean flag
)
1240 ctx
->_ForceEyeCoords
= !flag
;
1241 ctx
->NewState
|= _NEW_POINT
; /* one of the bits from
1242 * _MESA_NEW_NEED_EYE_COORDS.
1248 /**********************************************************************/
1249 /***** Initialization *****/
1250 /**********************************************************************/
1253 * Initialize the n-th light data structure.
1255 * \param l pointer to the gl_light structure to be initialized.
1256 * \param n number of the light.
1257 * \note The defaults for light 0 are different than the other lights.
1260 init_light( struct gl_light
*l
, GLuint n
)
1262 make_empty_list( l
);
1264 ASSIGN_4V( l
->Ambient
, 0.0, 0.0, 0.0, 1.0 );
1266 ASSIGN_4V( l
->Diffuse
, 1.0, 1.0, 1.0, 1.0 );
1267 ASSIGN_4V( l
->Specular
, 1.0, 1.0, 1.0, 1.0 );
1270 ASSIGN_4V( l
->Diffuse
, 0.0, 0.0, 0.0, 1.0 );
1271 ASSIGN_4V( l
->Specular
, 0.0, 0.0, 0.0, 1.0 );
1273 ASSIGN_4V( l
->EyePosition
, 0.0, 0.0, 1.0, 0.0 );
1274 ASSIGN_3V( l
->SpotDirection
, 0.0, 0.0, -1.0 );
1275 l
->SpotExponent
= 0.0;
1276 _mesa_invalidate_spot_exp_table( l
);
1277 l
->SpotCutoff
= 180.0;
1278 l
->_CosCutoffNeg
= -1.0f
;
1279 l
->_CosCutoff
= 0.0; /* KW: -ve values not admitted */
1280 l
->ConstantAttenuation
= 1.0;
1281 l
->LinearAttenuation
= 0.0;
1282 l
->QuadraticAttenuation
= 0.0;
1283 l
->Enabled
= GL_FALSE
;
1288 * Initialize the light model data structure.
1290 * \param lm pointer to the gl_lightmodel structure to be initialized.
1293 init_lightmodel( struct gl_lightmodel
*lm
)
1295 ASSIGN_4V( lm
->Ambient
, 0.2F
, 0.2F
, 0.2F
, 1.0F
);
1296 lm
->LocalViewer
= GL_FALSE
;
1297 lm
->TwoSide
= GL_FALSE
;
1298 lm
->ColorControl
= GL_SINGLE_COLOR
;
1303 * Initialize the material data structure.
1305 * \param m pointer to the gl_material structure to be initialized.
1308 init_material( struct gl_material
*m
)
1310 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_FRONT_AMBIENT
], 0.2F
, 0.2F
, 0.2F
, 1.0F
);
1311 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
], 0.8F
, 0.8F
, 0.8F
, 1.0F
);
1312 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_FRONT_SPECULAR
], 0.0F
, 0.0F
, 0.0F
, 1.0F
);
1313 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_FRONT_EMISSION
], 0.0F
, 0.0F
, 0.0F
, 1.0F
);
1314 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_FRONT_SHININESS
], 0.0F
, 0.0F
, 0.0F
, 0.0F
);
1315 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_FRONT_INDEXES
], 0.0F
, 1.0F
, 1.0F
, 0.0F
);
1317 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_BACK_AMBIENT
], 0.2F
, 0.2F
, 0.2F
, 1.0F
);
1318 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_BACK_DIFFUSE
], 0.8F
, 0.8F
, 0.8F
, 1.0F
);
1319 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_BACK_SPECULAR
], 0.0F
, 0.0F
, 0.0F
, 1.0F
);
1320 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_BACK_EMISSION
], 0.0F
, 0.0F
, 0.0F
, 1.0F
);
1321 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_BACK_SHININESS
], 0.0F
, 0.0F
, 0.0F
, 0.0F
);
1322 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_BACK_INDEXES
], 0.0F
, 1.0F
, 1.0F
, 0.0F
);
1327 * Initialize all lighting state for the given context.
1330 _mesa_init_lighting( struct gl_context
*ctx
)
1334 /* Lighting group */
1335 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
1336 init_light( &ctx
->Light
.Light
[i
], i
);
1338 make_empty_list( &ctx
->Light
.EnabledList
);
1340 init_lightmodel( &ctx
->Light
.Model
);
1341 init_material( &ctx
->Light
.Material
);
1342 ctx
->Light
.ShadeModel
= GL_SMOOTH
;
1343 ctx
->Light
.Enabled
= GL_FALSE
;
1344 ctx
->Light
.ColorMaterialFace
= GL_FRONT_AND_BACK
;
1345 ctx
->Light
.ColorMaterialMode
= GL_AMBIENT_AND_DIFFUSE
;
1346 ctx
->Light
.ColorMaterialBitmask
= _mesa_material_bitmask( ctx
,
1348 GL_AMBIENT_AND_DIFFUSE
, ~0,
1351 ctx
->Light
.ColorMaterialEnabled
= GL_FALSE
;
1352 ctx
->Light
.ClampVertexColor
= GL_TRUE
;
1354 /* Lighting miscellaneous */
1355 ctx
->_ShineTabList
= MALLOC_STRUCT( gl_shine_tab
);
1356 make_empty_list( ctx
->_ShineTabList
);
1357 /* Allocate 10 (arbitrary) shininess lookup tables */
1358 for (i
= 0 ; i
< 10 ; i
++) {
1359 struct gl_shine_tab
*s
= MALLOC_STRUCT( gl_shine_tab
);
1362 insert_at_tail( ctx
->_ShineTabList
, s
);
1366 ctx
->Light
._NeedEyeCoords
= GL_FALSE
;
1367 ctx
->_NeedEyeCoords
= GL_FALSE
;
1368 ctx
->_ForceEyeCoords
= GL_FALSE
;
1369 ctx
->_ModelViewInvScale
= 1.0;
1374 * Deallocate malloc'd lighting state attached to given context.
1377 _mesa_free_lighting_data( struct gl_context
*ctx
)
1379 struct gl_shine_tab
*s
, *tmps
;
1381 /* Free lighting shininess exponentiation table */
1382 foreach_s( s
, tmps
, ctx
->_ShineTabList
) {
1385 free( ctx
->_ShineTabList
);