2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #include "simple_list.h"
34 #include "math/m_matrix.h"
38 _mesa_ShadeModel( GLenum mode
)
40 GET_CURRENT_CONTEXT(ctx
);
41 ASSERT_OUTSIDE_BEGIN_END(ctx
);
43 if (MESA_VERBOSE
& VERBOSE_API
)
44 _mesa_debug(ctx
, "glShadeModel %s\n", _mesa_lookup_enum_by_nr(mode
));
46 if (mode
!= GL_FLAT
&& mode
!= GL_SMOOTH
) {
47 _mesa_error(ctx
, GL_INVALID_ENUM
, "glShadeModel");
51 if (ctx
->Light
.ShadeModel
== mode
)
54 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
55 ctx
->Light
.ShadeModel
= mode
;
57 ctx
->_TriangleCaps
|= DD_FLATSHADE
;
59 ctx
->_TriangleCaps
&= ~DD_FLATSHADE
;
61 if (ctx
->Driver
.ShadeModel
)
62 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(GLcontext
*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
->EyeDirection
, params
))
115 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
116 COPY_3V(light
->EyeDirection
, 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
) (_mesa_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
)
177 _mesa_Lightfv( light
, pname
, ¶m
);
182 _mesa_Lightfv( GLenum light
, GLenum pname
, const GLfloat
*params
)
184 GET_CURRENT_CONTEXT(ctx
);
185 GLint i
= (GLint
) (light
- GL_LIGHT0
);
188 if (i
< 0 || i
>= (GLint
) ctx
->Const
.MaxLights
) {
189 _mesa_error( ctx
, GL_INVALID_ENUM
, "glLight(light=0x%x)", light
);
193 /* do particular error checks, transformations */
201 /* transform position by ModelView matrix */
202 TRANSFORM_POINT(temp
, ctx
->ModelviewMatrixStack
.Top
->m
, params
);
205 case GL_SPOT_DIRECTION
:
206 /* transform direction by inverse modelview */
207 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
208 _math_matrix_analyse(ctx
->ModelviewMatrixStack
.Top
);
210 TRANSFORM_NORMAL(temp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
213 case GL_SPOT_EXPONENT
:
214 if (params
[0] < 0.0 || params
[0] > ctx
->Const
.MaxSpotExponent
) {
215 _mesa_error(ctx
, GL_INVALID_VALUE
, "glLight");
220 if ((params
[0] < 0.0 || params
[0] > 90.0) && params
[0] != 180.0) {
221 _mesa_error(ctx
, GL_INVALID_VALUE
, "glLight");
225 case GL_CONSTANT_ATTENUATION
:
226 if (params
[0] < 0.0) {
227 _mesa_error(ctx
, GL_INVALID_VALUE
, "glLight");
231 case GL_LINEAR_ATTENUATION
:
232 if (params
[0] < 0.0) {
233 _mesa_error(ctx
, GL_INVALID_VALUE
, "glLight");
237 case GL_QUADRATIC_ATTENUATION
:
238 if (params
[0] < 0.0) {
239 _mesa_error(ctx
, GL_INVALID_VALUE
, "glLight");
244 _mesa_error(ctx
, GL_INVALID_ENUM
, "glLight(pname=0x%x)", pname
);
248 _mesa_light(ctx
, i
, pname
, params
);
253 _mesa_Lighti( GLenum light
, GLenum pname
, GLint param
)
255 _mesa_Lightiv( light
, pname
, ¶m
);
260 _mesa_Lightiv( GLenum light
, GLenum pname
, const GLint
*params
)
268 fparam
[0] = INT_TO_FLOAT( params
[0] );
269 fparam
[1] = INT_TO_FLOAT( params
[1] );
270 fparam
[2] = INT_TO_FLOAT( params
[2] );
271 fparam
[3] = INT_TO_FLOAT( params
[3] );
274 fparam
[0] = (GLfloat
) params
[0];
275 fparam
[1] = (GLfloat
) params
[1];
276 fparam
[2] = (GLfloat
) params
[2];
277 fparam
[3] = (GLfloat
) params
[3];
279 case GL_SPOT_DIRECTION
:
280 fparam
[0] = (GLfloat
) params
[0];
281 fparam
[1] = (GLfloat
) params
[1];
282 fparam
[2] = (GLfloat
) params
[2];
284 case GL_SPOT_EXPONENT
:
286 case GL_CONSTANT_ATTENUATION
:
287 case GL_LINEAR_ATTENUATION
:
288 case GL_QUADRATIC_ATTENUATION
:
289 fparam
[0] = (GLfloat
) params
[0];
292 /* error will be caught later in gl_Lightfv */
296 _mesa_Lightfv( light
, pname
, fparam
);
302 _mesa_GetLightfv( GLenum light
, GLenum pname
, GLfloat
*params
)
304 GET_CURRENT_CONTEXT(ctx
);
305 GLint l
= (GLint
) (light
- GL_LIGHT0
);
306 ASSERT_OUTSIDE_BEGIN_END(ctx
);
308 if (l
< 0 || l
>= (GLint
) ctx
->Const
.MaxLights
) {
309 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetLightfv" );
315 COPY_4V( params
, ctx
->Light
.Light
[l
].Ambient
);
318 COPY_4V( params
, ctx
->Light
.Light
[l
].Diffuse
);
321 COPY_4V( params
, ctx
->Light
.Light
[l
].Specular
);
324 COPY_4V( params
, ctx
->Light
.Light
[l
].EyePosition
);
326 case GL_SPOT_DIRECTION
:
327 COPY_3V( params
, ctx
->Light
.Light
[l
].EyeDirection
);
329 case GL_SPOT_EXPONENT
:
330 params
[0] = ctx
->Light
.Light
[l
].SpotExponent
;
333 params
[0] = ctx
->Light
.Light
[l
].SpotCutoff
;
335 case GL_CONSTANT_ATTENUATION
:
336 params
[0] = ctx
->Light
.Light
[l
].ConstantAttenuation
;
338 case GL_LINEAR_ATTENUATION
:
339 params
[0] = ctx
->Light
.Light
[l
].LinearAttenuation
;
341 case GL_QUADRATIC_ATTENUATION
:
342 params
[0] = ctx
->Light
.Light
[l
].QuadraticAttenuation
;
345 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetLightfv" );
352 _mesa_GetLightiv( GLenum light
, GLenum pname
, GLint
*params
)
354 GET_CURRENT_CONTEXT(ctx
);
355 GLint l
= (GLint
) (light
- GL_LIGHT0
);
356 ASSERT_OUTSIDE_BEGIN_END(ctx
);
358 if (l
< 0 || l
>= (GLint
) ctx
->Const
.MaxLights
) {
359 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetLightiv" );
365 params
[0] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Ambient
[0]);
366 params
[1] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Ambient
[1]);
367 params
[2] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Ambient
[2]);
368 params
[3] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Ambient
[3]);
371 params
[0] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Diffuse
[0]);
372 params
[1] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Diffuse
[1]);
373 params
[2] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Diffuse
[2]);
374 params
[3] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Diffuse
[3]);
377 params
[0] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Specular
[0]);
378 params
[1] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Specular
[1]);
379 params
[2] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Specular
[2]);
380 params
[3] = FLOAT_TO_INT(ctx
->Light
.Light
[l
].Specular
[3]);
383 params
[0] = (GLint
) ctx
->Light
.Light
[l
].EyePosition
[0];
384 params
[1] = (GLint
) ctx
->Light
.Light
[l
].EyePosition
[1];
385 params
[2] = (GLint
) ctx
->Light
.Light
[l
].EyePosition
[2];
386 params
[3] = (GLint
) ctx
->Light
.Light
[l
].EyePosition
[3];
388 case GL_SPOT_DIRECTION
:
389 params
[0] = (GLint
) ctx
->Light
.Light
[l
].EyeDirection
[0];
390 params
[1] = (GLint
) ctx
->Light
.Light
[l
].EyeDirection
[1];
391 params
[2] = (GLint
) ctx
->Light
.Light
[l
].EyeDirection
[2];
393 case GL_SPOT_EXPONENT
:
394 params
[0] = (GLint
) ctx
->Light
.Light
[l
].SpotExponent
;
397 params
[0] = (GLint
) ctx
->Light
.Light
[l
].SpotCutoff
;
399 case GL_CONSTANT_ATTENUATION
:
400 params
[0] = (GLint
) ctx
->Light
.Light
[l
].ConstantAttenuation
;
402 case GL_LINEAR_ATTENUATION
:
403 params
[0] = (GLint
) ctx
->Light
.Light
[l
].LinearAttenuation
;
405 case GL_QUADRATIC_ATTENUATION
:
406 params
[0] = (GLint
) ctx
->Light
.Light
[l
].QuadraticAttenuation
;
409 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetLightiv" );
416 /**********************************************************************/
417 /*** Light Model ***/
418 /**********************************************************************/
422 _mesa_LightModelfv( GLenum pname
, const GLfloat
*params
)
426 GET_CURRENT_CONTEXT(ctx
);
427 ASSERT_OUTSIDE_BEGIN_END(ctx
);
430 case GL_LIGHT_MODEL_AMBIENT
:
431 if (TEST_EQ_4V( ctx
->Light
.Model
.Ambient
, params
))
433 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
434 COPY_4V( ctx
->Light
.Model
.Ambient
, params
);
436 case GL_LIGHT_MODEL_LOCAL_VIEWER
:
437 newbool
= (params
[0]!=0.0);
438 if (ctx
->Light
.Model
.LocalViewer
== newbool
)
440 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
441 ctx
->Light
.Model
.LocalViewer
= newbool
;
443 case GL_LIGHT_MODEL_TWO_SIDE
:
444 newbool
= (params
[0]!=0.0);
445 if (ctx
->Light
.Model
.TwoSide
== newbool
)
447 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
448 ctx
->Light
.Model
.TwoSide
= newbool
;
449 if (ctx
->Light
.Enabled
&& ctx
->Light
.Model
.TwoSide
)
450 ctx
->_TriangleCaps
|= DD_TRI_LIGHT_TWOSIDE
;
452 ctx
->_TriangleCaps
&= ~DD_TRI_LIGHT_TWOSIDE
;
454 case GL_LIGHT_MODEL_COLOR_CONTROL
:
455 if (params
[0] == (GLfloat
) GL_SINGLE_COLOR
)
456 newenum
= GL_SINGLE_COLOR
;
457 else if (params
[0] == (GLfloat
) GL_SEPARATE_SPECULAR_COLOR
)
458 newenum
= GL_SEPARATE_SPECULAR_COLOR
;
460 _mesa_error( ctx
, GL_INVALID_ENUM
, "glLightModel(param=0x0%x)",
464 if (ctx
->Light
.Model
.ColorControl
== newenum
)
466 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
467 ctx
->Light
.Model
.ColorControl
= newenum
;
470 _mesa_error( ctx
, GL_INVALID_ENUM
, "glLightModel(pname=0x%x)", pname
);
474 if (ctx
->Driver
.LightModelfv
)
475 ctx
->Driver
.LightModelfv( ctx
, pname
, params
);
480 _mesa_LightModeliv( GLenum pname
, const GLint
*params
)
485 case GL_LIGHT_MODEL_AMBIENT
:
486 fparam
[0] = INT_TO_FLOAT( params
[0] );
487 fparam
[1] = INT_TO_FLOAT( params
[1] );
488 fparam
[2] = INT_TO_FLOAT( params
[2] );
489 fparam
[3] = INT_TO_FLOAT( params
[3] );
491 case GL_LIGHT_MODEL_LOCAL_VIEWER
:
492 case GL_LIGHT_MODEL_TWO_SIDE
:
493 case GL_LIGHT_MODEL_COLOR_CONTROL
:
494 fparam
[0] = (GLfloat
) params
[0];
497 /* Error will be caught later in gl_LightModelfv */
500 _mesa_LightModelfv( pname
, fparam
);
505 _mesa_LightModeli( GLenum pname
, GLint param
)
507 _mesa_LightModeliv( pname
, ¶m
);
512 _mesa_LightModelf( GLenum pname
, GLfloat param
)
514 _mesa_LightModelfv( pname
, ¶m
);
519 /********** MATERIAL **********/
523 * Given a face and pname value (ala glColorMaterial), compute a bitmask
524 * of the targeted material values.
527 _mesa_material_bitmask( GLcontext
*ctx
, GLenum face
, GLenum pname
,
528 GLuint legal
, const char *where
)
532 /* Make a bitmask indicating what material attribute(s) we're updating */
535 bitmask
|= MAT_BIT_FRONT_EMISSION
| MAT_BIT_BACK_EMISSION
;
538 bitmask
|= MAT_BIT_FRONT_AMBIENT
| MAT_BIT_BACK_AMBIENT
;
541 bitmask
|= MAT_BIT_FRONT_DIFFUSE
| MAT_BIT_BACK_DIFFUSE
;
544 bitmask
|= MAT_BIT_FRONT_SPECULAR
| MAT_BIT_BACK_SPECULAR
;
547 bitmask
|= MAT_BIT_FRONT_SHININESS
| MAT_BIT_BACK_SHININESS
;
549 case GL_AMBIENT_AND_DIFFUSE
:
550 bitmask
|= MAT_BIT_FRONT_AMBIENT
| MAT_BIT_BACK_AMBIENT
;
551 bitmask
|= MAT_BIT_FRONT_DIFFUSE
| MAT_BIT_BACK_DIFFUSE
;
553 case GL_COLOR_INDEXES
:
554 bitmask
|= MAT_BIT_FRONT_INDEXES
| MAT_BIT_BACK_INDEXES
;
557 _mesa_error( ctx
, GL_INVALID_ENUM
, where
);
561 if (face
==GL_FRONT
) {
562 bitmask
&= FRONT_MATERIAL_BITS
;
564 else if (face
==GL_BACK
) {
565 bitmask
&= BACK_MATERIAL_BITS
;
567 else if (face
!= GL_FRONT_AND_BACK
) {
568 _mesa_error( ctx
, GL_INVALID_ENUM
, where
);
572 if (bitmask
& ~legal
) {
573 _mesa_error( ctx
, GL_INVALID_ENUM
, where
);
582 /* Perform a straight copy between materials.
585 _mesa_copy_materials( struct gl_material
*dst
,
586 const struct gl_material
*src
,
591 for (i
= 0 ; i
< MAT_ATTRIB_MAX
; i
++)
592 if (bitmask
& (1<<i
))
593 COPY_4FV( dst
->Attrib
[i
], src
->Attrib
[i
] );
598 /* Update derived values following a change in ctx->Light.Material
601 _mesa_update_material( GLcontext
*ctx
, GLuint bitmask
)
603 struct gl_light
*light
, *list
= &ctx
->Light
.EnabledList
;
604 GLfloat (*mat
)[4] = ctx
->Light
.Material
.Attrib
;
606 if (MESA_VERBOSE
&VERBOSE_IMMEDIATE
)
607 _mesa_debug(ctx
, "_mesa_update_material, mask 0x%x\n", bitmask
);
612 /* update material ambience */
613 if (bitmask
& MAT_BIT_FRONT_AMBIENT
) {
614 foreach (light
, list
) {
615 SCALE_3V( light
->_MatAmbient
[0], light
->Ambient
,
616 mat
[MAT_ATTRIB_FRONT_AMBIENT
]);
620 if (bitmask
& MAT_BIT_BACK_AMBIENT
) {
621 foreach (light
, list
) {
622 SCALE_3V( light
->_MatAmbient
[1], light
->Ambient
,
623 mat
[MAT_ATTRIB_BACK_AMBIENT
]);
627 /* update BaseColor = emission + scene's ambience * material's ambience */
628 if (bitmask
& (MAT_BIT_FRONT_EMISSION
| MAT_BIT_FRONT_AMBIENT
)) {
629 COPY_3V( ctx
->Light
._BaseColor
[0], mat
[MAT_ATTRIB_FRONT_EMISSION
] );
630 ACC_SCALE_3V( ctx
->Light
._BaseColor
[0], mat
[MAT_ATTRIB_FRONT_AMBIENT
],
631 ctx
->Light
.Model
.Ambient
);
634 if (bitmask
& (MAT_BIT_BACK_EMISSION
| MAT_BIT_BACK_AMBIENT
)) {
635 COPY_3V( ctx
->Light
._BaseColor
[1], mat
[MAT_ATTRIB_BACK_EMISSION
] );
636 ACC_SCALE_3V( ctx
->Light
._BaseColor
[1], mat
[MAT_ATTRIB_BACK_AMBIENT
],
637 ctx
->Light
.Model
.Ambient
);
640 /* update material diffuse values */
641 if (bitmask
& MAT_BIT_FRONT_DIFFUSE
) {
642 foreach (light
, list
) {
643 SCALE_3V( light
->_MatDiffuse
[0], light
->Diffuse
,
644 mat
[MAT_ATTRIB_FRONT_DIFFUSE
] );
648 if (bitmask
& MAT_BIT_BACK_DIFFUSE
) {
649 foreach (light
, list
) {
650 SCALE_3V( light
->_MatDiffuse
[1], light
->Diffuse
,
651 mat
[MAT_ATTRIB_BACK_DIFFUSE
] );
655 /* update material specular values */
656 if (bitmask
& MAT_BIT_FRONT_SPECULAR
) {
657 foreach (light
, list
) {
658 SCALE_3V( light
->_MatSpecular
[0], light
->Specular
,
659 mat
[MAT_ATTRIB_FRONT_SPECULAR
]);
663 if (bitmask
& MAT_BIT_BACK_SPECULAR
) {
664 foreach (light
, list
) {
665 SCALE_3V( light
->_MatSpecular
[1], light
->Specular
,
666 mat
[MAT_ATTRIB_BACK_SPECULAR
]);
670 if (bitmask
& MAT_BIT_FRONT_SHININESS
) {
671 _mesa_invalidate_shine_table( ctx
, 0 );
674 if (bitmask
& MAT_BIT_BACK_SHININESS
) {
675 _mesa_invalidate_shine_table( ctx
, 1 );
681 * Update the current materials from the given rgba color
682 * according to the bitmask in ColorMaterialBitmask, which is
683 * set by glColorMaterial().
686 _mesa_update_color_material( GLcontext
*ctx
, const GLfloat color
[4] )
688 GLuint bitmask
= ctx
->Light
.ColorMaterialBitmask
;
689 struct gl_material
*mat
= &ctx
->Light
.Material
;
692 for (i
= 0 ; i
< MAT_ATTRIB_MAX
; i
++)
693 if (bitmask
& (1<<i
))
694 COPY_4FV( mat
->Attrib
[i
], color
);
696 _mesa_update_material( ctx
, bitmask
);
701 _mesa_ColorMaterial( GLenum face
, GLenum mode
)
703 GET_CURRENT_CONTEXT(ctx
);
705 GLuint legal
= (MAT_BIT_FRONT_EMISSION
| MAT_BIT_BACK_EMISSION
|
706 MAT_BIT_FRONT_SPECULAR
| MAT_BIT_BACK_SPECULAR
|
707 MAT_BIT_FRONT_DIFFUSE
| MAT_BIT_BACK_DIFFUSE
|
708 MAT_BIT_FRONT_AMBIENT
| MAT_BIT_BACK_AMBIENT
);
709 ASSERT_OUTSIDE_BEGIN_END(ctx
);
711 if (MESA_VERBOSE
&VERBOSE_API
)
712 _mesa_debug(ctx
, "glColorMaterial %s %s\n",
713 _mesa_lookup_enum_by_nr(face
),
714 _mesa_lookup_enum_by_nr(mode
));
716 bitmask
= _mesa_material_bitmask(ctx
, face
, mode
, legal
, "glColorMaterial");
718 if (ctx
->Light
.ColorMaterialBitmask
== bitmask
&&
719 ctx
->Light
.ColorMaterialFace
== face
&&
720 ctx
->Light
.ColorMaterialMode
== mode
)
723 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
724 ctx
->Light
.ColorMaterialBitmask
= bitmask
;
725 ctx
->Light
.ColorMaterialFace
= face
;
726 ctx
->Light
.ColorMaterialMode
= mode
;
728 if (ctx
->Light
.ColorMaterialEnabled
) {
729 FLUSH_CURRENT( ctx
, 0 );
730 _mesa_update_color_material(ctx
,ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
]);
733 if (ctx
->Driver
.ColorMaterial
)
734 ctx
->Driver
.ColorMaterial( ctx
, face
, mode
);
739 _mesa_GetMaterialfv( GLenum face
, GLenum pname
, GLfloat
*params
)
741 GET_CURRENT_CONTEXT(ctx
);
743 GLfloat (*mat
)[4] = ctx
->Light
.Material
.Attrib
;
744 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
); /* update materials */
746 FLUSH_CURRENT(ctx
, 0); /* update ctx->Light.Material from vertex buffer */
748 if (face
==GL_FRONT
) {
751 else if (face
==GL_BACK
) {
755 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMaterialfv(face)" );
761 COPY_4FV( params
, mat
[MAT_ATTRIB_AMBIENT(f
)] );
764 COPY_4FV( params
, mat
[MAT_ATTRIB_DIFFUSE(f
)] );
767 COPY_4FV( params
, mat
[MAT_ATTRIB_SPECULAR(f
)] );
770 COPY_4FV( params
, mat
[MAT_ATTRIB_EMISSION(f
)] );
773 *params
= mat
[MAT_ATTRIB_SHININESS(f
)][0];
775 case GL_COLOR_INDEXES
:
776 params
[0] = mat
[MAT_ATTRIB_INDEXES(f
)][0];
777 params
[1] = mat
[MAT_ATTRIB_INDEXES(f
)][1];
778 params
[2] = mat
[MAT_ATTRIB_INDEXES(f
)][2];
781 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMaterialfv(pname)" );
787 _mesa_GetMaterialiv( GLenum face
, GLenum pname
, GLint
*params
)
789 GET_CURRENT_CONTEXT(ctx
);
791 GLfloat (*mat
)[4] = ctx
->Light
.Material
.Attrib
;
792 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
); /* update materials */
794 FLUSH_CURRENT(ctx
, 0); /* update ctx->Light.Material from vertex buffer */
796 if (face
==GL_FRONT
) {
799 else if (face
==GL_BACK
) {
803 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMaterialiv(face)" );
808 params
[0] = FLOAT_TO_INT( mat
[MAT_ATTRIB_AMBIENT(f
)][0] );
809 params
[1] = FLOAT_TO_INT( mat
[MAT_ATTRIB_AMBIENT(f
)][1] );
810 params
[2] = FLOAT_TO_INT( mat
[MAT_ATTRIB_AMBIENT(f
)][2] );
811 params
[3] = FLOAT_TO_INT( mat
[MAT_ATTRIB_AMBIENT(f
)][3] );
814 params
[0] = FLOAT_TO_INT( mat
[MAT_ATTRIB_DIFFUSE(f
)][0] );
815 params
[1] = FLOAT_TO_INT( mat
[MAT_ATTRIB_DIFFUSE(f
)][1] );
816 params
[2] = FLOAT_TO_INT( mat
[MAT_ATTRIB_DIFFUSE(f
)][2] );
817 params
[3] = FLOAT_TO_INT( mat
[MAT_ATTRIB_DIFFUSE(f
)][3] );
820 params
[0] = FLOAT_TO_INT( mat
[MAT_ATTRIB_SPECULAR(f
)][0] );
821 params
[1] = FLOAT_TO_INT( mat
[MAT_ATTRIB_SPECULAR(f
)][1] );
822 params
[2] = FLOAT_TO_INT( mat
[MAT_ATTRIB_SPECULAR(f
)][2] );
823 params
[3] = FLOAT_TO_INT( mat
[MAT_ATTRIB_SPECULAR(f
)][3] );
826 params
[0] = FLOAT_TO_INT( mat
[MAT_ATTRIB_EMISSION(f
)][0] );
827 params
[1] = FLOAT_TO_INT( mat
[MAT_ATTRIB_EMISSION(f
)][1] );
828 params
[2] = FLOAT_TO_INT( mat
[MAT_ATTRIB_EMISSION(f
)][2] );
829 params
[3] = FLOAT_TO_INT( mat
[MAT_ATTRIB_EMISSION(f
)][3] );
832 *params
= IROUND( mat
[MAT_ATTRIB_SHININESS(f
)][0] );
834 case GL_COLOR_INDEXES
:
835 params
[0] = IROUND( mat
[MAT_ATTRIB_INDEXES(f
)][0] );
836 params
[1] = IROUND( mat
[MAT_ATTRIB_INDEXES(f
)][1] );
837 params
[2] = IROUND( mat
[MAT_ATTRIB_INDEXES(f
)][2] );
840 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetMaterialfv(pname)" );
846 /**********************************************************************/
847 /***** Lighting computation *****/
848 /**********************************************************************/
853 * When two-sided lighting is enabled we compute the color (or index)
854 * for both the front and back side of the primitive. Then, when the
855 * orientation of the facet is later learned, we can determine which
856 * color (or index) to use for rendering.
858 * KW: We now know orientation in advance and only shade for
859 * the side or sides which are actually required.
863 * V = vertex position
864 * P = light source position
869 * // light at infinity
870 * IF local_viewer THEN
871 * _VP_inf_norm = unit vector from V to P // Precompute
874 * _h_inf_norm = Normalize( VP + <0,0,1> ) // Precompute
879 * Normalize( v ) = normalized vector v
880 * Magnitude( v ) = length of vector v
886 * Whenever the spotlight exponent for a light changes we must call
887 * this function to recompute the exponent lookup table.
890 _mesa_invalidate_spot_exp_table( struct gl_light
*l
)
892 l
->_SpotExpTable
[0][0] = -1;
897 validate_spot_exp_table( struct gl_light
*l
)
900 GLdouble exponent
= l
->SpotExponent
;
904 l
->_SpotExpTable
[0][0] = 0.0;
906 for (i
= EXP_TABLE_SIZE
- 1; i
> 0 ;i
--) {
908 tmp
= _mesa_pow(i
/ (GLdouble
) (EXP_TABLE_SIZE
- 1), exponent
);
909 if (tmp
< FLT_MIN
* 100.0) {
914 l
->_SpotExpTable
[i
][0] = (GLfloat
) tmp
;
916 for (i
= 0; i
< EXP_TABLE_SIZE
- 1; i
++) {
917 l
->_SpotExpTable
[i
][1] = (l
->_SpotExpTable
[i
+1][0] -
918 l
->_SpotExpTable
[i
][0]);
920 l
->_SpotExpTable
[EXP_TABLE_SIZE
-1][1] = 0.0;
925 /* Calculate a new shine table. Doing this here saves a branch in
926 * lighting, and the cost of doing it early may be partially offset
927 * by keeping a MRU cache of shine tables for various shine values.
930 _mesa_invalidate_shine_table( GLcontext
*ctx
, GLuint side
)
933 if (ctx
->_ShineTable
[side
])
934 ctx
->_ShineTable
[side
]->refcount
--;
935 ctx
->_ShineTable
[side
] = NULL
;
940 validate_shine_table( GLcontext
*ctx
, GLuint side
, GLfloat shininess
)
942 struct gl_shine_tab
*list
= ctx
->_ShineTabList
;
943 struct gl_shine_tab
*s
;
948 if ( s
->shininess
== shininess
)
956 if (s
->refcount
== 0)
961 if (shininess
== 0.0) {
962 for (j
= 1 ; j
<= SHINE_TABLE_SIZE
; j
++)
966 for (j
= 1 ; j
< SHINE_TABLE_SIZE
; j
++) {
967 GLdouble t
, x
= j
/ (GLfloat
) (SHINE_TABLE_SIZE
- 1);
968 if (x
< 0.005) /* underflow check */
970 t
= _mesa_pow(x
, shininess
);
976 m
[SHINE_TABLE_SIZE
] = 1.0;
979 s
->shininess
= shininess
;
982 if (ctx
->_ShineTable
[side
])
983 ctx
->_ShineTable
[side
]->refcount
--;
985 ctx
->_ShineTable
[side
] = s
;
986 move_to_tail( list
, s
);
992 _mesa_validate_all_lighting_tables( GLcontext
*ctx
)
997 shininess
= ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_SHININESS
][0];
998 if (!ctx
->_ShineTable
[0] || ctx
->_ShineTable
[0]->shininess
!= shininess
)
999 validate_shine_table( ctx
, 0, shininess
);
1001 shininess
= ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_BACK_SHININESS
][0];
1002 if (!ctx
->_ShineTable
[1] || ctx
->_ShineTable
[1]->shininess
!= shininess
)
1003 validate_shine_table( ctx
, 1, shininess
);
1005 for (i
= 0; i
< ctx
->Const
.MaxLights
; i
++)
1006 if (ctx
->Light
.Light
[i
]._SpotExpTable
[0][0] == -1)
1007 validate_spot_exp_table( &ctx
->Light
.Light
[i
] );
1012 * Examine current lighting parameters to determine if the optimized lighting
1013 * function can be used.
1014 * Also, precompute some lighting values such as the products of light
1015 * source and material ambient, diffuse and specular coefficients.
1018 _mesa_update_lighting( GLcontext
*ctx
)
1020 struct gl_light
*light
;
1021 ctx
->Light
._NeedEyeCoords
= GL_FALSE
;
1022 ctx
->Light
._Flags
= 0;
1024 if (!ctx
->Light
.Enabled
)
1027 foreach(light
, &ctx
->Light
.EnabledList
) {
1028 ctx
->Light
._Flags
|= light
->_Flags
;
1031 ctx
->Light
._NeedVertices
=
1032 ((ctx
->Light
._Flags
& (LIGHT_POSITIONAL
|LIGHT_SPOT
)) ||
1033 ctx
->Light
.Model
.ColorControl
== GL_SEPARATE_SPECULAR_COLOR
||
1034 ctx
->Light
.Model
.LocalViewer
);
1036 ctx
->Light
._NeedEyeCoords
= ((ctx
->Light
._Flags
& LIGHT_POSITIONAL
) ||
1037 ctx
->Light
.Model
.LocalViewer
);
1039 /* XXX: This test is overkill & needs to be fixed both for software and
1040 * hardware t&l drivers. The above should be sufficient & should
1041 * be tested to verify this.
1043 if (ctx
->Light
._NeedVertices
)
1044 ctx
->Light
._NeedEyeCoords
= GL_TRUE
;
1046 /* Precompute some shading values. Although we reference
1047 * Light.Material here, we can get away without flushing
1048 * FLUSH_UPDATE_CURRENT, as when any outstanding material changes
1049 * are flushed, they will update the derived state at that time.
1051 if (ctx
->Visual
.rgbMode
) {
1052 if (ctx
->Light
.Model
.TwoSide
)
1053 _mesa_update_material( ctx
,
1054 MAT_BIT_FRONT_EMISSION
|
1055 MAT_BIT_FRONT_AMBIENT
|
1056 MAT_BIT_FRONT_DIFFUSE
|
1057 MAT_BIT_FRONT_SPECULAR
|
1058 MAT_BIT_BACK_EMISSION
|
1059 MAT_BIT_BACK_AMBIENT
|
1060 MAT_BIT_BACK_DIFFUSE
|
1061 MAT_BIT_BACK_SPECULAR
);
1063 _mesa_update_material( ctx
,
1064 MAT_BIT_FRONT_EMISSION
|
1065 MAT_BIT_FRONT_AMBIENT
|
1066 MAT_BIT_FRONT_DIFFUSE
|
1067 MAT_BIT_FRONT_SPECULAR
);
1070 static const GLfloat ci
[3] = { .30F
, .59F
, .11F
};
1071 foreach(light
, &ctx
->Light
.EnabledList
) {
1072 light
->_dli
= DOT3(ci
, light
->Diffuse
);
1073 light
->_sli
= DOT3(ci
, light
->Specular
);
1080 * Update state derived from light position, spot direction.
1084 * _TNL_NEW_NEED_EYE_COORDS
1086 * Update on (_NEW_MODELVIEW | _NEW_LIGHT) when lighting is enabled.
1087 * Also update on lighting space changes.
1090 compute_light_positions( GLcontext
*ctx
)
1092 struct gl_light
*light
;
1093 static const GLfloat eye_z
[3] = { 0, 0, 1 };
1095 if (!ctx
->Light
.Enabled
)
1098 if (ctx
->_NeedEyeCoords
) {
1099 COPY_3V( ctx
->_EyeZDir
, eye_z
);
1102 TRANSFORM_NORMAL( ctx
->_EyeZDir
, eye_z
, ctx
->ModelviewMatrixStack
.Top
->m
);
1105 foreach (light
, &ctx
->Light
.EnabledList
) {
1107 if (ctx
->_NeedEyeCoords
) {
1108 /* _Position is in eye coordinate space */
1109 COPY_4FV( light
->_Position
, light
->EyePosition
);
1112 /* _Position is in object coordinate space */
1113 TRANSFORM_POINT( light
->_Position
, ctx
->ModelviewMatrixStack
.Top
->inv
,
1114 light
->EyePosition
);
1117 if (!(light
->_Flags
& LIGHT_POSITIONAL
)) {
1118 /* VP (VP) = Normalize( Position ) */
1119 COPY_3V( light
->_VP_inf_norm
, light
->_Position
);
1120 NORMALIZE_3FV( light
->_VP_inf_norm
);
1122 if (!ctx
->Light
.Model
.LocalViewer
) {
1123 /* _h_inf_norm = Normalize( V_to_P + <0,0,1> ) */
1124 ADD_3V( light
->_h_inf_norm
, light
->_VP_inf_norm
, ctx
->_EyeZDir
);
1125 NORMALIZE_3FV( light
->_h_inf_norm
);
1127 light
->_VP_inf_spot_attenuation
= 1.0;
1130 /* positional light w/ homogeneous coordinate, divide by W */
1131 GLfloat wInv
= 1.0 / light
->_Position
[3];
1132 light
->_Position
[0] *= wInv
;
1133 light
->_Position
[1] *= wInv
;
1134 light
->_Position
[2] *= wInv
;
1137 if (light
->_Flags
& LIGHT_SPOT
) {
1138 if (ctx
->_NeedEyeCoords
) {
1139 COPY_3V( light
->_NormDirection
, light
->EyeDirection
);
1142 TRANSFORM_NORMAL( light
->_NormDirection
,
1143 light
->EyeDirection
,
1144 ctx
->ModelviewMatrixStack
.Top
->m
);
1147 NORMALIZE_3FV( light
->_NormDirection
);
1149 if (!(light
->_Flags
& LIGHT_POSITIONAL
)) {
1150 GLfloat PV_dot_dir
= - DOT3(light
->_VP_inf_norm
,
1151 light
->_NormDirection
);
1153 if (PV_dot_dir
> light
->_CosCutoff
) {
1154 double x
= PV_dot_dir
* (EXP_TABLE_SIZE
-1);
1156 light
->_VP_inf_spot_attenuation
=
1157 (GLfloat
) (light
->_SpotExpTable
[k
][0] +
1158 (x
-k
)*light
->_SpotExpTable
[k
][1]);
1161 light
->_VP_inf_spot_attenuation
= 0;
1171 update_modelview_scale( GLcontext
*ctx
)
1173 ctx
->_ModelViewInvScale
= 1.0F
;
1174 if (!_math_matrix_is_length_preserving(ctx
->ModelviewMatrixStack
.Top
)) {
1175 const GLfloat
*m
= ctx
->ModelviewMatrixStack
.Top
->inv
;
1176 GLfloat f
= m
[2] * m
[2] + m
[6] * m
[6] + m
[10] * m
[10];
1177 if (f
< 1e-12) f
= 1.0;
1178 if (ctx
->_NeedEyeCoords
)
1179 ctx
->_ModelViewInvScale
= (GLfloat
) INV_SQRTF(f
);
1181 ctx
->_ModelViewInvScale
= (GLfloat
) SQRTF(f
);
1187 * Bring up to date any state that relies on _NeedEyeCoords.
1190 _mesa_update_tnl_spaces( GLcontext
*ctx
, GLuint new_state
)
1192 const GLuint oldneedeyecoords
= ctx
->_NeedEyeCoords
;
1195 ctx
->_NeedEyeCoords
= GL_FALSE
;
1197 if (ctx
->_ForceEyeCoords
||
1198 (ctx
->Texture
._GenFlags
& TEXGEN_NEED_EYE_COORD
) ||
1199 ctx
->Point
._Attenuated
||
1200 ctx
->Light
._NeedEyeCoords
)
1201 ctx
->_NeedEyeCoords
= GL_TRUE
;
1203 if (ctx
->Light
.Enabled
&&
1204 !_math_matrix_is_length_preserving(ctx
->ModelviewMatrixStack
.Top
))
1205 ctx
->_NeedEyeCoords
= GL_TRUE
;
1207 /* Check if the truth-value interpretations of the bitfields have
1210 if (oldneedeyecoords
!= ctx
->_NeedEyeCoords
) {
1211 /* Recalculate all state that depends on _NeedEyeCoords.
1213 update_modelview_scale(ctx
);
1214 compute_light_positions( ctx
);
1216 if (ctx
->Driver
.LightingSpaceChange
)
1217 ctx
->Driver
.LightingSpaceChange( ctx
);
1220 GLuint new_state
= ctx
->NewState
;
1222 /* Recalculate that same state only if it has been invalidated
1223 * by other statechanges.
1225 if (new_state
& _NEW_MODELVIEW
)
1226 update_modelview_scale(ctx
);
1228 if (new_state
& (_NEW_LIGHT
|_NEW_MODELVIEW
))
1229 compute_light_positions( ctx
);
1235 * Drivers may need this if the hardware tnl unit doesn't support the
1236 * light-in-modelspace optimization. It's also useful for debugging.
1239 _mesa_allow_light_in_model( GLcontext
*ctx
, GLboolean flag
)
1241 ctx
->_ForceEyeCoords
= !flag
;
1242 ctx
->NewState
|= _NEW_POINT
; /* one of the bits from
1243 * _MESA_NEW_NEED_EYE_COORDS.
1249 /**********************************************************************/
1250 /***** Initialization *****/
1251 /**********************************************************************/
1254 * Initialize the n-th light data structure.
1256 * \param l pointer to the gl_light structure to be initialized.
1257 * \param n number of the light.
1258 * \note The defaults for light 0 are different than the other lights.
1261 init_light( struct gl_light
*l
, GLuint n
)
1263 make_empty_list( l
);
1265 ASSIGN_4V( l
->Ambient
, 0.0, 0.0, 0.0, 1.0 );
1267 ASSIGN_4V( l
->Diffuse
, 1.0, 1.0, 1.0, 1.0 );
1268 ASSIGN_4V( l
->Specular
, 1.0, 1.0, 1.0, 1.0 );
1271 ASSIGN_4V( l
->Diffuse
, 0.0, 0.0, 0.0, 1.0 );
1272 ASSIGN_4V( l
->Specular
, 0.0, 0.0, 0.0, 1.0 );
1274 ASSIGN_4V( l
->EyePosition
, 0.0, 0.0, 1.0, 0.0 );
1275 ASSIGN_3V( l
->EyeDirection
, 0.0, 0.0, -1.0 );
1276 l
->SpotExponent
= 0.0;
1277 _mesa_invalidate_spot_exp_table( l
);
1278 l
->SpotCutoff
= 180.0;
1279 l
->_CosCutoffNeg
= -1.0f
;
1280 l
->_CosCutoff
= 0.0; /* KW: -ve values not admitted */
1281 l
->ConstantAttenuation
= 1.0;
1282 l
->LinearAttenuation
= 0.0;
1283 l
->QuadraticAttenuation
= 0.0;
1284 l
->Enabled
= GL_FALSE
;
1289 * Initialize the light model data structure.
1291 * \param lm pointer to the gl_lightmodel structure to be initialized.
1294 init_lightmodel( struct gl_lightmodel
*lm
)
1296 ASSIGN_4V( lm
->Ambient
, 0.2F
, 0.2F
, 0.2F
, 1.0F
);
1297 lm
->LocalViewer
= GL_FALSE
;
1298 lm
->TwoSide
= GL_FALSE
;
1299 lm
->ColorControl
= GL_SINGLE_COLOR
;
1304 * Initialize the material data structure.
1306 * \param m pointer to the gl_material structure to be initialized.
1309 init_material( struct gl_material
*m
)
1311 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_FRONT_AMBIENT
], 0.2F
, 0.2F
, 0.2F
, 1.0F
);
1312 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
], 0.8F
, 0.8F
, 0.8F
, 1.0F
);
1313 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_FRONT_SPECULAR
], 0.0F
, 0.0F
, 0.0F
, 1.0F
);
1314 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_FRONT_EMISSION
], 0.0F
, 0.0F
, 0.0F
, 1.0F
);
1315 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_FRONT_SHININESS
], 0.0F
, 0.0F
, 0.0F
, 0.0F
);
1316 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_FRONT_INDEXES
], 0.0F
, 1.0F
, 1.0F
, 0.0F
);
1318 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_BACK_AMBIENT
], 0.2F
, 0.2F
, 0.2F
, 1.0F
);
1319 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_BACK_DIFFUSE
], 0.8F
, 0.8F
, 0.8F
, 1.0F
);
1320 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_BACK_SPECULAR
], 0.0F
, 0.0F
, 0.0F
, 1.0F
);
1321 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_BACK_EMISSION
], 0.0F
, 0.0F
, 0.0F
, 1.0F
);
1322 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_BACK_SHININESS
], 0.0F
, 0.0F
, 0.0F
, 0.0F
);
1323 ASSIGN_4V( m
->Attrib
[MAT_ATTRIB_BACK_INDEXES
], 0.0F
, 1.0F
, 1.0F
, 0.0F
);
1328 * Initialize all lighting state for the given context.
1331 _mesa_init_lighting( GLcontext
*ctx
)
1335 /* Lighting group */
1336 for (i
= 0; i
< MAX_LIGHTS
; i
++) {
1337 init_light( &ctx
->Light
.Light
[i
], i
);
1339 make_empty_list( &ctx
->Light
.EnabledList
);
1341 init_lightmodel( &ctx
->Light
.Model
);
1342 init_material( &ctx
->Light
.Material
);
1343 ctx
->Light
.ShadeModel
= GL_SMOOTH
;
1344 ctx
->Light
.Enabled
= GL_FALSE
;
1345 ctx
->Light
.ColorMaterialFace
= GL_FRONT_AND_BACK
;
1346 ctx
->Light
.ColorMaterialMode
= GL_AMBIENT_AND_DIFFUSE
;
1347 ctx
->Light
.ColorMaterialBitmask
= _mesa_material_bitmask( ctx
,
1349 GL_AMBIENT_AND_DIFFUSE
, ~0,
1352 ctx
->Light
.ColorMaterialEnabled
= GL_FALSE
;
1353 ctx
->Light
.ClampVertexColor
= GL_TRUE
;
1355 /* Lighting miscellaneous */
1356 ctx
->_ShineTabList
= MALLOC_STRUCT( gl_shine_tab
);
1357 make_empty_list( ctx
->_ShineTabList
);
1358 /* Allocate 10 (arbitrary) shininess lookup tables */
1359 for (i
= 0 ; i
< 10 ; i
++) {
1360 struct gl_shine_tab
*s
= MALLOC_STRUCT( gl_shine_tab
);
1363 insert_at_tail( ctx
->_ShineTabList
, s
);
1367 ctx
->Light
._NeedEyeCoords
= GL_FALSE
;
1368 ctx
->_NeedEyeCoords
= GL_FALSE
;
1369 ctx
->_ModelViewInvScale
= 1.0;
1374 * Deallocate malloc'd lighting state attached to given context.
1377 _mesa_free_lighting_data( GLcontext
*ctx
)
1379 struct gl_shine_tab
*s
, *tmps
;
1381 /* Free lighting shininess exponentiation table */
1382 foreach_s( s
, tmps
, ctx
->_ShineTabList
) {
1385 _mesa_free( ctx
->_ShineTabList
);