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 "arbprogram.h"
39 #include "arbprogparse.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 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
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 */
136 if (target
== GL_VERTEX_PROGRAM_ARB
) { /* == GL_VERTEX_PROGRAM_NV */
137 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
.Current
,
138 (struct gl_vertex_program
*) newProg
);
140 else if (target
== GL_FRAGMENT_PROGRAM_NV
||
141 target
== GL_FRAGMENT_PROGRAM_ARB
) {
142 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
.Current
,
143 (struct gl_fragment_program
*) newProg
);
146 /* Never null pointers */
147 ASSERT(ctx
->VertexProgram
.Current
);
148 ASSERT(ctx
->FragmentProgram
.Current
);
150 if (ctx
->Driver
.BindProgram
)
151 ctx
->Driver
.BindProgram(ctx
, target
, newProg
);
156 * Delete a list of programs.
157 * \note Not compiled into display lists.
158 * \note Called by both glDeleteProgramsNV and glDeleteProgramsARB.
161 _mesa_DeletePrograms(GLsizei n
, const GLuint
*ids
)
164 GET_CURRENT_CONTEXT(ctx
);
165 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
168 _mesa_error( ctx
, GL_INVALID_VALUE
, "glDeleteProgramsNV" );
172 for (i
= 0; i
< n
; i
++) {
174 struct gl_program
*prog
= _mesa_lookup_program(ctx
, ids
[i
]);
175 if (prog
== &_mesa_DummyProgram
) {
176 _mesa_HashRemove(ctx
->Shared
->Programs
, ids
[i
]);
179 /* Unbind program if necessary */
180 if (prog
->Target
== GL_VERTEX_PROGRAM_ARB
|| /* == GL_VERTEX_PROGRAM_NV */
181 prog
->Target
== GL_VERTEX_STATE_PROGRAM_NV
) {
182 if (ctx
->VertexProgram
.Current
&&
183 ctx
->VertexProgram
.Current
->Base
.Id
== ids
[i
]) {
184 /* unbind this currently bound program */
185 _mesa_BindProgram(prog
->Target
, 0);
188 else if (prog
->Target
== GL_FRAGMENT_PROGRAM_NV
||
189 prog
->Target
== GL_FRAGMENT_PROGRAM_ARB
) {
190 if (ctx
->FragmentProgram
.Current
&&
191 ctx
->FragmentProgram
.Current
->Base
.Id
== ids
[i
]) {
192 /* unbind this currently bound program */
193 _mesa_BindProgram(prog
->Target
, 0);
197 _mesa_problem(ctx
, "bad target in glDeleteProgramsNV");
200 /* The ID is immediately available for re-use now */
201 _mesa_HashRemove(ctx
->Shared
->Programs
, ids
[i
]);
202 _mesa_reference_program(ctx
, &prog
, NULL
);
210 * Generate a list of new program identifiers.
211 * \note Not compiled into display lists.
212 * \note Called by both glGenProgramsNV and glGenProgramsARB.
215 _mesa_GenPrograms(GLsizei n
, GLuint
*ids
)
219 GET_CURRENT_CONTEXT(ctx
);
220 ASSERT_OUTSIDE_BEGIN_END(ctx
);
223 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenPrograms");
230 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->Programs
, n
);
232 /* Insert pointer to dummy program as placeholder */
233 for (i
= 0; i
< (GLuint
) n
; i
++) {
234 _mesa_HashInsert(ctx
->Shared
->Programs
, first
+ i
, &_mesa_DummyProgram
);
237 /* Return the program names */
238 for (i
= 0; i
< (GLuint
) n
; i
++) {
245 _mesa_EnableVertexAttribArrayARB(GLuint index
)
247 GET_CURRENT_CONTEXT(ctx
);
248 ASSERT_OUTSIDE_BEGIN_END(ctx
);
250 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
251 _mesa_error(ctx
, GL_INVALID_VALUE
,
252 "glEnableVertexAttribArrayARB(index)");
256 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
257 ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Enabled
= GL_TRUE
;
258 ctx
->Array
.ArrayObj
->_Enabled
|= _NEW_ARRAY_ATTRIB(index
);
259 ctx
->Array
.NewState
|= _NEW_ARRAY_ATTRIB(index
);
264 _mesa_DisableVertexAttribArrayARB(GLuint index
)
266 GET_CURRENT_CONTEXT(ctx
);
267 ASSERT_OUTSIDE_BEGIN_END(ctx
);
269 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
270 _mesa_error(ctx
, GL_INVALID_VALUE
,
271 "glEnableVertexAttribArrayARB(index)");
275 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
276 ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Enabled
= GL_FALSE
;
277 ctx
->Array
.ArrayObj
->_Enabled
&= ~_NEW_ARRAY_ATTRIB(index
);
278 ctx
->Array
.NewState
|= _NEW_ARRAY_ATTRIB(index
);
283 _mesa_GetVertexAttribdvARB(GLuint index
, GLenum pname
, GLdouble
*params
)
286 GET_CURRENT_CONTEXT(ctx
);
287 ASSERT_OUTSIDE_BEGIN_END(ctx
);
289 _mesa_GetVertexAttribfvARB(index
, pname
, fparams
);
290 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
291 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
292 COPY_4V(params
, fparams
);
295 params
[0] = fparams
[0];
302 _mesa_GetVertexAttribfvARB(GLuint index
, GLenum pname
, GLfloat
*params
)
304 GET_CURRENT_CONTEXT(ctx
);
305 ASSERT_OUTSIDE_BEGIN_END(ctx
);
307 if (index
>= MAX_VERTEX_PROGRAM_ATTRIBS
) {
308 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribfvARB(index)");
313 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
314 params
[0] = (GLfloat
) ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Enabled
;
316 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
317 params
[0] = (GLfloat
) ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Size
;
319 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
320 params
[0] = (GLfloat
) ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Stride
;
322 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
323 params
[0] = (GLfloat
) ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Type
;
325 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
326 params
[0] = ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Normalized
;
328 case GL_CURRENT_VERTEX_ATTRIB_ARB
:
330 _mesa_error(ctx
, GL_INVALID_OPERATION
,
331 "glGetVertexAttribfvARB(index==0)");
334 FLUSH_CURRENT(ctx
, 0);
335 COPY_4V(params
, ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC0
+ index
]);
337 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
338 params
[0] = (GLfloat
) ctx
->Array
.ArrayObj
->VertexAttrib
[index
].BufferObj
->Name
;
341 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribfvARB(pname)");
348 _mesa_GetVertexAttribivARB(GLuint index
, GLenum pname
, GLint
*params
)
351 GET_CURRENT_CONTEXT(ctx
);
352 ASSERT_OUTSIDE_BEGIN_END(ctx
);
354 _mesa_GetVertexAttribfvARB(index
, pname
, fparams
);
355 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
356 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
357 COPY_4V_CAST(params
, fparams
, GLint
); /* float to int */
360 params
[0] = (GLint
) fparams
[0];
367 _mesa_GetVertexAttribPointervARB(GLuint index
, GLenum pname
, GLvoid
**pointer
)
369 GET_CURRENT_CONTEXT(ctx
);
370 ASSERT_OUTSIDE_BEGIN_END(ctx
);
372 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
373 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
377 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
378 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
382 *pointer
= (GLvoid
*) ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Ptr
;
387 * Determine if id names a vertex or fragment program.
388 * \note Not compiled into display lists.
389 * \note Called from both glIsProgramNV and glIsProgramARB.
390 * \param id is the program identifier
391 * \return GL_TRUE if id is a program, else GL_FALSE.
394 _mesa_IsProgramARB(GLuint id
)
396 struct gl_program
*prog
= NULL
;
397 GET_CURRENT_CONTEXT(ctx
);
398 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
403 prog
= _mesa_lookup_program(ctx
, id
);
404 if (prog
&& (prog
!= &_mesa_DummyProgram
))
412 _mesa_ProgramStringARB(GLenum target
, GLenum format
, GLsizei len
,
413 const GLvoid
*string
)
415 GET_CURRENT_CONTEXT(ctx
);
416 ASSERT_OUTSIDE_BEGIN_END(ctx
);
418 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
420 if (format
!= GL_PROGRAM_FORMAT_ASCII_ARB
) {
421 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(format)");
425 if (target
== GL_VERTEX_PROGRAM_ARB
426 && ctx
->Extensions
.ARB_vertex_program
) {
427 struct gl_vertex_program
*prog
= ctx
->VertexProgram
.Current
;
428 _mesa_parse_arb_vertex_program(ctx
, target
, string
, len
, prog
);
430 if (ctx
->Program
.ErrorPos
== -1 && ctx
->Driver
.ProgramStringNotify
)
431 ctx
->Driver
.ProgramStringNotify( ctx
, target
, &prog
->Base
);
433 else if (target
== GL_FRAGMENT_PROGRAM_ARB
434 && ctx
->Extensions
.ARB_fragment_program
) {
435 struct gl_fragment_program
*prog
= ctx
->FragmentProgram
.Current
;
436 _mesa_parse_arb_fragment_program(ctx
, target
, string
, len
, prog
);
438 if (ctx
->Program
.ErrorPos
== -1 && ctx
->Driver
.ProgramStringNotify
)
439 ctx
->Driver
.ProgramStringNotify( ctx
, target
, &prog
->Base
);
442 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(target)");
449 * Set a program env parameter register.
450 * \note Called from the GL API dispatcher.
451 * Note, this function is also used by the GL_NV_vertex_program extension
452 * (alias to ProgramParameterdNV)
455 _mesa_ProgramEnvParameter4dARB(GLenum target
, GLuint index
,
456 GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
458 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
459 (GLfloat
) z
, (GLfloat
) w
);
464 * Set a program env parameter register.
465 * \note Called from the GL API dispatcher.
466 * Note, this function is also used by the GL_NV_vertex_program extension
467 * (alias to ProgramParameterdvNV)
470 _mesa_ProgramEnvParameter4dvARB(GLenum target
, GLuint index
,
471 const GLdouble
*params
)
473 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) params
[0],
474 (GLfloat
) params
[1], (GLfloat
) params
[2],
475 (GLfloat
) params
[3]);
480 * Set a program env parameter register.
481 * \note Called from the GL API dispatcher.
482 * Note, this function is also used by the GL_NV_vertex_program extension
483 * (alias to ProgramParameterfNV)
486 _mesa_ProgramEnvParameter4fARB(GLenum target
, GLuint index
,
487 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
489 GET_CURRENT_CONTEXT(ctx
);
490 ASSERT_OUTSIDE_BEGIN_END(ctx
);
492 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
494 if (target
== GL_FRAGMENT_PROGRAM_ARB
495 && ctx
->Extensions
.ARB_fragment_program
) {
496 if (index
>= ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
497 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter(index)");
500 ASSIGN_4V(ctx
->FragmentProgram
.Parameters
[index
], x
, y
, z
, w
);
502 else if (target
== GL_VERTEX_PROGRAM_ARB
/* == GL_VERTEX_PROGRAM_NV */
503 && (ctx
->Extensions
.ARB_vertex_program
|| ctx
->Extensions
.NV_vertex_program
)) {
504 if (index
>= ctx
->Const
.VertexProgram
.MaxEnvParams
) {
505 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter(index)");
508 ASSIGN_4V(ctx
->VertexProgram
.Parameters
[index
], x
, y
, z
, w
);
511 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameter(target)");
517 * Set a program env parameter register.
518 * \note Called from the GL API dispatcher.
519 * Note, this function is also used by the GL_NV_vertex_program extension
520 * (alias to ProgramParameterfvNV)
523 _mesa_ProgramEnvParameter4fvARB(GLenum target
, GLuint index
,
524 const GLfloat
*params
)
526 _mesa_ProgramEnvParameter4fARB(target
, index
, params
[0], params
[1],
527 params
[2], params
[3]);
532 _mesa_ProgramEnvParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
533 const GLfloat
*params
)
535 GET_CURRENT_CONTEXT(ctx
);
538 ASSERT_OUTSIDE_BEGIN_END(ctx
);
540 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
543 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(count)");
546 if (target
== GL_FRAGMENT_PROGRAM_ARB
547 && ctx
->Extensions
.ARB_fragment_program
) {
548 if ((index
+ count
) > ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
549 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
552 dest
= ctx
->FragmentProgram
.Parameters
[index
];
554 else if (target
== GL_VERTEX_PROGRAM_ARB
555 && ctx
->Extensions
.ARB_vertex_program
) {
556 if ((index
+ count
) > ctx
->Const
.VertexProgram
.MaxEnvParams
) {
557 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
560 dest
= ctx
->VertexProgram
.Parameters
[index
];
563 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameters4fv(target)");
567 for ( i
= 0 ; i
< count
; i
++ ) {
568 COPY_4V(dest
, params
);
576 _mesa_GetProgramEnvParameterdvARB(GLenum target
, GLuint index
,
579 GET_CURRENT_CONTEXT(ctx
);
582 _mesa_GetProgramEnvParameterfvARB(target
, index
, fparams
);
583 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
584 params
[0] = fparams
[0];
585 params
[1] = fparams
[1];
586 params
[2] = fparams
[2];
587 params
[3] = fparams
[3];
593 _mesa_GetProgramEnvParameterfvARB(GLenum target
, GLuint index
,
596 GET_CURRENT_CONTEXT(ctx
);
598 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
600 if (!ctx
->_CurrentProgram
)
601 ASSERT_OUTSIDE_BEGIN_END(ctx
);
603 if (target
== GL_FRAGMENT_PROGRAM_ARB
604 && ctx
->Extensions
.ARB_fragment_program
) {
605 if (index
>= ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
606 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramEnvParameter(index)");
609 COPY_4V(params
, ctx
->FragmentProgram
.Parameters
[index
]);
611 else if (target
== GL_VERTEX_PROGRAM_ARB
612 && ctx
->Extensions
.ARB_vertex_program
) {
613 if (index
>= ctx
->Const
.VertexProgram
.MaxEnvParams
) {
614 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramEnvParameter(index)");
617 COPY_4V(params
, ctx
->VertexProgram
.Parameters
[index
]);
620 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramEnvParameter(target)");
627 * Note, this function is also used by the GL_NV_fragment_program extension.
630 _mesa_ProgramLocalParameter4fARB(GLenum target
, GLuint index
,
631 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
633 GET_CURRENT_CONTEXT(ctx
);
634 struct gl_program
*prog
;
635 ASSERT_OUTSIDE_BEGIN_END(ctx
);
637 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
639 if ((target
== GL_FRAGMENT_PROGRAM_NV
640 && ctx
->Extensions
.NV_fragment_program
) ||
641 (target
== GL_FRAGMENT_PROGRAM_ARB
642 && ctx
->Extensions
.ARB_fragment_program
)) {
643 if (index
>= ctx
->Const
.FragmentProgram
.MaxLocalParams
) {
644 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameterARB");
647 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
649 else if (target
== GL_VERTEX_PROGRAM_ARB
650 && ctx
->Extensions
.ARB_vertex_program
) {
651 if (index
>= ctx
->Const
.VertexProgram
.MaxLocalParams
) {
652 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameterARB");
655 prog
= &(ctx
->VertexProgram
.Current
->Base
);
658 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameterARB");
662 ASSERT(index
< MAX_PROGRAM_LOCAL_PARAMS
);
663 prog
->LocalParams
[index
][0] = x
;
664 prog
->LocalParams
[index
][1] = y
;
665 prog
->LocalParams
[index
][2] = z
;
666 prog
->LocalParams
[index
][3] = w
;
671 * Note, this function is also used by the GL_NV_fragment_program extension.
674 _mesa_ProgramLocalParameter4fvARB(GLenum target
, GLuint index
,
675 const GLfloat
*params
)
677 _mesa_ProgramLocalParameter4fARB(target
, index
, params
[0], params
[1],
678 params
[2], params
[3]);
683 _mesa_ProgramLocalParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
684 const GLfloat
*params
)
686 GET_CURRENT_CONTEXT(ctx
);
687 struct gl_program
*prog
;
689 ASSERT_OUTSIDE_BEGIN_END(ctx
);
691 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
694 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fv(count)");
697 if (target
== GL_FRAGMENT_PROGRAM_ARB
698 && ctx
->Extensions
.ARB_fragment_program
) {
699 if ((index
+ count
) > ctx
->Const
.FragmentProgram
.MaxLocalParams
) {
700 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fvEXT(index + count)");
703 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
705 else if (target
== GL_VERTEX_PROGRAM_ARB
706 && ctx
->Extensions
.ARB_vertex_program
) {
707 if ((index
+ count
) > ctx
->Const
.VertexProgram
.MaxLocalParams
) {
708 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fvEXT(index + count)");
711 prog
= &(ctx
->VertexProgram
.Current
->Base
);
714 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameters4fvEXT(target)");
718 for (i
= 0; i
< count
; i
++) {
719 ASSERT((index
+ i
) < MAX_PROGRAM_LOCAL_PARAMS
);
720 COPY_4V(prog
->LocalParams
[index
+ i
], params
);
727 * Note, this function is also used by the GL_NV_fragment_program extension.
730 _mesa_ProgramLocalParameter4dARB(GLenum target
, GLuint index
,
731 GLdouble x
, GLdouble y
,
732 GLdouble z
, GLdouble w
)
734 _mesa_ProgramLocalParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
735 (GLfloat
) z
, (GLfloat
) w
);
740 * Note, this function is also used by the GL_NV_fragment_program extension.
743 _mesa_ProgramLocalParameter4dvARB(GLenum target
, GLuint index
,
744 const GLdouble
*params
)
746 _mesa_ProgramLocalParameter4fARB(target
, index
,
747 (GLfloat
) params
[0], (GLfloat
) params
[1],
748 (GLfloat
) params
[2], (GLfloat
) params
[3]);
753 * Note, this function is also used by the GL_NV_fragment_program extension.
756 _mesa_GetProgramLocalParameterfvARB(GLenum target
, GLuint index
,
759 const struct gl_program
*prog
;
761 GET_CURRENT_CONTEXT(ctx
);
762 ASSERT_OUTSIDE_BEGIN_END(ctx
);
764 if (target
== GL_VERTEX_PROGRAM_ARB
765 && ctx
->Extensions
.ARB_vertex_program
) {
766 prog
= &(ctx
->VertexProgram
.Current
->Base
);
767 maxParams
= ctx
->Const
.VertexProgram
.MaxLocalParams
;
769 else if (target
== GL_FRAGMENT_PROGRAM_ARB
770 && ctx
->Extensions
.ARB_fragment_program
) {
771 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
772 maxParams
= ctx
->Const
.FragmentProgram
.MaxLocalParams
;
774 else if (target
== GL_FRAGMENT_PROGRAM_NV
775 && ctx
->Extensions
.NV_fragment_program
) {
776 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
777 maxParams
= MAX_NV_FRAGMENT_PROGRAM_PARAMS
;
780 _mesa_error(ctx
, GL_INVALID_ENUM
,
781 "glGetProgramLocalParameterARB(target)");
785 if (index
>= maxParams
) {
786 _mesa_error(ctx
, GL_INVALID_VALUE
,
787 "glGetProgramLocalParameterARB(index)");
792 ASSERT(index
< MAX_PROGRAM_LOCAL_PARAMS
);
793 COPY_4V(params
, prog
->LocalParams
[index
]);
798 * Note, this function is also used by the GL_NV_fragment_program extension.
801 _mesa_GetProgramLocalParameterdvARB(GLenum target
, GLuint index
,
804 GET_CURRENT_CONTEXT(ctx
);
805 GLfloat floatParams
[4];
806 ASSIGN_4V(floatParams
, 0.0F
, 0.0F
, 0.0F
, 0.0F
);
807 _mesa_GetProgramLocalParameterfvARB(target
, index
, floatParams
);
808 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
809 COPY_4V(params
, floatParams
);
815 _mesa_GetProgramivARB(GLenum target
, GLenum pname
, GLint
*params
)
817 const struct gl_program_constants
*limits
;
818 struct gl_program
*prog
;
819 GET_CURRENT_CONTEXT(ctx
);
821 if (!ctx
->_CurrentProgram
)
822 ASSERT_OUTSIDE_BEGIN_END(ctx
);
824 if (target
== GL_VERTEX_PROGRAM_ARB
825 && ctx
->Extensions
.ARB_vertex_program
) {
826 prog
= &(ctx
->VertexProgram
.Current
->Base
);
827 limits
= &ctx
->Const
.VertexProgram
;
829 else if (target
== GL_FRAGMENT_PROGRAM_ARB
830 && ctx
->Extensions
.ARB_fragment_program
) {
831 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
832 limits
= &ctx
->Const
.FragmentProgram
;
835 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
842 /* Queries supported for both vertex and fragment programs */
844 case GL_PROGRAM_LENGTH_ARB
:
846 = prog
->String
? (GLint
) _mesa_strlen((char *) prog
->String
) : 0;
848 case GL_PROGRAM_FORMAT_ARB
:
849 *params
= prog
->Format
;
851 case GL_PROGRAM_BINDING_ARB
:
854 case GL_PROGRAM_INSTRUCTIONS_ARB
:
855 *params
= prog
->NumInstructions
;
857 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB
:
858 *params
= limits
->MaxInstructions
;
860 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
861 *params
= prog
->NumNativeInstructions
;
863 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
864 *params
= limits
->MaxNativeInstructions
;
866 case GL_PROGRAM_TEMPORARIES_ARB
:
867 *params
= prog
->NumTemporaries
;
869 case GL_MAX_PROGRAM_TEMPORARIES_ARB
:
870 *params
= limits
->MaxTemps
;
872 case GL_PROGRAM_NATIVE_TEMPORARIES_ARB
:
873 *params
= prog
->NumNativeTemporaries
;
875 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB
:
876 *params
= limits
->MaxNativeTemps
;
878 case GL_PROGRAM_PARAMETERS_ARB
:
879 *params
= prog
->NumParameters
;
881 case GL_MAX_PROGRAM_PARAMETERS_ARB
:
882 *params
= limits
->MaxParameters
;
884 case GL_PROGRAM_NATIVE_PARAMETERS_ARB
:
885 *params
= prog
->NumNativeParameters
;
887 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB
:
888 *params
= limits
->MaxNativeParameters
;
890 case GL_PROGRAM_ATTRIBS_ARB
:
891 *params
= prog
->NumAttributes
;
893 case GL_MAX_PROGRAM_ATTRIBS_ARB
:
894 *params
= limits
->MaxAttribs
;
896 case GL_PROGRAM_NATIVE_ATTRIBS_ARB
:
897 *params
= prog
->NumNativeAttributes
;
899 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB
:
900 *params
= limits
->MaxNativeAttribs
;
902 case GL_PROGRAM_ADDRESS_REGISTERS_ARB
:
903 *params
= prog
->NumAddressRegs
;
905 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB
:
906 *params
= limits
->MaxAddressRegs
;
908 case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
909 *params
= prog
->NumNativeAddressRegs
;
911 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
912 *params
= limits
->MaxNativeAddressRegs
;
914 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB
:
915 *params
= limits
->MaxLocalParams
;
917 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB
:
918 *params
= limits
->MaxEnvParams
;
920 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB
:
922 * XXX we may not really need a driver callback here.
923 * If the number of native instructions, registers, etc. used
924 * are all below the maximums, we could return true.
925 * The spec says that even if this query returns true, there's
926 * no guarantee that the program will run in hardware.
929 /* default/null program */
932 else if (ctx
->Driver
.IsProgramNative
) {
934 *params
= ctx
->Driver
.IsProgramNative( ctx
, target
, prog
);
937 /* probably running in software */
942 /* continue with fragment-program only queries below */
947 * The following apply to fragment programs only (at this time)
949 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
950 const struct gl_fragment_program
*fp
= ctx
->FragmentProgram
.Current
;
952 case GL_PROGRAM_ALU_INSTRUCTIONS_ARB
:
953 *params
= fp
->Base
.NumNativeAluInstructions
;
955 case GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
956 *params
= fp
->Base
.NumAluInstructions
;
958 case GL_PROGRAM_TEX_INSTRUCTIONS_ARB
:
959 *params
= fp
->Base
.NumTexInstructions
;
961 case GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
962 *params
= fp
->Base
.NumNativeTexInstructions
;
964 case GL_PROGRAM_TEX_INDIRECTIONS_ARB
:
965 *params
= fp
->Base
.NumTexIndirections
;
967 case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
968 *params
= fp
->Base
.NumNativeTexIndirections
;
970 case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB
:
971 *params
= limits
->MaxAluInstructions
;
973 case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
974 *params
= limits
->MaxNativeAluInstructions
;
976 case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB
:
977 *params
= limits
->MaxTexInstructions
;
979 case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
980 *params
= limits
->MaxNativeTexInstructions
;
982 case GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB
:
983 *params
= limits
->MaxTexIndirections
;
985 case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
986 *params
= limits
->MaxNativeTexIndirections
;
989 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
997 _mesa_GetProgramStringARB(GLenum target
, GLenum pname
, GLvoid
*string
)
999 const struct gl_program
*prog
;
1000 char *dst
= (char *) string
;
1001 GET_CURRENT_CONTEXT(ctx
);
1003 if (!ctx
->_CurrentProgram
)
1004 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1006 if (target
== GL_VERTEX_PROGRAM_ARB
) {
1007 prog
= &(ctx
->VertexProgram
.Current
->Base
);
1009 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
1010 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
1013 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(target)");
1019 if (pname
!= GL_PROGRAM_STRING_ARB
) {
1020 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(pname)");
1025 _mesa_memcpy(dst
, prog
->String
, _mesa_strlen((char *) prog
->String
));