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
)
206 _mesa_bzero(prog
, sizeof(*prog
));
208 prog
->Target
= target
;
209 prog
->Resident
= GL_TRUE
;
211 prog
->Format
= GL_PROGRAM_FORMAT_ASCII_ARB
;
219 * Initialize a new fragment program object.
222 _mesa_init_fragment_program( GLcontext
*ctx
, struct gl_fragment_program
*prog
,
223 GLenum target
, GLuint id
)
226 return _mesa_init_program_struct( ctx
, &prog
->Base
, target
, id
);
233 * Initialize a new vertex program object.
236 _mesa_init_vertex_program( GLcontext
*ctx
, struct gl_vertex_program
*prog
,
237 GLenum target
, GLuint id
)
240 return _mesa_init_program_struct( ctx
, &prog
->Base
, target
, id
);
247 * Allocate and initialize a new fragment/vertex program object but
248 * don't put it into the program hash table. Called via
249 * ctx->Driver.NewProgram. May be overridden (ie. replaced) by a
250 * device driver function to implement OO deriviation with additional
251 * types not understood by this function.
254 * \param id program id/number
255 * \param target program target/type
256 * \return pointer to new program object
259 _mesa_new_program(GLcontext
*ctx
, GLenum target
, GLuint id
)
262 case GL_VERTEX_PROGRAM_ARB
: /* == GL_VERTEX_PROGRAM_NV */
263 return _mesa_init_vertex_program(ctx
, CALLOC_STRUCT(gl_vertex_program
),
265 case GL_FRAGMENT_PROGRAM_NV
:
266 case GL_FRAGMENT_PROGRAM_ARB
:
267 return _mesa_init_fragment_program(ctx
,
268 CALLOC_STRUCT(gl_fragment_program
),
271 _mesa_problem(ctx
, "bad target in _mesa_new_program");
278 * Delete a program and remove it from the hash table, ignoring the
280 * Called via ctx->Driver.DeleteProgram. May be wrapped (OO deriviation)
281 * by a device driver function.
284 _mesa_delete_program(GLcontext
*ctx
, struct gl_program
*prog
)
289 if (prog
== &_mesa_DummyProgram
)
293 _mesa_free(prog
->String
);
295 if (prog
->Instructions
) {
297 for (i
= 0; i
< prog
->NumInstructions
; i
++) {
298 if (prog
->Instructions
[i
].Data
)
299 _mesa_free(prog
->Instructions
[i
].Data
);
301 _mesa_free(prog
->Instructions
);
304 if (prog
->Parameters
) {
305 _mesa_free_parameter_list(prog
->Parameters
);
309 _mesa_free_parameter_list(prog
->Varying
);
312 /* XXX this is a little ugly */
313 if (prog
->Target
== GL_VERTEX_PROGRAM_ARB
) {
314 struct gl_vertex_program
*vprog
= (struct gl_vertex_program
*) prog
;
316 _mesa_free(vprog
->TnlData
);
324 * Return the gl_program object for a given ID.
325 * Basically just a wrapper for _mesa_HashLookup() to avoid a lot of
329 _mesa_lookup_program(GLcontext
*ctx
, GLuint id
)
332 return (struct gl_program
*) _mesa_HashLookup(ctx
->Shared
->Programs
, id
);
338 /**********************************************************************/
339 /* Program parameter functions */
340 /**********************************************************************/
342 struct gl_program_parameter_list
*
343 _mesa_new_parameter_list(void)
345 return (struct gl_program_parameter_list
*)
346 _mesa_calloc(sizeof(struct gl_program_parameter_list
));
351 * Free a parameter list and all its parameters
354 _mesa_free_parameter_list(struct gl_program_parameter_list
*paramList
)
357 for (i
= 0; i
< paramList
->NumParameters
; i
++) {
358 if (paramList
->Parameters
[i
].Name
)
359 _mesa_free((void *) paramList
->Parameters
[i
].Name
);
361 _mesa_free(paramList
->Parameters
);
362 if (paramList
->ParameterValues
)
363 _mesa_align_free(paramList
->ParameterValues
);
364 _mesa_free(paramList
);
369 * Add a new parameter to a parameter list.
370 * \param paramList the list to add the parameter to
371 * \param name the parameter name, will be duplicated/copied!
372 * \param values initial parameter value, up to 4 GLfloats
373 * \param size number of elements in 'values' vector (1..4)
374 * \param type type of parameter, such as
375 * \return index of new parameter in the list, or -1 if error (out of mem)
378 add_parameter(struct gl_program_parameter_list
*paramList
,
379 const char *name
, const GLfloat values
[4], GLuint size
,
380 enum register_file type
)
382 const GLuint n
= paramList
->NumParameters
;
384 if (n
== paramList
->Size
) {
385 /* Need to grow the parameter list array */
386 if (paramList
->Size
== 0)
389 paramList
->Size
*= 2;
392 paramList
->Parameters
= (struct gl_program_parameter
*)
393 _mesa_realloc(paramList
->Parameters
,
394 n
* sizeof(struct gl_program_parameter
),
395 paramList
->Size
* sizeof(struct gl_program_parameter
));
397 paramList
->ParameterValues
= (GLfloat (*)[4])
398 _mesa_align_realloc(paramList
->ParameterValues
, /* old buf */
399 n
* 4 * sizeof(GLfloat
), /* old size */
400 paramList
->Size
* 4 *sizeof(GLfloat
), /* new sz */
404 if (!paramList
->Parameters
||
405 !paramList
->ParameterValues
) {
407 paramList
->NumParameters
= 0;
412 paramList
->NumParameters
= n
+ 1;
414 _mesa_memset(¶mList
->Parameters
[n
], 0,
415 sizeof(struct gl_program_parameter
));
417 paramList
->Parameters
[n
].Name
= name
? _mesa_strdup(name
) : NULL
;
418 paramList
->Parameters
[n
].Type
= type
;
420 COPY_4V(paramList
->ParameterValues
[n
], values
);
427 * Add a new named program parameter (Ex: NV_fragment_program DEFINE statement)
428 * \return index of the new entry in the parameter list
431 _mesa_add_named_parameter(struct gl_program_parameter_list
*paramList
,
432 const char *name
, const GLfloat values
[4])
434 return add_parameter(paramList
, name
, values
, 4, PROGRAM_NAMED_PARAM
);
439 * Add a new named constant to the parameter list.
440 * This will be used when the program contains something like this:
441 * PARAM myVals = { 0, 1, 2, 3 };
443 * \param paramList the parameter list
444 * \param name the name for the constant
445 * \param values four float values
446 * \return index/position of the new parameter in the parameter list
449 _mesa_add_named_constant(struct gl_program_parameter_list
*paramList
,
450 const char *name
, const GLfloat values
[4],
453 #if 0 /* disable this for now -- we need to save the name! */
456 ASSERT(size
== 4); /* XXX future feature */
457 /* check if we already have this constant */
458 if (_mesa_lookup_parameter_constant(paramList
, values
, 4, &pos
, &swizzle
)) {
462 size
= 4; /** XXX fix */
463 return add_parameter(paramList
, name
, values
, size
, PROGRAM_CONSTANT
);
468 * Add a new unnamed constant to the parameter list.
469 * This will be used when the program contains something like this:
470 * MOV r, { 0, 1, 2, 3 };
472 * \param paramList the parameter list
473 * \param values four float values
474 * \param swizzleOut returns swizzle mask for accessing the constant
475 * \return index/position of the new parameter in the parameter list.
478 _mesa_add_unnamed_constant(struct gl_program_parameter_list
*paramList
,
479 const GLfloat values
[4], GLuint size
,
486 size
= 4; /* XXX temporary */
487 /* check if we already have this constant */
488 if (_mesa_lookup_parameter_constant(paramList
, values
,
489 size
, &pos
, &swizzle
)) {
492 return add_parameter(paramList
, NULL
, values
, size
, PROGRAM_CONSTANT
);
497 _mesa_add_uniform(struct gl_program_parameter_list
*paramList
,
498 const char *name
, GLuint size
)
500 GLint i
= _mesa_lookup_parameter_index(paramList
, -1, name
);
501 if (i
>= 0 && paramList
->Parameters
[i
].Type
== PROGRAM_UNIFORM
) {
502 /* already in list */
507 i
= add_parameter(paramList
, name
, NULL
, size
, PROGRAM_UNIFORM
);
514 _mesa_add_varying(struct gl_program_parameter_list
*paramList
,
515 const char *name
, GLuint size
)
517 GLint i
= _mesa_lookup_parameter_index(paramList
, -1, name
);
518 if (i
>= 0 && paramList
->Parameters
[i
].Type
== PROGRAM_VARYING
) {
519 /* already in list */
524 i
= add_parameter(paramList
, name
, NULL
, size
, PROGRAM_VARYING
);
532 #if 0 /* not used yet */
534 * Returns the number of 4-component registers needed to store a piece
535 * of GL state. For matrices this may be as many as 4 registers,
536 * everything else needs
540 sizeof_state_reference(const GLint
*stateTokens
)
542 if (stateTokens
[0] == STATE_MATRIX
) {
543 GLuint rows
= stateTokens
[4] - stateTokens
[3] + 1;
556 * Add a new state reference to the parameter list.
557 * This will be used when the program contains something like this:
558 * PARAM ambient = state.material.front.ambient;
560 * \param paramList the parameter list
561 * \param state an array of 6 state tokens
562 * \return index of the new parameter.
565 _mesa_add_state_reference(struct gl_program_parameter_list
*paramList
,
566 const GLint
*stateTokens
)
568 const GLuint size
= 4; /* XXX fix */
572 /* Check if the state reference is already in the list */
573 for (index
= 0; index
< paramList
->NumParameters
; index
++) {
575 for (i
= 0; i
< 6; i
++) {
576 if (paramList
->Parameters
[index
].StateIndexes
[i
] == stateTokens
[i
]) {
584 /* this state reference is already in the parameter list */
589 name
= make_state_string(stateTokens
);
590 index
= add_parameter(paramList
, name
, NULL
, size
, PROGRAM_STATE_VAR
);
593 for (i
= 0; i
< 6; i
++) {
594 paramList
->Parameters
[index
].StateIndexes
[i
]
595 = (gl_state_index
) stateTokens
[i
];
597 paramList
->StateFlags
|= make_state_flags(stateTokens
);
600 /* free name string here since we duplicated it in add_parameter() */
601 _mesa_free((void *) name
);
608 * Lookup a parameter value by name in the given parameter list.
609 * \return pointer to the float[4] values.
612 _mesa_lookup_parameter_value(const struct gl_program_parameter_list
*paramList
,
613 GLsizei nameLen
, const char *name
)
615 GLuint i
= _mesa_lookup_parameter_index(paramList
, nameLen
, name
);
619 return paramList
->ParameterValues
[i
];
624 * Given a program parameter name, find its position in the list of parameters.
625 * \param paramList the parameter list to search
626 * \param nameLen length of name (in chars).
627 * If length is negative, assume that name is null-terminated.
628 * \param name the name to search for
629 * \return index of parameter in the list.
632 _mesa_lookup_parameter_index(const struct gl_program_parameter_list
*paramList
,
633 GLsizei nameLen
, const char *name
)
641 /* name is null-terminated */
642 for (i
= 0; i
< (GLint
) paramList
->NumParameters
; i
++) {
643 if (paramList
->Parameters
[i
].Name
&&
644 _mesa_strcmp(paramList
->Parameters
[i
].Name
, name
) == 0)
649 /* name is not null-terminated, use nameLen */
650 for (i
= 0; i
< (GLint
) paramList
->NumParameters
; i
++) {
651 if (paramList
->Parameters
[i
].Name
&&
652 _mesa_strncmp(paramList
->Parameters
[i
].Name
, name
, nameLen
) == 0
653 && _mesa_strlen(paramList
->Parameters
[i
].Name
) == (size_t)nameLen
)
662 * Look for a float vector in the given parameter list. The float vector
663 * may be of length 1, 2, 3 or 4.
664 * \param paramList the parameter list to search
665 * \param v the float vector to search for
666 * \param size number of element in v
667 * \param posOut returns the position of the constant, if found
668 * \param swizzleOut returns a swizzle mask describing location of the
669 * vector elements if found
670 * \return GL_TRUE if found, GL_FALSE if not found
673 _mesa_lookup_parameter_constant(const struct gl_program_parameter_list
*paramList
,
674 const GLfloat v
[], GLsizei vSize
,
675 GLint
*posOut
, GLuint
*swizzleOut
)
685 for (i
= 0; i
< paramList
->NumParameters
; i
++) {
686 if (paramList
->Parameters
[i
].Type
== PROGRAM_CONSTANT
) {
687 const GLint maxShift
= 4 - vSize
;
689 for (shift
= 0; shift
<= maxShift
; shift
++) {
692 swizzle
[0] = swizzle
[1] = swizzle
[2] = swizzle
[3] = 0;
693 /* XXX we could do out-of-order swizzle matches too, someday */
694 for (j
= 0; j
< vSize
; j
++) {
695 assert(shift
+ j
< 4);
696 if (paramList
->ParameterValues
[i
][shift
+ j
] == v
[j
]) {
698 swizzle
[j
] = shift
+ j
;
699 ASSERT(swizzle
[j
] >= SWIZZLE_X
);
700 ASSERT(swizzle
[j
] <= SWIZZLE_W
);
703 if (matched
== vSize
) {
706 *swizzleOut
= MAKE_SWIZZLE4(swizzle
[0], swizzle
[1],
707 swizzle
[2], swizzle
[3]);
720 * Use the list of tokens in the state[] array to find global GL state
721 * and return it in <value>. Usually, four values are returned in <value>
722 * but matrix queries may return as many as 16 values.
723 * This function is used for ARB vertex/fragment programs.
724 * The program parser will produce the state[] values.
727 _mesa_fetch_state(GLcontext
*ctx
, const gl_state_index state
[],
733 /* state[1] is either 0=front or 1=back side */
734 const GLuint face
= (GLuint
) state
[1];
735 const struct gl_material
*mat
= &ctx
->Light
.Material
;
736 ASSERT(face
== 0 || face
== 1);
737 /* we rely on tokens numbered so that _BACK_ == _FRONT_+ 1 */
738 ASSERT(MAT_ATTRIB_FRONT_AMBIENT
+ 1 == MAT_ATTRIB_BACK_AMBIENT
);
739 /* XXX we could get rid of this switch entirely with a little
740 * work in arbprogparse.c's parse_state_single_item().
742 /* state[2] is the material attribute */
745 COPY_4V(value
, mat
->Attrib
[MAT_ATTRIB_FRONT_AMBIENT
+ face
]);
748 COPY_4V(value
, mat
->Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
+ face
]);
751 COPY_4V(value
, mat
->Attrib
[MAT_ATTRIB_FRONT_SPECULAR
+ face
]);
754 COPY_4V(value
, mat
->Attrib
[MAT_ATTRIB_FRONT_EMISSION
+ face
]);
756 case STATE_SHININESS
:
757 value
[0] = mat
->Attrib
[MAT_ATTRIB_FRONT_SHININESS
+ face
][0];
763 _mesa_problem(ctx
, "Invalid material state in fetch_state");
769 /* state[1] is the light number */
770 const GLuint ln
= (GLuint
) state
[1];
771 /* state[2] is the light attribute */
774 COPY_4V(value
, ctx
->Light
.Light
[ln
].Ambient
);
777 COPY_4V(value
, ctx
->Light
.Light
[ln
].Diffuse
);
780 COPY_4V(value
, ctx
->Light
.Light
[ln
].Specular
);
783 COPY_4V(value
, ctx
->Light
.Light
[ln
].EyePosition
);
785 case STATE_ATTENUATION
:
786 value
[0] = ctx
->Light
.Light
[ln
].ConstantAttenuation
;
787 value
[1] = ctx
->Light
.Light
[ln
].LinearAttenuation
;
788 value
[2] = ctx
->Light
.Light
[ln
].QuadraticAttenuation
;
789 value
[3] = ctx
->Light
.Light
[ln
].SpotExponent
;
791 case STATE_SPOT_DIRECTION
:
792 COPY_3V(value
, ctx
->Light
.Light
[ln
].EyeDirection
);
793 value
[3] = ctx
->Light
.Light
[ln
]._CosCutoff
;
797 GLfloat eye_z
[] = {0, 0, 1};
799 /* Compute infinite half angle vector:
800 * half-vector = light_position + (0, 0, 1)
801 * and then normalize. w = 0
803 * light.EyePosition.w should be 0 for infinite lights.
805 ADD_3V(value
, eye_z
, ctx
->Light
.Light
[ln
].EyePosition
);
806 NORMALIZE_3FV(value
);
810 case STATE_POSITION_NORMALIZED
:
811 COPY_4V(value
, ctx
->Light
.Light
[ln
].EyePosition
);
812 NORMALIZE_3FV( value
);
815 _mesa_problem(ctx
, "Invalid light state in fetch_state");
819 case STATE_LIGHTMODEL_AMBIENT
:
820 COPY_4V(value
, ctx
->Light
.Model
.Ambient
);
822 case STATE_LIGHTMODEL_SCENECOLOR
:
826 for (i
= 0; i
< 3; i
++) {
827 value
[i
] = ctx
->Light
.Model
.Ambient
[i
]
828 * ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_AMBIENT
][i
]
829 + ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_EMISSION
][i
];
831 value
[3] = ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
][3];
836 for (i
= 0; i
< 3; i
++) {
837 value
[i
] = ctx
->Light
.Model
.Ambient
[i
]
838 * ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_BACK_AMBIENT
][i
]
839 + ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_BACK_EMISSION
][i
];
841 value
[3] = ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_BACK_DIFFUSE
][3];
844 case STATE_LIGHTPROD
:
846 const GLuint ln
= (GLuint
) state
[1];
847 const GLuint face
= (GLuint
) state
[2];
849 ASSERT(face
== 0 || face
== 1);
852 for (i
= 0; i
< 3; i
++) {
853 value
[i
] = ctx
->Light
.Light
[ln
].Ambient
[i
] *
854 ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_AMBIENT
+face
][i
];
856 /* [3] = material alpha */
857 value
[3] = ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
+face
][3];
860 for (i
= 0; i
< 3; i
++) {
861 value
[i
] = ctx
->Light
.Light
[ln
].Diffuse
[i
] *
862 ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
+face
][i
];
864 /* [3] = material alpha */
865 value
[3] = ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
+face
][3];
868 for (i
= 0; i
< 3; i
++) {
869 value
[i
] = ctx
->Light
.Light
[ln
].Specular
[i
] *
870 ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_SPECULAR
+face
][i
];
872 /* [3] = material alpha */
873 value
[3] = ctx
->Light
.Material
.Attrib
[MAT_ATTRIB_FRONT_DIFFUSE
+face
][3];
876 _mesa_problem(ctx
, "Invalid lightprod state in fetch_state");
882 /* state[1] is the texture unit */
883 const GLuint unit
= (GLuint
) state
[1];
884 /* state[2] is the texgen attribute */
886 case STATE_TEXGEN_EYE_S
:
887 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].EyePlaneS
);
889 case STATE_TEXGEN_EYE_T
:
890 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].EyePlaneT
);
892 case STATE_TEXGEN_EYE_R
:
893 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].EyePlaneR
);
895 case STATE_TEXGEN_EYE_Q
:
896 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].EyePlaneQ
);
898 case STATE_TEXGEN_OBJECT_S
:
899 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].ObjectPlaneS
);
901 case STATE_TEXGEN_OBJECT_T
:
902 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].ObjectPlaneT
);
904 case STATE_TEXGEN_OBJECT_R
:
905 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].ObjectPlaneR
);
907 case STATE_TEXGEN_OBJECT_Q
:
908 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].ObjectPlaneQ
);
911 _mesa_problem(ctx
, "Invalid texgen state in fetch_state");
915 case STATE_TEXENV_COLOR
:
917 /* state[1] is the texture unit */
918 const GLuint unit
= (GLuint
) state
[1];
919 COPY_4V(value
, ctx
->Texture
.Unit
[unit
].EnvColor
);
922 case STATE_FOG_COLOR
:
923 COPY_4V(value
, ctx
->Fog
.Color
);
925 case STATE_FOG_PARAMS
:
926 value
[0] = ctx
->Fog
.Density
;
927 value
[1] = ctx
->Fog
.Start
;
928 value
[2] = ctx
->Fog
.End
;
929 value
[3] = 1.0F
/ (ctx
->Fog
.End
- ctx
->Fog
.Start
);
931 case STATE_CLIPPLANE
:
933 const GLuint plane
= (GLuint
) state
[1];
934 COPY_4V(value
, ctx
->Transform
.EyeUserPlane
[plane
]);
937 case STATE_POINT_SIZE
:
938 value
[0] = ctx
->Point
.Size
;
939 value
[1] = ctx
->Point
.MinSize
;
940 value
[2] = ctx
->Point
.MaxSize
;
941 value
[3] = ctx
->Point
.Threshold
;
943 case STATE_POINT_ATTENUATION
:
944 value
[0] = ctx
->Point
.Params
[0];
945 value
[1] = ctx
->Point
.Params
[1];
946 value
[2] = ctx
->Point
.Params
[2];
951 /* state[1] = modelview, projection, texture, etc. */
952 /* state[2] = which texture matrix or program matrix */
953 /* state[3] = first row to fetch */
954 /* state[4] = last row to fetch */
955 /* state[5] = transpose, inverse or invtrans */
957 const GLmatrix
*matrix
;
958 const gl_state_index mat
= state
[1];
959 const GLuint index
= (GLuint
) state
[2];
960 const GLuint firstRow
= (GLuint
) state
[3];
961 const GLuint lastRow
= (GLuint
) state
[4];
962 const gl_state_index modifier
= state
[5];
965 if (mat
== STATE_MODELVIEW
) {
966 matrix
= ctx
->ModelviewMatrixStack
.Top
;
968 else if (mat
== STATE_PROJECTION
) {
969 matrix
= ctx
->ProjectionMatrixStack
.Top
;
971 else if (mat
== STATE_MVP
) {
972 matrix
= &ctx
->_ModelProjectMatrix
;
974 else if (mat
== STATE_TEXTURE
) {
975 matrix
= ctx
->TextureMatrixStack
[index
].Top
;
977 else if (mat
== STATE_PROGRAM
) {
978 matrix
= ctx
->ProgramMatrixStack
[index
].Top
;
981 _mesa_problem(ctx
, "Bad matrix name in _mesa_fetch_state()");
984 if (modifier
== STATE_MATRIX_INVERSE
||
985 modifier
== STATE_MATRIX_INVTRANS
) {
986 /* Be sure inverse is up to date:
988 _math_matrix_alloc_inv( (GLmatrix
*) matrix
);
989 _math_matrix_analyse( (GLmatrix
*) matrix
);
995 if (modifier
== STATE_MATRIX_TRANSPOSE
||
996 modifier
== STATE_MATRIX_INVTRANS
) {
997 for (i
= 0, row
= firstRow
; row
<= lastRow
; row
++) {
998 value
[i
++] = m
[row
* 4 + 0];
999 value
[i
++] = m
[row
* 4 + 1];
1000 value
[i
++] = m
[row
* 4 + 2];
1001 value
[i
++] = m
[row
* 4 + 3];
1005 for (i
= 0, row
= firstRow
; row
<= lastRow
; row
++) {
1006 value
[i
++] = m
[row
+ 0];
1007 value
[i
++] = m
[row
+ 4];
1008 value
[i
++] = m
[row
+ 8];
1009 value
[i
++] = m
[row
+ 12];
1014 case STATE_DEPTH_RANGE
:
1015 value
[0] = ctx
->Viewport
.Near
; /* near */
1016 value
[1] = ctx
->Viewport
.Far
; /* far */
1017 value
[2] = ctx
->Viewport
.Far
- ctx
->Viewport
.Near
; /* far - near */
1020 case STATE_FRAGMENT_PROGRAM
:
1022 /* state[1] = {STATE_ENV, STATE_LOCAL} */
1023 /* state[2] = parameter index */
1024 const int idx
= (int) state
[2];
1027 COPY_4V(value
, ctx
->FragmentProgram
.Parameters
[idx
]);
1030 COPY_4V(value
, ctx
->FragmentProgram
.Current
->Base
.LocalParams
[idx
]);
1033 _mesa_problem(ctx
, "Bad state switch in _mesa_fetch_state()");
1039 case STATE_VERTEX_PROGRAM
:
1041 /* state[1] = {STATE_ENV, STATE_LOCAL} */
1042 /* state[2] = parameter index */
1043 const int idx
= (int) state
[2];
1046 COPY_4V(value
, ctx
->VertexProgram
.Parameters
[idx
]);
1049 COPY_4V(value
, ctx
->VertexProgram
.Current
->Base
.LocalParams
[idx
]);
1052 _mesa_problem(ctx
, "Bad state switch in _mesa_fetch_state()");
1058 case STATE_INTERNAL
:
1061 case STATE_NORMAL_SCALE
:
1062 ASSIGN_4V(value
, ctx
->_ModelViewInvScale
, 0, 0, 1);
1064 case STATE_TEXRECT_SCALE
: {
1065 const int unit
= (int) state
[2];
1066 const struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[unit
]._Current
;
1068 struct gl_texture_image
*texImage
= texObj
->Image
[0][0];
1069 ASSIGN_4V(value
, 1.0 / texImage
->Width
, 1.0 / texImage
->Height
, 0, 1);
1074 /* unknown state indexes are silently ignored
1075 * should be handled by the driver.
1083 _mesa_problem(ctx
, "Invalid state in _mesa_fetch_state");
1090 * Return a bitmask of the Mesa state flags (_NEW_* values) which would
1091 * indicate that the given context state may have changed.
1092 * The bitmask is used during validation to determine if we need to update
1093 * vertex/fragment program parameters (like "state.material.color") when
1094 * some GL state has changed.
1097 make_state_flags(const GLint state
[])
1100 case STATE_MATERIAL
:
1102 case STATE_LIGHTMODEL_AMBIENT
:
1103 case STATE_LIGHTMODEL_SCENECOLOR
:
1104 case STATE_LIGHTPROD
:
1108 case STATE_TEXENV_COLOR
:
1109 return _NEW_TEXTURE
;
1111 case STATE_FOG_COLOR
:
1112 case STATE_FOG_PARAMS
:
1115 case STATE_CLIPPLANE
:
1116 return _NEW_TRANSFORM
;
1118 case STATE_POINT_SIZE
:
1119 case STATE_POINT_ATTENUATION
:
1124 case STATE_MODELVIEW
:
1125 return _NEW_MODELVIEW
;
1126 case STATE_PROJECTION
:
1127 return _NEW_PROJECTION
;
1129 return _NEW_MODELVIEW
| _NEW_PROJECTION
;
1131 return _NEW_TEXTURE_MATRIX
;
1133 return _NEW_TRACK_MATRIX
;
1135 _mesa_problem(NULL
, "unexpected matrix in make_state_flags()");
1139 case STATE_DEPTH_RANGE
:
1140 return _NEW_VIEWPORT
;
1142 case STATE_FRAGMENT_PROGRAM
:
1143 case STATE_VERTEX_PROGRAM
:
1144 return _NEW_PROGRAM
;
1146 case STATE_INTERNAL
:
1148 case STATE_NORMAL_SCALE
:
1149 return _NEW_MODELVIEW
;
1150 case STATE_TEXRECT_SCALE
:
1151 return _NEW_TEXTURE
;
1153 /* unknown state indexes are silently ignored and
1154 * no flag set, since it is handled by the driver.
1160 _mesa_problem(NULL
, "unexpected state[0] in make_state_flags()");
1167 append(char *dst
, const char *src
)
1178 append_token(char *dst
, gl_state_index k
)
1181 case STATE_MATERIAL
:
1182 append(dst
, "material.");
1185 append(dst
, "light");
1187 case STATE_LIGHTMODEL_AMBIENT
:
1188 append(dst
, "lightmodel.ambient");
1190 case STATE_LIGHTMODEL_SCENECOLOR
:
1192 case STATE_LIGHTPROD
:
1193 append(dst
, "lightprod");
1196 append(dst
, "texgen");
1198 case STATE_FOG_COLOR
:
1199 append(dst
, "fog.color");
1201 case STATE_FOG_PARAMS
:
1202 append(dst
, "fog.params");
1204 case STATE_CLIPPLANE
:
1205 append(dst
, "clip");
1207 case STATE_POINT_SIZE
:
1208 append(dst
, "point.size");
1210 case STATE_POINT_ATTENUATION
:
1211 append(dst
, "point.attenuation");
1214 append(dst
, "matrix.");
1216 case STATE_MODELVIEW
:
1217 append(dst
, "modelview");
1219 case STATE_PROJECTION
:
1220 append(dst
, "projection");
1226 append(dst
, "texture");
1229 append(dst
, "program");
1231 case STATE_MATRIX_INVERSE
:
1232 append(dst
, ".inverse");
1234 case STATE_MATRIX_TRANSPOSE
:
1235 append(dst
, ".transpose");
1237 case STATE_MATRIX_INVTRANS
:
1238 append(dst
, ".invtrans");
1241 append(dst
, "ambient");
1244 append(dst
, "diffuse");
1246 case STATE_SPECULAR
:
1247 append(dst
, "specular");
1249 case STATE_EMISSION
:
1250 append(dst
, "emission");
1252 case STATE_SHININESS
:
1253 append(dst
, "shininess");
1256 append(dst
, "half");
1258 case STATE_POSITION
:
1259 append(dst
, ".position");
1261 case STATE_ATTENUATION
:
1262 append(dst
, ".attenuation");
1264 case STATE_SPOT_DIRECTION
:
1265 append(dst
, ".spot.direction");
1267 case STATE_TEXGEN_EYE_S
:
1268 append(dst
, "eye.s");
1270 case STATE_TEXGEN_EYE_T
:
1271 append(dst
, "eye.t");
1273 case STATE_TEXGEN_EYE_R
:
1274 append(dst
, "eye.r");
1276 case STATE_TEXGEN_EYE_Q
:
1277 append(dst
, "eye.q");
1279 case STATE_TEXGEN_OBJECT_S
:
1280 append(dst
, "object.s");
1282 case STATE_TEXGEN_OBJECT_T
:
1283 append(dst
, "object.t");
1285 case STATE_TEXGEN_OBJECT_R
:
1286 append(dst
, "object.r");
1288 case STATE_TEXGEN_OBJECT_Q
:
1289 append(dst
, "object.q");
1291 case STATE_TEXENV_COLOR
:
1292 append(dst
, "texenv");
1294 case STATE_DEPTH_RANGE
:
1295 append(dst
, "depth.range");
1297 case STATE_VERTEX_PROGRAM
:
1298 case STATE_FRAGMENT_PROGRAM
:
1304 append(dst
, "local");
1306 case STATE_INTERNAL
:
1307 case STATE_NORMAL_SCALE
:
1308 case STATE_POSITION_NORMALIZED
:
1309 append(dst
, "(internal)");
1317 append_face(char *dst
, GLint face
)
1320 append(dst
, "front.");
1322 append(dst
, "back.");
1326 append_index(char *dst
, GLint index
)
1329 _mesa_sprintf(s
, "[%d].", index
);
1334 * Make a string from the given state vector.
1335 * For example, return "state.matrix.texture[2].inverse".
1336 * Use _mesa_free() to deallocate the string.
1339 make_state_string(const GLint state
[6])
1341 char str
[1000] = "";
1344 append(str
, "state.");
1345 append_token(str
, (gl_state_index
) state
[0]);
1348 case STATE_MATERIAL
:
1349 append_face(str
, state
[1]);
1350 append_token(str
, (gl_state_index
) state
[2]);
1353 append(str
, "light");
1354 append_index(str
, state
[1]); /* light number [i]. */
1355 append_token(str
, (gl_state_index
) state
[2]); /* coefficients */
1357 case STATE_LIGHTMODEL_AMBIENT
:
1358 append(str
, "lightmodel.ambient");
1360 case STATE_LIGHTMODEL_SCENECOLOR
:
1361 if (state
[1] == 0) {
1362 append(str
, "lightmodel.front.scenecolor");
1365 append(str
, "lightmodel.back.scenecolor");
1368 case STATE_LIGHTPROD
:
1369 append_index(str
, state
[1]); /* light number [i]. */
1370 append_face(str
, state
[2]);
1371 append_token(str
, (gl_state_index
) state
[3]);
1374 append_index(str
, state
[1]); /* tex unit [i] */
1375 append_token(str
, (gl_state_index
) state
[2]); /* plane coef */
1377 case STATE_TEXENV_COLOR
:
1378 append_index(str
, state
[1]); /* tex unit [i] */
1379 append(str
, "color");
1381 case STATE_FOG_COLOR
:
1382 case STATE_FOG_PARAMS
:
1384 case STATE_CLIPPLANE
:
1385 append_index(str
, state
[1]); /* plane [i] */
1386 append(str
, "plane");
1388 case STATE_POINT_SIZE
:
1389 case STATE_POINT_ATTENUATION
:
1393 /* state[1] = modelview, projection, texture, etc. */
1394 /* state[2] = which texture matrix or program matrix */
1395 /* state[3] = first row to fetch */
1396 /* state[4] = last row to fetch */
1397 /* state[5] = transpose, inverse or invtrans */
1398 const gl_state_index mat
= (gl_state_index
) state
[1];
1399 const GLuint index
= (GLuint
) state
[2];
1400 const GLuint firstRow
= (GLuint
) state
[3];
1401 const GLuint lastRow
= (GLuint
) state
[4];
1402 const gl_state_index modifier
= (gl_state_index
) state
[5];
1403 append_token(str
, mat
);
1405 append_index(str
, index
);
1407 append_token(str
, modifier
);
1408 if (firstRow
== lastRow
)
1409 _mesa_sprintf(tmp
, ".row[%d]", firstRow
);
1411 _mesa_sprintf(tmp
, ".row[%d..%d]", firstRow
, lastRow
);
1415 case STATE_DEPTH_RANGE
:
1417 case STATE_FRAGMENT_PROGRAM
:
1418 case STATE_VERTEX_PROGRAM
:
1419 /* state[1] = {STATE_ENV, STATE_LOCAL} */
1420 /* state[2] = parameter index */
1421 append_token(str
, (gl_state_index
) state
[1]);
1422 append_index(str
, state
[2]);
1424 case STATE_INTERNAL
:
1427 _mesa_problem(NULL
, "Invalid state in make_state_string");
1431 return _mesa_strdup(str
);
1436 * Loop over all the parameters in a parameter list. If the parameter
1437 * is a GL state reference, look up the current value of that state
1438 * variable and put it into the parameter's Value[4] array.
1439 * This would be called at glBegin time when using a fragment program.
1442 _mesa_load_state_parameters(GLcontext
*ctx
,
1443 struct gl_program_parameter_list
*paramList
)
1450 for (i
= 0; i
< paramList
->NumParameters
; i
++) {
1451 if (paramList
->Parameters
[i
].Type
== PROGRAM_STATE_VAR
) {
1452 _mesa_fetch_state(ctx
,
1453 paramList
->Parameters
[i
].StateIndexes
,
1454 paramList
->ParameterValues
[i
]);
1461 * Initialize program instruction fields to defaults.
1462 * \param inst first instruction to initialize
1463 * \param count number of instructions to initialize
1466 _mesa_init_instructions(struct prog_instruction
*inst
, GLuint count
)
1470 _mesa_bzero(inst
, count
* sizeof(struct prog_instruction
));
1472 for (i
= 0; i
< count
; i
++) {
1473 inst
[i
].SrcReg
[0].File
= PROGRAM_UNDEFINED
;
1474 inst
[i
].SrcReg
[0].Swizzle
= SWIZZLE_NOOP
;
1475 inst
[i
].SrcReg
[1].File
= PROGRAM_UNDEFINED
;
1476 inst
[i
].SrcReg
[1].Swizzle
= SWIZZLE_NOOP
;
1477 inst
[i
].SrcReg
[2].File
= PROGRAM_UNDEFINED
;
1478 inst
[i
].SrcReg
[2].Swizzle
= SWIZZLE_NOOP
;
1480 inst
[i
].DstReg
.File
= PROGRAM_UNDEFINED
;
1481 inst
[i
].DstReg
.WriteMask
= WRITEMASK_XYZW
;
1482 inst
[i
].DstReg
.CondMask
= COND_TR
;
1483 inst
[i
].DstReg
.CondSwizzle
= SWIZZLE_NOOP
;
1485 inst
[i
].SaturateMode
= SATURATE_OFF
;
1486 inst
[i
].Precision
= FLOAT32
;
1492 * Allocate an array of program instructions.
1493 * \param numInst number of instructions
1494 * \return pointer to instruction memory
1496 struct prog_instruction
*
1497 _mesa_alloc_instructions(GLuint numInst
)
1499 return (struct prog_instruction
*)
1500 _mesa_calloc(numInst
* sizeof(struct prog_instruction
));
1505 * Reallocate memory storing an array of program instructions.
1506 * This is used when we need to append additional instructions onto an
1508 * \param oldInst pointer to first of old/src instructions
1509 * \param numOldInst number of instructions at <oldInst>
1510 * \param numNewInst desired size of new instruction array.
1511 * \return pointer to start of new instruction array.
1513 struct prog_instruction
*
1514 _mesa_realloc_instructions(struct prog_instruction
*oldInst
,
1515 GLuint numOldInst
, GLuint numNewInst
)
1517 struct prog_instruction
*newInst
;
1519 newInst
= (struct prog_instruction
*)
1520 _mesa_realloc(oldInst
,
1521 numOldInst
* sizeof(struct prog_instruction
),
1522 numNewInst
* sizeof(struct prog_instruction
));
1529 * Basic info about each instruction
1531 struct instruction_info
1533 gl_inst_opcode Opcode
;
1540 * \note Opcode should equal array index!
1542 static const struct instruction_info InstInfo
[MAX_OPCODE
] = {
1543 { OPCODE_NOP
, "NOP", 0 },
1544 { OPCODE_ABS
, "ABS", 1 },
1545 { OPCODE_ADD
, "ADD", 2 },
1546 { OPCODE_ARA
, "ARA", 1 },
1547 { OPCODE_ARL
, "ARL", 1 },
1548 { OPCODE_ARL_NV
, "ARL", 1 },
1549 { OPCODE_ARR
, "ARL", 1 },
1550 { OPCODE_BRA
, "BRA", 0 },
1551 { OPCODE_CAL
, "CAL", 0 },
1552 { OPCODE_CMP
, "CMP", 3 },
1553 { OPCODE_COS
, "COS", 1 },
1554 { OPCODE_DDX
, "DDX", 1 },
1555 { OPCODE_DDY
, "DDY", 1 },
1556 { OPCODE_DP3
, "DP3", 2 },
1557 { OPCODE_DP4
, "DP4", 2 },
1558 { OPCODE_DPH
, "DPH", 2 },
1559 { OPCODE_DST
, "DST", 2 },
1560 { OPCODE_END
, "END", 0 },
1561 { OPCODE_EX2
, "EX2", 1 },
1562 { OPCODE_EXP
, "EXP", 1 },
1563 { OPCODE_FLR
, "FLR", 1 },
1564 { OPCODE_FRC
, "FRC", 1 },
1565 { OPCODE_KIL
, "KIL", 1 },
1566 { OPCODE_KIL_NV
, "KIL", 0 },
1567 { OPCODE_LG2
, "LG2", 1 },
1568 { OPCODE_LIT
, "LIT", 1 },
1569 { OPCODE_LOG
, "LOG", 1 },
1570 { OPCODE_LRP
, "LRP", 3 },
1571 { OPCODE_MAD
, "MAD", 3 },
1572 { OPCODE_MAX
, "MAX", 2 },
1573 { OPCODE_MIN
, "MIN", 2 },
1574 { OPCODE_MOV
, "MOV", 1 },
1575 { OPCODE_MUL
, "MUL", 2 },
1576 { OPCODE_PK2H
, "PK2H", 1 },
1577 { OPCODE_PK2US
, "PK2US", 1 },
1578 { OPCODE_PK4B
, "PK4B", 1 },
1579 { OPCODE_PK4UB
, "PK4UB", 1 },
1580 { OPCODE_POW
, "POW", 2 },
1581 { OPCODE_POPA
, "POPA", 0 },
1582 { OPCODE_PRINT
, "PRINT", 1 },
1583 { OPCODE_PUSHA
, "PUSHA", 0 },
1584 { OPCODE_RCC
, "RCC", 1 },
1585 { OPCODE_RCP
, "RCP", 1 },
1586 { OPCODE_RET
, "RET", 0 },
1587 { OPCODE_RFL
, "RFL", 1 },
1588 { OPCODE_RSQ
, "RSQ", 1 },
1589 { OPCODE_SCS
, "SCS", 1 },
1590 { OPCODE_SEQ
, "SEQ", 2 },
1591 { OPCODE_SFL
, "SFL", 0 },
1592 { OPCODE_SGE
, "SGE", 2 },
1593 { OPCODE_SGT
, "SGT", 2 },
1594 { OPCODE_SIN
, "SIN", 1 },
1595 { OPCODE_SLE
, "SLE", 2 },
1596 { OPCODE_SLT
, "SLT", 2 },
1597 { OPCODE_SNE
, "SNE", 2 },
1598 { OPCODE_SSG
, "SSG", 1 },
1599 { OPCODE_STR
, "STR", 0 },
1600 { OPCODE_SUB
, "SUB", 2 },
1601 { OPCODE_SWZ
, "SWZ", 1 },
1602 { OPCODE_TEX
, "TEX", 1 },
1603 { OPCODE_TXB
, "TXB", 1 },
1604 { OPCODE_TXD
, "TXD", 3 },
1605 { OPCODE_TXL
, "TXL", 1 },
1606 { OPCODE_TXP
, "TXP", 1 },
1607 { OPCODE_TXP_NV
, "TXP", 1 },
1608 { OPCODE_UP2H
, "UP2H", 1 },
1609 { OPCODE_UP2US
, "UP2US", 1 },
1610 { OPCODE_UP4B
, "UP4B", 1 },
1611 { OPCODE_UP4UB
, "UP4UB", 1 },
1612 { OPCODE_X2D
, "X2D", 3 },
1613 { OPCODE_XPD
, "XPD", 2 }
1618 * Return the number of src registers for the given instruction/opcode.
1621 _mesa_num_inst_src_regs(gl_inst_opcode opcode
)
1623 ASSERT(opcode
== InstInfo
[opcode
].Opcode
);
1624 ASSERT(OPCODE_XPD
== InstInfo
[OPCODE_XPD
].Opcode
);
1625 return InstInfo
[opcode
].NumSrcRegs
;
1630 * Return string name for given program opcode.
1633 _mesa_opcode_string(gl_inst_opcode opcode
)
1635 ASSERT(opcode
< MAX_OPCODE
);
1636 return InstInfo
[opcode
].Name
;
1640 * Return string name for given program/register file.
1643 program_file_string(enum register_file f
)
1646 case PROGRAM_TEMPORARY
:
1648 case PROGRAM_LOCAL_PARAM
:
1650 case PROGRAM_ENV_PARAM
:
1652 case PROGRAM_STATE_VAR
:
1656 case PROGRAM_OUTPUT
:
1658 case PROGRAM_NAMED_PARAM
:
1660 case PROGRAM_CONSTANT
:
1662 case PROGRAM_UNIFORM
:
1664 case PROGRAM_VARYING
:
1666 case PROGRAM_WRITE_ONLY
:
1667 return "WRITE_ONLY";
1668 case PROGRAM_ADDRESS
:
1671 return "Unknown program file!";
1677 * Return a string representation of the given swizzle word.
1678 * If extended is true, use extended (comma-separated) format.
1681 swizzle_string(GLuint swizzle
, GLuint negateBase
, GLboolean extended
)
1683 static const char swz
[] = "xyzw01";
1687 if (!extended
&& swizzle
== SWIZZLE_NOOP
&& negateBase
== 0)
1688 return ""; /* no swizzle/negation */
1693 if (negateBase
& 0x1)
1695 s
[i
++] = swz
[GET_SWZ(swizzle
, 0)];
1701 if (negateBase
& 0x2)
1703 s
[i
++] = swz
[GET_SWZ(swizzle
, 1)];
1709 if (negateBase
& 0x4)
1711 s
[i
++] = swz
[GET_SWZ(swizzle
, 2)];
1717 if (negateBase
& 0x8)
1719 s
[i
++] = swz
[GET_SWZ(swizzle
, 3)];
1727 writemask_string(GLuint writeMask
)
1732 if (writeMask
== WRITEMASK_XYZW
)
1736 if (writeMask
& WRITEMASK_X
)
1738 if (writeMask
& WRITEMASK_Y
)
1740 if (writeMask
& WRITEMASK_Z
)
1742 if (writeMask
& WRITEMASK_W
)
1750 print_dst_reg(const struct prog_dst_register
*dstReg
)
1752 _mesa_printf(" %s[%d]%s",
1753 program_file_string((enum register_file
) dstReg
->File
),
1755 writemask_string(dstReg
->WriteMask
));
1759 print_src_reg(const struct prog_src_register
*srcReg
)
1761 _mesa_printf("%s[%d]%s",
1762 program_file_string((enum register_file
) srcReg
->File
),
1764 swizzle_string(srcReg
->Swizzle
,
1765 srcReg
->NegateBase
, GL_FALSE
));
1769 print_comment(const struct prog_instruction
*inst
)
1772 _mesa_printf("; # %s\n", inst
->Comment
);
1774 _mesa_printf(";\n");
1779 _mesa_print_alu_instruction(const struct prog_instruction
*inst
,
1780 const char *opcode_string
,
1785 _mesa_printf("%s", opcode_string
);
1787 /* frag prog only */
1788 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
1789 _mesa_printf("_SAT");
1791 if (inst
->DstReg
.File
!= PROGRAM_UNDEFINED
) {
1792 _mesa_printf(" %s[%d]%s",
1793 program_file_string((enum register_file
) inst
->DstReg
.File
),
1795 writemask_string(inst
->DstReg
.WriteMask
));
1798 _mesa_printf(" ???");
1804 for (j
= 0; j
< numRegs
; j
++) {
1805 print_src_reg(inst
->SrcReg
+ j
);
1806 if (j
+ 1 < numRegs
)
1811 _mesa_printf(" # %s", inst
->Comment
);
1813 print_comment(inst
);
1818 * Print a single vertex/fragment program instruction.
1821 _mesa_print_instruction(const struct prog_instruction
*inst
)
1823 switch (inst
->Opcode
) {
1825 _mesa_printf("PRINT '%s'", inst
->Data
);
1826 if (inst
->SrcReg
[0].File
!= PROGRAM_UNDEFINED
) {
1828 _mesa_printf("%s[%d]%s",
1829 program_file_string((enum register_file
) inst
->SrcReg
[0].File
),
1830 inst
->SrcReg
[0].Index
,
1831 swizzle_string(inst
->SrcReg
[0].Swizzle
,
1832 inst
->SrcReg
[0].NegateBase
, GL_FALSE
));
1835 _mesa_printf(" # %s", inst
->Comment
);
1836 print_comment(inst
);
1839 _mesa_printf("SWZ");
1840 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
1841 _mesa_printf("_SAT");
1842 print_dst_reg(&inst
->DstReg
);
1843 _mesa_printf("%s[%d], %s",
1844 program_file_string((enum register_file
) inst
->SrcReg
[0].File
),
1845 inst
->SrcReg
[0].Index
,
1846 swizzle_string(inst
->SrcReg
[0].Swizzle
,
1847 inst
->SrcReg
[0].NegateBase
, GL_TRUE
));
1848 print_comment(inst
);
1853 _mesa_printf("%s", _mesa_opcode_string(inst
->Opcode
));
1854 if (inst
->SaturateMode
== SATURATE_ZERO_ONE
)
1855 _mesa_printf("_SAT");
1857 print_dst_reg(&inst
->DstReg
);
1859 print_src_reg(&inst
->SrcReg
[0]);
1860 _mesa_printf(", texture[%d], ", inst
->TexSrcUnit
);
1861 switch (inst
->TexSrcTarget
) {
1862 case TEXTURE_1D_INDEX
: _mesa_printf("1D"); break;
1863 case TEXTURE_2D_INDEX
: _mesa_printf("2D"); break;
1864 case TEXTURE_3D_INDEX
: _mesa_printf("3D"); break;
1865 case TEXTURE_CUBE_INDEX
: _mesa_printf("CUBE"); break;
1866 case TEXTURE_RECT_INDEX
: _mesa_printf("RECT"); break;
1870 print_comment(inst
);
1873 _mesa_printf("ARL addr.x, ");
1874 print_src_reg(&inst
->SrcReg
[0]);
1875 print_comment(inst
);
1878 _mesa_printf("BRA %u", inst
->BranchTarget
);
1879 print_comment(inst
);
1882 _mesa_printf("CAL %u", inst
->BranchTarget
);
1883 print_comment(inst
);
1886 _mesa_printf("END");
1887 print_comment(inst
);
1889 /* XXX may need other special-case instructions */
1891 /* typical alu instruction */
1892 _mesa_print_alu_instruction(inst
,
1893 _mesa_opcode_string(inst
->Opcode
),
1894 _mesa_num_inst_src_regs(inst
->Opcode
));
1901 * Print a vertx/fragment program to stdout.
1902 * XXX this function could be greatly improved.
1905 _mesa_print_program(const struct gl_program
*prog
)
1908 for (i
= 0; i
< prog
->NumInstructions
; i
++) {
1909 _mesa_printf("%3d: ", i
);
1910 _mesa_print_instruction(prog
->Instructions
+ i
);
1916 * Print all of a program's parameters.
1919 _mesa_print_program_parameters(GLcontext
*ctx
, const struct gl_program
*prog
)
1923 _mesa_printf("NumInstructions=%d\n", prog
->NumInstructions
);
1924 _mesa_printf("NumTemporaries=%d\n", prog
->NumTemporaries
);
1925 _mesa_printf("NumParameters=%d\n", prog
->NumParameters
);
1926 _mesa_printf("NumAttributes=%d\n", prog
->NumAttributes
);
1927 _mesa_printf("NumAddressRegs=%d\n", prog
->NumAddressRegs
);
1929 _mesa_load_state_parameters(ctx
, prog
->Parameters
);
1932 _mesa_printf("Local Params:\n");
1933 for (i
= 0; i
< MAX_PROGRAM_LOCAL_PARAMS
; i
++){
1934 const GLfloat
*p
= prog
->LocalParams
[i
];
1935 _mesa_printf("%2d: %f, %f, %f, %f\n", i
, p
[0], p
[1], p
[2], p
[3]);
1939 for (i
= 0; i
< prog
->Parameters
->NumParameters
; i
++){
1940 struct gl_program_parameter
*param
= prog
->Parameters
->Parameters
+ i
;
1941 const GLfloat
*v
= prog
->Parameters
->ParameterValues
[i
];
1942 _mesa_printf("param[%d] %s %s = {%.3f, %.3f, %.3f, %.3f};\n",
1944 program_file_string(prog
->Parameters
->Parameters
[i
].Type
),
1945 param
->Name
, v
[0], v
[1], v
[2], v
[3]);
1951 * Mixing ARB and NV vertex/fragment programs can be tricky.
1952 * Note: GL_VERTEX_PROGRAM_ARB == GL_VERTEX_PROGRAM_NV
1953 * but, GL_FRAGMENT_PROGRAM_ARB != GL_FRAGMENT_PROGRAM_NV
1954 * The two different fragment program targets are supposed to be compatible
1955 * to some extent (see GL_ARB_fragment_program spec).
1956 * This function does the compatibility check.
1959 compatible_program_targets(GLenum t1
, GLenum t2
)
1963 if (t1
== GL_FRAGMENT_PROGRAM_ARB
&& t2
== GL_FRAGMENT_PROGRAM_NV
)
1965 if (t1
== GL_FRAGMENT_PROGRAM_NV
&& t2
== GL_FRAGMENT_PROGRAM_ARB
)
1972 /**********************************************************************/
1974 /**********************************************************************/
1978 * Bind a program (make it current)
1979 * \note Called from the GL API dispatcher by both glBindProgramNV
1980 * and glBindProgramARB.
1983 _mesa_BindProgram(GLenum target
, GLuint id
)
1985 struct gl_program
*curProg
, *newProg
;
1986 GET_CURRENT_CONTEXT(ctx
);
1987 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1989 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
1991 /* Error-check target and get curProg */
1992 if ((target
== GL_VERTEX_PROGRAM_ARB
) && /* == GL_VERTEX_PROGRAM_NV */
1993 (ctx
->Extensions
.NV_vertex_program
||
1994 ctx
->Extensions
.ARB_vertex_program
)) {
1995 curProg
= &ctx
->VertexProgram
.Current
->Base
;
1997 else if ((target
== GL_FRAGMENT_PROGRAM_NV
1998 && ctx
->Extensions
.NV_fragment_program
) ||
1999 (target
== GL_FRAGMENT_PROGRAM_ARB
2000 && ctx
->Extensions
.ARB_fragment_program
)) {
2001 curProg
= &ctx
->FragmentProgram
.Current
->Base
;
2004 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindProgramNV/ARB(target)");
2009 * Get pointer to new program to bind.
2010 * NOTE: binding to a non-existant program is not an error.
2011 * That's supposed to be caught in glBegin.
2014 /* Bind a default program */
2016 if (target
== GL_VERTEX_PROGRAM_ARB
) /* == GL_VERTEX_PROGRAM_NV */
2017 newProg
= ctx
->Shared
->DefaultVertexProgram
;
2019 newProg
= ctx
->Shared
->DefaultFragmentProgram
;
2022 /* Bind a user program */
2023 newProg
= _mesa_lookup_program(ctx
, id
);
2024 if (!newProg
|| newProg
== &_mesa_DummyProgram
) {
2025 /* allocate a new program now */
2026 newProg
= ctx
->Driver
.NewProgram(ctx
, target
, id
);
2028 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindProgramNV/ARB");
2031 _mesa_HashInsert(ctx
->Shared
->Programs
, id
, newProg
);
2033 else if (!compatible_program_targets(newProg
->Target
, target
)) {
2034 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2035 "glBindProgramNV/ARB(target mismatch)");
2040 /** All error checking is complete now **/
2042 if (curProg
->Id
== id
) {
2043 /* binding same program - no change */
2047 /* unbind/delete oldProg */
2048 if (curProg
->Id
!= 0) {
2049 /* decrement refcount on previously bound fragment program */
2050 curProg
->RefCount
--;
2051 /* and delete if refcount goes below one */
2052 if (curProg
->RefCount
<= 0) {
2053 /* the program ID was already removed from the hash table */
2054 ctx
->Driver
.DeleteProgram(ctx
, curProg
);
2059 if (target
== GL_VERTEX_PROGRAM_ARB
) { /* == GL_VERTEX_PROGRAM_NV */
2060 ctx
->VertexProgram
.Current
= (struct gl_vertex_program
*) newProg
;
2062 else if (target
== GL_FRAGMENT_PROGRAM_NV
||
2063 target
== GL_FRAGMENT_PROGRAM_ARB
) {
2064 ctx
->FragmentProgram
.Current
= (struct gl_fragment_program
*) newProg
;
2066 newProg
->RefCount
++;
2068 /* Never null pointers */
2069 ASSERT(ctx
->VertexProgram
.Current
);
2070 ASSERT(ctx
->FragmentProgram
.Current
);
2072 if (ctx
->Driver
.BindProgram
)
2073 ctx
->Driver
.BindProgram(ctx
, target
, newProg
);
2078 * Delete a list of programs.
2079 * \note Not compiled into display lists.
2080 * \note Called by both glDeleteProgramsNV and glDeleteProgramsARB.
2083 _mesa_DeletePrograms(GLsizei n
, const GLuint
*ids
)
2086 GET_CURRENT_CONTEXT(ctx
);
2087 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2090 _mesa_error( ctx
, GL_INVALID_VALUE
, "glDeleteProgramsNV" );
2094 for (i
= 0; i
< n
; i
++) {
2096 struct gl_program
*prog
= _mesa_lookup_program(ctx
, ids
[i
]);
2097 if (prog
== &_mesa_DummyProgram
) {
2098 _mesa_HashRemove(ctx
->Shared
->Programs
, ids
[i
]);
2101 /* Unbind program if necessary */
2102 if (prog
->Target
== GL_VERTEX_PROGRAM_ARB
|| /* == GL_VERTEX_PROGRAM_NV */
2103 prog
->Target
== GL_VERTEX_STATE_PROGRAM_NV
) {
2104 if (ctx
->VertexProgram
.Current
&&
2105 ctx
->VertexProgram
.Current
->Base
.Id
== ids
[i
]) {
2106 /* unbind this currently bound program */
2107 _mesa_BindProgram(prog
->Target
, 0);
2110 else if (prog
->Target
== GL_FRAGMENT_PROGRAM_NV
||
2111 prog
->Target
== GL_FRAGMENT_PROGRAM_ARB
) {
2112 if (ctx
->FragmentProgram
.Current
&&
2113 ctx
->FragmentProgram
.Current
->Base
.Id
== ids
[i
]) {
2114 /* unbind this currently bound program */
2115 _mesa_BindProgram(prog
->Target
, 0);
2119 _mesa_problem(ctx
, "bad target in glDeleteProgramsNV");
2122 /* The ID is immediately available for re-use now */
2123 _mesa_HashRemove(ctx
->Shared
->Programs
, ids
[i
]);
2125 if (prog
->RefCount
<= 0) {
2126 ctx
->Driver
.DeleteProgram(ctx
, prog
);
2135 * Generate a list of new program identifiers.
2136 * \note Not compiled into display lists.
2137 * \note Called by both glGenProgramsNV and glGenProgramsARB.
2140 _mesa_GenPrograms(GLsizei n
, GLuint
*ids
)
2144 GET_CURRENT_CONTEXT(ctx
);
2145 ASSERT_OUTSIDE_BEGIN_END(ctx
);
2148 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenPrograms");
2155 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->Programs
, n
);
2157 /* Insert pointer to dummy program as placeholder */
2158 for (i
= 0; i
< (GLuint
) n
; i
++) {
2159 _mesa_HashInsert(ctx
->Shared
->Programs
, first
+ i
, &_mesa_DummyProgram
);
2162 /* Return the program names */
2163 for (i
= 0; i
< (GLuint
) n
; i
++) {
2169 /**********************************************************************/
2170 /* GL_MESA_program_debug extension */
2171 /**********************************************************************/
2175 GLAPI
void GLAPIENTRY
2176 glProgramCallbackMESA(GLenum target
, GLprogramcallbackMESA callback
,
2179 _mesa_ProgramCallbackMESA(target
, callback
, data
);
2184 _mesa_ProgramCallbackMESA(GLenum target
, GLprogramcallbackMESA callback
,
2187 GET_CURRENT_CONTEXT(ctx
);
2190 case GL_FRAGMENT_PROGRAM_ARB
:
2191 if (!ctx
->Extensions
.ARB_fragment_program
) {
2192 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramCallbackMESA(target)");
2195 ctx
->FragmentProgram
.Callback
= callback
;
2196 ctx
->FragmentProgram
.CallbackData
= data
;
2198 case GL_FRAGMENT_PROGRAM_NV
:
2199 if (!ctx
->Extensions
.NV_fragment_program
) {
2200 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramCallbackMESA(target)");
2203 ctx
->FragmentProgram
.Callback
= callback
;
2204 ctx
->FragmentProgram
.CallbackData
= data
;
2206 case GL_VERTEX_PROGRAM_ARB
: /* == GL_VERTEX_PROGRAM_NV */
2207 if (!ctx
->Extensions
.ARB_vertex_program
&&
2208 !ctx
->Extensions
.NV_vertex_program
) {
2209 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramCallbackMESA(target)");
2212 ctx
->VertexProgram
.Callback
= callback
;
2213 ctx
->VertexProgram
.CallbackData
= data
;
2216 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramCallbackMESA(target)");
2223 GLAPI
void GLAPIENTRY
2224 glGetProgramRegisterfvMESA(GLenum target
,
2225 GLsizei len
, const GLubyte
*registerName
,
2228 _mesa_GetProgramRegisterfvMESA(target
, len
, registerName
, v
);
2233 _mesa_GetProgramRegisterfvMESA(GLenum target
,
2234 GLsizei len
, const GLubyte
*registerName
,
2238 GET_CURRENT_CONTEXT(ctx
);
2240 /* We _should_ be inside glBegin/glEnd */
2242 if (ctx
->Driver
.CurrentExecPrimitive
== PRIM_OUTSIDE_BEGIN_END
) {
2243 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetProgramRegisterfvMESA");
2248 /* make null-terminated copy of registerName */
2249 len
= MIN2((unsigned int) len
, sizeof(reg
) - 1);
2250 _mesa_memcpy(reg
, registerName
, len
);
2254 case GL_VERTEX_PROGRAM_ARB
: /* == GL_VERTEX_PROGRAM_NV */
2255 if (!ctx
->Extensions
.ARB_vertex_program
&&
2256 !ctx
->Extensions
.NV_vertex_program
) {
2257 _mesa_error(ctx
, GL_INVALID_ENUM
,
2258 "glGetProgramRegisterfvMESA(target)");
2261 if (!ctx
->VertexProgram
._Enabled
) {
2262 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2263 "glGetProgramRegisterfvMESA");
2266 /* GL_NV_vertex_program */
2267 if (reg
[0] == 'R') {
2269 GLint i
= _mesa_atoi(reg
+ 1);
2270 if (i
>= (GLint
)ctx
->Const
.VertexProgram
.MaxTemps
) {
2271 _mesa_error(ctx
, GL_INVALID_VALUE
,
2272 "glGetProgramRegisterfvMESA(registerName)");
2276 ctx
->Driver
.GetVertexProgramRegister(ctx
, PROGRAM_TEMPORARY
, i
, v
);
2279 else if (reg
[0] == 'v' && reg
[1] == '[') {
2280 /* Vertex Input attribute */
2282 for (i
= 0; i
< ctx
->Const
.VertexProgram
.MaxAttribs
; i
++) {
2283 const char *name
= _mesa_nv_vertex_input_register_name(i
);
2285 _mesa_sprintf(number
, "%d", i
);
2286 if (_mesa_strncmp(reg
+ 2, name
, 4) == 0 ||
2287 _mesa_strncmp(reg
+ 2, number
, _mesa_strlen(number
)) == 0) {
2289 ctx
->Driver
.GetVertexProgramRegister(ctx
, PROGRAM_INPUT
,
2295 _mesa_error(ctx
, GL_INVALID_VALUE
,
2296 "glGetProgramRegisterfvMESA(registerName)");
2299 else if (reg
[0] == 'o' && reg
[1] == '[') {
2300 /* Vertex output attribute */
2302 /* GL_ARB_vertex_program */
2303 else if (_mesa_strncmp(reg
, "vertex.", 7) == 0) {
2307 _mesa_error(ctx
, GL_INVALID_VALUE
,
2308 "glGetProgramRegisterfvMESA(registerName)");
2312 case GL_FRAGMENT_PROGRAM_ARB
:
2313 if (!ctx
->Extensions
.ARB_fragment_program
) {
2314 _mesa_error(ctx
, GL_INVALID_ENUM
,
2315 "glGetProgramRegisterfvMESA(target)");
2318 if (!ctx
->FragmentProgram
._Enabled
) {
2319 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2320 "glGetProgramRegisterfvMESA");
2325 case GL_FRAGMENT_PROGRAM_NV
:
2326 if (!ctx
->Extensions
.NV_fragment_program
) {
2327 _mesa_error(ctx
, GL_INVALID_ENUM
,
2328 "glGetProgramRegisterfvMESA(target)");
2331 if (!ctx
->FragmentProgram
._Enabled
) {
2332 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2333 "glGetProgramRegisterfvMESA");
2336 if (reg
[0] == 'R') {
2338 GLint i
= _mesa_atoi(reg
+ 1);
2339 if (i
>= (GLint
)ctx
->Const
.FragmentProgram
.MaxTemps
) {
2340 _mesa_error(ctx
, GL_INVALID_VALUE
,
2341 "glGetProgramRegisterfvMESA(registerName)");
2344 ctx
->Driver
.GetFragmentProgramRegister(ctx
, PROGRAM_TEMPORARY
,
2347 else if (reg
[0] == 'f' && reg
[1] == '[') {
2348 /* Fragment input attribute */
2350 for (i
= 0; i
< ctx
->Const
.FragmentProgram
.MaxAttribs
; i
++) {
2351 const char *name
= _mesa_nv_fragment_input_register_name(i
);
2352 if (_mesa_strncmp(reg
+ 2, name
, 4) == 0) {
2353 ctx
->Driver
.GetFragmentProgramRegister(ctx
,
2354 PROGRAM_INPUT
, i
, v
);
2358 _mesa_error(ctx
, GL_INVALID_VALUE
,
2359 "glGetProgramRegisterfvMESA(registerName)");
2362 else if (_mesa_strcmp(reg
, "o[COLR]") == 0) {
2363 /* Fragment output color */
2364 ctx
->Driver
.GetFragmentProgramRegister(ctx
, PROGRAM_OUTPUT
,
2365 FRAG_RESULT_COLR
, v
);
2367 else if (_mesa_strcmp(reg
, "o[COLH]") == 0) {
2368 /* Fragment output color */
2369 ctx
->Driver
.GetFragmentProgramRegister(ctx
, PROGRAM_OUTPUT
,
2370 FRAG_RESULT_COLH
, v
);
2372 else if (_mesa_strcmp(reg
, "o[DEPR]") == 0) {
2373 /* Fragment output depth */
2374 ctx
->Driver
.GetFragmentProgramRegister(ctx
, PROGRAM_OUTPUT
,
2375 FRAG_RESULT_DEPR
, v
);
2378 /* try user-defined identifiers */
2379 const GLfloat
*value
= _mesa_lookup_parameter_value(
2380 ctx
->FragmentProgram
.Current
->Base
.Parameters
, -1, reg
);
2385 _mesa_error(ctx
, GL_INVALID_VALUE
,
2386 "glGetProgramRegisterfvMESA(registerName)");
2392 _mesa_error(ctx
, GL_INVALID_ENUM
,
2393 "glGetProgramRegisterfvMESA(target)");