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"
45 * Bind a program (make it current)
46 * \note Called from the GL API dispatcher by both glBindProgramNV
47 * and glBindProgramARB.
50 _mesa_BindProgramARB(GLenum target
, GLuint id
)
52 struct gl_program
*curProg
, *newProg
;
53 GET_CURRENT_CONTEXT(ctx
);
55 /* Error-check target and get curProg */
56 if (target
== GL_VERTEX_PROGRAM_ARB
&& ctx
->Extensions
.ARB_vertex_program
) {
57 curProg
= ctx
->VertexProgram
.Current
;
59 else if (target
== GL_FRAGMENT_PROGRAM_ARB
60 && ctx
->Extensions
.ARB_fragment_program
) {
61 curProg
= ctx
->FragmentProgram
.Current
;
64 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindProgramARB(target)");
69 * Get pointer to new program to bind.
70 * NOTE: binding to a non-existant program is not an error.
71 * That's supposed to be caught in glBegin.
74 /* Bind a default program */
76 if (target
== GL_VERTEX_PROGRAM_ARB
)
77 newProg
= ctx
->Shared
->DefaultVertexProgram
;
79 newProg
= ctx
->Shared
->DefaultFragmentProgram
;
82 /* Bind a user program */
83 newProg
= _mesa_lookup_program(ctx
, id
);
84 if (!newProg
|| newProg
== &_mesa_DummyProgram
) {
85 /* allocate a new program now */
86 newProg
= ctx
->Driver
.NewProgram(ctx
, target
, id
, true);
88 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindProgramARB");
91 _mesa_HashInsert(ctx
->Shared
->Programs
, id
, newProg
);
93 else if (newProg
->Target
!= target
) {
94 _mesa_error(ctx
, GL_INVALID_OPERATION
,
95 "glBindProgramARB(target mismatch)");
100 /** All error checking is complete now **/
102 if (curProg
->Id
== id
) {
103 /* binding same program - no change */
107 /* signal new program (and its new constants) */
108 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
| _NEW_PROGRAM_CONSTANTS
);
111 if (target
== GL_VERTEX_PROGRAM_ARB
) {
112 _mesa_reference_program(ctx
, &ctx
->VertexProgram
.Current
, newProg
);
114 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
115 _mesa_reference_program(ctx
, &ctx
->FragmentProgram
.Current
, newProg
);
118 /* Never null pointers */
119 assert(ctx
->VertexProgram
.Current
);
120 assert(ctx
->FragmentProgram
.Current
);
125 * Delete a list of programs.
126 * \note Not compiled into display lists.
127 * \note Called by both glDeleteProgramsNV and glDeleteProgramsARB.
130 _mesa_DeleteProgramsARB(GLsizei n
, const GLuint
*ids
)
133 GET_CURRENT_CONTEXT(ctx
);
135 FLUSH_VERTICES(ctx
, 0);
138 _mesa_error( ctx
, GL_INVALID_VALUE
, "glDeleteProgramsNV" );
142 for (i
= 0; i
< n
; i
++) {
144 struct gl_program
*prog
= _mesa_lookup_program(ctx
, ids
[i
]);
145 if (prog
== &_mesa_DummyProgram
) {
146 _mesa_HashRemove(ctx
->Shared
->Programs
, ids
[i
]);
149 /* Unbind program if necessary */
150 switch (prog
->Target
) {
151 case GL_VERTEX_PROGRAM_ARB
:
152 if (ctx
->VertexProgram
.Current
&&
153 ctx
->VertexProgram
.Current
->Id
== ids
[i
]) {
154 /* unbind this currently bound program */
155 _mesa_BindProgramARB(prog
->Target
, 0);
158 case GL_FRAGMENT_PROGRAM_ARB
:
159 if (ctx
->FragmentProgram
.Current
&&
160 ctx
->FragmentProgram
.Current
->Id
== ids
[i
]) {
161 /* unbind this currently bound program */
162 _mesa_BindProgramARB(prog
->Target
, 0);
166 _mesa_problem(ctx
, "bad target in glDeleteProgramsNV");
169 /* The ID is immediately available for re-use now */
170 _mesa_HashRemove(ctx
->Shared
->Programs
, ids
[i
]);
171 _mesa_reference_program(ctx
, &prog
, NULL
);
179 * Generate a list of new program identifiers.
180 * \note Not compiled into display lists.
181 * \note Called by both glGenProgramsNV and glGenProgramsARB.
184 _mesa_GenProgramsARB(GLsizei n
, GLuint
*ids
)
188 GET_CURRENT_CONTEXT(ctx
);
191 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenPrograms");
198 _mesa_HashLockMutex(ctx
->Shared
->Programs
);
200 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->Programs
, n
);
202 /* Insert pointer to dummy program as placeholder */
203 for (i
= 0; i
< (GLuint
) n
; i
++) {
204 _mesa_HashInsertLocked(ctx
->Shared
->Programs
, first
+ i
,
205 &_mesa_DummyProgram
);
208 _mesa_HashUnlockMutex(ctx
->Shared
->Programs
);
210 /* Return the program names */
211 for (i
= 0; i
< (GLuint
) n
; i
++) {
218 * Determine if id names a vertex or fragment program.
219 * \note Not compiled into display lists.
220 * \note Called from both glIsProgramNV and glIsProgramARB.
221 * \param id is the program identifier
222 * \return GL_TRUE if id is a program, else GL_FALSE.
225 _mesa_IsProgramARB(GLuint id
)
227 struct gl_program
*prog
= NULL
;
228 GET_CURRENT_CONTEXT(ctx
);
229 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
234 prog
= _mesa_lookup_program(ctx
, id
);
235 if (prog
&& (prog
!= &_mesa_DummyProgram
))
242 get_local_param_pointer(struct gl_context
*ctx
, const char *func
,
243 GLenum target
, GLuint index
, GLfloat
**param
)
245 struct gl_program
*prog
;
248 if (target
== GL_VERTEX_PROGRAM_ARB
249 && ctx
->Extensions
.ARB_vertex_program
) {
250 prog
= ctx
->VertexProgram
.Current
;
251 maxParams
= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxLocalParams
;
253 else if (target
== GL_FRAGMENT_PROGRAM_ARB
254 && ctx
->Extensions
.ARB_fragment_program
) {
255 prog
= ctx
->FragmentProgram
.Current
;
256 maxParams
= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxLocalParams
;
259 _mesa_error(ctx
, GL_INVALID_ENUM
,
264 if (index
>= maxParams
) {
265 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
269 if (!prog
->arb
.LocalParams
) {
270 prog
->arb
.LocalParams
= rzalloc_array_size(prog
, sizeof(float[4]),
272 if (!prog
->arb
.LocalParams
)
276 *param
= prog
->arb
.LocalParams
[index
];
282 get_env_param_pointer(struct gl_context
*ctx
, const char *func
,
283 GLenum target
, GLuint index
, GLfloat
**param
)
285 if (target
== GL_FRAGMENT_PROGRAM_ARB
286 && ctx
->Extensions
.ARB_fragment_program
) {
287 if (index
>= ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxEnvParams
) {
288 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
291 *param
= ctx
->FragmentProgram
.Parameters
[index
];
294 else if (target
== GL_VERTEX_PROGRAM_ARB
&&
295 ctx
->Extensions
.ARB_vertex_program
) {
296 if (index
>= ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxEnvParams
) {
297 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(index)", func
);
300 *param
= ctx
->VertexProgram
.Parameters
[index
];
303 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
309 _mesa_ProgramStringARB(GLenum target
, GLenum format
, GLsizei len
,
310 const GLvoid
*string
)
312 struct gl_program
*prog
;
314 GET_CURRENT_CONTEXT(ctx
);
316 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
318 if (!ctx
->Extensions
.ARB_vertex_program
319 && !ctx
->Extensions
.ARB_fragment_program
) {
320 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glProgramStringARB()");
324 if (format
!= GL_PROGRAM_FORMAT_ASCII_ARB
) {
325 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(format)");
329 if (target
== GL_VERTEX_PROGRAM_ARB
&& ctx
->Extensions
.ARB_vertex_program
) {
330 prog
= ctx
->VertexProgram
.Current
;
331 _mesa_parse_arb_vertex_program(ctx
, target
, string
, len
, prog
);
333 else if (target
== GL_FRAGMENT_PROGRAM_ARB
334 && ctx
->Extensions
.ARB_fragment_program
) {
335 prog
= ctx
->FragmentProgram
.Current
;
336 _mesa_parse_arb_fragment_program(ctx
, target
, string
, len
, prog
);
339 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(target)");
343 failed
= ctx
->Program
.ErrorPos
!= -1;
346 /* finally, give the program to the driver for translation/checking */
347 if (!ctx
->Driver
.ProgramStringNotify(ctx
, target
, prog
)) {
349 _mesa_error(ctx
, GL_INVALID_OPERATION
,
350 "glProgramStringARB(rejected by driver");
354 if (ctx
->_Shader
->Flags
& GLSL_DUMP
) {
355 const char *shader_type
=
356 target
== GL_FRAGMENT_PROGRAM_ARB
? "fragment" : "vertex";
358 fprintf(stderr
, "ARB_%s_program source for program %d:\n",
359 shader_type
, prog
->Id
);
360 fprintf(stderr
, "%s\n", (const char *) string
);
363 fprintf(stderr
, "ARB_%s_program %d failed to compile.\n",
364 shader_type
, prog
->Id
);
366 fprintf(stderr
, "Mesa IR for ARB_%s_program %d:\n",
367 shader_type
, prog
->Id
);
368 _mesa_print_program(prog
);
369 fprintf(stderr
, "\n");
374 /* Capture vp-*.shader_test/fp-*.shader_test files. */
375 const char *capture_path
= _mesa_get_shader_capture_path();
376 if (capture_path
!= NULL
) {
378 const char *shader_type
=
379 target
== GL_FRAGMENT_PROGRAM_ARB
? "fragment" : "vertex";
381 ralloc_asprintf(NULL
, "%s/%cp-%u.shader_test",
382 capture_path
, shader_type
[0], prog
->Id
);
384 file
= fopen(filename
, "w");
387 "[require]\nGL_ARB_%s_program\n\n[%s program]\n%s\n",
388 shader_type
, shader_type
, (const char *) string
);
391 _mesa_warning(ctx
, "Failed to open %s", filename
);
393 ralloc_free(filename
);
399 * Set a program env parameter register.
400 * \note Called from the GL API dispatcher.
403 _mesa_ProgramEnvParameter4dARB(GLenum target
, GLuint index
,
404 GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
406 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
407 (GLfloat
) z
, (GLfloat
) w
);
412 * Set a program env parameter register.
413 * \note Called from the GL API dispatcher.
416 _mesa_ProgramEnvParameter4dvARB(GLenum target
, GLuint index
,
417 const GLdouble
*params
)
419 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) params
[0],
420 (GLfloat
) params
[1], (GLfloat
) params
[2],
421 (GLfloat
) params
[3]);
426 * Set a program env parameter register.
427 * \note Called from the GL API dispatcher.
430 _mesa_ProgramEnvParameter4fARB(GLenum target
, GLuint index
,
431 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
435 GET_CURRENT_CONTEXT(ctx
);
437 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
439 if (get_env_param_pointer(ctx
, "glProgramEnvParameter",
440 target
, index
, ¶m
)) {
441 ASSIGN_4V(param
, x
, y
, z
, w
);
448 * Set a program env parameter register.
449 * \note Called from the GL API dispatcher.
452 _mesa_ProgramEnvParameter4fvARB(GLenum target
, GLuint index
,
453 const GLfloat
*params
)
457 GET_CURRENT_CONTEXT(ctx
);
459 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
461 if (get_env_param_pointer(ctx
, "glProgramEnvParameter4fv",
462 target
, index
, ¶m
)) {
463 memcpy(param
, params
, 4 * sizeof(GLfloat
));
469 _mesa_ProgramEnvParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
470 const GLfloat
*params
)
472 GET_CURRENT_CONTEXT(ctx
);
475 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
478 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(count)");
481 if (target
== GL_FRAGMENT_PROGRAM_ARB
482 && ctx
->Extensions
.ARB_fragment_program
) {
483 if ((index
+ count
) > ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxEnvParams
) {
484 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
487 dest
= ctx
->FragmentProgram
.Parameters
[index
];
489 else if (target
== GL_VERTEX_PROGRAM_ARB
490 && ctx
->Extensions
.ARB_vertex_program
) {
491 if ((index
+ count
) > ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxEnvParams
) {
492 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
495 dest
= ctx
->VertexProgram
.Parameters
[index
];
498 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameters4fv(target)");
502 memcpy(dest
, params
, count
* 4 * sizeof(GLfloat
));
507 _mesa_GetProgramEnvParameterdvARB(GLenum target
, GLuint index
,
510 GET_CURRENT_CONTEXT(ctx
);
513 if (get_env_param_pointer(ctx
, "glGetProgramEnvParameterdv",
514 target
, index
, &fparam
)) {
515 COPY_4V(params
, fparam
);
521 _mesa_GetProgramEnvParameterfvARB(GLenum target
, GLuint index
,
526 GET_CURRENT_CONTEXT(ctx
);
528 if (get_env_param_pointer(ctx
, "glGetProgramEnvParameterfv",
529 target
, index
, ¶m
)) {
530 COPY_4V(params
, param
);
536 _mesa_ProgramLocalParameter4fARB(GLenum target
, GLuint index
,
537 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
539 GET_CURRENT_CONTEXT(ctx
);
542 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
544 if (get_local_param_pointer(ctx
, "glProgramLocalParameterARB",
545 target
, index
, ¶m
)) {
546 assert(index
< MAX_PROGRAM_LOCAL_PARAMS
);
547 ASSIGN_4V(param
, x
, y
, z
, w
);
553 _mesa_ProgramLocalParameter4fvARB(GLenum target
, GLuint index
,
554 const GLfloat
*params
)
556 _mesa_ProgramLocalParameter4fARB(target
, index
, params
[0], params
[1],
557 params
[2], params
[3]);
562 _mesa_ProgramLocalParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
563 const GLfloat
*params
)
565 GET_CURRENT_CONTEXT(ctx
);
568 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
571 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fv(count)");
574 if (get_local_param_pointer(ctx
, "glProgramLocalParameters4fvEXT",
575 target
, index
, &dest
)) {
576 GLuint maxParams
= target
== GL_FRAGMENT_PROGRAM_ARB
?
577 ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
].MaxLocalParams
:
578 ctx
->Const
.Program
[MESA_SHADER_VERTEX
].MaxLocalParams
;
580 if ((index
+ count
) > maxParams
) {
581 _mesa_error(ctx
, GL_INVALID_VALUE
,
582 "glProgramLocalParameters4fvEXT(index + count)");
586 memcpy(dest
, params
, count
* 4 * sizeof(GLfloat
));
592 _mesa_ProgramLocalParameter4dARB(GLenum target
, GLuint index
,
593 GLdouble x
, GLdouble y
,
594 GLdouble z
, GLdouble w
)
596 _mesa_ProgramLocalParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
597 (GLfloat
) z
, (GLfloat
) w
);
602 _mesa_ProgramLocalParameter4dvARB(GLenum target
, GLuint index
,
603 const GLdouble
*params
)
605 _mesa_ProgramLocalParameter4fARB(target
, index
,
606 (GLfloat
) params
[0], (GLfloat
) params
[1],
607 (GLfloat
) params
[2], (GLfloat
) params
[3]);
612 _mesa_GetProgramLocalParameterfvARB(GLenum target
, GLuint index
,
616 GET_CURRENT_CONTEXT(ctx
);
618 if (get_local_param_pointer(ctx
, "glProgramLocalParameters4fvEXT",
619 target
, index
, ¶m
)) {
620 COPY_4V(params
, param
);
626 _mesa_GetProgramLocalParameterdvARB(GLenum target
, GLuint index
,
630 GET_CURRENT_CONTEXT(ctx
);
632 if (get_local_param_pointer(ctx
, "glProgramLocalParameters4fvEXT",
633 target
, index
, ¶m
)) {
634 COPY_4V(params
, param
);
640 _mesa_GetProgramivARB(GLenum target
, GLenum pname
, GLint
*params
)
642 const struct gl_program_constants
*limits
;
643 struct gl_program
*prog
;
644 GET_CURRENT_CONTEXT(ctx
);
646 if (target
== GL_VERTEX_PROGRAM_ARB
647 && ctx
->Extensions
.ARB_vertex_program
) {
648 prog
= ctx
->VertexProgram
.Current
;
649 limits
= &ctx
->Const
.Program
[MESA_SHADER_VERTEX
];
651 else if (target
== GL_FRAGMENT_PROGRAM_ARB
652 && ctx
->Extensions
.ARB_fragment_program
) {
653 prog
= ctx
->FragmentProgram
.Current
;
654 limits
= &ctx
->Const
.Program
[MESA_SHADER_FRAGMENT
];
657 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
664 /* Queries supported for both vertex and fragment programs */
666 case GL_PROGRAM_LENGTH_ARB
:
668 = prog
->String
? (GLint
) strlen((char *) prog
->String
) : 0;
670 case GL_PROGRAM_FORMAT_ARB
:
671 *params
= prog
->Format
;
673 case GL_PROGRAM_BINDING_ARB
:
676 case GL_PROGRAM_INSTRUCTIONS_ARB
:
677 *params
= prog
->arb
.NumInstructions
;
679 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB
:
680 *params
= limits
->MaxInstructions
;
682 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
683 *params
= prog
->arb
.NumNativeInstructions
;
685 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
686 *params
= limits
->MaxNativeInstructions
;
688 case GL_PROGRAM_TEMPORARIES_ARB
:
689 *params
= prog
->arb
.NumTemporaries
;
691 case GL_MAX_PROGRAM_TEMPORARIES_ARB
:
692 *params
= limits
->MaxTemps
;
694 case GL_PROGRAM_NATIVE_TEMPORARIES_ARB
:
695 *params
= prog
->arb
.NumNativeTemporaries
;
697 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB
:
698 *params
= limits
->MaxNativeTemps
;
700 case GL_PROGRAM_PARAMETERS_ARB
:
701 *params
= prog
->arb
.NumParameters
;
703 case GL_MAX_PROGRAM_PARAMETERS_ARB
:
704 *params
= limits
->MaxParameters
;
706 case GL_PROGRAM_NATIVE_PARAMETERS_ARB
:
707 *params
= prog
->arb
.NumNativeParameters
;
709 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB
:
710 *params
= limits
->MaxNativeParameters
;
712 case GL_PROGRAM_ATTRIBS_ARB
:
713 *params
= prog
->arb
.NumAttributes
;
715 case GL_MAX_PROGRAM_ATTRIBS_ARB
:
716 *params
= limits
->MaxAttribs
;
718 case GL_PROGRAM_NATIVE_ATTRIBS_ARB
:
719 *params
= prog
->arb
.NumNativeAttributes
;
721 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB
:
722 *params
= limits
->MaxNativeAttribs
;
724 case GL_PROGRAM_ADDRESS_REGISTERS_ARB
:
725 *params
= prog
->arb
.NumAddressRegs
;
727 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB
:
728 *params
= limits
->MaxAddressRegs
;
730 case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
731 *params
= prog
->arb
.NumNativeAddressRegs
;
733 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
734 *params
= limits
->MaxNativeAddressRegs
;
736 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB
:
737 *params
= limits
->MaxLocalParams
;
739 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB
:
740 *params
= limits
->MaxEnvParams
;
742 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB
:
744 * XXX we may not really need a driver callback here.
745 * If the number of native instructions, registers, etc. used
746 * are all below the maximums, we could return true.
747 * The spec says that even if this query returns true, there's
748 * no guarantee that the program will run in hardware.
751 /* default/null program */
754 else if (ctx
->Driver
.IsProgramNative
) {
756 *params
= ctx
->Driver
.IsProgramNative( ctx
, target
, prog
);
759 /* probably running in software */
764 /* continue with fragment-program only queries below */
769 * The following apply to fragment programs only (at this time)
771 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
772 const struct gl_program
*fp
= ctx
->FragmentProgram
.Current
;
774 case GL_PROGRAM_ALU_INSTRUCTIONS_ARB
:
775 *params
= fp
->arb
.NumNativeAluInstructions
;
777 case GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
778 *params
= fp
->arb
.NumAluInstructions
;
780 case GL_PROGRAM_TEX_INSTRUCTIONS_ARB
:
781 *params
= fp
->arb
.NumTexInstructions
;
783 case GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
784 *params
= fp
->arb
.NumNativeTexInstructions
;
786 case GL_PROGRAM_TEX_INDIRECTIONS_ARB
:
787 *params
= fp
->arb
.NumTexIndirections
;
789 case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
790 *params
= fp
->arb
.NumNativeTexIndirections
;
792 case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB
:
793 *params
= limits
->MaxAluInstructions
;
795 case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
796 *params
= limits
->MaxNativeAluInstructions
;
798 case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB
:
799 *params
= limits
->MaxTexInstructions
;
801 case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
802 *params
= limits
->MaxNativeTexInstructions
;
804 case GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB
:
805 *params
= limits
->MaxTexIndirections
;
807 case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
808 *params
= limits
->MaxNativeTexIndirections
;
811 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
815 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
822 _mesa_GetProgramStringARB(GLenum target
, GLenum pname
, GLvoid
*string
)
824 const struct gl_program
*prog
;
825 char *dst
= (char *) string
;
826 GET_CURRENT_CONTEXT(ctx
);
828 if (target
== GL_VERTEX_PROGRAM_ARB
) {
829 prog
= ctx
->VertexProgram
.Current
;
831 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
832 prog
= ctx
->FragmentProgram
.Current
;
835 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(target)");
841 if (pname
!= GL_PROGRAM_STRING_ARB
) {
842 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(pname)");
847 memcpy(dst
, prog
->String
, strlen((char *) prog
->String
));