2 * Mesa 3-D graphics library
5 * Copyright (C) 2004-2006 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.
26 * \file shaderobjects.c
27 * ARB_shader_objects state management functions
35 #include "shaderobjects.h"
36 #include "shaderobjects_3dlabs.h"
39 #define I_UNKNOWN struct gl2_unknown_intf **
40 #define I_GENERIC struct gl2_generic_intf **
41 #define I_CONTAINER struct gl2_container_intf **
42 #define I_PROGRAM struct gl2_program_intf **
43 #define I_SHADER struct gl2_shader_intf **
45 #define RELEASE_GENERIC(x)\
46 (**x)._unknown.Release ((I_UNKNOWN) x)
48 #define RELEASE_CONTAINER(x)\
49 (**x)._generic._unknown.Release ((I_UNKNOWN) x)
51 #define RELEASE_PROGRAM(x)\
52 (**x)._container._generic._unknown.Release ((I_UNKNOWN) x)
54 #define RELEASE_SHADER(x)\
55 (**x)._generic._unknown.Release ((I_UNKNOWN) x);
57 #define _LOOKUP_HANDLE(handle, function)\
59 _glthread_LOCK_MUTEX (ctx->Shared->Mutex);\
60 unk = (I_UNKNOWN) _mesa_HashLookup (ctx->Shared->GL2Objects, handle);\
61 _glthread_UNLOCK_MUTEX (ctx->Shared->Mutex);\
63 _mesa_error (ctx, GL_INVALID_VALUE, function);\
67 #define _QUERY_INTERFACE(x, type, uuid, function)\
68 x = (type) (**unk).QueryInterface (unk, uuid);\
70 _mesa_error (ctx, GL_INVALID_OPERATION, function);\
74 #define GET_GENERIC(x, handle, function)\
77 _LOOKUP_HANDLE(handle, function);\
78 _QUERY_INTERFACE(x, I_GENERIC, UIID_GENERIC, function);\
81 #define GET_CONTAINER(x, handle, function)\
82 I_CONTAINER x = NULL;\
84 _LOOKUP_HANDLE(handle, function);\
85 _QUERY_INTERFACE(x, I_CONTAINER, UIID_CONTAINER, function);\
88 #define GET_PROGRAM(x, handle, function)\
91 _LOOKUP_HANDLE(handle, function);\
92 _QUERY_INTERFACE(x, I_PROGRAM, UIID_PROGRAM, function);\
95 #define GET_SHADER(x, handle, function)\
98 _LOOKUP_HANDLE(handle, function);\
99 _QUERY_INTERFACE(x, I_SHADER, UIID_SHADER, function);\
102 #define _LINKED_PROGRAM(x, function)\
103 if ((**x).GetLinkStatus (x) == GL_FALSE) {\
105 _mesa_error (ctx, GL_INVALID_OPERATION, function);\
109 #define GET_LINKED_PROGRAM(x, handle, function)\
112 _LOOKUP_HANDLE(handle, function);\
113 _QUERY_INTERFACE(x, I_PROGRAM, UIID_PROGRAM, function);\
114 _LINKED_PROGRAM(x, function);\
117 #define _CURRENT_PROGRAM(x, function)\
118 if (ctx->ShaderObjects.CurrentProgram == NULL) {\
119 _mesa_error (ctx, GL_INVALID_OPERATION, function);\
122 x = ctx->ShaderObjects.CurrentProgram;
124 #define GET_CURRENT_LINKED_PROGRAM(x, function)\
127 _CURRENT_PROGRAM(x, function);\
128 _LINKED_PROGRAM(x, function);\
133 _mesa_DeleteObjectARB (GLhandleARB obj
)
135 GET_CURRENT_CONTEXT(ctx
);
136 GET_GENERIC(gen
, obj
, "glDeleteObjectARB");
140 (**gen
).Delete (gen
);
141 RELEASE_GENERIC(gen
);
145 GLhandleARB GLAPIENTRY
146 _mesa_GetHandleARB (GLenum pname
)
148 GET_CURRENT_CONTEXT(ctx
);
152 case GL_PROGRAM_OBJECT_ARB
:
154 I_PROGRAM pro
= ctx
->ShaderObjects
.CurrentProgram
;
157 return (**pro
)._container
._generic
.GetName ((I_GENERIC
) pro
);
161 _mesa_error (ctx
, GL_INVALID_ENUM
, "glGetHandleARB");
168 _mesa_DetachObjectARB (GLhandleARB containerObj
, GLhandleARB attachedObj
)
170 GET_CURRENT_CONTEXT(ctx
);
171 GET_CONTAINER(con
, containerObj
, "glDetachObjectARB");
175 GET_GENERIC(att
, attachedObj
, "glDetachObjectARB");
179 (**con
).Detach (con
, att
);
180 RELEASE_GENERIC(att
);
182 RELEASE_CONTAINER(con
);
186 GLhandleARB GLAPIENTRY
187 _mesa_CreateShaderObjectARB (GLenum shaderType
)
189 return _mesa_3dlabs_create_shader_object (shaderType
);
193 _mesa_ShaderSourceARB (GLhandleARB shaderObj
, GLsizei count
, const GLcharARB
**string
,
196 GET_CURRENT_CONTEXT(ctx
);
200 GET_SHADER(sha
, shaderObj
, "glShaderSourceARB");
208 _mesa_error (ctx
, GL_INVALID_VALUE
, "glShaderSourceARB");
213 * This array holds offsets of where the appropriate string ends, thus the last
214 * element will be set to the total length of the source code.
216 offsets
= (GLint
*) _mesa_malloc (count
* sizeof (GLint
));
220 _mesa_error (ctx
, GL_OUT_OF_MEMORY
, "glShaderSourceARB");
224 for (i
= 0; i
< count
; i
++)
226 if (string
[i
] == NULL
)
228 _mesa_free ((GLvoid
*) offsets
);
230 _mesa_error (ctx
, GL_INVALID_VALUE
, "glShaderSourceARB");
233 if (length
== NULL
|| length
[i
] < 0)
234 offsets
[i
] = _mesa_strlen (string
[i
]);
236 offsets
[i
] = length
[i
];
237 /* accumulate string lengths */
239 offsets
[i
] += offsets
[i
- 1];
242 source
= (GLcharARB
*) _mesa_malloc ((offsets
[count
- 1] + 1) * sizeof (GLcharARB
));
245 _mesa_free ((GLvoid
*) offsets
);
247 _mesa_error (ctx
, GL_OUT_OF_MEMORY
, "glShaderSourceARB");
251 for (i
= 0; i
< count
; i
++)
253 GLint start
= (i
> 0) ? offsets
[i
- 1] : 0;
254 _mesa_memcpy (source
+ start
, string
[i
], (offsets
[i
] - start
) * sizeof (GLcharARB
));
256 source
[offsets
[count
- 1]] = '\0';
258 (**sha
).SetSource (sha
, source
, offsets
, count
);
263 _mesa_CompileShaderARB (GLhandleARB shaderObj
)
265 GET_CURRENT_CONTEXT(ctx
);
266 GET_SHADER(sha
, shaderObj
, "glCompileShaderARB");
270 (**sha
).Compile (sha
);
275 GLhandleARB GLAPIENTRY
276 _mesa_CreateProgramObjectARB (GLvoid
)
278 return _mesa_3dlabs_create_program_object ();
282 _mesa_AttachObjectARB (GLhandleARB containerObj
, GLhandleARB obj
)
284 GET_CURRENT_CONTEXT(ctx
);
285 GET_CONTAINER(con
, containerObj
, "glAttachObjectARB");
289 GET_GENERIC(att
, obj
, "glAttachObjectARB");
293 (**con
).Attach (con
, att
);
294 RELEASE_GENERIC(att
);
296 RELEASE_CONTAINER(con
);
301 _mesa_LinkProgramARB (GLhandleARB programObj
)
303 GET_CURRENT_CONTEXT(ctx
);
304 GET_PROGRAM(pro
, programObj
, "glLinkProgramARB");
309 if (pro
== ctx
->ShaderObjects
.CurrentProgram
)
311 if ((**pro
).GetLinkStatus (pro
))
312 _mesa_UseProgramObjectARB (programObj
);
314 _mesa_UseProgramObjectARB (0);
316 RELEASE_PROGRAM(pro
);
321 _mesa_UseProgramObjectARB (GLhandleARB programObj
)
323 GET_CURRENT_CONTEXT(ctx
);
324 I_PROGRAM program
= NULL
;
326 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
330 GET_PROGRAM(pro
, programObj
, "glUseProgramObjectARB");
335 if ((**pro
).GetLinkStatus (pro
) == GL_FALSE
)
337 RELEASE_PROGRAM(pro
);
338 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUseProgramObjectARB");
344 ctx
->ShaderObjects
._VertexShaderPresent
= (**pro
).IsShaderPresent (pro
, GL_VERTEX_SHADER_ARB
);
345 ctx
->ShaderObjects
._FragmentShaderPresent
= (**pro
).IsShaderPresent (pro
,
346 GL_FRAGMENT_SHADER_ARB
);
350 ctx
->ShaderObjects
._VertexShaderPresent
= GL_FALSE
;
351 ctx
->ShaderObjects
._FragmentShaderPresent
= GL_FALSE
;
354 if (ctx
->ShaderObjects
.CurrentProgram
!= NULL
)
355 RELEASE_PROGRAM(ctx
->ShaderObjects
.CurrentProgram
);
356 ctx
->ShaderObjects
.CurrentProgram
= program
;
360 _mesa_ValidateProgramARB (GLhandleARB programObj
)
362 GET_CURRENT_CONTEXT(ctx
);
363 GET_PROGRAM(pro
, programObj
, "glValidateProgramARB");
367 (**pro
).Validate (pro
);
368 RELEASE_PROGRAM(pro
);
373 _mesa_Uniform1fARB (GLint location
, GLfloat v0
)
375 GET_CURRENT_CONTEXT(ctx
);
376 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniform1fARB");
378 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
382 if (!_slang_write_uniform (pro
, location
, 1, &v0
, GL_FLOAT
))
383 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniform1fARB");
388 _mesa_Uniform2fARB (GLint location
, GLfloat v0
, GLfloat v1
)
390 GET_CURRENT_CONTEXT(ctx
);
391 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniform2fARB");
393 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
401 if (!_slang_write_uniform (pro
, location
, 1, v
, GL_FLOAT_VEC2
))
402 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniform2fARB");
407 _mesa_Uniform3fARB (GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
)
409 GET_CURRENT_CONTEXT(ctx
);
410 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniform3fARB");
412 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
421 if (!_slang_write_uniform (pro
, location
, 1, v
, GL_FLOAT_VEC3
))
422 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniform3fARB");
427 _mesa_Uniform4fARB (GLint location
, GLfloat v0
, GLfloat v1
, GLfloat v2
, GLfloat v3
)
429 GET_CURRENT_CONTEXT(ctx
);
430 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniform4fARB");
432 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
442 if (!_slang_write_uniform (pro
, location
, 1, v
, GL_FLOAT_VEC4
))
443 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniform4fARB");
448 _mesa_Uniform1iARB (GLint location
, GLint v0
)
450 GET_CURRENT_CONTEXT(ctx
);
451 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniform1iARB");
453 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
457 if (!_slang_write_uniform (pro
, location
, 1, &v0
, GL_INT
))
458 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniform1iARB");
463 _mesa_Uniform2iARB (GLint location
, GLint v0
, GLint v1
)
465 GET_CURRENT_CONTEXT(ctx
);
466 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniform2iARB");
468 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
476 if (!_slang_write_uniform (pro
, location
, 1, v
, GL_INT_VEC2
))
477 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniform2iARB");
482 _mesa_Uniform3iARB (GLint location
, GLint v0
, GLint v1
, GLint v2
)
484 GET_CURRENT_CONTEXT(ctx
);
485 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniform3iARB");
487 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
496 if (!_slang_write_uniform (pro
, location
, 1, v
, GL_INT_VEC3
))
497 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniform3iARB");
502 _mesa_Uniform4iARB (GLint location
, GLint v0
, GLint v1
, GLint v2
, GLint v3
)
504 GET_CURRENT_CONTEXT(ctx
);
505 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniform4iARB");
507 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
517 if (!_slang_write_uniform (pro
, location
, 1, v
, GL_INT_VEC4
))
518 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniform4iARB");
523 _mesa_Uniform1fvARB (GLint location
, GLsizei count
, const GLfloat
*value
)
525 GET_CURRENT_CONTEXT(ctx
);
526 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniform1fvARB");
528 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
532 if (!_slang_write_uniform (pro
, location
, count
, value
, GL_FLOAT
))
533 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniform1fvARB");
538 _mesa_Uniform2fvARB (GLint location
, GLsizei count
, const GLfloat
*value
)
540 GET_CURRENT_CONTEXT(ctx
);
541 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniform2fvARB");
543 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
547 if (!_slang_write_uniform (pro
, location
, count
, value
, GL_FLOAT_VEC2
))
548 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniform2fvARB");
553 _mesa_Uniform3fvARB (GLint location
, GLsizei count
, const GLfloat
*value
)
555 GET_CURRENT_CONTEXT(ctx
);
556 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniform3fvARB");
558 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
562 if (!_slang_write_uniform (pro
, location
, count
, value
, GL_FLOAT_VEC3
))
563 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniform3fvARB");
568 _mesa_Uniform4fvARB (GLint location
, GLsizei count
, const GLfloat
*value
)
570 GET_CURRENT_CONTEXT(ctx
);
571 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniform4fvARB");
573 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
577 if (!_slang_write_uniform (pro
, location
, count
, value
, GL_FLOAT_VEC4
))
578 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniform4fvARB");
583 _mesa_Uniform1ivARB (GLint location
, GLsizei count
, const GLint
*value
)
585 GET_CURRENT_CONTEXT(ctx
);
586 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniform1ivARB");
588 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
592 if (!_slang_write_uniform (pro
, location
, count
, value
, GL_INT
))
593 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniform1ivARB");
598 _mesa_Uniform2ivARB (GLint location
, GLsizei count
, const GLint
*value
)
600 GET_CURRENT_CONTEXT(ctx
);
601 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniform2ivARB");
603 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
607 if (!_slang_write_uniform (pro
, location
, count
, value
, GL_INT_VEC2
))
608 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniform2ivARB");
613 _mesa_Uniform3ivARB (GLint location
, GLsizei count
, const GLint
*value
)
615 GET_CURRENT_CONTEXT(ctx
);
616 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniform3ivARB");
618 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
622 if (!_slang_write_uniform (pro
, location
, count
, value
, GL_INT_VEC3
))
623 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniform3ivARB");
628 _mesa_Uniform4ivARB (GLint location
, GLsizei count
, const GLint
*value
)
630 GET_CURRENT_CONTEXT(ctx
);
631 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniform4ivARB");
633 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
637 if (!_slang_write_uniform (pro
, location
, count
, value
, GL_INT_VEC4
))
638 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniform4ivARB");
643 _mesa_UniformMatrix2fvARB (GLint location
, GLsizei count
, GLboolean transpose
, const GLfloat
*value
)
645 GET_CURRENT_CONTEXT(ctx
);
646 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniformMatrix2fvARB");
648 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
657 trans
= (GLfloat
*) _mesa_malloc (count
* 4 * sizeof (GLfloat
));
660 _mesa_error (ctx
, GL_OUT_OF_MEMORY
, "glUniformMatrix2fvARB");
663 for (pt
= trans
, pv
= value
; pt
!= trans
+ count
* 4; pt
+= 4, pv
+= 4)
670 if (!_slang_write_uniform (pro
, location
, count
, trans
, GL_FLOAT_MAT2
))
671 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniformMatrix2fvARB");
676 if (!_slang_write_uniform (pro
, location
, count
, value
, GL_FLOAT_MAT2
))
677 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniformMatrix2fvARB");
683 _mesa_UniformMatrix3fvARB (GLint location
, GLsizei count
, GLboolean transpose
, const GLfloat
*value
)
685 GET_CURRENT_CONTEXT(ctx
);
686 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniformMatrix3fvARB");
688 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
697 trans
= (GLfloat
*) _mesa_malloc (count
* 9 * sizeof (GLfloat
));
700 _mesa_error (ctx
, GL_OUT_OF_MEMORY
, "glUniformMatrix3fvARB");
703 for (pt
= trans
, pv
= value
; pt
!= trans
+ count
* 9; pt
+= 9, pv
+= 9)
715 if (!_slang_write_uniform (pro
, location
, count
, trans
, GL_FLOAT_MAT3
))
716 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniformMatrix3fvARB");
721 if (!_slang_write_uniform (pro
, location
, count
, value
, GL_FLOAT_MAT3
))
722 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniformMatrix3fvARB");
728 _mesa_UniformMatrix4fvARB (GLint location
, GLsizei count
, GLboolean transpose
, const GLfloat
*value
)
730 GET_CURRENT_CONTEXT(ctx
);
731 GET_CURRENT_LINKED_PROGRAM(pro
, "glUniformMatrix4fvARB");
733 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
742 trans
= (GLfloat
*) _mesa_malloc (count
* 16 * sizeof (GLfloat
));
745 _mesa_error (ctx
, GL_OUT_OF_MEMORY
, "glUniformMatrix4fvARB");
748 for (pt
= trans
, pv
= value
; pt
!= trans
+ count
* 16; pt
+= 16, pv
+= 16)
750 _math_transposef (pt
, pv
);
752 if (!_slang_write_uniform (pro
, location
, count
, trans
, GL_FLOAT_MAT4
))
753 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniformMatrix4fvARB");
758 if (!_slang_write_uniform (pro
, location
, count
, value
, GL_FLOAT_MAT4
))
759 _mesa_error (ctx
, GL_INVALID_OPERATION
, "glUniformMatrix4fvARB");
765 _mesa_get_object_parameter (GLhandleARB obj
, GLenum pname
, GLvoid
*params
, GLboolean
*integral
,
768 GET_CURRENT_CONTEXT(ctx
);
769 GLint
*ipar
= (GLint
*) params
;
771 /* set default values */
772 *integral
= GL_TRUE
; /* indicates param type, TRUE: GLint, FALSE: GLfloat */
773 *size
= 1; /* param array size */
777 case GL_OBJECT_TYPE_ARB
:
778 case GL_OBJECT_DELETE_STATUS_ARB
:
779 case GL_OBJECT_INFO_LOG_LENGTH_ARB
:
781 GET_GENERIC(gen
, obj
, "glGetObjectParameterivARB");
788 case GL_OBJECT_TYPE_ARB
:
789 *ipar
= (**gen
).GetType (gen
);
791 case GL_OBJECT_DELETE_STATUS_ARB
:
792 *ipar
= (**gen
).GetDeleteStatus (gen
);
794 case GL_OBJECT_INFO_LOG_LENGTH_ARB
:
796 const GLcharARB
*info
= (**gen
).GetInfoLog (gen
);
801 *ipar
= _mesa_strlen (info
) + 1;
806 RELEASE_GENERIC(gen
);
809 case GL_OBJECT_SUBTYPE_ARB
:
810 case GL_OBJECT_COMPILE_STATUS_ARB
:
811 case GL_OBJECT_SHADER_SOURCE_LENGTH_ARB
:
813 GET_SHADER(sha
, obj
, "glGetObjectParameterivARB");
820 case GL_OBJECT_SUBTYPE_ARB
:
821 *ipar
= (**sha
).GetSubType (sha
);
823 case GL_OBJECT_COMPILE_STATUS_ARB
:
824 *ipar
= (**sha
).GetCompileStatus (sha
);
826 case GL_OBJECT_SHADER_SOURCE_LENGTH_ARB
:
828 const GLcharARB
*src
= (**sha
).GetSource (sha
);
833 *ipar
= _mesa_strlen (src
) + 1;
841 case GL_OBJECT_LINK_STATUS_ARB
:
842 case GL_OBJECT_VALIDATE_STATUS_ARB
:
843 case GL_OBJECT_ATTACHED_OBJECTS_ARB
:
844 case GL_OBJECT_ACTIVE_UNIFORMS_ARB
:
845 case GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB
:
847 GET_PROGRAM(pro
, obj
, "glGetObjectParameterivARB");
854 case GL_OBJECT_LINK_STATUS_ARB
:
855 *ipar
= (**pro
).GetLinkStatus (pro
);
857 case GL_OBJECT_VALIDATE_STATUS_ARB
:
858 *ipar
= (**pro
).GetValidateStatus (pro
);
860 case GL_OBJECT_ATTACHED_OBJECTS_ARB
:
861 *ipar
= (**pro
)._container
.GetAttachedCount ((I_CONTAINER
) pro
);
863 case GL_OBJECT_ACTIVE_UNIFORMS_ARB
:
864 *ipar
= _slang_get_active_uniform_count (pro
);
866 case GL_OBJECT_ACTIVE_UNIFORM_MAX_LENGTH_ARB
:
867 *ipar
= _slang_get_active_uniform_max_length (pro
);
871 RELEASE_PROGRAM(pro
);
875 _mesa_error (ctx
, GL_INVALID_ENUM
, "glGetObjectParameterivARB");
883 _mesa_GetObjectParameterfvARB (GLhandleARB obj
, GLenum pname
, GLfloat
*params
)
888 assert (sizeof (GLfloat
) == sizeof (GLint
));
890 if (_mesa_get_object_parameter (obj
, pname
, (GLvoid
*) params
, &integral
, &size
))
895 for (i
= 0; i
< size
; i
++)
896 params
[i
] = (GLfloat
) ((GLint
*) params
)[i
];
901 _mesa_GetObjectParameterivARB (GLhandleARB obj
, GLenum pname
, GLint
*params
)
906 assert (sizeof (GLfloat
) == sizeof (GLint
));
908 if (_mesa_get_object_parameter (obj
, pname
, (GLvoid
*) params
, &integral
, &size
))
913 for (i
= 0; i
< size
; i
++)
914 params
[i
] = (GLint
) ((GLfloat
*) params
)[i
];
920 * Copy string from <src> to <dst>, up to maxLength characters, returning
921 * length of <dst> in <length>.
922 * \param src the strings source
923 * \param maxLength max chars to copy
924 * \param length returns numberof chars copied
925 * \param dst the string destination
928 copy_string(const GLcharARB
*src
, GLsizei maxLength
, GLsizei
*length
,
932 for (len
= 0; len
< maxLength
- 1 && src
&& src
[len
]; len
++)
942 _mesa_GetInfoLogARB (GLhandleARB obj
, GLsizei maxLength
, GLsizei
*length
, GLcharARB
*infoLog
)
944 GET_CURRENT_CONTEXT(ctx
);
945 GET_GENERIC(gen
, obj
, "glGetInfoLogARB");
949 copy_string((**gen
).GetInfoLog (gen
), maxLength
, length
, infoLog
);
950 RELEASE_GENERIC(gen
);
955 _mesa_GetAttachedObjectsARB (GLhandleARB containerObj
, GLsizei maxCount
, GLsizei
*count
,
958 GET_CURRENT_CONTEXT(ctx
);
960 GET_CONTAINER(con
, containerObj
, "glGetAttachedObjectsARB");
964 cnt
= (**con
).GetAttachedCount (con
);
970 for (i
= 0; i
< cnt
; i
++)
972 I_GENERIC x
= (**con
).GetAttached (con
, i
);
973 obj
[i
] = (**x
).GetName (x
);
976 RELEASE_CONTAINER(con
);
981 _mesa_GetUniformLocationARB (GLhandleARB programObj
, const GLcharARB
*name
)
983 GET_CURRENT_CONTEXT(ctx
);
985 GET_LINKED_PROGRAM(pro
, programObj
, "glGetUniformLocationARB");
989 if (name
!= NULL
&& (name
[0] != 'g' || name
[1] != 'l' || name
[2] != '_'))
990 loc
= _slang_get_uniform_location (pro
, name
);
991 RELEASE_PROGRAM(pro
);
997 _mesa_GetActiveUniformARB (GLhandleARB programObj
, GLuint index
, GLsizei maxLength
, GLsizei
*length
,
998 GLint
*size
, GLenum
*type
, GLcharARB
*name
)
1000 GET_CURRENT_CONTEXT(ctx
);
1001 GET_PROGRAM(pro
, programObj
, "glGetActiveUniformARB");
1005 if (index
< _slang_get_active_uniform_count (pro
))
1006 _slang_get_active_uniform (pro
, index
, maxLength
, length
, size
, type
, name
);
1008 _mesa_error (ctx
, GL_INVALID_VALUE
, "glGetActiveUniformARB");
1009 RELEASE_PROGRAM(pro
);
1014 _mesa_GetUniformfvARB (GLhandleARB programObj
, GLint location
, GLfloat
*params
)
1016 GET_CURRENT_CONTEXT(ctx
);
1017 GET_LINKED_PROGRAM(pro
, programObj
, "glGetUniformfvARB");
1022 RELEASE_PROGRAM(pro
);
1027 _mesa_GetUniformivARB (GLhandleARB programObj
, GLint location
, GLint
*params
)
1029 GET_CURRENT_CONTEXT(ctx
);
1030 GET_LINKED_PROGRAM(pro
, programObj
, "glGetUniformivARB");
1035 RELEASE_PROGRAM(pro
);
1040 _mesa_GetShaderSourceARB (GLhandleARB obj
, GLsizei maxLength
, GLsizei
*length
, GLcharARB
*source
)
1042 GET_CURRENT_CONTEXT(ctx
);
1043 GET_SHADER(sha
, obj
, "glGetShaderSourceARB");
1047 copy_string((**sha
).GetSource (sha
), maxLength
, length
, source
);
1048 RELEASE_SHADER(sha
);
1052 /* GL_ARB_vertex_shader */
1055 _mesa_BindAttribLocationARB (GLhandleARB programObj
, GLuint index
, const GLcharARB
*name
)
1057 GET_CURRENT_CONTEXT(ctx
);
1058 GET_PROGRAM(pro
, programObj
, "glBindAttribLocationARB");
1062 if (name
!= NULL
&& (name
[0] != 'g' || name
[1] != 'l' || name
[2] != '_'))
1066 RELEASE_PROGRAM(pro
);
1071 _mesa_GetActiveAttribARB (GLhandleARB programObj
, GLuint index
, GLsizei maxLength
, GLsizei
*length
,
1072 GLint
*size
, GLenum
*type
, GLcharARB
*name
)
1074 GET_CURRENT_CONTEXT(ctx
);
1075 GET_PROGRAM(pro
, programObj
, "glGetActiveAttribARB");
1080 RELEASE_PROGRAM(pro
);
1085 _mesa_GetAttribLocationARB (GLhandleARB programObj
, const GLcharARB
*name
)
1087 GET_CURRENT_CONTEXT(ctx
);
1089 GET_PROGRAM(pro
, programObj
, "glGetAttribLocationARB");
1093 if (name
!= NULL
&& (name
[0] != 'g' || name
[1] != 'l' || name
[2] != '_'))
1097 RELEASE_PROGRAM(pro
);
1103 _mesa_init_shaderobjects (GLcontext
*ctx
)
1105 ctx
->ShaderObjects
.CurrentProgram
= NULL
;
1106 ctx
->ShaderObjects
._FragmentShaderPresent
= GL_FALSE
;
1107 ctx
->ShaderObjects
._VertexShaderPresent
= GL_FALSE
;
1109 _mesa_init_shaderobjects_3dlabs (ctx
);