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 && ctx
->Driver
.ProgramStringNotify
)
493 ctx
->Driver
.ProgramStringNotify( ctx
, target
, base
);
498 * Set a program env parameter register.
499 * \note Called from the GL API dispatcher.
500 * Note, this function is also used by the GL_NV_vertex_program extension
501 * (alias to ProgramParameterdNV)
504 _mesa_ProgramEnvParameter4dARB(GLenum target
, GLuint index
,
505 GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
507 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
508 (GLfloat
) z
, (GLfloat
) w
);
513 * Set a program env parameter register.
514 * \note Called from the GL API dispatcher.
515 * Note, this function is also used by the GL_NV_vertex_program extension
516 * (alias to ProgramParameterdvNV)
519 _mesa_ProgramEnvParameter4dvARB(GLenum target
, GLuint index
,
520 const GLdouble
*params
)
522 _mesa_ProgramEnvParameter4fARB(target
, index
, (GLfloat
) params
[0],
523 (GLfloat
) params
[1], (GLfloat
) params
[2],
524 (GLfloat
) params
[3]);
529 * Set a program env parameter register.
530 * \note Called from the GL API dispatcher.
531 * Note, this function is also used by the GL_NV_vertex_program extension
532 * (alias to ProgramParameterfNV)
535 _mesa_ProgramEnvParameter4fARB(GLenum target
, GLuint index
,
536 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
538 GET_CURRENT_CONTEXT(ctx
);
539 ASSERT_OUTSIDE_BEGIN_END(ctx
);
541 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
543 if (target
== GL_FRAGMENT_PROGRAM_ARB
544 && ctx
->Extensions
.ARB_fragment_program
) {
545 if (index
>= ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
546 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter(index)");
549 ASSIGN_4V(ctx
->FragmentProgram
.Parameters
[index
], x
, y
, z
, w
);
551 else if (target
== GL_VERTEX_PROGRAM_ARB
/* == GL_VERTEX_PROGRAM_NV */
552 && (ctx
->Extensions
.ARB_vertex_program
|| ctx
->Extensions
.NV_vertex_program
)) {
553 if (index
>= ctx
->Const
.VertexProgram
.MaxEnvParams
) {
554 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter(index)");
557 ASSIGN_4V(ctx
->VertexProgram
.Parameters
[index
], x
, y
, z
, w
);
560 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameter(target)");
568 * Set a program env parameter register.
569 * \note Called from the GL API dispatcher.
570 * Note, this function is also used by the GL_NV_vertex_program extension
571 * (alias to ProgramParameterfvNV)
574 _mesa_ProgramEnvParameter4fvARB(GLenum target
, GLuint index
,
575 const GLfloat
*params
)
577 GET_CURRENT_CONTEXT(ctx
);
578 ASSERT_OUTSIDE_BEGIN_END(ctx
);
580 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
582 if (target
== GL_FRAGMENT_PROGRAM_ARB
583 && ctx
->Extensions
.ARB_fragment_program
) {
584 if (index
>= ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
585 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter4fv(index)");
588 memcpy(ctx
->FragmentProgram
.Parameters
[index
], params
,
589 4 * sizeof(GLfloat
));
591 else if (target
== GL_VERTEX_PROGRAM_ARB
/* == GL_VERTEX_PROGRAM_NV */
592 && (ctx
->Extensions
.ARB_vertex_program
|| ctx
->Extensions
.NV_vertex_program
)) {
593 if (index
>= ctx
->Const
.VertexProgram
.MaxEnvParams
) {
594 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter4fv(index)");
597 memcpy(ctx
->VertexProgram
.Parameters
[index
], params
,
598 4 * sizeof(GLfloat
));
601 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameter4fv(target)");
608 _mesa_ProgramEnvParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
609 const GLfloat
*params
)
611 GET_CURRENT_CONTEXT(ctx
);
613 ASSERT_OUTSIDE_BEGIN_END(ctx
);
615 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
618 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(count)");
621 if (target
== GL_FRAGMENT_PROGRAM_ARB
622 && ctx
->Extensions
.ARB_fragment_program
) {
623 if ((index
+ count
) > ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
624 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
627 dest
= ctx
->FragmentProgram
.Parameters
[index
];
629 else if (target
== GL_VERTEX_PROGRAM_ARB
630 && ctx
->Extensions
.ARB_vertex_program
) {
631 if ((index
+ count
) > ctx
->Const
.VertexProgram
.MaxEnvParams
) {
632 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameters4fv(index + count)");
635 dest
= ctx
->VertexProgram
.Parameters
[index
];
638 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameters4fv(target)");
642 memcpy(dest
, params
, count
* 4 * sizeof(GLfloat
));
647 _mesa_GetProgramEnvParameterdvARB(GLenum target
, GLuint index
,
650 GET_CURRENT_CONTEXT(ctx
);
653 _mesa_GetProgramEnvParameterfvARB(target
, index
, fparams
);
654 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
655 params
[0] = fparams
[0];
656 params
[1] = fparams
[1];
657 params
[2] = fparams
[2];
658 params
[3] = fparams
[3];
664 _mesa_GetProgramEnvParameterfvARB(GLenum target
, GLuint index
,
667 GET_CURRENT_CONTEXT(ctx
);
669 ASSERT_OUTSIDE_BEGIN_END(ctx
);
671 if (target
== GL_FRAGMENT_PROGRAM_ARB
672 && ctx
->Extensions
.ARB_fragment_program
) {
673 if (index
>= ctx
->Const
.FragmentProgram
.MaxEnvParams
) {
674 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramEnvParameter(index)");
677 COPY_4V(params
, ctx
->FragmentProgram
.Parameters
[index
]);
679 else if (target
== GL_VERTEX_PROGRAM_ARB
680 && ctx
->Extensions
.ARB_vertex_program
) {
681 if (index
>= ctx
->Const
.VertexProgram
.MaxEnvParams
) {
682 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramEnvParameter(index)");
685 COPY_4V(params
, ctx
->VertexProgram
.Parameters
[index
]);
688 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramEnvParameter(target)");
695 * Note, this function is also used by the GL_NV_fragment_program extension.
698 _mesa_ProgramLocalParameter4fARB(GLenum target
, GLuint index
,
699 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
701 GET_CURRENT_CONTEXT(ctx
);
702 struct gl_program
*prog
;
703 ASSERT_OUTSIDE_BEGIN_END(ctx
);
705 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
707 if ((target
== GL_FRAGMENT_PROGRAM_NV
708 && ctx
->Extensions
.NV_fragment_program
) ||
709 (target
== GL_FRAGMENT_PROGRAM_ARB
710 && ctx
->Extensions
.ARB_fragment_program
)) {
711 if (index
>= ctx
->Const
.FragmentProgram
.MaxLocalParams
) {
712 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameterARB");
715 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
717 else if (target
== GL_VERTEX_PROGRAM_ARB
718 && ctx
->Extensions
.ARB_vertex_program
) {
719 if (index
>= ctx
->Const
.VertexProgram
.MaxLocalParams
) {
720 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameterARB");
723 prog
= &(ctx
->VertexProgram
.Current
->Base
);
726 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameterARB");
730 ASSERT(index
< MAX_PROGRAM_LOCAL_PARAMS
);
731 prog
->LocalParams
[index
][0] = x
;
732 prog
->LocalParams
[index
][1] = y
;
733 prog
->LocalParams
[index
][2] = z
;
734 prog
->LocalParams
[index
][3] = w
;
739 * Note, this function is also used by the GL_NV_fragment_program extension.
742 _mesa_ProgramLocalParameter4fvARB(GLenum target
, GLuint index
,
743 const GLfloat
*params
)
745 _mesa_ProgramLocalParameter4fARB(target
, index
, params
[0], params
[1],
746 params
[2], params
[3]);
751 _mesa_ProgramLocalParameters4fvEXT(GLenum target
, GLuint index
, GLsizei count
,
752 const GLfloat
*params
)
754 GET_CURRENT_CONTEXT(ctx
);
756 ASSERT_OUTSIDE_BEGIN_END(ctx
);
758 FLUSH_VERTICES(ctx
, _NEW_PROGRAM_CONSTANTS
);
761 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fv(count)");
764 if (target
== GL_FRAGMENT_PROGRAM_ARB
765 && ctx
->Extensions
.ARB_fragment_program
) {
766 if ((index
+ count
) > ctx
->Const
.FragmentProgram
.MaxLocalParams
) {
767 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fvEXT(index + count)");
770 dest
= ctx
->FragmentProgram
.Current
->Base
.LocalParams
[index
];
772 else if (target
== GL_VERTEX_PROGRAM_ARB
773 && ctx
->Extensions
.ARB_vertex_program
) {
774 if ((index
+ count
) > ctx
->Const
.VertexProgram
.MaxLocalParams
) {
775 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameters4fvEXT(index + count)");
778 dest
= ctx
->VertexProgram
.Current
->Base
.LocalParams
[index
];
781 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameters4fvEXT(target)");
785 memcpy(dest
, params
, count
* 4 * sizeof(GLfloat
));
790 * Note, this function is also used by the GL_NV_fragment_program extension.
793 _mesa_ProgramLocalParameter4dARB(GLenum target
, GLuint index
,
794 GLdouble x
, GLdouble y
,
795 GLdouble z
, GLdouble w
)
797 _mesa_ProgramLocalParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
798 (GLfloat
) z
, (GLfloat
) w
);
803 * Note, this function is also used by the GL_NV_fragment_program extension.
806 _mesa_ProgramLocalParameter4dvARB(GLenum target
, GLuint index
,
807 const GLdouble
*params
)
809 _mesa_ProgramLocalParameter4fARB(target
, index
,
810 (GLfloat
) params
[0], (GLfloat
) params
[1],
811 (GLfloat
) params
[2], (GLfloat
) params
[3]);
816 * Note, this function is also used by the GL_NV_fragment_program extension.
819 _mesa_GetProgramLocalParameterfvARB(GLenum target
, GLuint index
,
822 const struct gl_program
*prog
;
824 GET_CURRENT_CONTEXT(ctx
);
825 ASSERT_OUTSIDE_BEGIN_END(ctx
);
827 if (target
== GL_VERTEX_PROGRAM_ARB
828 && ctx
->Extensions
.ARB_vertex_program
) {
829 prog
= &(ctx
->VertexProgram
.Current
->Base
);
830 maxParams
= ctx
->Const
.VertexProgram
.MaxLocalParams
;
832 else if (target
== GL_FRAGMENT_PROGRAM_ARB
833 && ctx
->Extensions
.ARB_fragment_program
) {
834 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
835 maxParams
= ctx
->Const
.FragmentProgram
.MaxLocalParams
;
837 else if (target
== GL_FRAGMENT_PROGRAM_NV
838 && ctx
->Extensions
.NV_fragment_program
) {
839 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
840 maxParams
= MAX_NV_FRAGMENT_PROGRAM_PARAMS
;
843 _mesa_error(ctx
, GL_INVALID_ENUM
,
844 "glGetProgramLocalParameterARB(target)");
848 if (index
>= maxParams
) {
849 _mesa_error(ctx
, GL_INVALID_VALUE
,
850 "glGetProgramLocalParameterARB(index)");
855 ASSERT(index
< MAX_PROGRAM_LOCAL_PARAMS
);
856 COPY_4V(params
, prog
->LocalParams
[index
]);
861 * Note, this function is also used by the GL_NV_fragment_program extension.
864 _mesa_GetProgramLocalParameterdvARB(GLenum target
, GLuint index
,
867 GET_CURRENT_CONTEXT(ctx
);
868 GLfloat floatParams
[4];
869 ASSIGN_4V(floatParams
, 0.0F
, 0.0F
, 0.0F
, 0.0F
);
870 _mesa_GetProgramLocalParameterfvARB(target
, index
, floatParams
);
871 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
872 COPY_4V(params
, floatParams
);
878 _mesa_GetProgramivARB(GLenum target
, GLenum pname
, GLint
*params
)
880 const struct gl_program_constants
*limits
;
881 struct gl_program
*prog
;
882 GET_CURRENT_CONTEXT(ctx
);
884 ASSERT_OUTSIDE_BEGIN_END(ctx
);
886 if (target
== GL_VERTEX_PROGRAM_ARB
887 && ctx
->Extensions
.ARB_vertex_program
) {
888 prog
= &(ctx
->VertexProgram
.Current
->Base
);
889 limits
= &ctx
->Const
.VertexProgram
;
891 else if (target
== GL_FRAGMENT_PROGRAM_ARB
892 && ctx
->Extensions
.ARB_fragment_program
) {
893 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
894 limits
= &ctx
->Const
.FragmentProgram
;
897 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
904 /* Queries supported for both vertex and fragment programs */
906 case GL_PROGRAM_LENGTH_ARB
:
908 = prog
->String
? (GLint
) _mesa_strlen((char *) prog
->String
) : 0;
910 case GL_PROGRAM_FORMAT_ARB
:
911 *params
= prog
->Format
;
913 case GL_PROGRAM_BINDING_ARB
:
916 case GL_PROGRAM_INSTRUCTIONS_ARB
:
917 *params
= prog
->NumInstructions
;
919 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB
:
920 *params
= limits
->MaxInstructions
;
922 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
923 *params
= prog
->NumNativeInstructions
;
925 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
926 *params
= limits
->MaxNativeInstructions
;
928 case GL_PROGRAM_TEMPORARIES_ARB
:
929 *params
= prog
->NumTemporaries
;
931 case GL_MAX_PROGRAM_TEMPORARIES_ARB
:
932 *params
= limits
->MaxTemps
;
934 case GL_PROGRAM_NATIVE_TEMPORARIES_ARB
:
935 *params
= prog
->NumNativeTemporaries
;
937 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB
:
938 *params
= limits
->MaxNativeTemps
;
940 case GL_PROGRAM_PARAMETERS_ARB
:
941 *params
= prog
->NumParameters
;
943 case GL_MAX_PROGRAM_PARAMETERS_ARB
:
944 *params
= limits
->MaxParameters
;
946 case GL_PROGRAM_NATIVE_PARAMETERS_ARB
:
947 *params
= prog
->NumNativeParameters
;
949 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB
:
950 *params
= limits
->MaxNativeParameters
;
952 case GL_PROGRAM_ATTRIBS_ARB
:
953 *params
= prog
->NumAttributes
;
955 case GL_MAX_PROGRAM_ATTRIBS_ARB
:
956 *params
= limits
->MaxAttribs
;
958 case GL_PROGRAM_NATIVE_ATTRIBS_ARB
:
959 *params
= prog
->NumNativeAttributes
;
961 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB
:
962 *params
= limits
->MaxNativeAttribs
;
964 case GL_PROGRAM_ADDRESS_REGISTERS_ARB
:
965 *params
= prog
->NumAddressRegs
;
967 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB
:
968 *params
= limits
->MaxAddressRegs
;
970 case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
971 *params
= prog
->NumNativeAddressRegs
;
973 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
974 *params
= limits
->MaxNativeAddressRegs
;
976 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB
:
977 *params
= limits
->MaxLocalParams
;
979 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB
:
980 *params
= limits
->MaxEnvParams
;
982 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB
:
984 * XXX we may not really need a driver callback here.
985 * If the number of native instructions, registers, etc. used
986 * are all below the maximums, we could return true.
987 * The spec says that even if this query returns true, there's
988 * no guarantee that the program will run in hardware.
991 /* default/null program */
994 else if (ctx
->Driver
.IsProgramNative
) {
996 *params
= ctx
->Driver
.IsProgramNative( ctx
, target
, prog
);
999 /* probably running in software */
1004 /* continue with fragment-program only queries below */
1009 * The following apply to fragment programs only (at this time)
1011 if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
1012 const struct gl_fragment_program
*fp
= ctx
->FragmentProgram
.Current
;
1014 case GL_PROGRAM_ALU_INSTRUCTIONS_ARB
:
1015 *params
= fp
->Base
.NumNativeAluInstructions
;
1017 case GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
1018 *params
= fp
->Base
.NumAluInstructions
;
1020 case GL_PROGRAM_TEX_INSTRUCTIONS_ARB
:
1021 *params
= fp
->Base
.NumTexInstructions
;
1023 case GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
1024 *params
= fp
->Base
.NumNativeTexInstructions
;
1026 case GL_PROGRAM_TEX_INDIRECTIONS_ARB
:
1027 *params
= fp
->Base
.NumTexIndirections
;
1029 case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
1030 *params
= fp
->Base
.NumNativeTexIndirections
;
1032 case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB
:
1033 *params
= limits
->MaxAluInstructions
;
1035 case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
1036 *params
= limits
->MaxNativeAluInstructions
;
1038 case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB
:
1039 *params
= limits
->MaxTexInstructions
;
1041 case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
1042 *params
= limits
->MaxNativeTexInstructions
;
1044 case GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB
:
1045 *params
= limits
->MaxTexIndirections
;
1047 case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
1048 *params
= limits
->MaxNativeTexIndirections
;
1051 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
1055 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
1062 _mesa_GetProgramStringARB(GLenum target
, GLenum pname
, GLvoid
*string
)
1064 const struct gl_program
*prog
;
1065 char *dst
= (char *) string
;
1066 GET_CURRENT_CONTEXT(ctx
);
1068 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1070 if (target
== GL_VERTEX_PROGRAM_ARB
) {
1071 prog
= &(ctx
->VertexProgram
.Current
->Base
);
1073 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
1074 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
1077 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(target)");
1083 if (pname
!= GL_PROGRAM_STRING_ARB
) {
1084 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(pname)");
1089 _mesa_memcpy(dst
, prog
->String
, _mesa_strlen((char *) prog
->String
));