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 "arbprogram.h"
43 _mesa_VertexAttrib1sARB(GLuint index
, GLshort x
)
48 _mesa_VertexAttrib1fARB(GLuint index
, GLfloat x
)
53 _mesa_VertexAttrib1dARB(GLuint index
, GLdouble x
)
58 _mesa_VertexAttrib2sARB(GLuint index
, GLshort x
, GLshort y
)
63 _mesa_VertexAttrib2fARB(GLuint index
, GLfloat x
, GLfloat y
)
68 _mesa_VertexAttrib2dARB(GLuint index
, GLdouble x
, GLdouble y
)
73 _mesa_VertexAttrib3sARB(GLuint index
, GLshort x
, GLshort y
, GLshort z
)
78 _mesa_VertexAttrib3fARB(GLuint index
, GLfloat x
, GLfloat y
, GLfloat z
)
83 _mesa_VertexAttrib3dARB(GLuint index
, GLdouble x
, GLdouble y
, GLdouble z
)
88 _mesa_VertexAttrib4sARB(GLuint index
, GLshort x
, GLshort y
, GLshort z
, GLshort w
)
93 _mesa_VertexAttrib4fARB(GLuint index
, GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
98 _mesa_VertexAttrib4dARB(GLuint index
, GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
103 _mesa_VertexAttrib4NubARB(GLuint index
, GLubyte x
, GLubyte y
, GLubyte z
, GLubyte w
)
108 _mesa_VertexAttrib1svARB(GLuint index
, const GLshort
*v
)
113 _mesa_VertexAttrib1fvARB(GLuint index
, const GLfloat
*v
)
118 _mesa_VertexAttrib1dvARB(GLuint index
, const GLdouble
*v
)
123 _mesa_VertexAttrib2svARB(GLuint index
, const GLshort
*v
)
128 _mesa_VertexAttrib2fvARB(GLuint index
, const GLfloat
*v
)
133 _mesa_VertexAttrib2dvARB(GLuint index
, const GLdouble
*v
)
138 _mesa_VertexAttrib3svARB(GLuint index
, const GLshort
*v
)
143 _mesa_VertexAttrib3fvARB(GLuint index
, const GLfloat
*v
)
148 _mesa_VertexAttrib3dvARB(GLuint index
, const GLdouble
*v
)
153 _mesa_VertexAttrib4bvARB(GLuint index
, const GLbyte
*v
)
158 _mesa_VertexAttrib4svARB(GLuint index
, const GLshort
*v
)
163 _mesa_VertexAttrib4ivARB(GLuint index
, const GLint
*v
)
168 _mesa_VertexAttrib4ubvARB(GLuint index
, const GLubyte
*v
)
173 _mesa_VertexAttrib4usvARB(GLuint index
, const GLushort
*v
)
178 _mesa_VertexAttrib4uivARB(GLuint index
, const GLuint
*v
)
183 _mesa_VertexAttrib4fvARB(GLuint index
, const GLfloat
*v
)
188 _mesa_VertexAttrib4dvARB(GLuint index
, const GLdouble
*v
)
193 _mesa_VertexAttrib4NbvARB(GLuint index
, const GLbyte
*v
)
198 _mesa_VertexAttrib4NsvARB(GLuint index
, const GLshort
*v
)
203 _mesa_VertexAttrib4NivARB(GLuint index
, const GLint
*v
)
208 _mesa_VertexAttrib4NubvARB(GLuint index
, const GLubyte
*v
)
213 _mesa_VertexAttrib4NusvARB(GLuint index
, const GLushort
*v
)
218 _mesa_VertexAttrib4NuivARB(GLuint index
, const GLuint
*v
)
224 _mesa_VertexAttribPointerARB(GLuint index
, GLint size
, GLenum type
,
225 GLboolean normalized
, GLsizei stride
,
226 const GLvoid
*pointer
)
232 _mesa_EnableVertexAttribArrayARB(GLuint index
)
238 _mesa_DisableVertexAttribArrayARB(GLuint index
)
244 _mesa_GetVertexAttribdvARB(GLuint index
, GLenum pname
, GLdouble
*params
)
250 _mesa_GetVertexAttribfvARB(GLuint index
, GLenum pname
, GLfloat
*params
)
256 _mesa_GetVertexAttribivARB(GLuint index
, GLenum pname
, GLint
*params
)
262 _mesa_GetVertexAttribPointervARB(GLuint index
, GLenum pname
, GLvoid
**pointer
)
268 _mesa_ProgramStringARB(GLenum target
, GLenum format
, GLsizei len
,
269 const GLvoid
*string
)
275 _mesa_BindProgramARB(GLenum target
, GLuint program
)
281 _mesa_DeleteProgramsARB(GLsizei n
, const GLuint
*programs
)
287 _mesa_GenProgramsARB(GLsizei n
, GLuint
*programs
)
293 _mesa_ProgramEnvParameter4dARB(GLenum target
, GLuint index
,
294 GLdouble x
, GLdouble y
, GLdouble z
, GLdouble w
)
300 _mesa_ProgramEnvParameter4dvARB(GLenum target
, GLuint index
,
301 const GLdouble
*params
)
307 _mesa_ProgramEnvParameter4fARB(GLenum target
, GLuint index
,
308 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
314 _mesa_ProgramEnvParameter4fvARB(GLenum target
, GLuint index
,
315 const GLfloat
*params
)
323 _mesa_ProgramLocalParameter4fARB(GLenum target
, GLuint index
,
324 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
326 GET_CURRENT_CONTEXT(ctx
);
327 ASSERT_OUTSIDE_BEGIN_END(ctx
);
329 if (target
== GL_FRAGMENT_PROGRAM_NV
) {
330 struct fragment_program
*fprog
= ctx
->FragmentProgram
.Current
;
332 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameterARB");
335 if (index
>= MAX_NV_FRAGMENT_PROGRAM_PARAMS
) {
336 _mesa_error(ctx
, GL_INVALID_VALUE
, "glProgramLocalParameterARB");
339 fprog
->Base
.LocalParams
[index
][0] = x
;
340 fprog
->Base
.LocalParams
[index
][1] = y
;
341 fprog
->Base
.LocalParams
[index
][2] = z
;
342 fprog
->Base
.LocalParams
[index
][3] = w
;
345 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramLocalParameterARB");
352 _mesa_ProgramLocalParameter4fvARB(GLenum target
, GLuint index
,
353 const GLfloat
*params
)
355 glProgramLocalParameter4fARB(target
, index
, params
[0], params
[1],
356 params
[2], params
[3]);
361 _mesa_ProgramLocalParameter4dARB(GLenum target
, GLuint index
,
362 GLdouble x
, GLdouble y
,
363 GLdouble z
, GLdouble w
)
365 glProgramLocalParameter4fARB(target
, index
, (GLfloat
)x
, (GLfloat
)y
,
366 (GLfloat
)z
, (GLfloat
)w
);
371 _mesa_ProgramLocalParameter4dvARB(GLenum target
, GLuint index
,
372 const GLdouble
*params
)
374 glProgramLocalParameter4fARB(target
, index
, (GLfloat
)params
[0],
375 (GLfloat
)params
[1], (GLfloat
)params
[2],
381 _mesa_GetProgramLocalParameterfvARB(GLenum target
, GLuint index
,
384 struct program
*prog
;
386 GET_CURRENT_CONTEXT(ctx
);
387 ASSERT_OUTSIDE_BEGIN_END(ctx
);
389 if (target
== GL_VERTEX_PROGRAM_ARB
390 && ctx
->Extensions
.ARB_vertex_program
) {
391 prog
= &(ctx
->VertexProgram
.Current
->Base
);
392 maxParams
= ctx
->Const
.MaxVertexProgramParams
;
394 else if ((target
== GL_FRAGMENT_PROGRAM_ARB
395 && ctx
->Extensions
.ARB_fragment_program
) ||
396 (target
== GL_FRAGMENT_PROGRAM_NV
397 && ctx
->Extensions
.NV_fragment_program
)) {
398 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
399 maxParams
= ctx
->Const
.MaxFragmentProgramParams
;
402 _mesa_error(ctx
, GL_INVALID_ENUM
,
403 "glGetProgramLocalParameterARB(target)");
407 if (index
>= maxParams
) {
408 _mesa_error(ctx
, GL_INVALID_VALUE
,
409 "glGetProgramLocalParameterARB(index)");
414 params
[0] = prog
->LocalParams
[index
][0];
415 params
[1] = prog
->LocalParams
[index
][1];
416 params
[2] = prog
->LocalParams
[index
][2];
417 params
[3] = prog
->LocalParams
[index
][3];
422 _mesa_GetProgramLocalParameterdvARB(GLenum target
, GLuint index
,
425 GLfloat floatParams
[4];
426 glGetProgramLocalParameterfvARB(target
, index
, floatParams
);
427 COPY_4V(params
, floatParams
);
434 _mesa_ProgramLocalParameter4dARB(GLenum target
, GLuint index
,
435 GLdouble x
, GLdouble y
,
436 GLdouble z
, GLdouble w
)
442 _mesa_ProgramLocalParameter4dvARB(GLenum target
, GLuint index
,
443 const GLdouble
*params
)
449 _mesa_ProgramLocalParameter4fARB(GLenum target
, GLuint index
,
450 GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
)
456 _mesa_ProgramLocalParameter4fvARB(GLenum target
, GLuint index
,
457 const GLfloat
*params
)
464 _mesa_GetProgramEnvParameterdvARB(GLenum target
, GLuint index
,
471 _mesa_GetProgramEnvParameterfvARB(GLenum target
, GLuint index
,
479 _mesa_GetProgramLocalParameterdvARB(GLenum target
, GLuint index
,
486 _mesa_GetProgramLocalParameterfvARB(GLenum target
, GLuint index
,
495 _mesa_GetProgramivARB(GLenum target
, GLenum pname
, GLint
*params
)
497 struct program
*prog
;
498 GET_CURRENT_CONTEXT(ctx
);
499 ASSERT_OUTSIDE_BEGIN_END(ctx
);
501 if (target
== GL_VERTEX_PROGRAM_ARB
) {
502 prog
= &(ctx
->VertexProgram
.Current
->Base
);
504 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
505 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
508 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(target)");
515 case GL_PROGRAM_LENGTH_ARB
:
516 *params
= prog
->String
? _mesa_strlen((char *) prog
->String
) : 0;
518 case GL_PROGRAM_FORMAT_ARB
:
519 *params
= prog
->Format
;
521 case GL_PROGRAM_BINDING_ARB
:
524 case GL_PROGRAM_INSTRUCTIONS_ARB
:
525 *params
= prog
->NumInstructions
;
527 case GL_MAX_PROGRAM_INSTRUCTIONS_ARB
:
528 case GL_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
529 case GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB
:
530 case GL_PROGRAM_TEMPORARIES_ARB
:
531 case GL_MAX_PROGRAM_TEMPORARIES_ARB
:
532 case GL_PROGRAM_NATIVE_TEMPORARIES_ARB
:
533 case GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB
:
534 case GL_PROGRAM_PARAMETERS_ARB
:
535 case GL_MAX_PROGRAM_PARAMETERS_ARB
:
536 case GL_PROGRAM_NATIVE_PARAMETERS_ARB
:
537 case GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB
:
538 case GL_PROGRAM_ATTRIBS_ARB
:
539 case GL_MAX_PROGRAM_ATTRIBS_ARB
:
540 case GL_PROGRAM_NATIVE_ATTRIBS_ARB
:
541 case GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB
:
542 case GL_PROGRAM_ADDRESS_REGISTERS_ARB
:
543 case GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB
:
544 case GL_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
545 case GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
:
546 case GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB
:
547 case GL_MAX_PROGRAM_ENV_PARAMETERS_ARB
:
548 case GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB
:
551 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramivARB(pname)");
558 _mesa_GetProgramStringARB(GLenum target
, GLenum pname
, GLvoid
*string
)
560 struct program
*prog
;
561 GET_CURRENT_CONTEXT(ctx
);
562 ASSERT_OUTSIDE_BEGIN_END(ctx
);
564 if (target
== GL_VERTEX_PROGRAM_ARB
) {
565 prog
= &(ctx
->VertexProgram
.Current
->Base
);
567 else if (target
== GL_FRAGMENT_PROGRAM_ARB
) {
568 prog
= &(ctx
->FragmentProgram
.Current
->Base
);
571 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(target)");
577 if (pname
!= GL_PROGRAM_STRING_ARB
) {
578 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramStringARB(pname)");
582 MEMCPY(string
, prog
->String
, _mesa_strlen((char *) prog
->String
));
587 _mesa_IsProgramARB(GLuint program
)
589 struct program
*prog
;
590 GET_CURRENT_CONTEXT(ctx
);
591 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
596 prog
= (struct program
*) _mesa_HashLookup(ctx
->Shared
->Programs
, program
);
597 if (prog
&& prog
->Target
)