2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2003 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 * \brief ARB_vertex/fragment_program state management functions.
38 #include "nvprogram.h"
39 #include "arbprogram.h"
44 _mesa_parse_arb_vertex_program(GLcontext
*ctx
, GLenum target
,
45 const GLubyte
*string
, GLsizei len
,
46 struct vertex_program
*prog
)
52 _mesa_parse_arb_fragment_program(GLcontext
*ctx
, GLenum target
,
53 const GLubyte
*string
, GLsizei len
,
54 struct fragment_program
*prog
)
61 _mesa_VertexAttrib1sARB(GLuint index
, GLshort x
)
66 _mesa_VertexAttrib1fARB(GLuint index
, GLfloat x
)
71 _mesa_VertexAttrib1dARB(GLuint index
, GLdouble x
)
76 _mesa_VertexAttrib2sARB(GLuint index
, GLshort x
, GLshort y
)
81 _mesa_VertexAttrib2fARB(GLuint index
, GLfloat x
, GLfloat y
)
86 _mesa_VertexAttrib2dARB(GLuint index
, GLdouble x
, GLdouble y
)
91 _mesa_VertexAttrib3sARB(GLuint index
, GLshort x
, GLshort y
, GLshort z
)
96 _mesa_VertexAttrib3fARB(GLuint index
, GLfloat x
, GLfloat y
, GLfloat z
)
101 _mesa_VertexAttrib3dARB(GLuint index
, GLdouble x
, GLdouble y
, GLdouble z
)
106 _mesa_VertexAttrib4sARB(GLuint index
, GLshort x
, GLshort y
, GLshort z
, GLshort w
)
111 _mesa_VertexAttrib4fARB(GLuint index
, GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
116 _mesa_VertexAttrib4dARB(GLuint index
, GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
121 _mesa_VertexAttrib4NubARB(GLuint index
, GLubyte x
, GLubyte y
, GLubyte z
, GLubyte w
)
126 _mesa_VertexAttrib1svARB(GLuint index
, const GLshort
*v
)
131 _mesa_VertexAttrib1fvARB(GLuint index
, const GLfloat
*v
)
136 _mesa_VertexAttrib1dvARB(GLuint index
, const GLdouble
*v
)
141 _mesa_VertexAttrib2svARB(GLuint index
, const GLshort
*v
)
146 _mesa_VertexAttrib2fvARB(GLuint index
, const GLfloat
*v
)
151 _mesa_VertexAttrib2dvARB(GLuint index
, const GLdouble
*v
)
156 _mesa_VertexAttrib3svARB(GLuint index
, const GLshort
*v
)
161 _mesa_VertexAttrib3fvARB(GLuint index
, const GLfloat
*v
)
166 _mesa_VertexAttrib3dvARB(GLuint index
, const GLdouble
*v
)
171 _mesa_VertexAttrib4bvARB(GLuint index
, const GLbyte
*v
)
176 _mesa_VertexAttrib4svARB(GLuint index
, const GLshort
*v
)
181 _mesa_VertexAttrib4ivARB(GLuint index
, const GLint
*v
)
186 _mesa_VertexAttrib4ubvARB(GLuint index
, const GLubyte
*v
)
191 _mesa_VertexAttrib4usvARB(GLuint index
, const GLushort
*v
)
196 _mesa_VertexAttrib4uivARB(GLuint index
, const GLuint
*v
)
201 _mesa_VertexAttrib4fvARB(GLuint index
, const GLfloat
*v
)
206 _mesa_VertexAttrib4dvARB(GLuint index
, const GLdouble
*v
)
211 _mesa_VertexAttrib4NbvARB(GLuint index
, const GLbyte
*v
)
216 _mesa_VertexAttrib4NsvARB(GLuint index
, const GLshort
*v
)
221 _mesa_VertexAttrib4NivARB(GLuint index
, const GLint
*v
)
226 _mesa_VertexAttrib4NubvARB(GLuint index
, const GLubyte
*v
)
231 _mesa_VertexAttrib4NusvARB(GLuint index
, const GLushort
*v
)
236 _mesa_VertexAttrib4NuivARB(GLuint index
, const GLuint
*v
)
242 _mesa_VertexAttribPointerARB(GLuint index
, GLint size
, GLenum type
,
243 GLboolean normalized
, GLsizei stride
,
244 const GLvoid
*pointer
)
250 _mesa_EnableVertexAttribArrayARB(GLuint index
)
252 GET_CURRENT_CONTEXT(ctx
);
253 ASSERT_OUTSIDE_BEGIN_END(ctx
);
255 if (index
>= ctx
->Const
.MaxVertexProgramAttribs
) {
256 _mesa_error(ctx
, GL_INVALID_VALUE
,
257 "glEnableVertexAttribArrayARB(index)");
261 ctx
->Array
.VertexAttrib
[index
].Enabled
= GL_TRUE
;
262 ctx
->Array
._Enabled
|= _NEW_ARRAY_ATTRIB(index
);
263 ctx
->Array
.NewState
|= _NEW_ARRAY_ATTRIB(index
);
268 _mesa_DisableVertexAttribArrayARB(GLuint index
)
270 GET_CURRENT_CONTEXT(ctx
);
271 ASSERT_OUTSIDE_BEGIN_END(ctx
);
273 if (index
>= ctx
->Const
.MaxVertexProgramAttribs
) {
274 _mesa_error(ctx
, GL_INVALID_VALUE
,
275 "glEnableVertexAttribArrayARB(index)");
279 ctx
->Array
.VertexAttrib
[index
].Enabled
= GL_FALSE
;
280 ctx
->Array
._Enabled
&= ~_NEW_ARRAY_ATTRIB(index
);
281 ctx
->Array
.NewState
&= ~_NEW_ARRAY_ATTRIB(index
);
286 _mesa_GetVertexAttribdvARB(GLuint index
, GLenum pname
, GLdouble
*params
)
289 GET_CURRENT_CONTEXT(ctx
);
290 ASSERT_OUTSIDE_BEGIN_END(ctx
);
292 _mesa_GetVertexAttribfvARB(index
, pname
, fparams
);
293 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
294 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
295 COPY_4V(params
, fparams
);
298 params
[0] = fparams
[0];
305 _mesa_GetVertexAttribfvARB(GLuint index
, GLenum pname
, GLfloat
*params
)
307 GET_CURRENT_CONTEXT(ctx
);
308 ASSERT_OUTSIDE_BEGIN_END(ctx
);
310 if (index
== 0 || index
>= VERT_ATTRIB_MAX
) {
311 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribfvARB(index)");
316 case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB
:
317 params
[0] = ctx
->Array
.VertexAttrib
[index
].Enabled
;
319 case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB
:
320 params
[0] = ctx
->Array
.VertexAttrib
[index
].Size
;
322 case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB
:
323 params
[0] = ctx
->Array
.VertexAttrib
[index
].Stride
;
325 case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB
:
326 params
[0] = ctx
->Array
.VertexAttrib
[index
].Type
;
328 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB
:
329 params
[0] = ctx
->Array
.VertexAttrib
[index
].Normalized
;
331 case GL_CURRENT_VERTEX_ATTRIB_ARB
:
332 COPY_4V(params
, ctx
->Current
.Attrib
[index
]);
335 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribfvARB(pname)");
342 _mesa_GetVertexAttribivARB(GLuint index
, GLenum pname
, GLint
*params
)
345 GET_CURRENT_CONTEXT(ctx
);
346 ASSERT_OUTSIDE_BEGIN_END(ctx
);
348 _mesa_GetVertexAttribfvARB(index
, pname
, fparams
);
349 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
350 if (pname
== GL_CURRENT_VERTEX_ATTRIB_ARB
) {
351 COPY_4V(params
, fparams
); /* float to int */
354 params
[0] = fparams
[0];
361 _mesa_GetVertexAttribPointervARB(GLuint index
, GLenum pname
, GLvoid
**pointer
)
363 GET_CURRENT_CONTEXT(ctx
);
364 ASSERT_OUTSIDE_BEGIN_END(ctx
);
366 if (index
>= ctx
->Const
.MaxVertexProgramAttribs
) {
367 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerARB(index)");
371 if (pname
!= GL_VERTEX_ATTRIB_ARRAY_POINTER_ARB
) {
372 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerARB(pname)");
376 *pointer
= ctx
->Array
.VertexAttrib
[index
].Ptr
;;
381 _mesa_ProgramStringARB(GLenum target
, GLenum format
, GLsizei len
,
382 const GLvoid
*string
)
384 GET_CURRENT_CONTEXT(ctx
);
385 ASSERT_OUTSIDE_BEGIN_END(ctx
);
387 if (target
== GL_VERTEX_PROGRAM_ARB
388 && ctx
->Extensions
.ARB_vertex_program
) {
389 struct vertex_program
*prog
= ctx
->VertexProgram
.Current
;
390 if (format
!= GL_PROGRAM_FORMAT_ASCII_ARB
) {
391 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(format)");
394 _mesa_parse_arb_vertex_program(ctx
, target
, string
, len
, prog
);
396 else if (target
== GL_FRAGMENT_PROGRAM_ARB
397 && ctx
->Extensions
.ARB_fragment_program
) {
398 struct fragment_program
*prog
= ctx
->FragmentProgram
.Current
;
399 if (format
!= GL_PROGRAM_FORMAT_ASCII_ARB
) {
400 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(format)");
403 _mesa_parse_arb_fragment_program(ctx
, target
, string
, len
, prog
);
406 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramStringARB(target)");
412 _mesa_BindProgramARB(GLenum target
, GLuint program
)
414 struct program
*prog
;
415 GET_CURRENT_CONTEXT(ctx
);
416 ASSERT_OUTSIDE_BEGIN_END(ctx
);
418 if (target
== GL_VERTEX_PROGRAM_ARB
419 && ctx
->Extensions
.ARB_vertex_program
) {
420 if (ctx
->VertexProgram
.Current
&&
421 ctx
->VertexProgram
.Current
->Base
.Id
== program
)
423 /* decrement refcount on previously bound vertex program */
424 if (ctx
->VertexProgram
.Current
) {
425 ctx
->VertexProgram
.Current
->Base
.RefCount
--;
426 /* and delete if refcount goes below one */
427 if (ctx
->VertexProgram
.Current
->Base
.RefCount
<= 0) {
428 _mesa_delete_program(ctx
, &(ctx
->VertexProgram
.Current
->Base
));
429 _mesa_HashRemove(ctx
->Shared
->Programs
, program
);
433 else if (target
== GL_FRAGMENT_PROGRAM_ARB
434 && ctx
->Extensions
.ARB_fragment_program
) {
435 if (ctx
->FragmentProgram
.Current
&&
436 ctx
->FragmentProgram
.Current
->Base
.Id
== program
)
438 /* decrement refcount on previously bound fragment program */
439 if (ctx
->FragmentProgram
.Current
) {
440 ctx
->FragmentProgram
.Current
->Base
.RefCount
--;
441 /* and delete if refcount goes below one */
442 if (ctx
->FragmentProgram
.Current
->Base
.RefCount
<= 0) {
443 _mesa_delete_program(ctx
, &(ctx
->FragmentProgram
.Current
->Base
));
444 _mesa_HashRemove(ctx
->Shared
->Programs
, program
);
449 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindProgramARB(target)");
453 /* NOTE: binding to a non-existant program is not an error.
454 * That's supposed to be caught in glBegin.
455 * NOTE: program number 0 is legal here.
458 /* default program */
459 if (target
== GL_VERTEX_PROGRAM_ARB
)
460 prog
= ctx
->Shared
->DefaultVertexProgram
;
462 prog
= ctx
->Shared
->DefaultFragmentProgram
;
465 prog
= (struct program
*) _mesa_HashLookup(ctx
->Shared
->Programs
, program
);
467 if (!prog
&& program
> 0){
468 /* allocate new program */
469 prog
= _mesa_alloc_program(ctx
, target
, program
);
471 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindProgramARB");
475 prog
->Target
= target
;
476 prog
->Resident
= GL_TRUE
;
478 _mesa_HashInsert(ctx
->Shared
->Programs
, program
, prog
);
482 if (target
== GL_VERTEX_PROGRAM_ARB
) {
483 ctx
->VertexProgram
.Current
= (struct vertex_program
*) prog
;
486 ASSERT(target
== GL_FRAGMENT_PROGRAM_ARB
);
487 ctx
->FragmentProgram
.Current
= (struct fragment_program
*) prog
;
496 _mesa_DeleteProgramsARB(GLsizei n
, const GLuint
*programs
)
498 _mesa_DeleteProgramsNV(n
, programs
);
503 _mesa_GenProgramsARB(GLsizei n
, GLuint
*programs
)
505 _mesa_GenProgramsNV(n
, programs
);
510 _mesa_IsProgramARB(GLuint program
)
512 return _mesa_IsProgramNV(program
);
517 _mesa_ProgramEnvParameter4dARB(GLenum target
, GLuint index
,
518 GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
520 _mesa_ProgramEnvParameter4fARB(target
, index
, x
, y
, z
, w
);
525 _mesa_ProgramEnvParameter4dvARB(GLenum target
, GLuint index
,
526 const GLdouble
*params
)
528 _mesa_ProgramEnvParameter4fARB(target
, index
, params
[0], params
[1],
529 params
[2], params
[3]);
534 _mesa_ProgramEnvParameter4fARB(GLenum target
, GLuint index
,
535 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
537 GET_CURRENT_CONTEXT(ctx
);
538 ASSERT_OUTSIDE_BEGIN_END(ctx
);
540 if (target
== GL_FRAGMENT_PROGRAM_ARB
541 && ctx
->Extensions
.ARB_fragment_program
) {
542 if (index
>= ctx
->Const
.MaxFragmentProgramEnvParams
) {
543 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter(index)");
546 index
+= MAX_NV_FRAGMENT_PROGRAM_TEMPS
; /* XXX fix */
547 ASSIGN_4V(ctx
->FragmentProgram
.Machine
.Registers
[index
], x
, y
, z
, w
);
549 if (target
== GL_VERTEX_PROGRAM_ARB
550 && ctx
->Extensions
.ARB_vertex_program
) {
551 if (index
>= ctx
->Const
.MaxVertexProgramEnvParams
) {
552 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter(index)");
555 index
+= MAX_NV_VERTEX_PROGRAM_TEMPS
; /* XXX fix */
556 ASSIGN_4V(ctx
->VertexProgram
.Machine
.Registers
[index
], x
, y
, z
, w
);
559 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameter(target)");
566 _mesa_ProgramEnvParameter4fvARB(GLenum target
, GLuint index
,
567 const GLfloat
*params
)
569 _mesa_ProgramEnvParameter4fARB(target
, index
, params
[0], params
[1],
570 params
[2], params
[3]);
575 _mesa_GetProgramEnvParameterdvARB(GLenum target
, GLuint index
,
578 GET_CURRENT_CONTEXT(ctx
);
581 _mesa_GetProgramEnvParameterfvARB(target
, index
, fparams
);
582 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
583 params
[0] = fparams
[0];
584 params
[1] = fparams
[1];
585 params
[2] = fparams
[2];
586 params
[3] = fparams
[3];
592 _mesa_GetProgramEnvParameterfvARB(GLenum target
, GLuint index
,
595 GET_CURRENT_CONTEXT(ctx
);
596 ASSERT_OUTSIDE_BEGIN_END(ctx
);
598 if (target
== GL_FRAGMENT_PROGRAM_ARB
599 && ctx
->Extensions
.ARB_fragment_program
) {
600 if (index
>= ctx
->Const
.MaxFragmentProgramEnvParams
) {
601 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramEnvParameter(index)");
604 index
+= MAX_NV_FRAGMENT_PROGRAM_TEMPS
; /* XXX fix */
605 COPY_4V(params
, ctx
->FragmentProgram
.Machine
.Registers
[index
]);
607 if (target
== GL_VERTEX_PROGRAM_ARB
608 && ctx
->Extensions
.ARB_vertex_program
) {
609 if (index
>= ctx
->Const
.MaxVertexProgramEnvParams
) {
610 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramEnvParameter(index)");
613 index
+= MAX_NV_VERTEX_PROGRAM_TEMPS
; /* XXX fix */
614 COPY_4V(params
, ctx
->VertexProgram
.Machine
.Registers
[index
]);
617 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramEnvParameter(target)");
624 * Note, this function is also used by the GL_NV_fragment_program extension.
627 _mesa_ProgramLocalParameter4fARB(GLenum target
, GLuint index
,
628 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
630 GET_CURRENT_CONTEXT(ctx
);
631 ASSERT_OUTSIDE_BEGIN_END(ctx
);
633 if ((target
== GL_FRAGMENT_PROGRAM_NV
634 && ctx
->Extensions
.NV_fragment_program
) ||
635 (target
== GL_FRAGMENT_PROGRAM_ARB
636 && ctx
->Extensions
.ARB_fragment_program
)) {
637 struct fragment_program
*fprog
= ctx
->FragmentProgram
.Current
;
639 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameterARB");
642 if (index
>= ctx
->Const
.MaxFragmentProgramLocalParams
) {
643 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameterARB");
646 fprog
->Base
.LocalParams
[index
][0] = x
;
647 fprog
->Base
.LocalParams
[index
][1] = y
;
648 fprog
->Base
.LocalParams
[index
][2] = z
;
649 fprog
->Base
.LocalParams
[index
][3] = w
;
651 else if (target
== GL_VERTEX_PROGRAM_ARB
652 && ctx
->Extensions
.ARB_vertex_program
) {
653 struct vertex_program
*vprog
= ctx
->VertexProgram
.Current
;
655 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameterARB");
658 if (index
>= ctx
->Const
.MaxVertexProgramLocalParams
) {
659 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameterARB");
662 vprog
->Base
.LocalParams
[index
][0] = x
;
663 vprog
->Base
.LocalParams
[index
][1] = y
;
664 vprog
->Base
.LocalParams
[index
][2] = z
;
665 vprog
->Base
.LocalParams
[index
][3] = w
;
668 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameterARB");
675 * Note, this function is also used by the GL_NV_fragment_program extension.
678 _mesa_ProgramLocalParameter4fvARB(GLenum target
, GLuint index
,
679 const GLfloat
*params
)
681 _mesa_ProgramLocalParameter4fARB(target
, index
, params
[0], params
[1],
682 params
[2], params
[3]);
687 * Note, this function is also used by the GL_NV_fragment_program extension.
690 _mesa_ProgramLocalParameter4dARB(GLenum target
, GLuint index
,
691 GLdouble x
, GLdouble y
,
692 GLdouble z
, GLdouble w
)
694 _mesa_ProgramLocalParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
695 (GLfloat
) z
, (GLfloat
) w
);
700 * Note, this function is also used by the GL_NV_fragment_program extension.
703 _mesa_ProgramLocalParameter4dvARB(GLenum target
, GLuint index
,
704 const GLdouble
*params
)
706 _mesa_ProgramLocalParameter4fARB(target
, index
,
707 (GLfloat
) params
[0], (GLfloat
) params
[1],
708 (GLfloat
) params
[2], (GLfloat
) params
[3]);
713 * Note, this function is also used by the GL_NV_fragment_program extension.
716 _mesa_GetProgramLocalParameterfvARB(GLenum target
, GLuint index
,
719 const struct program
*prog
;
721 GET_CURRENT_CONTEXT(ctx
);
722 ASSERT_OUTSIDE_BEGIN_END(ctx
);
724 if (target
== GL_VERTEX_PROGRAM_ARB
725 && ctx
->Extensions
.ARB_vertex_program
) {
726 prog
= &(ctx
->VertexProgram
.Current
->Base
);
727 maxParams
= ctx
->Const
.MaxVertexProgramLocalParams
;
729 else if (target
== GL_FRAGMENT_PROGRAM_ARB
730 && ctx
->Extensions
.ARB_fragment_program
) {
731 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
732 maxParams
= ctx
->Const
.MaxFragmentProgramLocalParams
;
734 else if (target
== GL_FRAGMENT_PROGRAM_NV
735 && ctx
->Extensions
.NV_fragment_program
) {
736 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
737 maxParams
= MAX_NV_FRAGMENT_PROGRAM_PARAMS
;
740 _mesa_error(ctx
, GL_INVALID_ENUM
,
741 "glGetProgramLocalParameterARB(target)");
745 if (index
>= maxParams
) {
746 _mesa_error(ctx
, GL_INVALID_VALUE
,
747 "glGetProgramLocalParameterARB(index)");
752 COPY_4V(params
, prog
->LocalParams
[index
]);
757 * Note, this function is also used by the GL_NV_fragment_program extension.
760 _mesa_GetProgramLocalParameterdvARB(GLenum target
, GLuint index
,
763 GET_CURRENT_CONTEXT(ctx
);
764 GLfloat floatParams
[4];
765 _mesa_GetProgramLocalParameterfvARB(target
, index
, floatParams
);
766 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
767 COPY_4V(params
, floatParams
);
773 _mesa_GetProgramivARB(GLenum target
, GLenum pname
, GLint
*params
)
775 struct program
*prog
;
776 GET_CURRENT_CONTEXT(ctx
);
777 ASSERT_OUTSIDE_BEGIN_END(ctx
);
779 if (target
== GL_VERTEX_PROGRAM_ARB
780 && ctx
->Extensions
.ARB_vertex_program
) {
781 prog
= &(ctx
->VertexProgram
.Current
->Base
);
783 else if (target
== GL_FRAGMENT_PROGRAM_ARB
784 && ctx
->Extensions
.ARB_vertex_program
) {
785 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
788 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
795 case GL_PROGRAM_LENGTH_ARB
:
796 *params
= prog
->String
? _mesa_strlen((char *) prog
->String
) : 0;
798 case GL_PROGRAM_FORMAT_ARB
:
799 *params
= prog
->Format
;
801 case GL_PROGRAM_BINDING_ARB
:
804 case GL_PROGRAM_INSTRUCTIONS_ARB
:
805 *params
= prog
->NumInstructions
;
807 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB
:
808 if (target
== GL_VERTEX_PROGRAM_ARB
)
809 *params
= ctx
->Const
.MaxVertexProgramInstructions
;
811 *params
= ctx
->Const
.MaxFragmentProgramInstructions
;
813 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
814 *params
= prog
->NumInstructions
;
816 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
817 if (target
== GL_VERTEX_PROGRAM_ARB
)
818 *params
= ctx
->Const
.MaxVertexProgramInstructions
;
820 *params
= ctx
->Const
.MaxFragmentProgramInstructions
;
822 case GL_PROGRAM_TEMPORARIES_ARB
:
823 *params
= prog
->NumTemporaries
;
825 case GL_MAX_PROGRAM_TEMPORARIES_ARB
:
826 if (target
== GL_VERTEX_PROGRAM_ARB
)
827 *params
= ctx
->Const
.MaxVertexProgramTemps
;
829 *params
= ctx
->Const
.MaxFragmentProgramTemps
;
831 case GL_PROGRAM_NATIVE_TEMPORARIES_ARB
:
832 /* XXX same as GL_PROGRAM_TEMPORARIES_ARB? */
833 *params
= prog
->NumTemporaries
;
835 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB
:
836 /* XXX same as GL_MAX_PROGRAM_TEMPORARIES_ARB? */
837 if (target
== GL_VERTEX_PROGRAM_ARB
)
838 *params
= ctx
->Const
.MaxVertexProgramTemps
;
840 *params
= ctx
->Const
.MaxFragmentProgramTemps
;
842 case GL_PROGRAM_PARAMETERS_ARB
:
843 *params
= prog
->NumParameters
;
845 case GL_MAX_PROGRAM_PARAMETERS_ARB
:
846 if (target
== GL_VERTEX_PROGRAM_ARB
)
847 *params
= ctx
->Const
.MaxVertexProgramLocalParams
;
849 *params
= ctx
->Const
.MaxFragmentProgramLocalParams
;
851 case GL_PROGRAM_NATIVE_PARAMETERS_ARB
:
852 /* XXX same as GL_MAX_PROGRAM_PARAMETERS_ARB? */
853 *params
= prog
->NumParameters
;
855 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB
:
856 /* XXX same as GL_MAX_PROGRAM_PARAMETERS_ARB? */
857 if (target
== GL_VERTEX_PROGRAM_ARB
)
858 *params
= ctx
->Const
.MaxVertexProgramLocalParams
;
860 *params
= ctx
->Const
.MaxFragmentProgramLocalParams
;
862 case GL_PROGRAM_ATTRIBS_ARB
:
863 *params
= prog
->NumAttributes
;
865 case GL_MAX_PROGRAM_ATTRIBS_ARB
:
866 if (target
== GL_VERTEX_PROGRAM_ARB
)
867 *params
= ctx
->Const
.MaxVertexProgramAttribs
;
869 *params
= ctx
->Const
.MaxFragmentProgramAttribs
;
871 case GL_PROGRAM_NATIVE_ATTRIBS_ARB
:
872 /* XXX same as GL_PROGRAM_ATTRIBS_ARB? */
873 *params
= prog
->NumAttributes
;
875 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB
:
876 /* XXX same as GL_MAX_PROGRAM_ATTRIBS_ARB? */
877 if (target
== GL_VERTEX_PROGRAM_ARB
)
878 *params
= ctx
->Const
.MaxVertexProgramAttribs
;
880 *params
= ctx
->Const
.MaxFragmentProgramAttribs
;
882 case GL_PROGRAM_ADDRESS_REGISTERS_ARB
:
883 *params
= prog
->NumAddressRegs
;
885 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB
:
886 if (target
== GL_VERTEX_PROGRAM_ARB
)
887 *params
= ctx
->Const
.MaxVertexProgramAddressRegs
;
889 *params
= ctx
->Const
.MaxFragmentProgramAddressRegs
;
891 case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
892 /* XXX same as GL_PROGRAM_ADDRESS_REGISTERS_ARB? */
893 *params
= prog
->NumAddressRegs
;
895 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
896 /* XXX same as GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB? */
897 if (target
== GL_VERTEX_PROGRAM_ARB
)
898 *params
= ctx
->Const
.MaxVertexProgramAddressRegs
;
900 *params
= ctx
->Const
.MaxFragmentProgramAddressRegs
;
902 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB
:
903 if (target
== GL_VERTEX_PROGRAM_ARB
)
904 *params
= ctx
->Const
.MaxVertexProgramLocalParams
;
906 *params
= ctx
->Const
.MaxFragmentProgramLocalParams
;
908 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB
:
909 if (target
== GL_VERTEX_PROGRAM_ARB
)
910 *params
= ctx
->Const
.MaxVertexProgramEnvParams
;
912 *params
= ctx
->Const
.MaxFragmentProgramEnvParams
;
914 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB
:
920 * The following apply to fragment programs only.
922 case GL_PROGRAM_ALU_INSTRUCTIONS_ARB
:
923 case GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
924 if (target
!= GL_FRAGMENT_PROGRAM_ARB
) {
925 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
928 *params
= ctx
->FragmentProgram
.Current
->NumAluInstructions
;
930 case GL_PROGRAM_TEX_INSTRUCTIONS_ARB
:
931 case GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
932 if (target
!= GL_FRAGMENT_PROGRAM_ARB
) {
933 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
936 *params
= ctx
->FragmentProgram
.Current
->NumTexInstructions
;
938 case GL_PROGRAM_TEX_INDIRECTIONS_ARB
:
939 case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
940 if (target
!= GL_FRAGMENT_PROGRAM_ARB
) {
941 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
944 *params
= ctx
->FragmentProgram
.Current
->NumTexIndirections
;
946 case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB
:
947 case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
948 if (target
!= GL_FRAGMENT_PROGRAM_ARB
) {
949 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
952 *params
= ctx
->Const
.MaxFragmentProgramAluInstructions
;
954 case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB
:
955 case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
956 if (target
!= GL_FRAGMENT_PROGRAM_ARB
) {
957 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
960 *params
= ctx
->Const
.MaxFragmentProgramTexInstructions
;
962 case GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB
:
963 case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
964 if (target
!= GL_FRAGMENT_PROGRAM_ARB
) {
965 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
968 *params
= ctx
->Const
.MaxFragmentProgramTexIndirections
;
971 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
978 _mesa_GetProgramStringARB(GLenum target
, GLenum pname
, GLvoid
*string
)
980 struct program
*prog
;
981 GET_CURRENT_CONTEXT(ctx
);
982 ASSERT_OUTSIDE_BEGIN_END(ctx
);
984 if (target
== GL_VERTEX_PROGRAM_ARB
) {
985 prog
= &(ctx
->VertexProgram
.Current
->Base
);
987 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
988 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
991 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(target)");
997 if (pname
!= GL_PROGRAM_STRING_ARB
) {
998 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(pname)");
1002 MEMCPY(string
, prog
->String
, _mesa_strlen((char *) prog
->String
));