blob: daec9252fff20b31b68f4dd95f79bf101f865a50 [file] [log] [blame]
Michal Krol2861e732004-03-29 11:09:34 +00001/*
2 * Mesa 3-D graphics library
Brian Paul6d460af2004-04-23 14:16:46 +00003 * Version: 6.1
Michal Krol2861e732004-03-29 11:09:34 +00004 *
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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.
23 */
24
25/**
26 * \file program.c
27 * Vertex and fragment program support functions.
28 * \author Brian Paul
29 */
30
31
32#include "glheader.h"
33#include "context.h"
34#include "hash.h"
35#include "imports.h"
36#include "macros.h"
37#include "mtypes.h"
38#include "program.h"
39#include "nvfragparse.h"
40#include "nvfragprog.h"
41#include "nvvertparse.h"
42
43
44/**********************************************************************/
45/* Utility functions */
46/**********************************************************************/
47
48
49/**
Brian Paul21841f02004-08-14 14:28:11 +000050 * Init context's vertex/fragment program state
Michal Krol2861e732004-03-29 11:09:34 +000051 */
52void
53_mesa_init_program(GLcontext *ctx)
54{
55 GLuint i;
56
57 ctx->Program.ErrorPos = -1;
58 ctx->Program.ErrorString = _mesa_strdup("");
59
60#if FEATURE_NV_vertex_program || FEATURE_ARB_vertex_program
61 ctx->VertexProgram.Enabled = GL_FALSE;
62 ctx->VertexProgram.PointSizeEnabled = GL_FALSE;
63 ctx->VertexProgram.TwoSideEnabled = GL_FALSE;
Michal Krol2861e732004-03-29 11:09:34 +000064 ctx->VertexProgram.Current = (struct vertex_program *) ctx->Shared->DefaultVertexProgram;
65 assert(ctx->VertexProgram.Current);
66 ctx->VertexProgram.Current->Base.RefCount++;
67 for (i = 0; i < MAX_NV_VERTEX_PROGRAM_PARAMS / 4; i++) {
68 ctx->VertexProgram.TrackMatrix[i] = GL_NONE;
69 ctx->VertexProgram.TrackMatrixTransform[i] = GL_IDENTITY_NV;
70 }
71#endif
72
73#if FEATURE_NV_fragment_program || FEATURE_ARB_fragment_program
74 ctx->FragmentProgram.Enabled = GL_FALSE;
75 ctx->FragmentProgram.Current = (struct fragment_program *) ctx->Shared->DefaultFragmentProgram;
76 assert(ctx->FragmentProgram.Current);
77 ctx->FragmentProgram.Current->Base.RefCount++;
78#endif
79}
80
81
82/**
Brian Paul21841f02004-08-14 14:28:11 +000083 * Free a context's vertex/fragment program state
84 */
85void
86_mesa_free_program_data(GLcontext *ctx)
87{
88#if FEATURE_NV_vertex_program
89 if (ctx->VertexProgram.Current) {
90 ctx->VertexProgram.Current->Base.RefCount--;
91 if (ctx->VertexProgram.Current->Base.RefCount <= 0)
92 ctx->Driver.DeleteProgram(ctx, &(ctx->VertexProgram.Current->Base));
93 }
94#endif
95#if FEATURE_NV_fragment_program
96 if (ctx->FragmentProgram.Current) {
97 ctx->FragmentProgram.Current->Base.RefCount--;
98 if (ctx->FragmentProgram.Current->Base.RefCount <= 0)
99 ctx->Driver.DeleteProgram(ctx, &(ctx->FragmentProgram.Current->Base));
100 }
101#endif
102 _mesa_free((void *) ctx->Program.ErrorString);
103}
104
105
106
107
108/**
Michal Krol2861e732004-03-29 11:09:34 +0000109 * Set the vertex/fragment program error state (position and error string).
110 * This is generally called from within the parsers.
111 */
112void
113_mesa_set_program_error(GLcontext *ctx, GLint pos, const char *string)
114{
115 ctx->Program.ErrorPos = pos;
116 _mesa_free((void *) ctx->Program.ErrorString);
117 if (!string)
118 string = "";
119 ctx->Program.ErrorString = _mesa_strdup(string);
120}
121
122
123/**
124 * Find the line number and column for 'pos' within 'string'.
125 * Return a copy of the line which contains 'pos'. Free the line with
126 * _mesa_free().
127 * \param string the program string
128 * \param pos the position within the string
129 * \param line returns the line number corresponding to 'pos'.
130 * \param col returns the column number corresponding to 'pos'.
131 * \return copy of the line containing 'pos'.
132 */
133const GLubyte *
134_mesa_find_line_column(const GLubyte *string, const GLubyte *pos,
135 GLint *line, GLint *col)
136{
137 const GLubyte *lineStart = string;
138 const GLubyte *p = string;
139 GLubyte *s;
140 int len;
141
142 *line = 1;
143
144 while (p != pos) {
145 if (*p == (GLubyte) '\n') {
146 (*line)++;
147 lineStart = p + 1;
148 }
149 p++;
150 }
151
152 *col = (pos - lineStart) + 1;
153
154 /* return copy of this line */
155 while (*p != 0 && *p != '\n')
156 p++;
157 len = p - lineStart;
158 s = (GLubyte *) _mesa_malloc(len + 1);
159 _mesa_memcpy(s, lineStart, len);
160 s[len] = 0;
161
162 return s;
163}
164
165
166static struct program * _mesa_init_program_struct( GLcontext *ctx,
167 struct program *prog,
168 GLenum target, GLuint id)
169{
170 if (prog) {
171 prog->Id = id;
172 prog->Target = target;
173 prog->Resident = GL_TRUE;
174 prog->RefCount = 1;
175 }
176
177 return prog;
178}
179
180struct program * _mesa_init_fragment_program( GLcontext *ctx,
181 struct fragment_program *prog,
182 GLenum target, GLuint id)
183{
184 if (prog)
185 return _mesa_init_program_struct( ctx, &prog->Base, target, id );
186 else
187 return NULL;
188}
189
190struct program * _mesa_init_vertex_program( GLcontext *ctx,
191 struct vertex_program *prog,
192 GLenum target, GLuint id)
193{
194 if (prog)
195 return _mesa_init_program_struct( ctx, &prog->Base, target, id );
196 else
197 return NULL;
198}
199
200
201/**
202 * Allocate and initialize a new fragment/vertex program object but
203 * don't put it into the program hash table. Called via
204 * ctx->Driver.NewProgram. May be overridden (ie. replaced) by a
205 * device driver function to implement OO deriviation with additional
206 * types not understood by this function.
207 *
208 * \param ctx context
209 * \param id program id/number
210 * \param target program target/type
211 * \return pointer to new program object
212 */
213struct program *
214_mesa_new_program(GLcontext *ctx, GLenum target, GLuint id)
215{
216 switch (target) {
217 case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */
218 return _mesa_init_vertex_program( ctx, CALLOC_STRUCT(vertex_program),
219 target, id );
220
221 case GL_FRAGMENT_PROGRAM_NV:
222 case GL_FRAGMENT_PROGRAM_ARB:
223 return _mesa_init_fragment_program( ctx, CALLOC_STRUCT(fragment_program),
224 target, id );
225
226 default:
227 _mesa_problem(ctx, "bad target in _mesa_new_program");
228 return NULL;
229 }
230}
231
232
233/**
234 * Delete a program and remove it from the hash table, ignoring the
235 * reference count.
236 * Called via ctx->Driver.DeleteProgram. May be wrapped (OO deriviation)
237 * by a device driver function.
238 */
239void
240_mesa_delete_program(GLcontext *ctx, struct program *prog)
241{
242 ASSERT(prog);
243
244 if (prog->String)
245 _mesa_free(prog->String);
246 if (prog->Target == GL_VERTEX_PROGRAM_NV ||
247 prog->Target == GL_VERTEX_STATE_PROGRAM_NV) {
248 struct vertex_program *vprog = (struct vertex_program *) prog;
249 if (vprog->Instructions)
250 _mesa_free(vprog->Instructions);
Brian Paul21841f02004-08-14 14:28:11 +0000251 if (vprog->Parameters)
252 _mesa_free_parameter_list(vprog->Parameters);
Michal Krol2861e732004-03-29 11:09:34 +0000253 }
254 else if (prog->Target == GL_FRAGMENT_PROGRAM_NV ||
255 prog->Target == GL_FRAGMENT_PROGRAM_ARB) {
256 struct fragment_program *fprog = (struct fragment_program *) prog;
257 if (fprog->Instructions)
258 _mesa_free(fprog->Instructions);
Brian Paul21841f02004-08-14 14:28:11 +0000259 if (fprog->Parameters)
Michal Krol2861e732004-03-29 11:09:34 +0000260 _mesa_free_parameter_list(fprog->Parameters);
Michal Krol2861e732004-03-29 11:09:34 +0000261 }
262 _mesa_free(prog);
263}
264
265
266
267/**********************************************************************/
268/* Program parameter functions */
269/**********************************************************************/
270
271struct program_parameter_list *
272_mesa_new_parameter_list(void)
273{
274 return (struct program_parameter_list *)
275 _mesa_calloc(sizeof(struct program_parameter_list));
276}
277
278
279/**
280 * Free a parameter list and all its parameters
281 */
282void
283_mesa_free_parameter_list(struct program_parameter_list *paramList)
284{
285 _mesa_free_parameters(paramList);
286 _mesa_free(paramList);
287}
288
289
290/**
291 * Free all the parameters in the given list, but don't free the
292 * paramList structure itself.
293 */
294void
295_mesa_free_parameters(struct program_parameter_list *paramList)
296{
297 GLuint i;
298 for (i = 0; i < paramList->NumParameters; i++) {
299 _mesa_free((void *) paramList->Parameters[i].Name);
300 }
301 _mesa_free(paramList->Parameters);
302 paramList->NumParameters = 0;
303 paramList->Parameters = NULL;
304}
305
306
307/**
308 * Helper function used by the functions below.
309 */
310static GLint
311add_parameter(struct program_parameter_list *paramList,
312 const char *name, const GLfloat values[4],
313 enum parameter_type type)
314{
315 const GLuint n = paramList->NumParameters;
316
317 paramList->Parameters = (struct program_parameter *)
318 _mesa_realloc(paramList->Parameters,
319 n * sizeof(struct program_parameter),
320 (n + 1) * sizeof(struct program_parameter));
321 if (!paramList->Parameters) {
322 /* out of memory */
323 paramList->NumParameters = 0;
324 return -1;
325 }
326 else {
327 paramList->NumParameters = n + 1;
328 paramList->Parameters[n].Name = _mesa_strdup(name);
329 paramList->Parameters[n].Type = type;
330 if (values)
331 COPY_4V(paramList->Parameters[n].Values, values);
332 return (GLint) n;
333 }
334}
335
336
337/**
338 * Add a new named program parameter (Ex: NV_fragment_program DEFINE statement)
339 * \return index of the new entry in the parameter list
340 */
341GLint
342_mesa_add_named_parameter(struct program_parameter_list *paramList,
343 const char *name, const GLfloat values[4])
344{
345 return add_parameter(paramList, name, values, NAMED_PARAMETER);
346}
347
348
349/**
350 * Add a new unnamed constant to the parameter list.
351 * \param paramList - the parameter list
352 * \param values - four float values
353 * \return index of the new parameter.
354 */
355GLint
356_mesa_add_named_constant(struct program_parameter_list *paramList,
357 const char *name, const GLfloat values[4])
358{
359 return add_parameter(paramList, name, values, CONSTANT);
360}
361
362
363/**
364 * Add a new unnamed constant to the parameter list.
365 * \param paramList - the parameter list
366 * \param values - four float values
367 * \return index of the new parameter.
368 */
369GLint
370_mesa_add_unnamed_constant(struct program_parameter_list *paramList,
371 const GLfloat values[4])
372{
373 /* generate a new dummy name */
374 static GLuint n = 0;
375 char name[20];
376 _mesa_sprintf(name, "constant%d", n);
377 n++;
378 /* store it */
379 return add_parameter(paramList, name, values, CONSTANT);
380}
381
382
383/**
384 * Add a new state reference to the parameter list.
385 * \param paramList - the parameter list
386 * \param state - an array of 6 state tokens
387 *
388 * \return index of the new parameter.
389 */
390GLint
391_mesa_add_state_reference(struct program_parameter_list *paramList,
392 GLint *stateTokens)
393{
394 /* XXX Should we parse <stateString> here and produce the parameter's
395 * list of STATE_* tokens here, or in the parser?
396 */
397 GLint a, idx;
398
399 idx = add_parameter(paramList, "Some State", NULL, STATE);
400
401 for (a=0; a<6; a++)
402 paramList->Parameters[idx].StateIndexes[a] = (enum state_index) stateTokens[a];
403
404 return idx;
405}
406
407
408/**
409 * Lookup a parameter value by name in the given parameter list.
410 * \return pointer to the float[4] values.
411 */
412GLfloat *
413_mesa_lookup_parameter_value(struct program_parameter_list *paramList,
414 GLsizei nameLen, const char *name)
415{
416 GLuint i;
417
418 if (!paramList)
419 return NULL;
420
421 if (nameLen == -1) {
422 /* name is null-terminated */
423 for (i = 0; i < paramList->NumParameters; i++) {
424 if (_mesa_strcmp(paramList->Parameters[i].Name, name) == 0)
425 return paramList->Parameters[i].Values;
426 }
427 }
428 else {
429 /* name is not null-terminated, use nameLen */
430 for (i = 0; i < paramList->NumParameters; i++) {
431 if (_mesa_strncmp(paramList->Parameters[i].Name, name, nameLen) == 0
432 && _mesa_strlen(paramList->Parameters[i].Name) == (size_t)nameLen)
433 return paramList->Parameters[i].Values;
434 }
435 }
436 return NULL;
437}
438
439
440/**
441 * Lookup a parameter index by name in the given parameter list.
442 * \return index of parameter in the list.
443 */
444GLint
445_mesa_lookup_parameter_index(struct program_parameter_list *paramList,
446 GLsizei nameLen, const char *name)
447{
448 GLint i;
449
450 if (!paramList)
451 return -1;
452
453 if (nameLen == -1) {
454 /* name is null-terminated */
455 for (i = 0; i < (GLint) paramList->NumParameters; i++) {
456 if (_mesa_strcmp(paramList->Parameters[i].Name, name) == 0)
457 return i;
458 }
459 }
460 else {
461 /* name is not null-terminated, use nameLen */
462 for (i = 0; i < (GLint) paramList->NumParameters; i++) {
463 if (_mesa_strncmp(paramList->Parameters[i].Name, name, nameLen) == 0
464 && _mesa_strlen(paramList->Parameters[i].Name) == (size_t)nameLen)
465 return i;
466 }
467 }
468 return -1;
469}
470
471
472/**
473 * Use the list of tokens in the state[] array to find global GL state
474 * and return it in <value>. Usually, four values are returned in <value>
475 * but matrix queries may return as many as 16 values.
476 * This function is used for ARB vertex/fragment programs.
477 * The program parser will produce the state[] values.
478 */
479static void
480_mesa_fetch_state(GLcontext *ctx, const enum state_index state[],
481 GLfloat *value)
482{
483 switch (state[0]) {
484 case STATE_MATERIAL:
485 {
486 /* state[1] is either 0=front or 1=back side */
487 const GLuint face = (GLuint) state[1];
488 /* state[2] is the material attribute */
489 switch (state[2]) {
490 case STATE_AMBIENT:
491 if (face == 0)
492 COPY_4V(value, ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_AMBIENT]);
493 else
494 COPY_4V(value, ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_AMBIENT]);
495 return;
496 case STATE_DIFFUSE:
497 if (face == 0)
498 COPY_4V(value, ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE]);
499 else
500 COPY_4V(value, ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_DIFFUSE]);
501 return;
502 case STATE_SPECULAR:
503 if (face == 0)
504 COPY_4V(value, ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SPECULAR]);
505 else
506 COPY_4V(value, ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_SPECULAR]);
507 return;
508 case STATE_EMISSION:
509 if (face == 0)
510 COPY_4V(value, ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_EMISSION]);
511 else
512 COPY_4V(value, ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_EMISSION]);
513 return;
514 case STATE_SHININESS:
515 if (face == 0)
516 value[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SHININESS][0];
517 else
518 value[0] = ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_SHININESS][0];
519 value[1] = 0.0F;
520 value[2] = 0.0F;
521 value[3] = 1.0F;
522 return;
523 default:
524 _mesa_problem(ctx, "Invalid material state in fetch_state");
525 return;
526 }
527 };
528 return;
529 case STATE_LIGHT:
530 {
531 /* state[1] is the light number */
532 const GLuint ln = (GLuint) state[1];
533 /* state[2] is the light attribute */
534 switch (state[2]) {
535 case STATE_AMBIENT:
536 COPY_4V(value, ctx->Light.Light[ln].Ambient);
537 return;
538 case STATE_DIFFUSE:
539 COPY_4V(value, ctx->Light.Light[ln].Diffuse);
540 return;
541 case STATE_SPECULAR:
542 COPY_4V(value, ctx->Light.Light[ln].Specular);
543 return;
544 case STATE_POSITION:
545 COPY_4V(value, ctx->Light.Light[ln].EyePosition);
546 return;
547 case STATE_ATTENUATION:
548 value[0] = ctx->Light.Light[ln].ConstantAttenuation;
549 value[1] = ctx->Light.Light[ln].LinearAttenuation;
550 value[2] = ctx->Light.Light[ln].QuadraticAttenuation;
551 value[3] = ctx->Light.Light[ln].SpotExponent;
552 return;
553 case STATE_SPOT_DIRECTION:
554 COPY_4V(value, ctx->Light.Light[ln].EyeDirection);
555 return;
556 case STATE_HALF:
557 {
558 GLfloat eye_z[] = {0, 0, 1};
559
560 /* Compute infinite half angle vector:
561 * half-vector = light_position + (0, 0, 1)
562 * and then normalize. w = 0
563 *
564 * light.EyePosition.w should be 0 for infinite lights.
565 */
566 ADD_3V(value, eye_z, ctx->Light.Light[ln].EyePosition);
567 NORMALIZE_3FV(value);
568 value[3] = 0;
569 }
570 return;
571 default:
572 _mesa_problem(ctx, "Invalid light state in fetch_state");
573 return;
574 }
575 }
576 return;
577 case STATE_LIGHTMODEL_AMBIENT:
578 COPY_4V(value, ctx->Light.Model.Ambient);
579 return;
580 case STATE_LIGHTMODEL_SCENECOLOR:
581 if (state[1] == 0) {
582 /* front */
583 GLint i;
584 for (i = 0; i < 4; i++) {
585 value[i] = ctx->Light.Model.Ambient[i]
586 * ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_AMBIENT][i]
587 + ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_EMISSION][i];
588 }
589 }
590 else {
591 /* back */
592 GLint i;
593 for (i = 0; i < 4; i++) {
594 value[i] = ctx->Light.Model.Ambient[i]
595 * ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_AMBIENT][i]
596 + ctx->Light.Material.Attrib[MAT_ATTRIB_BACK_EMISSION][i];
597 }
598 }
599 return;
600 case STATE_LIGHTPROD:
601 {
602 const GLuint ln = (GLuint) state[1];
603 const GLuint face = (GLuint) state[2];
604 GLint i;
605 ASSERT(face == 0 || face == 1);
606 switch (state[3]) {
607 case STATE_AMBIENT:
608 for (i = 0; i < 3; i++) {
609 value[i] = ctx->Light.Light[ln].Ambient[i] *
610 ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_AMBIENT+face][i];
611 }
612 /* [3] = material alpha */
613 value[3] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE+face][3];
614 return;
615 case STATE_DIFFUSE:
616 for (i = 0; i < 3; i++) {
617 value[i] = ctx->Light.Light[ln].Diffuse[i] *
618 ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE+face][i];
619 }
620 /* [3] = material alpha */
621 value[3] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE+face][3];
622 return;
623 case STATE_SPECULAR:
624 for (i = 0; i < 3; i++) {
625 value[i] = ctx->Light.Light[ln].Specular[i] *
626 ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_SPECULAR+face][i];
627 }
628 /* [3] = material alpha */
629 value[3] = ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE+face][3];
630 return;
631 default:
632 _mesa_problem(ctx, "Invalid lightprod state in fetch_state");
633 return;
634 }
635 }
636 return;
637 case STATE_TEXGEN:
638 {
639 /* state[1] is the texture unit */
640 const GLuint unit = (GLuint) state[1];
641 /* state[2] is the texgen attribute */
642 switch (state[2]) {
643 case STATE_TEXGEN_EYE_S:
644 COPY_4V(value, ctx->Texture.Unit[unit].EyePlaneS);
645 return;
646 case STATE_TEXGEN_EYE_T:
647 COPY_4V(value, ctx->Texture.Unit[unit].EyePlaneT);
648 return;
649 case STATE_TEXGEN_EYE_R:
650 COPY_4V(value, ctx->Texture.Unit[unit].EyePlaneR);
651 return;
652 case STATE_TEXGEN_EYE_Q:
653 COPY_4V(value, ctx->Texture.Unit[unit].EyePlaneQ);
654 return;
655 case STATE_TEXGEN_OBJECT_S:
656 COPY_4V(value, ctx->Texture.Unit[unit].ObjectPlaneS);
657 return;
658 case STATE_TEXGEN_OBJECT_T:
659 COPY_4V(value, ctx->Texture.Unit[unit].ObjectPlaneT);
660 return;
661 case STATE_TEXGEN_OBJECT_R:
662 COPY_4V(value, ctx->Texture.Unit[unit].ObjectPlaneR);
663 return;
664 case STATE_TEXGEN_OBJECT_Q:
665 COPY_4V(value, ctx->Texture.Unit[unit].ObjectPlaneQ);
666 return;
667 default:
668 _mesa_problem(ctx, "Invalid texgen state in fetch_state");
669 return;
670 }
671 }
672 return;
673 case STATE_TEXENV_COLOR:
674 {
675 /* state[1] is the texture unit */
676 const GLuint unit = (GLuint) state[1];
677 COPY_4V(value, ctx->Texture.Unit[unit].EnvColor);
678 }
679 return;
680 case STATE_FOG_COLOR:
681 COPY_4V(value, ctx->Fog.Color);
682 return;
683 case STATE_FOG_PARAMS:
684 value[0] = ctx->Fog.Density;
685 value[1] = ctx->Fog.Start;
686 value[2] = ctx->Fog.End;
687 value[3] = 1.0F / (ctx->Fog.End - ctx->Fog.Start);
688 return;
689 case STATE_CLIPPLANE:
690 {
691 const GLuint plane = (GLuint) state[1];
692 COPY_4V(value, ctx->Transform.EyeUserPlane[plane]);
693 }
694 return;
695 case STATE_POINT_SIZE:
696 value[0] = ctx->Point.Size;
697 value[1] = ctx->Point.MinSize;
698 value[2] = ctx->Point.MaxSize;
699 value[3] = ctx->Point.Threshold;
700 return;
701 case STATE_POINT_ATTENUATION:
702 value[0] = ctx->Point.Params[0];
703 value[1] = ctx->Point.Params[1];
704 value[2] = ctx->Point.Params[2];
705 value[3] = 1.0F;
706 return;
707 case STATE_MATRIX:
708 {
709 /* state[1] = modelview, projection, texture, etc. */
710 /* state[2] = which texture matrix or program matrix */
711 /* state[3] = first column to fetch */
712 /* state[4] = last column to fetch */
713 /* state[5] = transpose, inverse or invtrans */
714
715 const GLmatrix *matrix;
716 const enum state_index mat = state[1];
717 const GLuint index = (GLuint) state[2];
718 const GLuint first = (GLuint) state[3];
719 const GLuint last = (GLuint) state[4];
720 const enum state_index modifier = state[5];
721 const GLfloat *m;
722 GLuint row, i;
723 if (mat == STATE_MODELVIEW) {
724 matrix = ctx->ModelviewMatrixStack.Top;
725 }
726 else if (mat == STATE_PROJECTION) {
727 matrix = ctx->ProjectionMatrixStack.Top;
728 }
729 else if (mat == STATE_MVP) {
730 matrix = &ctx->_ModelProjectMatrix;
731 }
732 else if (mat == STATE_TEXTURE) {
733 matrix = ctx->TextureMatrixStack[index].Top;
734 }
735 else if (mat == STATE_PROGRAM) {
736 matrix = ctx->ProgramMatrixStack[index].Top;
737 }
738 else {
739 _mesa_problem(ctx, "Bad matrix name in _mesa_fetch_state()");
740 return;
741 }
742 if (modifier == STATE_MATRIX_INVERSE ||
743 modifier == STATE_MATRIX_INVTRANS) {
744 /* XXX be sure inverse is up to date */
745 m = matrix->inv;
746 }
747 else {
748 m = matrix->m;
749 }
750 if (modifier == STATE_MATRIX_TRANSPOSE ||
751 modifier == STATE_MATRIX_INVTRANS) {
752 for (i = 0, row = first; row <= last; row++) {
753 value[i++] = m[row * 4 + 0];
754 value[i++] = m[row * 4 + 1];
755 value[i++] = m[row * 4 + 2];
756 value[i++] = m[row * 4 + 3];
757 }
758 }
759 else {
760 for (i = 0, row = first; row <= last; row++) {
761 value[i++] = m[row + 0];
762 value[i++] = m[row + 4];
763 value[i++] = m[row + 8];
764 value[i++] = m[row + 12];
765 }
766 }
767 }
768 return;
769 case STATE_DEPTH_RANGE:
Brian Paul824fdf02004-06-29 00:00:06 +0000770 value[0] = ctx->Viewport.Near; /* near */
771 value[1] = ctx->Viewport.Far; /* far */
772 value[2] = ctx->Viewport.Far - ctx->Viewport.Near; /* far - near */
773 value[3] = 0;
Michal Krol2861e732004-03-29 11:09:34 +0000774 return;
775 case STATE_FRAGMENT_PROGRAM:
776 {
777 /* state[1] = {STATE_ENV, STATE_LOCAL} */
778 /* state[2] = parameter index */
Brian Paul824fdf02004-06-29 00:00:06 +0000779 const int idx = (int) state[2];
Michal Krol2861e732004-03-29 11:09:34 +0000780 switch (state[1]) {
781 case STATE_ENV:
Brian Paul824fdf02004-06-29 00:00:06 +0000782 COPY_4V(value, ctx->FragmentProgram.Parameters[idx]);
Michal Krol2861e732004-03-29 11:09:34 +0000783 break;
Michal Krol2861e732004-03-29 11:09:34 +0000784 case STATE_LOCAL:
785 COPY_4V(value, ctx->FragmentProgram.Current->Base.LocalParams[idx]);
Brian Paul824fdf02004-06-29 00:00:06 +0000786 break;
Michal Krol2861e732004-03-29 11:09:34 +0000787 default:
788 _mesa_problem(ctx, "Bad state switch in _mesa_fetch_state()");
789 return;
Brian Paul824fdf02004-06-29 00:00:06 +0000790 }
791 }
Michal Krol2861e732004-03-29 11:09:34 +0000792 return;
793
794 case STATE_VERTEX_PROGRAM:
Brian Paul824fdf02004-06-29 00:00:06 +0000795 {
Michal Krol2861e732004-03-29 11:09:34 +0000796 /* state[1] = {STATE_ENV, STATE_LOCAL} */
797 /* state[2] = parameter index */
Brian Paul824fdf02004-06-29 00:00:06 +0000798 const int idx = (int) state[2];
Michal Krol2861e732004-03-29 11:09:34 +0000799 switch (state[1]) {
800 case STATE_ENV:
Brian Paul824fdf02004-06-29 00:00:06 +0000801 COPY_4V(value, ctx->VertexProgram.Parameters[idx]);
Michal Krol2861e732004-03-29 11:09:34 +0000802 break;
Michal Krol2861e732004-03-29 11:09:34 +0000803 case STATE_LOCAL:
804 COPY_4V(value, ctx->VertexProgram.Current->Base.LocalParams[idx]);
Brian Paul824fdf02004-06-29 00:00:06 +0000805 break;
Michal Krol2861e732004-03-29 11:09:34 +0000806 default:
807 _mesa_problem(ctx, "Bad state switch in _mesa_fetch_state()");
808 return;
Brian Paul824fdf02004-06-29 00:00:06 +0000809 }
810 }
Michal Krol2861e732004-03-29 11:09:34 +0000811 return;
812 default:
Brian Paul824fdf02004-06-29 00:00:06 +0000813 _mesa_problem(ctx, "Invalid state in _mesa_fetch_state");
Michal Krol2861e732004-03-29 11:09:34 +0000814 return;
815 }
816}
817
818
819/**
820 * Loop over all the parameters in a parameter list. If the parameter
821 * is a GL state reference, look up the current value of that state
822 * variable and put it into the parameter's Value[4] array.
823 * This would be called at glBegin time when using a fragment program.
824 */
825void
826_mesa_load_state_parameters(GLcontext *ctx,
827 struct program_parameter_list *paramList)
828{
829 GLuint i;
830
831 if (!paramList)
832 return;
833
834 for (i = 0; i < paramList->NumParameters; i++) {
835 if (paramList->Parameters[i].Type == STATE) {
836 _mesa_fetch_state(ctx, paramList->Parameters[i].StateIndexes,
837 paramList->Parameters[i].Values);
838 }
839 }
840}
841
842
843
844/**********************************************************************/
845/* API functions */
846/**********************************************************************/
847
848
849/**
850 * Bind a program (make it current)
851 * \note Called from the GL API dispatcher by both glBindProgramNV
852 * and glBindProgramARB.
853 */
854void GLAPIENTRY
855_mesa_BindProgram(GLenum target, GLuint id)
856{
857 struct program *prog;
858 GET_CURRENT_CONTEXT(ctx);
859 ASSERT_OUTSIDE_BEGIN_END(ctx);
860
861 FLUSH_VERTICES(ctx, _NEW_PROGRAM);
862
863 if ((target == GL_VERTEX_PROGRAM_NV
864 && ctx->Extensions.NV_vertex_program) ||
865 (target == GL_VERTEX_PROGRAM_ARB
866 && ctx->Extensions.ARB_vertex_program)) {
867 if (ctx->VertexProgram.Current &&
868 ctx->VertexProgram.Current->Base.Id == id)
869 return;
870 /* decrement refcount on previously bound vertex program */
871 if (ctx->VertexProgram.Current) {
872 ctx->VertexProgram.Current->Base.RefCount--;
873 /* and delete if refcount goes below one */
874 if (ctx->VertexProgram.Current->Base.RefCount <= 0) {
875 ctx->Driver.DeleteProgram(ctx, &(ctx->VertexProgram.Current->Base));
876 _mesa_HashRemove(ctx->Shared->Programs, id);
877 }
878 }
879 }
880 else if ((target == GL_FRAGMENT_PROGRAM_NV
881 && ctx->Extensions.NV_fragment_program) ||
882 (target == GL_FRAGMENT_PROGRAM_ARB
883 && ctx->Extensions.ARB_fragment_program)) {
884 if (ctx->FragmentProgram.Current &&
885 ctx->FragmentProgram.Current->Base.Id == id)
886 return;
887 /* decrement refcount on previously bound fragment program */
888 if (ctx->FragmentProgram.Current) {
889 ctx->FragmentProgram.Current->Base.RefCount--;
890 /* and delete if refcount goes below one */
891 if (ctx->FragmentProgram.Current->Base.RefCount <= 0) {
892 ctx->Driver.DeleteProgram(ctx, &(ctx->FragmentProgram.Current->Base));
893 _mesa_HashRemove(ctx->Shared->Programs, id);
894 }
895 }
896 }
897 else {
898 _mesa_error(ctx, GL_INVALID_ENUM, "glBindProgramNV/ARB(target)");
899 return;
900 }
901
902 /* NOTE: binding to a non-existant program is not an error.
903 * That's supposed to be caught in glBegin.
904 */
905 if (id == 0) {
906 /* default program */
907 prog = NULL;
908 if (target == GL_VERTEX_PROGRAM_NV || target == GL_VERTEX_PROGRAM_ARB)
909 prog = ctx->Shared->DefaultVertexProgram;
910 else
911 prog = ctx->Shared->DefaultFragmentProgram;
912 }
913 else {
914 prog = (struct program *) _mesa_HashLookup(ctx->Shared->Programs, id);
915 if (prog) {
916 if (prog->Target == 0) {
917 /* prog was allocated with glGenProgramsNV */
918 prog->Target = target;
919 }
920 else if (prog->Target != target) {
921 _mesa_error(ctx, GL_INVALID_OPERATION,
922 "glBindProgramNV/ARB(target mismatch)");
923 return;
924 }
925 }
926 else {
927 /* allocate a new program now */
928 prog = ctx->Driver.NewProgram(ctx, target, id);
929 if (!prog) {
930 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindProgramNV/ARB");
931 return;
932 }
Michal Krol2861e732004-03-29 11:09:34 +0000933 _mesa_HashInsert(ctx->Shared->Programs, id, prog);
934 }
935 }
936
937 /* bind now */
938 if (target == GL_VERTEX_PROGRAM_NV || target == GL_VERTEX_PROGRAM_ARB) {
939 ctx->VertexProgram.Current = (struct vertex_program *) prog;
940 }
941 else if (target == GL_FRAGMENT_PROGRAM_NV || target == GL_FRAGMENT_PROGRAM_ARB) {
942 ctx->FragmentProgram.Current = (struct fragment_program *) prog;
943 }
944
945 if (prog)
946 prog->RefCount++;
947
948 if (ctx->Driver.BindProgram)
949 ctx->Driver.BindProgram(ctx, target, prog);
950}
951
952
953/**
954 * Delete a list of programs.
955 * \note Not compiled into display lists.
956 * \note Called by both glDeleteProgramsNV and glDeleteProgramsARB.
957 */
958void GLAPIENTRY
959_mesa_DeletePrograms(GLsizei n, const GLuint *ids)
960{
961 GLint i;
962 GET_CURRENT_CONTEXT(ctx);
963 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
964
965 if (n < 0) {
966 _mesa_error( ctx, GL_INVALID_VALUE, "glDeleteProgramsNV" );
967 return;
968 }
969
970 for (i = 0; i < n; i++) {
971 if (ids[i] != 0) {
972 struct program *prog = (struct program *)
973 _mesa_HashLookup(ctx->Shared->Programs, ids[i]);
974 if (prog) {
975 if (prog->Target == GL_VERTEX_PROGRAM_NV ||
976 prog->Target == GL_VERTEX_STATE_PROGRAM_NV) {
977 if (ctx->VertexProgram.Current &&
978 ctx->VertexProgram.Current->Base.Id == ids[i]) {
979 /* unbind this currently bound program */
980 _mesa_BindProgram(prog->Target, 0);
981 }
982 }
983 else if (prog->Target == GL_FRAGMENT_PROGRAM_NV ||
984 prog->Target == GL_FRAGMENT_PROGRAM_ARB) {
985 if (ctx->FragmentProgram.Current &&
986 ctx->FragmentProgram.Current->Base.Id == ids[i]) {
987 /* unbind this currently bound program */
988 _mesa_BindProgram(prog->Target, 0);
989 }
990 }
991 else {
992 _mesa_problem(ctx, "bad target in glDeleteProgramsNV");
993 return;
994 }
995 prog->RefCount--;
996 if (prog->RefCount <= 0) {
997 ctx->Driver.DeleteProgram(ctx, prog);
998 }
999 }
Brian Paulc9a415662004-06-25 14:46:48 +00001000 /* Always remove entry from hash table.
1001 * This is necessary as we can't tell from HashLookup
1002 * whether the entry exists with data == 0, or if it
1003 * doesn't exist at all. As GenPrograms creates the first
1004 * case below, need to call Remove() to avoid memory leak:
1005 */
1006 _mesa_HashRemove(ctx->Shared->Programs, ids[i]);
Michal Krol2861e732004-03-29 11:09:34 +00001007 }
1008 }
1009}
1010
1011
1012/**
1013 * Generate a list of new program identifiers.
1014 * \note Not compiled into display lists.
1015 * \note Called by both glGenProgramsNV and glGenProgramsARB.
1016 */
1017void GLAPIENTRY
1018_mesa_GenPrograms(GLsizei n, GLuint *ids)
1019{
1020 GLuint first;
1021 GLuint i;
1022 GET_CURRENT_CONTEXT(ctx);
1023 ASSERT_OUTSIDE_BEGIN_END(ctx);
1024
1025 if (n < 0) {
1026 _mesa_error(ctx, GL_INVALID_VALUE, "glGenPrograms");
1027 return;
1028 }
1029
1030 if (!ids)
1031 return;
1032
1033 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->Programs, n);
1034
1035 for (i = 0; i < (GLuint) n; i++) {
1036 _mesa_HashInsert(ctx->Shared->Programs, first + i, 0);
1037 }
1038
1039 /* Return the program names */
1040 for (i = 0; i < (GLuint) n; i++) {
1041 ids[i] = first + i;
1042 }
1043}
1044
1045
1046/**
1047 * Determine if id names a program.
1048 * \note Not compiled into display lists.
1049 * \note Called from both glIsProgramNV and glIsProgramARB.
1050 * \param id is the program identifier
1051 * \return GL_TRUE if id is a program, else GL_FALSE.
1052 */
1053GLboolean GLAPIENTRY
1054_mesa_IsProgram(GLuint id)
1055{
1056 GET_CURRENT_CONTEXT(ctx);
1057 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
1058
1059 if (id == 0)
1060 return GL_FALSE;
1061
1062 if (_mesa_HashLookup(ctx->Shared->Programs, id))
1063 return GL_TRUE;
1064 else
1065 return GL_FALSE;
1066}
1067
1068
1069
1070/**********************************************************************/
1071/* GL_MESA_program_debug extension */
1072/**********************************************************************/
1073
1074
1075/* XXX temporary */
1076void
1077glProgramCallbackMESA(GLenum target, GLprogramcallbackMESA callback,
1078 GLvoid *data)
1079{
1080 _mesa_ProgramCallbackMESA(target, callback, data);
1081}
1082
1083
1084void
1085_mesa_ProgramCallbackMESA(GLenum target, GLprogramcallbackMESA callback,
1086 GLvoid *data)
1087{
1088 GET_CURRENT_CONTEXT(ctx);
1089
1090 switch (target) {
1091 case GL_FRAGMENT_PROGRAM_ARB:
1092 if (!ctx->Extensions.ARB_fragment_program) {
1093 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramCallbackMESA(target)");
1094 return;
1095 }
1096 ctx->FragmentProgram.Callback = callback;
1097 ctx->FragmentProgram.CallbackData = data;
1098 break;
1099 case GL_FRAGMENT_PROGRAM_NV:
1100 if (!ctx->Extensions.NV_fragment_program) {
1101 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramCallbackMESA(target)");
1102 return;
1103 }
1104 ctx->FragmentProgram.Callback = callback;
1105 ctx->FragmentProgram.CallbackData = data;
1106 break;
1107 case GL_VERTEX_PROGRAM_ARB: /* == GL_VERTEX_PROGRAM_NV */
1108 if (!ctx->Extensions.ARB_vertex_program &&
1109 !ctx->Extensions.NV_vertex_program) {
1110 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramCallbackMESA(target)");
1111 return;
1112 }
1113 ctx->VertexProgram.Callback = callback;
1114 ctx->VertexProgram.CallbackData = data;
1115 break;
1116 default:
1117 _mesa_error(ctx, GL_INVALID_ENUM, "glProgramCallbackMESA(target)");
1118 return;
1119 }
1120}
1121
1122
1123/* XXX temporary */
1124void
1125glGetProgramRegisterfvMESA(GLenum target,
1126 GLsizei len, const GLubyte *registerName,
1127 GLfloat *v)
1128{
1129 _mesa_GetProgramRegisterfvMESA(target, len, registerName, v);
1130}
1131
1132
1133void
1134_mesa_GetProgramRegisterfvMESA(GLenum target,
1135 GLsizei len, const GLubyte *registerName,
1136 GLfloat *v)
1137{
1138 char reg[1000];
1139 GET_CURRENT_CONTEXT(ctx);
1140
1141 /* We _should_ be inside glBegin/glEnd */
1142#if 0
1143 if (ctx->Driver.CurrentExecPrimitive == PRIM_OUTSIDE_BEGIN_END) {
1144 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetProgramRegisterfvMESA");
1145 return;
1146 }
1147#endif
1148
1149 /* make null-terminated copy of registerName */
1150 len = MIN2((unsigned int) len, sizeof(reg) - 1);
1151 _mesa_memcpy(reg, registerName, len);
1152 reg[len] = 0;
1153
1154 switch (target) {
1155 case GL_VERTEX_PROGRAM_NV:
1156 if (!ctx->Extensions.ARB_vertex_program &&
1157 !ctx->Extensions.NV_vertex_program) {
1158 _mesa_error(ctx, GL_INVALID_ENUM,
1159 "glGetProgramRegisterfvMESA(target)");
1160 return;
1161 }
Brian Paul6d460af2004-04-23 14:16:46 +00001162 if (!ctx->VertexProgram._Enabled) {
Michal Krol2861e732004-03-29 11:09:34 +00001163 _mesa_error(ctx, GL_INVALID_OPERATION,
1164 "glGetProgramRegisterfvMESA");
1165 return;
1166 }
1167 /* GL_NV_vertex_program */
1168 if (reg[0] == 'R') {
1169 /* Temp register */
1170 GLint i = _mesa_atoi(reg + 1);
1171 if (i >= (GLint)ctx->Const.MaxVertexProgramTemps) {
1172 _mesa_error(ctx, GL_INVALID_VALUE,
1173 "glGetProgramRegisterfvMESA(registerName)");
1174 return;
1175 }
1176 COPY_4V(v, ctx->VertexProgram.Temporaries[i]);
1177 }
1178 else if (reg[0] == 'v' && reg[1] == '[') {
1179 /* Vertex Input attribute */
1180 GLuint i;
1181 for (i = 0; i < ctx->Const.MaxVertexProgramAttribs; i++) {
1182 const char *name = _mesa_nv_vertex_input_register_name(i);
1183 char number[10];
1184 sprintf(number, "%d", i);
1185 if (_mesa_strncmp(reg + 2, name, 4) == 0 ||
1186 _mesa_strncmp(reg + 2, number, _mesa_strlen(number)) == 0) {
1187 COPY_4V(v, ctx->VertexProgram.Inputs[i]);
1188 return;
1189 }
1190 }
1191 _mesa_error(ctx, GL_INVALID_VALUE,
1192 "glGetProgramRegisterfvMESA(registerName)");
1193 return;
1194 }
1195 else if (reg[0] == 'o' && reg[1] == '[') {
1196 /* Vertex output attribute */
1197 }
1198 /* GL_ARB_vertex_program */
1199 else if (_mesa_strncmp(reg, "vertex.", 7) == 0) {
1200
1201 }
1202 else {
1203 _mesa_error(ctx, GL_INVALID_VALUE,
1204 "glGetProgramRegisterfvMESA(registerName)");
1205 return;
1206 }
1207 break;
1208 case GL_FRAGMENT_PROGRAM_ARB:
1209 if (!ctx->Extensions.ARB_fragment_program) {
1210 _mesa_error(ctx, GL_INVALID_ENUM,
1211 "glGetProgramRegisterfvMESA(target)");
1212 return;
1213 }
Brian Paul6d460af2004-04-23 14:16:46 +00001214 if (!ctx->FragmentProgram._Enabled) {
Michal Krol2861e732004-03-29 11:09:34 +00001215 _mesa_error(ctx, GL_INVALID_OPERATION,
1216 "glGetProgramRegisterfvMESA");
1217 return;
1218 }
1219 /* XXX to do */
1220 break;
1221 case GL_FRAGMENT_PROGRAM_NV:
1222 if (!ctx->Extensions.NV_fragment_program) {
1223 _mesa_error(ctx, GL_INVALID_ENUM,
1224 "glGetProgramRegisterfvMESA(target)");
1225 return;
1226 }
Brian Paul6d460af2004-04-23 14:16:46 +00001227 if (!ctx->FragmentProgram._Enabled) {
Michal Krol2861e732004-03-29 11:09:34 +00001228 _mesa_error(ctx, GL_INVALID_OPERATION,
1229 "glGetProgramRegisterfvMESA");
1230 return;
1231 }
1232 if (reg[0] == 'R') {
1233 /* Temp register */
1234 GLint i = _mesa_atoi(reg + 1);
1235 if (i >= (GLint)ctx->Const.MaxFragmentProgramTemps) {
1236 _mesa_error(ctx, GL_INVALID_VALUE,
1237 "glGetProgramRegisterfvMESA(registerName)");
1238 return;
1239 }
1240 COPY_4V(v, ctx->FragmentProgram.Machine.Temporaries[i]);
1241 }
1242 else if (reg[0] == 'f' && reg[1] == '[') {
1243 /* Fragment input attribute */
1244 GLuint i;
1245 for (i = 0; i < ctx->Const.MaxFragmentProgramAttribs; i++) {
1246 const char *name = _mesa_nv_fragment_input_register_name(i);
1247 if (_mesa_strncmp(reg + 2, name, 4) == 0) {
1248 COPY_4V(v, ctx->FragmentProgram.Machine.Inputs[i]);
1249 return;
1250 }
1251 }
1252 _mesa_error(ctx, GL_INVALID_VALUE,
1253 "glGetProgramRegisterfvMESA(registerName)");
1254 return;
1255 }
1256 else if (_mesa_strcmp(reg, "o[COLR]") == 0) {
1257 /* Fragment output color */
1258 COPY_4V(v, ctx->FragmentProgram.Machine.Outputs[FRAG_OUTPUT_COLR]);
1259 }
1260 else if (_mesa_strcmp(reg, "o[COLH]") == 0) {
1261 /* Fragment output color */
1262 COPY_4V(v, ctx->FragmentProgram.Machine.Outputs[FRAG_OUTPUT_COLH]);
1263 }
1264 else if (_mesa_strcmp(reg, "o[DEPR]") == 0) {
1265 /* Fragment output depth */
1266 COPY_4V(v, ctx->FragmentProgram.Machine.Outputs[FRAG_OUTPUT_DEPR]);
1267 }
1268 else {
1269 /* try user-defined identifiers */
1270 const GLfloat *value = _mesa_lookup_parameter_value(
1271 ctx->FragmentProgram.Current->Parameters, -1, reg);
1272 if (value) {
1273 COPY_4V(v, value);
1274 }
1275 else {
1276 _mesa_error(ctx, GL_INVALID_VALUE,
1277 "glGetProgramRegisterfvMESA(registerName)");
1278 return;
1279 }
1280 }
1281 break;
1282 default:
1283 _mesa_error(ctx, GL_INVALID_ENUM,
1284 "glGetProgramRegisterfvMESA(target)");
1285 return;
1286 }
1287
1288}