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"
40 #include "nvfragparse.h"
41 #include "nvvertparse.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 _mesa_EnableVertexAttribArrayARB(GLuint index
)
251 GET_CURRENT_CONTEXT(ctx
);
252 ASSERT_OUTSIDE_BEGIN_END(ctx
);
254 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
255 _mesa_error(ctx
, GL_INVALID_VALUE
,
256 "glEnableVertexAttribArrayARB(index)");
260 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
262 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
263 ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Enabled
= GL_TRUE
;
264 ctx
->Array
.ArrayObj
->_Enabled
|= _NEW_ARRAY_ATTRIB(index
);
265 ctx
->Array
.NewState
|= _NEW_ARRAY_ATTRIB(index
);
270 _mesa_DisableVertexAttribArrayARB(GLuint index
)
272 GET_CURRENT_CONTEXT(ctx
);
273 ASSERT_OUTSIDE_BEGIN_END(ctx
);
275 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
276 _mesa_error(ctx
, GL_INVALID_VALUE
,
277 "glEnableVertexAttribArrayARB(index)");
281 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
283 FLUSH_VERTICES(ctx
, _NEW_ARRAY
);
284 ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Enabled
= GL_FALSE
;
285 ctx
->Array
.ArrayObj
->_Enabled
&= ~_NEW_ARRAY_ATTRIB(index
);
286 ctx
->Array
.NewState
|= _NEW_ARRAY_ATTRIB(index
);
291 _mesa_GetVertexAttribdvARB(GLuint index
, GLenum pname
, GLdouble
*params
)
294 GET_CURRENT_CONTEXT(ctx
);
295 ASSERT_OUTSIDE_BEGIN_END(ctx
);
297 _mesa_GetVertexAttribfvARB(index
, pname
, fparams
);
298 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
299 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
300 COPY_4V(params
, fparams
);
303 params
[0] = fparams
[0];
310 * Return info for a generic vertex attribute array (no alias with
311 * legacy vertex attributes (pos, normal, color, etc)).
314 _mesa_GetVertexAttribfvARB(GLuint index
, GLenum pname
, GLfloat
*params
)
316 const struct gl_client_array
*array
;
317 GET_CURRENT_CONTEXT(ctx
);
318 ASSERT_OUTSIDE_BEGIN_END(ctx
);
320 if (index
>= MAX_VERTEX_GENERIC_ATTRIBS
) {
321 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribfvARB(index)");
325 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
327 array
= &ctx
->Array
.ArrayObj
->VertexAttrib
[index
];
330 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
331 params
[0] = (GLfloat
) array
->Enabled
;
333 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
334 params
[0] = (GLfloat
) array
->Size
;
336 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
337 params
[0] = (GLfloat
) array
->Stride
;
339 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
340 params
[0] = (GLfloat
) array
->Type
;
342 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
343 params
[0] = array
->Normalized
;
345 case GL_CURRENT_VERTEX_ATTRIB_ARB
:
347 _mesa_error(ctx
, GL_INVALID_OPERATION
,
348 "glGetVertexAttribfvARB(index==0)");
351 FLUSH_CURRENT(ctx
, 0);
352 COPY_4V(params
, ctx
->Current
.Attrib
[VERT_ATTRIB_GENERIC0
+ index
]);
354 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
355 params
[0] = (GLfloat
) array
->BufferObj
->Name
;
358 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribfvARB(pname)");
365 _mesa_GetVertexAttribivARB(GLuint index
, GLenum pname
, GLint
*params
)
368 GET_CURRENT_CONTEXT(ctx
);
369 ASSERT_OUTSIDE_BEGIN_END(ctx
);
371 _mesa_GetVertexAttribfvARB(index
, pname
, fparams
);
372 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
373 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
374 COPY_4V_CAST(params
, fparams
, GLint
); /* float to int */
377 params
[0] = (GLint
) fparams
[0];
384 _mesa_GetVertexAttribPointervARB(GLuint index
, GLenum pname
, GLvoid
**pointer
)
386 GET_CURRENT_CONTEXT(ctx
);
387 ASSERT_OUTSIDE_BEGIN_END(ctx
);
389 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
390 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
394 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
395 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
399 ASSERT(index
< Elements(ctx
->Array
.ArrayObj
->VertexAttrib
));
401 *pointer
= (GLvoid
*) ctx
->Array
.ArrayObj
->VertexAttrib
[index
].Ptr
;
406 * Determine if id names a vertex or fragment program.
407 * \note Not compiled into display lists.
408 * \note Called from both glIsProgramNV and glIsProgramARB.
409 * \param id is the program identifier
410 * \return GL_TRUE if id is a program, else GL_FALSE.
413 _mesa_IsProgramARB(GLuint id
)
415 struct gl_program
*prog
= NULL
;
416 GET_CURRENT_CONTEXT(ctx
);
417 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
422 prog
= _mesa_lookup_program(ctx
, id
);
423 if (prog
&& (prog
!= &_mesa_DummyProgram
))
431 _mesa_ProgramStringARB(GLenum target
, GLenum format
, GLsizei len
,
432 const GLvoid
*string
)
434 struct gl_program
*base
;
435 GET_CURRENT_CONTEXT(ctx
);
436 ASSERT_OUTSIDE_BEGIN_END(ctx
);
438 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
440 if (!ctx
->Extensions
.ARB_vertex_program
441 && !ctx
->Extensions
.ARB_fragment_program
) {
442 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glProgramStringARB()");
446 if (format
!= GL_PROGRAM_FORMAT_ASCII_ARB
) {
447 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(format)");
451 /* The first couple cases are complicated. The same enum value is used for
452 * ARB and NV vertex programs. If the target is a vertex program, parse it
453 * using the ARB grammar if the string starts with "!!ARB" or if
454 * NV_vertex_program is not supported.
456 if (target
== GL_VERTEX_PROGRAM_ARB
457 && ctx
->Extensions
.ARB_vertex_program
458 && ((strncmp(string
, "!!ARB", 5) == 0)
459 || !ctx
->Extensions
.NV_vertex_program
)) {
460 struct gl_vertex_program
*prog
= ctx
->VertexProgram
.Current
;
461 _mesa_parse_arb_vertex_program(ctx
, target
, string
, len
, prog
);
465 else if ((target
== GL_VERTEX_PROGRAM_ARB
466 || target
== GL_VERTEX_STATE_PROGRAM_NV
)
467 && ctx
->Extensions
.NV_vertex_program
) {
468 struct gl_vertex_program
*prog
= ctx
->VertexProgram
.Current
;
469 _mesa_parse_nv_vertex_program(ctx
, target
, string
, len
, prog
);
473 else if (target
== GL_FRAGMENT_PROGRAM_ARB
474 && ctx
->Extensions
.ARB_fragment_program
) {
475 struct gl_fragment_program
*prog
= ctx
->FragmentProgram
.Current
;
476 _mesa_parse_arb_fragment_program(ctx
, target
, string
, len
, prog
);
480 else if (target
== GL_FRAGMENT_PROGRAM_NV
481 && ctx
->Extensions
.NV_fragment_program
) {
482 struct gl_fragment_program
*prog
= ctx
->FragmentProgram
.Current
;
483 _mesa_parse_nv_fragment_program(ctx
, target
, string
, len
, prog
);
488 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(target)");
492 if (ctx
->Program
.ErrorPos
== -1) {
493 /* finally, give the program to the driver for translation/checking */
494 if (!ctx
->Driver
.ProgramStringNotify(ctx
, target
, base
)) {
495 _mesa_error(ctx
, GL_INVALID_OPERATION
,
496 "glProgramStringARB(rejected by driver");
503 * Set a program env parameter register.
504 * \note Called from the GL API dispatcher.
505 * Note, this function is also used by the GL_NV_vertex_program extension
506 * (alias to ProgramParameterdNV)
509 _mesa_ProgramEnvParameter4dARB(GLenum target
, GLuint index
,
510 GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
512 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
513 (GLfloat
) z
, (GLfloat
) w
);
518 * Set a program env parameter register.
519 * \note Called from the GL API dispatcher.
520 * Note, this function is also used by the GL_NV_vertex_program extension
521 * (alias to ProgramParameterdvNV)
524 _mesa_ProgramEnvParameter4dvARB(GLenum target
, GLuint index
,
525 const GLdouble
*params
)
527 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) params
[0],
528 (GLfloat
) params
[1], (GLfloat
) params
[2],
529 (GLfloat
) params
[3]);
534 * Set a program env parameter register.
535 * \note Called from the GL API dispatcher.
536 * Note, this function is also used by the GL_NV_vertex_program extension
537 * (alias to ProgramParameterfNV)
540 _mesa_ProgramEnvParameter4fARB(GLenum target
, GLuint index
,
541 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
543 GET_CURRENT_CONTEXT(ctx
);
544 ASSERT_OUTSIDE_BEGIN_END(ctx
);
546 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
548 if (target
== GL_FRAGMENT_PROGRAM_ARB
549 && ctx
->Extensions
.ARB_fragment_program
) {
550 if (index
>= ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
551 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter(index)");
554 ASSIGN_4V(ctx
->FragmentProgram
.Parameters
[index
], x
, y
, z
, w
);
556 else if (target
== GL_VERTEX_PROGRAM_ARB
/* == GL_VERTEX_PROGRAM_NV */
557 && (ctx
->Extensions
.ARB_vertex_program
|| ctx
->Extensions
.NV_vertex_program
)) {
558 if (index
>= ctx
->Const
.VertexProgram
.MaxEnvParams
) {
559 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter(index)");
562 ASSIGN_4V(ctx
->VertexProgram
.Parameters
[index
], x
, y
, z
, w
);
565 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameter(target)");
573 * Set a program env parameter register.
574 * \note Called from the GL API dispatcher.
575 * Note, this function is also used by the GL_NV_vertex_program extension
576 * (alias to ProgramParameterfvNV)
579 _mesa_ProgramEnvParameter4fvARB(GLenum target
, GLuint index
,
580 const GLfloat
*params
)
582 GET_CURRENT_CONTEXT(ctx
);
583 ASSERT_OUTSIDE_BEGIN_END(ctx
);
585 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
587 if (target
== GL_FRAGMENT_PROGRAM_ARB
588 && ctx
->Extensions
.ARB_fragment_program
) {
589 if (index
>= ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
590 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter4fv(index)");
593 memcpy(ctx
->FragmentProgram
.Parameters
[index
], params
,
594 4 * sizeof(GLfloat
));
596 else if (target
== GL_VERTEX_PROGRAM_ARB
/* == GL_VERTEX_PROGRAM_NV */
597 && (ctx
->Extensions
.ARB_vertex_program
|| ctx
->Extensions
.NV_vertex_program
)) {
598 if (index
>= ctx
->Const
.VertexProgram
.MaxEnvParams
) {
599 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter4fv(index)");
602 memcpy(ctx
->VertexProgram
.Parameters
[index
], params
,
603 4 * sizeof(GLfloat
));
606 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameter4fv(target)");
613 _mesa_ProgramEnvParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
614 const GLfloat
*params
)
616 GET_CURRENT_CONTEXT(ctx
);
618 ASSERT_OUTSIDE_BEGIN_END(ctx
);
620 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
623 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(count)");
626 if (target
== GL_FRAGMENT_PROGRAM_ARB
627 && ctx
->Extensions
.ARB_fragment_program
) {
628 if ((index
+ count
) > ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
629 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
632 dest
= ctx
->FragmentProgram
.Parameters
[index
];
634 else if (target
== GL_VERTEX_PROGRAM_ARB
635 && ctx
->Extensions
.ARB_vertex_program
) {
636 if ((index
+ count
) > ctx
->Const
.VertexProgram
.MaxEnvParams
) {
637 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
640 dest
= ctx
->VertexProgram
.Parameters
[index
];
643 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameters4fv(target)");
647 memcpy(dest
, params
, count
* 4 * sizeof(GLfloat
));
652 _mesa_GetProgramEnvParameterdvARB(GLenum target
, GLuint index
,
655 GET_CURRENT_CONTEXT(ctx
);
658 _mesa_GetProgramEnvParameterfvARB(target
, index
, fparams
);
659 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
660 params
[0] = fparams
[0];
661 params
[1] = fparams
[1];
662 params
[2] = fparams
[2];
663 params
[3] = fparams
[3];
669 _mesa_GetProgramEnvParameterfvARB(GLenum target
, GLuint index
,
672 GET_CURRENT_CONTEXT(ctx
);
674 ASSERT_OUTSIDE_BEGIN_END(ctx
);
676 if (target
== GL_FRAGMENT_PROGRAM_ARB
677 && ctx
->Extensions
.ARB_fragment_program
) {
678 if (index
>= ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
679 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramEnvParameter(index)");
682 COPY_4V(params
, ctx
->FragmentProgram
.Parameters
[index
]);
684 else if (target
== GL_VERTEX_PROGRAM_ARB
685 && ctx
->Extensions
.ARB_vertex_program
) {
686 if (index
>= ctx
->Const
.VertexProgram
.MaxEnvParams
) {
687 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramEnvParameter(index)");
690 COPY_4V(params
, ctx
->VertexProgram
.Parameters
[index
]);
693 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramEnvParameter(target)");
700 * Note, this function is also used by the GL_NV_fragment_program extension.
703 _mesa_ProgramLocalParameter4fARB(GLenum target
, GLuint index
,
704 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
706 GET_CURRENT_CONTEXT(ctx
);
707 struct gl_program
*prog
;
708 ASSERT_OUTSIDE_BEGIN_END(ctx
);
710 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
712 if ((target
== GL_FRAGMENT_PROGRAM_NV
713 && ctx
->Extensions
.NV_fragment_program
) ||
714 (target
== GL_FRAGMENT_PROGRAM_ARB
715 && ctx
->Extensions
.ARB_fragment_program
)) {
716 if (index
>= ctx
->Const
.FragmentProgram
.MaxLocalParams
) {
717 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameterARB");
720 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
722 else if (target
== GL_VERTEX_PROGRAM_ARB
723 && ctx
->Extensions
.ARB_vertex_program
) {
724 if (index
>= ctx
->Const
.VertexProgram
.MaxLocalParams
) {
725 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameterARB");
728 prog
= &(ctx
->VertexProgram
.Current
->Base
);
731 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameterARB");
735 ASSERT(index
< MAX_PROGRAM_LOCAL_PARAMS
);
736 prog
->LocalParams
[index
][0] = x
;
737 prog
->LocalParams
[index
][1] = y
;
738 prog
->LocalParams
[index
][2] = z
;
739 prog
->LocalParams
[index
][3] = w
;
744 * Note, this function is also used by the GL_NV_fragment_program extension.
747 _mesa_ProgramLocalParameter4fvARB(GLenum target
, GLuint index
,
748 const GLfloat
*params
)
750 _mesa_ProgramLocalParameter4fARB(target
, index
, params
[0], params
[1],
751 params
[2], params
[3]);
756 _mesa_ProgramLocalParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
757 const GLfloat
*params
)
759 GET_CURRENT_CONTEXT(ctx
);
761 ASSERT_OUTSIDE_BEGIN_END(ctx
);
763 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
766 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fv(count)");
769 if (target
== GL_FRAGMENT_PROGRAM_ARB
770 && ctx
->Extensions
.ARB_fragment_program
) {
771 if ((index
+ count
) > ctx
->Const
.FragmentProgram
.MaxLocalParams
) {
772 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fvEXT(index + count)");
775 dest
= ctx
->FragmentProgram
.Current
->Base
.LocalParams
[index
];
777 else if (target
== GL_VERTEX_PROGRAM_ARB
778 && ctx
->Extensions
.ARB_vertex_program
) {
779 if ((index
+ count
) > ctx
->Const
.VertexProgram
.MaxLocalParams
) {
780 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fvEXT(index + count)");
783 dest
= ctx
->VertexProgram
.Current
->Base
.LocalParams
[index
];
786 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameters4fvEXT(target)");
790 memcpy(dest
, params
, count
* 4 * sizeof(GLfloat
));
795 * Note, this function is also used by the GL_NV_fragment_program extension.
798 _mesa_ProgramLocalParameter4dARB(GLenum target
, GLuint index
,
799 GLdouble x
, GLdouble y
,
800 GLdouble z
, GLdouble w
)
802 _mesa_ProgramLocalParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
803 (GLfloat
) z
, (GLfloat
) w
);
808 * Note, this function is also used by the GL_NV_fragment_program extension.
811 _mesa_ProgramLocalParameter4dvARB(GLenum target
, GLuint index
,
812 const GLdouble
*params
)
814 _mesa_ProgramLocalParameter4fARB(target
, index
,
815 (GLfloat
) params
[0], (GLfloat
) params
[1],
816 (GLfloat
) params
[2], (GLfloat
) params
[3]);
821 * Note, this function is also used by the GL_NV_fragment_program extension.
824 _mesa_GetProgramLocalParameterfvARB(GLenum target
, GLuint index
,
827 const struct gl_program
*prog
;
829 GET_CURRENT_CONTEXT(ctx
);
830 ASSERT_OUTSIDE_BEGIN_END(ctx
);
832 if (target
== GL_VERTEX_PROGRAM_ARB
833 && ctx
->Extensions
.ARB_vertex_program
) {
834 prog
= &(ctx
->VertexProgram
.Current
->Base
);
835 maxParams
= ctx
->Const
.VertexProgram
.MaxLocalParams
;
837 else if (target
== GL_FRAGMENT_PROGRAM_ARB
838 && ctx
->Extensions
.ARB_fragment_program
) {
839 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
840 maxParams
= ctx
->Const
.FragmentProgram
.MaxLocalParams
;
842 else if (target
== GL_FRAGMENT_PROGRAM_NV
843 && ctx
->Extensions
.NV_fragment_program
) {
844 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
845 maxParams
= MAX_NV_FRAGMENT_PROGRAM_PARAMS
;
848 _mesa_error(ctx
, GL_INVALID_ENUM
,
849 "glGetProgramLocalParameterARB(target)");
853 if (index
>= maxParams
) {
854 _mesa_error(ctx
, GL_INVALID_VALUE
,
855 "glGetProgramLocalParameterARB(index)");
860 ASSERT(index
< MAX_PROGRAM_LOCAL_PARAMS
);
861 COPY_4V(params
, prog
->LocalParams
[index
]);
866 * Note, this function is also used by the GL_NV_fragment_program extension.
869 _mesa_GetProgramLocalParameterdvARB(GLenum target
, GLuint index
,
872 GET_CURRENT_CONTEXT(ctx
);
873 GLfloat floatParams
[4];
874 ASSIGN_4V(floatParams
, 0.0F
, 0.0F
, 0.0F
, 0.0F
);
875 _mesa_GetProgramLocalParameterfvARB(target
, index
, floatParams
);
876 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
877 COPY_4V(params
, floatParams
);
883 _mesa_GetProgramivARB(GLenum target
, GLenum pname
, GLint
*params
)
885 const struct gl_program_constants
*limits
;
886 struct gl_program
*prog
;
887 GET_CURRENT_CONTEXT(ctx
);
889 ASSERT_OUTSIDE_BEGIN_END(ctx
);
891 if (target
== GL_VERTEX_PROGRAM_ARB
892 && ctx
->Extensions
.ARB_vertex_program
) {
893 prog
= &(ctx
->VertexProgram
.Current
->Base
);
894 limits
= &ctx
->Const
.VertexProgram
;
896 else if (target
== GL_FRAGMENT_PROGRAM_ARB
897 && ctx
->Extensions
.ARB_fragment_program
) {
898 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
899 limits
= &ctx
->Const
.FragmentProgram
;
902 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
909 /* Queries supported for both vertex and fragment programs */
911 case GL_PROGRAM_LENGTH_ARB
:
913 = prog
->String
? (GLint
) strlen((char *) prog
->String
) : 0;
915 case GL_PROGRAM_FORMAT_ARB
:
916 *params
= prog
->Format
;
918 case GL_PROGRAM_BINDING_ARB
:
921 case GL_PROGRAM_INSTRUCTIONS_ARB
:
922 *params
= prog
->NumInstructions
;
924 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB
:
925 *params
= limits
->MaxInstructions
;
927 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
928 *params
= prog
->NumNativeInstructions
;
930 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
931 *params
= limits
->MaxNativeInstructions
;
933 case GL_PROGRAM_TEMPORARIES_ARB
:
934 *params
= prog
->NumTemporaries
;
936 case GL_MAX_PROGRAM_TEMPORARIES_ARB
:
937 *params
= limits
->MaxTemps
;
939 case GL_PROGRAM_NATIVE_TEMPORARIES_ARB
:
940 *params
= prog
->NumNativeTemporaries
;
942 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB
:
943 *params
= limits
->MaxNativeTemps
;
945 case GL_PROGRAM_PARAMETERS_ARB
:
946 *params
= prog
->NumParameters
;
948 case GL_MAX_PROGRAM_PARAMETERS_ARB
:
949 *params
= limits
->MaxParameters
;
951 case GL_PROGRAM_NATIVE_PARAMETERS_ARB
:
952 *params
= prog
->NumNativeParameters
;
954 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB
:
955 *params
= limits
->MaxNativeParameters
;
957 case GL_PROGRAM_ATTRIBS_ARB
:
958 *params
= prog
->NumAttributes
;
960 case GL_MAX_PROGRAM_ATTRIBS_ARB
:
961 *params
= limits
->MaxAttribs
;
963 case GL_PROGRAM_NATIVE_ATTRIBS_ARB
:
964 *params
= prog
->NumNativeAttributes
;
966 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB
:
967 *params
= limits
->MaxNativeAttribs
;
969 case GL_PROGRAM_ADDRESS_REGISTERS_ARB
:
970 *params
= prog
->NumAddressRegs
;
972 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB
:
973 *params
= limits
->MaxAddressRegs
;
975 case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
976 *params
= prog
->NumNativeAddressRegs
;
978 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
979 *params
= limits
->MaxNativeAddressRegs
;
981 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB
:
982 *params
= limits
->MaxLocalParams
;
984 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB
:
985 *params
= limits
->MaxEnvParams
;
987 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB
:
989 * XXX we may not really need a driver callback here.
990 * If the number of native instructions, registers, etc. used
991 * are all below the maximums, we could return true.
992 * The spec says that even if this query returns true, there's
993 * no guarantee that the program will run in hardware.
996 /* default/null program */
999 else if (ctx
->Driver
.IsProgramNative
) {
1000 /* ask the driver */
1001 *params
= ctx
->Driver
.IsProgramNative( ctx
, target
, prog
);
1004 /* probably running in software */
1009 /* continue with fragment-program only queries below */
1014 * The following apply to fragment programs only (at this time)
1016 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
1017 const struct gl_fragment_program
*fp
= ctx
->FragmentProgram
.Current
;
1019 case GL_PROGRAM_ALU_INSTRUCTIONS_ARB
:
1020 *params
= fp
->Base
.NumNativeAluInstructions
;
1022 case GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
1023 *params
= fp
->Base
.NumAluInstructions
;
1025 case GL_PROGRAM_TEX_INSTRUCTIONS_ARB
:
1026 *params
= fp
->Base
.NumTexInstructions
;
1028 case GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
1029 *params
= fp
->Base
.NumNativeTexInstructions
;
1031 case GL_PROGRAM_TEX_INDIRECTIONS_ARB
:
1032 *params
= fp
->Base
.NumTexIndirections
;
1034 case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
1035 *params
= fp
->Base
.NumNativeTexIndirections
;
1037 case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB
:
1038 *params
= limits
->MaxAluInstructions
;
1040 case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
1041 *params
= limits
->MaxNativeAluInstructions
;
1043 case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB
:
1044 *params
= limits
->MaxTexInstructions
;
1046 case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
1047 *params
= limits
->MaxNativeTexInstructions
;
1049 case GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB
:
1050 *params
= limits
->MaxTexIndirections
;
1052 case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
1053 *params
= limits
->MaxNativeTexIndirections
;
1056 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
1060 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
1067 _mesa_GetProgramStringARB(GLenum target
, GLenum pname
, GLvoid
*string
)
1069 const struct gl_program
*prog
;
1070 char *dst
= (char *) string
;
1071 GET_CURRENT_CONTEXT(ctx
);
1073 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1075 if (target
== GL_VERTEX_PROGRAM_ARB
) {
1076 prog
= &(ctx
->VertexProgram
.Current
->Base
);
1078 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
1079 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
1082 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(target)");
1088 if (pname
!= GL_PROGRAM_STRING_ARB
) {
1089 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(pname)");
1094 memcpy(dst
, prog
->String
, strlen((char *) prog
->String
));