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.
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] = (ctx
->Fog
.End
== ctx
->Fog
.Start
)
260 ? 1.0f
: (GLfloat
)(1.0 / (ctx
->Fog
.End
- ctx
->Fog
.Start
));
262 case STATE_CLIPPLANE
:
264 const GLuint plane
= (GLuint
) state
[1];
265 COPY_4V(value
, ctx
->Transform
.EyeUserPlane
[plane
]);
268 case STATE_POINT_SIZE
:
269 value
[0] = ctx
->Point
.Size
;
270 value
[1] = ctx
->Point
.MinSize
;
271 value
[2] = ctx
->Point
.MaxSize
;
272 value
[3] = ctx
->Point
.Threshold
;
274 case STATE_POINT_ATTENUATION
:
275 value
[0] = ctx
->Point
.Params
[0];
276 value
[1] = ctx
->Point
.Params
[1];
277 value
[2] = ctx
->Point
.Params
[2];
280 case STATE_MODELVIEW_MATRIX
:
281 case STATE_PROJECTION_MATRIX
:
282 case STATE_MVP_MATRIX
:
283 case STATE_TEXTURE_MATRIX
:
284 case STATE_PROGRAM_MATRIX
:
286 /* state[0] = modelview, projection, texture, etc. */
287 /* state[1] = which texture matrix or program matrix */
288 /* state[2] = first row to fetch */
289 /* state[3] = last row to fetch */
290 /* state[4] = transpose, inverse or invtrans */
291 const GLmatrix
*matrix
;
292 const gl_state_index mat
= state
[0];
293 const GLuint index
= (GLuint
) state
[1];
294 const GLuint firstRow
= (GLuint
) state
[2];
295 const GLuint lastRow
= (GLuint
) state
[3];
296 const gl_state_index modifier
= state
[4];
299 ASSERT(firstRow
>= 0);
300 ASSERT(firstRow
< 4);
301 ASSERT(lastRow
>= 0);
303 if (mat
== STATE_MODELVIEW_MATRIX
) {
304 matrix
= ctx
->ModelviewMatrixStack
.Top
;
306 else if (mat
== STATE_PROJECTION_MATRIX
) {
307 matrix
= ctx
->ProjectionMatrixStack
.Top
;
309 else if (mat
== STATE_MVP_MATRIX
) {
310 matrix
= &ctx
->_ModelProjectMatrix
;
312 else if (mat
== STATE_TEXTURE_MATRIX
) {
313 ASSERT(index
< Elements(ctx
->TextureMatrixStack
));
314 matrix
= ctx
->TextureMatrixStack
[index
].Top
;
316 else if (mat
== STATE_PROGRAM_MATRIX
) {
317 ASSERT(index
< Elements(ctx
->ProgramMatrixStack
));
318 matrix
= ctx
->ProgramMatrixStack
[index
].Top
;
321 _mesa_problem(ctx
, "Bad matrix name in _mesa_fetch_state()");
324 if (modifier
== STATE_MATRIX_INVERSE
||
325 modifier
== STATE_MATRIX_INVTRANS
) {
326 /* Be sure inverse is up to date:
328 _math_matrix_analyse( (GLmatrix
*) matrix
);
334 if (modifier
== STATE_MATRIX_TRANSPOSE
||
335 modifier
== STATE_MATRIX_INVTRANS
) {
336 for (i
= 0, row
= firstRow
; row
<= lastRow
; row
++) {
337 value
[i
++] = m
[row
* 4 + 0];
338 value
[i
++] = m
[row
* 4 + 1];
339 value
[i
++] = m
[row
* 4 + 2];
340 value
[i
++] = m
[row
* 4 + 3];
344 for (i
= 0, row
= firstRow
; row
<= lastRow
; row
++) {
345 value
[i
++] = m
[row
+ 0];
346 value
[i
++] = m
[row
+ 4];
347 value
[i
++] = m
[row
+ 8];
348 value
[i
++] = m
[row
+ 12];
353 case STATE_DEPTH_RANGE
:
354 value
[0] = ctx
->Viewport
.Near
; /* near */
355 value
[1] = ctx
->Viewport
.Far
; /* far */
356 value
[2] = ctx
->Viewport
.Far
- ctx
->Viewport
.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 COPY_4V(value
, ctx
->FragmentProgram
.Current
->Base
.LocalParams
[idx
]);
372 _mesa_problem(ctx
, "Bad state switch in _mesa_fetch_state()");
378 case STATE_VERTEX_PROGRAM
:
380 /* state[1] = {STATE_ENV, STATE_LOCAL} */
381 /* state[2] = parameter index */
382 const int idx
= (int) state
[2];
385 COPY_4V(value
, ctx
->VertexProgram
.Parameters
[idx
]);
388 COPY_4V(value
, ctx
->VertexProgram
.Current
->Base
.LocalParams
[idx
]);
391 _mesa_problem(ctx
, "Bad state switch in _mesa_fetch_state()");
397 case STATE_NORMAL_SCALE
:
398 ASSIGN_4V(value
, ctx
->_ModelViewInvScale
, 0, 0, 1);
403 case STATE_CURRENT_ATTRIB
:
405 const GLuint idx
= (GLuint
) state
[2];
406 COPY_4V(value
, ctx
->Current
.Attrib
[idx
]);
410 case STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED
:
412 const GLuint idx
= (GLuint
) state
[2];
413 if(ctx
->Light
._ClampVertexColor
&&
414 (idx
== VERT_ATTRIB_COLOR0
||
415 idx
== VERT_ATTRIB_COLOR1
)) {
416 value
[0] = CLAMP(ctx
->Current
.Attrib
[idx
][0], 0.0f
, 1.0f
);
417 value
[1] = CLAMP(ctx
->Current
.Attrib
[idx
][1], 0.0f
, 1.0f
);
418 value
[2] = CLAMP(ctx
->Current
.Attrib
[idx
][2], 0.0f
, 1.0f
);
419 value
[3] = CLAMP(ctx
->Current
.Attrib
[idx
][3], 0.0f
, 1.0f
);
422 COPY_4V(value
, ctx
->Current
.Attrib
[idx
]);
426 case STATE_NORMAL_SCALE
:
428 ctx
->_ModelViewInvScale
,
429 ctx
->_ModelViewInvScale
,
430 ctx
->_ModelViewInvScale
,
434 case STATE_TEXRECT_SCALE
:
435 /* Value = { 1/texWidth, 1/texHeight, 0, 1 }.
436 * Used to convert unnormalized texcoords to normalized texcoords.
439 const int unit
= (int) state
[2];
440 const struct gl_texture_object
*texObj
441 = ctx
->Texture
.Unit
[unit
]._Current
;
443 struct gl_texture_image
*texImage
= texObj
->Image
[0][0];
445 (GLfloat
) (1.0 / texImage
->Width
),
446 (GLfloat
) (1.0 / texImage
->Height
),
452 case STATE_FOG_PARAMS_OPTIMIZED
:
453 /* for simpler per-vertex/pixel fog calcs. POW (for EXP/EXP2 fog)
454 * might be more expensive than EX2 on some hw, plus it needs
455 * another constant (e) anyway. Linear fog can now be done with a
457 * linear: fogcoord * -1/(end-start) + end/(end-start)
458 * exp: 2^-(density/ln(2) * fogcoord)
459 * exp2: 2^-((density/(ln(2)^2) * fogcoord)^2)
461 value
[0] = (ctx
->Fog
.End
== ctx
->Fog
.Start
)
462 ? 1.0f
: (GLfloat
)(-1.0F
/ (ctx
->Fog
.End
- ctx
->Fog
.Start
));
463 value
[1] = ctx
->Fog
.End
* -value
[0];
464 value
[2] = (GLfloat
)(ctx
->Fog
.Density
* M_LOG2E
); /* M_LOG2E == 1/ln(2) */
465 value
[3] = (GLfloat
)(ctx
->Fog
.Density
* ONE_DIV_SQRT_LN2
);
468 case STATE_POINT_SIZE_CLAMPED
:
470 /* this includes implementation dependent limits, to avoid
471 * another potentially necessary clamp.
472 * Note: for sprites, point smooth (point AA) is ignored
473 * and we'll clamp to MinPointSizeAA and MaxPointSize, because we
474 * expect drivers will want to say their minimum for AA size is 0.0
475 * but for non-AA it's 1.0 (because normal points with size below 1.0
476 * need to get rounded up to 1.0, hence never disappear). GL does
477 * not specify max clamp size for sprites, other than it needs to be
478 * at least as large as max AA size, hence use non-AA size there.
482 if (ctx
->Point
.PointSprite
) {
483 minImplSize
= ctx
->Const
.MinPointSizeAA
;
484 maxImplSize
= ctx
->Const
.MaxPointSize
;
486 else if (ctx
->Point
.SmoothFlag
|| ctx
->Multisample
._Enabled
) {
487 minImplSize
= ctx
->Const
.MinPointSizeAA
;
488 maxImplSize
= ctx
->Const
.MaxPointSizeAA
;
491 minImplSize
= ctx
->Const
.MinPointSize
;
492 maxImplSize
= ctx
->Const
.MaxPointSize
;
494 value
[0] = ctx
->Point
.Size
;
495 value
[1] = ctx
->Point
.MinSize
>= minImplSize
? ctx
->Point
.MinSize
: minImplSize
;
496 value
[2] = ctx
->Point
.MaxSize
<= maxImplSize
? ctx
->Point
.MaxSize
: maxImplSize
;
497 value
[3] = ctx
->Point
.Threshold
;
500 case STATE_LIGHT_SPOT_DIR_NORMALIZED
:
502 /* here, state[2] is the light number */
503 /* pre-normalize spot dir */
504 const GLuint ln
= (GLuint
) state
[2];
505 COPY_3V(value
, ctx
->Light
.Light
[ln
]._NormSpotDirection
);
506 value
[3] = ctx
->Light
.Light
[ln
]._CosCutoff
;
510 case STATE_LIGHT_POSITION
:
512 const GLuint ln
= (GLuint
) state
[2];
513 COPY_4V(value
, ctx
->Light
.Light
[ln
]._Position
);
517 case STATE_LIGHT_POSITION_NORMALIZED
:
519 const GLuint ln
= (GLuint
) state
[2];
520 COPY_4V(value
, ctx
->Light
.Light
[ln
]._Position
);
521 NORMALIZE_3FV( value
);
525 case STATE_LIGHT_HALF_VECTOR
:
527 const GLuint ln
= (GLuint
) state
[2];
529 /* Compute infinite half angle vector:
530 * halfVector = normalize(normalize(lightPos) + (0, 0, 1))
531 * light.EyePosition.w should be 0 for infinite lights.
533 COPY_3V(p
, ctx
->Light
.Light
[ln
]._Position
);
535 ADD_3V(value
, p
, ctx
->_EyeZDir
);
536 NORMALIZE_3FV(value
);
542 value
[0] = ctx
->Pixel
.RedScale
;
543 value
[1] = ctx
->Pixel
.GreenScale
;
544 value
[2] = ctx
->Pixel
.BlueScale
;
545 value
[3] = ctx
->Pixel
.AlphaScale
;
549 value
[0] = ctx
->Pixel
.RedBias
;
550 value
[1] = ctx
->Pixel
.GreenBias
;
551 value
[2] = ctx
->Pixel
.BlueBias
;
552 value
[3] = ctx
->Pixel
.AlphaBias
;
556 value
[0] = (GLfloat
) (ctx
->DrawBuffer
->Width
- 1);
557 value
[1] = (GLfloat
) (ctx
->DrawBuffer
->Height
- 1);
562 case STATE_FB_WPOS_Y_TRANSFORM
:
563 /* A driver may negate this conditional by using ZW swizzle
564 * instead of XY (based on e.g. some other state). */
565 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
566 /* Identity (XY) followed by flipping Y upside down (ZW). */
570 value
[3] = (GLfloat
) ctx
->DrawBuffer
->Height
;
572 /* Flipping Y upside down (XY) followed by identity (ZW). */
574 value
[1] = (GLfloat
) ctx
->DrawBuffer
->Height
;
580 case STATE_ROT_MATRIX_0
:
582 const int unit
= (int) state
[2];
583 GLfloat
*rotMat22
= ctx
->Texture
.Unit
[unit
].RotMatrix
;
584 value
[0] = rotMat22
[0];
585 value
[1] = rotMat22
[2];
591 case STATE_ROT_MATRIX_1
:
593 const int unit
= (int) state
[2];
594 GLfloat
*rotMat22
= ctx
->Texture
.Unit
[unit
].RotMatrix
;
595 value
[0] = rotMat22
[1];
596 value
[1] = rotMat22
[3];
602 /* XXX: make sure new tokens added here are also handled in the
603 * _mesa_program_state_flags() switch, below.
606 /* Unknown state indexes are silently ignored here.
607 * Drivers may do something special.
614 _mesa_problem(ctx
, "Invalid state in _mesa_fetch_state");
621 * Return a bitmask of the Mesa state flags (_NEW_* values) which would
622 * indicate that the given context state may have changed.
623 * The bitmask is used during validation to determine if we need to update
624 * vertex/fragment program parameters (like "state.material.color") when
625 * some GL state has changed.
628 _mesa_program_state_flags(const gl_state_index state
[STATE_LENGTH
])
632 case STATE_LIGHTPROD
:
633 case STATE_LIGHTMODEL_SCENECOLOR
:
634 /* these can be effected by glColor when colormaterial mode is used */
635 return _NEW_LIGHT
| _NEW_CURRENT_ATTRIB
;
638 case STATE_LIGHTMODEL_AMBIENT
:
643 case STATE_TEXENV_COLOR
:
644 return _NEW_TEXTURE
| _NEW_BUFFERS
| _NEW_FRAG_CLAMP
;
646 case STATE_FOG_COLOR
:
647 return _NEW_FOG
| _NEW_BUFFERS
| _NEW_FRAG_CLAMP
;
648 case STATE_FOG_PARAMS
:
651 case STATE_CLIPPLANE
:
652 return _NEW_TRANSFORM
;
654 case STATE_POINT_SIZE
:
655 case STATE_POINT_ATTENUATION
:
658 case STATE_MODELVIEW_MATRIX
:
659 return _NEW_MODELVIEW
;
660 case STATE_PROJECTION_MATRIX
:
661 return _NEW_PROJECTION
;
662 case STATE_MVP_MATRIX
:
663 return _NEW_MODELVIEW
| _NEW_PROJECTION
;
664 case STATE_TEXTURE_MATRIX
:
665 return _NEW_TEXTURE_MATRIX
;
666 case STATE_PROGRAM_MATRIX
:
667 return _NEW_TRACK_MATRIX
;
669 case STATE_DEPTH_RANGE
:
670 return _NEW_VIEWPORT
;
672 case STATE_FRAGMENT_PROGRAM
:
673 case STATE_VERTEX_PROGRAM
:
676 case STATE_NORMAL_SCALE
:
677 return _NEW_MODELVIEW
;
681 case STATE_CURRENT_ATTRIB
:
682 return _NEW_CURRENT_ATTRIB
;
683 case STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED
:
684 return _NEW_CURRENT_ATTRIB
| _NEW_LIGHT
| _NEW_BUFFERS
;
686 case STATE_NORMAL_SCALE
:
687 return _NEW_MODELVIEW
;
689 case STATE_TEXRECT_SCALE
:
690 case STATE_ROT_MATRIX_0
:
691 case STATE_ROT_MATRIX_1
:
693 case STATE_FOG_PARAMS_OPTIMIZED
:
695 case STATE_POINT_SIZE_CLAMPED
:
696 return _NEW_POINT
| _NEW_MULTISAMPLE
;
697 case STATE_LIGHT_SPOT_DIR_NORMALIZED
:
698 case STATE_LIGHT_POSITION
:
699 case STATE_LIGHT_POSITION_NORMALIZED
:
700 case STATE_LIGHT_HALF_VECTOR
:
708 case STATE_FB_WPOS_Y_TRANSFORM
:
712 /* unknown state indexes are silently ignored and
713 * no flag set, since it is handled by the driver.
719 _mesa_problem(NULL
, "unexpected state[0] in make_state_flags()");
726 append(char *dst
, const char *src
)
737 * Convert token 'k' to a string, append it onto 'dst' string.
740 append_token(char *dst
, gl_state_index k
)
744 append(dst
, "material");
747 append(dst
, "light");
749 case STATE_LIGHTMODEL_AMBIENT
:
750 append(dst
, "lightmodel.ambient");
752 case STATE_LIGHTMODEL_SCENECOLOR
:
754 case STATE_LIGHTPROD
:
755 append(dst
, "lightprod");
758 append(dst
, "texgen");
760 case STATE_FOG_COLOR
:
761 append(dst
, "fog.color");
763 case STATE_FOG_PARAMS
:
764 append(dst
, "fog.params");
766 case STATE_CLIPPLANE
:
769 case STATE_POINT_SIZE
:
770 append(dst
, "point.size");
772 case STATE_POINT_ATTENUATION
:
773 append(dst
, "point.attenuation");
775 case STATE_MODELVIEW_MATRIX
:
776 append(dst
, "matrix.modelview");
778 case STATE_PROJECTION_MATRIX
:
779 append(dst
, "matrix.projection");
781 case STATE_MVP_MATRIX
:
782 append(dst
, "matrix.mvp");
784 case STATE_TEXTURE_MATRIX
:
785 append(dst
, "matrix.texture");
787 case STATE_PROGRAM_MATRIX
:
788 append(dst
, "matrix.program");
790 case STATE_MATRIX_INVERSE
:
791 append(dst
, ".inverse");
793 case STATE_MATRIX_TRANSPOSE
:
794 append(dst
, ".transpose");
796 case STATE_MATRIX_INVTRANS
:
797 append(dst
, ".invtrans");
800 append(dst
, ".ambient");
803 append(dst
, ".diffuse");
806 append(dst
, ".specular");
809 append(dst
, ".emission");
811 case STATE_SHININESS
:
812 append(dst
, "lshininess");
814 case STATE_HALF_VECTOR
:
815 append(dst
, ".half");
818 append(dst
, ".position");
820 case STATE_ATTENUATION
:
821 append(dst
, ".attenuation");
823 case STATE_SPOT_DIRECTION
:
824 append(dst
, ".spot.direction");
826 case STATE_SPOT_CUTOFF
:
827 append(dst
, ".spot.cutoff");
829 case STATE_TEXGEN_EYE_S
:
830 append(dst
, ".eye.s");
832 case STATE_TEXGEN_EYE_T
:
833 append(dst
, ".eye.t");
835 case STATE_TEXGEN_EYE_R
:
836 append(dst
, ".eye.r");
838 case STATE_TEXGEN_EYE_Q
:
839 append(dst
, ".eye.q");
841 case STATE_TEXGEN_OBJECT_S
:
842 append(dst
, ".object.s");
844 case STATE_TEXGEN_OBJECT_T
:
845 append(dst
, ".object.t");
847 case STATE_TEXGEN_OBJECT_R
:
848 append(dst
, ".object.r");
850 case STATE_TEXGEN_OBJECT_Q
:
851 append(dst
, ".object.q");
853 case STATE_TEXENV_COLOR
:
854 append(dst
, "texenv");
856 case STATE_DEPTH_RANGE
:
857 append(dst
, "depth.range");
859 case STATE_VERTEX_PROGRAM
:
860 case STATE_FRAGMENT_PROGRAM
:
866 append(dst
, "local");
868 /* BEGIN internal state vars */
870 append(dst
, ".internal.");
872 case STATE_CURRENT_ATTRIB
:
873 append(dst
, "current");
875 case STATE_CURRENT_ATTRIB_MAYBE_VP_CLAMPED
:
876 append(dst
, "currentAttribMaybeVPClamped");
878 case STATE_NORMAL_SCALE
:
879 append(dst
, "normalScale");
881 case STATE_TEXRECT_SCALE
:
882 append(dst
, "texrectScale");
884 case STATE_FOG_PARAMS_OPTIMIZED
:
885 append(dst
, "fogParamsOptimized");
887 case STATE_POINT_SIZE_CLAMPED
:
888 append(dst
, "pointSizeClamped");
890 case STATE_LIGHT_SPOT_DIR_NORMALIZED
:
891 append(dst
, "lightSpotDirNormalized");
893 case STATE_LIGHT_POSITION
:
894 append(dst
, "lightPosition");
896 case STATE_LIGHT_POSITION_NORMALIZED
:
897 append(dst
, "light.position.normalized");
899 case STATE_LIGHT_HALF_VECTOR
:
900 append(dst
, "lightHalfVector");
903 append(dst
, "PTscale");
906 append(dst
, "PTbias");
909 append(dst
, "FbSize");
911 case STATE_FB_WPOS_Y_TRANSFORM
:
912 append(dst
, "FbWposYTransform");
914 case STATE_ROT_MATRIX_0
:
915 append(dst
, "rotMatrixRow0");
917 case STATE_ROT_MATRIX_1
:
918 append(dst
, "rotMatrixRow1");
921 /* probably STATE_INTERNAL_DRIVER+i (driver private state) */
922 append(dst
, "driverState");
927 append_face(char *dst
, GLint face
)
930 append(dst
, "front.");
932 append(dst
, "back.");
936 append_index(char *dst
, GLint index
)
939 sprintf(s
, "[%d]", index
);
944 * Make a string from the given state vector.
945 * For example, return "state.matrix.texture[2].inverse".
946 * Use free() to deallocate the string.
949 _mesa_program_state_string(const gl_state_index state
[STATE_LENGTH
])
954 append(str
, "state.");
955 append_token(str
, state
[0]);
959 append_face(str
, state
[1]);
960 append_token(str
, state
[2]);
963 append_index(str
, state
[1]); /* light number [i]. */
964 append_token(str
, state
[2]); /* coefficients */
966 case STATE_LIGHTMODEL_AMBIENT
:
967 append(str
, "lightmodel.ambient");
969 case STATE_LIGHTMODEL_SCENECOLOR
:
971 append(str
, "lightmodel.front.scenecolor");
974 append(str
, "lightmodel.back.scenecolor");
977 case STATE_LIGHTPROD
:
978 append_index(str
, state
[1]); /* light number [i]. */
979 append_face(str
, state
[2]);
980 append_token(str
, state
[3]);
983 append_index(str
, state
[1]); /* tex unit [i] */
984 append_token(str
, state
[2]); /* plane coef */
986 case STATE_TEXENV_COLOR
:
987 append_index(str
, state
[1]); /* tex unit [i] */
988 append(str
, "color");
990 case STATE_CLIPPLANE
:
991 append_index(str
, state
[1]); /* plane [i] */
992 append(str
, ".plane");
994 case STATE_MODELVIEW_MATRIX
:
995 case STATE_PROJECTION_MATRIX
:
996 case STATE_MVP_MATRIX
:
997 case STATE_TEXTURE_MATRIX
:
998 case STATE_PROGRAM_MATRIX
:
1000 /* state[0] = modelview, projection, texture, etc. */
1001 /* state[1] = which texture matrix or program matrix */
1002 /* state[2] = first row to fetch */
1003 /* state[3] = last row to fetch */
1004 /* state[4] = transpose, inverse or invtrans */
1005 const gl_state_index mat
= state
[0];
1006 const GLuint index
= (GLuint
) state
[1];
1007 const GLuint firstRow
= (GLuint
) state
[2];
1008 const GLuint lastRow
= (GLuint
) state
[3];
1009 const gl_state_index modifier
= state
[4];
1011 mat
== STATE_TEXTURE_MATRIX
||
1012 mat
== STATE_PROGRAM_MATRIX
)
1013 append_index(str
, index
);
1015 append_token(str
, modifier
);
1016 if (firstRow
== lastRow
)
1017 sprintf(tmp
, ".row[%d]", firstRow
);
1019 sprintf(tmp
, ".row[%d..%d]", firstRow
, lastRow
);
1023 case STATE_POINT_SIZE
:
1025 case STATE_POINT_ATTENUATION
:
1027 case STATE_FOG_PARAMS
:
1029 case STATE_FOG_COLOR
:
1031 case STATE_DEPTH_RANGE
:
1033 case STATE_FRAGMENT_PROGRAM
:
1034 case STATE_VERTEX_PROGRAM
:
1035 /* state[1] = {STATE_ENV, STATE_LOCAL} */
1036 /* state[2] = parameter index */
1037 append_token(str
, state
[1]);
1038 append_index(str
, state
[2]);
1040 case STATE_NORMAL_SCALE
:
1042 case STATE_INTERNAL
:
1043 append_token(str
, state
[1]);
1044 if (state
[1] == STATE_CURRENT_ATTRIB
)
1045 append_index(str
, state
[2]);
1048 _mesa_problem(NULL
, "Invalid state in _mesa_program_state_string");
1052 return _mesa_strdup(str
);
1057 * Loop over all the parameters in a parameter list. If the parameter
1058 * is a GL state reference, look up the current value of that state
1059 * variable and put it into the parameter's Value[4] array.
1060 * Other parameter types never change or are explicitly set by the user
1061 * with glUniform() or glProgramParameter(), etc.
1062 * This would be called at glBegin time.
1065 _mesa_load_state_parameters(struct gl_context
*ctx
,
1066 struct gl_program_parameter_list
*paramList
)
1073 for (i
= 0; i
< paramList
->NumParameters
; i
++) {
1074 if (paramList
->Parameters
[i
].Type
== PROGRAM_STATE_VAR
) {
1075 _mesa_fetch_state(ctx
,
1076 paramList
->Parameters
[i
].StateIndexes
,
1077 ¶mList
->ParameterValues
[i
][0].f
);