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 * NVIDIA vertex/fragment program state management functions.
38 #include "nvfragparse.h"
39 #include "nvfragprog.h"
40 #include "nvvertexec.h"
41 #include "nvvertparse.h"
42 #include "nvvertprog.h"
43 #include "nvprogram.h"
47 * Set the vertex/fragment program error state (position and error string).
48 * This is generally called from within the parsers.
51 _mesa_set_program_error(GLcontext
*ctx
, GLint pos
, const char *string
)
53 ctx
->Program
.ErrorPos
= pos
;
54 _mesa_free((void *) ctx
->Program
.ErrorString
);
57 ctx
->Program
.ErrorString
= _mesa_strdup(string
);
62 * Find the line number and column for 'pos' within 'string'.
63 * Return a copy of the line which contains 'pos'. Free the line with
65 * \param string the program string
66 * \param pos the position within the string
67 * \param line returns the line number corresponding to 'pos'.
68 * \param col returns the column number corresponding to 'pos'.
69 * \return copy of the line containing 'pos'.
72 _mesa_find_line_column(const GLubyte
*string
, const GLubyte
*pos
,
73 GLint
*line
, GLint
*col
)
75 const GLubyte
*lineStart
= string
;
76 const GLubyte
*p
= string
;
83 if (*p
== (GLubyte
) '\n') {
90 *col
= (pos
- lineStart
) + 1;
92 /* return copy of this line */
93 while (*p
!= 0 && *p
!= '\n')
96 s
= (GLubyte
*) _mesa_malloc(len
+ 1);
97 _mesa_memcpy(s
, lineStart
, len
);
106 * Allocate and initialize a new fragment/vertex program object
108 * \param id program id/number
109 * \param target program target/type
110 * \return pointer to new program object
113 _mesa_alloc_program(GLcontext
*ctx
, GLenum target
, GLuint id
)
115 struct program
*prog
;
117 if (target
== GL_VERTEX_PROGRAM_NV
118 || target
== GL_VERTEX_PROGRAM_ARB
) {
119 struct vertex_program
*vprog
= CALLOC_STRUCT(vertex_program
);
123 prog
= &(vprog
->Base
);
125 else if (target
== GL_FRAGMENT_PROGRAM_NV
126 || target
== GL_FRAGMENT_PROGRAM_ARB
) {
127 struct fragment_program
*fprog
= CALLOC_STRUCT(fragment_program
);
131 prog
= &(fprog
->Base
);
134 _mesa_problem(ctx
, "bad target in _mesa_alloc_program");
138 prog
->Target
= target
;
139 prog
->Resident
= GL_TRUE
;
146 * Delete a program and remove it from the hash table, ignoring the
148 * \note Called from the GL API dispatcher.
151 _mesa_delete_program(GLcontext
*ctx
, struct program
*prog
)
156 _mesa_free(prog
->String
);
157 if (prog
->Target
== GL_VERTEX_PROGRAM_NV
||
158 prog
->Target
== GL_VERTEX_STATE_PROGRAM_NV
) {
159 struct vertex_program
*vprog
= (struct vertex_program
*) prog
;
160 if (vprog
->Instructions
)
161 _mesa_free(vprog
->Instructions
);
163 else if (prog
->Target
== GL_FRAGMENT_PROGRAM_NV
) {
164 struct fragment_program
*fprog
= (struct fragment_program
*) prog
;
165 if (fprog
->Instructions
)
166 _mesa_free(fprog
->Instructions
);
167 if (fprog
->Parameters
) {
169 for (i
= 0; i
< fprog
->NumParameters
; i
++) {
170 _mesa_free((void *) fprog
->Parameters
[i
].Name
);
172 _mesa_free(fprog
->Parameters
);
180 * Bind a program (make it current)
181 * \note Called from the GL API dispatcher by both glBindProgramNV
182 * and glBindProgramARB.
185 _mesa_BindProgramNV(GLenum target
, GLuint id
)
187 struct program
*prog
;
188 GET_CURRENT_CONTEXT(ctx
);
189 ASSERT_OUTSIDE_BEGIN_END(ctx
);
191 if ((target
== GL_VERTEX_PROGRAM_NV
192 && ctx
->Extensions
.NV_vertex_program
) ||
193 (target
== GL_VERTEX_PROGRAM_ARB
194 && ctx
->Extensions
.ARB_vertex_program
)) {
195 if (ctx
->VertexProgram
.Current
&&
196 ctx
->VertexProgram
.Current
->Base
.Id
== id
)
198 /* decrement refcount on previously bound vertex program */
199 if (ctx
->VertexProgram
.Current
) {
200 ctx
->VertexProgram
.Current
->Base
.RefCount
--;
201 /* and delete if refcount goes below one */
202 if (ctx
->VertexProgram
.Current
->Base
.RefCount
<= 0) {
203 _mesa_delete_program(ctx
, &(ctx
->VertexProgram
.Current
->Base
));
204 _mesa_HashRemove(ctx
->Shared
->Programs
, id
);
208 else if ((target
== GL_FRAGMENT_PROGRAM_NV
209 && ctx
->Extensions
.NV_fragment_program
) ||
210 (target
== GL_FRAGMENT_PROGRAM_ARB
211 && ctx
->Extensions
.ARB_fragment_program
)) {
212 if (ctx
->FragmentProgram
.Current
&&
213 ctx
->FragmentProgram
.Current
->Base
.Id
== id
)
215 /* decrement refcount on previously bound fragment program */
216 if (ctx
->FragmentProgram
.Current
) {
217 ctx
->FragmentProgram
.Current
->Base
.RefCount
--;
218 /* and delete if refcount goes below one */
219 if (ctx
->FragmentProgram
.Current
->Base
.RefCount
<= 0) {
220 _mesa_delete_program(ctx
, &(ctx
->FragmentProgram
.Current
->Base
));
221 _mesa_HashRemove(ctx
->Shared
->Programs
, id
);
226 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindProgramNV/ARB(target)");
230 /* NOTE: binding to a non-existant program is not an error.
231 * That's supposed to be caught in glBegin.
234 /* default program */
236 if (target
== GL_VERTEX_PROGRAM_NV
|| target
== GL_VERTEX_PROGRAM_ARB
)
237 prog
= ctx
->Shared
->DefaultVertexProgram
;
239 prog
= ctx
->Shared
->DefaultFragmentProgram
;
242 prog
= (struct program
*) _mesa_HashLookup(ctx
->Shared
->Programs
, id
);
244 if (prog
->Target
== 0) {
245 /* prog was allocated with glGenProgramsNV */
246 prog
->Target
= target
;
248 else if (prog
->Target
!= target
) {
249 _mesa_error(ctx
, GL_INVALID_OPERATION
,
250 "glBindProgramNV/ARB(target mismatch)");
255 /* allocate a new program now */
256 prog
= _mesa_alloc_program(ctx
, target
, id
);
258 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindProgramNV/ARB");
262 prog
->Target
= target
;
263 prog
->Resident
= GL_TRUE
;
265 _mesa_HashInsert(ctx
->Shared
->Programs
, id
, prog
);
270 if (target
== GL_VERTEX_PROGRAM_NV
|| target
== GL_VERTEX_PROGRAM_ARB
) {
271 ctx
->VertexProgram
.Current
= (struct vertex_program
*) prog
;
273 else if (target
== GL_FRAGMENT_PROGRAM_NV
|| target
== GL_FRAGMENT_PROGRAM_ARB
) {
274 ctx
->FragmentProgram
.Current
= (struct fragment_program
*) prog
;
283 * Delete a list of programs.
284 * \note Not compiled into display lists.
285 * \note Called by both glDeleteProgramsNV and glDeleteProgramsARB.
288 _mesa_DeleteProgramsNV(GLsizei n
, const GLuint
*ids
)
291 GET_CURRENT_CONTEXT(ctx
);
292 ASSERT_OUTSIDE_BEGIN_END(ctx
);
295 _mesa_error( ctx
, GL_INVALID_VALUE
, "glDeleteProgramsNV" );
299 for (i
= 0; i
< n
; i
++) {
301 struct program
*prog
= (struct program
*)
302 _mesa_HashLookup(ctx
->Shared
->Programs
, ids
[i
]);
304 if (prog
->Target
== GL_VERTEX_PROGRAM_NV
||
305 prog
->Target
== GL_VERTEX_STATE_PROGRAM_NV
) {
306 if (ctx
->VertexProgram
.Current
&&
307 ctx
->VertexProgram
.Current
->Base
.Id
== ids
[i
]) {
308 /* unbind this currently bound program */
309 _mesa_BindProgramNV(prog
->Target
, 0);
312 else if (prog
->Target
== GL_FRAGMENT_PROGRAM_NV
) {
313 if (ctx
->FragmentProgram
.Current
&&
314 ctx
->FragmentProgram
.Current
->Base
.Id
== ids
[i
]) {
315 /* unbind this currently bound program */
316 _mesa_BindProgramNV(prog
->Target
, 0);
320 _mesa_problem(ctx
, "bad target in glDeleteProgramsNV");
324 if (prog
->RefCount
<= 0) {
325 _mesa_delete_program(ctx
, prog
);
334 * Execute a vertex state program.
335 * \note Called from the GL API dispatcher.
338 _mesa_ExecuteProgramNV(GLenum target
, GLuint id
, const GLfloat
*params
)
340 struct vertex_program
*vprog
;
341 GET_CURRENT_CONTEXT(ctx
);
342 ASSERT_OUTSIDE_BEGIN_END(ctx
);
344 if (target
!= GL_VERTEX_STATE_PROGRAM_NV
) {
345 _mesa_error(ctx
, GL_INVALID_ENUM
, "glExecuteProgramNV");
349 vprog
= (struct vertex_program
*)
350 _mesa_HashLookup(ctx
->Shared
->Programs
, id
);
352 if (!vprog
|| vprog
->Base
.Target
!= GL_VERTEX_STATE_PROGRAM_NV
) {
353 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glExecuteProgramNV");
357 _mesa_init_vp_registers(ctx
);
358 _mesa_init_tracked_matrices(ctx
);
359 COPY_4V(ctx
->VertexProgram
.Inputs
[VERT_ATTRIB_POS
], params
);
360 _mesa_exec_vertex_program(ctx
, vprog
);
365 * Generate a list of new program identifiers.
366 * \note Not compiled into display lists.
367 * \note Called by both glGenProgramsNV and glGenProgramsARB.
370 _mesa_GenProgramsNV(GLsizei n
, GLuint
*ids
)
374 GET_CURRENT_CONTEXT(ctx
);
375 ASSERT_OUTSIDE_BEGIN_END(ctx
);
378 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGenPrograms");
385 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->Programs
, n
);
387 for (i
= 0; i
< (GLuint
) n
; i
++) {
388 const int bytes
= MAX2(sizeof(struct vertex_program
),
389 sizeof(struct fragment_program
));
390 struct program
*prog
= (struct program
*) _mesa_calloc(bytes
);
392 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGenPrograms");
396 prog
->Id
= first
+ i
;
397 _mesa_HashInsert(ctx
->Shared
->Programs
, first
+ i
, prog
);
400 /* Return the program names */
401 for (i
= 0; i
< (GLuint
) n
; i
++) {
408 * Determine if a set of programs is resident in hardware.
409 * \note Not compiled into display lists.
410 * \note Called from the GL API dispatcher.
412 GLboolean
_mesa_AreProgramsResidentNV(GLsizei n
, const GLuint
*ids
,
413 GLboolean
*residences
)
416 GLboolean allResident
= GL_TRUE
;
417 GET_CURRENT_CONTEXT(ctx
);
418 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
421 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreProgramsResidentNV(n)");
425 for (i
= 0; i
< n
; i
++) {
426 const struct program
*prog
;
428 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreProgramsResidentNV");
431 prog
= (const struct program
*)
432 _mesa_HashLookup(ctx
->Shared
->Programs
, ids
[i
]);
434 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreProgramsResidentNV");
437 if (prog
->Resident
) {
439 residences
[i
] = GL_TRUE
;
443 allResident
= GL_FALSE
;
444 for (j
= 0; j
< i
; j
++)
445 residences
[j
] = GL_TRUE
;
447 residences
[i
] = GL_FALSE
;
456 * Request that a set of programs be resident in hardware.
457 * \note Called from the GL API dispatcher.
460 _mesa_RequestResidentProgramsNV(GLsizei n
, const GLuint
*ids
)
463 GET_CURRENT_CONTEXT(ctx
);
464 ASSERT_OUTSIDE_BEGIN_END(ctx
);
467 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRequestResidentProgramsNV(n)");
471 /* just error checking for now */
472 for (i
= 0; i
< n
; i
++) {
473 struct program
*prog
;
476 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRequestResidentProgramsNV(id)");
480 prog
= (struct program
*) _mesa_HashLookup(ctx
->Shared
->Programs
, ids
[i
]);
483 _mesa_error(ctx
, GL_INVALID_VALUE
, "glRequestResidentProgramsNV(id)");
487 prog
->Resident
= GL_TRUE
;
493 * Get a program parameter register.
494 * \note Not compiled into display lists.
495 * \note Called from the GL API dispatcher.
498 _mesa_GetProgramParameterfvNV(GLenum target
, GLuint index
,
499 GLenum pname
, GLfloat
*params
)
501 GET_CURRENT_CONTEXT(ctx
);
502 ASSERT_OUTSIDE_BEGIN_END(ctx
);
504 if (target
== GL_VERTEX_PROGRAM_NV
) {
505 if (pname
== GL_PROGRAM_PARAMETER_NV
) {
506 if (index
< MAX_NV_VERTEX_PROGRAM_PARAMS
) {
507 COPY_4V(params
, ctx
->VertexProgram
.Parameters
[index
]);
510 _mesa_error(ctx
, GL_INVALID_VALUE
,
511 "glGetProgramParameterfvNV(index)");
516 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramParameterfvNV(pname)");
521 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramParameterfvNV(target)");
528 * Get a program parameter register.
529 * \note Not compiled into display lists.
530 * \note Called from the GL API dispatcher.
533 _mesa_GetProgramParameterdvNV(GLenum target
, GLuint index
,
534 GLenum pname
, GLdouble
*params
)
536 GET_CURRENT_CONTEXT(ctx
);
537 ASSERT_OUTSIDE_BEGIN_END(ctx
);
539 if (target
== GL_VERTEX_PROGRAM_NV
) {
540 if (pname
== GL_PROGRAM_PARAMETER_NV
) {
541 if (index
< MAX_NV_VERTEX_PROGRAM_PARAMS
) {
542 COPY_4V(params
, ctx
->VertexProgram
.Parameters
[index
]);
545 _mesa_error(ctx
, GL_INVALID_VALUE
,
546 "glGetProgramParameterdvNV(index)");
551 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramParameterdvNV(pname)");
556 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramParameterdvNV(target)");
563 * Get a program attribute.
564 * \note Not compiled into display lists.
565 * \note Called from the GL API dispatcher.
568 _mesa_GetProgramivNV(GLuint id
, GLenum pname
, GLint
*params
)
570 struct program
*prog
;
571 GET_CURRENT_CONTEXT(ctx
);
573 if (!ctx
->_CurrentProgram
)
574 ASSERT_OUTSIDE_BEGIN_END(ctx
);
576 prog
= (struct program
*) _mesa_HashLookup(ctx
->Shared
->Programs
, id
);
578 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetProgramivNV");
583 case GL_PROGRAM_TARGET_NV
:
584 *params
= prog
->Target
;
586 case GL_PROGRAM_LENGTH_NV
:
587 *params
= prog
->String
? _mesa_strlen((char *) prog
->String
) : 0;
589 case GL_PROGRAM_RESIDENT_NV
:
590 *params
= prog
->Resident
;
593 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivNV(pname)");
600 * Get the program source code.
601 * \note Not compiled into display lists.
602 * \note Called from the GL API dispatcher.
605 _mesa_GetProgramStringNV(GLuint id
, GLenum pname
, GLubyte
*program
)
607 struct program
*prog
;
608 GET_CURRENT_CONTEXT(ctx
);
610 if (!ctx
->_CurrentProgram
)
611 ASSERT_OUTSIDE_BEGIN_END(ctx
);
613 if (pname
!= GL_PROGRAM_STRING_NV
) {
614 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringNV(pname)");
618 prog
= (struct program
*) _mesa_HashLookup(ctx
->Shared
->Programs
, id
);
620 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetProgramStringNV");
625 MEMCPY(program
, prog
->String
, _mesa_strlen((char *) prog
->String
));
634 * Get matrix tracking information.
635 * \note Not compiled into display lists.
636 * \note Called from the GL API dispatcher.
639 _mesa_GetTrackMatrixivNV(GLenum target
, GLuint address
,
640 GLenum pname
, GLint
*params
)
642 GET_CURRENT_CONTEXT(ctx
);
643 ASSERT_OUTSIDE_BEGIN_END(ctx
);
645 if (target
== GL_VERTEX_PROGRAM_NV
646 && ctx
->Extensions
.NV_vertex_program
) {
649 if ((address
& 0x3) || address
>= MAX_NV_VERTEX_PROGRAM_PARAMS
) {
650 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetTrackMatrixivNV(address)");
657 case GL_TRACK_MATRIX_NV
:
658 params
[0] = (GLint
) ctx
->VertexProgram
.TrackMatrix
[i
];
660 case GL_TRACK_MATRIX_TRANSFORM_NV
:
661 params
[0] = (GLint
) ctx
->VertexProgram
.TrackMatrixTransform
[i
];
664 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTrackMatrixivNV");
669 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTrackMatrixivNV");
676 * Get a vertex (or vertex array) attribute.
677 * \note Not compiled into display lists.
678 * \note Called from the GL API dispatcher.
681 _mesa_GetVertexAttribdvNV(GLuint index
, GLenum pname
, GLdouble
*params
)
683 GET_CURRENT_CONTEXT(ctx
);
684 ASSERT_OUTSIDE_BEGIN_END(ctx
);
686 if (index
== 0 || index
>= MAX_NV_VERTEX_PROGRAM_INPUTS
) {
687 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribdvNV(index)");
692 case GL_ATTRIB_ARRAY_SIZE_NV
:
693 params
[0] = ctx
->Array
.VertexAttrib
[index
].Size
;
695 case GL_ATTRIB_ARRAY_STRIDE_NV
:
696 params
[0] = ctx
->Array
.VertexAttrib
[index
].Stride
;
698 case GL_ATTRIB_ARRAY_TYPE_NV
:
699 params
[0] = ctx
->Array
.VertexAttrib
[index
].Type
;
701 case GL_CURRENT_ATTRIB_NV
:
702 FLUSH_CURRENT(ctx
, 0);
703 COPY_4V(params
, ctx
->Current
.Attrib
[index
]);
706 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribdvNV");
712 * Get a vertex (or vertex array) attribute.
713 * \note Not compiled into display lists.
714 * \note Called from the GL API dispatcher.
717 _mesa_GetVertexAttribfvNV(GLuint index
, GLenum pname
, GLfloat
*params
)
719 GET_CURRENT_CONTEXT(ctx
);
720 ASSERT_OUTSIDE_BEGIN_END(ctx
);
722 if (index
== 0 || index
>= MAX_NV_VERTEX_PROGRAM_INPUTS
) {
723 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribdvNV(index)");
728 case GL_ATTRIB_ARRAY_SIZE_NV
:
729 params
[0] = (GLfloat
) ctx
->Array
.VertexAttrib
[index
].Size
;
731 case GL_ATTRIB_ARRAY_STRIDE_NV
:
732 params
[0] = (GLfloat
) ctx
->Array
.VertexAttrib
[index
].Stride
;
734 case GL_ATTRIB_ARRAY_TYPE_NV
:
735 params
[0] = (GLfloat
) ctx
->Array
.VertexAttrib
[index
].Type
;
737 case GL_CURRENT_ATTRIB_NV
:
738 FLUSH_CURRENT(ctx
, 0);
739 COPY_4V(params
, ctx
->Current
.Attrib
[index
]);
742 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribdvNV");
748 * Get a vertex (or vertex array) attribute.
749 * \note Not compiled into display lists.
750 * \note Called from the GL API dispatcher.
753 _mesa_GetVertexAttribivNV(GLuint index
, GLenum pname
, GLint
*params
)
755 GET_CURRENT_CONTEXT(ctx
);
756 ASSERT_OUTSIDE_BEGIN_END(ctx
);
758 if (index
== 0 || index
>= MAX_NV_VERTEX_PROGRAM_INPUTS
) {
759 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribdvNV(index)");
764 case GL_ATTRIB_ARRAY_SIZE_NV
:
765 params
[0] = ctx
->Array
.VertexAttrib
[index
].Size
;
767 case GL_ATTRIB_ARRAY_STRIDE_NV
:
768 params
[0] = ctx
->Array
.VertexAttrib
[index
].Stride
;
770 case GL_ATTRIB_ARRAY_TYPE_NV
:
771 params
[0] = ctx
->Array
.VertexAttrib
[index
].Type
;
773 case GL_CURRENT_ATTRIB_NV
:
774 FLUSH_CURRENT(ctx
, 0);
775 params
[0] = (GLint
) ctx
->Current
.Attrib
[index
][0];
776 params
[1] = (GLint
) ctx
->Current
.Attrib
[index
][1];
777 params
[2] = (GLint
) ctx
->Current
.Attrib
[index
][2];
778 params
[3] = (GLint
) ctx
->Current
.Attrib
[index
][3];
780 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB
:
781 if (!ctx
->Extensions
.ARB_vertex_buffer_object
) {
782 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribdvNV");
785 params
[0] = ctx
->Array
.VertexAttribArrayBufferBinding
[index
];
788 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribdvNV");
795 * Get a vertex array attribute pointer.
796 * \note Not compiled into display lists.
797 * \note Called from the GL API dispatcher.
800 _mesa_GetVertexAttribPointervNV(GLuint index
, GLenum pname
, GLvoid
**pointer
)
802 GET_CURRENT_CONTEXT(ctx
);
803 ASSERT_OUTSIDE_BEGIN_END(ctx
);
805 if (index
>= MAX_NV_VERTEX_PROGRAM_INPUTS
) {
806 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetVertexAttribPointerNV(index)");
810 if (pname
!= GL_ATTRIB_ARRAY_POINTER_NV
) {
811 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetVertexAttribPointerNV(pname)");
815 *pointer
= ctx
->Array
.VertexAttrib
[index
].Ptr
;;
820 * Determine if id names a program.
821 * \note Not compiled into display lists.
822 * \note Called from both glIsProgramNV and glIsProgramARB.
823 * \param id is the program identifier
824 * \return GL_TRUE if id is a program, else GL_FALSE.
827 _mesa_IsProgramNV(GLuint id
)
829 struct program
*prog
;
830 GET_CURRENT_CONTEXT(ctx
);
831 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
836 prog
= (struct program
*) _mesa_HashLookup(ctx
->Shared
->Programs
, id
);
837 if (prog
&& prog
->Target
)
845 * Load/parse/compile a program.
846 * \note Called from the GL API dispatcher.
849 _mesa_LoadProgramNV(GLenum target
, GLuint id
, GLsizei len
,
850 const GLubyte
*program
)
852 struct program
*prog
;
853 GET_CURRENT_CONTEXT(ctx
);
854 ASSERT_OUTSIDE_BEGIN_END(ctx
);
857 _mesa_error(ctx
, GL_INVALID_VALUE
, "glLoadProgramNV(id)");
861 prog
= (struct program
*) _mesa_HashLookup(ctx
->Shared
->Programs
, id
);
863 if (prog
&& prog
->Target
!= 0 && prog
->Target
!= target
) {
864 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glLoadProgramNV(target)");
868 if ((target
== GL_VERTEX_PROGRAM_NV
||
869 target
== GL_VERTEX_STATE_PROGRAM_NV
)
870 && ctx
->Extensions
.NV_vertex_program
) {
871 struct vertex_program
*vprog
= (struct vertex_program
*) prog
;
873 vprog
= CALLOC_STRUCT(vertex_program
);
875 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glLoadProgramNV");
878 vprog
->Base
.RefCount
= 1;
879 vprog
->Base
.Resident
= GL_TRUE
;
880 _mesa_HashInsert(ctx
->Shared
->Programs
, id
, vprog
);
882 _mesa_parse_nv_vertex_program(ctx
, target
, program
, len
, vprog
);
884 else if (target
== GL_FRAGMENT_PROGRAM_NV
885 && ctx
->Extensions
.NV_fragment_program
) {
886 struct fragment_program
*fprog
= (struct fragment_program
*) prog
;
888 fprog
= CALLOC_STRUCT(fragment_program
);
890 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glLoadProgramNV");
893 fprog
->Base
.RefCount
= 1;
894 fprog
->Base
.Resident
= GL_TRUE
;
895 _mesa_HashInsert(ctx
->Shared
->Programs
, id
, fprog
);
897 _mesa_parse_nv_fragment_program(ctx
, target
, program
, len
, fprog
);
900 _mesa_error(ctx
, GL_INVALID_ENUM
, "glLoadProgramNV(target)");
907 * Set a program parameter register.
908 * \note Called from the GL API dispatcher.
911 _mesa_ProgramParameter4dNV(GLenum target
, GLuint index
,
912 GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
914 _mesa_ProgramParameter4fNV(target
, index
,
915 (GLfloat
)x
, (GLfloat
)y
, (GLfloat
)z
, (GLfloat
)w
);
920 * Set a program parameter register.
921 * \note Called from the GL API dispatcher.
924 _mesa_ProgramParameter4dvNV(GLenum target
, GLuint index
,
925 const GLdouble
*params
)
927 _mesa_ProgramParameter4fNV(target
, index
,
928 (GLfloat
)params
[0], (GLfloat
)params
[1],
929 (GLfloat
)params
[2], (GLfloat
)params
[3]);
934 * Set a program parameter register.
935 * \note Called from the GL API dispatcher.
938 _mesa_ProgramParameter4fNV(GLenum target
, GLuint index
,
939 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
941 GET_CURRENT_CONTEXT(ctx
);
942 ASSERT_OUTSIDE_BEGIN_END(ctx
);
944 if (target
== GL_VERTEX_PROGRAM_NV
&& ctx
->Extensions
.NV_vertex_program
) {
945 if (index
< MAX_NV_VERTEX_PROGRAM_PARAMS
) {
946 ASSIGN_4V(ctx
->VertexProgram
.Parameters
[index
], x
, y
, z
, w
);
949 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramParameterNV(index)");
954 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramParameterNV");
961 * Set a program parameter register.
962 * \note Called from the GL API dispatcher.
965 _mesa_ProgramParameter4fvNV(GLenum target
, GLuint index
,
966 const GLfloat
*params
)
968 _mesa_ProgramParameter4fNV(target
, index
,
969 params
[0], params
[1], params
[2], params
[3]);
975 * Set a sequence of program parameter registers.
976 * \note Called from the GL API dispatcher.
979 _mesa_ProgramParameters4dvNV(GLenum target
, GLuint index
,
980 GLuint num
, const GLdouble
*params
)
982 GET_CURRENT_CONTEXT(ctx
);
983 ASSERT_OUTSIDE_BEGIN_END(ctx
);
985 if (target
== GL_VERTEX_PROGRAM_NV
&& ctx
->Extensions
.NV_vertex_program
) {
987 if (index
+ num
> MAX_NV_VERTEX_PROGRAM_PARAMS
) {
988 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramParameters4dvNV");
991 for (i
= 0; i
< num
; i
++) {
992 ctx
->VertexProgram
.Parameters
[index
+ i
][0] = (GLfloat
) params
[0];
993 ctx
->VertexProgram
.Parameters
[index
+ i
][1] = (GLfloat
) params
[1];
994 ctx
->VertexProgram
.Parameters
[index
+ i
][2] = (GLfloat
) params
[2];
995 ctx
->VertexProgram
.Parameters
[index
+ i
][3] = (GLfloat
) params
[3];
1000 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramParameters4dvNV");
1007 * Set a sequence of program parameter registers.
1008 * \note Called from the GL API dispatcher.
1011 _mesa_ProgramParameters4fvNV(GLenum target
, GLuint index
,
1012 GLuint num
, const GLfloat
*params
)
1014 GET_CURRENT_CONTEXT(ctx
);
1015 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1017 if (target
== GL_VERTEX_PROGRAM_NV
&& ctx
->Extensions
.NV_vertex_program
) {
1019 if (index
+ num
> MAX_NV_VERTEX_PROGRAM_PARAMS
) {
1020 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramParameters4fvNV");
1023 for (i
= 0; i
< num
; i
++) {
1024 COPY_4V(ctx
->VertexProgram
.Parameters
[index
+ i
], params
);
1029 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramParameters4fvNV");
1037 * Setup tracking of matrices into program parameter registers.
1038 * \note Called from the GL API dispatcher.
1041 _mesa_TrackMatrixNV(GLenum target
, GLuint address
,
1042 GLenum matrix
, GLenum transform
)
1044 GET_CURRENT_CONTEXT(ctx
);
1045 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1047 if (target
== GL_VERTEX_PROGRAM_NV
&& ctx
->Extensions
.NV_vertex_program
) {
1048 if (address
& 0x3) {
1049 /* addr must be multiple of four */
1050 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTrackMatrixNV(address)");
1060 case GL_MODELVIEW_PROJECTION_NV
:
1069 /* OK, fallthrough */
1072 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTrackMatrixNV(matrix)");
1076 switch (transform
) {
1077 case GL_IDENTITY_NV
:
1079 case GL_TRANSPOSE_NV
:
1080 case GL_INVERSE_TRANSPOSE_NV
:
1081 /* OK, fallthrough */
1084 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTrackMatrixNV(transform)");
1088 ctx
->VertexProgram
.TrackMatrix
[address
/ 4] = matrix
;
1089 ctx
->VertexProgram
.TrackMatrixTransform
[address
/ 4] = transform
;
1092 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTrackMatrixNV(target)");
1099 _mesa_ProgramNamedParameter4fNV(GLuint id
, GLsizei len
, const GLubyte
*name
,
1100 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
1102 struct program
*prog
;
1103 struct fragment_program
*fragProg
;
1105 GET_CURRENT_CONTEXT(ctx
);
1106 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1108 prog
= (struct program
*) _mesa_HashLookup(ctx
->Shared
->Programs
, id
);
1109 if (!prog
|| prog
->Target
!= GL_FRAGMENT_PROGRAM_NV
) {
1110 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glProgramNamedParameterNV");
1115 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramNamedParameterNV");
1119 fragProg
= (struct fragment_program
*) prog
;
1120 for (i
= 0; i
< fragProg
->NumParameters
; i
++) {
1121 if (!_mesa_strncmp(fragProg
->Parameters
[i
].Name
,
1122 (const char *) name
, len
) &&
1123 fragProg
->Parameters
[i
].Name
[len
] == 0) {
1124 ASSERT(!fragProg
->Parameters
[i
].Constant
);
1125 fragProg
->Parameters
[i
].Values
[0] = x
;
1126 fragProg
->Parameters
[i
].Values
[1] = y
;
1127 fragProg
->Parameters
[i
].Values
[2] = z
;
1128 fragProg
->Parameters
[i
].Values
[3] = w
;
1133 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramNamedParameterNV");
1138 _mesa_ProgramNamedParameter4fvNV(GLuint id
, GLsizei len
, const GLubyte
*name
,
1141 _mesa_ProgramNamedParameter4fNV(id
, len
, name
, v
[0], v
[1], v
[2], v
[3]);
1146 _mesa_ProgramNamedParameter4dNV(GLuint id
, GLsizei len
, const GLubyte
*name
,
1147 GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
1149 _mesa_ProgramNamedParameter4fNV(id
, len
, name
, (GLfloat
)x
, (GLfloat
)y
,
1150 (GLfloat
)z
, (GLfloat
)w
);
1155 _mesa_ProgramNamedParameter4dvNV(GLuint id
, GLsizei len
, const GLubyte
*name
,
1158 _mesa_ProgramNamedParameter4fNV(id
, len
, name
,
1159 (GLfloat
)v
[0], (GLfloat
)v
[1],
1160 (GLfloat
)v
[2], (GLfloat
)v
[3]);
1165 _mesa_GetProgramNamedParameterfvNV(GLuint id
, GLsizei len
, const GLubyte
*name
,
1168 struct program
*prog
;
1169 struct fragment_program
*fragProg
;
1171 GET_CURRENT_CONTEXT(ctx
);
1173 if (!ctx
->_CurrentProgram
)
1174 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1176 prog
= (struct program
*) _mesa_HashLookup(ctx
->Shared
->Programs
, id
);
1177 if (!prog
|| prog
->Target
!= GL_FRAGMENT_PROGRAM_NV
) {
1178 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetProgramNamedParameterNV");
1183 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramNamedParameterNV");
1187 fragProg
= (struct fragment_program
*) prog
;
1188 for (i
= 0; i
< fragProg
->NumParameters
; i
++) {
1189 if (!_mesa_strncmp(fragProg
->Parameters
[i
].Name
,
1190 (const char *) name
, len
) &&
1191 fragProg
->Parameters
[i
].Name
[len
] == 0) {
1192 ASSERT(!fragProg
->Parameters
[i
].Constant
);
1193 params
[0] = fragProg
->Parameters
[i
].Values
[0];
1194 params
[1] = fragProg
->Parameters
[i
].Values
[1];
1195 params
[2] = fragProg
->Parameters
[i
].Values
[2];
1196 params
[3] = fragProg
->Parameters
[i
].Values
[3];
1201 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramNamedParameterNV");
1206 _mesa_GetProgramNamedParameterdvNV(GLuint id
, GLsizei len
, const GLubyte
*name
,
1209 GLfloat floatParams
[4];
1210 _mesa_GetProgramNamedParameterfvNV(id
, len
, name
, floatParams
);
1211 COPY_4V(params
, floatParams
);