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/program.h"
45 * Mixing ARB and NV vertex/fragment programs can be tricky.
46 * Note: GL_VERTEX_PROGRAM_ARB == GL_VERTEX_PROGRAM_NV
47 * but, GL_FRAGMENT_PROGRAM_ARB != GL_FRAGMENT_PROGRAM_NV
48 * The two different fragment program targets are supposed to be compatible
49 * to some extent (see GL_ARB_fragment_program spec).
50 * This function does the compatibility check.
53 compatible_program_targets(GLenum t1
, GLenum t2
)
57 if (t1
== GL_FRAGMENT_PROGRAM_ARB
&& t2
== GL_FRAGMENT_PROGRAM_NV
)
59 if (t1
== GL_FRAGMENT_PROGRAM_NV
&& t2
== GL_FRAGMENT_PROGRAM_ARB
)
66 * Bind a program (make it current)
67 * \note Called from the GL API dispatcher by both glBindProgramNV
68 * and glBindProgramARB.
71 _mesa_BindProgram(GLenum target
, GLuint id
)
73 struct gl_program
*curProg
, *newProg
;
74 GET_CURRENT_CONTEXT(ctx
);
75 ASSERT_OUTSIDE_BEGIN_END(ctx
);
77 /* Error-check target and get curProg */
78 if (target
== GL_VERTEX_PROGRAM_ARB
&& ctx
->Extensions
.ARB_vertex_program
) {
79 curProg
= &ctx
->VertexProgram
.Current
->Base
;
81 else if ((target
== GL_FRAGMENT_PROGRAM_NV
82 && ctx
->Extensions
.NV_fragment_program
) ||
83 (target
== GL_FRAGMENT_PROGRAM_ARB
84 && ctx
->Extensions
.ARB_fragment_program
)) {
85 curProg
= &ctx
->FragmentProgram
.Current
->Base
;
88 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindProgramNV/ARB(target)");
93 * Get pointer to new program to bind.
94 * NOTE: binding to a non-existant program is not an error.
95 * That's supposed to be caught in glBegin.
98 /* Bind a default program */
100 if (target
== GL_VERTEX_PROGRAM_ARB
) /* == GL_VERTEX_PROGRAM_NV */
101 newProg
= &ctx
->Shared
->DefaultVertexProgram
->Base
;
103 newProg
= &ctx
->Shared
->DefaultFragmentProgram
->Base
;
106 /* Bind a user program */
107 newProg
= _mesa_lookup_program(ctx
, id
);
108 if (!newProg
|| newProg
== &_mesa_DummyProgram
) {
109 /* allocate a new program now */
110 newProg
= ctx
->Driver
.NewProgram(ctx
, target
, id
);
112 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindProgramNV/ARB");
115 _mesa_HashInsert(ctx
->Shared
->Programs
, id
, newProg
);
117 else if (!compatible_program_targets(newProg
->Target
, target
)) {
118 _mesa_error(ctx
, GL_INVALID_OPERATION
,
119 "glBindProgramNV/ARB(target mismatch)");
124 /** All error checking is complete now **/
126 if (curProg
->Id
== id
) {
127 /* binding same program - no change */
131 /* signal new program (and its new constants) */
132 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
| _NEW_PROGRAM_CONSTANTS
);
135 if (target
== GL_VERTEX_PROGRAM_ARB
) { /* == GL_VERTEX_PROGRAM_NV */
136 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
.Current
,
137 gl_vertex_program(newProg
));
139 else if (target
== GL_FRAGMENT_PROGRAM_NV
||
140 target
== GL_FRAGMENT_PROGRAM_ARB
) {
141 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
.Current
,
142 gl_fragment_program(newProg
));
145 /* Never null pointers */
146 ASSERT(ctx
->VertexProgram
.Current
);
147 ASSERT(ctx
->FragmentProgram
.Current
);
149 if (ctx
->Driver
.BindProgram
)
150 ctx
->Driver
.BindProgram(ctx
, target
, newProg
);
155 * Delete a list of programs.
156 * \note Not compiled into display lists.
157 * \note Called by both glDeleteProgramsNV and glDeleteProgramsARB.
160 _mesa_DeletePrograms(GLsizei n
, const GLuint
*ids
)
163 GET_CURRENT_CONTEXT(ctx
);
164 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
167 _mesa_error( ctx
, GL_INVALID_VALUE
, "glDeleteProgramsNV" );
171 for (i
= 0; i
< n
; i
++) {
173 struct gl_program
*prog
= _mesa_lookup_program(ctx
, ids
[i
]);
174 if (prog
== &_mesa_DummyProgram
) {
175 _mesa_HashRemove(ctx
->Shared
->Programs
, ids
[i
]);
178 /* Unbind program if necessary */
179 switch (prog
->Target
) {
180 case GL_VERTEX_PROGRAM_ARB
: /* == GL_VERTEX_PROGRAM_NV */
181 if (ctx
->VertexProgram
.Current
&&
182 ctx
->VertexProgram
.Current
->Base
.Id
== ids
[i
]) {
183 /* unbind this currently bound program */
184 _mesa_BindProgram(prog
->Target
, 0);
187 case GL_FRAGMENT_PROGRAM_NV
:
188 case GL_FRAGMENT_PROGRAM_ARB
:
189 if (ctx
->FragmentProgram
.Current
&&
190 ctx
->FragmentProgram
.Current
->Base
.Id
== ids
[i
]) {
191 /* unbind this currently bound program */
192 _mesa_BindProgram(prog
->Target
, 0);
196 _mesa_problem(ctx
, "bad target in glDeleteProgramsNV");
199 /* The ID is immediately available for re-use now */
200 _mesa_HashRemove(ctx
->Shared
->Programs
, ids
[i
]);
201 _mesa_reference_program(ctx
, &prog
, NULL
);
209 * Generate a list of new program identifiers.
210 * \note Not compiled into display lists.
211 * \note Called by both glGenProgramsNV and glGenProgramsARB.
214 _mesa_GenPrograms(GLsizei n
, GLuint
*ids
)
218 GET_CURRENT_CONTEXT(ctx
);
219 ASSERT_OUTSIDE_BEGIN_END(ctx
);
222 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenPrograms");
229 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->Programs
, n
);
231 /* Insert pointer to dummy program as placeholder */
232 for (i
= 0; i
< (GLuint
) n
; i
++) {
233 _mesa_HashInsert(ctx
->Shared
->Programs
, first
+ i
, &_mesa_DummyProgram
);
236 /* Return the program names */
237 for (i
= 0; i
< (GLuint
) n
; i
++) {
244 * Determine if id names a vertex or fragment program.
245 * \note Not compiled into display lists.
246 * \note Called from both glIsProgramNV and glIsProgramARB.
247 * \param id is the program identifier
248 * \return GL_TRUE if id is a program, else GL_FALSE.
251 _mesa_IsProgramARB(GLuint id
)
253 struct gl_program
*prog
= NULL
;
254 GET_CURRENT_CONTEXT(ctx
);
255 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
260 prog
= _mesa_lookup_program(ctx
, id
);
261 if (prog
&& (prog
!= &_mesa_DummyProgram
))
268 get_local_param_pointer(struct gl_context
*ctx
, const char *func
,
269 GLenum target
, GLuint index
, GLfloat
**param
)
271 struct gl_program
*prog
;
274 if (target
== GL_VERTEX_PROGRAM_ARB
275 && ctx
->Extensions
.ARB_vertex_program
) {
276 prog
= &(ctx
->VertexProgram
.Current
->Base
);
277 maxParams
= ctx
->Const
.VertexProgram
.MaxLocalParams
;
279 else if (target
== GL_FRAGMENT_PROGRAM_ARB
280 && ctx
->Extensions
.ARB_fragment_program
) {
281 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
282 maxParams
= ctx
->Const
.FragmentProgram
.MaxLocalParams
;
284 else if (target
== GL_FRAGMENT_PROGRAM_NV
285 && ctx
->Extensions
.NV_fragment_program
) {
286 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
287 maxParams
= MAX_NV_FRAGMENT_PROGRAM_PARAMS
;
290 _mesa_error(ctx
, GL_INVALID_ENUM
,
295 if (index
>= maxParams
) {
296 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
300 *param
= prog
->LocalParams
[index
];
306 get_env_param_pointer(struct gl_context
*ctx
, const char *func
,
307 GLenum target
, GLuint index
, GLfloat
**param
)
309 if (target
== GL_FRAGMENT_PROGRAM_ARB
310 && ctx
->Extensions
.ARB_fragment_program
) {
311 if (index
>= ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
312 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
315 *param
= ctx
->FragmentProgram
.Parameters
[index
];
318 else if (target
== GL_VERTEX_PROGRAM_ARB
&&
319 ctx
->Extensions
.ARB_vertex_program
) {
320 if (index
>= ctx
->Const
.VertexProgram
.MaxEnvParams
) {
321 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
324 *param
= ctx
->VertexProgram
.Parameters
[index
];
327 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
333 _mesa_ProgramStringARB(GLenum target
, GLenum format
, GLsizei len
,
334 const GLvoid
*string
)
336 struct gl_program
*base
;
337 GET_CURRENT_CONTEXT(ctx
);
338 ASSERT_OUTSIDE_BEGIN_END(ctx
);
340 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
342 if (!ctx
->Extensions
.ARB_vertex_program
343 && !ctx
->Extensions
.ARB_fragment_program
) {
344 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glProgramStringARB()");
348 if (format
!= GL_PROGRAM_FORMAT_ASCII_ARB
) {
349 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(format)");
353 if (target
== GL_VERTEX_PROGRAM_ARB
&& ctx
->Extensions
.ARB_vertex_program
) {
354 struct gl_vertex_program
*prog
= ctx
->VertexProgram
.Current
;
355 _mesa_parse_arb_vertex_program(ctx
, target
, string
, len
, prog
);
359 else if (target
== GL_FRAGMENT_PROGRAM_ARB
360 && ctx
->Extensions
.ARB_fragment_program
) {
361 struct gl_fragment_program
*prog
= ctx
->FragmentProgram
.Current
;
362 _mesa_parse_arb_fragment_program(ctx
, target
, string
, len
, prog
);
367 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(target)");
371 if (ctx
->Program
.ErrorPos
== -1) {
372 /* finally, give the program to the driver for translation/checking */
373 if (!ctx
->Driver
.ProgramStringNotify(ctx
, target
, base
)) {
374 _mesa_error(ctx
, GL_INVALID_OPERATION
,
375 "glProgramStringARB(rejected by driver");
382 * Set a program env parameter register.
383 * \note Called from the GL API dispatcher.
386 _mesa_ProgramEnvParameter4dARB(GLenum target
, GLuint index
,
387 GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
389 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
390 (GLfloat
) z
, (GLfloat
) w
);
395 * Set a program env parameter register.
396 * \note Called from the GL API dispatcher.
399 _mesa_ProgramEnvParameter4dvARB(GLenum target
, GLuint index
,
400 const GLdouble
*params
)
402 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) params
[0],
403 (GLfloat
) params
[1], (GLfloat
) params
[2],
404 (GLfloat
) params
[3]);
409 * Set a program env parameter register.
410 * \note Called from the GL API dispatcher.
413 _mesa_ProgramEnvParameter4fARB(GLenum target
, GLuint index
,
414 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
418 GET_CURRENT_CONTEXT(ctx
);
419 ASSERT_OUTSIDE_BEGIN_END(ctx
);
421 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
423 if (get_env_param_pointer(ctx
, "glProgramEnvParameter",
424 target
, index
, ¶m
)) {
425 ASSIGN_4V(param
, x
, y
, z
, w
);
432 * Set a program env parameter register.
433 * \note Called from the GL API dispatcher.
436 _mesa_ProgramEnvParameter4fvARB(GLenum target
, GLuint index
,
437 const GLfloat
*params
)
441 GET_CURRENT_CONTEXT(ctx
);
442 ASSERT_OUTSIDE_BEGIN_END(ctx
);
444 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
446 if (get_env_param_pointer(ctx
, "glProgramEnvParameter4fv",
447 target
, index
, ¶m
)) {
448 memcpy(param
, params
, 4 * sizeof(GLfloat
));
454 _mesa_ProgramEnvParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
455 const GLfloat
*params
)
457 GET_CURRENT_CONTEXT(ctx
);
459 ASSERT_OUTSIDE_BEGIN_END(ctx
);
461 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
464 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(count)");
467 if (target
== GL_FRAGMENT_PROGRAM_ARB
468 && ctx
->Extensions
.ARB_fragment_program
) {
469 if ((index
+ count
) > ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
470 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
473 dest
= ctx
->FragmentProgram
.Parameters
[index
];
475 else if (target
== GL_VERTEX_PROGRAM_ARB
476 && ctx
->Extensions
.ARB_vertex_program
) {
477 if ((index
+ count
) > ctx
->Const
.VertexProgram
.MaxEnvParams
) {
478 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
481 dest
= ctx
->VertexProgram
.Parameters
[index
];
484 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameters4fv(target)");
488 memcpy(dest
, params
, count
* 4 * sizeof(GLfloat
));
493 _mesa_GetProgramEnvParameterdvARB(GLenum target
, GLuint index
,
496 GET_CURRENT_CONTEXT(ctx
);
499 if (get_env_param_pointer(ctx
, "glGetProgramEnvParameterdv",
500 target
, index
, &fparam
)) {
501 COPY_4V(params
, fparam
);
507 _mesa_GetProgramEnvParameterfvARB(GLenum target
, GLuint index
,
512 GET_CURRENT_CONTEXT(ctx
);
514 ASSERT_OUTSIDE_BEGIN_END(ctx
);
516 if (get_env_param_pointer(ctx
, "glGetProgramEnvParameterfv",
517 target
, index
, ¶m
)) {
518 COPY_4V(params
, param
);
524 * Note, this function is also used by the GL_NV_fragment_program extension.
527 _mesa_ProgramLocalParameter4fARB(GLenum target
, GLuint index
,
528 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
530 GET_CURRENT_CONTEXT(ctx
);
532 ASSERT_OUTSIDE_BEGIN_END(ctx
);
534 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
536 if (get_local_param_pointer(ctx
, "glProgramLocalParameterARB",
537 target
, index
, ¶m
)) {
538 ASSERT(index
< MAX_PROGRAM_LOCAL_PARAMS
);
539 ASSIGN_4V(param
, x
, y
, z
, w
);
545 * Note, this function is also used by the GL_NV_fragment_program extension.
548 _mesa_ProgramLocalParameter4fvARB(GLenum target
, GLuint index
,
549 const GLfloat
*params
)
551 _mesa_ProgramLocalParameter4fARB(target
, index
, params
[0], params
[1],
552 params
[2], params
[3]);
557 _mesa_ProgramLocalParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
558 const GLfloat
*params
)
560 GET_CURRENT_CONTEXT(ctx
);
562 ASSERT_OUTSIDE_BEGIN_END(ctx
);
564 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
567 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fv(count)");
570 if (target
== GL_FRAGMENT_PROGRAM_ARB
571 && ctx
->Extensions
.ARB_fragment_program
) {
572 if ((index
+ count
) > ctx
->Const
.FragmentProgram
.MaxLocalParams
) {
573 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fvEXT(index + count)");
576 dest
= ctx
->FragmentProgram
.Current
->Base
.LocalParams
[index
];
578 else if (target
== GL_VERTEX_PROGRAM_ARB
579 && ctx
->Extensions
.ARB_vertex_program
) {
580 if ((index
+ count
) > ctx
->Const
.VertexProgram
.MaxLocalParams
) {
581 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fvEXT(index + count)");
584 dest
= ctx
->VertexProgram
.Current
->Base
.LocalParams
[index
];
587 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameters4fvEXT(target)");
591 memcpy(dest
, params
, count
* 4 * sizeof(GLfloat
));
596 * Note, this function is also used by the GL_NV_fragment_program extension.
599 _mesa_ProgramLocalParameter4dARB(GLenum target
, GLuint index
,
600 GLdouble x
, GLdouble y
,
601 GLdouble z
, GLdouble w
)
603 _mesa_ProgramLocalParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
604 (GLfloat
) z
, (GLfloat
) w
);
609 * Note, this function is also used by the GL_NV_fragment_program extension.
612 _mesa_ProgramLocalParameter4dvARB(GLenum target
, GLuint index
,
613 const GLdouble
*params
)
615 _mesa_ProgramLocalParameter4fARB(target
, index
,
616 (GLfloat
) params
[0], (GLfloat
) params
[1],
617 (GLfloat
) params
[2], (GLfloat
) params
[3]);
622 * Note, this function is also used by the GL_NV_fragment_program extension.
625 _mesa_GetProgramLocalParameterfvARB(GLenum target
, GLuint index
,
629 GET_CURRENT_CONTEXT(ctx
);
630 ASSERT_OUTSIDE_BEGIN_END(ctx
);
632 if (get_local_param_pointer(ctx
, "glProgramLocalParameters4fvEXT",
633 target
, index
, ¶m
)) {
634 COPY_4V(params
, param
);
640 * Note, this function is also used by the GL_NV_fragment_program extension.
643 _mesa_GetProgramLocalParameterdvARB(GLenum target
, GLuint index
,
647 GET_CURRENT_CONTEXT(ctx
);
648 ASSERT_OUTSIDE_BEGIN_END(ctx
);
650 if (get_local_param_pointer(ctx
, "glProgramLocalParameters4fvEXT",
651 target
, index
, ¶m
)) {
652 COPY_4V(params
, param
);
658 _mesa_GetProgramivARB(GLenum target
, GLenum pname
, GLint
*params
)
660 const struct gl_program_constants
*limits
;
661 struct gl_program
*prog
;
662 GET_CURRENT_CONTEXT(ctx
);
664 ASSERT_OUTSIDE_BEGIN_END(ctx
);
666 if (target
== GL_VERTEX_PROGRAM_ARB
667 && ctx
->Extensions
.ARB_vertex_program
) {
668 prog
= &(ctx
->VertexProgram
.Current
->Base
);
669 limits
= &ctx
->Const
.VertexProgram
;
671 else if (target
== GL_FRAGMENT_PROGRAM_ARB
672 && ctx
->Extensions
.ARB_fragment_program
) {
673 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
674 limits
= &ctx
->Const
.FragmentProgram
;
677 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
684 /* Queries supported for both vertex and fragment programs */
686 case GL_PROGRAM_LENGTH_ARB
:
688 = prog
->String
? (GLint
) strlen((char *) prog
->String
) : 0;
690 case GL_PROGRAM_FORMAT_ARB
:
691 *params
= prog
->Format
;
693 case GL_PROGRAM_BINDING_ARB
:
696 case GL_PROGRAM_INSTRUCTIONS_ARB
:
697 *params
= prog
->NumInstructions
;
699 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB
:
700 *params
= limits
->MaxInstructions
;
702 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
703 *params
= prog
->NumNativeInstructions
;
705 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
706 *params
= limits
->MaxNativeInstructions
;
708 case GL_PROGRAM_TEMPORARIES_ARB
:
709 *params
= prog
->NumTemporaries
;
711 case GL_MAX_PROGRAM_TEMPORARIES_ARB
:
712 *params
= limits
->MaxTemps
;
714 case GL_PROGRAM_NATIVE_TEMPORARIES_ARB
:
715 *params
= prog
->NumNativeTemporaries
;
717 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB
:
718 *params
= limits
->MaxNativeTemps
;
720 case GL_PROGRAM_PARAMETERS_ARB
:
721 *params
= prog
->NumParameters
;
723 case GL_MAX_PROGRAM_PARAMETERS_ARB
:
724 *params
= limits
->MaxParameters
;
726 case GL_PROGRAM_NATIVE_PARAMETERS_ARB
:
727 *params
= prog
->NumNativeParameters
;
729 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB
:
730 *params
= limits
->MaxNativeParameters
;
732 case GL_PROGRAM_ATTRIBS_ARB
:
733 *params
= prog
->NumAttributes
;
735 case GL_MAX_PROGRAM_ATTRIBS_ARB
:
736 *params
= limits
->MaxAttribs
;
738 case GL_PROGRAM_NATIVE_ATTRIBS_ARB
:
739 *params
= prog
->NumNativeAttributes
;
741 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB
:
742 *params
= limits
->MaxNativeAttribs
;
744 case GL_PROGRAM_ADDRESS_REGISTERS_ARB
:
745 *params
= prog
->NumAddressRegs
;
747 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB
:
748 *params
= limits
->MaxAddressRegs
;
750 case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
751 *params
= prog
->NumNativeAddressRegs
;
753 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
754 *params
= limits
->MaxNativeAddressRegs
;
756 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB
:
757 *params
= limits
->MaxLocalParams
;
759 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB
:
760 *params
= limits
->MaxEnvParams
;
762 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB
:
764 * XXX we may not really need a driver callback here.
765 * If the number of native instructions, registers, etc. used
766 * are all below the maximums, we could return true.
767 * The spec says that even if this query returns true, there's
768 * no guarantee that the program will run in hardware.
771 /* default/null program */
774 else if (ctx
->Driver
.IsProgramNative
) {
776 *params
= ctx
->Driver
.IsProgramNative( ctx
, target
, prog
);
779 /* probably running in software */
784 /* continue with fragment-program only queries below */
789 * The following apply to fragment programs only (at this time)
791 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
792 const struct gl_fragment_program
*fp
= ctx
->FragmentProgram
.Current
;
794 case GL_PROGRAM_ALU_INSTRUCTIONS_ARB
:
795 *params
= fp
->Base
.NumNativeAluInstructions
;
797 case GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
798 *params
= fp
->Base
.NumAluInstructions
;
800 case GL_PROGRAM_TEX_INSTRUCTIONS_ARB
:
801 *params
= fp
->Base
.NumTexInstructions
;
803 case GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
804 *params
= fp
->Base
.NumNativeTexInstructions
;
806 case GL_PROGRAM_TEX_INDIRECTIONS_ARB
:
807 *params
= fp
->Base
.NumTexIndirections
;
809 case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
810 *params
= fp
->Base
.NumNativeTexIndirections
;
812 case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB
:
813 *params
= limits
->MaxAluInstructions
;
815 case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
816 *params
= limits
->MaxNativeAluInstructions
;
818 case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB
:
819 *params
= limits
->MaxTexInstructions
;
821 case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
822 *params
= limits
->MaxNativeTexInstructions
;
824 case GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB
:
825 *params
= limits
->MaxTexIndirections
;
827 case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
828 *params
= limits
->MaxNativeTexIndirections
;
831 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
835 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
842 _mesa_GetProgramStringARB(GLenum target
, GLenum pname
, GLvoid
*string
)
844 const struct gl_program
*prog
;
845 char *dst
= (char *) string
;
846 GET_CURRENT_CONTEXT(ctx
);
848 ASSERT_OUTSIDE_BEGIN_END(ctx
);
850 if (target
== GL_VERTEX_PROGRAM_ARB
) {
851 prog
= &(ctx
->VertexProgram
.Current
->Base
);
853 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
854 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
857 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(target)");
863 if (pname
!= GL_PROGRAM_STRING_ARB
) {
864 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(pname)");
869 memcpy(dst
, prog
->String
, strlen((char *) prog
->String
));