2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * 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 "main/shaderapi.h"
40 #include "program/arbprogparse.h"
41 #include "program/program.h"
42 #include "program/prog_print.h"
46 #define PATH_MAX _MAX_PATH
50 * Bind a program (make it current)
51 * \note Called from the GL API dispatcher by both glBindProgramNV
52 * and glBindProgramARB.
55 _mesa_BindProgramARB(GLenum target
, GLuint id
)
57 struct gl_program
*curProg
, *newProg
;
58 GET_CURRENT_CONTEXT(ctx
);
60 /* Error-check target and get curProg */
61 if (target
== GL_VERTEX_PROGRAM_ARB
&& ctx
->Extensions
.ARB_vertex_program
) {
62 curProg
= &ctx
->VertexProgram
.Current
->Base
;
64 else if (target
== GL_FRAGMENT_PROGRAM_ARB
65 && ctx
->Extensions
.ARB_fragment_program
) {
66 curProg
= &ctx
->FragmentProgram
.Current
->Base
;
69 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindProgramARB(target)");
74 * Get pointer to new program to bind.
75 * NOTE: binding to a non-existant program is not an error.
76 * That's supposed to be caught in glBegin.
79 /* Bind a default program */
81 if (target
== GL_VERTEX_PROGRAM_ARB
)
82 newProg
= &ctx
->Shared
->DefaultVertexProgram
->Base
;
84 newProg
= &ctx
->Shared
->DefaultFragmentProgram
->Base
;
87 /* Bind a user program */
88 newProg
= _mesa_lookup_program(ctx
, id
);
89 if (!newProg
|| newProg
== &_mesa_DummyProgram
) {
90 /* allocate a new program now */
91 newProg
= ctx
->Driver
.NewProgram(ctx
, target
, id
);
93 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindProgramARB");
96 _mesa_HashInsert(ctx
->Shared
->Programs
, id
, newProg
);
98 else if (newProg
->Target
!= target
) {
99 _mesa_error(ctx
, GL_INVALID_OPERATION
,
100 "glBindProgramARB(target mismatch)");
105 /** All error checking is complete now **/
107 if (curProg
->Id
== id
) {
108 /* binding same program - no change */
112 /* signal new program (and its new constants) */
113 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
| _NEW_PROGRAM_CONSTANTS
);
116 if (target
== GL_VERTEX_PROGRAM_ARB
) {
117 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
.Current
,
118 gl_vertex_program(newProg
));
120 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
121 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
.Current
,
122 gl_fragment_program(newProg
));
125 /* Never null pointers */
126 assert(ctx
->VertexProgram
.Current
);
127 assert(ctx
->FragmentProgram
.Current
);
129 if (ctx
->Driver
.BindProgram
)
130 ctx
->Driver
.BindProgram(ctx
, target
, newProg
);
135 * Delete a list of programs.
136 * \note Not compiled into display lists.
137 * \note Called by both glDeleteProgramsNV and glDeleteProgramsARB.
140 _mesa_DeleteProgramsARB(GLsizei n
, const GLuint
*ids
)
143 GET_CURRENT_CONTEXT(ctx
);
145 FLUSH_VERTICES(ctx
, 0);
148 _mesa_error( ctx
, GL_INVALID_VALUE
, "glDeleteProgramsNV" );
152 for (i
= 0; i
< n
; i
++) {
154 struct gl_program
*prog
= _mesa_lookup_program(ctx
, ids
[i
]);
155 if (prog
== &_mesa_DummyProgram
) {
156 _mesa_HashRemove(ctx
->Shared
->Programs
, ids
[i
]);
159 /* Unbind program if necessary */
160 switch (prog
->Target
) {
161 case GL_VERTEX_PROGRAM_ARB
:
162 if (ctx
->VertexProgram
.Current
&&
163 ctx
->VertexProgram
.Current
->Base
.Id
== ids
[i
]) {
164 /* unbind this currently bound program */
165 _mesa_BindProgramARB(prog
->Target
, 0);
168 case GL_FRAGMENT_PROGRAM_ARB
:
169 if (ctx
->FragmentProgram
.Current
&&
170 ctx
->FragmentProgram
.Current
->Base
.Id
== ids
[i
]) {
171 /* unbind this currently bound program */
172 _mesa_BindProgramARB(prog
->Target
, 0);
176 _mesa_problem(ctx
, "bad target in glDeleteProgramsNV");
179 /* The ID is immediately available for re-use now */
180 _mesa_HashRemove(ctx
->Shared
->Programs
, ids
[i
]);
181 _mesa_reference_program(ctx
, &prog
, NULL
);
189 * Generate a list of new program identifiers.
190 * \note Not compiled into display lists.
191 * \note Called by both glGenProgramsNV and glGenProgramsARB.
194 _mesa_GenProgramsARB(GLsizei n
, GLuint
*ids
)
198 GET_CURRENT_CONTEXT(ctx
);
201 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenPrograms");
208 _mesa_HashLockMutex(ctx
->Shared
->Programs
);
210 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->Programs
, n
);
212 /* Insert pointer to dummy program as placeholder */
213 for (i
= 0; i
< (GLuint
) n
; i
++) {
214 _mesa_HashInsertLocked(ctx
->Shared
->Programs
, first
+ i
,
215 &_mesa_DummyProgram
);
218 _mesa_HashUnlockMutex(ctx
->Shared
->Programs
);
220 /* Return the program names */
221 for (i
= 0; i
< (GLuint
) n
; i
++) {
228 * Determine if id names a vertex or fragment program.
229 * \note Not compiled into display lists.
230 * \note Called from both glIsProgramNV and glIsProgramARB.
231 * \param id is the program identifier
232 * \return GL_TRUE if id is a program, else GL_FALSE.
235 _mesa_IsProgramARB(GLuint id
)
237 struct gl_program
*prog
= NULL
;
238 GET_CURRENT_CONTEXT(ctx
);
239 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
244 prog
= _mesa_lookup_program(ctx
, id
);
245 if (prog
&& (prog
!= &_mesa_DummyProgram
))
252 get_local_param_pointer(struct gl_context
*ctx
, const char *func
,
253 GLenum target
, GLuint index
, GLfloat
**param
)
255 struct gl_program
*prog
;
258 if (target
== GL_VERTEX_PROGRAM_ARB
259 && ctx
->Extensions
.ARB_vertex_program
) {
260 prog
= &(ctx
->VertexProgram
.Current
->Base
);
261 maxParams
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxLocalParams
;
263 else if (target
== GL_FRAGMENT_PROGRAM_ARB
264 && ctx
->Extensions
.ARB_fragment_program
) {
265 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
266 maxParams
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxLocalParams
;
269 _mesa_error(ctx
, GL_INVALID_ENUM
,
274 if (index
>= maxParams
) {
275 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
279 if (!prog
->LocalParams
) {
280 prog
->LocalParams
= calloc(maxParams
, sizeof(float[4]));
281 if (!prog
->LocalParams
)
285 *param
= prog
->LocalParams
[index
];
291 get_env_param_pointer(struct gl_context
*ctx
, const char *func
,
292 GLenum target
, GLuint index
, GLfloat
**param
)
294 if (target
== GL_FRAGMENT_PROGRAM_ARB
295 && ctx
->Extensions
.ARB_fragment_program
) {
296 if (index
>= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxEnvParams
) {
297 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
300 *param
= ctx
->FragmentProgram
.Parameters
[index
];
303 else if (target
== GL_VERTEX_PROGRAM_ARB
&&
304 ctx
->Extensions
.ARB_vertex_program
) {
305 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxEnvParams
) {
306 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
309 *param
= ctx
->VertexProgram
.Parameters
[index
];
312 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
318 _mesa_ProgramStringARB(GLenum target
, GLenum format
, GLsizei len
,
319 const GLvoid
*string
)
321 struct gl_program
*base
;
323 GET_CURRENT_CONTEXT(ctx
);
325 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
327 if (!ctx
->Extensions
.ARB_vertex_program
328 && !ctx
->Extensions
.ARB_fragment_program
) {
329 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glProgramStringARB()");
333 if (format
!= GL_PROGRAM_FORMAT_ASCII_ARB
) {
334 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(format)");
338 if (target
== GL_VERTEX_PROGRAM_ARB
&& ctx
->Extensions
.ARB_vertex_program
) {
339 struct gl_vertex_program
*prog
= ctx
->VertexProgram
.Current
;
340 _mesa_parse_arb_vertex_program(ctx
, target
, string
, len
, prog
);
344 else if (target
== GL_FRAGMENT_PROGRAM_ARB
345 && ctx
->Extensions
.ARB_fragment_program
) {
346 struct gl_fragment_program
*prog
= ctx
->FragmentProgram
.Current
;
347 _mesa_parse_arb_fragment_program(ctx
, target
, string
, len
, prog
);
352 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(target)");
356 failed
= ctx
->Program
.ErrorPos
!= -1;
359 /* finally, give the program to the driver for translation/checking */
360 if (!ctx
->Driver
.ProgramStringNotify(ctx
, target
, base
)) {
362 _mesa_error(ctx
, GL_INVALID_OPERATION
,
363 "glProgramStringARB(rejected by driver");
367 if (ctx
->_Shader
->Flags
& GLSL_DUMP
) {
368 const char *shader_type
=
369 target
== GL_FRAGMENT_PROGRAM_ARB
? "fragment" : "vertex";
371 fprintf(stderr
, "ARB_%s_program source for program %d:\n",
372 shader_type
, base
->Id
);
373 fprintf(stderr
, "%s\n", (const char *) string
);
376 fprintf(stderr
, "ARB_%s_program %d failed to compile.\n",
377 shader_type
, base
->Id
);
379 fprintf(stderr
, "Mesa IR for ARB_%s_program %d:\n",
380 shader_type
, base
->Id
);
381 _mesa_print_program(base
);
382 fprintf(stderr
, "\n");
387 /* Capture vp-*.shader_test/fp-*.shader_test files. */
388 const char *capture_path
= _mesa_get_shader_capture_path();
389 if (capture_path
!= NULL
) {
391 char filename
[PATH_MAX
];
392 const char *shader_type
=
393 target
== GL_FRAGMENT_PROGRAM_ARB
? "fragment" : "vertex";
395 _mesa_snprintf(filename
, sizeof(filename
), "%s/%cp-%u.shader_test",
396 capture_path
, shader_type
[0], base
->Id
);
397 file
= fopen(filename
, "w");
400 "[require]\nGL_ARB_%s_program\n\n[%s program]\n%s\n",
401 shader_type
, shader_type
, (const char *) string
);
404 _mesa_warning(ctx
, "Failed to open %s", filename
);
411 * Set a program env parameter register.
412 * \note Called from the GL API dispatcher.
415 _mesa_ProgramEnvParameter4dARB(GLenum target
, GLuint index
,
416 GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
418 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
419 (GLfloat
) z
, (GLfloat
) w
);
424 * Set a program env parameter register.
425 * \note Called from the GL API dispatcher.
428 _mesa_ProgramEnvParameter4dvARB(GLenum target
, GLuint index
,
429 const GLdouble
*params
)
431 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) params
[0],
432 (GLfloat
) params
[1], (GLfloat
) params
[2],
433 (GLfloat
) params
[3]);
438 * Set a program env parameter register.
439 * \note Called from the GL API dispatcher.
442 _mesa_ProgramEnvParameter4fARB(GLenum target
, GLuint index
,
443 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
447 GET_CURRENT_CONTEXT(ctx
);
449 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
451 if (get_env_param_pointer(ctx
, "glProgramEnvParameter",
452 target
, index
, ¶m
)) {
453 ASSIGN_4V(param
, x
, y
, z
, w
);
460 * Set a program env parameter register.
461 * \note Called from the GL API dispatcher.
464 _mesa_ProgramEnvParameter4fvARB(GLenum target
, GLuint index
,
465 const GLfloat
*params
)
469 GET_CURRENT_CONTEXT(ctx
);
471 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
473 if (get_env_param_pointer(ctx
, "glProgramEnvParameter4fv",
474 target
, index
, ¶m
)) {
475 memcpy(param
, params
, 4 * sizeof(GLfloat
));
481 _mesa_ProgramEnvParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
482 const GLfloat
*params
)
484 GET_CURRENT_CONTEXT(ctx
);
487 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
490 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(count)");
493 if (target
== GL_FRAGMENT_PROGRAM_ARB
494 && ctx
->Extensions
.ARB_fragment_program
) {
495 if ((index
+ count
) > ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxEnvParams
) {
496 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
499 dest
= ctx
->FragmentProgram
.Parameters
[index
];
501 else if (target
== GL_VERTEX_PROGRAM_ARB
502 && ctx
->Extensions
.ARB_vertex_program
) {
503 if ((index
+ count
) > ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxEnvParams
) {
504 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
507 dest
= ctx
->VertexProgram
.Parameters
[index
];
510 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameters4fv(target)");
514 memcpy(dest
, params
, count
* 4 * sizeof(GLfloat
));
519 _mesa_GetProgramEnvParameterdvARB(GLenum target
, GLuint index
,
522 GET_CURRENT_CONTEXT(ctx
);
525 if (get_env_param_pointer(ctx
, "glGetProgramEnvParameterdv",
526 target
, index
, &fparam
)) {
527 COPY_4V(params
, fparam
);
533 _mesa_GetProgramEnvParameterfvARB(GLenum target
, GLuint index
,
538 GET_CURRENT_CONTEXT(ctx
);
540 if (get_env_param_pointer(ctx
, "glGetProgramEnvParameterfv",
541 target
, index
, ¶m
)) {
542 COPY_4V(params
, param
);
548 _mesa_ProgramLocalParameter4fARB(GLenum target
, GLuint index
,
549 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
551 GET_CURRENT_CONTEXT(ctx
);
554 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
556 if (get_local_param_pointer(ctx
, "glProgramLocalParameterARB",
557 target
, index
, ¶m
)) {
558 assert(index
< MAX_PROGRAM_LOCAL_PARAMS
);
559 ASSIGN_4V(param
, x
, y
, z
, w
);
565 _mesa_ProgramLocalParameter4fvARB(GLenum target
, GLuint index
,
566 const GLfloat
*params
)
568 _mesa_ProgramLocalParameter4fARB(target
, index
, params
[0], params
[1],
569 params
[2], params
[3]);
574 _mesa_ProgramLocalParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
575 const GLfloat
*params
)
577 GET_CURRENT_CONTEXT(ctx
);
580 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
583 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fv(count)");
586 if (get_local_param_pointer(ctx
, "glProgramLocalParameters4fvEXT",
587 target
, index
, &dest
)) {
588 GLuint maxParams
= target
== GL_FRAGMENT_PROGRAM_ARB
?
589 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxLocalParams
:
590 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxLocalParams
;
592 if ((index
+ count
) > maxParams
) {
593 _mesa_error(ctx
, GL_INVALID_VALUE
,
594 "glProgramLocalParameters4fvEXT(index + count)");
598 memcpy(dest
, params
, count
* 4 * sizeof(GLfloat
));
604 _mesa_ProgramLocalParameter4dARB(GLenum target
, GLuint index
,
605 GLdouble x
, GLdouble y
,
606 GLdouble z
, GLdouble w
)
608 _mesa_ProgramLocalParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
609 (GLfloat
) z
, (GLfloat
) w
);
614 _mesa_ProgramLocalParameter4dvARB(GLenum target
, GLuint index
,
615 const GLdouble
*params
)
617 _mesa_ProgramLocalParameter4fARB(target
, index
,
618 (GLfloat
) params
[0], (GLfloat
) params
[1],
619 (GLfloat
) params
[2], (GLfloat
) params
[3]);
624 _mesa_GetProgramLocalParameterfvARB(GLenum target
, GLuint index
,
628 GET_CURRENT_CONTEXT(ctx
);
630 if (get_local_param_pointer(ctx
, "glProgramLocalParameters4fvEXT",
631 target
, index
, ¶m
)) {
632 COPY_4V(params
, param
);
638 _mesa_GetProgramLocalParameterdvARB(GLenum target
, GLuint index
,
642 GET_CURRENT_CONTEXT(ctx
);
644 if (get_local_param_pointer(ctx
, "glProgramLocalParameters4fvEXT",
645 target
, index
, ¶m
)) {
646 COPY_4V(params
, param
);
652 _mesa_GetProgramivARB(GLenum target
, GLenum pname
, GLint
*params
)
654 const struct gl_program_constants
*limits
;
655 struct gl_program
*prog
;
656 GET_CURRENT_CONTEXT(ctx
);
658 if (target
== GL_VERTEX_PROGRAM_ARB
659 && ctx
->Extensions
.ARB_vertex_program
) {
660 prog
= &(ctx
->VertexProgram
.Current
->Base
);
661 limits
= &ctx
->Const
.Program
[MESA_SHADER_VERTEX
];
663 else if (target
== GL_FRAGMENT_PROGRAM_ARB
664 && ctx
->Extensions
.ARB_fragment_program
) {
665 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
666 limits
= &ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
];
669 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
676 /* Queries supported for both vertex and fragment programs */
678 case GL_PROGRAM_LENGTH_ARB
:
680 = prog
->String
? (GLint
) strlen((char *) prog
->String
) : 0;
682 case GL_PROGRAM_FORMAT_ARB
:
683 *params
= prog
->Format
;
685 case GL_PROGRAM_BINDING_ARB
:
688 case GL_PROGRAM_INSTRUCTIONS_ARB
:
689 *params
= prog
->NumInstructions
;
691 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB
:
692 *params
= limits
->MaxInstructions
;
694 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
695 *params
= prog
->NumNativeInstructions
;
697 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
698 *params
= limits
->MaxNativeInstructions
;
700 case GL_PROGRAM_TEMPORARIES_ARB
:
701 *params
= prog
->NumTemporaries
;
703 case GL_MAX_PROGRAM_TEMPORARIES_ARB
:
704 *params
= limits
->MaxTemps
;
706 case GL_PROGRAM_NATIVE_TEMPORARIES_ARB
:
707 *params
= prog
->NumNativeTemporaries
;
709 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB
:
710 *params
= limits
->MaxNativeTemps
;
712 case GL_PROGRAM_PARAMETERS_ARB
:
713 *params
= prog
->NumParameters
;
715 case GL_MAX_PROGRAM_PARAMETERS_ARB
:
716 *params
= limits
->MaxParameters
;
718 case GL_PROGRAM_NATIVE_PARAMETERS_ARB
:
719 *params
= prog
->NumNativeParameters
;
721 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB
:
722 *params
= limits
->MaxNativeParameters
;
724 case GL_PROGRAM_ATTRIBS_ARB
:
725 *params
= prog
->NumAttributes
;
727 case GL_MAX_PROGRAM_ATTRIBS_ARB
:
728 *params
= limits
->MaxAttribs
;
730 case GL_PROGRAM_NATIVE_ATTRIBS_ARB
:
731 *params
= prog
->NumNativeAttributes
;
733 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB
:
734 *params
= limits
->MaxNativeAttribs
;
736 case GL_PROGRAM_ADDRESS_REGISTERS_ARB
:
737 *params
= prog
->NumAddressRegs
;
739 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB
:
740 *params
= limits
->MaxAddressRegs
;
742 case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
743 *params
= prog
->NumNativeAddressRegs
;
745 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
746 *params
= limits
->MaxNativeAddressRegs
;
748 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB
:
749 *params
= limits
->MaxLocalParams
;
751 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB
:
752 *params
= limits
->MaxEnvParams
;
754 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB
:
756 * XXX we may not really need a driver callback here.
757 * If the number of native instructions, registers, etc. used
758 * are all below the maximums, we could return true.
759 * The spec says that even if this query returns true, there's
760 * no guarantee that the program will run in hardware.
763 /* default/null program */
766 else if (ctx
->Driver
.IsProgramNative
) {
768 *params
= ctx
->Driver
.IsProgramNative( ctx
, target
, prog
);
771 /* probably running in software */
776 /* continue with fragment-program only queries below */
781 * The following apply to fragment programs only (at this time)
783 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
784 const struct gl_fragment_program
*fp
= ctx
->FragmentProgram
.Current
;
786 case GL_PROGRAM_ALU_INSTRUCTIONS_ARB
:
787 *params
= fp
->Base
.NumNativeAluInstructions
;
789 case GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
790 *params
= fp
->Base
.NumAluInstructions
;
792 case GL_PROGRAM_TEX_INSTRUCTIONS_ARB
:
793 *params
= fp
->Base
.NumTexInstructions
;
795 case GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
796 *params
= fp
->Base
.NumNativeTexInstructions
;
798 case GL_PROGRAM_TEX_INDIRECTIONS_ARB
:
799 *params
= fp
->Base
.NumTexIndirections
;
801 case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
802 *params
= fp
->Base
.NumNativeTexIndirections
;
804 case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB
:
805 *params
= limits
->MaxAluInstructions
;
807 case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
808 *params
= limits
->MaxNativeAluInstructions
;
810 case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB
:
811 *params
= limits
->MaxTexInstructions
;
813 case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
814 *params
= limits
->MaxNativeTexInstructions
;
816 case GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB
:
817 *params
= limits
->MaxTexIndirections
;
819 case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
820 *params
= limits
->MaxNativeTexIndirections
;
823 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
827 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
834 _mesa_GetProgramStringARB(GLenum target
, GLenum pname
, GLvoid
*string
)
836 const struct gl_program
*prog
;
837 char *dst
= (char *) string
;
838 GET_CURRENT_CONTEXT(ctx
);
840 if (target
== GL_VERTEX_PROGRAM_ARB
) {
841 prog
= &(ctx
->VertexProgram
.Current
->Base
);
843 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
844 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
847 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(target)");
853 if (pname
!= GL_PROGRAM_STRING_ARB
) {
854 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(pname)");
859 memcpy(dst
, prog
->String
, strlen((char *) prog
->String
));