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
))
274 _mesa_ProgramStringARB(GLenum target
, GLenum format
, GLsizei len
,
275 const GLvoid
*string
)
277 struct gl_program
*base
;
278 GET_CURRENT_CONTEXT(ctx
);
279 ASSERT_OUTSIDE_BEGIN_END(ctx
);
281 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
283 if (!ctx
->Extensions
.ARB_vertex_program
284 && !ctx
->Extensions
.ARB_fragment_program
) {
285 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glProgramStringARB()");
289 if (format
!= GL_PROGRAM_FORMAT_ASCII_ARB
) {
290 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(format)");
294 /* The first couple cases are complicated. The same enum value is used for
295 * ARB and NV vertex programs. If the target is a vertex program, parse it
296 * using the ARB grammar if the string starts with "!!ARB" or if
297 * NV_vertex_program is not supported.
299 if (target
== GL_VERTEX_PROGRAM_ARB
300 && ctx
->Extensions
.ARB_vertex_program
301 && ((strncmp(string
, "!!ARB", 5) == 0)
302 || !ctx
->Extensions
.NV_vertex_program
)) {
303 struct gl_vertex_program
*prog
= ctx
->VertexProgram
.Current
;
304 _mesa_parse_arb_vertex_program(ctx
, target
, string
, len
, prog
);
308 else if ((target
== GL_VERTEX_PROGRAM_ARB
309 || target
== GL_VERTEX_STATE_PROGRAM_NV
)
310 && ctx
->Extensions
.NV_vertex_program
) {
311 struct gl_vertex_program
*prog
= ctx
->VertexProgram
.Current
;
312 _mesa_parse_nv_vertex_program(ctx
, target
, string
, len
, prog
);
316 else if (target
== GL_FRAGMENT_PROGRAM_ARB
317 && ctx
->Extensions
.ARB_fragment_program
) {
318 struct gl_fragment_program
*prog
= ctx
->FragmentProgram
.Current
;
319 _mesa_parse_arb_fragment_program(ctx
, target
, string
, len
, prog
);
323 else if (target
== GL_FRAGMENT_PROGRAM_NV
324 && ctx
->Extensions
.NV_fragment_program
) {
325 struct gl_fragment_program
*prog
= ctx
->FragmentProgram
.Current
;
326 _mesa_parse_nv_fragment_program(ctx
, target
, string
, len
, prog
);
331 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(target)");
335 if (ctx
->Program
.ErrorPos
== -1) {
336 /* finally, give the program to the driver for translation/checking */
337 if (!ctx
->Driver
.ProgramStringNotify(ctx
, target
, base
)) {
338 _mesa_error(ctx
, GL_INVALID_OPERATION
,
339 "glProgramStringARB(rejected by driver");
346 * Set a program env parameter register.
347 * \note Called from the GL API dispatcher.
348 * Note, this function is also used by the GL_NV_vertex_program extension
349 * (alias to ProgramParameterdNV)
352 _mesa_ProgramEnvParameter4dARB(GLenum target
, GLuint index
,
353 GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
355 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
356 (GLfloat
) z
, (GLfloat
) w
);
361 * Set a program env parameter register.
362 * \note Called from the GL API dispatcher.
363 * Note, this function is also used by the GL_NV_vertex_program extension
364 * (alias to ProgramParameterdvNV)
367 _mesa_ProgramEnvParameter4dvARB(GLenum target
, GLuint index
,
368 const GLdouble
*params
)
370 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) params
[0],
371 (GLfloat
) params
[1], (GLfloat
) params
[2],
372 (GLfloat
) params
[3]);
377 * Set a program env parameter register.
378 * \note Called from the GL API dispatcher.
379 * Note, this function is also used by the GL_NV_vertex_program extension
380 * (alias to ProgramParameterfNV)
383 _mesa_ProgramEnvParameter4fARB(GLenum target
, GLuint index
,
384 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
386 GET_CURRENT_CONTEXT(ctx
);
387 ASSERT_OUTSIDE_BEGIN_END(ctx
);
389 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
391 if (target
== GL_FRAGMENT_PROGRAM_ARB
392 && ctx
->Extensions
.ARB_fragment_program
) {
393 if (index
>= ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
394 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter(index)");
397 ASSIGN_4V(ctx
->FragmentProgram
.Parameters
[index
], x
, y
, z
, w
);
399 else if (target
== GL_VERTEX_PROGRAM_ARB
/* == GL_VERTEX_PROGRAM_NV */
400 && (ctx
->Extensions
.ARB_vertex_program
|| ctx
->Extensions
.NV_vertex_program
)) {
401 if (index
>= ctx
->Const
.VertexProgram
.MaxEnvParams
) {
402 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter(index)");
405 ASSIGN_4V(ctx
->VertexProgram
.Parameters
[index
], x
, y
, z
, w
);
408 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameter(target)");
416 * Set a program env parameter register.
417 * \note Called from the GL API dispatcher.
418 * Note, this function is also used by the GL_NV_vertex_program extension
419 * (alias to ProgramParameterfvNV)
422 _mesa_ProgramEnvParameter4fvARB(GLenum target
, GLuint index
,
423 const GLfloat
*params
)
425 GET_CURRENT_CONTEXT(ctx
);
426 ASSERT_OUTSIDE_BEGIN_END(ctx
);
428 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
430 if (target
== GL_FRAGMENT_PROGRAM_ARB
431 && ctx
->Extensions
.ARB_fragment_program
) {
432 if (index
>= ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
433 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter4fv(index)");
436 memcpy(ctx
->FragmentProgram
.Parameters
[index
], params
,
437 4 * sizeof(GLfloat
));
439 else if (target
== GL_VERTEX_PROGRAM_ARB
/* == GL_VERTEX_PROGRAM_NV */
440 && (ctx
->Extensions
.ARB_vertex_program
|| ctx
->Extensions
.NV_vertex_program
)) {
441 if (index
>= ctx
->Const
.VertexProgram
.MaxEnvParams
) {
442 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter4fv(index)");
445 memcpy(ctx
->VertexProgram
.Parameters
[index
], params
,
446 4 * sizeof(GLfloat
));
449 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameter4fv(target)");
456 _mesa_ProgramEnvParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
457 const GLfloat
*params
)
459 GET_CURRENT_CONTEXT(ctx
);
461 ASSERT_OUTSIDE_BEGIN_END(ctx
);
463 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
466 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(count)");
469 if (target
== GL_FRAGMENT_PROGRAM_ARB
470 && ctx
->Extensions
.ARB_fragment_program
) {
471 if ((index
+ count
) > ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
472 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
475 dest
= ctx
->FragmentProgram
.Parameters
[index
];
477 else if (target
== GL_VERTEX_PROGRAM_ARB
478 && ctx
->Extensions
.ARB_vertex_program
) {
479 if ((index
+ count
) > ctx
->Const
.VertexProgram
.MaxEnvParams
) {
480 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
483 dest
= ctx
->VertexProgram
.Parameters
[index
];
486 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameters4fv(target)");
490 memcpy(dest
, params
, count
* 4 * sizeof(GLfloat
));
495 _mesa_GetProgramEnvParameterdvARB(GLenum target
, GLuint index
,
498 GET_CURRENT_CONTEXT(ctx
);
501 _mesa_GetProgramEnvParameterfvARB(target
, index
, fparams
);
502 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
503 params
[0] = fparams
[0];
504 params
[1] = fparams
[1];
505 params
[2] = fparams
[2];
506 params
[3] = fparams
[3];
512 _mesa_GetProgramEnvParameterfvARB(GLenum target
, GLuint index
,
515 GET_CURRENT_CONTEXT(ctx
);
517 ASSERT_OUTSIDE_BEGIN_END(ctx
);
519 if (target
== GL_FRAGMENT_PROGRAM_ARB
520 && ctx
->Extensions
.ARB_fragment_program
) {
521 if (index
>= ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
522 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramEnvParameter(index)");
525 COPY_4V(params
, ctx
->FragmentProgram
.Parameters
[index
]);
527 else if (target
== GL_VERTEX_PROGRAM_ARB
528 && ctx
->Extensions
.ARB_vertex_program
) {
529 if (index
>= ctx
->Const
.VertexProgram
.MaxEnvParams
) {
530 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramEnvParameter(index)");
533 COPY_4V(params
, ctx
->VertexProgram
.Parameters
[index
]);
536 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramEnvParameter(target)");
543 * Note, this function is also used by the GL_NV_fragment_program extension.
546 _mesa_ProgramLocalParameter4fARB(GLenum target
, GLuint index
,
547 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
549 GET_CURRENT_CONTEXT(ctx
);
550 struct gl_program
*prog
;
551 ASSERT_OUTSIDE_BEGIN_END(ctx
);
553 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
555 if ((target
== GL_FRAGMENT_PROGRAM_NV
556 && ctx
->Extensions
.NV_fragment_program
) ||
557 (target
== GL_FRAGMENT_PROGRAM_ARB
558 && ctx
->Extensions
.ARB_fragment_program
)) {
559 if (index
>= ctx
->Const
.FragmentProgram
.MaxLocalParams
) {
560 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameterARB");
563 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
565 else if (target
== GL_VERTEX_PROGRAM_ARB
566 && ctx
->Extensions
.ARB_vertex_program
) {
567 if (index
>= ctx
->Const
.VertexProgram
.MaxLocalParams
) {
568 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameterARB");
571 prog
= &(ctx
->VertexProgram
.Current
->Base
);
574 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameterARB");
578 ASSERT(index
< MAX_PROGRAM_LOCAL_PARAMS
);
579 prog
->LocalParams
[index
][0] = x
;
580 prog
->LocalParams
[index
][1] = y
;
581 prog
->LocalParams
[index
][2] = z
;
582 prog
->LocalParams
[index
][3] = w
;
587 * Note, this function is also used by the GL_NV_fragment_program extension.
590 _mesa_ProgramLocalParameter4fvARB(GLenum target
, GLuint index
,
591 const GLfloat
*params
)
593 _mesa_ProgramLocalParameter4fARB(target
, index
, params
[0], params
[1],
594 params
[2], params
[3]);
599 _mesa_ProgramLocalParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
600 const GLfloat
*params
)
602 GET_CURRENT_CONTEXT(ctx
);
604 ASSERT_OUTSIDE_BEGIN_END(ctx
);
606 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
609 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fv(count)");
612 if (target
== GL_FRAGMENT_PROGRAM_ARB
613 && ctx
->Extensions
.ARB_fragment_program
) {
614 if ((index
+ count
) > ctx
->Const
.FragmentProgram
.MaxLocalParams
) {
615 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fvEXT(index + count)");
618 dest
= ctx
->FragmentProgram
.Current
->Base
.LocalParams
[index
];
620 else if (target
== GL_VERTEX_PROGRAM_ARB
621 && ctx
->Extensions
.ARB_vertex_program
) {
622 if ((index
+ count
) > ctx
->Const
.VertexProgram
.MaxLocalParams
) {
623 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fvEXT(index + count)");
626 dest
= ctx
->VertexProgram
.Current
->Base
.LocalParams
[index
];
629 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameters4fvEXT(target)");
633 memcpy(dest
, params
, count
* 4 * sizeof(GLfloat
));
638 * Note, this function is also used by the GL_NV_fragment_program extension.
641 _mesa_ProgramLocalParameter4dARB(GLenum target
, GLuint index
,
642 GLdouble x
, GLdouble y
,
643 GLdouble z
, GLdouble w
)
645 _mesa_ProgramLocalParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
646 (GLfloat
) z
, (GLfloat
) w
);
651 * Note, this function is also used by the GL_NV_fragment_program extension.
654 _mesa_ProgramLocalParameter4dvARB(GLenum target
, GLuint index
,
655 const GLdouble
*params
)
657 _mesa_ProgramLocalParameter4fARB(target
, index
,
658 (GLfloat
) params
[0], (GLfloat
) params
[1],
659 (GLfloat
) params
[2], (GLfloat
) params
[3]);
664 * Note, this function is also used by the GL_NV_fragment_program extension.
667 _mesa_GetProgramLocalParameterfvARB(GLenum target
, GLuint index
,
670 const struct gl_program
*prog
;
672 GET_CURRENT_CONTEXT(ctx
);
673 ASSERT_OUTSIDE_BEGIN_END(ctx
);
675 if (target
== GL_VERTEX_PROGRAM_ARB
676 && ctx
->Extensions
.ARB_vertex_program
) {
677 prog
= &(ctx
->VertexProgram
.Current
->Base
);
678 maxParams
= ctx
->Const
.VertexProgram
.MaxLocalParams
;
680 else if (target
== GL_FRAGMENT_PROGRAM_ARB
681 && ctx
->Extensions
.ARB_fragment_program
) {
682 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
683 maxParams
= ctx
->Const
.FragmentProgram
.MaxLocalParams
;
685 else if (target
== GL_FRAGMENT_PROGRAM_NV
686 && ctx
->Extensions
.NV_fragment_program
) {
687 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
688 maxParams
= MAX_NV_FRAGMENT_PROGRAM_PARAMS
;
691 _mesa_error(ctx
, GL_INVALID_ENUM
,
692 "glGetProgramLocalParameterARB(target)");
696 if (index
>= maxParams
) {
697 _mesa_error(ctx
, GL_INVALID_VALUE
,
698 "glGetProgramLocalParameterARB(index)");
703 ASSERT(index
< MAX_PROGRAM_LOCAL_PARAMS
);
704 COPY_4V(params
, prog
->LocalParams
[index
]);
709 * Note, this function is also used by the GL_NV_fragment_program extension.
712 _mesa_GetProgramLocalParameterdvARB(GLenum target
, GLuint index
,
715 GET_CURRENT_CONTEXT(ctx
);
716 GLfloat floatParams
[4];
717 ASSIGN_4V(floatParams
, 0.0F
, 0.0F
, 0.0F
, 0.0F
);
718 _mesa_GetProgramLocalParameterfvARB(target
, index
, floatParams
);
719 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
720 COPY_4V(params
, floatParams
);
726 _mesa_GetProgramivARB(GLenum target
, GLenum pname
, GLint
*params
)
728 const struct gl_program_constants
*limits
;
729 struct gl_program
*prog
;
730 GET_CURRENT_CONTEXT(ctx
);
732 ASSERT_OUTSIDE_BEGIN_END(ctx
);
734 if (target
== GL_VERTEX_PROGRAM_ARB
735 && ctx
->Extensions
.ARB_vertex_program
) {
736 prog
= &(ctx
->VertexProgram
.Current
->Base
);
737 limits
= &ctx
->Const
.VertexProgram
;
739 else if (target
== GL_FRAGMENT_PROGRAM_ARB
740 && ctx
->Extensions
.ARB_fragment_program
) {
741 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
742 limits
= &ctx
->Const
.FragmentProgram
;
745 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
752 /* Queries supported for both vertex and fragment programs */
754 case GL_PROGRAM_LENGTH_ARB
:
756 = prog
->String
? (GLint
) strlen((char *) prog
->String
) : 0;
758 case GL_PROGRAM_FORMAT_ARB
:
759 *params
= prog
->Format
;
761 case GL_PROGRAM_BINDING_ARB
:
764 case GL_PROGRAM_INSTRUCTIONS_ARB
:
765 *params
= prog
->NumInstructions
;
767 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB
:
768 *params
= limits
->MaxInstructions
;
770 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
771 *params
= prog
->NumNativeInstructions
;
773 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
774 *params
= limits
->MaxNativeInstructions
;
776 case GL_PROGRAM_TEMPORARIES_ARB
:
777 *params
= prog
->NumTemporaries
;
779 case GL_MAX_PROGRAM_TEMPORARIES_ARB
:
780 *params
= limits
->MaxTemps
;
782 case GL_PROGRAM_NATIVE_TEMPORARIES_ARB
:
783 *params
= prog
->NumNativeTemporaries
;
785 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB
:
786 *params
= limits
->MaxNativeTemps
;
788 case GL_PROGRAM_PARAMETERS_ARB
:
789 *params
= prog
->NumParameters
;
791 case GL_MAX_PROGRAM_PARAMETERS_ARB
:
792 *params
= limits
->MaxParameters
;
794 case GL_PROGRAM_NATIVE_PARAMETERS_ARB
:
795 *params
= prog
->NumNativeParameters
;
797 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB
:
798 *params
= limits
->MaxNativeParameters
;
800 case GL_PROGRAM_ATTRIBS_ARB
:
801 *params
= prog
->NumAttributes
;
803 case GL_MAX_PROGRAM_ATTRIBS_ARB
:
804 *params
= limits
->MaxAttribs
;
806 case GL_PROGRAM_NATIVE_ATTRIBS_ARB
:
807 *params
= prog
->NumNativeAttributes
;
809 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB
:
810 *params
= limits
->MaxNativeAttribs
;
812 case GL_PROGRAM_ADDRESS_REGISTERS_ARB
:
813 *params
= prog
->NumAddressRegs
;
815 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB
:
816 *params
= limits
->MaxAddressRegs
;
818 case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
819 *params
= prog
->NumNativeAddressRegs
;
821 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
822 *params
= limits
->MaxNativeAddressRegs
;
824 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB
:
825 *params
= limits
->MaxLocalParams
;
827 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB
:
828 *params
= limits
->MaxEnvParams
;
830 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB
:
832 * XXX we may not really need a driver callback here.
833 * If the number of native instructions, registers, etc. used
834 * are all below the maximums, we could return true.
835 * The spec says that even if this query returns true, there's
836 * no guarantee that the program will run in hardware.
839 /* default/null program */
842 else if (ctx
->Driver
.IsProgramNative
) {
844 *params
= ctx
->Driver
.IsProgramNative( ctx
, target
, prog
);
847 /* probably running in software */
852 /* continue with fragment-program only queries below */
857 * The following apply to fragment programs only (at this time)
859 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
860 const struct gl_fragment_program
*fp
= ctx
->FragmentProgram
.Current
;
862 case GL_PROGRAM_ALU_INSTRUCTIONS_ARB
:
863 *params
= fp
->Base
.NumNativeAluInstructions
;
865 case GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
866 *params
= fp
->Base
.NumAluInstructions
;
868 case GL_PROGRAM_TEX_INSTRUCTIONS_ARB
:
869 *params
= fp
->Base
.NumTexInstructions
;
871 case GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
872 *params
= fp
->Base
.NumNativeTexInstructions
;
874 case GL_PROGRAM_TEX_INDIRECTIONS_ARB
:
875 *params
= fp
->Base
.NumTexIndirections
;
877 case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
878 *params
= fp
->Base
.NumNativeTexIndirections
;
880 case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB
:
881 *params
= limits
->MaxAluInstructions
;
883 case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
884 *params
= limits
->MaxNativeAluInstructions
;
886 case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB
:
887 *params
= limits
->MaxTexInstructions
;
889 case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
890 *params
= limits
->MaxNativeTexInstructions
;
892 case GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB
:
893 *params
= limits
->MaxTexIndirections
;
895 case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
896 *params
= limits
->MaxNativeTexIndirections
;
899 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
903 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
910 _mesa_GetProgramStringARB(GLenum target
, GLenum pname
, GLvoid
*string
)
912 const struct gl_program
*prog
;
913 char *dst
= (char *) string
;
914 GET_CURRENT_CONTEXT(ctx
);
916 ASSERT_OUTSIDE_BEGIN_END(ctx
);
918 if (target
== GL_VERTEX_PROGRAM_ARB
) {
919 prog
= &(ctx
->VertexProgram
.Current
->Base
);
921 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
922 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
925 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(target)");
931 if (pname
!= GL_PROGRAM_STRING_ARB
) {
932 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(pname)");
937 memcpy(dst
, prog
->String
, strlen((char *) prog
->String
));