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
->Target
== 0) {
468 /* prog was allocated with glGenProgramsARB */
469 prog
->Target
= target
;
471 else if (prog
->Target
!= target
) {
472 _mesa_error(ctx
, GL_INVALID_OPERATION
,
473 "glBindProgramARB(target mismatch)");
478 /* allocate a new program now */
479 prog
= _mesa_alloc_program(ctx
, target
, program
);
481 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindProgramARB");
485 prog
->Target
= target
;
486 prog
->Resident
= GL_TRUE
;
488 _mesa_HashInsert(ctx
->Shared
->Programs
, program
, prog
);
493 if (target
== GL_VERTEX_PROGRAM_ARB
) {
494 ctx
->VertexProgram
.Current
= (struct vertex_program
*) prog
;
497 ASSERT(target
== GL_FRAGMENT_PROGRAM_ARB
);
498 ctx
->FragmentProgram
.Current
= (struct fragment_program
*) prog
;
507 _mesa_DeleteProgramsARB(GLsizei n
, const GLuint
*programs
)
509 _mesa_DeleteProgramsNV(n
, programs
);
514 _mesa_GenProgramsARB(GLsizei n
, GLuint
*programs
)
516 _mesa_GenProgramsNV(n
, programs
);
521 _mesa_IsProgramARB(GLuint program
)
523 return _mesa_IsProgramNV(program
);
528 _mesa_ProgramEnvParameter4dARB(GLenum target
, GLuint index
,
529 GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
531 _mesa_ProgramEnvParameter4fARB(target
, index
, x
, y
, z
, w
);
536 _mesa_ProgramEnvParameter4dvARB(GLenum target
, GLuint index
,
537 const GLdouble
*params
)
539 _mesa_ProgramEnvParameter4fARB(target
, index
, params
[0], params
[1],
540 params
[2], params
[3]);
545 _mesa_ProgramEnvParameter4fARB(GLenum target
, GLuint index
,
546 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
548 GET_CURRENT_CONTEXT(ctx
);
549 ASSERT_OUTSIDE_BEGIN_END(ctx
);
551 if (target
== GL_FRAGMENT_PROGRAM_ARB
552 && ctx
->Extensions
.ARB_fragment_program
) {
553 if (index
>= ctx
->Const
.MaxFragmentProgramEnvParams
) {
554 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter(index)");
557 index
+= MAX_NV_FRAGMENT_PROGRAM_TEMPS
; /* XXX fix */
558 ASSIGN_4V(ctx
->FragmentProgram
.Machine
.Registers
[index
], x
, y
, z
, w
);
560 if (target
== GL_VERTEX_PROGRAM_ARB
561 && ctx
->Extensions
.ARB_vertex_program
) {
562 if (index
>= ctx
->Const
.MaxVertexProgramEnvParams
) {
563 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramEnvParameter(index)");
566 index
+= MAX_NV_VERTEX_PROGRAM_TEMPS
; /* XXX fix */
567 ASSIGN_4V(ctx
->VertexProgram
.Machine
.Registers
[index
], x
, y
, z
, w
);
570 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramEnvParameter(target)");
577 _mesa_ProgramEnvParameter4fvARB(GLenum target
, GLuint index
,
578 const GLfloat
*params
)
580 _mesa_ProgramEnvParameter4fARB(target
, index
, params
[0], params
[1],
581 params
[2], params
[3]);
586 _mesa_GetProgramEnvParameterdvARB(GLenum target
, GLuint index
,
589 GET_CURRENT_CONTEXT(ctx
);
592 _mesa_GetProgramEnvParameterfvARB(target
, index
, fparams
);
593 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
594 params
[0] = fparams
[0];
595 params
[1] = fparams
[1];
596 params
[2] = fparams
[2];
597 params
[3] = fparams
[3];
603 _mesa_GetProgramEnvParameterfvARB(GLenum target
, GLuint index
,
606 GET_CURRENT_CONTEXT(ctx
);
607 ASSERT_OUTSIDE_BEGIN_END(ctx
);
609 if (target
== GL_FRAGMENT_PROGRAM_ARB
610 && ctx
->Extensions
.ARB_fragment_program
) {
611 if (index
>= ctx
->Const
.MaxFragmentProgramEnvParams
) {
612 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramEnvParameter(index)");
615 index
+= MAX_NV_FRAGMENT_PROGRAM_TEMPS
; /* XXX fix */
616 COPY_4V(params
, ctx
->FragmentProgram
.Machine
.Registers
[index
]);
618 if (target
== GL_VERTEX_PROGRAM_ARB
619 && ctx
->Extensions
.ARB_vertex_program
) {
620 if (index
>= ctx
->Const
.MaxVertexProgramEnvParams
) {
621 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramEnvParameter(index)");
624 index
+= MAX_NV_VERTEX_PROGRAM_TEMPS
; /* XXX fix */
625 COPY_4V(params
, ctx
->VertexProgram
.Machine
.Registers
[index
]);
628 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramEnvParameter(target)");
635 * Note, this function is also used by the GL_NV_fragment_program extension.
638 _mesa_ProgramLocalParameter4fARB(GLenum target
, GLuint index
,
639 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
641 GET_CURRENT_CONTEXT(ctx
);
642 ASSERT_OUTSIDE_BEGIN_END(ctx
);
644 if ((target
== GL_FRAGMENT_PROGRAM_NV
645 && ctx
->Extensions
.NV_fragment_program
) ||
646 (target
== GL_FRAGMENT_PROGRAM_ARB
647 && ctx
->Extensions
.ARB_fragment_program
)) {
648 struct fragment_program
*fprog
= ctx
->FragmentProgram
.Current
;
650 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameterARB");
653 if (index
>= ctx
->Const
.MaxFragmentProgramLocalParams
) {
654 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameterARB");
657 fprog
->Base
.LocalParams
[index
][0] = x
;
658 fprog
->Base
.LocalParams
[index
][1] = y
;
659 fprog
->Base
.LocalParams
[index
][2] = z
;
660 fprog
->Base
.LocalParams
[index
][3] = w
;
662 else if (target
== GL_VERTEX_PROGRAM_ARB
663 && ctx
->Extensions
.ARB_vertex_program
) {
664 struct vertex_program
*vprog
= ctx
->VertexProgram
.Current
;
666 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameterARB");
669 if (index
>= ctx
->Const
.MaxVertexProgramLocalParams
) {
670 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameterARB");
673 vprog
->Base
.LocalParams
[index
][0] = x
;
674 vprog
->Base
.LocalParams
[index
][1] = y
;
675 vprog
->Base
.LocalParams
[index
][2] = z
;
676 vprog
->Base
.LocalParams
[index
][3] = w
;
679 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameterARB");
686 * Note, this function is also used by the GL_NV_fragment_program extension.
689 _mesa_ProgramLocalParameter4fvARB(GLenum target
, GLuint index
,
690 const GLfloat
*params
)
692 _mesa_ProgramLocalParameter4fARB(target
, index
, params
[0], params
[1],
693 params
[2], params
[3]);
698 * Note, this function is also used by the GL_NV_fragment_program extension.
701 _mesa_ProgramLocalParameter4dARB(GLenum target
, GLuint index
,
702 GLdouble x
, GLdouble y
,
703 GLdouble z
, GLdouble w
)
705 _mesa_ProgramLocalParameter4fARB(target
, index
, (GLfloat
) x
, (GLfloat
) y
,
706 (GLfloat
) z
, (GLfloat
) w
);
711 * Note, this function is also used by the GL_NV_fragment_program extension.
714 _mesa_ProgramLocalParameter4dvARB(GLenum target
, GLuint index
,
715 const GLdouble
*params
)
717 _mesa_ProgramLocalParameter4fARB(target
, index
,
718 (GLfloat
) params
[0], (GLfloat
) params
[1],
719 (GLfloat
) params
[2], (GLfloat
) params
[3]);
724 * Note, this function is also used by the GL_NV_fragment_program extension.
727 _mesa_GetProgramLocalParameterfvARB(GLenum target
, GLuint index
,
730 const struct program
*prog
;
732 GET_CURRENT_CONTEXT(ctx
);
733 ASSERT_OUTSIDE_BEGIN_END(ctx
);
735 if (target
== GL_VERTEX_PROGRAM_ARB
736 && ctx
->Extensions
.ARB_vertex_program
) {
737 prog
= &(ctx
->VertexProgram
.Current
->Base
);
738 maxParams
= ctx
->Const
.MaxVertexProgramLocalParams
;
740 else if (target
== GL_FRAGMENT_PROGRAM_ARB
741 && ctx
->Extensions
.ARB_fragment_program
) {
742 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
743 maxParams
= ctx
->Const
.MaxFragmentProgramLocalParams
;
745 else if (target
== GL_FRAGMENT_PROGRAM_NV
746 && ctx
->Extensions
.NV_fragment_program
) {
747 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
748 maxParams
= MAX_NV_FRAGMENT_PROGRAM_PARAMS
;
751 _mesa_error(ctx
, GL_INVALID_ENUM
,
752 "glGetProgramLocalParameterARB(target)");
756 if (index
>= maxParams
) {
757 _mesa_error(ctx
, GL_INVALID_VALUE
,
758 "glGetProgramLocalParameterARB(index)");
763 COPY_4V(params
, prog
->LocalParams
[index
]);
768 * Note, this function is also used by the GL_NV_fragment_program extension.
771 _mesa_GetProgramLocalParameterdvARB(GLenum target
, GLuint index
,
774 GET_CURRENT_CONTEXT(ctx
);
775 GLfloat floatParams
[4];
776 _mesa_GetProgramLocalParameterfvARB(target
, index
, floatParams
);
777 if (ctx
->ErrorValue
== GL_NO_ERROR
) {
778 COPY_4V(params
, floatParams
);
784 _mesa_GetProgramivARB(GLenum target
, GLenum pname
, GLint
*params
)
786 struct program
*prog
;
787 GET_CURRENT_CONTEXT(ctx
);
788 ASSERT_OUTSIDE_BEGIN_END(ctx
);
790 if (target
== GL_VERTEX_PROGRAM_ARB
791 && ctx
->Extensions
.ARB_vertex_program
) {
792 prog
= &(ctx
->VertexProgram
.Current
->Base
);
794 else if (target
== GL_FRAGMENT_PROGRAM_ARB
795 && ctx
->Extensions
.ARB_vertex_program
) {
796 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
799 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
806 case GL_PROGRAM_LENGTH_ARB
:
807 *params
= prog
->String
? _mesa_strlen((char *) prog
->String
) : 0;
809 case GL_PROGRAM_FORMAT_ARB
:
810 *params
= prog
->Format
;
812 case GL_PROGRAM_BINDING_ARB
:
815 case GL_PROGRAM_INSTRUCTIONS_ARB
:
816 *params
= prog
->NumInstructions
;
818 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB
:
819 if (target
== GL_VERTEX_PROGRAM_ARB
)
820 *params
= ctx
->Const
.MaxVertexProgramInstructions
;
822 *params
= ctx
->Const
.MaxFragmentProgramInstructions
;
824 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
825 *params
= prog
->NumInstructions
;
827 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
828 if (target
== GL_VERTEX_PROGRAM_ARB
)
829 *params
= ctx
->Const
.MaxVertexProgramInstructions
;
831 *params
= ctx
->Const
.MaxFragmentProgramInstructions
;
833 case GL_PROGRAM_TEMPORARIES_ARB
:
834 *params
= prog
->NumTemporaries
;
836 case 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_NATIVE_TEMPORARIES_ARB
:
843 /* XXX same as GL_PROGRAM_TEMPORARIES_ARB? */
844 *params
= prog
->NumTemporaries
;
846 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB
:
847 /* XXX same as GL_MAX_PROGRAM_TEMPORARIES_ARB? */
848 if (target
== GL_VERTEX_PROGRAM_ARB
)
849 *params
= ctx
->Const
.MaxVertexProgramTemps
;
851 *params
= ctx
->Const
.MaxFragmentProgramTemps
;
853 case GL_PROGRAM_PARAMETERS_ARB
:
854 *params
= prog
->NumParameters
;
856 case 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_NATIVE_PARAMETERS_ARB
:
863 /* XXX same as GL_MAX_PROGRAM_PARAMETERS_ARB? */
864 *params
= prog
->NumParameters
;
866 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB
:
867 /* XXX same as GL_MAX_PROGRAM_PARAMETERS_ARB? */
868 if (target
== GL_VERTEX_PROGRAM_ARB
)
869 *params
= ctx
->Const
.MaxVertexProgramLocalParams
;
871 *params
= ctx
->Const
.MaxFragmentProgramLocalParams
;
873 case GL_PROGRAM_ATTRIBS_ARB
:
874 *params
= prog
->NumAttributes
;
876 case 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_NATIVE_ATTRIBS_ARB
:
883 /* XXX same as GL_PROGRAM_ATTRIBS_ARB? */
884 *params
= prog
->NumAttributes
;
886 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB
:
887 /* XXX same as GL_MAX_PROGRAM_ATTRIBS_ARB? */
888 if (target
== GL_VERTEX_PROGRAM_ARB
)
889 *params
= ctx
->Const
.MaxVertexProgramAttribs
;
891 *params
= ctx
->Const
.MaxFragmentProgramAttribs
;
893 case GL_PROGRAM_ADDRESS_REGISTERS_ARB
:
894 *params
= prog
->NumAddressRegs
;
896 case 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_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
903 /* XXX same as GL_PROGRAM_ADDRESS_REGISTERS_ARB? */
904 *params
= prog
->NumAddressRegs
;
906 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
907 /* XXX same as GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB? */
908 if (target
== GL_VERTEX_PROGRAM_ARB
)
909 *params
= ctx
->Const
.MaxVertexProgramAddressRegs
;
911 *params
= ctx
->Const
.MaxFragmentProgramAddressRegs
;
913 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB
:
914 if (target
== GL_VERTEX_PROGRAM_ARB
)
915 *params
= ctx
->Const
.MaxVertexProgramLocalParams
;
917 *params
= ctx
->Const
.MaxFragmentProgramLocalParams
;
919 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB
:
920 if (target
== GL_VERTEX_PROGRAM_ARB
)
921 *params
= ctx
->Const
.MaxVertexProgramEnvParams
;
923 *params
= ctx
->Const
.MaxFragmentProgramEnvParams
;
925 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB
:
931 * The following apply to fragment programs only.
933 case GL_PROGRAM_ALU_INSTRUCTIONS_ARB
:
934 case GL_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
935 if (target
!= GL_FRAGMENT_PROGRAM_ARB
) {
936 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
939 *params
= ctx
->FragmentProgram
.Current
->NumAluInstructions
;
941 case GL_PROGRAM_TEX_INSTRUCTIONS_ARB
:
942 case GL_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
943 if (target
!= GL_FRAGMENT_PROGRAM_ARB
) {
944 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
947 *params
= ctx
->FragmentProgram
.Current
->NumTexInstructions
;
949 case GL_PROGRAM_TEX_INDIRECTIONS_ARB
:
950 case GL_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
951 if (target
!= GL_FRAGMENT_PROGRAM_ARB
) {
952 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
955 *params
= ctx
->FragmentProgram
.Current
->NumTexIndirections
;
957 case GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB
:
958 case GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB
:
959 if (target
!= GL_FRAGMENT_PROGRAM_ARB
) {
960 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
963 *params
= ctx
->Const
.MaxFragmentProgramAluInstructions
;
965 case GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB
:
966 case GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB
:
967 if (target
!= GL_FRAGMENT_PROGRAM_ARB
) {
968 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
971 *params
= ctx
->Const
.MaxFragmentProgramTexInstructions
;
973 case GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB
:
974 case GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB
:
975 if (target
!= GL_FRAGMENT_PROGRAM_ARB
) {
976 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
979 *params
= ctx
->Const
.MaxFragmentProgramTexIndirections
;
982 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
989 _mesa_GetProgramStringARB(GLenum target
, GLenum pname
, GLvoid
*string
)
991 struct program
*prog
;
992 GET_CURRENT_CONTEXT(ctx
);
993 ASSERT_OUTSIDE_BEGIN_END(ctx
);
995 if (target
== GL_VERTEX_PROGRAM_ARB
) {
996 prog
= &(ctx
->VertexProgram
.Current
->Base
);
998 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
999 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
1002 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(target)");
1008 if (pname
!= GL_PROGRAM_STRING_ARB
) {
1009 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(pname)");
1013 MEMCPY(string
, prog
->String
, _mesa_strlen((char *) prog
->String
));