2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * ARB_vertex/fragment_program state management functions.
32 #include "main/glheader.h"
33 #include "main/context.h"
34 #include "main/hash.h"
35 #include "main/imports.h"
36 #include "main/macros.h"
37 #include "main/mtypes.h"
38 #include "main/arbprogram.h"
39 #include "program/arbprogparse.h"
40 #include "program/nvfragparse.h"
41 #include "program/nvvertparse.h"
42 #include "program/program.h"
47 * Mixing ARB and NV vertex/fragment programs can be tricky.
48 * Note: GL_VERTEX_PROGRAM_ARB == GL_VERTEX_PROGRAM_NV
49 * but, GL_FRAGMENT_PROGRAM_ARB != GL_FRAGMENT_PROGRAM_NV
50 * The two different fragment program targets are supposed to be compatible
51 * to some extent (see GL_ARB_fragment_program spec).
52 * This function does the compatibility check.
55 compatible_program_targets(GLenum t1
, GLenum t2
)
59 if (t1
== GL_FRAGMENT_PROGRAM_ARB
&& t2
== GL_FRAGMENT_PROGRAM_NV
)
61 if (t1
== GL_FRAGMENT_PROGRAM_NV
&& t2
== GL_FRAGMENT_PROGRAM_ARB
)
68 * Bind a program (make it current)
69 * \note Called from the GL API dispatcher by both glBindProgramNV
70 * and glBindProgramARB.
73 _mesa_BindProgram(GLenum target
, GLuint id
)
75 struct gl_program
*curProg
, *newProg
;
76 GET_CURRENT_CONTEXT(ctx
);
77 ASSERT_OUTSIDE_BEGIN_END(ctx
);
79 /* Error-check target and get curProg */
80 if ((target
== GL_VERTEX_PROGRAM_ARB
) && /* == GL_VERTEX_PROGRAM_NV */
81 (ctx
->Extensions
.NV_vertex_program
||
82 ctx
->Extensions
.ARB_vertex_program
)) {
83 curProg
= &ctx
->VertexProgram
.Current
->Base
;
85 else if ((target
== GL_FRAGMENT_PROGRAM_NV
86 && ctx
->Extensions
.NV_fragment_program
) ||
87 (target
== GL_FRAGMENT_PROGRAM_ARB
88 && ctx
->Extensions
.ARB_fragment_program
)) {
89 curProg
= &ctx
->FragmentProgram
.Current
->Base
;
92 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindProgramNV/ARB(target)");
97 * Get pointer to new program to bind.
98 * NOTE: binding to a non-existant program is not an error.
99 * That's supposed to be caught in glBegin.
102 /* Bind a default program */
104 if (target
== GL_VERTEX_PROGRAM_ARB
) /* == GL_VERTEX_PROGRAM_NV */
105 newProg
= &ctx
->Shared
->DefaultVertexProgram
->Base
;
107 newProg
= &ctx
->Shared
->DefaultFragmentProgram
->Base
;
110 /* Bind a user program */
111 newProg
= _mesa_lookup_program(ctx
, id
);
112 if (!newProg
|| newProg
== &_mesa_DummyProgram
) {
113 /* allocate a new program now */
114 newProg
= ctx
->Driver
.NewProgram(ctx
, target
, id
);
116 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindProgramNV/ARB");
119 _mesa_HashInsert(ctx
->Shared
->Programs
, id
, newProg
);
121 else if (!compatible_program_targets(newProg
->Target
, target
)) {
122 _mesa_error(ctx
, GL_INVALID_OPERATION
,
123 "glBindProgramNV/ARB(target mismatch)");
128 /** All error checking is complete now **/
130 if (curProg
->Id
== id
) {
131 /* binding same program - no change */
135 /* signal new program (and its new constants) */
136 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
| _NEW_PROGRAM_CONSTANTS
);
139 if (target
== GL_VERTEX_PROGRAM_ARB
) { /* == GL_VERTEX_PROGRAM_NV */
140 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
.Current
,
141 (struct gl_vertex_program
*) newProg
);
143 else if (target
== GL_FRAGMENT_PROGRAM_NV
||
144 target
== GL_FRAGMENT_PROGRAM_ARB
) {
145 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
.Current
,
146 (struct gl_fragment_program
*) newProg
);
149 /* Never null pointers */
150 ASSERT(ctx
->VertexProgram
.Current
);
151 ASSERT(ctx
->FragmentProgram
.Current
);
153 if (ctx
->Driver
.BindProgram
)
154 ctx
->Driver
.BindProgram(ctx
, target
, newProg
);
159 * Delete a list of programs.
160 * \note Not compiled into display lists.
161 * \note Called by both glDeleteProgramsNV and glDeleteProgramsARB.
164 _mesa_DeletePrograms(GLsizei n
, const GLuint
*ids
)
167 GET_CURRENT_CONTEXT(ctx
);
168 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
171 _mesa_error( ctx
, GL_INVALID_VALUE
, "glDeleteProgramsNV" );
175 for (i
= 0; i
< n
; i
++) {
177 struct gl_program
*prog
= _mesa_lookup_program(ctx
, ids
[i
]);
178 if (prog
== &_mesa_DummyProgram
) {
179 _mesa_HashRemove(ctx
->Shared
->Programs
, ids
[i
]);
182 /* Unbind program if necessary */
183 switch (prog
->Target
) {
184 case GL_VERTEX_PROGRAM_ARB
: /* == GL_VERTEX_PROGRAM_NV */
185 case GL_VERTEX_STATE_PROGRAM_NV
:
186 if (ctx
->VertexProgram
.Current
&&
187 ctx
->VertexProgram
.Current
->Base
.Id
== ids
[i
]) {
188 /* unbind this currently bound program */
189 _mesa_BindProgram(prog
->Target
, 0);
192 case GL_FRAGMENT_PROGRAM_NV
:
193 case GL_FRAGMENT_PROGRAM_ARB
:
194 if (ctx
->FragmentProgram
.Current
&&
195 ctx
->FragmentProgram
.Current
->Base
.Id
== ids
[i
]) {
196 /* unbind this currently bound program */
197 _mesa_BindProgram(prog
->Target
, 0);
201 _mesa_problem(ctx
, "bad target in glDeleteProgramsNV");
204 /* The ID is immediately available for re-use now */
205 _mesa_HashRemove(ctx
->Shared
->Programs
, ids
[i
]);
206 _mesa_reference_program(ctx
, &prog
, NULL
);
214 * Generate a list of new program identifiers.
215 * \note Not compiled into display lists.
216 * \note Called by both glGenProgramsNV and glGenProgramsARB.
219 _mesa_GenPrograms(GLsizei n
, GLuint
*ids
)
223 GET_CURRENT_CONTEXT(ctx
);
224 ASSERT_OUTSIDE_BEGIN_END(ctx
);
227 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenPrograms");
234 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->Programs
, n
);
236 /* Insert pointer to dummy program as placeholder */
237 for (i
= 0; i
< (GLuint
) n
; i
++) {
238 _mesa_HashInsert(ctx
->Shared
->Programs
, first
+ i
, &_mesa_DummyProgram
);
241 /* Return the program names */
242 for (i
= 0; i
< (GLuint
) n
; i
++) {
249 * Determine if id names a vertex or fragment program.
250 * \note Not compiled into display lists.
251 * \note Called from both glIsProgramNV and glIsProgramARB.
252 * \param id is the program identifier
253 * \return GL_TRUE if id is a program, else GL_FALSE.
256 _mesa_IsProgramARB(GLuint id
)
258 struct gl_program
*prog
= NULL
;
259 GET_CURRENT_CONTEXT(ctx
);
260 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
265 prog
= _mesa_lookup_program(ctx
, id
);
266 if (prog
&& (prog
!= &_mesa_DummyProgram
))
273 get_env_param_pointer(struct gl_context
*ctx
, const char *func
,
274 GLenum target
, GLuint index
, GLfloat
**param
)
276 if (target
== GL_FRAGMENT_PROGRAM_ARB
277 && ctx
->Extensions
.ARB_fragment_program
) {
278 if (index
>= ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
279 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
282 *param
= ctx
->FragmentProgram
.Parameters
[index
];
285 else if (target
== GL_VERTEX_PROGRAM_ARB
&&
286 (ctx
->Extensions
.ARB_vertex_program
||
287 ctx
->Extensions
.NV_vertex_program
)) {
288 if (index
>= ctx
->Const
.VertexProgram
.MaxEnvParams
) {
289 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
292 *param
= ctx
->VertexProgram
.Parameters
[index
];
295 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
301 _mesa_ProgramStringARB(GLenum target
, GLenum format
, GLsizei len
,
302 const GLvoid
*string
)
304 struct gl_program
*base
;
305 GET_CURRENT_CONTEXT(ctx
);
306 ASSERT_OUTSIDE_BEGIN_END(ctx
);
308 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
310 if (!ctx
->Extensions
.ARB_vertex_program
311 && !ctx
->Extensions
.ARB_fragment_program
) {
312 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glProgramStringARB()");
316 if (format
!= GL_PROGRAM_FORMAT_ASCII_ARB
) {
317 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(format)");
321 /* The first couple cases are complicated. The same enum value is used for
322 * ARB and NV vertex programs. If the target is a vertex program, parse it
323 * using the ARB grammar if the string starts with "!!ARB" or if
324 * NV_vertex_program is not supported.
326 if (target
== GL_VERTEX_PROGRAM_ARB
327 && ctx
->Extensions
.ARB_vertex_program
328 && ((strncmp(string
, "!!ARB", 5) == 0)
329 || !ctx
->Extensions
.NV_vertex_program
)) {
330 struct gl_vertex_program
*prog
= ctx
->VertexProgram
.Current
;
331 _mesa_parse_arb_vertex_program(ctx
, target
, string
, len
, prog
);
335 else if ((target
== GL_VERTEX_PROGRAM_ARB
336 || target
== GL_VERTEX_STATE_PROGRAM_NV
)
337 && ctx
->Extensions
.NV_vertex_program
) {
338 struct gl_vertex_program
*prog
= ctx
->VertexProgram
.Current
;
339 _mesa_parse_nv_vertex_program(ctx
, target
, string
, len
, prog
);
343 else if (target
== GL_FRAGMENT_PROGRAM_ARB
344 && ctx
->Extensions
.ARB_fragment_program
) {
345 struct gl_fragment_program
*prog
= ctx
->FragmentProgram
.Current
;
346 _mesa_parse_arb_fragment_program(ctx
, target
, string
, len
, prog
);
350 else if (target
== GL_FRAGMENT_PROGRAM_NV
351 && ctx
->Extensions
.NV_fragment_program
) {
352 struct gl_fragment_program
*prog
= ctx
->FragmentProgram
.Current
;
353 _mesa_parse_nv_fragment_program(ctx
, target
, string
, len
, prog
);
358 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(target)");
362 if (ctx
->Program
.ErrorPos
== -1) {
363 /* finally, give the program to the driver for translation/checking */
364 if (!ctx
->Driver
.ProgramStringNotify(ctx
, target
, base
)) {
365 _mesa_error(ctx
, GL_INVALID_OPERATION
,
366 "glProgramStringARB(rejected by driver");
373 * Set a program env parameter register.
374 * \note Called from the GL API dispatcher.
375 * Note, this function is also used by the GL_NV_vertex_program extension
376 * (alias to ProgramParameterdNV)
379 _mesa_ProgramEnvParameter4dARB(GLenum target
, GLuint index
,
380 GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
382 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
383 (GLfloat
) z
, (GLfloat
) w
);
388 * Set a program env parameter register.
389 * \note Called from the GL API dispatcher.
390 * Note, this function is also used by the GL_NV_vertex_program extension
391 * (alias to ProgramParameterdvNV)
394 _mesa_ProgramEnvParameter4dvARB(GLenum target
, GLuint index
,
395 const GLdouble
*params
)
397 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) params
[0],
398 (GLfloat
) params
[1], (GLfloat
) params
[2],
399 (GLfloat
) params
[3]);
404 * Set a program env parameter register.
405 * \note Called from the GL API dispatcher.
406 * Note, this function is also used by the GL_NV_vertex_program extension
407 * (alias to ProgramParameterfNV)
410 _mesa_ProgramEnvParameter4fARB(GLenum target
, GLuint index
,
411 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
415 GET_CURRENT_CONTEXT(ctx
);
416 ASSERT_OUTSIDE_BEGIN_END(ctx
);
418 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
420 if (get_env_param_pointer(ctx
, "glProgramEnvParameter",
421 target
, index
, ¶m
)) {
422 ASSIGN_4V(param
, x
, y
, z
, w
);
429 * Set a program env parameter register.
430 * \note Called from the GL API dispatcher.
431 * Note, this function is also used by the GL_NV_vertex_program extension
432 * (alias to ProgramParameterfvNV)
435 _mesa_ProgramEnvParameter4fvARB(GLenum target
, GLuint index
,
436 const GLfloat
*params
)
440 GET_CURRENT_CONTEXT(ctx
);
441 ASSERT_OUTSIDE_BEGIN_END(ctx
);
443 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
445 if (get_env_param_pointer(ctx
, "glProgramEnvParameter4fv",
446 target
, index
, ¶m
)) {
447 memcpy(param
, params
, 4 * sizeof(GLfloat
));
453 _mesa_ProgramEnvParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
454 const GLfloat
*params
)
456 GET_CURRENT_CONTEXT(ctx
);
458 ASSERT_OUTSIDE_BEGIN_END(ctx
);
460 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
463 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(count)");
466 if (target
== GL_FRAGMENT_PROGRAM_ARB
467 && ctx
->Extensions
.ARB_fragment_program
) {
468 if ((index
+ count
) > ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
469 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
472 dest
= ctx
->FragmentProgram
.Parameters
[index
];
474 else if (target
== GL_VERTEX_PROGRAM_ARB
475 && ctx
->Extensions
.ARB_vertex_program
) {
476 if ((index
+ count
) > ctx
->Const
.VertexProgram
.MaxEnvParams
) {
477 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
480 dest
= ctx
->VertexProgram
.Parameters
[index
];
483 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameters4fv(target)");
487 memcpy(dest
, params
, count
* 4 * sizeof(GLfloat
));
492 _mesa_GetProgramEnvParameterdvARB(GLenum target
, GLuint index
,
495 GET_CURRENT_CONTEXT(ctx
);
498 if (get_env_param_pointer(ctx
, "glGetProgramEnvParameterdv",
499 target
, index
, &fparam
)) {
500 COPY_4V(params
, fparam
);
506 _mesa_GetProgramEnvParameterfvARB(GLenum target
, GLuint index
,
511 GET_CURRENT_CONTEXT(ctx
);
513 ASSERT_OUTSIDE_BEGIN_END(ctx
);
515 if (get_env_param_pointer(ctx
, "glGetProgramEnvParameterfv",
516 target
, index
, ¶m
)) {
517 COPY_4V(params
, param
);
523 * Note, this function is also used by the GL_NV_fragment_program extension.
526 _mesa_ProgramLocalParameter4fARB(GLenum target
, GLuint index
,
527 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
529 GET_CURRENT_CONTEXT(ctx
);
530 struct gl_program
*prog
;
531 ASSERT_OUTSIDE_BEGIN_END(ctx
);
533 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
535 if ((target
== GL_FRAGMENT_PROGRAM_NV
536 && ctx
->Extensions
.NV_fragment_program
) ||
537 (target
== GL_FRAGMENT_PROGRAM_ARB
538 && ctx
->Extensions
.ARB_fragment_program
)) {
539 if (index
>= ctx
->Const
.FragmentProgram
.MaxLocalParams
) {
540 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameterARB");
543 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
545 else if (target
== GL_VERTEX_PROGRAM_ARB
546 && ctx
->Extensions
.ARB_vertex_program
) {
547 if (index
>= ctx
->Const
.VertexProgram
.MaxLocalParams
) {
548 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameterARB");
551 prog
= &(ctx
->VertexProgram
.Current
->Base
);
554 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameterARB");
558 ASSERT(index
< MAX_PROGRAM_LOCAL_PARAMS
);
559 prog
->LocalParams
[index
][0] = x
;
560 prog
->LocalParams
[index
][1] = y
;
561 prog
->LocalParams
[index
][2] = z
;
562 prog
->LocalParams
[index
][3] = w
;
567 * Note, this function is also used by the GL_NV_fragment_program extension.
570 _mesa_ProgramLocalParameter4fvARB(GLenum target
, GLuint index
,
571 const GLfloat
*params
)
573 _mesa_ProgramLocalParameter4fARB(target
, index
, params
[0], params
[1],
574 params
[2], params
[3]);
579 _mesa_ProgramLocalParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
580 const GLfloat
*params
)
582 GET_CURRENT_CONTEXT(ctx
);
584 ASSERT_OUTSIDE_BEGIN_END(ctx
);
586 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
589 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fv(count)");
592 if (target
== GL_FRAGMENT_PROGRAM_ARB
593 && ctx
->Extensions
.ARB_fragment_program
) {
594 if ((index
+ count
) > ctx
->Const
.FragmentProgram
.MaxLocalParams
) {
595 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fvEXT(index + count)");
598 dest
= ctx
->FragmentProgram
.Current
->Base
.LocalParams
[index
];
600 else if (target
== GL_VERTEX_PROGRAM_ARB
601 && ctx
->Extensions
.ARB_vertex_program
) {
602 if ((index
+ count
) > ctx
->Const
.VertexProgram
.MaxLocalParams
) {
603 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fvEXT(index + count)");
606 dest
= ctx
->VertexProgram
.Current
->Base
.LocalParams
[index
];
609 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameters4fvEXT(target)");
613 memcpy(dest
, params
, count
* 4 * sizeof(GLfloat
));
618 * Note, this function is also used by the GL_NV_fragment_program extension.
621 _mesa_ProgramLocalParameter4dARB(GLenum target
, GLuint index
,
622 GLdouble x
, GLdouble y
,
623 GLdouble z
, GLdouble w
)
625 _mesa_ProgramLocalParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
626 (GLfloat
) z
, (GLfloat
) w
);
631 * Note, this function is also used by the GL_NV_fragment_program extension.
634 _mesa_ProgramLocalParameter4dvARB(GLenum target
, GLuint index
,
635 const GLdouble
*params
)
637 _mesa_ProgramLocalParameter4fARB(target
, index
,
638 (GLfloat
) params
[0], (GLfloat
) params
[1],
639 (GLfloat
) params
[2], (GLfloat
) params
[3]);
644 * Note, this function is also used by the GL_NV_fragment_program extension.
647 _mesa_GetProgramLocalParameterfvARB(GLenum target
, GLuint index
,
650 const struct gl_program
*prog
;
652 GET_CURRENT_CONTEXT(ctx
);
653 ASSERT_OUTSIDE_BEGIN_END(ctx
);
655 if (target
== GL_VERTEX_PROGRAM_ARB
656 && ctx
->Extensions
.ARB_vertex_program
) {
657 prog
= &(ctx
->VertexProgram
.Current
->Base
);
658 maxParams
= ctx
->Const
.VertexProgram
.MaxLocalParams
;
660 else if (target
== GL_FRAGMENT_PROGRAM_ARB
661 && ctx
->Extensions
.ARB_fragment_program
) {
662 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
663 maxParams
= ctx
->Const
.FragmentProgram
.MaxLocalParams
;
665 else if (target
== GL_FRAGMENT_PROGRAM_NV
666 && ctx
->Extensions
.NV_fragment_program
) {
667 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
668 maxParams
= MAX_NV_FRAGMENT_PROGRAM_PARAMS
;
671 _mesa_error(ctx
, GL_INVALID_ENUM
,
672 "glGetProgramLocalParameterARB(target)");
676 if (index
>= maxParams
) {
677 _mesa_error(ctx
, GL_INVALID_VALUE
,
678 "glGetProgramLocalParameterARB(index)");
683 ASSERT(index
< MAX_PROGRAM_LOCAL_PARAMS
);
684 COPY_4V(params
, prog
->LocalParams
[index
]);
689 * Note, this function is also used by the GL_NV_fragment_program extension.
692 _mesa_GetProgramLocalParameterdvARB(GLenum target
, GLuint index
,
695 GET_CURRENT_CONTEXT(ctx
);
696 GLfloat floatParams
[4];
697 ASSIGN_4V(floatParams
, 0.0F
, 0.0F
, 0.0F
, 0.0F
);
698 _mesa_GetProgramLocalParameterfvARB(target
, index
, floatParams
);
699 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
700 COPY_4V(params
, floatParams
);
706 _mesa_GetProgramivARB(GLenum target
, GLenum pname
, GLint
*params
)
708 const struct gl_program_constants
*limits
;
709 struct gl_program
*prog
;
710 GET_CURRENT_CONTEXT(ctx
);
712 ASSERT_OUTSIDE_BEGIN_END(ctx
);
714 if (target
== GL_VERTEX_PROGRAM_ARB
715 && ctx
->Extensions
.ARB_vertex_program
) {
716 prog
= &(ctx
->VertexProgram
.Current
->Base
);
717 limits
= &ctx
->Const
.VertexProgram
;
719 else if (target
== GL_FRAGMENT_PROGRAM_ARB
720 && ctx
->Extensions
.ARB_fragment_program
) {
721 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
722 limits
= &ctx
->Const
.FragmentProgram
;
725 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
732 /* Queries supported for both vertex and fragment programs */
734 case GL_PROGRAM_LENGTH_ARB
:
736 = prog
->String
? (GLint
) strlen((char *) prog
->String
) : 0;
738 case GL_PROGRAM_FORMAT_ARB
:
739 *params
= prog
->Format
;
741 case GL_PROGRAM_BINDING_ARB
:
744 case GL_PROGRAM_INSTRUCTIONS_ARB
:
745 *params
= prog
->NumInstructions
;
747 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB
:
748 *params
= limits
->MaxInstructions
;
750 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
751 *params
= prog
->NumNativeInstructions
;
753 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
754 *params
= limits
->MaxNativeInstructions
;
756 case GL_PROGRAM_TEMPORARIES_ARB
:
757 *params
= prog
->NumTemporaries
;
759 case GL_MAX_PROGRAM_TEMPORARIES_ARB
:
760 *params
= limits
->MaxTemps
;
762 case GL_PROGRAM_NATIVE_TEMPORARIES_ARB
:
763 *params
= prog
->NumNativeTemporaries
;
765 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB
:
766 *params
= limits
->MaxNativeTemps
;
768 case GL_PROGRAM_PARAMETERS_ARB
:
769 *params
= prog
->NumParameters
;
771 case GL_MAX_PROGRAM_PARAMETERS_ARB
:
772 *params
= limits
->MaxParameters
;
774 case GL_PROGRAM_NATIVE_PARAMETERS_ARB
:
775 *params
= prog
->NumNativeParameters
;
777 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB
:
778 *params
= limits
->MaxNativeParameters
;
780 case GL_PROGRAM_ATTRIBS_ARB
:
781 *params
= prog
->NumAttributes
;
783 case GL_MAX_PROGRAM_ATTRIBS_ARB
:
784 *params
= limits
->MaxAttribs
;
786 case GL_PROGRAM_NATIVE_ATTRIBS_ARB
:
787 *params
= prog
->NumNativeAttributes
;
789 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB
:
790 *params
= limits
->MaxNativeAttribs
;
792 case GL_PROGRAM_ADDRESS_REGISTERS_ARB
:
793 *params
= prog
->NumAddressRegs
;
795 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB
:
796 *params
= limits
->MaxAddressRegs
;
798 case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
799 *params
= prog
->NumNativeAddressRegs
;
801 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
802 *params
= limits
->MaxNativeAddressRegs
;
804 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB
:
805 *params
= limits
->MaxLocalParams
;
807 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB
:
808 *params
= limits
->MaxEnvParams
;
810 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB
:
812 * XXX we may not really need a driver callback here.
813 * If the number of native instructions, registers, etc. used
814 * are all below the maximums, we could return true.
815 * The spec says that even if this query returns true, there's
816 * no guarantee that the program will run in hardware.
819 /* default/null program */
822 else if (ctx
->Driver
.IsProgramNative
) {
824 *params
= ctx
->Driver
.IsProgramNative( ctx
, target
, prog
);
827 /* probably running in software */
832 /* continue with fragment-program only queries below */
837 * The following apply to fragment programs only (at this time)
839 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
840 const struct gl_fragment_program
*fp
= ctx
->FragmentProgram
.Current
;
842 case GL_PROGRAM_ALU_INSTRUCTIONS_ARB
:
843 *params
= fp
->Base
.NumNativeAluInstructions
;
845 case GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
846 *params
= fp
->Base
.NumAluInstructions
;
848 case GL_PROGRAM_TEX_INSTRUCTIONS_ARB
:
849 *params
= fp
->Base
.NumTexInstructions
;
851 case GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
852 *params
= fp
->Base
.NumNativeTexInstructions
;
854 case GL_PROGRAM_TEX_INDIRECTIONS_ARB
:
855 *params
= fp
->Base
.NumTexIndirections
;
857 case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
858 *params
= fp
->Base
.NumNativeTexIndirections
;
860 case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB
:
861 *params
= limits
->MaxAluInstructions
;
863 case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
864 *params
= limits
->MaxNativeAluInstructions
;
866 case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB
:
867 *params
= limits
->MaxTexInstructions
;
869 case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
870 *params
= limits
->MaxNativeTexInstructions
;
872 case GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB
:
873 *params
= limits
->MaxTexIndirections
;
875 case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
876 *params
= limits
->MaxNativeTexIndirections
;
879 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
883 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
890 _mesa_GetProgramStringARB(GLenum target
, GLenum pname
, GLvoid
*string
)
892 const struct gl_program
*prog
;
893 char *dst
= (char *) string
;
894 GET_CURRENT_CONTEXT(ctx
);
896 ASSERT_OUTSIDE_BEGIN_END(ctx
);
898 if (target
== GL_VERTEX_PROGRAM_ARB
) {
899 prog
= &(ctx
->VertexProgram
.Current
->Base
);
901 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
902 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
905 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(target)");
911 if (pname
!= GL_PROGRAM_STRING_ARB
) {
912 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(pname)");
917 memcpy(dst
, prog
->String
, strlen((char *) prog
->String
));