2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
26 * \file prog_statevars.c
27 * Program state variable management.
32 #include "main/glheader.h"
33 #include "main/context.h"
34 #include "main/blend.h"
35 #include "main/imports.h"
36 #include "main/macros.h"
37 #include "main/mtypes.h"
38 #include "main/fbobject.h"
39 #include "prog_statevars.h"
40 #include "prog_parameter.h"
41 #include "main/samplerobj.h"
45 * Use the list of tokens in the state[] array to find global GL state
46 * and return it in <value>. Usually, four values are returned in <value>
47 * but matrix queries may return as many as 16 values.
48 * This function is used for ARB vertex/fragment programs.
49 * The program parser will produce the state[] values.
52 _mesa_fetch_state(struct gl_context
*ctx
, const gl_state_index state
[],
58 /* state[1] is either 0=front or 1=back side */
59 const GLuint face
= (GLuint
) state
[1];
60 const struct gl_material
*mat
= &ctx
->Light
.Material
;
61 assert(face
== 0 || face
== 1);
62 /* we rely on tokens numbered so that _BACK_ == _FRONT_+ 1 */
63 assert(MAT_ATTRIB_FRONT_AMBIENT
+ 1 == MAT_ATTRIB_BACK_AMBIENT
);
64 /* XXX we could get rid of this switch entirely with a little
65 * work in arbprogparse.c's parse_state_single_item().
67 /* state[2] is the material attribute */
70 COPY_4V(value
, mat
->Attrib
[MAT_ATTRIB_FRONT_AMBIENT
+ face
]);
73 COPY_4V(value
, mat
->Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
+ face
]);
76 COPY_4V(value
, mat
->Attrib
[MAT_ATTRIB_FRONT_SPECULAR
+ face
]);
79 COPY_4V(value
, mat
->Attrib
[MAT_ATTRIB_FRONT_EMISSION
+ face
]);
82 value
[0] = mat
->Attrib
[MAT_ATTRIB_FRONT_SHININESS
+ face
][0];
88 _mesa_problem(ctx
, "Invalid material state in fetch_state");
94 /* state[1] is the light number */
95 const GLuint ln
= (GLuint
) state
[1];
96 /* state[2] is the light attribute */
99 COPY_4V(value
, ctx
->Light
.Light
[ln
].Ambient
);
102 COPY_4V(value
, ctx
->Light
.Light
[ln
].Diffuse
);
105 COPY_4V(value
, ctx
->Light
.Light
[ln
].Specular
);
108 COPY_4V(value
, ctx
->Light
.Light
[ln
].EyePosition
);
110 case STATE_ATTENUATION
:
111 value
[0] = ctx
->Light
.Light
[ln
].ConstantAttenuation
;
112 value
[1] = ctx
->Light
.Light
[ln
].LinearAttenuation
;
113 value
[2] = ctx
->Light
.Light
[ln
].QuadraticAttenuation
;
114 value
[3] = ctx
->Light
.Light
[ln
].SpotExponent
;
116 case STATE_SPOT_DIRECTION
:
117 COPY_3V(value
, ctx
->Light
.Light
[ln
].SpotDirection
);
118 value
[3] = ctx
->Light
.Light
[ln
]._CosCutoff
;
120 case STATE_SPOT_CUTOFF
:
121 value
[0] = ctx
->Light
.Light
[ln
].SpotCutoff
;
123 case STATE_HALF_VECTOR
:
125 static const GLfloat eye_z
[] = {0, 0, 1};
127 /* Compute infinite half angle vector:
128 * halfVector = normalize(normalize(lightPos) + (0, 0, 1))
129 * light.EyePosition.w should be 0 for infinite lights.
131 COPY_3V(p
, ctx
->Light
.Light
[ln
].EyePosition
);
133 ADD_3V(value
, p
, eye_z
);
134 NORMALIZE_3FV(value
);
139 _mesa_problem(ctx
, "Invalid light state in fetch_state");
143 case STATE_LIGHTMODEL_AMBIENT
:
144 COPY_4V(value
, ctx
->Light
.Model
.Ambient
);
146 case STATE_LIGHTMODEL_SCENECOLOR
:
150 for (i
= 0; i
< 3; i
++) {
151 value
[i
] = ctx
->Light
.Model
.Ambient
[i
]
152 * ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_AMBIENT
][i
]
153 + ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_EMISSION
][i
];
155 value
[3] = ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
][3];
160 for (i
= 0; i
< 3; i
++) {
161 value
[i
] = ctx
->Light
.Model
.Ambient
[i
]
162 * ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_BACK_AMBIENT
][i
]
163 + ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_BACK_EMISSION
][i
];
165 value
[3] = ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_BACK_DIFFUSE
][3];
168 case STATE_LIGHTPROD
:
170 const GLuint ln
= (GLuint
) state
[1];
171 const GLuint face
= (GLuint
) state
[2];
173 assert(face
== 0 || face
== 1);
176 for (i
= 0; i
< 3; i
++) {
177 value
[i
] = ctx
->Light
.Light
[ln
].Ambient
[i
] *
178 ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_AMBIENT
+face
][i
];
180 /* [3] = material alpha */
181 value
[3] = ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_AMBIENT
+face
][3];
184 for (i
= 0; i
< 3; i
++) {
185 value
[i
] = ctx
->Light
.Light
[ln
].Diffuse
[i
] *
186 ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
+face
][i
];
188 /* [3] = material alpha */
189 value
[3] = ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
+face
][3];
192 for (i
= 0; i
< 3; i
++) {
193 value
[i
] = ctx
->Light
.Light
[ln
].Specular
[i
] *
194 ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_SPECULAR
+face
][i
];
196 /* [3] = material alpha */
197 value
[3] = ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_SPECULAR
+face
][3];
200 _mesa_problem(ctx
, "Invalid lightprod state in fetch_state");
206 /* state[1] is the texture unit */
207 const GLuint unit
= (GLuint
) state
[1];
208 /* state[2] is the texgen attribute */
210 case STATE_TEXGEN_EYE_S
:
211 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].GenS
.EyePlane
);
213 case STATE_TEXGEN_EYE_T
:
214 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].GenT
.EyePlane
);
216 case STATE_TEXGEN_EYE_R
:
217 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].GenR
.EyePlane
);
219 case STATE_TEXGEN_EYE_Q
:
220 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].GenQ
.EyePlane
);
222 case STATE_TEXGEN_OBJECT_S
:
223 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].GenS
.ObjectPlane
);
225 case STATE_TEXGEN_OBJECT_T
:
226 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].GenT
.ObjectPlane
);
228 case STATE_TEXGEN_OBJECT_R
:
229 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].GenR
.ObjectPlane
);
231 case STATE_TEXGEN_OBJECT_Q
:
232 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].GenQ
.ObjectPlane
);
235 _mesa_problem(ctx
, "Invalid texgen state in fetch_state");
239 case STATE_TEXENV_COLOR
:
241 /* state[1] is the texture unit */
242 const GLuint unit
= (GLuint
) state
[1];
243 if (_mesa_get_clamp_fragment_color(ctx
))
244 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].EnvColor
);
246 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].EnvColorUnclamped
);
249 case STATE_FOG_COLOR
:
250 if (_mesa_get_clamp_fragment_color(ctx
))
251 COPY_4V(value
, ctx
->Fog
.Color
);
253 COPY_4V(value
, ctx
->Fog
.ColorUnclamped
);
255 case STATE_FOG_PARAMS
:
256 value
[0] = ctx
->Fog
.Density
;
257 value
[1] = ctx
->Fog
.Start
;
258 value
[2] = ctx
->Fog
.End
;
259 value
[3] = 1.0f
/ (ctx
->Fog
.End
- ctx
->Fog
.Start
);
261 case STATE_CLIPPLANE
:
263 const GLuint plane
= (GLuint
) state
[1];
264 COPY_4V(value
, ctx
->Transform
.EyeUserPlane
[plane
]);
267 case STATE_POINT_SIZE
:
268 value
[0] = ctx
->Point
.Size
;
269 value
[1] = ctx
->Point
.MinSize
;
270 value
[2] = ctx
->Point
.MaxSize
;
271 value
[3] = ctx
->Point
.Threshold
;
273 case STATE_POINT_ATTENUATION
:
274 value
[0] = ctx
->Point
.Params
[0];
275 value
[1] = ctx
->Point
.Params
[1];
276 value
[2] = ctx
->Point
.Params
[2];
279 case STATE_MODELVIEW_MATRIX
:
280 case STATE_PROJECTION_MATRIX
:
281 case STATE_MVP_MATRIX
:
282 case STATE_TEXTURE_MATRIX
:
283 case STATE_PROGRAM_MATRIX
:
285 /* state[0] = modelview, projection, texture, etc. */
286 /* state[1] = which texture matrix or program matrix */
287 /* state[2] = first row to fetch */
288 /* state[3] = last row to fetch */
289 /* state[4] = transpose, inverse or invtrans */
290 const GLmatrix
*matrix
;
291 const gl_state_index mat
= state
[0];
292 const GLuint index
= (GLuint
) state
[1];
293 const GLuint firstRow
= (GLuint
) state
[2];
294 const GLuint lastRow
= (GLuint
) state
[3];
295 const gl_state_index modifier
= state
[4];
298 assert(firstRow
< 4);
300 if (mat
== STATE_MODELVIEW_MATRIX
) {
301 matrix
= ctx
->ModelviewMatrixStack
.Top
;
303 else if (mat
== STATE_PROJECTION_MATRIX
) {
304 matrix
= ctx
->ProjectionMatrixStack
.Top
;
306 else if (mat
== STATE_MVP_MATRIX
) {
307 matrix
= &ctx
->_ModelProjectMatrix
;
309 else if (mat
== STATE_TEXTURE_MATRIX
) {
310 assert(index
< Elements(ctx
->TextureMatrixStack
));
311 matrix
= ctx
->TextureMatrixStack
[index
].Top
;
313 else if (mat
== STATE_PROGRAM_MATRIX
) {
314 assert(index
< Elements(ctx
->ProgramMatrixStack
));
315 matrix
= ctx
->ProgramMatrixStack
[index
].Top
;
318 _mesa_problem(ctx
, "Bad matrix name in _mesa_fetch_state()");
321 if (modifier
== STATE_MATRIX_INVERSE
||
322 modifier
== STATE_MATRIX_INVTRANS
) {
323 /* Be sure inverse is up to date:
325 _math_matrix_analyse( (GLmatrix
*) matrix
);
331 if (modifier
== STATE_MATRIX_TRANSPOSE
||
332 modifier
== STATE_MATRIX_INVTRANS
) {
333 for (i
= 0, row
= firstRow
; row
<= lastRow
; row
++) {
334 value
[i
++] = m
[row
* 4 + 0];
335 value
[i
++] = m
[row
* 4 + 1];
336 value
[i
++] = m
[row
* 4 + 2];
337 value
[i
++] = m
[row
* 4 + 3];
341 for (i
= 0, row
= firstRow
; row
<= lastRow
; row
++) {
342 value
[i
++] = m
[row
+ 0];
343 value
[i
++] = m
[row
+ 4];
344 value
[i
++] = m
[row
+ 8];
345 value
[i
++] = m
[row
+ 12];
350 case STATE_NUM_SAMPLES
:
351 ((int *)value
)[0] = ctx
->DrawBuffer
->Visual
.samples
;
353 case STATE_DEPTH_RANGE
:
354 value
[0] = ctx
->ViewportArray
[0].Near
; /* near */
355 value
[1] = ctx
->ViewportArray
[0].Far
; /* far */
356 value
[2] = ctx
->ViewportArray
[0].Far
- ctx
->ViewportArray
[0].Near
; /* far - near */
359 case STATE_FRAGMENT_PROGRAM
:
361 /* state[1] = {STATE_ENV, STATE_LOCAL} */
362 /* state[2] = parameter index */
363 const int idx
= (int) state
[2];
366 COPY_4V(value
, ctx
->FragmentProgram
.Parameters
[idx
]);
369 if (!ctx
->FragmentProgram
.Current
->Base
.LocalParams
) {
370 ctx
->FragmentProgram
.Current
->Base
.LocalParams
=
371 calloc(MAX_PROGRAM_LOCAL_PARAMS
, sizeof(float[4]));
372 if (!ctx
->FragmentProgram
.Current
->Base
.LocalParams
)
376 COPY_4V(value
, ctx
->FragmentProgram
.Current
->Base
.LocalParams
[idx
]);
379 _mesa_problem(ctx
, "Bad state switch in _mesa_fetch_state()");
385 case STATE_VERTEX_PROGRAM
:
387 /* state[1] = {STATE_ENV, STATE_LOCAL} */
388 /* state[2] = parameter index */
389 const int idx
= (int) state
[2];
392 COPY_4V(value
, ctx
->VertexProgram
.Parameters
[idx
]);
395 if (!ctx
->VertexProgram
.Current
->Base
.LocalParams
) {
396 ctx
->VertexProgram
.Current
->Base
.LocalParams
=
397 calloc(MAX_PROGRAM_LOCAL_PARAMS
, sizeof(float[4]));
398 if (!ctx
->VertexProgram
.Current
->Base
.LocalParams
)
402 COPY_4V(value
, ctx
->VertexProgram
.Current
->Base
.LocalParams
[idx
]);
405 _mesa_problem(ctx
, "Bad state switch in _mesa_fetch_state()");
411 case STATE_NORMAL_SCALE
:
412 ASSIGN_4V(value
, ctx
->_ModelViewInvScale
, 0, 0, 1);
417 case STATE_CURRENT_ATTRIB
:
419 const GLuint idx
= (GLuint
) state
[2];
420 COPY_4V(value
, ctx
->Current
.Attrib
[idx
]);
424 case STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED
:
426 const GLuint idx
= (GLuint
) state
[2];
427 if(ctx
->Light
._ClampVertexColor
&&
428 (idx
== VERT_ATTRIB_COLOR0
||
429 idx
== VERT_ATTRIB_COLOR1
)) {
430 value
[0] = CLAMP(ctx
->Current
.Attrib
[idx
][0], 0.0f
, 1.0f
);
431 value
[1] = CLAMP(ctx
->Current
.Attrib
[idx
][1], 0.0f
, 1.0f
);
432 value
[2] = CLAMP(ctx
->Current
.Attrib
[idx
][2], 0.0f
, 1.0f
);
433 value
[3] = CLAMP(ctx
->Current
.Attrib
[idx
][3], 0.0f
, 1.0f
);
436 COPY_4V(value
, ctx
->Current
.Attrib
[idx
]);
440 case STATE_NORMAL_SCALE
:
442 ctx
->_ModelViewInvScale
,
443 ctx
->_ModelViewInvScale
,
444 ctx
->_ModelViewInvScale
,
448 case STATE_TEXRECT_SCALE
:
449 /* Value = { 1/texWidth, 1/texHeight, 0, 1 }.
450 * Used to convert unnormalized texcoords to normalized texcoords.
453 const int unit
= (int) state
[2];
454 const struct gl_texture_object
*texObj
455 = ctx
->Texture
.Unit
[unit
]._Current
;
457 struct gl_texture_image
*texImage
= texObj
->Image
[0][0];
459 (GLfloat
) (1.0 / texImage
->Width
),
460 (GLfloat
) (1.0 / texImage
->Height
),
466 case STATE_FOG_PARAMS_OPTIMIZED
:
467 /* for simpler per-vertex/pixel fog calcs. POW (for EXP/EXP2 fog)
468 * might be more expensive than EX2 on some hw, plus it needs
469 * another constant (e) anyway. Linear fog can now be done with a
471 * linear: fogcoord * -1/(end-start) + end/(end-start)
472 * exp: 2^-(density/ln(2) * fogcoord)
473 * exp2: 2^-((density/(ln(2)^2) * fogcoord)^2)
475 value
[0] = (ctx
->Fog
.End
== ctx
->Fog
.Start
)
476 ? 1.0f
: (GLfloat
)(-1.0F
/ (ctx
->Fog
.End
- ctx
->Fog
.Start
));
477 value
[1] = ctx
->Fog
.End
* -value
[0];
478 value
[2] = (GLfloat
)(ctx
->Fog
.Density
* M_LOG2E
); /* M_LOG2E == 1/ln(2) */
479 value
[3] = (GLfloat
)(ctx
->Fog
.Density
* ONE_DIV_SQRT_LN2
);
482 case STATE_POINT_SIZE_CLAMPED
:
484 /* this includes implementation dependent limits, to avoid
485 * another potentially necessary clamp.
486 * Note: for sprites, point smooth (point AA) is ignored
487 * and we'll clamp to MinPointSizeAA and MaxPointSize, because we
488 * expect drivers will want to say their minimum for AA size is 0.0
489 * but for non-AA it's 1.0 (because normal points with size below 1.0
490 * need to get rounded up to 1.0, hence never disappear). GL does
491 * not specify max clamp size for sprites, other than it needs to be
492 * at least as large as max AA size, hence use non-AA size there.
496 if (ctx
->Point
.PointSprite
) {
497 minImplSize
= ctx
->Const
.MinPointSizeAA
;
498 maxImplSize
= ctx
->Const
.MaxPointSize
;
500 else if (ctx
->Point
.SmoothFlag
|| ctx
->Multisample
._Enabled
) {
501 minImplSize
= ctx
->Const
.MinPointSizeAA
;
502 maxImplSize
= ctx
->Const
.MaxPointSizeAA
;
505 minImplSize
= ctx
->Const
.MinPointSize
;
506 maxImplSize
= ctx
->Const
.MaxPointSize
;
508 value
[0] = ctx
->Point
.Size
;
509 value
[1] = ctx
->Point
.MinSize
>= minImplSize
? ctx
->Point
.MinSize
: minImplSize
;
510 value
[2] = ctx
->Point
.MaxSize
<= maxImplSize
? ctx
->Point
.MaxSize
: maxImplSize
;
511 value
[3] = ctx
->Point
.Threshold
;
514 case STATE_LIGHT_SPOT_DIR_NORMALIZED
:
516 /* here, state[2] is the light number */
517 /* pre-normalize spot dir */
518 const GLuint ln
= (GLuint
) state
[2];
519 COPY_3V(value
, ctx
->Light
.Light
[ln
]._NormSpotDirection
);
520 value
[3] = ctx
->Light
.Light
[ln
]._CosCutoff
;
524 case STATE_LIGHT_POSITION
:
526 const GLuint ln
= (GLuint
) state
[2];
527 COPY_4V(value
, ctx
->Light
.Light
[ln
]._Position
);
531 case STATE_LIGHT_POSITION_NORMALIZED
:
533 const GLuint ln
= (GLuint
) state
[2];
534 COPY_4V(value
, ctx
->Light
.Light
[ln
]._Position
);
535 NORMALIZE_3FV( value
);
539 case STATE_LIGHT_HALF_VECTOR
:
541 const GLuint ln
= (GLuint
) state
[2];
543 /* Compute infinite half angle vector:
544 * halfVector = normalize(normalize(lightPos) + (0, 0, 1))
545 * light.EyePosition.w should be 0 for infinite lights.
547 COPY_3V(p
, ctx
->Light
.Light
[ln
]._Position
);
549 ADD_3V(value
, p
, ctx
->_EyeZDir
);
550 NORMALIZE_3FV(value
);
556 value
[0] = ctx
->Pixel
.RedScale
;
557 value
[1] = ctx
->Pixel
.GreenScale
;
558 value
[2] = ctx
->Pixel
.BlueScale
;
559 value
[3] = ctx
->Pixel
.AlphaScale
;
563 value
[0] = ctx
->Pixel
.RedBias
;
564 value
[1] = ctx
->Pixel
.GreenBias
;
565 value
[2] = ctx
->Pixel
.BlueBias
;
566 value
[3] = ctx
->Pixel
.AlphaBias
;
570 value
[0] = (GLfloat
) (ctx
->DrawBuffer
->Width
- 1);
571 value
[1] = (GLfloat
) (ctx
->DrawBuffer
->Height
- 1);
576 case STATE_FB_WPOS_Y_TRANSFORM
:
577 /* A driver may negate this conditional by using ZW swizzle
578 * instead of XY (based on e.g. some other state). */
579 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
580 /* Identity (XY) followed by flipping Y upside down (ZW). */
584 value
[3] = (GLfloat
) ctx
->DrawBuffer
->Height
;
586 /* Flipping Y upside down (XY) followed by identity (ZW). */
588 value
[1] = (GLfloat
) ctx
->DrawBuffer
->Height
;
594 /* XXX: make sure new tokens added here are also handled in the
595 * _mesa_program_state_flags() switch, below.
598 /* Unknown state indexes are silently ignored here.
599 * Drivers may do something special.
606 _mesa_problem(ctx
, "Invalid state in _mesa_fetch_state");
613 * Return a bitmask of the Mesa state flags (_NEW_* values) which would
614 * indicate that the given context state may have changed.
615 * The bitmask is used during validation to determine if we need to update
616 * vertex/fragment program parameters (like "state.material.color") when
617 * some GL state has changed.
620 _mesa_program_state_flags(const gl_state_index state
[STATE_LENGTH
])
624 case STATE_LIGHTPROD
:
625 case STATE_LIGHTMODEL_SCENECOLOR
:
626 /* these can be effected by glColor when colormaterial mode is used */
627 return _NEW_LIGHT
| _NEW_CURRENT_ATTRIB
;
630 case STATE_LIGHTMODEL_AMBIENT
:
635 case STATE_TEXENV_COLOR
:
636 return _NEW_TEXTURE
| _NEW_BUFFERS
| _NEW_FRAG_CLAMP
;
638 case STATE_FOG_COLOR
:
639 return _NEW_FOG
| _NEW_BUFFERS
| _NEW_FRAG_CLAMP
;
640 case STATE_FOG_PARAMS
:
643 case STATE_CLIPPLANE
:
644 return _NEW_TRANSFORM
;
646 case STATE_POINT_SIZE
:
647 case STATE_POINT_ATTENUATION
:
650 case STATE_MODELVIEW_MATRIX
:
651 return _NEW_MODELVIEW
;
652 case STATE_PROJECTION_MATRIX
:
653 return _NEW_PROJECTION
;
654 case STATE_MVP_MATRIX
:
655 return _NEW_MODELVIEW
| _NEW_PROJECTION
;
656 case STATE_TEXTURE_MATRIX
:
657 return _NEW_TEXTURE_MATRIX
;
658 case STATE_PROGRAM_MATRIX
:
659 return _NEW_TRACK_MATRIX
;
661 case STATE_NUM_SAMPLES
:
664 case STATE_DEPTH_RANGE
:
665 return _NEW_VIEWPORT
;
667 case STATE_FRAGMENT_PROGRAM
:
668 case STATE_VERTEX_PROGRAM
:
671 case STATE_NORMAL_SCALE
:
672 return _NEW_MODELVIEW
;
676 case STATE_CURRENT_ATTRIB
:
677 return _NEW_CURRENT_ATTRIB
;
678 case STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED
:
679 return _NEW_CURRENT_ATTRIB
| _NEW_LIGHT
| _NEW_BUFFERS
;
681 case STATE_NORMAL_SCALE
:
682 return _NEW_MODELVIEW
;
684 case STATE_TEXRECT_SCALE
:
686 case STATE_FOG_PARAMS_OPTIMIZED
:
688 case STATE_POINT_SIZE_CLAMPED
:
689 return _NEW_POINT
| _NEW_MULTISAMPLE
;
690 case STATE_LIGHT_SPOT_DIR_NORMALIZED
:
691 case STATE_LIGHT_POSITION
:
692 case STATE_LIGHT_POSITION_NORMALIZED
:
693 case STATE_LIGHT_HALF_VECTOR
:
701 case STATE_FB_WPOS_Y_TRANSFORM
:
705 /* unknown state indexes are silently ignored and
706 * no flag set, since it is handled by the driver.
712 _mesa_problem(NULL
, "unexpected state[0] in make_state_flags()");
719 append(char *dst
, const char *src
)
730 * Convert token 'k' to a string, append it onto 'dst' string.
733 append_token(char *dst
, gl_state_index k
)
737 append(dst
, "material");
740 append(dst
, "light");
742 case STATE_LIGHTMODEL_AMBIENT
:
743 append(dst
, "lightmodel.ambient");
745 case STATE_LIGHTMODEL_SCENECOLOR
:
747 case STATE_LIGHTPROD
:
748 append(dst
, "lightprod");
751 append(dst
, "texgen");
753 case STATE_FOG_COLOR
:
754 append(dst
, "fog.color");
756 case STATE_FOG_PARAMS
:
757 append(dst
, "fog.params");
759 case STATE_CLIPPLANE
:
762 case STATE_POINT_SIZE
:
763 append(dst
, "point.size");
765 case STATE_POINT_ATTENUATION
:
766 append(dst
, "point.attenuation");
768 case STATE_MODELVIEW_MATRIX
:
769 append(dst
, "matrix.modelview");
771 case STATE_PROJECTION_MATRIX
:
772 append(dst
, "matrix.projection");
774 case STATE_MVP_MATRIX
:
775 append(dst
, "matrix.mvp");
777 case STATE_TEXTURE_MATRIX
:
778 append(dst
, "matrix.texture");
780 case STATE_PROGRAM_MATRIX
:
781 append(dst
, "matrix.program");
783 case STATE_MATRIX_INVERSE
:
784 append(dst
, ".inverse");
786 case STATE_MATRIX_TRANSPOSE
:
787 append(dst
, ".transpose");
789 case STATE_MATRIX_INVTRANS
:
790 append(dst
, ".invtrans");
793 append(dst
, ".ambient");
796 append(dst
, ".diffuse");
799 append(dst
, ".specular");
802 append(dst
, ".emission");
804 case STATE_SHININESS
:
805 append(dst
, "lshininess");
807 case STATE_HALF_VECTOR
:
808 append(dst
, ".half");
811 append(dst
, ".position");
813 case STATE_ATTENUATION
:
814 append(dst
, ".attenuation");
816 case STATE_SPOT_DIRECTION
:
817 append(dst
, ".spot.direction");
819 case STATE_SPOT_CUTOFF
:
820 append(dst
, ".spot.cutoff");
822 case STATE_TEXGEN_EYE_S
:
823 append(dst
, ".eye.s");
825 case STATE_TEXGEN_EYE_T
:
826 append(dst
, ".eye.t");
828 case STATE_TEXGEN_EYE_R
:
829 append(dst
, ".eye.r");
831 case STATE_TEXGEN_EYE_Q
:
832 append(dst
, ".eye.q");
834 case STATE_TEXGEN_OBJECT_S
:
835 append(dst
, ".object.s");
837 case STATE_TEXGEN_OBJECT_T
:
838 append(dst
, ".object.t");
840 case STATE_TEXGEN_OBJECT_R
:
841 append(dst
, ".object.r");
843 case STATE_TEXGEN_OBJECT_Q
:
844 append(dst
, ".object.q");
846 case STATE_TEXENV_COLOR
:
847 append(dst
, "texenv");
849 case STATE_NUM_SAMPLES
:
850 append(dst
, "numsamples");
852 case STATE_DEPTH_RANGE
:
853 append(dst
, "depth.range");
855 case STATE_VERTEX_PROGRAM
:
856 case STATE_FRAGMENT_PROGRAM
:
862 append(dst
, "local");
864 /* BEGIN internal state vars */
866 append(dst
, ".internal.");
868 case STATE_CURRENT_ATTRIB
:
869 append(dst
, "current");
871 case STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED
:
872 append(dst
, "currentAttribMaybeVPClamped");
874 case STATE_NORMAL_SCALE
:
875 append(dst
, "normalScale");
877 case STATE_TEXRECT_SCALE
:
878 append(dst
, "texrectScale");
880 case STATE_FOG_PARAMS_OPTIMIZED
:
881 append(dst
, "fogParamsOptimized");
883 case STATE_POINT_SIZE_CLAMPED
:
884 append(dst
, "pointSizeClamped");
886 case STATE_LIGHT_SPOT_DIR_NORMALIZED
:
887 append(dst
, "lightSpotDirNormalized");
889 case STATE_LIGHT_POSITION
:
890 append(dst
, "lightPosition");
892 case STATE_LIGHT_POSITION_NORMALIZED
:
893 append(dst
, "light.position.normalized");
895 case STATE_LIGHT_HALF_VECTOR
:
896 append(dst
, "lightHalfVector");
899 append(dst
, "PTscale");
902 append(dst
, "PTbias");
905 append(dst
, "FbSize");
907 case STATE_FB_WPOS_Y_TRANSFORM
:
908 append(dst
, "FbWposYTransform");
911 /* probably STATE_INTERNAL_DRIVER+i (driver private state) */
912 append(dst
, "driverState");
917 append_face(char *dst
, GLint face
)
920 append(dst
, "front.");
922 append(dst
, "back.");
926 append_index(char *dst
, GLint index
)
929 sprintf(s
, "[%d]", index
);
934 * Make a string from the given state vector.
935 * For example, return "state.matrix.texture[2].inverse".
936 * Use free() to deallocate the string.
939 _mesa_program_state_string(const gl_state_index state
[STATE_LENGTH
])
944 append(str
, "state.");
945 append_token(str
, state
[0]);
949 append_face(str
, state
[1]);
950 append_token(str
, state
[2]);
953 append_index(str
, state
[1]); /* light number [i]. */
954 append_token(str
, state
[2]); /* coefficients */
956 case STATE_LIGHTMODEL_AMBIENT
:
957 append(str
, "lightmodel.ambient");
959 case STATE_LIGHTMODEL_SCENECOLOR
:
961 append(str
, "lightmodel.front.scenecolor");
964 append(str
, "lightmodel.back.scenecolor");
967 case STATE_LIGHTPROD
:
968 append_index(str
, state
[1]); /* light number [i]. */
969 append_face(str
, state
[2]);
970 append_token(str
, state
[3]);
973 append_index(str
, state
[1]); /* tex unit [i] */
974 append_token(str
, state
[2]); /* plane coef */
976 case STATE_TEXENV_COLOR
:
977 append_index(str
, state
[1]); /* tex unit [i] */
978 append(str
, "color");
980 case STATE_CLIPPLANE
:
981 append_index(str
, state
[1]); /* plane [i] */
982 append(str
, ".plane");
984 case STATE_MODELVIEW_MATRIX
:
985 case STATE_PROJECTION_MATRIX
:
986 case STATE_MVP_MATRIX
:
987 case STATE_TEXTURE_MATRIX
:
988 case STATE_PROGRAM_MATRIX
:
990 /* state[0] = modelview, projection, texture, etc. */
991 /* state[1] = which texture matrix or program matrix */
992 /* state[2] = first row to fetch */
993 /* state[3] = last row to fetch */
994 /* state[4] = transpose, inverse or invtrans */
995 const gl_state_index mat
= state
[0];
996 const GLuint index
= (GLuint
) state
[1];
997 const GLuint firstRow
= (GLuint
) state
[2];
998 const GLuint lastRow
= (GLuint
) state
[3];
999 const gl_state_index modifier
= state
[4];
1001 mat
== STATE_TEXTURE_MATRIX
||
1002 mat
== STATE_PROGRAM_MATRIX
)
1003 append_index(str
, index
);
1005 append_token(str
, modifier
);
1006 if (firstRow
== lastRow
)
1007 sprintf(tmp
, ".row[%d]", firstRow
);
1009 sprintf(tmp
, ".row[%d..%d]", firstRow
, lastRow
);
1013 case STATE_POINT_SIZE
:
1015 case STATE_POINT_ATTENUATION
:
1017 case STATE_FOG_PARAMS
:
1019 case STATE_FOG_COLOR
:
1021 case STATE_NUM_SAMPLES
:
1023 case STATE_DEPTH_RANGE
:
1025 case STATE_FRAGMENT_PROGRAM
:
1026 case STATE_VERTEX_PROGRAM
:
1027 /* state[1] = {STATE_ENV, STATE_LOCAL} */
1028 /* state[2] = parameter index */
1029 append_token(str
, state
[1]);
1030 append_index(str
, state
[2]);
1032 case STATE_NORMAL_SCALE
:
1034 case STATE_INTERNAL
:
1035 append_token(str
, state
[1]);
1036 if (state
[1] == STATE_CURRENT_ATTRIB
)
1037 append_index(str
, state
[2]);
1040 _mesa_problem(NULL
, "Invalid state in _mesa_program_state_string");
1044 return _mesa_strdup(str
);
1049 * Loop over all the parameters in a parameter list. If the parameter
1050 * is a GL state reference, look up the current value of that state
1051 * variable and put it into the parameter's Value[4] array.
1052 * Other parameter types never change or are explicitly set by the user
1053 * with glUniform() or glProgramParameter(), etc.
1054 * This would be called at glBegin time.
1057 _mesa_load_state_parameters(struct gl_context
*ctx
,
1058 struct gl_program_parameter_list
*paramList
)
1065 for (i
= 0; i
< paramList
->NumParameters
; i
++) {
1066 if (paramList
->Parameters
[i
].Type
== PROGRAM_STATE_VAR
) {
1067 _mesa_fetch_state(ctx
,
1068 paramList
->Parameters
[i
].StateIndexes
,
1069 ¶mList
->ParameterValues
[i
][0].f
);