2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 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.
27 * Vertex and fragment program support functions.
39 #include "nvfragparse.h"
40 #include "program_instruction.h"
41 #include "nvvertparse.h"
42 #include "atifragshader.h"
46 make_state_string(const GLint stateTokens
[6]);
49 make_state_flags(const GLint state
[]);
52 /**********************************************************************/
53 /* Utility functions */
54 /**********************************************************************/
57 /* A pointer to this dummy program is put into the hash table when
58 * glGenPrograms is called.
60 struct gl_program _mesa_DummyProgram
;
64 * Init context's vertex/fragment program state
67 _mesa_init_program(GLcontext
*ctx
)
71 ctx
->Program
.ErrorPos
= -1;
72 ctx
->Program
.ErrorString
= _mesa_strdup("");
74 #if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
75 ctx
->VertexProgram
.Enabled
= GL_FALSE
;
76 ctx
->VertexProgram
.PointSizeEnabled
= GL_FALSE
;
77 ctx
->VertexProgram
.TwoSideEnabled
= GL_FALSE
;
78 ctx
->VertexProgram
.Current
= (struct gl_vertex_program
*) ctx
->Shared
->DefaultVertexProgram
;
79 assert(ctx
->VertexProgram
.Current
);
80 ctx
->VertexProgram
.Current
->Base
.RefCount
++;
81 for (i
= 0; i
< MAX_NV_VERTEX_PROGRAM_PARAMS
/ 4; i
++) {
82 ctx
->VertexProgram
.TrackMatrix
[i
] = GL_NONE
;
83 ctx
->VertexProgram
.TrackMatrixTransform
[i
] = GL_IDENTITY_NV
;
87 #if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program
88 ctx
->FragmentProgram
.Enabled
= GL_FALSE
;
89 ctx
->FragmentProgram
.Current
= (struct gl_fragment_program
*) ctx
->Shared
->DefaultFragmentProgram
;
90 assert(ctx
->FragmentProgram
.Current
);
91 ctx
->FragmentProgram
.Current
->Base
.RefCount
++;
94 /* XXX probably move this stuff */
95 #if FEATURE_ATI_fragment_shader
96 ctx
->ATIFragmentShader
.Enabled
= GL_FALSE
;
97 ctx
->ATIFragmentShader
.Current
= (struct ati_fragment_shader
*) ctx
->Shared
->DefaultFragmentShader
;
98 assert(ctx
->ATIFragmentShader
.Current
);
99 ctx
->ATIFragmentShader
.Current
->RefCount
++;
105 * Free a context's vertex/fragment program state
108 _mesa_free_program_data(GLcontext
*ctx
)
110 #if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
111 if (ctx
->VertexProgram
.Current
) {
112 ctx
->VertexProgram
.Current
->Base
.RefCount
--;
113 if (ctx
->VertexProgram
.Current
->Base
.RefCount
<= 0)
114 ctx
->Driver
.DeleteProgram(ctx
, &(ctx
->VertexProgram
.Current
->Base
));
117 #if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program
118 if (ctx
->FragmentProgram
.Current
) {
119 ctx
->FragmentProgram
.Current
->Base
.RefCount
--;
120 if (ctx
->FragmentProgram
.Current
->Base
.RefCount
<= 0)
121 ctx
->Driver
.DeleteProgram(ctx
, &(ctx
->FragmentProgram
.Current
->Base
));
124 /* XXX probably move this stuff */
125 #if FEATURE_ATI_fragment_shader
126 if (ctx
->ATIFragmentShader
.Current
) {
127 ctx
->ATIFragmentShader
.Current
->RefCount
--;
128 if (ctx
->ATIFragmentShader
.Current
->RefCount
<= 0) {
129 _mesa_free(ctx
->ATIFragmentShader
.Current
);
133 _mesa_free((void *) ctx
->Program
.ErrorString
);
140 * Set the vertex/fragment program error state (position and error string).
141 * This is generally called from within the parsers.
144 _mesa_set_program_error(GLcontext
*ctx
, GLint pos
, const char *string
)
146 ctx
->Program
.ErrorPos
= pos
;
147 _mesa_free((void *) ctx
->Program
.ErrorString
);
150 ctx
->Program
.ErrorString
= _mesa_strdup(string
);
155 * Find the line number and column for 'pos' within 'string'.
156 * Return a copy of the line which contains 'pos'. Free the line with
158 * \param string the program string
159 * \param pos the position within the string
160 * \param line returns the line number corresponding to 'pos'.
161 * \param col returns the column number corresponding to 'pos'.
162 * \return copy of the line containing 'pos'.
165 _mesa_find_line_column(const GLubyte
*string
, const GLubyte
*pos
,
166 GLint
*line
, GLint
*col
)
168 const GLubyte
*lineStart
= string
;
169 const GLubyte
*p
= string
;
176 if (*p
== (GLubyte
) '\n') {
183 *col
= (pos
- lineStart
) + 1;
185 /* return copy of this line */
186 while (*p
!= 0 && *p
!= '\n')
189 s
= (GLubyte
*) _mesa_malloc(len
+ 1);
190 _mesa_memcpy(s
, lineStart
, len
);
198 * Initialize a new vertex/fragment program object.
200 static struct gl_program
*
201 _mesa_init_program_struct( GLcontext
*ctx
, struct gl_program
*prog
,
202 GLenum target
, GLuint id
)
207 prog
->Target
= target
;
208 prog
->Resident
= GL_TRUE
;
210 prog
->Format
= GL_PROGRAM_FORMAT_ASCII_ARB
;
218 * Initialize a new fragment program object.
221 _mesa_init_fragment_program( GLcontext
*ctx
, struct gl_fragment_program
*prog
,
222 GLenum target
, GLuint id
)
225 return _mesa_init_program_struct( ctx
, &prog
->Base
, target
, id
);
232 * Initialize a new vertex program object.
235 _mesa_init_vertex_program( GLcontext
*ctx
, struct gl_vertex_program
*prog
,
236 GLenum target
, GLuint id
)
239 return _mesa_init_program_struct( ctx
, &prog
->Base
, target
, id
);
246 * Allocate and initialize a new fragment/vertex program object but
247 * don't put it into the program hash table. Called via
248 * ctx->Driver.NewProgram. May be overridden (ie. replaced) by a
249 * device driver function to implement OO deriviation with additional
250 * types not understood by this function.
253 * \param id program id/number
254 * \param target program target/type
255 * \return pointer to new program object
258 _mesa_new_program(GLcontext
*ctx
, GLenum target
, GLuint id
)
261 case GL_VERTEX_PROGRAM_ARB
: /* == GL_VERTEX_PROGRAM_NV */
262 return _mesa_init_vertex_program(ctx
, CALLOC_STRUCT(gl_vertex_program
),
264 case GL_FRAGMENT_PROGRAM_NV
:
265 case GL_FRAGMENT_PROGRAM_ARB
:
266 return _mesa_init_fragment_program(ctx
,
267 CALLOC_STRUCT(gl_fragment_program
),
270 _mesa_problem(ctx
, "bad target in _mesa_new_program");
277 * Delete a program and remove it from the hash table, ignoring the
279 * Called via ctx->Driver.DeleteProgram. May be wrapped (OO deriviation)
280 * by a device driver function.
283 _mesa_delete_program(GLcontext
*ctx
, struct gl_program
*prog
)
288 if (prog
== &_mesa_DummyProgram
)
292 _mesa_free(prog
->String
);
294 if (prog
->Instructions
) {
296 for (i
= 0; i
< prog
->NumInstructions
; i
++) {
297 if (prog
->Instructions
[i
].Data
)
298 _mesa_free(prog
->Instructions
[i
].Data
);
300 _mesa_free(prog
->Instructions
);
303 if (prog
->Parameters
) {
304 _mesa_free_parameter_list(prog
->Parameters
);
307 /* XXX this is a little ugly */
308 if (prog
->Target
== GL_VERTEX_PROGRAM_ARB
) {
309 struct gl_vertex_program
*vprog
= (struct gl_vertex_program
*) prog
;
311 _mesa_free(vprog
->TnlData
);
319 * Return the gl_program object for a given ID.
320 * Basically just a wrapper for _mesa_HashLookup() to avoid a lot of
324 _mesa_lookup_program(GLcontext
*ctx
, GLuint id
)
327 return (struct gl_program
*) _mesa_HashLookup(ctx
->Shared
->Programs
, id
);
333 /**********************************************************************/
334 /* Program parameter functions */
335 /**********************************************************************/
337 struct gl_program_parameter_list
*
338 _mesa_new_parameter_list(void)
340 return (struct gl_program_parameter_list
*)
341 _mesa_calloc(sizeof(struct gl_program_parameter_list
));
346 * Free a parameter list and all its parameters
349 _mesa_free_parameter_list(struct gl_program_parameter_list
*paramList
)
352 for (i
= 0; i
< paramList
->NumParameters
; i
++) {
353 if (paramList
->Parameters
[i
].Name
)
354 _mesa_free((void *) paramList
->Parameters
[i
].Name
);
356 _mesa_free(paramList
->Parameters
);
357 if (paramList
->ParameterValues
)
358 _mesa_align_free(paramList
->ParameterValues
);
359 _mesa_free(paramList
);
364 * Add a new parameter to a parameter list.
365 * \param paramList the list to add the parameter to
366 * \param name the parameter name, will be duplicated/copied!
367 * \param values initial parameter value, 4 GLfloats
368 * \param type type of parameter, such as
369 * \return index of new parameter in the list, or -1 if error (out of mem)
372 add_parameter(struct gl_program_parameter_list
*paramList
,
373 const char *name
, const GLfloat values
[4],
374 enum register_file type
)
376 const GLuint n
= paramList
->NumParameters
;
378 if (n
== paramList
->Size
) {
379 /* Need to grow the parameter list array */
380 if (paramList
->Size
== 0)
383 paramList
->Size
*= 2;
386 paramList
->Parameters
= (struct gl_program_parameter
*)
387 _mesa_realloc(paramList
->Parameters
,
388 n
* sizeof(struct gl_program_parameter
),
389 paramList
->Size
* sizeof(struct gl_program_parameter
));
391 paramList
->ParameterValues
= (GLfloat (*)[4])
392 _mesa_align_realloc(paramList
->ParameterValues
, /* old buf */
393 n
* 4 * sizeof(GLfloat
), /* old size */
394 paramList
->Size
* 4 *sizeof(GLfloat
), /* new sz */
398 if (!paramList
->Parameters
||
399 !paramList
->ParameterValues
) {
401 paramList
->NumParameters
= 0;
406 paramList
->NumParameters
= n
+ 1;
408 _mesa_memset(¶mList
->Parameters
[n
], 0,
409 sizeof(struct gl_program_parameter
));
411 paramList
->Parameters
[n
].Name
= name
? _mesa_strdup(name
) : NULL
;
412 paramList
->Parameters
[n
].Type
= type
;
414 COPY_4V(paramList
->ParameterValues
[n
], values
);
421 * Add a new named program parameter (Ex: NV_fragment_program DEFINE statement)
422 * \return index of the new entry in the parameter list
425 _mesa_add_named_parameter(struct gl_program_parameter_list
*paramList
,
426 const char *name
, const GLfloat values
[4])
428 return add_parameter(paramList
, name
, values
, PROGRAM_NAMED_PARAM
);
433 * Add a new named constant to the parameter list.
434 * This will be used when the program contains something like this:
435 * PARAM myVals = { 0, 1, 2, 3 };
437 * \param paramList the parameter list
438 * \param name the name for the constant
439 * \param values four float values
440 * \return index/position of the new parameter in the parameter list
443 _mesa_add_named_constant(struct gl_program_parameter_list
*paramList
,
444 const char *name
, const GLfloat values
[4],
447 #if 0 /* disable this for now -- we need to save the name! */
449 ASSERT(size
== 4); /* XXX future feature */
450 /* check if we already have this constant */
451 if (_mesa_lookup_parameter_constant(paramList
, values
, 4, &pos
, &swizzle
)) {
455 return add_parameter(paramList
, name
, values
, PROGRAM_CONSTANT
);
460 * Add a new unnamed constant to the parameter list.
461 * This will be used when the program contains something like this:
462 * MOV r, { 0, 1, 2, 3 };
464 * \param paramList the parameter list
465 * \param values four float values
466 * \return index/position of the new parameter in the parameter list.
469 _mesa_add_unnamed_constant(struct gl_program_parameter_list
*paramList
,
470 const GLfloat values
[4], GLuint size
)
473 ASSERT(size
== 4); /* XXX future feature */
474 /* check if we already have this constant */
475 if (_mesa_lookup_parameter_constant(paramList
, values
, 4, &pos
, &swizzle
)) {
478 return add_parameter(paramList
, NULL
, values
, PROGRAM_CONSTANT
);
483 * Add a new state reference to the parameter list.
484 * This will be used when the program contains something like this:
485 * PARAM ambient = state.material.front.ambient;
487 * \param paramList the parameter list
488 * \param state an array of 6 state tokens
489 * \return index of the new parameter.
492 _mesa_add_state_reference(struct gl_program_parameter_list
*paramList
,
493 const GLint
*stateTokens
)
495 /* XXX we should probably search the current parameter list to see if
496 * the new state reference is already present.
499 const char *name
= make_state_string(stateTokens
);
501 index
= add_parameter(paramList
, name
, NULL
, PROGRAM_STATE_VAR
);
504 for (i
= 0; i
< 6; i
++) {
505 paramList
->Parameters
[index
].StateIndexes
[i
]
506 = (enum state_index
) stateTokens
[i
];
508 paramList
->StateFlags
|= make_state_flags(stateTokens
);
511 /* free name string here since we duplicated it in add_parameter() */
512 _mesa_free((void *) name
);
519 * Lookup a parameter value by name in the given parameter list.
520 * \return pointer to the float[4] values.
523 _mesa_lookup_parameter_value(const struct gl_program_parameter_list
*paramList
,
524 GLsizei nameLen
, const char *name
)
532 /* name is null-terminated */
533 for (i
= 0; i
< paramList
->NumParameters
; i
++) {
534 if (paramList
->Parameters
[i
].Name
&&
535 _mesa_strcmp(paramList
->Parameters
[i
].Name
, name
) == 0)
536 return paramList
->ParameterValues
[i
];
540 /* name is not null-terminated, use nameLen */
541 for (i
= 0; i
< paramList
->NumParameters
; i
++) {
542 if (paramList
->Parameters
[i
].Name
&&
543 _mesa_strncmp(paramList
->Parameters
[i
].Name
, name
, nameLen
) == 0
544 && _mesa_strlen(paramList
->Parameters
[i
].Name
) == (size_t)nameLen
)
545 return paramList
->ParameterValues
[i
];
553 * Given a program parameter name, find its position in the list of parameters.
554 * \param paramList the parameter list to search
555 * \param nameLen length of name (in chars).
556 * If length is negative, assume that name is null-terminated.
557 * \param name the name to search for
558 * \return index of parameter in the list.
561 _mesa_lookup_parameter_index(const struct gl_program_parameter_list
*paramList
,
562 GLsizei nameLen
, const char *name
)
570 /* name is null-terminated */
571 for (i
= 0; i
< (GLint
) paramList
->NumParameters
; i
++) {
572 if (paramList
->Parameters
[i
].Name
&&
573 _mesa_strcmp(paramList
->Parameters
[i
].Name
, name
) == 0)
578 /* name is not null-terminated, use nameLen */
579 for (i
= 0; i
< (GLint
) paramList
->NumParameters
; i
++) {
580 if (paramList
->Parameters
[i
].Name
&&
581 _mesa_strncmp(paramList
->Parameters
[i
].Name
, name
, nameLen
) == 0
582 && _mesa_strlen(paramList
->Parameters
[i
].Name
) == (size_t)nameLen
)
591 * Look for a float vector in the given parameter list. The float vector
592 * may be of length 1, 2, 3 or 4.
593 * \param paramList the parameter list to search
594 * \param v the float vector to search for
595 * \param size number of element in v
596 * \param posOut returns the position of the constant, if found
597 * \param swizzleOut returns a swizzle mask describing location of the
598 * vector elements if found
599 * \return GL_TRUE if found, GL_FALSE if not found
602 _mesa_lookup_parameter_constant(const struct gl_program_parameter_list
*paramList
,
603 const GLfloat v
[], GLsizei vSize
,
604 GLuint
*posOut
, GLuint
*swizzleOut
)
614 for (i
= 0; i
< paramList
->NumParameters
; i
++) {
615 if (paramList
->Parameters
[i
].Type
== PROGRAM_CONSTANT
) {
616 const GLint maxShift
= 4 - vSize
;
618 for (shift
= 0; shift
<= maxShift
; shift
++) {
621 swizzle
[0] = swizzle
[1] = swizzle
[2] = swizzle
[3] = 0;
622 /* XXX we could do out-of-order swizzle matches too, someday */
623 for (j
= 0; j
< vSize
; j
++) {
624 assert(shift
+ j
< 4);
625 if (paramList
->ParameterValues
[i
][shift
+ j
] == v
[j
]) {
627 swizzle
[j
] = shift
+ j
;
630 if (matched
== vSize
) {
633 *swizzleOut
= MAKE_SWIZZLE4(swizzle
[0], swizzle
[1],
634 swizzle
[2], swizzle
[3]);
646 * Use the list of tokens in the state[] array to find global GL state
647 * and return it in <value>. Usually, four values are returned in <value>
648 * but matrix queries may return as many as 16 values.
649 * This function is used for ARB vertex/fragment programs.
650 * The program parser will produce the state[] values.
653 _mesa_fetch_state(GLcontext
*ctx
, const enum state_index state
[],
659 /* state[1] is either 0=front or 1=back side */
660 const GLuint face
= (GLuint
) state
[1];
661 const struct gl_material
*mat
= &ctx
->Light
.Material
;
662 ASSERT(face
== 0 || face
== 1);
663 /* we rely on tokens numbered so that _BACK_ == _FRONT_+ 1 */
664 ASSERT(MAT_ATTRIB_FRONT_AMBIENT
+ 1 == MAT_ATTRIB_BACK_AMBIENT
);
665 /* XXX we could get rid of this switch entirely with a little
666 * work in arbprogparse.c's parse_state_single_item().
668 /* state[2] is the material attribute */
671 COPY_4V(value
, mat
->Attrib
[MAT_ATTRIB_FRONT_AMBIENT
+ face
]);
674 COPY_4V(value
, mat
->Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
+ face
]);
677 COPY_4V(value
, mat
->Attrib
[MAT_ATTRIB_FRONT_SPECULAR
+ face
]);
680 COPY_4V(value
, mat
->Attrib
[MAT_ATTRIB_FRONT_EMISSION
+ face
]);
682 case STATE_SHININESS
:
683 value
[0] = mat
->Attrib
[MAT_ATTRIB_FRONT_SHININESS
+ face
][0];
689 _mesa_problem(ctx
, "Invalid material state in fetch_state");
695 /* state[1] is the light number */
696 const GLuint ln
= (GLuint
) state
[1];
697 /* state[2] is the light attribute */
700 COPY_4V(value
, ctx
->Light
.Light
[ln
].Ambient
);
703 COPY_4V(value
, ctx
->Light
.Light
[ln
].Diffuse
);
706 COPY_4V(value
, ctx
->Light
.Light
[ln
].Specular
);
709 COPY_4V(value
, ctx
->Light
.Light
[ln
].EyePosition
);
711 case STATE_ATTENUATION
:
712 value
[0] = ctx
->Light
.Light
[ln
].ConstantAttenuation
;
713 value
[1] = ctx
->Light
.Light
[ln
].LinearAttenuation
;
714 value
[2] = ctx
->Light
.Light
[ln
].QuadraticAttenuation
;
715 value
[3] = ctx
->Light
.Light
[ln
].SpotExponent
;
717 case STATE_SPOT_DIRECTION
:
718 COPY_3V(value
, ctx
->Light
.Light
[ln
].EyeDirection
);
719 value
[3] = ctx
->Light
.Light
[ln
]._CosCutoff
;
723 GLfloat eye_z
[] = {0, 0, 1};
725 /* Compute infinite half angle vector:
726 * half-vector = light_position + (0, 0, 1)
727 * and then normalize. w = 0
729 * light.EyePosition.w should be 0 for infinite lights.
731 ADD_3V(value
, eye_z
, ctx
->Light
.Light
[ln
].EyePosition
);
732 NORMALIZE_3FV(value
);
736 case STATE_POSITION_NORMALIZED
:
737 COPY_4V(value
, ctx
->Light
.Light
[ln
].EyePosition
);
738 NORMALIZE_3FV( value
);
741 _mesa_problem(ctx
, "Invalid light state in fetch_state");
745 case STATE_LIGHTMODEL_AMBIENT
:
746 COPY_4V(value
, ctx
->Light
.Model
.Ambient
);
748 case STATE_LIGHTMODEL_SCENECOLOR
:
752 for (i
= 0; i
< 3; i
++) {
753 value
[i
] = ctx
->Light
.Model
.Ambient
[i
]
754 * ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_AMBIENT
][i
]
755 + ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_EMISSION
][i
];
757 value
[3] = ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
][3];
762 for (i
= 0; i
< 3; i
++) {
763 value
[i
] = ctx
->Light
.Model
.Ambient
[i
]
764 * ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_BACK_AMBIENT
][i
]
765 + ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_BACK_EMISSION
][i
];
767 value
[3] = ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_BACK_DIFFUSE
][3];
770 case STATE_LIGHTPROD
:
772 const GLuint ln
= (GLuint
) state
[1];
773 const GLuint face
= (GLuint
) state
[2];
775 ASSERT(face
== 0 || face
== 1);
778 for (i
= 0; i
< 3; i
++) {
779 value
[i
] = ctx
->Light
.Light
[ln
].Ambient
[i
] *
780 ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_AMBIENT
+face
][i
];
782 /* [3] = material alpha */
783 value
[3] = ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
+face
][3];
786 for (i
= 0; i
< 3; i
++) {
787 value
[i
] = ctx
->Light
.Light
[ln
].Diffuse
[i
] *
788 ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
+face
][i
];
790 /* [3] = material alpha */
791 value
[3] = ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
+face
][3];
794 for (i
= 0; i
< 3; i
++) {
795 value
[i
] = ctx
->Light
.Light
[ln
].Specular
[i
] *
796 ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_SPECULAR
+face
][i
];
798 /* [3] = material alpha */
799 value
[3] = ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
+face
][3];
802 _mesa_problem(ctx
, "Invalid lightprod state in fetch_state");
808 /* state[1] is the texture unit */
809 const GLuint unit
= (GLuint
) state
[1];
810 /* state[2] is the texgen attribute */
812 case STATE_TEXGEN_EYE_S
:
813 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].EyePlaneS
);
815 case STATE_TEXGEN_EYE_T
:
816 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].EyePlaneT
);
818 case STATE_TEXGEN_EYE_R
:
819 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].EyePlaneR
);
821 case STATE_TEXGEN_EYE_Q
:
822 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].EyePlaneQ
);
824 case STATE_TEXGEN_OBJECT_S
:
825 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].ObjectPlaneS
);
827 case STATE_TEXGEN_OBJECT_T
:
828 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].ObjectPlaneT
);
830 case STATE_TEXGEN_OBJECT_R
:
831 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].ObjectPlaneR
);
833 case STATE_TEXGEN_OBJECT_Q
:
834 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].ObjectPlaneQ
);
837 _mesa_problem(ctx
, "Invalid texgen state in fetch_state");
841 case STATE_TEXENV_COLOR
:
843 /* state[1] is the texture unit */
844 const GLuint unit
= (GLuint
) state
[1];
845 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].EnvColor
);
848 case STATE_FOG_COLOR
:
849 COPY_4V(value
, ctx
->Fog
.Color
);
851 case STATE_FOG_PARAMS
:
852 value
[0] = ctx
->Fog
.Density
;
853 value
[1] = ctx
->Fog
.Start
;
854 value
[2] = ctx
->Fog
.End
;
855 value
[3] = 1.0F
/ (ctx
->Fog
.End
- ctx
->Fog
.Start
);
857 case STATE_CLIPPLANE
:
859 const GLuint plane
= (GLuint
) state
[1];
860 COPY_4V(value
, ctx
->Transform
.EyeUserPlane
[plane
]);
863 case STATE_POINT_SIZE
:
864 value
[0] = ctx
->Point
.Size
;
865 value
[1] = ctx
->Point
.MinSize
;
866 value
[2] = ctx
->Point
.MaxSize
;
867 value
[3] = ctx
->Point
.Threshold
;
869 case STATE_POINT_ATTENUATION
:
870 value
[0] = ctx
->Point
.Params
[0];
871 value
[1] = ctx
->Point
.Params
[1];
872 value
[2] = ctx
->Point
.Params
[2];
877 /* state[1] = modelview, projection, texture, etc. */
878 /* state[2] = which texture matrix or program matrix */
879 /* state[3] = first column to fetch */
880 /* state[4] = last column to fetch */
881 /* state[5] = transpose, inverse or invtrans */
883 const GLmatrix
*matrix
;
884 const enum state_index mat
= state
[1];
885 const GLuint index
= (GLuint
) state
[2];
886 const GLuint first
= (GLuint
) state
[3];
887 const GLuint last
= (GLuint
) state
[4];
888 const enum state_index modifier
= state
[5];
891 if (mat
== STATE_MODELVIEW
) {
892 matrix
= ctx
->ModelviewMatrixStack
.Top
;
894 else if (mat
== STATE_PROJECTION
) {
895 matrix
= ctx
->ProjectionMatrixStack
.Top
;
897 else if (mat
== STATE_MVP
) {
898 matrix
= &ctx
->_ModelProjectMatrix
;
900 else if (mat
== STATE_TEXTURE
) {
901 matrix
= ctx
->TextureMatrixStack
[index
].Top
;
903 else if (mat
== STATE_PROGRAM
) {
904 matrix
= ctx
->ProgramMatrixStack
[index
].Top
;
907 _mesa_problem(ctx
, "Bad matrix name in _mesa_fetch_state()");
910 if (modifier
== STATE_MATRIX_INVERSE
||
911 modifier
== STATE_MATRIX_INVTRANS
) {
912 /* Be sure inverse is up to date:
914 _math_matrix_alloc_inv( (GLmatrix
*) matrix
);
915 _math_matrix_analyse( (GLmatrix
*) matrix
);
921 if (modifier
== STATE_MATRIX_TRANSPOSE
||
922 modifier
== STATE_MATRIX_INVTRANS
) {
923 for (i
= 0, row
= first
; row
<= last
; row
++) {
924 value
[i
++] = m
[row
* 4 + 0];
925 value
[i
++] = m
[row
* 4 + 1];
926 value
[i
++] = m
[row
* 4 + 2];
927 value
[i
++] = m
[row
* 4 + 3];
931 for (i
= 0, row
= first
; row
<= last
; row
++) {
932 value
[i
++] = m
[row
+ 0];
933 value
[i
++] = m
[row
+ 4];
934 value
[i
++] = m
[row
+ 8];
935 value
[i
++] = m
[row
+ 12];
940 case STATE_DEPTH_RANGE
:
941 value
[0] = ctx
->Viewport
.Near
; /* near */
942 value
[1] = ctx
->Viewport
.Far
; /* far */
943 value
[2] = ctx
->Viewport
.Far
- ctx
->Viewport
.Near
; /* far - near */
946 case STATE_FRAGMENT_PROGRAM
:
948 /* state[1] = {STATE_ENV, STATE_LOCAL} */
949 /* state[2] = parameter index */
950 const int idx
= (int) state
[2];
953 COPY_4V(value
, ctx
->FragmentProgram
.Parameters
[idx
]);
956 COPY_4V(value
, ctx
->FragmentProgram
.Current
->Base
.LocalParams
[idx
]);
959 _mesa_problem(ctx
, "Bad state switch in _mesa_fetch_state()");
965 case STATE_VERTEX_PROGRAM
:
967 /* state[1] = {STATE_ENV, STATE_LOCAL} */
968 /* state[2] = parameter index */
969 const int idx
= (int) state
[2];
972 COPY_4V(value
, ctx
->VertexProgram
.Parameters
[idx
]);
975 COPY_4V(value
, ctx
->VertexProgram
.Current
->Base
.LocalParams
[idx
]);
978 _mesa_problem(ctx
, "Bad state switch in _mesa_fetch_state()");
987 case STATE_NORMAL_SCALE
:
988 ASSIGN_4V(value
, ctx
->_ModelViewInvScale
, 0, 0, 1);
990 case STATE_TEXRECT_SCALE
: {
991 const int unit
= (int) state
[2];
992 const struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[unit
]._Current
;
994 struct gl_texture_image
*texImage
= texObj
->Image
[0][0];
995 ASSIGN_4V(value
, 1.0 / texImage
->Width
, 1.0 / texImage
->Height
, 0, 1);
999 case STATE_FOG_PARAMS_OPTIMIZED
:
1000 /* for simpler per-vertex/pixel fog calcs. POW
1001 (for EXP/EXP2 fog) might be more expensive than EX2 on some hw,
1002 plus it needs another constant (e) anyway. Linear fog can now be
1003 done with a single MAD.
1004 linear: fogcoord * -1/(end-start) + end/(end-start)
1005 exp: 2^-(density/ln(2) * fogcoord)
1006 exp2: 2^-((density/(ln(2)^2) * fogcoord)^2) */
1007 value
[0] = -1.0F
/ (ctx
->Fog
.End
- ctx
->Fog
.Start
);
1008 value
[1] = ctx
->Fog
.End
/ (ctx
->Fog
.End
- ctx
->Fog
.Start
);
1009 value
[2] = ctx
->Fog
.Density
* ONE_DIV_LN2
;
1010 value
[3] = ctx
->Fog
.Density
* ONE_DIV_SQRT_LN2
;
1012 case STATE_SPOT_DIR_NORMALIZED
: {
1013 /* here, state[2] is the light number */
1014 /* pre-normalize spot dir */
1015 const GLuint ln
= (GLuint
) state
[2];
1016 value
[0] = ctx
->Light
.Light
[ln
].EyeDirection
[0];
1017 value
[1] = ctx
->Light
.Light
[ln
].EyeDirection
[1];
1018 value
[2] = ctx
->Light
.Light
[ln
].EyeDirection
[2];
1019 NORMALIZE_3FV(value
);
1020 value
[3] = ctx
->Light
.Light
[ln
]._CosCutoff
;
1024 /* unknown state indexes are silently ignored
1025 * should be handled by the driver.
1033 _mesa_problem(ctx
, "Invalid state in _mesa_fetch_state");
1040 * Return a bitmask of the Mesa state flags (_NEW_* values) which would
1041 * indicate that the given context state may have changed.
1042 * The bitmask is used during validation to determine if we need to update
1043 * vertex/fragment program parameters (like "state.material.color") when
1044 * some GL state has changed.
1047 make_state_flags(const GLint state
[])
1050 case STATE_MATERIAL
:
1052 case STATE_LIGHTMODEL_AMBIENT
:
1053 case STATE_LIGHTMODEL_SCENECOLOR
:
1054 case STATE_LIGHTPROD
:
1058 case STATE_TEXENV_COLOR
:
1059 return _NEW_TEXTURE
;
1061 case STATE_FOG_COLOR
:
1062 case STATE_FOG_PARAMS
:
1065 case STATE_CLIPPLANE
:
1066 return _NEW_TRANSFORM
;
1068 case STATE_POINT_SIZE
:
1069 case STATE_POINT_ATTENUATION
:
1074 case STATE_MODELVIEW
:
1075 return _NEW_MODELVIEW
;
1076 case STATE_PROJECTION
:
1077 return _NEW_PROJECTION
;
1079 return _NEW_MODELVIEW
| _NEW_PROJECTION
;
1081 return _NEW_TEXTURE_MATRIX
;
1083 return _NEW_TRACK_MATRIX
;
1085 _mesa_problem(NULL
, "unexpected matrix in make_state_flags()");
1089 case STATE_DEPTH_RANGE
:
1090 return _NEW_VIEWPORT
;
1092 case STATE_FRAGMENT_PROGRAM
:
1093 case STATE_VERTEX_PROGRAM
:
1094 return _NEW_PROGRAM
;
1096 case STATE_INTERNAL
:
1098 case STATE_NORMAL_SCALE
:
1099 return _NEW_MODELVIEW
;
1100 case STATE_TEXRECT_SCALE
:
1101 return _NEW_TEXTURE
;
1102 case STATE_FOG_PARAMS_OPTIMIZED
:
1104 case STATE_SPOT_DIR_NORMALIZED
:
1107 /* unknown state indexes are silently ignored and
1108 * no flag set, since it is handled by the driver.
1114 _mesa_problem(NULL
, "unexpected state[0] in make_state_flags()");
1121 append(char *dst
, const char *src
)
1132 append_token(char *dst
, enum state_index k
)
1135 case STATE_MATERIAL
:
1136 append(dst
, "material.");
1139 append(dst
, "light");
1141 case STATE_LIGHTMODEL_AMBIENT
:
1142 append(dst
, "lightmodel.ambient");
1144 case STATE_LIGHTMODEL_SCENECOLOR
:
1146 case STATE_LIGHTPROD
:
1147 append(dst
, "lightprod");
1150 append(dst
, "texgen");
1152 case STATE_FOG_COLOR
:
1153 append(dst
, "fog.color");
1155 case STATE_FOG_PARAMS
:
1156 append(dst
, "fog.params");
1158 case STATE_CLIPPLANE
:
1159 append(dst
, "clip");
1161 case STATE_POINT_SIZE
:
1162 append(dst
, "point.size");
1164 case STATE_POINT_ATTENUATION
:
1165 append(dst
, "point.attenuation");
1168 append(dst
, "matrix.");
1170 case STATE_MODELVIEW
:
1171 append(dst
, "modelview");
1173 case STATE_PROJECTION
:
1174 append(dst
, "projection");
1180 append(dst
, "texture");
1183 append(dst
, "program");
1185 case STATE_MATRIX_INVERSE
:
1186 append(dst
, ".inverse");
1188 case STATE_MATRIX_TRANSPOSE
:
1189 append(dst
, ".transpose");
1191 case STATE_MATRIX_INVTRANS
:
1192 append(dst
, ".invtrans");
1195 append(dst
, "ambient");
1198 append(dst
, "diffuse");
1200 case STATE_SPECULAR
:
1201 append(dst
, "specular");
1203 case STATE_EMISSION
:
1204 append(dst
, "emission");
1206 case STATE_SHININESS
:
1207 append(dst
, "shininess");
1210 append(dst
, "half");
1212 case STATE_POSITION
:
1213 append(dst
, ".position");
1215 case STATE_ATTENUATION
:
1216 append(dst
, ".attenuation");
1218 case STATE_SPOT_DIRECTION
:
1219 append(dst
, ".spot.direction");
1221 case STATE_TEXGEN_EYE_S
:
1222 append(dst
, "eye.s");
1224 case STATE_TEXGEN_EYE_T
:
1225 append(dst
, "eye.t");
1227 case STATE_TEXGEN_EYE_R
:
1228 append(dst
, "eye.r");
1230 case STATE_TEXGEN_EYE_Q
:
1231 append(dst
, "eye.q");
1233 case STATE_TEXGEN_OBJECT_S
:
1234 append(dst
, "object.s");
1236 case STATE_TEXGEN_OBJECT_T
:
1237 append(dst
, "object.t");
1239 case STATE_TEXGEN_OBJECT_R
:
1240 append(dst
, "object.r");
1242 case STATE_TEXGEN_OBJECT_Q
:
1243 append(dst
, "object.q");
1245 case STATE_TEXENV_COLOR
:
1246 append(dst
, "texenv");
1248 case STATE_DEPTH_RANGE
:
1249 append(dst
, "depth.range");
1251 case STATE_VERTEX_PROGRAM
:
1252 case STATE_FRAGMENT_PROGRAM
:
1258 append(dst
, "local");
1260 case STATE_INTERNAL
:
1261 case STATE_NORMAL_SCALE
:
1262 case STATE_POSITION_NORMALIZED
:
1263 case STATE_FOG_PARAMS_OPTIMIZED
:
1264 case STATE_SPOT_DIR_NORMALIZED
:
1265 append(dst
, "(internal)");
1273 append_face(char *dst
, GLint face
)
1276 append(dst
, "front.");
1278 append(dst
, "back.");
1282 append_index(char *dst
, GLint index
)
1285 _mesa_sprintf(s
, "[%d].", index
);
1290 * Make a string from the given state vector.
1291 * For example, return "state.matrix.texture[2].inverse".
1292 * Use _mesa_free() to deallocate the string.
1295 make_state_string(const GLint state
[6])
1297 char str
[1000] = "";
1300 append(str
, "state.");
1301 append_token(str
, (enum state_index
) state
[0]);
1304 case STATE_MATERIAL
:
1305 append_face(str
, state
[1]);
1306 append_token(str
, (enum state_index
) state
[2]);
1309 append(str
, "light");
1310 append_index(str
, state
[1]); /* light number [i]. */
1311 append_token(str
, (enum state_index
) state
[2]); /* coefficients */
1313 case STATE_LIGHTMODEL_AMBIENT
:
1314 append(str
, "lightmodel.ambient");
1316 case STATE_LIGHTMODEL_SCENECOLOR
:
1317 if (state
[1] == 0) {
1318 append(str
, "lightmodel.front.scenecolor");
1321 append(str
, "lightmodel.back.scenecolor");
1324 case STATE_LIGHTPROD
:
1325 append_index(str
, state
[1]); /* light number [i]. */
1326 append_face(str
, state
[2]);
1327 append_token(str
, (enum state_index
) state
[3]);
1330 append_index(str
, state
[1]); /* tex unit [i] */
1331 append_token(str
, (enum state_index
) state
[2]); /* plane coef */
1333 case STATE_TEXENV_COLOR
:
1334 append_index(str
, state
[1]); /* tex unit [i] */
1335 append(str
, "color");
1337 case STATE_FOG_COLOR
:
1338 case STATE_FOG_PARAMS
:
1340 case STATE_CLIPPLANE
:
1341 append_index(str
, state
[1]); /* plane [i] */
1342 append(str
, "plane");
1344 case STATE_POINT_SIZE
:
1345 case STATE_POINT_ATTENUATION
:
1349 /* state[1] = modelview, projection, texture, etc. */
1350 /* state[2] = which texture matrix or program matrix */
1351 /* state[3] = first column to fetch */
1352 /* state[4] = last column to fetch */
1353 /* state[5] = transpose, inverse or invtrans */
1354 const enum state_index mat
= (enum state_index
) state
[1];
1355 const GLuint index
= (GLuint
) state
[2];
1356 const GLuint first
= (GLuint
) state
[3];
1357 const GLuint last
= (GLuint
) state
[4];
1358 const enum state_index modifier
= (enum state_index
) state
[5];
1359 append_token(str
, mat
);
1361 append_index(str
, index
);
1363 append_token(str
, modifier
);
1365 _mesa_sprintf(tmp
, ".row[%d]", first
);
1367 _mesa_sprintf(tmp
, ".row[%d..%d]", first
, last
);
1371 case STATE_DEPTH_RANGE
:
1373 case STATE_FRAGMENT_PROGRAM
:
1374 case STATE_VERTEX_PROGRAM
:
1375 /* state[1] = {STATE_ENV, STATE_LOCAL} */
1376 /* state[2] = parameter index */
1377 append_token(str
, (enum state_index
) state
[1]);
1378 append_index(str
, state
[2]);
1380 case STATE_INTERNAL
:
1383 _mesa_problem(NULL
, "Invalid state in make_state_string");
1387 return _mesa_strdup(str
);
1392 * Loop over all the parameters in a parameter list. If the parameter
1393 * is a GL state reference, look up the current value of that state
1394 * variable and put it into the parameter's Value[4] array.
1395 * This would be called at glBegin time when using a fragment program.
1398 _mesa_load_state_parameters(GLcontext
*ctx
,
1399 struct gl_program_parameter_list
*paramList
)
1406 for (i
= 0; i
< paramList
->NumParameters
; i
++) {
1407 if (paramList
->Parameters
[i
].Type
== PROGRAM_STATE_VAR
) {
1408 _mesa_fetch_state(ctx
,
1409 paramList
->Parameters
[i
].StateIndexes
,
1410 paramList
->ParameterValues
[i
]);
1417 * Initialize program instruction fields to defaults.
1418 * \param inst first instruction to initialize
1419 * \param count number of instructions to initialize
1422 _mesa_init_instructions(struct prog_instruction
*inst
, GLuint count
)
1426 _mesa_bzero(inst
, count
* sizeof(struct prog_instruction
));
1428 for (i
= 0; i
< count
; i
++) {
1429 inst
[i
].SrcReg
[0].File
= PROGRAM_UNDEFINED
;
1430 inst
[i
].SrcReg
[0].Swizzle
= SWIZZLE_NOOP
;
1431 inst
[i
].SrcReg
[1].File
= PROGRAM_UNDEFINED
;
1432 inst
[i
].SrcReg
[1].Swizzle
= SWIZZLE_NOOP
;
1433 inst
[i
].SrcReg
[2].File
= PROGRAM_UNDEFINED
;
1434 inst
[i
].SrcReg
[2].Swizzle
= SWIZZLE_NOOP
;
1436 inst
[i
].DstReg
.File
= PROGRAM_UNDEFINED
;
1437 inst
[i
].DstReg
.WriteMask
= WRITEMASK_XYZW
;
1438 inst
[i
].DstReg
.CondMask
= COND_TR
;
1439 inst
[i
].DstReg
.CondSwizzle
= SWIZZLE_NOOP
;
1441 inst
[i
].SaturateMode
= SATURATE_OFF
;
1442 inst
[i
].Precision
= FLOAT32
;
1448 * Allocate an array of program instructions.
1449 * \param numInst number of instructions
1450 * \return pointer to instruction memory
1452 struct prog_instruction
*
1453 _mesa_alloc_instructions(GLuint numInst
)
1455 return (struct prog_instruction
*)
1456 _mesa_calloc(numInst
* sizeof(struct prog_instruction
));
1461 * Reallocate memory storing an array of program instructions.
1462 * This is used when we need to append additional instructions onto an
1464 * \param oldInst pointer to first of old/src instructions
1465 * \param numOldInst number of instructions at <oldInst>
1466 * \param numNewInst desired size of new instruction array.
1467 * \return pointer to start of new instruction array.
1469 struct prog_instruction
*
1470 _mesa_realloc_instructions(struct prog_instruction
*oldInst
,
1471 GLuint numOldInst
, GLuint numNewInst
)
1473 struct prog_instruction
*newInst
;
1475 newInst
= (struct prog_instruction
*)
1476 _mesa_realloc(oldInst
,
1477 numOldInst
* sizeof(struct prog_instruction
),
1478 numNewInst
* sizeof(struct prog_instruction
));
1485 * Basic info about each instruction
1487 struct instruction_info
1489 enum prog_opcode Opcode
;
1496 * \note Opcode should equal array index!
1498 static const struct instruction_info InstInfo
[MAX_OPCODE
] = {
1499 { OPCODE_ABS
, "ABS", 1 },
1500 { OPCODE_ADD
, "ADD", 2 },
1501 { OPCODE_ARA
, "ARA", 1 },
1502 { OPCODE_ARL
, "ARL", 1 },
1503 { OPCODE_ARL_NV
, "ARL", 1 },
1504 { OPCODE_ARR
, "ARL", 1 },
1505 { OPCODE_BRA
, "BRA", 1 },
1506 { OPCODE_CAL
, "CAL", 1 },
1507 { OPCODE_CMP
, "CMP", 3 },
1508 { OPCODE_COS
, "COS", 1 },
1509 { OPCODE_DDX
, "DDX", 1 },
1510 { OPCODE_DDY
, "DDY", 1 },
1511 { OPCODE_DP3
, "DP3", 2 },
1512 { OPCODE_DP4
, "DP4", 2 },
1513 { OPCODE_DPH
, "DPH", 2 },
1514 { OPCODE_DST
, "DST", 2 },
1515 { OPCODE_END
, "END", 0 },
1516 { OPCODE_EX2
, "EX2", 1 },
1517 { OPCODE_EXP
, "EXP", 1 },
1518 { OPCODE_FLR
, "FLR", 1 },
1519 { OPCODE_FRC
, "FRC", 1 },
1520 { OPCODE_KIL
, "KIL", 1 },
1521 { OPCODE_KIL_NV
, "KIL", 0 },
1522 { OPCODE_LG2
, "LG2", 1 },
1523 { OPCODE_LIT
, "LIT", 1 },
1524 { OPCODE_LOG
, "LOG", 1 },
1525 { OPCODE_LRP
, "LRP", 3 },
1526 { OPCODE_MAD
, "MAD", 3 },
1527 { OPCODE_MAX
, "MAX", 2 },
1528 { OPCODE_MIN
, "MIN", 2 },
1529 { OPCODE_MOV
, "MOV", 1 },
1530 { OPCODE_MUL
, "MUL", 2 },
1531 { OPCODE_PK2H
, "PK2H", 1 },
1532 { OPCODE_PK2US
, "PK2US", 1 },
1533 { OPCODE_PK4B
, "PK4B", 1 },
1534 { OPCODE_PK4UB
, "PK4UB", 1 },
1535 { OPCODE_POW
, "POW", 2 },
1536 { OPCODE_POPA
, "POPA", 0 },
1537 { OPCODE_PRINT
, "PRINT", 1 },
1538 { OPCODE_PUSHA
, "PUSHA", 0 },
1539 { OPCODE_RCC
, "RCC", 1 },
1540 { OPCODE_RCP
, "RCP", 1 },
1541 { OPCODE_RET
, "RET", 1 },
1542 { OPCODE_RFL
, "RFL", 1 },
1543 { OPCODE_RSQ
, "RSQ", 1 },
1544 { OPCODE_SCS
, "SCS", 1 },
1545 { OPCODE_SEQ
, "SEQ", 2 },
1546 { OPCODE_SFL
, "SFL", 0 },
1547 { OPCODE_SGE
, "SGE", 2 },
1548 { OPCODE_SGT
, "SGT", 2 },
1549 { OPCODE_SIN
, "SIN", 1 },
1550 { OPCODE_SLE
, "SLE", 2 },
1551 { OPCODE_SLT
, "SLT", 2 },
1552 { OPCODE_SNE
, "SNE", 2 },
1553 { OPCODE_SSG
, "SSG", 1 },
1554 { OPCODE_STR
, "STR", 0 },
1555 { OPCODE_SUB
, "SUB", 2 },
1556 { OPCODE_SWZ
, "SWZ", 1 },
1557 { OPCODE_TEX
, "TEX", 1 },
1558 { OPCODE_TXB
, "TXB", 1 },
1559 { OPCODE_TXD
, "TXD", 3 },
1560 { OPCODE_TXL
, "TXL", 1 },
1561 { OPCODE_TXP
, "TXP", 1 },
1562 { OPCODE_TXP_NV
, "TXP", 1 },
1563 { OPCODE_UP2H
, "UP2H", 1 },
1564 { OPCODE_UP2US
, "UP2US", 1 },
1565 { OPCODE_UP4B
, "UP4B", 1 },
1566 { OPCODE_UP4UB
, "UP4UB", 1 },
1567 { OPCODE_X2D
, "X2D", 3 },
1568 { OPCODE_XPD
, "XPD", 2 }
1573 * Return the number of src registers for the given instruction/opcode.
1576 _mesa_num_inst_src_regs(enum prog_opcode opcode
)
1578 ASSERT(opcode
== InstInfo
[opcode
].Opcode
);
1579 return InstInfo
[opcode
].NumSrcRegs
;
1584 * Return string name for given program opcode.
1587 _mesa_opcode_string(enum prog_opcode opcode
)
1589 ASSERT(opcode
< MAX_OPCODE
);
1590 return InstInfo
[opcode
].Name
;
1594 * Return string name for given program/register file.
1597 program_file_string(enum register_file f
)
1600 case PROGRAM_TEMPORARY
:
1602 case PROGRAM_LOCAL_PARAM
:
1604 case PROGRAM_ENV_PARAM
:
1606 case PROGRAM_STATE_VAR
:
1610 case PROGRAM_OUTPUT
:
1612 case PROGRAM_NAMED_PARAM
:
1614 case PROGRAM_CONSTANT
:
1616 case PROGRAM_WRITE_ONLY
:
1617 return "WRITE_ONLY";
1618 case PROGRAM_ADDRESS
:
1627 * Return a string representation of the given swizzle word.
1628 * If extended is true, use extended (comma-separated) format.
1631 swizzle_string(GLuint swizzle
, GLuint negateBase
, GLboolean extended
)
1633 static const char swz
[] = "xyzw01";
1637 if (!extended
&& swizzle
== SWIZZLE_NOOP
&& negateBase
== 0)
1638 return ""; /* no swizzle/negation */
1643 if (negateBase
& 0x1)
1645 s
[i
++] = swz
[GET_SWZ(swizzle
, 0)];
1651 if (negateBase
& 0x2)
1653 s
[i
++] = swz
[GET_SWZ(swizzle
, 1)];
1659 if (negateBase
& 0x4)
1661 s
[i
++] = swz
[GET_SWZ(swizzle
, 2)];
1667 if (negateBase
& 0x8)
1669 s
[i
++] = swz
[GET_SWZ(swizzle
, 3)];
1677 writemask_string(GLuint writeMask
)
1682 if (writeMask
== WRITEMASK_XYZW
)
1686 if (writeMask
& WRITEMASK_X
)
1688 if (writeMask
& WRITEMASK_Y
)
1690 if (writeMask
& WRITEMASK_Z
)
1692 if (writeMask
& WRITEMASK_W
)
1700 print_dst_reg(const struct prog_dst_register
*dstReg
)
1702 _mesa_printf(" %s[%d]%s",
1703 program_file_string((enum register_file
) dstReg
->File
),
1705 writemask_string(dstReg
->WriteMask
));
1709 print_src_reg(const struct prog_src_register
*srcReg
)
1711 _mesa_printf("%s[%d]%s",
1712 program_file_string((enum register_file
) srcReg
->File
),
1714 swizzle_string(srcReg
->Swizzle
,
1715 srcReg
->NegateBase
, GL_FALSE
));
1719 _mesa_print_alu_instruction(const struct prog_instruction
*inst
,
1720 const char *opcode_string
,
1725 _mesa_printf("%s", opcode_string
);
1727 /* frag prog only */
1728 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
1729 _mesa_printf("_SAT");
1731 if (inst
->DstReg
.File
!= PROGRAM_UNDEFINED
) {
1732 _mesa_printf(" %s[%d]%s",
1733 program_file_string((enum register_file
) inst
->DstReg
.File
),
1735 writemask_string(inst
->DstReg
.WriteMask
));
1741 for (j
= 0; j
< numRegs
; j
++) {
1742 print_src_reg(inst
->SrcReg
+ j
);
1743 if (j
+ 1 < numRegs
)
1747 _mesa_printf(";\n");
1752 * Print a single vertex/fragment program instruction.
1755 _mesa_print_instruction(const struct prog_instruction
*inst
)
1757 switch (inst
->Opcode
) {
1759 _mesa_printf("PRINT '%s'", inst
->Data
);
1760 if (inst
->SrcReg
[0].File
!= PROGRAM_UNDEFINED
) {
1762 _mesa_printf("%s[%d]%s",
1763 program_file_string((enum register_file
) inst
->SrcReg
[0].File
),
1764 inst
->SrcReg
[0].Index
,
1765 swizzle_string(inst
->SrcReg
[0].Swizzle
,
1766 inst
->SrcReg
[0].NegateBase
, GL_FALSE
));
1768 _mesa_printf(";\n");
1771 _mesa_printf("SWZ");
1772 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
1773 _mesa_printf("_SAT");
1774 print_dst_reg(&inst
->DstReg
);
1775 _mesa_printf("%s[%d], %s;\n",
1776 program_file_string((enum register_file
) inst
->SrcReg
[0].File
),
1777 inst
->SrcReg
[0].Index
,
1778 swizzle_string(inst
->SrcReg
[0].Swizzle
,
1779 inst
->SrcReg
[0].NegateBase
, GL_TRUE
));
1784 _mesa_printf("%s", _mesa_opcode_string(inst
->Opcode
));
1785 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
1786 _mesa_printf("_SAT");
1788 print_dst_reg(&inst
->DstReg
);
1790 print_src_reg(&inst
->SrcReg
[0]);
1791 _mesa_printf(", texture[%d], ", inst
->TexSrcUnit
);
1792 switch (inst
->TexSrcTarget
) {
1793 case TEXTURE_1D_INDEX
: _mesa_printf("1D"); break;
1794 case TEXTURE_2D_INDEX
: _mesa_printf("2D"); break;
1795 case TEXTURE_3D_INDEX
: _mesa_printf("3D"); break;
1796 case TEXTURE_CUBE_INDEX
: _mesa_printf("CUBE"); break;
1797 case TEXTURE_RECT_INDEX
: _mesa_printf("RECT"); break;
1804 _mesa_printf("ARL addr.x, ");
1805 print_src_reg(&inst
->SrcReg
[0]);
1806 _mesa_printf(";\n");
1809 _mesa_printf("END;\n");
1811 /* XXX may need for other special-case instructions */
1813 /* typical alu instruction */
1814 _mesa_print_alu_instruction(inst
,
1815 _mesa_opcode_string(inst
->Opcode
),
1816 _mesa_num_inst_src_regs(inst
->Opcode
));
1823 * Print a vertx/fragment program to stdout.
1824 * XXX this function could be greatly improved.
1827 _mesa_print_program(const struct gl_program
*prog
)
1830 for (i
= 0; i
< prog
->NumInstructions
; i
++) {
1831 _mesa_printf("%3d: ", i
);
1832 _mesa_print_instruction(prog
->Instructions
+ i
);
1838 * Print all of a program's parameters.
1841 _mesa_print_program_parameters(GLcontext
*ctx
, const struct gl_program
*prog
)
1845 _mesa_printf("NumInstructions=%d\n", prog
->NumInstructions
);
1846 _mesa_printf("NumTemporaries=%d\n", prog
->NumTemporaries
);
1847 _mesa_printf("NumParameters=%d\n", prog
->NumParameters
);
1848 _mesa_printf("NumAttributes=%d\n", prog
->NumAttributes
);
1849 _mesa_printf("NumAddressRegs=%d\n", prog
->NumAddressRegs
);
1851 _mesa_load_state_parameters(ctx
, prog
->Parameters
);
1854 _mesa_printf("Local Params:\n");
1855 for (i
= 0; i
< MAX_PROGRAM_LOCAL_PARAMS
; i
++){
1856 const GLfloat
*p
= prog
->LocalParams
[i
];
1857 _mesa_printf("%2d: %f, %f, %f, %f\n", i
, p
[0], p
[1], p
[2], p
[3]);
1861 for (i
= 0; i
< prog
->Parameters
->NumParameters
; i
++){
1862 struct gl_program_parameter
*param
= prog
->Parameters
->Parameters
+ i
;
1863 const GLfloat
*v
= prog
->Parameters
->ParameterValues
[i
];
1864 _mesa_printf("param[%d] %s = {%.3f, %.3f, %.3f, %.3f};\n",
1865 i
, param
->Name
, v
[0], v
[1], v
[2], v
[3]);
1871 * Mixing ARB and NV vertex/fragment programs can be tricky.
1872 * Note: GL_VERTEX_PROGRAM_ARB == GL_VERTEX_PROGRAM_NV
1873 * but, GL_FRAGMENT_PROGRAM_ARB != GL_FRAGMENT_PROGRAM_NV
1874 * The two different fragment program targets are supposed to be compatible
1875 * to some extent (see GL_ARB_fragment_program spec).
1876 * This function does the compatibility check.
1879 compatible_program_targets(GLenum t1
, GLenum t2
)
1883 if (t1
== GL_FRAGMENT_PROGRAM_ARB
&& t2
== GL_FRAGMENT_PROGRAM_NV
)
1885 if (t1
== GL_FRAGMENT_PROGRAM_NV
&& t2
== GL_FRAGMENT_PROGRAM_ARB
)
1892 /**********************************************************************/
1894 /**********************************************************************/
1898 * Bind a program (make it current)
1899 * \note Called from the GL API dispatcher by both glBindProgramNV
1900 * and glBindProgramARB.
1903 _mesa_BindProgram(GLenum target
, GLuint id
)
1905 struct gl_program
*curProg
, *newProg
;
1906 GET_CURRENT_CONTEXT(ctx
);
1907 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1909 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
1911 /* Error-check target and get curProg */
1912 if ((target
== GL_VERTEX_PROGRAM_ARB
) && /* == GL_VERTEX_PROGRAM_NV */
1913 (ctx
->Extensions
.NV_vertex_program
||
1914 ctx
->Extensions
.ARB_vertex_program
)) {
1915 curProg
= &ctx
->VertexProgram
.Current
->Base
;
1917 else if ((target
== GL_FRAGMENT_PROGRAM_NV
1918 && ctx
->Extensions
.NV_fragment_program
) ||
1919 (target
== GL_FRAGMENT_PROGRAM_ARB
1920 && ctx
->Extensions
.ARB_fragment_program
)) {
1921 curProg
= &ctx
->FragmentProgram
.Current
->Base
;
1924 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindProgramNV/ARB(target)");
1929 * Get pointer to new program to bind.
1930 * NOTE: binding to a non-existant program is not an error.
1931 * That's supposed to be caught in glBegin.
1934 /* Bind a default program */
1936 if (target
== GL_VERTEX_PROGRAM_ARB
) /* == GL_VERTEX_PROGRAM_NV */
1937 newProg
= ctx
->Shared
->DefaultVertexProgram
;
1939 newProg
= ctx
->Shared
->DefaultFragmentProgram
;
1942 /* Bind a user program */
1943 newProg
= _mesa_lookup_program(ctx
, id
);
1944 if (!newProg
|| newProg
== &_mesa_DummyProgram
) {
1945 /* allocate a new program now */
1946 newProg
= ctx
->Driver
.NewProgram(ctx
, target
, id
);
1948 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindProgramNV/ARB");
1951 _mesa_HashInsert(ctx
->Shared
->Programs
, id
, newProg
);
1953 else if (!compatible_program_targets(newProg
->Target
, target
)) {
1954 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1955 "glBindProgramNV/ARB(target mismatch)");
1960 /** All error checking is complete now **/
1962 if (curProg
->Id
== id
) {
1963 /* binding same program - no change */
1967 /* unbind/delete oldProg */
1968 if (curProg
->Id
!= 0) {
1969 /* decrement refcount on previously bound fragment program */
1970 curProg
->RefCount
--;
1971 /* and delete if refcount goes below one */
1972 if (curProg
->RefCount
<= 0) {
1973 /* the program ID was already removed from the hash table */
1974 ctx
->Driver
.DeleteProgram(ctx
, curProg
);
1979 if (target
== GL_VERTEX_PROGRAM_ARB
) { /* == GL_VERTEX_PROGRAM_NV */
1980 if (ctx
->VertexProgram
._Current
== ctx
->VertexProgram
.Current
)
1981 ctx
->VertexProgram
._Current
= (struct gl_vertex_program
*) newProg
;
1982 ctx
->VertexProgram
.Current
= (struct gl_vertex_program
*) newProg
;
1984 else if (target
== GL_FRAGMENT_PROGRAM_NV
||
1985 target
== GL_FRAGMENT_PROGRAM_ARB
) {
1986 if (ctx
->FragmentProgram
._Current
== ctx
->FragmentProgram
.Current
)
1987 ctx
->FragmentProgram
._Current
= (struct gl_fragment_program
*) newProg
;
1988 ctx
->FragmentProgram
.Current
= (struct gl_fragment_program
*) newProg
;
1990 newProg
->RefCount
++;
1992 /* Never null pointers */
1993 ASSERT(ctx
->VertexProgram
.Current
);
1994 ASSERT(ctx
->FragmentProgram
.Current
);
1996 if (ctx
->Driver
.BindProgram
)
1997 ctx
->Driver
.BindProgram(ctx
, target
, newProg
);
2002 * Delete a list of programs.
2003 * \note Not compiled into display lists.
2004 * \note Called by both glDeleteProgramsNV and glDeleteProgramsARB.
2007 _mesa_DeletePrograms(GLsizei n
, const GLuint
*ids
)
2010 GET_CURRENT_CONTEXT(ctx
);
2011 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2014 _mesa_error( ctx
, GL_INVALID_VALUE
, "glDeleteProgramsNV" );
2018 for (i
= 0; i
< n
; i
++) {
2020 struct gl_program
*prog
= _mesa_lookup_program(ctx
, ids
[i
]);
2021 if (prog
== &_mesa_DummyProgram
) {
2022 _mesa_HashRemove(ctx
->Shared
->Programs
, ids
[i
]);
2025 /* Unbind program if necessary */
2026 if (prog
->Target
== GL_VERTEX_PROGRAM_ARB
|| /* == GL_VERTEX_PROGRAM_NV */
2027 prog
->Target
== GL_VERTEX_STATE_PROGRAM_NV
) {
2028 if (ctx
->VertexProgram
.Current
&&
2029 ctx
->VertexProgram
.Current
->Base
.Id
== ids
[i
]) {
2030 /* unbind this currently bound program */
2031 _mesa_BindProgram(prog
->Target
, 0);
2034 else if (prog
->Target
== GL_FRAGMENT_PROGRAM_NV
||
2035 prog
->Target
== GL_FRAGMENT_PROGRAM_ARB
) {
2036 if (ctx
->FragmentProgram
.Current
&&
2037 ctx
->FragmentProgram
.Current
->Base
.Id
== ids
[i
]) {
2038 /* unbind this currently bound program */
2039 _mesa_BindProgram(prog
->Target
, 0);
2043 _mesa_problem(ctx
, "bad target in glDeleteProgramsNV");
2046 /* The ID is immediately available for re-use now */
2047 _mesa_HashRemove(ctx
->Shared
->Programs
, ids
[i
]);
2049 if (prog
->RefCount
<= 0) {
2050 ctx
->Driver
.DeleteProgram(ctx
, prog
);
2059 * Generate a list of new program identifiers.
2060 * \note Not compiled into display lists.
2061 * \note Called by both glGenProgramsNV and glGenProgramsARB.
2064 _mesa_GenPrograms(GLsizei n
, GLuint
*ids
)
2068 GET_CURRENT_CONTEXT(ctx
);
2069 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2072 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenPrograms");
2079 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->Programs
, n
);
2081 /* Insert pointer to dummy program as placeholder */
2082 for (i
= 0; i
< (GLuint
) n
; i
++) {
2083 _mesa_HashInsert(ctx
->Shared
->Programs
, first
+ i
, &_mesa_DummyProgram
);
2086 /* Return the program names */
2087 for (i
= 0; i
< (GLuint
) n
; i
++) {
2093 /**********************************************************************/
2094 /* GL_MESA_program_debug extension */
2095 /**********************************************************************/
2099 GLAPI
void GLAPIENTRY
2100 glProgramCallbackMESA(GLenum target
, GLprogramcallbackMESA callback
,
2103 _mesa_ProgramCallbackMESA(target
, callback
, data
);
2108 _mesa_ProgramCallbackMESA(GLenum target
, GLprogramcallbackMESA callback
,
2111 GET_CURRENT_CONTEXT(ctx
);
2114 case GL_FRAGMENT_PROGRAM_ARB
:
2115 if (!ctx
->Extensions
.ARB_fragment_program
) {
2116 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramCallbackMESA(target)");
2119 ctx
->FragmentProgram
.Callback
= callback
;
2120 ctx
->FragmentProgram
.CallbackData
= data
;
2122 case GL_FRAGMENT_PROGRAM_NV
:
2123 if (!ctx
->Extensions
.NV_fragment_program
) {
2124 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramCallbackMESA(target)");
2127 ctx
->FragmentProgram
.Callback
= callback
;
2128 ctx
->FragmentProgram
.CallbackData
= data
;
2130 case GL_VERTEX_PROGRAM_ARB
: /* == GL_VERTEX_PROGRAM_NV */
2131 if (!ctx
->Extensions
.ARB_vertex_program
&&
2132 !ctx
->Extensions
.NV_vertex_program
) {
2133 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramCallbackMESA(target)");
2136 ctx
->VertexProgram
.Callback
= callback
;
2137 ctx
->VertexProgram
.CallbackData
= data
;
2140 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramCallbackMESA(target)");
2147 GLAPI
void GLAPIENTRY
2148 glGetProgramRegisterfvMESA(GLenum target
,
2149 GLsizei len
, const GLubyte
*registerName
,
2152 _mesa_GetProgramRegisterfvMESA(target
, len
, registerName
, v
);
2157 _mesa_GetProgramRegisterfvMESA(GLenum target
,
2158 GLsizei len
, const GLubyte
*registerName
,
2162 GET_CURRENT_CONTEXT(ctx
);
2164 /* We _should_ be inside glBegin/glEnd */
2166 if (ctx
->Driver
.CurrentExecPrimitive
== PRIM_OUTSIDE_BEGIN_END
) {
2167 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetProgramRegisterfvMESA");
2172 /* make null-terminated copy of registerName */
2173 len
= MIN2((unsigned int) len
, sizeof(reg
) - 1);
2174 _mesa_memcpy(reg
, registerName
, len
);
2178 case GL_VERTEX_PROGRAM_ARB
: /* == GL_VERTEX_PROGRAM_NV */
2179 if (!ctx
->Extensions
.ARB_vertex_program
&&
2180 !ctx
->Extensions
.NV_vertex_program
) {
2181 _mesa_error(ctx
, GL_INVALID_ENUM
,
2182 "glGetProgramRegisterfvMESA(target)");
2185 if (!ctx
->VertexProgram
._Enabled
) {
2186 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2187 "glGetProgramRegisterfvMESA");
2190 /* GL_NV_vertex_program */
2191 if (reg
[0] == 'R') {
2193 GLint i
= _mesa_atoi(reg
+ 1);
2194 if (i
>= (GLint
)ctx
->Const
.VertexProgram
.MaxTemps
) {
2195 _mesa_error(ctx
, GL_INVALID_VALUE
,
2196 "glGetProgramRegisterfvMESA(registerName)");
2200 ctx
->Driver
.GetVertexProgramRegister(ctx
, PROGRAM_TEMPORARY
, i
, v
);
2203 else if (reg
[0] == 'v' && reg
[1] == '[') {
2204 /* Vertex Input attribute */
2206 for (i
= 0; i
< ctx
->Const
.VertexProgram
.MaxAttribs
; i
++) {
2207 const char *name
= _mesa_nv_vertex_input_register_name(i
);
2209 _mesa_sprintf(number
, "%d", i
);
2210 if (_mesa_strncmp(reg
+ 2, name
, 4) == 0 ||
2211 _mesa_strncmp(reg
+ 2, number
, _mesa_strlen(number
)) == 0) {
2213 ctx
->Driver
.GetVertexProgramRegister(ctx
, PROGRAM_INPUT
,
2219 _mesa_error(ctx
, GL_INVALID_VALUE
,
2220 "glGetProgramRegisterfvMESA(registerName)");
2223 else if (reg
[0] == 'o' && reg
[1] == '[') {
2224 /* Vertex output attribute */
2226 /* GL_ARB_vertex_program */
2227 else if (_mesa_strncmp(reg
, "vertex.", 7) == 0) {
2231 _mesa_error(ctx
, GL_INVALID_VALUE
,
2232 "glGetProgramRegisterfvMESA(registerName)");
2236 case GL_FRAGMENT_PROGRAM_ARB
:
2237 if (!ctx
->Extensions
.ARB_fragment_program
) {
2238 _mesa_error(ctx
, GL_INVALID_ENUM
,
2239 "glGetProgramRegisterfvMESA(target)");
2242 if (!ctx
->FragmentProgram
._Enabled
) {
2243 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2244 "glGetProgramRegisterfvMESA");
2249 case GL_FRAGMENT_PROGRAM_NV
:
2250 if (!ctx
->Extensions
.NV_fragment_program
) {
2251 _mesa_error(ctx
, GL_INVALID_ENUM
,
2252 "glGetProgramRegisterfvMESA(target)");
2255 if (!ctx
->FragmentProgram
._Enabled
) {
2256 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2257 "glGetProgramRegisterfvMESA");
2260 if (reg
[0] == 'R') {
2262 GLint i
= _mesa_atoi(reg
+ 1);
2263 if (i
>= (GLint
)ctx
->Const
.FragmentProgram
.MaxTemps
) {
2264 _mesa_error(ctx
, GL_INVALID_VALUE
,
2265 "glGetProgramRegisterfvMESA(registerName)");
2268 ctx
->Driver
.GetFragmentProgramRegister(ctx
, PROGRAM_TEMPORARY
,
2271 else if (reg
[0] == 'f' && reg
[1] == '[') {
2272 /* Fragment input attribute */
2274 for (i
= 0; i
< ctx
->Const
.FragmentProgram
.MaxAttribs
; i
++) {
2275 const char *name
= _mesa_nv_fragment_input_register_name(i
);
2276 if (_mesa_strncmp(reg
+ 2, name
, 4) == 0) {
2277 ctx
->Driver
.GetFragmentProgramRegister(ctx
,
2278 PROGRAM_INPUT
, i
, v
);
2282 _mesa_error(ctx
, GL_INVALID_VALUE
,
2283 "glGetProgramRegisterfvMESA(registerName)");
2286 else if (_mesa_strcmp(reg
, "o[COLR]") == 0) {
2287 /* Fragment output color */
2288 ctx
->Driver
.GetFragmentProgramRegister(ctx
, PROGRAM_OUTPUT
,
2289 FRAG_RESULT_COLR
, v
);
2291 else if (_mesa_strcmp(reg
, "o[COLH]") == 0) {
2292 /* Fragment output color */
2293 ctx
->Driver
.GetFragmentProgramRegister(ctx
, PROGRAM_OUTPUT
,
2294 FRAG_RESULT_COLH
, v
);
2296 else if (_mesa_strcmp(reg
, "o[DEPR]") == 0) {
2297 /* Fragment output depth */
2298 ctx
->Driver
.GetFragmentProgramRegister(ctx
, PROGRAM_OUTPUT
,
2299 FRAG_RESULT_DEPR
, v
);
2302 /* try user-defined identifiers */
2303 const GLfloat
*value
= _mesa_lookup_parameter_value(
2304 ctx
->FragmentProgram
.Current
->Base
.Parameters
, -1, reg
);
2309 _mesa_error(ctx
, GL_INVALID_VALUE
,
2310 "glGetProgramRegisterfvMESA(registerName)");
2316 _mesa_error(ctx
, GL_INVALID_ENUM
,
2317 "glGetProgramRegisterfvMESA(target)");