2 * Mesa 3-D graphics library
5 * Copyright (C) 2004-2008 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 * Implementation of GLSL-related API functions
33 * 1. Check that the right error code is generated for all _mesa_error() calls.
34 * 2. Insert FLUSH_VERTICES calls in various places
38 #include "main/glheader.h"
39 #include "main/context.h"
40 #include "main/hash.h"
41 #include "main/macros.h"
42 #include "shader/program.h"
43 #include "shader/prog_parameter.h"
44 #include "shader/prog_print.h"
45 #include "shader/prog_statevars.h"
46 #include "shader/prog_uniform.h"
47 #include "shader/shader_api.h"
48 #include "shader/slang/slang_compile.h"
49 #include "shader/slang/slang_link.h"
50 #include "glapi/dispatch.h"
53 #ifndef GL_PROGRAM_BINARY_LENGTH_OES
54 #define GL_PROGRAM_BINARY_LENGTH_OES 0x8741
59 * Allocate a new gl_shader_program object, initialize it.
61 static struct gl_shader_program
*
62 _mesa_new_shader_program(GLcontext
*ctx
, GLuint name
)
64 struct gl_shader_program
*shProg
;
65 shProg
= CALLOC_STRUCT(gl_shader_program
);
67 shProg
->Type
= GL_SHADER_PROGRAM_MESA
;
70 shProg
->Attributes
= _mesa_new_parameter_list();
77 * Clear (free) the shader program state that gets produced by linking.
80 _mesa_clear_shader_program_data(GLcontext
*ctx
,
81 struct gl_shader_program
*shProg
)
83 _mesa_reference_vertprog(ctx
, &shProg
->VertexProgram
, NULL
);
84 _mesa_reference_fragprog(ctx
, &shProg
->FragmentProgram
, NULL
);
86 if (shProg
->Uniforms
) {
87 _mesa_free_uniform_list(shProg
->Uniforms
);
88 shProg
->Uniforms
= NULL
;
91 if (shProg
->Varying
) {
92 _mesa_free_parameter_list(shProg
->Varying
);
93 shProg
->Varying
= NULL
;
99 * Free all the data that hangs off a shader program object, but not the
103 _mesa_free_shader_program_data(GLcontext
*ctx
,
104 struct gl_shader_program
*shProg
)
108 assert(shProg
->Type
== GL_SHADER_PROGRAM_MESA
);
110 _mesa_clear_shader_program_data(ctx
, shProg
);
112 if (shProg
->Attributes
) {
113 _mesa_free_parameter_list(shProg
->Attributes
);
114 shProg
->Attributes
= NULL
;
118 for (i
= 0; i
< shProg
->NumShaders
; i
++) {
119 _mesa_reference_shader(ctx
, &shProg
->Shaders
[i
], NULL
);
121 shProg
->NumShaders
= 0;
123 if (shProg
->Shaders
) {
124 _mesa_free(shProg
->Shaders
);
125 shProg
->Shaders
= NULL
;
128 if (shProg
->InfoLog
) {
129 _mesa_free(shProg
->InfoLog
);
130 shProg
->InfoLog
= NULL
;
136 * Free/delete a shader program object.
139 _mesa_free_shader_program(GLcontext
*ctx
, struct gl_shader_program
*shProg
)
141 _mesa_free_shader_program_data(ctx
, shProg
);
148 * Set ptr to point to shProg.
149 * If ptr is pointing to another object, decrement its refcount (and delete
150 * if refcount hits zero).
151 * Then set ptr to point to shProg, incrementing its refcount.
153 /* XXX this could be static */
155 _mesa_reference_shader_program(GLcontext
*ctx
,
156 struct gl_shader_program
**ptr
,
157 struct gl_shader_program
*shProg
)
160 if (*ptr
== shProg
) {
165 /* Unreference the old shader program */
166 GLboolean deleteFlag
= GL_FALSE
;
167 struct gl_shader_program
*old
= *ptr
;
169 ASSERT(old
->RefCount
> 0);
172 printf("ShaderProgram %p ID=%u RefCount-- to %d\n",
173 (void *) old
, old
->Name
, old
->RefCount
);
175 deleteFlag
= (old
->RefCount
== 0);
178 _mesa_HashRemove(ctx
->Shared
->ShaderObjects
, old
->Name
);
179 _mesa_free_shader_program(ctx
, old
);
189 printf("ShaderProgram %p ID=%u RefCount++ to %d\n",
190 (void *) shProg
, shProg
->Name
, shProg
->RefCount
);
198 * Lookup a GLSL program object.
200 struct gl_shader_program
*
201 _mesa_lookup_shader_program(GLcontext
*ctx
, GLuint name
)
203 struct gl_shader_program
*shProg
;
205 shProg
= (struct gl_shader_program
*)
206 _mesa_HashLookup(ctx
->Shared
->ShaderObjects
, name
);
207 /* Note that both gl_shader and gl_shader_program objects are kept
208 * in the same hash table. Check the object's type to be sure it's
209 * what we're expecting.
211 if (shProg
&& shProg
->Type
!= GL_SHADER_PROGRAM_MESA
) {
221 * As above, but record an error if program is not found.
223 static struct gl_shader_program
*
224 _mesa_lookup_shader_program_err(GLcontext
*ctx
, GLuint name
,
228 _mesa_error(ctx
, GL_INVALID_VALUE
, caller
);
232 struct gl_shader_program
*shProg
= (struct gl_shader_program
*)
233 _mesa_HashLookup(ctx
->Shared
->ShaderObjects
, name
);
235 _mesa_error(ctx
, GL_INVALID_VALUE
, caller
);
238 if (shProg
->Type
!= GL_SHADER_PROGRAM_MESA
) {
239 _mesa_error(ctx
, GL_INVALID_OPERATION
, caller
);
250 * Allocate a new gl_shader object, initialize it.
253 _mesa_new_shader(GLcontext
*ctx
, GLuint name
, GLenum type
)
255 struct gl_shader
*shader
;
256 assert(type
== GL_FRAGMENT_SHADER
|| type
== GL_VERTEX_SHADER
);
257 shader
= CALLOC_STRUCT(gl_shader
);
261 shader
->RefCount
= 1;
268 _mesa_free_shader(GLcontext
*ctx
, struct gl_shader
*sh
)
271 _mesa_free((void *) sh
->Source
);
273 _mesa_free(sh
->InfoLog
);
274 _mesa_reference_program(ctx
, &sh
->Program
, NULL
);
280 * Set ptr to point to sh.
281 * If ptr is pointing to another shader, decrement its refcount (and delete
282 * if refcount hits zero).
283 * Then set ptr to point to sh, incrementing its refcount.
285 /* XXX this could be static */
287 _mesa_reference_shader(GLcontext
*ctx
, struct gl_shader
**ptr
,
288 struct gl_shader
*sh
)
296 /* Unreference the old shader */
297 GLboolean deleteFlag
= GL_FALSE
;
298 struct gl_shader
*old
= *ptr
;
300 ASSERT(old
->RefCount
> 0);
302 /*printf("SHADER DECR %p (%d) to %d\n",
303 (void*) old, old->Name, old->RefCount);*/
304 deleteFlag
= (old
->RefCount
== 0);
307 _mesa_HashRemove(ctx
->Shared
->ShaderObjects
, old
->Name
);
308 _mesa_free_shader(ctx
, old
);
318 /*printf("SHADER INCR %p (%d) to %d\n",
319 (void*) sh, sh->Name, sh->RefCount);*/
326 * Lookup a GLSL shader object.
329 _mesa_lookup_shader(GLcontext
*ctx
, GLuint name
)
332 struct gl_shader
*sh
= (struct gl_shader
*)
333 _mesa_HashLookup(ctx
->Shared
->ShaderObjects
, name
);
334 /* Note that both gl_shader and gl_shader_program objects are kept
335 * in the same hash table. Check the object's type to be sure it's
336 * what we're expecting.
338 if (sh
&& sh
->Type
== GL_SHADER_PROGRAM_MESA
) {
348 * As above, but record an error if shader is not found.
350 static struct gl_shader
*
351 _mesa_lookup_shader_err(GLcontext
*ctx
, GLuint name
, const char *caller
)
354 _mesa_error(ctx
, GL_INVALID_VALUE
, caller
);
358 struct gl_shader
*sh
= (struct gl_shader
*)
359 _mesa_HashLookup(ctx
->Shared
->ShaderObjects
, name
);
361 _mesa_error(ctx
, GL_INVALID_VALUE
, caller
);
364 if (sh
->Type
== GL_SHADER_PROGRAM_MESA
) {
365 _mesa_error(ctx
, GL_INVALID_OPERATION
, caller
);
374 * Return mask of GLSL_x flags by examining the MESA_GLSL env var.
377 get_shader_flags(void)
379 GLbitfield flags
= 0x0;
380 const char *env
= _mesa_getenv("MESA_GLSL");
383 if (_mesa_strstr(env
, "dump"))
385 if (_mesa_strstr(env
, "log"))
387 if (_mesa_strstr(env
, "nopt"))
388 flags
|= GLSL_NO_OPT
;
389 else if (_mesa_strstr(env
, "opt"))
391 if (_mesa_strstr(env
, "uniform"))
392 flags
|= GLSL_UNIFORMS
;
400 * Initialize context's shader state.
403 _mesa_init_shader_state(GLcontext
* ctx
)
405 /* Device drivers may override these to control what kind of instructions
406 * are generated by the GLSL compiler.
408 ctx
->Shader
.EmitHighLevelInstructions
= GL_TRUE
;
409 ctx
->Shader
.EmitCondCodes
= GL_FALSE
;/*GL_TRUE;*/ /* XXX probably want GL_FALSE... */
410 ctx
->Shader
.EmitComments
= GL_FALSE
;
411 ctx
->Shader
.Flags
= get_shader_flags();
416 * Free the per-context shader-related state.
419 _mesa_free_shader_state(GLcontext
*ctx
)
421 _mesa_reference_shader_program(ctx
, &ctx
->Shader
.CurrentProgram
, NULL
);
426 * Copy string from <src> to <dst>, up to maxLength characters, returning
427 * length of <dst> in <length>.
428 * \param src the strings source
429 * \param maxLength max chars to copy
430 * \param length returns number of chars copied
431 * \param dst the string destination
434 copy_string(GLchar
*dst
, GLsizei maxLength
, GLsizei
*length
, const GLchar
*src
)
437 for (len
= 0; len
< maxLength
- 1 && src
&& src
[len
]; len
++)
447 _mesa_is_program(GLcontext
*ctx
, GLuint name
)
449 struct gl_shader_program
*shProg
= _mesa_lookup_shader_program(ctx
, name
);
450 return shProg
? GL_TRUE
: GL_FALSE
;
455 _mesa_is_shader(GLcontext
*ctx
, GLuint name
)
457 struct gl_shader
*shader
= _mesa_lookup_shader(ctx
, name
);
458 return shader
? GL_TRUE
: GL_FALSE
;
463 * Called via ctx->Driver.AttachShader()
466 _mesa_attach_shader(GLcontext
*ctx
, GLuint program
, GLuint shader
)
468 struct gl_shader_program
*shProg
;
469 struct gl_shader
*sh
;
472 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glAttachShader");
476 sh
= _mesa_lookup_shader_err(ctx
, shader
, "glAttachShader");
481 n
= shProg
->NumShaders
;
482 for (i
= 0; i
< n
; i
++) {
483 if (shProg
->Shaders
[i
] == sh
) {
484 /* The shader is already attched to this program. The
485 * GL_ARB_shader_objects spec says:
487 * "The error INVALID_OPERATION is generated by AttachObjectARB
488 * if <obj> is already attached to <containerObj>."
490 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glAttachShader");
496 shProg
->Shaders
= (struct gl_shader
**)
497 _mesa_realloc(shProg
->Shaders
,
498 n
* sizeof(struct gl_shader
*),
499 (n
+ 1) * sizeof(struct gl_shader
*));
500 if (!shProg
->Shaders
) {
501 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glAttachShader");
506 shProg
->Shaders
[n
] = NULL
; /* since realloc() didn't zero the new space */
507 _mesa_reference_shader(ctx
, &shProg
->Shaders
[n
], sh
);
508 shProg
->NumShaders
++;
513 _mesa_get_attrib_location(GLcontext
*ctx
, GLuint program
,
516 struct gl_shader_program
*shProg
517 = _mesa_lookup_shader_program_err(ctx
, program
, "glGetAttribLocation");
523 if (!shProg
->LinkStatus
) {
524 _mesa_error(ctx
, GL_INVALID_OPERATION
,
525 "glGetAttribLocation(program not linked)");
532 if (shProg
->VertexProgram
) {
533 const struct gl_program_parameter_list
*attribs
=
534 shProg
->VertexProgram
->Base
.Attributes
;
536 GLint i
= _mesa_lookup_parameter_index(attribs
, -1, name
);
538 return attribs
->Parameters
[i
].StateIndexes
[0];
547 _mesa_bind_attrib_location(GLcontext
*ctx
, GLuint program
, GLuint index
,
550 struct gl_shader_program
*shProg
;
551 const GLint size
= -1; /* unknown size */
553 GLenum datatype
= GL_FLOAT_VEC4
;
555 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
556 "glBindAttribLocation");
564 if (strncmp(name
, "gl_", 3) == 0) {
565 _mesa_error(ctx
, GL_INVALID_OPERATION
,
566 "glBindAttribLocation(illegal name)");
570 if (index
>= ctx
->Const
.VertexProgram
.MaxAttribs
) {
571 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindAttribLocation(index)");
575 if (shProg
->LinkStatus
) {
576 /* get current index/location for the attribute */
577 oldIndex
= _mesa_get_attrib_location(ctx
, program
, name
);
583 /* this will replace the current value if it's already in the list */
584 i
= _mesa_add_attribute(shProg
->Attributes
, name
, size
, datatype
, index
);
586 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindAttribLocation");
591 * Note that this attribute binding won't go into effect until
592 * glLinkProgram is called again.
598 _mesa_create_shader(GLcontext
*ctx
, GLenum type
)
600 struct gl_shader
*sh
;
603 name
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->ShaderObjects
, 1);
606 case GL_FRAGMENT_SHADER
:
607 case GL_VERTEX_SHADER
:
608 sh
= _mesa_new_shader(ctx
, name
, type
);
611 _mesa_error(ctx
, GL_INVALID_ENUM
, "CreateShader(type)");
615 _mesa_HashInsert(ctx
->Shared
->ShaderObjects
, name
, sh
);
622 _mesa_create_program(GLcontext
*ctx
)
625 struct gl_shader_program
*shProg
;
627 name
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->ShaderObjects
, 1);
628 shProg
= _mesa_new_shader_program(ctx
, name
);
630 _mesa_HashInsert(ctx
->Shared
->ShaderObjects
, name
, shProg
);
632 assert(shProg
->RefCount
== 1);
639 * Named w/ "2" to indicate OpenGL 2.x vs GL_ARB_fragment_programs's
643 _mesa_delete_program2(GLcontext
*ctx
, GLuint name
)
646 * NOTE: deleting shaders/programs works a bit differently than
647 * texture objects (and buffer objects, etc). Shader/program
648 * handles/IDs exist in the hash table until the object is really
649 * deleted (refcount==0). With texture objects, the handle/ID is
650 * removed from the hash table in glDeleteTextures() while the tex
651 * object itself might linger until its refcount goes to zero.
653 struct gl_shader_program
*shProg
;
655 shProg
= _mesa_lookup_shader_program_err(ctx
, name
, "glDeleteProgram");
659 shProg
->DeletePending
= GL_TRUE
;
661 /* effectively, decr shProg's refcount */
662 _mesa_reference_shader_program(ctx
, &shProg
, NULL
);
667 _mesa_delete_shader(GLcontext
*ctx
, GLuint shader
)
669 struct gl_shader
*sh
;
671 sh
= _mesa_lookup_shader_err(ctx
, shader
, "glDeleteShader");
675 sh
->DeletePending
= GL_TRUE
;
677 /* effectively, decr sh's refcount */
678 _mesa_reference_shader(ctx
, &sh
, NULL
);
683 _mesa_detach_shader(GLcontext
*ctx
, GLuint program
, GLuint shader
)
685 struct gl_shader_program
*shProg
;
689 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glDetachShader");
693 n
= shProg
->NumShaders
;
695 for (i
= 0; i
< n
; i
++) {
696 if (shProg
->Shaders
[i
]->Name
== shader
) {
698 struct gl_shader
**newList
;
701 _mesa_reference_shader(ctx
, &shProg
->Shaders
[i
], NULL
);
703 /* alloc new, smaller array */
704 newList
= (struct gl_shader
**)
705 _mesa_malloc((n
- 1) * sizeof(struct gl_shader
*));
707 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glDetachShader");
710 for (j
= 0; j
< i
; j
++) {
711 newList
[j
] = shProg
->Shaders
[j
];
714 newList
[j
++] = shProg
->Shaders
[i
];
715 _mesa_free(shProg
->Shaders
);
717 shProg
->Shaders
= newList
;
718 shProg
->NumShaders
= n
- 1;
723 for (j
= 0; j
< shProg
->NumShaders
; j
++) {
724 assert(shProg
->Shaders
[j
]->Type
== GL_VERTEX_SHADER
||
725 shProg
->Shaders
[j
]->Type
== GL_FRAGMENT_SHADER
);
726 assert(shProg
->Shaders
[j
]->RefCount
> 0);
738 if (_mesa_is_shader(ctx
, shader
))
739 err
= GL_INVALID_OPERATION
;
740 else if (_mesa_is_program(ctx
, shader
))
741 err
= GL_INVALID_OPERATION
;
743 err
= GL_INVALID_VALUE
;
744 _mesa_error(ctx
, err
, "glDetachProgram(shader)");
751 sizeof_glsl_type(GLenum type
)
760 case GL_SAMPLER_CUBE
:
761 case GL_SAMPLER_1D_SHADOW
:
762 case GL_SAMPLER_2D_SHADOW
:
763 case GL_SAMPLER_2D_RECT_ARB
:
764 case GL_SAMPLER_2D_RECT_SHADOW_ARB
:
765 case GL_SAMPLER_1D_ARRAY_SHADOW_EXT
:
766 case GL_SAMPLER_2D_ARRAY_SHADOW_EXT
:
767 case GL_SAMPLER_CUBE_SHADOW_EXT
:
782 case GL_FLOAT_MAT2x3
:
783 case GL_FLOAT_MAT2x4
:
784 return 8; /* two float[4] vectors */
786 case GL_FLOAT_MAT3x2
:
787 case GL_FLOAT_MAT3x4
:
788 return 12; /* three float[4] vectors */
790 case GL_FLOAT_MAT4x2
:
791 case GL_FLOAT_MAT4x3
:
792 return 16; /* four float[4] vectors */
794 _mesa_problem(NULL
, "Invalid type in sizeof_glsl_type()");
801 is_boolean_type(GLenum type
)
816 is_integer_type(GLenum type
)
831 _mesa_get_active_attrib(GLcontext
*ctx
, GLuint program
, GLuint index
,
832 GLsizei maxLength
, GLsizei
*length
, GLint
*size
,
833 GLenum
*type
, GLchar
*nameOut
)
835 const struct gl_program_parameter_list
*attribs
= NULL
;
836 struct gl_shader_program
*shProg
;
838 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glGetActiveAttrib");
842 if (shProg
->VertexProgram
)
843 attribs
= shProg
->VertexProgram
->Base
.Attributes
;
845 if (!attribs
|| index
>= attribs
->NumParameters
) {
846 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveAttrib(index)");
850 copy_string(nameOut
, maxLength
, length
, attribs
->Parameters
[index
].Name
);
853 *size
= attribs
->Parameters
[index
].Size
854 / sizeof_glsl_type(attribs
->Parameters
[index
].DataType
);
857 *type
= attribs
->Parameters
[index
].DataType
;
861 static struct gl_program_parameter
*
862 get_uniform_parameter(const struct gl_shader_program
*shProg
, GLuint index
)
864 const struct gl_program
*prog
;
867 progPos
= shProg
->Uniforms
->Uniforms
[index
].VertPos
;
869 prog
= &shProg
->VertexProgram
->Base
;
872 progPos
= shProg
->Uniforms
->Uniforms
[index
].FragPos
;
874 prog
= &shProg
->FragmentProgram
->Base
;
878 if (!prog
|| progPos
< 0)
879 return NULL
; /* should never happen */
881 return &prog
->Parameters
->Parameters
[progPos
];
886 * Called via ctx->Driver.GetActiveUniform().
889 _mesa_get_active_uniform(GLcontext
*ctx
, GLuint program
, GLuint index
,
890 GLsizei maxLength
, GLsizei
*length
, GLint
*size
,
891 GLenum
*type
, GLchar
*nameOut
)
893 const struct gl_shader_program
*shProg
;
894 const struct gl_program
*prog
;
897 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glGetActiveUniform");
901 if (!shProg
->Uniforms
|| index
>= shProg
->Uniforms
->NumUniforms
) {
902 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetActiveUniform(index)");
906 progPos
= shProg
->Uniforms
->Uniforms
[index
].VertPos
;
908 prog
= &shProg
->VertexProgram
->Base
;
911 progPos
= shProg
->Uniforms
->Uniforms
[index
].FragPos
;
913 prog
= &shProg
->FragmentProgram
->Base
;
917 if (!prog
|| progPos
< 0)
918 return; /* should never happen */
921 copy_string(nameOut
, maxLength
, length
,
922 prog
->Parameters
->Parameters
[progPos
].Name
);
924 *size
= prog
->Parameters
->Parameters
[progPos
].Size
925 / sizeof_glsl_type(prog
->Parameters
->Parameters
[progPos
].DataType
);
927 *type
= prog
->Parameters
->Parameters
[progPos
].DataType
;
932 * Called via ctx->Driver.GetAttachedShaders().
935 _mesa_get_attached_shaders(GLcontext
*ctx
, GLuint program
, GLsizei maxCount
,
936 GLsizei
*count
, GLuint
*obj
)
938 struct gl_shader_program
*shProg
=
939 _mesa_lookup_shader_program_err(ctx
, program
, "glGetAttachedShaders");
942 for (i
= 0; i
< (GLuint
) maxCount
&& i
< shProg
->NumShaders
; i
++) {
943 obj
[i
] = shProg
->Shaders
[i
]->Name
;
952 _mesa_get_handle(GLcontext
*ctx
, GLenum pname
)
956 if (pname
== GL_PROGRAM_OBJECT_ARB
) {
957 CALL_GetIntegerv(ctx
->Exec
, (GL_CURRENT_PROGRAM
, &handle
));
959 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetHandleARB");
967 _mesa_get_programiv(GLcontext
*ctx
, GLuint program
,
968 GLenum pname
, GLint
*params
)
970 const struct gl_program_parameter_list
*attribs
;
971 struct gl_shader_program
*shProg
972 = _mesa_lookup_shader_program(ctx
, program
);
975 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramiv(program)");
979 if (shProg
->VertexProgram
)
980 attribs
= shProg
->VertexProgram
->Base
.Attributes
;
985 case GL_DELETE_STATUS
:
986 *params
= shProg
->DeletePending
;
989 *params
= shProg
->LinkStatus
;
991 case GL_VALIDATE_STATUS
:
992 *params
= shProg
->Validated
;
994 case GL_INFO_LOG_LENGTH
:
995 *params
= shProg
->InfoLog
? strlen(shProg
->InfoLog
) + 1 : 0;
997 case GL_ATTACHED_SHADERS
:
998 *params
= shProg
->NumShaders
;
1000 case GL_ACTIVE_ATTRIBUTES
:
1001 *params
= attribs
? attribs
->NumParameters
: 0;
1003 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
:
1004 *params
= _mesa_longest_parameter_name(attribs
, PROGRAM_INPUT
) + 1;
1006 case GL_ACTIVE_UNIFORMS
:
1007 *params
= shProg
->Uniforms
? shProg
->Uniforms
->NumUniforms
: 0;
1009 case GL_ACTIVE_UNIFORM_MAX_LENGTH
:
1010 *params
= _mesa_longest_uniform_name(shProg
->Uniforms
);
1012 (*params
)++; /* add one for terminating zero */
1014 case GL_PROGRAM_BINARY_LENGTH_OES
:
1018 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramiv(pname)");
1025 _mesa_get_shaderiv(GLcontext
*ctx
, GLuint name
, GLenum pname
, GLint
*params
)
1027 struct gl_shader
*shader
= _mesa_lookup_shader_err(ctx
, name
, "glGetShaderiv");
1034 case GL_SHADER_TYPE
:
1035 *params
= shader
->Type
;
1037 case GL_DELETE_STATUS
:
1038 *params
= shader
->DeletePending
;
1040 case GL_COMPILE_STATUS
:
1041 *params
= shader
->CompileStatus
;
1043 case GL_INFO_LOG_LENGTH
:
1044 *params
= shader
->InfoLog
? strlen(shader
->InfoLog
) + 1 : 0;
1046 case GL_SHADER_SOURCE_LENGTH
:
1047 *params
= shader
->Source
? strlen((char *) shader
->Source
) + 1 : 0;
1050 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetShaderiv(pname)");
1057 _mesa_get_program_info_log(GLcontext
*ctx
, GLuint program
, GLsizei bufSize
,
1058 GLsizei
*length
, GLchar
*infoLog
)
1060 struct gl_shader_program
*shProg
1061 = _mesa_lookup_shader_program(ctx
, program
);
1063 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramInfoLog(program)");
1066 copy_string(infoLog
, bufSize
, length
, shProg
->InfoLog
);
1071 _mesa_get_shader_info_log(GLcontext
*ctx
, GLuint shader
, GLsizei bufSize
,
1072 GLsizei
*length
, GLchar
*infoLog
)
1074 struct gl_shader
*sh
= _mesa_lookup_shader(ctx
, shader
);
1076 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetShaderInfoLog(shader)");
1079 copy_string(infoLog
, bufSize
, length
, sh
->InfoLog
);
1084 * Called via ctx->Driver.GetShaderSource().
1087 _mesa_get_shader_source(GLcontext
*ctx
, GLuint shader
, GLsizei maxLength
,
1088 GLsizei
*length
, GLchar
*sourceOut
)
1090 struct gl_shader
*sh
;
1091 sh
= _mesa_lookup_shader_err(ctx
, shader
, "glGetShaderSource");
1095 copy_string(sourceOut
, maxLength
, length
, sh
->Source
);
1100 get_matrix_dims(GLenum type
, GLint
*rows
, GLint
*cols
)
1106 case GL_FLOAT_MAT2x3
:
1110 case GL_FLOAT_MAT2x4
:
1118 case GL_FLOAT_MAT3x2
:
1122 case GL_FLOAT_MAT3x4
:
1130 case GL_FLOAT_MAT4x2
:
1134 case GL_FLOAT_MAT4x3
:
1145 * Determine the number of rows and columns occupied by a uniform
1146 * according to its datatype. For non-matrix types (such as GL_FLOAT_VEC4),
1147 * the number of rows = 1 and cols = number of elements in the vector.
1150 get_uniform_rows_cols(const struct gl_program_parameter
*p
,
1151 GLint
*rows
, GLint
*cols
)
1153 get_matrix_dims(p
->DataType
, rows
, cols
);
1154 if (*rows
== 0 && *cols
== 0) {
1155 /* not a matrix type, probably a float or vector */
1161 *rows
= p
->Size
/ 4 + 1;
1162 if (p
->Size
% 4 == 0)
1165 *cols
= p
->Size
% 4;
1171 #define MAX_UNIFORM_ELEMENTS 16
1174 * Helper for GetUniformfv(), GetUniformiv()
1175 * Returns number of elements written to 'params' output.
1178 get_uniformfv(GLcontext
*ctx
, GLuint program
, GLint location
,
1181 struct gl_shader_program
*shProg
1182 = _mesa_lookup_shader_program_err(ctx
, program
, "glGetUniform[if]v");
1184 if (shProg
->Uniforms
&&
1185 location
>= 0 && location
< (GLint
) shProg
->Uniforms
->NumUniforms
) {
1187 const struct gl_program
*prog
= NULL
;
1189 progPos
= shProg
->Uniforms
->Uniforms
[location
].VertPos
;
1191 prog
= &shProg
->VertexProgram
->Base
;
1194 progPos
= shProg
->Uniforms
->Uniforms
[location
].FragPos
;
1196 prog
= &shProg
->FragmentProgram
->Base
;
1202 const struct gl_program_parameter
*p
=
1203 &prog
->Parameters
->Parameters
[progPos
];
1204 GLint rows
, cols
, i
, j
, k
;
1206 /* See uniformiv() below */
1207 assert(p
->Size
<= MAX_UNIFORM_ELEMENTS
);
1209 get_uniform_rows_cols(p
, &rows
, &cols
);
1212 for (i
= 0; i
< rows
; i
++) {
1213 for (j
= 0; j
< cols
; j
++ ) {
1214 params
[k
++] = prog
->Parameters
->ParameterValues
[progPos
+i
][j
];
1222 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetUniformfv(location)");
1230 * Called via ctx->Driver.GetUniformfv().
1233 _mesa_get_uniformfv(GLcontext
*ctx
, GLuint program
, GLint location
,
1236 (void) get_uniformfv(ctx
, program
, location
, params
);
1241 * Called via ctx->Driver.GetUniformiv().
1244 _mesa_get_uniformiv(GLcontext
*ctx
, GLuint program
, GLint location
,
1247 GLfloat fparams
[MAX_UNIFORM_ELEMENTS
];
1248 GLuint n
= get_uniformfv(ctx
, program
, location
, fparams
);
1250 assert(n
<= MAX_UNIFORM_ELEMENTS
);
1251 for (i
= 0; i
< n
; i
++) {
1252 params
[i
] = (GLint
) fparams
[i
];
1258 * The value returned by GetUniformLocation actually encodes two things:
1259 * 1. the index into the prog->Uniforms[] array for the uniform
1260 * 2. an offset in the prog->ParameterValues[] array for specifying array
1261 * elements or structure fields.
1262 * This function merges those two values.
1265 merge_location_offset(GLint
*location
, GLint offset
)
1267 *location
= *location
| (offset
<< 16);
1272 * Seperate the uniform location and parameter offset. See above.
1275 split_location_offset(GLint
*location
, GLint
*offset
)
1277 *offset
= (*location
>> 16);
1278 *location
= *location
& 0xffff;
1283 * Called via ctx->Driver.GetUniformLocation().
1285 * The return value will encode two values, the uniform location and an
1286 * offset (used for arrays, structs).
1289 _mesa_get_uniform_location(GLcontext
*ctx
, GLuint program
, const GLchar
*name
)
1291 GLint offset
= 0, location
= -1;
1293 struct gl_shader_program
*shProg
=
1294 _mesa_lookup_shader_program_err(ctx
, program
, "glGetUniformLocation");
1299 if (shProg
->LinkStatus
== GL_FALSE
) {
1300 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetUniformfv(program)");
1304 /* XXX we should return -1 if the uniform was declared, but not
1308 /* XXX we need to be able to parse uniform names for structs and arrays
1315 /* handle 1-dimension arrays here... */
1316 char *c
= strchr(name
, '[');
1318 /* truncate name at [ */
1319 const GLint len
= c
- name
;
1320 GLchar
*newName
= _mesa_malloc(len
+ 1);
1322 return -1; /* out of mem */
1323 _mesa_memcpy(newName
, name
, len
);
1326 location
= _mesa_lookup_uniform(shProg
->Uniforms
, newName
);
1327 if (location
>= 0) {
1328 const GLint element
= _mesa_atoi(c
+ 1);
1330 /* get type of the uniform array element */
1331 struct gl_program_parameter
*p
;
1332 p
= get_uniform_parameter(shProg
, location
);
1335 get_matrix_dims(p
->DataType
, &rows
, &cols
);
1338 offset
= element
* rows
;
1343 _mesa_free(newName
);
1348 location
= _mesa_lookup_uniform(shProg
->Uniforms
, name
);
1351 if (location
>= 0) {
1352 merge_location_offset(&location
, offset
);
1361 * Called via ctx->Driver.ShaderSource()
1364 _mesa_shader_source(GLcontext
*ctx
, GLuint shader
, const GLchar
*source
)
1366 struct gl_shader
*sh
;
1368 sh
= _mesa_lookup_shader_err(ctx
, shader
, "glShaderSource");
1372 /* free old shader source string and install new one */
1374 _mesa_free((void *) sh
->Source
);
1376 sh
->Source
= source
;
1377 sh
->CompileStatus
= GL_FALSE
;
1382 * Called via ctx->Driver.CompileShader()
1385 _mesa_compile_shader(GLcontext
*ctx
, GLuint shaderObj
)
1387 struct gl_shader
*sh
;
1389 sh
= _mesa_lookup_shader_err(ctx
, shaderObj
, "glCompileShader");
1393 /* this call will set the sh->CompileStatus field to indicate if
1394 * compilation was successful.
1396 (void) _slang_compile(ctx
, sh
);
1401 * Called via ctx->Driver.LinkProgram()
1404 _mesa_link_program(GLcontext
*ctx
, GLuint program
)
1406 struct gl_shader_program
*shProg
;
1408 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glLinkProgram");
1412 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
1414 _slang_link(ctx
, program
, shProg
);
1419 * Called via ctx->Driver.UseProgram()
1422 _mesa_use_program(GLcontext
*ctx
, GLuint program
)
1424 struct gl_shader_program
*shProg
;
1426 if (ctx
->Shader
.CurrentProgram
&&
1427 ctx
->Shader
.CurrentProgram
->Name
== program
) {
1432 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
1435 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glUseProgram");
1439 if (!shProg
->LinkStatus
) {
1440 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUseProgram");
1448 _mesa_reference_shader_program(ctx
, &ctx
->Shader
.CurrentProgram
, shProg
);
1454 * Update the vertex/fragment program's TexturesUsed array.
1456 * This needs to be called after glUniform(set sampler var) is called.
1457 * A call to glUniform(samplerVar, value) causes a sampler to point to a
1458 * particular texture unit. We know the sampler's texture target
1459 * (1D/2D/3D/etc) from compile time but the sampler's texture unit is
1460 * set by glUniform() calls.
1462 * So, scan the program->SamplerUnits[] and program->SamplerTargets[]
1463 * information to update the prog->TexturesUsed[] values.
1464 * Each value of TexturesUsed[unit] is one of zero, TEXTURE_1D_INDEX,
1465 * TEXTURE_2D_INDEX, TEXTURE_3D_INDEX, etc.
1466 * We'll use that info for state validation before rendering.
1469 _mesa_update_shader_textures_used(struct gl_program
*prog
)
1473 memset(prog
->TexturesUsed
, 0, sizeof(prog
->TexturesUsed
));
1475 for (s
= 0; s
< MAX_SAMPLERS
; s
++) {
1476 if (prog
->SamplersUsed
& (1 << s
)) {
1477 GLuint u
= prog
->SamplerUnits
[s
];
1478 GLuint t
= prog
->SamplerTargets
[s
];
1479 assert(u
< MAX_TEXTURE_IMAGE_UNITS
);
1480 prog
->TexturesUsed
[u
] |= (1 << t
);
1487 is_sampler_type(GLenum type
)
1493 case GL_SAMPLER_CUBE
:
1494 case GL_SAMPLER_1D_SHADOW
:
1495 case GL_SAMPLER_2D_SHADOW
:
1496 case GL_SAMPLER_2D_RECT_ARB
:
1497 case GL_SAMPLER_2D_RECT_SHADOW_ARB
:
1498 case GL_SAMPLER_1D_ARRAY_EXT
:
1499 case GL_SAMPLER_2D_ARRAY_EXT
:
1508 * Check if the type given by userType is allowed to set a uniform of the
1509 * target type. Generally, equivalence is required, but setting Boolean
1510 * uniforms can be done with glUniformiv or glUniformfv.
1513 compatible_types(GLenum userType
, GLenum targetType
)
1515 if (userType
== targetType
)
1518 if (targetType
== GL_BOOL
&& (userType
== GL_FLOAT
|| userType
== GL_INT
))
1521 if (targetType
== GL_BOOL_VEC2
&& (userType
== GL_FLOAT_VEC2
||
1522 userType
== GL_INT_VEC2
))
1525 if (targetType
== GL_BOOL_VEC3
&& (userType
== GL_FLOAT_VEC3
||
1526 userType
== GL_INT_VEC3
))
1529 if (targetType
== GL_BOOL_VEC4
&& (userType
== GL_FLOAT_VEC4
||
1530 userType
== GL_INT_VEC4
))
1533 if (is_sampler_type(targetType
) && userType
== GL_INT
)
1541 * Set the value of a program's uniform variable.
1542 * \param program the program whose uniform to update
1543 * \param index the index of the program parameter for the uniform
1544 * \param offset additional parameter slot offset (for arrays)
1545 * \param type the datatype of the uniform
1546 * \param count the number of uniforms to set
1547 * \param elems number of elements per uniform
1548 * \param values the new values
1551 set_program_uniform(GLcontext
*ctx
, struct gl_program
*program
,
1552 GLint index
, GLint offset
,
1553 GLenum type
, GLsizei count
, GLint elems
,
1556 struct gl_program_parameter
*param
=
1557 &program
->Parameters
->Parameters
[index
];
1559 assert(offset
>= 0);
1561 if (!compatible_types(type
, param
->DataType
)) {
1562 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUniform(type mismatch)");
1566 if (index
+ offset
> (GLint
) program
->Parameters
->Size
) {
1567 /* out of bounds! */
1571 if (param
->Type
== PROGRAM_SAMPLER
) {
1572 /* This controls which texture unit which is used by a sampler */
1573 GLuint texUnit
, sampler
;
1575 /* data type for setting samplers must be int */
1576 if (type
!= GL_INT
|| count
!= 1) {
1577 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1578 "glUniform(only glUniform1i can be used "
1579 "to set sampler uniforms)");
1583 sampler
= (GLuint
) program
->Parameters
->ParameterValues
[index
][0];
1584 texUnit
= ((GLuint
*) values
)[0];
1586 /* check that the sampler (tex unit index) is legal */
1587 if (texUnit
>= ctx
->Const
.MaxTextureImageUnits
) {
1588 _mesa_error(ctx
, GL_INVALID_VALUE
,
1589 "glUniform1(invalid sampler/tex unit index)");
1593 /* This maps a sampler to a texture unit: */
1594 program
->SamplerUnits
[sampler
] = texUnit
;
1595 _mesa_update_shader_textures_used(program
);
1597 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1600 /* ordinary uniform variable */
1602 GLint slots
= (param
->Size
+ 3) / 4;
1604 if (count
* elems
> (GLint
) param
->Size
) {
1605 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUniform(count too large)");
1612 for (k
= 0; k
< count
; k
++) {
1613 GLfloat
*uniformVal
=
1614 program
->Parameters
->ParameterValues
[index
+ offset
+ k
];
1615 if (is_integer_type(type
)) {
1616 const GLint
*iValues
= ((const GLint
*) values
) + k
* elems
;
1617 for (i
= 0; i
< elems
; i
++) {
1618 uniformVal
[i
] = (GLfloat
) iValues
[i
];
1622 const GLfloat
*fValues
= ((const GLfloat
*) values
) + k
* elems
;
1623 for (i
= 0; i
< elems
; i
++) {
1624 uniformVal
[i
] = fValues
[i
];
1628 /* if the uniform is bool-valued, convert to 1.0 or 0.0 */
1629 if (is_boolean_type(param
->DataType
)) {
1630 for (i
= 0; i
< elems
; i
++) {
1631 uniformVal
[i
] = uniformVal
[i
] ? 1.0f
: 0.0f
;
1640 * Called via ctx->Driver.Uniform().
1643 _mesa_uniform(GLcontext
*ctx
, GLint location
, GLsizei count
,
1644 const GLvoid
*values
, GLenum type
)
1646 struct gl_shader_program
*shProg
= ctx
->Shader
.CurrentProgram
;
1647 struct gl_uniform
*uniform
;
1648 GLint elems
, offset
;
1651 if (!shProg
|| !shProg
->LinkStatus
) {
1652 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glUniform(program not linked)");
1657 return; /* The standard specifies this as a no-op */
1659 split_location_offset(&location
, &offset
);
1661 if (location
< 0 || location
>= (GLint
) shProg
->Uniforms
->NumUniforms
) {
1662 _mesa_error(ctx
, GL_INVALID_VALUE
, "glUniform(location)");
1667 _mesa_error(ctx
, GL_INVALID_VALUE
, "glUniform(count < 0)");
1673 basicType
= GL_FLOAT
;
1681 basicType
= GL_FLOAT
;
1689 basicType
= GL_FLOAT
;
1697 basicType
= GL_FLOAT
;
1705 _mesa_problem(ctx
, "Invalid type in _mesa_uniform");
1709 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
1711 uniform
= &shProg
->Uniforms
->Uniforms
[location
];
1713 if (ctx
->Shader
.Flags
& GLSL_UNIFORMS
) {
1715 _mesa_printf("Mesa: set program %u uniform %s (loc %d) to: ",
1716 shProg
->Name
, uniform
->Name
, location
);
1717 if (basicType
== GL_INT
) {
1718 const GLint
*v
= (const GLint
*) values
;
1719 for (i
= 0; i
< count
* elems
; i
++) {
1720 _mesa_printf("%d ", v
[i
]);
1724 const GLfloat
*v
= (const GLfloat
*) values
;
1725 for (i
= 0; i
< count
* elems
; i
++) {
1726 _mesa_printf("%g ", v
[i
]);
1732 /* A uniform var may be used by both a vertex shader and a fragment
1733 * shader. We may need to update one or both shader's uniform here:
1735 if (shProg
->VertexProgram
) {
1736 /* convert uniform location to program parameter index */
1737 GLint index
= uniform
->VertPos
;
1739 set_program_uniform(ctx
, &shProg
->VertexProgram
->Base
,
1740 index
, offset
, type
, count
, elems
, values
);
1744 if (shProg
->FragmentProgram
) {
1745 /* convert uniform location to program parameter index */
1746 GLint index
= uniform
->FragPos
;
1748 set_program_uniform(ctx
, &shProg
->FragmentProgram
->Base
,
1749 index
, offset
, type
, count
, elems
, values
);
1753 uniform
->Initialized
= GL_TRUE
;
1758 * Set a matrix-valued program parameter.
1761 set_program_uniform_matrix(GLcontext
*ctx
, struct gl_program
*program
,
1762 GLuint index
, GLuint offset
,
1763 GLuint count
, GLuint rows
, GLuint cols
,
1764 GLboolean transpose
, const GLfloat
*values
)
1766 GLuint mat
, row
, col
;
1767 GLuint dst
= index
+ offset
, src
= 0;
1770 /* check that the number of rows, columns is correct */
1771 get_matrix_dims(program
->Parameters
->Parameters
[index
].DataType
, &nr
, &nc
);
1772 if (rows
!= nr
|| cols
!= nc
) {
1773 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1774 "glUniformMatrix(matrix size mismatch)");
1778 if (index
+ offset
> program
->Parameters
->Size
) {
1779 /* out of bounds! */
1784 * Note: the _columns_ of a matrix are stored in program registers, not
1785 * the rows. So, the loops below look a little funny.
1786 * XXX could optimize this a bit...
1789 /* loop over matrices */
1790 for (mat
= 0; mat
< count
; mat
++) {
1793 for (col
= 0; col
< cols
; col
++) {
1794 GLfloat
*v
= program
->Parameters
->ParameterValues
[dst
];
1795 for (row
= 0; row
< rows
; row
++) {
1797 v
[row
] = values
[src
+ row
* cols
+ col
];
1800 v
[row
] = values
[src
+ col
* rows
+ row
];
1806 src
+= rows
* cols
; /* next matrix */
1812 * Called by ctx->Driver.UniformMatrix().
1813 * Note: cols=2, rows=4 ==> array[2] of vec4
1816 _mesa_uniform_matrix(GLcontext
*ctx
, GLint cols
, GLint rows
,
1817 GLenum matrixType
, GLint location
, GLsizei count
,
1818 GLboolean transpose
, const GLfloat
*values
)
1820 struct gl_shader_program
*shProg
= ctx
->Shader
.CurrentProgram
;
1821 struct gl_uniform
*uniform
;
1824 if (!shProg
|| !shProg
->LinkStatus
) {
1825 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1826 "glUniformMatrix(program not linked)");
1831 return; /* The standard specifies this as a no-op */
1833 split_location_offset(&location
, &offset
);
1835 if (location
< 0 || location
>= (GLint
) shProg
->Uniforms
->NumUniforms
) {
1836 _mesa_error(ctx
, GL_INVALID_VALUE
, "glUniformMatrix(location)");
1839 if (values
== NULL
) {
1840 _mesa_error(ctx
, GL_INVALID_VALUE
, "glUniformMatrix");
1844 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
1846 uniform
= &shProg
->Uniforms
->Uniforms
[location
];
1848 if (shProg
->VertexProgram
) {
1849 /* convert uniform location to program parameter index */
1850 GLint index
= uniform
->VertPos
;
1852 set_program_uniform_matrix(ctx
, &shProg
->VertexProgram
->Base
,
1854 count
, rows
, cols
, transpose
, values
);
1858 if (shProg
->FragmentProgram
) {
1859 /* convert uniform location to program parameter index */
1860 GLint index
= uniform
->FragPos
;
1862 set_program_uniform_matrix(ctx
, &shProg
->FragmentProgram
->Base
,
1864 count
, rows
, cols
, transpose
, values
);
1868 uniform
->Initialized
= GL_TRUE
;
1873 _mesa_validate_program(GLcontext
*ctx
, GLuint program
)
1875 struct gl_shader_program
*shProg
;
1877 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glValidateProgram");
1882 if (!shProg
->LinkStatus
) {
1883 shProg
->Validated
= GL_FALSE
;
1887 /* From the GL spec, a program is invalid if any of these are true:
1889 any two active samplers in the current program object are of
1890 different types, but refer to the same texture image unit,
1892 any active sampler in the current program object refers to a texture
1893 image unit where fixed-function fragment processing accesses a
1894 texture target that does not match the sampler type, or
1896 the sum of the number of active samplers in the program and the
1897 number of texture image units enabled for fixed-function fragment
1898 processing exceeds the combined limit on the total number of texture
1899 image units allowed.
1902 shProg
->Validated
= GL_TRUE
;
1907 * Plug in Mesa's GLSL functions into the device driver function table.
1910 _mesa_init_glsl_driver_functions(struct dd_function_table
*driver
)
1912 driver
->AttachShader
= _mesa_attach_shader
;
1913 driver
->BindAttribLocation
= _mesa_bind_attrib_location
;
1914 driver
->CompileShader
= _mesa_compile_shader
;
1915 driver
->CreateProgram
= _mesa_create_program
;
1916 driver
->CreateShader
= _mesa_create_shader
;
1917 driver
->DeleteProgram2
= _mesa_delete_program2
;
1918 driver
->DeleteShader
= _mesa_delete_shader
;
1919 driver
->DetachShader
= _mesa_detach_shader
;
1920 driver
->GetActiveAttrib
= _mesa_get_active_attrib
;
1921 driver
->GetActiveUniform
= _mesa_get_active_uniform
;
1922 driver
->GetAttachedShaders
= _mesa_get_attached_shaders
;
1923 driver
->GetAttribLocation
= _mesa_get_attrib_location
;
1924 driver
->GetHandle
= _mesa_get_handle
;
1925 driver
->GetProgramiv
= _mesa_get_programiv
;
1926 driver
->GetProgramInfoLog
= _mesa_get_program_info_log
;
1927 driver
->GetShaderiv
= _mesa_get_shaderiv
;
1928 driver
->GetShaderInfoLog
= _mesa_get_shader_info_log
;
1929 driver
->GetShaderSource
= _mesa_get_shader_source
;
1930 driver
->GetUniformfv
= _mesa_get_uniformfv
;
1931 driver
->GetUniformiv
= _mesa_get_uniformiv
;
1932 driver
->GetUniformLocation
= _mesa_get_uniform_location
;
1933 driver
->IsProgram
= _mesa_is_program
;
1934 driver
->IsShader
= _mesa_is_shader
;
1935 driver
->LinkProgram
= _mesa_link_program
;
1936 driver
->ShaderSource
= _mesa_shader_source
;
1937 driver
->Uniform
= _mesa_uniform
;
1938 driver
->UniformMatrix
= _mesa_uniform_matrix
;
1939 driver
->UseProgram
= _mesa_use_program
;
1940 driver
->ValidateProgram
= _mesa_validate_program
;