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
;
64 else if (target
== GL_FRAGMENT_PROGRAM_ARB
65 && ctx
->Extensions
.ARB_fragment_program
) {
66 curProg
= ctx
->FragmentProgram
.Current
;
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
;
84 newProg
= ctx
->Shared
->DefaultFragmentProgram
;
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_program(ctx
, &ctx
->VertexProgram
.Current
, newProg
);
119 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
120 _mesa_reference_program(ctx
, &ctx
->FragmentProgram
.Current
, newProg
);
123 /* Never null pointers */
124 assert(ctx
->VertexProgram
.Current
);
125 assert(ctx
->FragmentProgram
.Current
);
127 if (ctx
->Driver
.BindProgram
)
128 ctx
->Driver
.BindProgram(ctx
, target
, newProg
);
133 * Delete a list of programs.
134 * \note Not compiled into display lists.
135 * \note Called by both glDeleteProgramsNV and glDeleteProgramsARB.
138 _mesa_DeleteProgramsARB(GLsizei n
, const GLuint
*ids
)
141 GET_CURRENT_CONTEXT(ctx
);
143 FLUSH_VERTICES(ctx
, 0);
146 _mesa_error( ctx
, GL_INVALID_VALUE
, "glDeleteProgramsNV" );
150 for (i
= 0; i
< n
; i
++) {
152 struct gl_program
*prog
= _mesa_lookup_program(ctx
, ids
[i
]);
153 if (prog
== &_mesa_DummyProgram
) {
154 _mesa_HashRemove(ctx
->Shared
->Programs
, ids
[i
]);
157 /* Unbind program if necessary */
158 switch (prog
->Target
) {
159 case GL_VERTEX_PROGRAM_ARB
:
160 if (ctx
->VertexProgram
.Current
&&
161 ctx
->VertexProgram
.Current
->Id
== ids
[i
]) {
162 /* unbind this currently bound program */
163 _mesa_BindProgramARB(prog
->Target
, 0);
166 case GL_FRAGMENT_PROGRAM_ARB
:
167 if (ctx
->FragmentProgram
.Current
&&
168 ctx
->FragmentProgram
.Current
->Id
== ids
[i
]) {
169 /* unbind this currently bound program */
170 _mesa_BindProgramARB(prog
->Target
, 0);
174 _mesa_problem(ctx
, "bad target in glDeleteProgramsNV");
177 /* The ID is immediately available for re-use now */
178 _mesa_HashRemove(ctx
->Shared
->Programs
, ids
[i
]);
179 _mesa_reference_program(ctx
, &prog
, NULL
);
187 * Generate a list of new program identifiers.
188 * \note Not compiled into display lists.
189 * \note Called by both glGenProgramsNV and glGenProgramsARB.
192 _mesa_GenProgramsARB(GLsizei n
, GLuint
*ids
)
196 GET_CURRENT_CONTEXT(ctx
);
199 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenPrograms");
206 _mesa_HashLockMutex(ctx
->Shared
->Programs
);
208 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->Programs
, n
);
210 /* Insert pointer to dummy program as placeholder */
211 for (i
= 0; i
< (GLuint
) n
; i
++) {
212 _mesa_HashInsertLocked(ctx
->Shared
->Programs
, first
+ i
,
213 &_mesa_DummyProgram
);
216 _mesa_HashUnlockMutex(ctx
->Shared
->Programs
);
218 /* Return the program names */
219 for (i
= 0; i
< (GLuint
) n
; i
++) {
226 * Determine if id names a vertex or fragment program.
227 * \note Not compiled into display lists.
228 * \note Called from both glIsProgramNV and glIsProgramARB.
229 * \param id is the program identifier
230 * \return GL_TRUE if id is a program, else GL_FALSE.
233 _mesa_IsProgramARB(GLuint id
)
235 struct gl_program
*prog
= NULL
;
236 GET_CURRENT_CONTEXT(ctx
);
237 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
242 prog
= _mesa_lookup_program(ctx
, id
);
243 if (prog
&& (prog
!= &_mesa_DummyProgram
))
250 get_local_param_pointer(struct gl_context
*ctx
, const char *func
,
251 GLenum target
, GLuint index
, GLfloat
**param
)
253 struct gl_program
*prog
;
256 if (target
== GL_VERTEX_PROGRAM_ARB
257 && ctx
->Extensions
.ARB_vertex_program
) {
258 prog
= ctx
->VertexProgram
.Current
;
259 maxParams
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxLocalParams
;
261 else if (target
== GL_FRAGMENT_PROGRAM_ARB
262 && ctx
->Extensions
.ARB_fragment_program
) {
263 prog
= ctx
->FragmentProgram
.Current
;
264 maxParams
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxLocalParams
;
267 _mesa_error(ctx
, GL_INVALID_ENUM
,
272 if (index
>= maxParams
) {
273 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
277 if (!prog
->LocalParams
) {
278 prog
->LocalParams
= calloc(maxParams
, sizeof(float[4]));
279 if (!prog
->LocalParams
)
283 *param
= prog
->LocalParams
[index
];
289 get_env_param_pointer(struct gl_context
*ctx
, const char *func
,
290 GLenum target
, GLuint index
, GLfloat
**param
)
292 if (target
== GL_FRAGMENT_PROGRAM_ARB
293 && ctx
->Extensions
.ARB_fragment_program
) {
294 if (index
>= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxEnvParams
) {
295 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
298 *param
= ctx
->FragmentProgram
.Parameters
[index
];
301 else if (target
== GL_VERTEX_PROGRAM_ARB
&&
302 ctx
->Extensions
.ARB_vertex_program
) {
303 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxEnvParams
) {
304 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
307 *param
= ctx
->VertexProgram
.Parameters
[index
];
310 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
316 _mesa_ProgramStringARB(GLenum target
, GLenum format
, GLsizei len
,
317 const GLvoid
*string
)
319 struct gl_program
*prog
;
321 GET_CURRENT_CONTEXT(ctx
);
323 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
325 if (!ctx
->Extensions
.ARB_vertex_program
326 && !ctx
->Extensions
.ARB_fragment_program
) {
327 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glProgramStringARB()");
331 if (format
!= GL_PROGRAM_FORMAT_ASCII_ARB
) {
332 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(format)");
336 if (target
== GL_VERTEX_PROGRAM_ARB
&& ctx
->Extensions
.ARB_vertex_program
) {
337 prog
= ctx
->VertexProgram
.Current
;
338 _mesa_parse_arb_vertex_program(ctx
, target
, string
, len
, prog
);
340 else if (target
== GL_FRAGMENT_PROGRAM_ARB
341 && ctx
->Extensions
.ARB_fragment_program
) {
342 prog
= ctx
->FragmentProgram
.Current
;
343 _mesa_parse_arb_fragment_program(ctx
, target
, string
, len
, prog
);
346 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(target)");
350 failed
= ctx
->Program
.ErrorPos
!= -1;
353 /* finally, give the program to the driver for translation/checking */
354 if (!ctx
->Driver
.ProgramStringNotify(ctx
, target
, prog
)) {
356 _mesa_error(ctx
, GL_INVALID_OPERATION
,
357 "glProgramStringARB(rejected by driver");
361 if (ctx
->_Shader
->Flags
& GLSL_DUMP
) {
362 const char *shader_type
=
363 target
== GL_FRAGMENT_PROGRAM_ARB
? "fragment" : "vertex";
365 fprintf(stderr
, "ARB_%s_program source for program %d:\n",
366 shader_type
, prog
->Id
);
367 fprintf(stderr
, "%s\n", (const char *) string
);
370 fprintf(stderr
, "ARB_%s_program %d failed to compile.\n",
371 shader_type
, prog
->Id
);
373 fprintf(stderr
, "Mesa IR for ARB_%s_program %d:\n",
374 shader_type
, prog
->Id
);
375 _mesa_print_program(prog
);
376 fprintf(stderr
, "\n");
381 /* Capture vp-*.shader_test/fp-*.shader_test files. */
382 const char *capture_path
= _mesa_get_shader_capture_path();
383 if (capture_path
!= NULL
) {
385 char filename
[PATH_MAX
];
386 const char *shader_type
=
387 target
== GL_FRAGMENT_PROGRAM_ARB
? "fragment" : "vertex";
389 _mesa_snprintf(filename
, sizeof(filename
), "%s/%cp-%u.shader_test",
390 capture_path
, shader_type
[0], prog
->Id
);
391 file
= fopen(filename
, "w");
394 "[require]\nGL_ARB_%s_program\n\n[%s program]\n%s\n",
395 shader_type
, shader_type
, (const char *) string
);
398 _mesa_warning(ctx
, "Failed to open %s", filename
);
405 * Set a program env parameter register.
406 * \note Called from the GL API dispatcher.
409 _mesa_ProgramEnvParameter4dARB(GLenum target
, GLuint index
,
410 GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
412 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
413 (GLfloat
) z
, (GLfloat
) w
);
418 * Set a program env parameter register.
419 * \note Called from the GL API dispatcher.
422 _mesa_ProgramEnvParameter4dvARB(GLenum target
, GLuint index
,
423 const GLdouble
*params
)
425 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) params
[0],
426 (GLfloat
) params
[1], (GLfloat
) params
[2],
427 (GLfloat
) params
[3]);
432 * Set a program env parameter register.
433 * \note Called from the GL API dispatcher.
436 _mesa_ProgramEnvParameter4fARB(GLenum target
, GLuint index
,
437 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
441 GET_CURRENT_CONTEXT(ctx
);
443 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
445 if (get_env_param_pointer(ctx
, "glProgramEnvParameter",
446 target
, index
, ¶m
)) {
447 ASSIGN_4V(param
, x
, y
, z
, w
);
454 * Set a program env parameter register.
455 * \note Called from the GL API dispatcher.
458 _mesa_ProgramEnvParameter4fvARB(GLenum target
, GLuint index
,
459 const GLfloat
*params
)
463 GET_CURRENT_CONTEXT(ctx
);
465 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
467 if (get_env_param_pointer(ctx
, "glProgramEnvParameter4fv",
468 target
, index
, ¶m
)) {
469 memcpy(param
, params
, 4 * sizeof(GLfloat
));
475 _mesa_ProgramEnvParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
476 const GLfloat
*params
)
478 GET_CURRENT_CONTEXT(ctx
);
481 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
484 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(count)");
487 if (target
== GL_FRAGMENT_PROGRAM_ARB
488 && ctx
->Extensions
.ARB_fragment_program
) {
489 if ((index
+ count
) > ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxEnvParams
) {
490 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
493 dest
= ctx
->FragmentProgram
.Parameters
[index
];
495 else if (target
== GL_VERTEX_PROGRAM_ARB
496 && ctx
->Extensions
.ARB_vertex_program
) {
497 if ((index
+ count
) > ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxEnvParams
) {
498 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
501 dest
= ctx
->VertexProgram
.Parameters
[index
];
504 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameters4fv(target)");
508 memcpy(dest
, params
, count
* 4 * sizeof(GLfloat
));
513 _mesa_GetProgramEnvParameterdvARB(GLenum target
, GLuint index
,
516 GET_CURRENT_CONTEXT(ctx
);
519 if (get_env_param_pointer(ctx
, "glGetProgramEnvParameterdv",
520 target
, index
, &fparam
)) {
521 COPY_4V(params
, fparam
);
527 _mesa_GetProgramEnvParameterfvARB(GLenum target
, GLuint index
,
532 GET_CURRENT_CONTEXT(ctx
);
534 if (get_env_param_pointer(ctx
, "glGetProgramEnvParameterfv",
535 target
, index
, ¶m
)) {
536 COPY_4V(params
, param
);
542 _mesa_ProgramLocalParameter4fARB(GLenum target
, GLuint index
,
543 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
545 GET_CURRENT_CONTEXT(ctx
);
548 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
550 if (get_local_param_pointer(ctx
, "glProgramLocalParameterARB",
551 target
, index
, ¶m
)) {
552 assert(index
< MAX_PROGRAM_LOCAL_PARAMS
);
553 ASSIGN_4V(param
, x
, y
, z
, w
);
559 _mesa_ProgramLocalParameter4fvARB(GLenum target
, GLuint index
,
560 const GLfloat
*params
)
562 _mesa_ProgramLocalParameter4fARB(target
, index
, params
[0], params
[1],
563 params
[2], params
[3]);
568 _mesa_ProgramLocalParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
569 const GLfloat
*params
)
571 GET_CURRENT_CONTEXT(ctx
);
574 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
577 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fv(count)");
580 if (get_local_param_pointer(ctx
, "glProgramLocalParameters4fvEXT",
581 target
, index
, &dest
)) {
582 GLuint maxParams
= target
== GL_FRAGMENT_PROGRAM_ARB
?
583 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxLocalParams
:
584 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxLocalParams
;
586 if ((index
+ count
) > maxParams
) {
587 _mesa_error(ctx
, GL_INVALID_VALUE
,
588 "glProgramLocalParameters4fvEXT(index + count)");
592 memcpy(dest
, params
, count
* 4 * sizeof(GLfloat
));
598 _mesa_ProgramLocalParameter4dARB(GLenum target
, GLuint index
,
599 GLdouble x
, GLdouble y
,
600 GLdouble z
, GLdouble w
)
602 _mesa_ProgramLocalParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
603 (GLfloat
) z
, (GLfloat
) w
);
608 _mesa_ProgramLocalParameter4dvARB(GLenum target
, GLuint index
,
609 const GLdouble
*params
)
611 _mesa_ProgramLocalParameter4fARB(target
, index
,
612 (GLfloat
) params
[0], (GLfloat
) params
[1],
613 (GLfloat
) params
[2], (GLfloat
) params
[3]);
618 _mesa_GetProgramLocalParameterfvARB(GLenum target
, GLuint index
,
622 GET_CURRENT_CONTEXT(ctx
);
624 if (get_local_param_pointer(ctx
, "glProgramLocalParameters4fvEXT",
625 target
, index
, ¶m
)) {
626 COPY_4V(params
, param
);
632 _mesa_GetProgramLocalParameterdvARB(GLenum target
, GLuint index
,
636 GET_CURRENT_CONTEXT(ctx
);
638 if (get_local_param_pointer(ctx
, "glProgramLocalParameters4fvEXT",
639 target
, index
, ¶m
)) {
640 COPY_4V(params
, param
);
646 _mesa_GetProgramivARB(GLenum target
, GLenum pname
, GLint
*params
)
648 const struct gl_program_constants
*limits
;
649 struct gl_program
*prog
;
650 GET_CURRENT_CONTEXT(ctx
);
652 if (target
== GL_VERTEX_PROGRAM_ARB
653 && ctx
->Extensions
.ARB_vertex_program
) {
654 prog
= ctx
->VertexProgram
.Current
;
655 limits
= &ctx
->Const
.Program
[MESA_SHADER_VERTEX
];
657 else if (target
== GL_FRAGMENT_PROGRAM_ARB
658 && ctx
->Extensions
.ARB_fragment_program
) {
659 prog
= ctx
->FragmentProgram
.Current
;
660 limits
= &ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
];
663 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
670 /* Queries supported for both vertex and fragment programs */
672 case GL_PROGRAM_LENGTH_ARB
:
674 = prog
->String
? (GLint
) strlen((char *) prog
->String
) : 0;
676 case GL_PROGRAM_FORMAT_ARB
:
677 *params
= prog
->Format
;
679 case GL_PROGRAM_BINDING_ARB
:
682 case GL_PROGRAM_INSTRUCTIONS_ARB
:
683 *params
= prog
->NumInstructions
;
685 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB
:
686 *params
= limits
->MaxInstructions
;
688 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
689 *params
= prog
->NumNativeInstructions
;
691 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
692 *params
= limits
->MaxNativeInstructions
;
694 case GL_PROGRAM_TEMPORARIES_ARB
:
695 *params
= prog
->NumTemporaries
;
697 case GL_MAX_PROGRAM_TEMPORARIES_ARB
:
698 *params
= limits
->MaxTemps
;
700 case GL_PROGRAM_NATIVE_TEMPORARIES_ARB
:
701 *params
= prog
->NumNativeTemporaries
;
703 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB
:
704 *params
= limits
->MaxNativeTemps
;
706 case GL_PROGRAM_PARAMETERS_ARB
:
707 *params
= prog
->NumParameters
;
709 case GL_MAX_PROGRAM_PARAMETERS_ARB
:
710 *params
= limits
->MaxParameters
;
712 case GL_PROGRAM_NATIVE_PARAMETERS_ARB
:
713 *params
= prog
->NumNativeParameters
;
715 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB
:
716 *params
= limits
->MaxNativeParameters
;
718 case GL_PROGRAM_ATTRIBS_ARB
:
719 *params
= prog
->NumAttributes
;
721 case GL_MAX_PROGRAM_ATTRIBS_ARB
:
722 *params
= limits
->MaxAttribs
;
724 case GL_PROGRAM_NATIVE_ATTRIBS_ARB
:
725 *params
= prog
->NumNativeAttributes
;
727 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB
:
728 *params
= limits
->MaxNativeAttribs
;
730 case GL_PROGRAM_ADDRESS_REGISTERS_ARB
:
731 *params
= prog
->NumAddressRegs
;
733 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB
:
734 *params
= limits
->MaxAddressRegs
;
736 case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
737 *params
= prog
->NumNativeAddressRegs
;
739 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
740 *params
= limits
->MaxNativeAddressRegs
;
742 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB
:
743 *params
= limits
->MaxLocalParams
;
745 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB
:
746 *params
= limits
->MaxEnvParams
;
748 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB
:
750 * XXX we may not really need a driver callback here.
751 * If the number of native instructions, registers, etc. used
752 * are all below the maximums, we could return true.
753 * The spec says that even if this query returns true, there's
754 * no guarantee that the program will run in hardware.
757 /* default/null program */
760 else if (ctx
->Driver
.IsProgramNative
) {
762 *params
= ctx
->Driver
.IsProgramNative( ctx
, target
, prog
);
765 /* probably running in software */
770 /* continue with fragment-program only queries below */
775 * The following apply to fragment programs only (at this time)
777 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
778 const struct gl_program
*fp
= ctx
->FragmentProgram
.Current
;
780 case GL_PROGRAM_ALU_INSTRUCTIONS_ARB
:
781 *params
= fp
->NumNativeAluInstructions
;
783 case GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
784 *params
= fp
->NumAluInstructions
;
786 case GL_PROGRAM_TEX_INSTRUCTIONS_ARB
:
787 *params
= fp
->NumTexInstructions
;
789 case GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
790 *params
= fp
->NumNativeTexInstructions
;
792 case GL_PROGRAM_TEX_INDIRECTIONS_ARB
:
793 *params
= fp
->NumTexIndirections
;
795 case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
796 *params
= fp
->NumNativeTexIndirections
;
798 case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB
:
799 *params
= limits
->MaxAluInstructions
;
801 case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
802 *params
= limits
->MaxNativeAluInstructions
;
804 case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB
:
805 *params
= limits
->MaxTexInstructions
;
807 case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
808 *params
= limits
->MaxNativeTexInstructions
;
810 case GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB
:
811 *params
= limits
->MaxTexIndirections
;
813 case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
814 *params
= limits
->MaxNativeTexIndirections
;
817 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
821 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
828 _mesa_GetProgramStringARB(GLenum target
, GLenum pname
, GLvoid
*string
)
830 const struct gl_program
*prog
;
831 char *dst
= (char *) string
;
832 GET_CURRENT_CONTEXT(ctx
);
834 if (target
== GL_VERTEX_PROGRAM_ARB
) {
835 prog
= ctx
->VertexProgram
.Current
;
837 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
838 prog
= ctx
->FragmentProgram
.Current
;
841 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(target)");
847 if (pname
!= GL_PROGRAM_STRING_ARB
) {
848 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(pname)");
853 memcpy(dst
, prog
->String
, strlen((char *) prog
->String
));