2 * Mesa 3-D graphics library
4 * Copyright (C) 2004-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009-2010 VMware, Inc. 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 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
30 * Implementation of GLSL-related API functions.
31 * The glUniform* functions are in uniforms.c
35 * 1. Check that the right error code is generated for all _mesa_error() calls.
36 * 2. Insert FLUSH_VERTICES calls in various places
40 #include "main/glheader.h"
41 #include "main/context.h"
42 #include "main/dispatch.h"
43 #include "main/enums.h"
44 #include "main/hash.h"
45 #include "main/mtypes.h"
46 #include "main/shaderapi.h"
47 #include "main/shaderobj.h"
48 #include "main/transformfeedback.h"
49 #include "main/uniforms.h"
50 #include "program/program.h"
51 #include "program/prog_print.h"
52 #include "program/prog_parameter.h"
55 #include "../glsl/glsl_parser_extras.h"
56 #include "../glsl/ir.h"
57 #include "../glsl/ir_uniform.h"
58 #include "../glsl/program.h"
60 /** Define this to enable shader substitution (see below) */
61 #define SHADER_SUBST 0
65 * Return mask of GLSL_x flags by examining the MESA_GLSL env var.
68 get_shader_flags(void)
70 GLbitfield flags
= 0x0;
71 const char *env
= _mesa_getenv("MESA_GLSL");
74 if (strstr(env
, "dump"))
76 if (strstr(env
, "log"))
78 if (strstr(env
, "nopvert"))
79 flags
|= GLSL_NOP_VERT
;
80 if (strstr(env
, "nopfrag"))
81 flags
|= GLSL_NOP_FRAG
;
82 if (strstr(env
, "nopt"))
84 else if (strstr(env
, "opt"))
86 if (strstr(env
, "uniform"))
87 flags
|= GLSL_UNIFORMS
;
88 if (strstr(env
, "useprog"))
89 flags
|= GLSL_USE_PROG
;
90 if (strstr(env
, "errors"))
91 flags
|= GLSL_REPORT_ERRORS
;
99 * Initialize context's shader state.
102 _mesa_init_shader_state(struct gl_context
*ctx
)
104 /* Device drivers may override these to control what kind of instructions
105 * are generated by the GLSL compiler.
107 struct gl_shader_compiler_options options
;
110 memset(&options
, 0, sizeof(options
));
111 options
.MaxUnrollIterations
= 32;
112 options
.MaxIfDepth
= UINT_MAX
;
114 /* Default pragma settings */
115 options
.DefaultPragmas
.Optimize
= GL_TRUE
;
117 for (sh
= 0; sh
< MESA_SHADER_TYPES
; ++sh
)
118 memcpy(&ctx
->ShaderCompilerOptions
[sh
], &options
, sizeof(options
));
120 ctx
->Shader
.Flags
= get_shader_flags();
125 * Free the per-context shader-related state.
128 _mesa_free_shader_state(struct gl_context
*ctx
)
130 _mesa_reference_shader_program(ctx
, &ctx
->Shader
.CurrentVertexProgram
, NULL
);
131 _mesa_reference_shader_program(ctx
, &ctx
->Shader
.CurrentGeometryProgram
,
133 _mesa_reference_shader_program(ctx
, &ctx
->Shader
.CurrentFragmentProgram
,
135 _mesa_reference_shader_program(ctx
, &ctx
->Shader
._CurrentFragmentProgram
,
137 _mesa_reference_shader_program(ctx
, &ctx
->Shader
.ActiveProgram
, NULL
);
142 * Copy string from <src> to <dst>, up to maxLength characters, returning
143 * length of <dst> in <length>.
144 * \param src the strings source
145 * \param maxLength max chars to copy
146 * \param length returns number of chars copied
147 * \param dst the string destination
150 _mesa_copy_string(GLchar
*dst
, GLsizei maxLength
,
151 GLsizei
*length
, const GLchar
*src
)
154 for (len
= 0; len
< maxLength
- 1 && src
&& src
[len
]; len
++)
165 * Confirm that the a shader type is valid and supported by the implementation
167 * \param ctx Current GL context
168 * \param type Shader target
172 validate_shader_target(const struct gl_context
*ctx
, GLenum type
)
175 case GL_FRAGMENT_SHADER
:
176 return ctx
->Extensions
.ARB_fragment_shader
;
177 case GL_VERTEX_SHADER
:
178 return ctx
->Extensions
.ARB_vertex_shader
;
179 case GL_GEOMETRY_SHADER_ARB
:
180 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_geometry_shader4
;
188 is_program(struct gl_context
*ctx
, GLuint name
)
190 struct gl_shader_program
*shProg
= _mesa_lookup_shader_program(ctx
, name
);
191 return shProg
? GL_TRUE
: GL_FALSE
;
196 is_shader(struct gl_context
*ctx
, GLuint name
)
198 struct gl_shader
*shader
= _mesa_lookup_shader(ctx
, name
);
199 return shader
? GL_TRUE
: GL_FALSE
;
204 * Attach shader to a shader program.
207 attach_shader(struct gl_context
*ctx
, GLuint program
, GLuint shader
)
209 struct gl_shader_program
*shProg
;
210 struct gl_shader
*sh
;
213 const bool same_type_disallowed
= _mesa_is_gles(ctx
);
215 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glAttachShader");
219 sh
= _mesa_lookup_shader_err(ctx
, shader
, "glAttachShader");
224 n
= shProg
->NumShaders
;
225 for (i
= 0; i
< n
; i
++) {
226 if (shProg
->Shaders
[i
] == sh
) {
227 /* The shader is already attched to this program. The
228 * GL_ARB_shader_objects spec says:
230 * "The error INVALID_OPERATION is generated by AttachObjectARB
231 * if <obj> is already attached to <containerObj>."
233 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glAttachShader");
235 } else if (same_type_disallowed
&&
236 shProg
->Shaders
[i
]->Type
== sh
->Type
) {
237 /* Shader with the same type is already attached to this program,
238 * OpenGL ES 2.0 and 3.0 specs say:
240 * "Multiple shader objects of the same type may not be attached
241 * to a single program object. [...] The error INVALID_OPERATION
242 * is generated if [...] another shader object of the same type
243 * as shader is already attached to program."
245 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glAttachShader");
251 shProg
->Shaders
= (struct gl_shader
**)
252 _mesa_realloc(shProg
->Shaders
,
253 n
* sizeof(struct gl_shader
*),
254 (n
+ 1) * sizeof(struct gl_shader
*));
255 if (!shProg
->Shaders
) {
256 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glAttachShader");
261 shProg
->Shaders
[n
] = NULL
; /* since realloc() didn't zero the new space */
262 _mesa_reference_shader(ctx
, &shProg
->Shaders
[n
], sh
);
263 shProg
->NumShaders
++;
268 create_shader(struct gl_context
*ctx
, GLenum type
)
270 struct gl_shader
*sh
;
273 if (!validate_shader_target(ctx
, type
)) {
274 _mesa_error(ctx
, GL_INVALID_ENUM
, "CreateShader(type)");
278 name
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->ShaderObjects
, 1);
279 sh
= ctx
->Driver
.NewShader(ctx
, name
, type
);
280 _mesa_HashInsert(ctx
->Shared
->ShaderObjects
, name
, sh
);
287 create_shader_program(struct gl_context
*ctx
)
290 struct gl_shader_program
*shProg
;
292 name
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->ShaderObjects
, 1);
294 shProg
= ctx
->Driver
.NewShaderProgram(ctx
, name
);
296 _mesa_HashInsert(ctx
->Shared
->ShaderObjects
, name
, shProg
);
298 assert(shProg
->RefCount
== 1);
305 * Named w/ "2" to indicate OpenGL 2.x vs GL_ARB_fragment_programs's
309 delete_shader_program(struct gl_context
*ctx
, GLuint name
)
312 * NOTE: deleting shaders/programs works a bit differently than
313 * texture objects (and buffer objects, etc). Shader/program
314 * handles/IDs exist in the hash table until the object is really
315 * deleted (refcount==0). With texture objects, the handle/ID is
316 * removed from the hash table in glDeleteTextures() while the tex
317 * object itself might linger until its refcount goes to zero.
319 struct gl_shader_program
*shProg
;
321 shProg
= _mesa_lookup_shader_program_err(ctx
, name
, "glDeleteProgram");
325 if (!shProg
->DeletePending
) {
326 shProg
->DeletePending
= GL_TRUE
;
328 /* effectively, decr shProg's refcount */
329 _mesa_reference_shader_program(ctx
, &shProg
, NULL
);
335 delete_shader(struct gl_context
*ctx
, GLuint shader
)
337 struct gl_shader
*sh
;
339 sh
= _mesa_lookup_shader_err(ctx
, shader
, "glDeleteShader");
343 if (!sh
->DeletePending
) {
344 sh
->DeletePending
= GL_TRUE
;
346 /* effectively, decr sh's refcount */
347 _mesa_reference_shader(ctx
, &sh
, NULL
);
353 detach_shader(struct gl_context
*ctx
, GLuint program
, GLuint shader
)
355 struct gl_shader_program
*shProg
;
359 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glDetachShader");
363 n
= shProg
->NumShaders
;
365 for (i
= 0; i
< n
; i
++) {
366 if (shProg
->Shaders
[i
]->Name
== shader
) {
368 struct gl_shader
**newList
;
371 _mesa_reference_shader(ctx
, &shProg
->Shaders
[i
], NULL
);
373 /* alloc new, smaller array */
375 malloc((n
- 1) * sizeof(struct gl_shader
*));
377 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glDetachShader");
380 for (j
= 0; j
< i
; j
++) {
381 newList
[j
] = shProg
->Shaders
[j
];
384 newList
[j
++] = shProg
->Shaders
[i
];
385 free(shProg
->Shaders
);
387 shProg
->Shaders
= newList
;
388 shProg
->NumShaders
= n
- 1;
393 for (j
= 0; j
< shProg
->NumShaders
; j
++) {
394 assert(shProg
->Shaders
[j
]->Type
== GL_VERTEX_SHADER
||
395 shProg
->Shaders
[j
]->Type
== GL_FRAGMENT_SHADER
);
396 assert(shProg
->Shaders
[j
]->RefCount
> 0);
408 if (is_shader(ctx
, shader
))
409 err
= GL_INVALID_OPERATION
;
410 else if (is_program(ctx
, shader
))
411 err
= GL_INVALID_OPERATION
;
413 err
= GL_INVALID_VALUE
;
414 _mesa_error(ctx
, err
, "glDetachProgram(shader)");
421 * Return list of shaders attached to shader program.
424 get_attached_shaders(struct gl_context
*ctx
, GLuint program
, GLsizei maxCount
,
425 GLsizei
*count
, GLuint
*obj
)
427 struct gl_shader_program
*shProg
=
428 _mesa_lookup_shader_program_err(ctx
, program
, "glGetAttachedShaders");
431 for (i
= 0; i
< (GLuint
) maxCount
&& i
< shProg
->NumShaders
; i
++) {
432 obj
[i
] = shProg
->Shaders
[i
]->Name
;
441 * glGetHandleARB() - return ID/name of currently bound shader program.
444 get_handle(struct gl_context
*ctx
, GLenum pname
)
446 if (pname
== GL_PROGRAM_OBJECT_ARB
) {
447 if (ctx
->Shader
.ActiveProgram
)
448 return ctx
->Shader
.ActiveProgram
->Name
;
453 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetHandleARB");
460 * glGetProgramiv() - get shader program state.
461 * Note that this is for GLSL shader programs, not ARB vertex/fragment
462 * programs (see glGetProgramivARB).
465 get_programiv(struct gl_context
*ctx
, GLuint program
, GLenum pname
, GLint
*params
)
467 struct gl_shader_program
*shProg
468 = _mesa_lookup_shader_program(ctx
, program
);
470 /* Is transform feedback available in this context?
473 (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.EXT_transform_feedback
)
474 || ctx
->API
== API_OPENGL_CORE
475 || _mesa_is_gles3(ctx
);
477 /* Are geometry shaders available in this context?
480 _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_geometry_shader4
;
482 /* Are uniform buffer objects available in this context?
485 (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_uniform_buffer_object
)
486 || ctx
->API
== API_OPENGL_CORE
487 || _mesa_is_gles3(ctx
);
490 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramiv(program)");
495 case GL_DELETE_STATUS
:
496 *params
= shProg
->DeletePending
;
499 *params
= shProg
->LinkStatus
;
501 case GL_VALIDATE_STATUS
:
502 *params
= shProg
->Validated
;
504 case GL_INFO_LOG_LENGTH
:
505 *params
= shProg
->InfoLog
? strlen(shProg
->InfoLog
) + 1 : 0;
507 case GL_ATTACHED_SHADERS
:
508 *params
= shProg
->NumShaders
;
510 case GL_ACTIVE_ATTRIBUTES
:
511 *params
= _mesa_count_active_attribs(shProg
);
513 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
:
514 *params
= _mesa_longest_attribute_name_length(shProg
);
516 case GL_ACTIVE_UNIFORMS
:
517 *params
= shProg
->NumUserUniformStorage
;
519 case GL_ACTIVE_UNIFORM_MAX_LENGTH
: {
523 for (i
= 0; i
< shProg
->NumUserUniformStorage
; i
++) {
524 /* Add one for the terminating NUL character for a non-array, and
525 * 4 for the "[0]" and the NUL for an array.
527 const GLint len
= strlen(shProg
->UniformStorage
[i
].name
) + 1 +
528 ((shProg
->UniformStorage
[i
].array_elements
!= 0) ? 3 : 0);
537 case GL_TRANSFORM_FEEDBACK_VARYINGS
:
540 *params
= shProg
->TransformFeedback
.NumVarying
;
542 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH
: {
548 for (i
= 0; i
< shProg
->TransformFeedback
.NumVarying
; i
++) {
549 /* Add one for the terminating NUL character.
551 const GLint len
= strlen(shProg
->TransformFeedback
.VaryingNames
[i
]) + 1;
560 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE
:
563 *params
= shProg
->TransformFeedback
.BufferMode
;
565 case GL_GEOMETRY_VERTICES_OUT_ARB
:
568 *params
= shProg
->Geom
.VerticesOut
;
570 case GL_GEOMETRY_INPUT_TYPE_ARB
:
573 *params
= shProg
->Geom
.InputType
;
575 case GL_GEOMETRY_OUTPUT_TYPE_ARB
:
578 *params
= shProg
->Geom
.OutputType
;
580 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH
: {
587 for (i
= 0; i
< shProg
->NumUniformBlocks
; i
++) {
588 /* Add one for the terminating NUL character.
590 const GLint len
= strlen(shProg
->UniformBlocks
[i
].Name
) + 1;
599 case GL_ACTIVE_UNIFORM_BLOCKS
:
603 *params
= shProg
->NumUniformBlocks
;
605 case GL_PROGRAM_BINARY_RETRIEVABLE_HINT
:
606 /* This enum isn't part of the OES extension for OpenGL ES 2.0. It is
607 * only available with desktop OpenGL 3.0+ with the
608 * GL_ARB_get_program_binary extension or OpenGL ES 3.0.
610 * On desktop, we ignore the 3.0+ requirement because it is silly.
612 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
615 *params
= shProg
->BinaryRetreivableHint
;
617 case GL_PROGRAM_BINARY_LENGTH
:
624 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramiv(pname=%s)",
625 _mesa_lookup_enum_by_nr(pname
));
630 * glGetShaderiv() - get GLSL shader state
633 get_shaderiv(struct gl_context
*ctx
, GLuint name
, GLenum pname
, GLint
*params
)
635 struct gl_shader
*shader
=
636 _mesa_lookup_shader_err(ctx
, name
, "glGetShaderiv");
644 *params
= shader
->Type
;
646 case GL_DELETE_STATUS
:
647 *params
= shader
->DeletePending
;
649 case GL_COMPILE_STATUS
:
650 *params
= shader
->CompileStatus
;
652 case GL_INFO_LOG_LENGTH
:
653 *params
= shader
->InfoLog
? strlen(shader
->InfoLog
) + 1 : 0;
655 case GL_SHADER_SOURCE_LENGTH
:
656 *params
= shader
->Source
? strlen((char *) shader
->Source
) + 1 : 0;
659 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetShaderiv(pname)");
666 get_program_info_log(struct gl_context
*ctx
, GLuint program
, GLsizei bufSize
,
667 GLsizei
*length
, GLchar
*infoLog
)
669 struct gl_shader_program
*shProg
670 = _mesa_lookup_shader_program(ctx
, program
);
672 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramInfoLog(program)");
675 _mesa_copy_string(infoLog
, bufSize
, length
, shProg
->InfoLog
);
680 get_shader_info_log(struct gl_context
*ctx
, GLuint shader
, GLsizei bufSize
,
681 GLsizei
*length
, GLchar
*infoLog
)
683 struct gl_shader
*sh
= _mesa_lookup_shader(ctx
, shader
);
685 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetShaderInfoLog(shader)");
688 _mesa_copy_string(infoLog
, bufSize
, length
, sh
->InfoLog
);
693 * Return shader source code.
696 get_shader_source(struct gl_context
*ctx
, GLuint shader
, GLsizei maxLength
,
697 GLsizei
*length
, GLchar
*sourceOut
)
699 struct gl_shader
*sh
;
700 sh
= _mesa_lookup_shader_err(ctx
, shader
, "glGetShaderSource");
704 _mesa_copy_string(sourceOut
, maxLength
, length
, sh
->Source
);
709 * Set/replace shader source code. A helper function used by
710 * glShaderSource[ARB] and glCreateShaderProgramEXT.
713 shader_source(struct gl_context
*ctx
, GLuint shader
, const GLchar
*source
)
715 struct gl_shader
*sh
;
717 sh
= _mesa_lookup_shader_err(ctx
, shader
, "glShaderSource");
721 /* free old shader source string and install new one */
722 free((void *)sh
->Source
);
724 sh
->CompileStatus
= GL_FALSE
;
726 sh
->SourceChecksum
= _mesa_str_checksum(sh
->Source
);
735 compile_shader(struct gl_context
*ctx
, GLuint shaderObj
)
737 struct gl_shader
*sh
;
738 struct gl_shader_compiler_options
*options
;
740 sh
= _mesa_lookup_shader_err(ctx
, shaderObj
, "glCompileShader");
744 options
= &ctx
->ShaderCompilerOptions
[_mesa_shader_type_to_index(sh
->Type
)];
746 /* set default pragma state for shader */
747 sh
->Pragmas
= options
->DefaultPragmas
;
750 /* If the user called glCompileShader without first calling
751 * glShaderSource, we should fail to compile, but not raise a GL_ERROR.
753 sh
->CompileStatus
= GL_FALSE
;
755 if (ctx
->Shader
.Flags
& GLSL_DUMP
) {
756 printf("GLSL source for %s shader %d:\n",
757 _mesa_glsl_shader_target_name(sh
->Type
), sh
->Name
);
758 printf("%s\n", sh
->Source
);
761 /* this call will set the shader->CompileStatus field to indicate if
762 * compilation was successful.
764 _mesa_glsl_compile_shader(ctx
, sh
, false, false);
766 if (ctx
->Shader
.Flags
& GLSL_LOG
) {
767 _mesa_write_shader_to_file(sh
);
770 if (ctx
->Shader
.Flags
& GLSL_DUMP
) {
771 if (sh
->CompileStatus
) {
772 printf("GLSL IR for shader %d:\n", sh
->Name
);
773 _mesa_print_ir(sh
->ir
, NULL
);
776 printf("GLSL shader %d failed to compile.\n", sh
->Name
);
778 if (sh
->InfoLog
&& sh
->InfoLog
[0] != 0) {
779 printf("GLSL shader %d info log:\n", sh
->Name
);
780 printf("%s\n", sh
->InfoLog
);
786 if (sh
->CompileStatus
== GL_FALSE
&&
787 (ctx
->Shader
.Flags
& GLSL_REPORT_ERRORS
)) {
788 _mesa_debug(ctx
, "Error compiling shader %u:\n%s\n",
789 sh
->Name
, sh
->InfoLog
);
795 * Link a program's shaders.
798 link_program(struct gl_context
*ctx
, GLuint program
)
800 struct gl_shader_program
*shProg
;
801 struct gl_transform_feedback_object
*obj
=
802 ctx
->TransformFeedback
.CurrentObject
;
804 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glLinkProgram");
809 && (shProg
== ctx
->Shader
.CurrentVertexProgram
810 || shProg
== ctx
->Shader
.CurrentGeometryProgram
811 || shProg
== ctx
->Shader
.CurrentFragmentProgram
)) {
812 _mesa_error(ctx
, GL_INVALID_OPERATION
,
813 "glLinkProgram(transform feedback active)");
817 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
819 _mesa_glsl_link_shader(ctx
, shProg
);
821 if (shProg
->LinkStatus
== GL_FALSE
&&
822 (ctx
->Shader
.Flags
& GLSL_REPORT_ERRORS
)) {
823 _mesa_debug(ctx
, "Error linking program %u:\n%s\n",
824 shProg
->Name
, shProg
->InfoLog
);
831 printf("Link %u shaders in program %u: %s\n",
832 shProg
->NumShaders
, shProg
->Name
,
833 shProg
->LinkStatus
? "Success" : "Failed");
835 for (i
= 0; i
< shProg
->NumShaders
; i
++) {
836 printf(" shader %u, type 0x%x\n",
837 shProg
->Shaders
[i
]->Name
,
838 shProg
->Shaders
[i
]->Type
);
845 * Print basic shader info (for debug).
848 print_shader_info(const struct gl_shader_program
*shProg
)
852 printf("Mesa: glUseProgram(%u)\n", shProg
->Name
);
853 for (i
= 0; i
< shProg
->NumShaders
; i
++) {
854 printf(" %s shader %u, checksum %u\n",
855 _mesa_glsl_shader_target_name(shProg
->Shaders
[i
]->Type
),
856 shProg
->Shaders
[i
]->Name
,
857 shProg
->Shaders
[i
]->SourceChecksum
);
859 if (shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
])
860 printf(" vert prog %u\n",
861 shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
]->Program
->Id
);
862 if (shProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
])
863 printf(" frag prog %u\n",
864 shProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
]->Program
->Id
);
865 if (shProg
->_LinkedShaders
[MESA_SHADER_GEOMETRY
])
866 printf(" geom prog %u\n",
867 shProg
->_LinkedShaders
[MESA_SHADER_GEOMETRY
]->Program
->Id
);
872 * Use the named shader program for subsequent glUniform calls
875 _mesa_active_program(struct gl_context
*ctx
, struct gl_shader_program
*shProg
,
878 if ((shProg
!= NULL
) && !shProg
->LinkStatus
) {
879 _mesa_error(ctx
, GL_INVALID_OPERATION
,
880 "%s(program %u not linked)", caller
, shProg
->Name
);
884 if (ctx
->Shader
.ActiveProgram
!= shProg
) {
885 _mesa_reference_shader_program(ctx
, &ctx
->Shader
.ActiveProgram
, shProg
);
892 use_shader_program(struct gl_context
*ctx
, GLenum type
,
893 struct gl_shader_program
*shProg
)
895 struct gl_shader_program
**target
;
898 case GL_VERTEX_SHADER
:
899 target
= &ctx
->Shader
.CurrentVertexProgram
;
901 || (shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
)) {
905 case GL_GEOMETRY_SHADER_ARB
:
906 target
= &ctx
->Shader
.CurrentGeometryProgram
;
908 || (shProg
->_LinkedShaders
[MESA_SHADER_GEOMETRY
] == NULL
)) {
912 case GL_FRAGMENT_SHADER
:
913 target
= &ctx
->Shader
.CurrentFragmentProgram
;
915 || (shProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
] == NULL
)) {
923 if (*target
!= shProg
) {
924 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
| _NEW_PROGRAM_CONSTANTS
);
926 /* If the shader is also bound as the current rendering shader, unbind
927 * it from that binding point as well. This ensures that the correct
928 * semantics of glDeleteProgram are maintained.
931 case GL_VERTEX_SHADER
:
934 case GL_GEOMETRY_SHADER_ARB
:
937 case GL_FRAGMENT_SHADER
:
938 if (*target
== ctx
->Shader
._CurrentFragmentProgram
) {
939 _mesa_reference_shader_program(ctx
,
940 &ctx
->Shader
._CurrentFragmentProgram
,
946 _mesa_reference_shader_program(ctx
, target
, shProg
);
954 * Use the named shader program for subsequent rendering.
957 _mesa_use_program(struct gl_context
*ctx
, struct gl_shader_program
*shProg
)
959 use_shader_program(ctx
, GL_VERTEX_SHADER
, shProg
);
960 use_shader_program(ctx
, GL_GEOMETRY_SHADER_ARB
, shProg
);
961 use_shader_program(ctx
, GL_FRAGMENT_SHADER
, shProg
);
962 _mesa_active_program(ctx
, shProg
, "glUseProgram");
964 if (ctx
->Driver
.UseProgram
)
965 ctx
->Driver
.UseProgram(ctx
, shProg
);
970 * Do validation of the given shader program.
971 * \param errMsg returns error message if validation fails.
972 * \return GL_TRUE if valid, GL_FALSE if invalid (and set errMsg)
975 validate_shader_program(const struct gl_shader_program
*shProg
,
978 if (!shProg
->LinkStatus
) {
982 /* From the GL spec, a program is invalid if any of these are true:
984 any two active samplers in the current program object are of
985 different types, but refer to the same texture image unit,
987 any active sampler in the current program object refers to a texture
988 image unit where fixed-function fragment processing accesses a
989 texture target that does not match the sampler type, or
991 the sum of the number of active samplers in the program and the
992 number of texture image units enabled for fixed-function fragment
993 processing exceeds the combined limit on the total number of texture
999 * Check: any two active samplers in the current program object are of
1000 * different types, but refer to the same texture image unit,
1002 if (!_mesa_sampler_uniforms_are_valid(shProg
, errMsg
, 100))
1010 * Called via glValidateProgram()
1013 validate_program(struct gl_context
*ctx
, GLuint program
)
1015 struct gl_shader_program
*shProg
;
1016 char errMsg
[100] = "";
1018 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glValidateProgram");
1023 shProg
->Validated
= validate_shader_program(shProg
, errMsg
);
1024 if (!shProg
->Validated
) {
1025 /* update info log */
1026 if (shProg
->InfoLog
) {
1027 ralloc_free(shProg
->InfoLog
);
1029 shProg
->InfoLog
= ralloc_strdup(shProg
, errMsg
);
1036 _mesa_AttachObjectARB(GLhandleARB program
, GLhandleARB shader
)
1038 GET_CURRENT_CONTEXT(ctx
);
1039 attach_shader(ctx
, program
, shader
);
1044 _mesa_AttachShader(GLuint program
, GLuint shader
)
1046 GET_CURRENT_CONTEXT(ctx
);
1047 attach_shader(ctx
, program
, shader
);
1052 _mesa_CompileShader(GLhandleARB shaderObj
)
1054 GET_CURRENT_CONTEXT(ctx
);
1055 if (MESA_VERBOSE
& VERBOSE_API
)
1056 _mesa_debug(ctx
, "glCompileShader %u\n", shaderObj
);
1057 compile_shader(ctx
, shaderObj
);
1062 _mesa_CreateShader(GLenum type
)
1064 GET_CURRENT_CONTEXT(ctx
);
1065 if (MESA_VERBOSE
& VERBOSE_API
)
1066 _mesa_debug(ctx
, "glCreateShader %s\n", _mesa_lookup_enum_by_nr(type
));
1067 return create_shader(ctx
, type
);
1071 GLhandleARB GLAPIENTRY
1072 _mesa_CreateShaderObjectARB(GLenum type
)
1074 GET_CURRENT_CONTEXT(ctx
);
1075 return create_shader(ctx
, type
);
1080 _mesa_CreateProgram(void)
1082 GET_CURRENT_CONTEXT(ctx
);
1083 if (MESA_VERBOSE
& VERBOSE_API
)
1084 _mesa_debug(ctx
, "glCreateProgram\n");
1085 return create_shader_program(ctx
);
1089 GLhandleARB GLAPIENTRY
1090 _mesa_CreateProgramObjectARB(void)
1092 GET_CURRENT_CONTEXT(ctx
);
1093 return create_shader_program(ctx
);
1098 _mesa_DeleteObjectARB(GLhandleARB obj
)
1100 if (MESA_VERBOSE
& VERBOSE_API
) {
1101 GET_CURRENT_CONTEXT(ctx
);
1102 _mesa_debug(ctx
, "glDeleteObjectARB(%u)\n", obj
);
1106 GET_CURRENT_CONTEXT(ctx
);
1107 FLUSH_VERTICES(ctx
, 0);
1108 if (is_program(ctx
, obj
)) {
1109 delete_shader_program(ctx
, obj
);
1111 else if (is_shader(ctx
, obj
)) {
1112 delete_shader(ctx
, obj
);
1122 _mesa_DeleteProgram(GLuint name
)
1125 GET_CURRENT_CONTEXT(ctx
);
1126 FLUSH_VERTICES(ctx
, 0);
1127 delete_shader_program(ctx
, name
);
1133 _mesa_DeleteShader(GLuint name
)
1136 GET_CURRENT_CONTEXT(ctx
);
1137 FLUSH_VERTICES(ctx
, 0);
1138 delete_shader(ctx
, name
);
1144 _mesa_DetachObjectARB(GLhandleARB program
, GLhandleARB shader
)
1146 GET_CURRENT_CONTEXT(ctx
);
1147 detach_shader(ctx
, program
, shader
);
1152 _mesa_DetachShader(GLuint program
, GLuint shader
)
1154 GET_CURRENT_CONTEXT(ctx
);
1155 detach_shader(ctx
, program
, shader
);
1160 _mesa_GetAttachedObjectsARB(GLhandleARB container
, GLsizei maxCount
,
1161 GLsizei
* count
, GLhandleARB
* obj
)
1163 GET_CURRENT_CONTEXT(ctx
);
1164 get_attached_shaders(ctx
, container
, maxCount
, count
, obj
);
1169 _mesa_GetAttachedShaders(GLuint program
, GLsizei maxCount
,
1170 GLsizei
*count
, GLuint
*obj
)
1172 GET_CURRENT_CONTEXT(ctx
);
1173 get_attached_shaders(ctx
, program
, maxCount
, count
, obj
);
1178 _mesa_GetInfoLogARB(GLhandleARB object
, GLsizei maxLength
, GLsizei
* length
,
1179 GLcharARB
* infoLog
)
1181 GET_CURRENT_CONTEXT(ctx
);
1182 if (is_program(ctx
, object
)) {
1183 get_program_info_log(ctx
, object
, maxLength
, length
, infoLog
);
1185 else if (is_shader(ctx
, object
)) {
1186 get_shader_info_log(ctx
, object
, maxLength
, length
, infoLog
);
1189 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInfoLogARB");
1195 _mesa_GetObjectParameterivARB(GLhandleARB object
, GLenum pname
, GLint
*params
)
1197 GET_CURRENT_CONTEXT(ctx
);
1198 /* Implement in terms of GetProgramiv, GetShaderiv */
1199 if (is_program(ctx
, object
)) {
1200 if (pname
== GL_OBJECT_TYPE_ARB
) {
1201 *params
= GL_PROGRAM_OBJECT_ARB
;
1204 get_programiv(ctx
, object
, pname
, params
);
1207 else if (is_shader(ctx
, object
)) {
1208 if (pname
== GL_OBJECT_TYPE_ARB
) {
1209 *params
= GL_SHADER_OBJECT_ARB
;
1212 get_shaderiv(ctx
, object
, pname
, params
);
1216 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetObjectParameterivARB");
1222 _mesa_GetObjectParameterfvARB(GLhandleARB object
, GLenum pname
,
1225 GLint iparams
[1]; /* XXX is one element enough? */
1226 _mesa_GetObjectParameterivARB(object
, pname
, iparams
);
1227 params
[0] = (GLfloat
) iparams
[0];
1232 _mesa_GetProgramiv(GLuint program
, GLenum pname
, GLint
*params
)
1234 GET_CURRENT_CONTEXT(ctx
);
1235 get_programiv(ctx
, program
, pname
, params
);
1240 _mesa_GetShaderiv(GLuint shader
, GLenum pname
, GLint
*params
)
1242 GET_CURRENT_CONTEXT(ctx
);
1243 get_shaderiv(ctx
, shader
, pname
, params
);
1248 _mesa_GetProgramInfoLog(GLuint program
, GLsizei bufSize
,
1249 GLsizei
*length
, GLchar
*infoLog
)
1251 GET_CURRENT_CONTEXT(ctx
);
1252 get_program_info_log(ctx
, program
, bufSize
, length
, infoLog
);
1257 _mesa_GetShaderInfoLog(GLuint shader
, GLsizei bufSize
,
1258 GLsizei
*length
, GLchar
*infoLog
)
1260 GET_CURRENT_CONTEXT(ctx
);
1261 get_shader_info_log(ctx
, shader
, bufSize
, length
, infoLog
);
1266 _mesa_GetShaderSource(GLhandleARB shader
, GLsizei maxLength
,
1267 GLsizei
*length
, GLcharARB
*sourceOut
)
1269 GET_CURRENT_CONTEXT(ctx
);
1270 get_shader_source(ctx
, shader
, maxLength
, length
, sourceOut
);
1274 GLhandleARB GLAPIENTRY
1275 _mesa_GetHandleARB(GLenum pname
)
1277 GET_CURRENT_CONTEXT(ctx
);
1278 return get_handle(ctx
, pname
);
1282 GLboolean GLAPIENTRY
1283 _mesa_IsProgram(GLuint name
)
1285 GET_CURRENT_CONTEXT(ctx
);
1286 return is_program(ctx
, name
);
1290 GLboolean GLAPIENTRY
1291 _mesa_IsShader(GLuint name
)
1293 GET_CURRENT_CONTEXT(ctx
);
1294 return is_shader(ctx
, name
);
1299 _mesa_LinkProgram(GLhandleARB programObj
)
1301 GET_CURRENT_CONTEXT(ctx
);
1302 link_program(ctx
, programObj
);
1308 * Read shader source code from a file.
1309 * Useful for debugging to override an app's shader.
1312 read_shader(const char *fname
)
1314 const int max
= 50*1000;
1315 FILE *f
= fopen(fname
, "r");
1316 GLcharARB
*buffer
, *shader
;
1323 buffer
= malloc(max
);
1324 len
= fread(buffer
, 1, max
, f
);
1329 shader
= _mesa_strdup(buffer
);
1337 * Called via glShaderSource() and glShaderSourceARB() API functions.
1338 * Basically, concatenate the source code strings into one long string
1339 * and pass it to _mesa_shader_source().
1342 _mesa_ShaderSource(GLhandleARB shaderObj
, GLsizei count
,
1343 const GLcharARB
* const * string
, const GLint
* length
)
1345 GET_CURRENT_CONTEXT(ctx
);
1347 GLsizei i
, totalLength
;
1351 if (!shaderObj
|| string
== NULL
) {
1352 _mesa_error(ctx
, GL_INVALID_VALUE
, "glShaderSourceARB");
1357 * This array holds offsets of where the appropriate string ends, thus the
1358 * last element will be set to the total length of the source code.
1360 offsets
= malloc(count
* sizeof(GLint
));
1361 if (offsets
== NULL
) {
1362 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glShaderSourceARB");
1366 for (i
= 0; i
< count
; i
++) {
1367 if (string
[i
] == NULL
) {
1368 free((GLvoid
*) offsets
);
1369 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1370 "glShaderSourceARB(null string)");
1373 if (length
== NULL
|| length
[i
] < 0)
1374 offsets
[i
] = strlen(string
[i
]);
1376 offsets
[i
] = length
[i
];
1377 /* accumulate string lengths */
1379 offsets
[i
] += offsets
[i
- 1];
1382 /* Total length of source string is sum off all strings plus two.
1383 * One extra byte for terminating zero, another extra byte to silence
1384 * valgrind warnings in the parser/grammer code.
1386 totalLength
= offsets
[count
- 1] + 2;
1387 source
= malloc(totalLength
* sizeof(GLcharARB
));
1388 if (source
== NULL
) {
1389 free((GLvoid
*) offsets
);
1390 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glShaderSourceARB");
1394 for (i
= 0; i
< count
; i
++) {
1395 GLint start
= (i
> 0) ? offsets
[i
- 1] : 0;
1396 memcpy(source
+ start
, string
[i
],
1397 (offsets
[i
] - start
) * sizeof(GLcharARB
));
1399 source
[totalLength
- 1] = '\0';
1400 source
[totalLength
- 2] = '\0';
1403 /* Compute the shader's source code checksum then try to open a file
1404 * named newshader_<CHECKSUM>. If it exists, use it in place of the
1405 * original shader source code. For debugging.
1408 GLcharARB
*newSource
;
1410 checksum
= _mesa_str_checksum(source
);
1412 _mesa_snprintf(filename
, sizeof(filename
), "newshader_%d", checksum
);
1414 newSource
= read_shader(filename
);
1416 fprintf(stderr
, "Mesa: Replacing shader %u chksum=%d with %s\n",
1417 shaderObj
, checksum
, filename
);
1423 shader_source(ctx
, shaderObj
, source
);
1426 struct gl_shader
*sh
= _mesa_lookup_shader(ctx
, shaderObj
);
1428 sh
->SourceChecksum
= checksum
; /* save original checksum */
1436 _mesa_UseProgram(GLhandleARB program
)
1438 GET_CURRENT_CONTEXT(ctx
);
1439 struct gl_shader_program
*shProg
;
1441 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
1442 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1443 "glUseProgram(transform feedback active)");
1448 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glUseProgram");
1452 if (!shProg
->LinkStatus
) {
1453 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1454 "glUseProgram(program %u not linked)", program
);
1459 if (ctx
->Shader
.Flags
& GLSL_USE_PROG
) {
1460 print_shader_info(shProg
);
1467 _mesa_use_program(ctx
, shProg
);
1472 _mesa_ValidateProgram(GLhandleARB program
)
1474 GET_CURRENT_CONTEXT(ctx
);
1475 validate_program(ctx
, program
);
1480 * For OpenGL ES 2.0, GL_ARB_ES2_compatibility
1483 _mesa_GetShaderPrecisionFormat(GLenum shadertype
, GLenum precisiontype
,
1484 GLint
* range
, GLint
* precision
)
1486 const struct gl_program_constants
*limits
;
1487 const struct gl_precision
*p
;
1488 GET_CURRENT_CONTEXT(ctx
);
1490 switch (shadertype
) {
1491 case GL_VERTEX_SHADER
:
1492 limits
= &ctx
->Const
.VertexProgram
;
1494 case GL_FRAGMENT_SHADER
:
1495 limits
= &ctx
->Const
.FragmentProgram
;
1498 _mesa_error(ctx
, GL_INVALID_ENUM
,
1499 "glGetShaderPrecisionFormat(shadertype)");
1503 switch (precisiontype
) {
1505 p
= &limits
->LowFloat
;
1507 case GL_MEDIUM_FLOAT
:
1508 p
= &limits
->MediumFloat
;
1511 p
= &limits
->HighFloat
;
1514 p
= &limits
->LowInt
;
1517 p
= &limits
->MediumInt
;
1520 p
= &limits
->HighInt
;
1523 _mesa_error(ctx
, GL_INVALID_ENUM
,
1524 "glGetShaderPrecisionFormat(precisiontype)");
1528 range
[0] = p
->RangeMin
;
1529 range
[1] = p
->RangeMax
;
1530 precision
[0] = p
->Precision
;
1535 * For OpenGL ES 2.0, GL_ARB_ES2_compatibility
1538 _mesa_ReleaseShaderCompiler(void)
1540 _mesa_destroy_shader_compiler_caches();
1545 * For OpenGL ES 2.0, GL_ARB_ES2_compatibility
1548 _mesa_ShaderBinary(GLint n
, const GLuint
* shaders
, GLenum binaryformat
,
1549 const void* binary
, GLint length
)
1551 GET_CURRENT_CONTEXT(ctx
);
1554 (void) binaryformat
;
1557 _mesa_error(ctx
, GL_INVALID_OPERATION
, __FUNCTION__
);
1562 _mesa_GetProgramBinary(GLuint program
, GLsizei bufSize
, GLsizei
*length
,
1563 GLenum
*binaryFormat
, GLvoid
*binary
)
1565 struct gl_shader_program
*shProg
;
1566 GET_CURRENT_CONTEXT(ctx
);
1568 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glGetProgramBinary");
1572 if (!shProg
->LinkStatus
) {
1573 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1574 "glGetProgramBinary(program %u not linked)",
1580 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramBinary(bufSize < 0)");
1584 /* The ARB_get_program_binary spec says:
1586 * "If <length> is NULL, then no length is returned."
1591 (void) binaryFormat
;
1596 _mesa_ProgramBinary(GLuint program
, GLenum binaryFormat
,
1597 const GLvoid
*binary
, GLsizei length
)
1599 struct gl_shader_program
*shProg
;
1600 GET_CURRENT_CONTEXT(ctx
);
1602 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glProgramBinary");
1606 (void) binaryFormat
;
1609 _mesa_error(ctx
, GL_INVALID_OPERATION
, __FUNCTION__
);
1614 _mesa_ProgramParameteri(GLuint program
, GLenum pname
, GLint value
)
1616 struct gl_shader_program
*shProg
;
1617 GET_CURRENT_CONTEXT(ctx
);
1619 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
1620 "glProgramParameteri");
1625 case GL_GEOMETRY_VERTICES_OUT_ARB
:
1626 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_geometry_shader4
)
1630 (unsigned) value
> ctx
->Const
.MaxGeometryOutputVertices
) {
1631 _mesa_error(ctx
, GL_INVALID_VALUE
,
1632 "glProgramParameteri(GL_GEOMETRY_VERTICES_OUT_ARB=%d",
1636 shProg
->Geom
.VerticesOut
= value
;
1638 case GL_GEOMETRY_INPUT_TYPE_ARB
:
1639 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_geometry_shader4
)
1645 case GL_LINES_ADJACENCY_ARB
:
1647 case GL_TRIANGLES_ADJACENCY_ARB
:
1648 shProg
->Geom
.InputType
= value
;
1651 _mesa_error(ctx
, GL_INVALID_VALUE
,
1652 "glProgramParameteri(geometry input type = %s",
1653 _mesa_lookup_enum_by_nr(value
));
1657 case GL_GEOMETRY_OUTPUT_TYPE_ARB
:
1658 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_geometry_shader4
)
1664 case GL_TRIANGLE_STRIP
:
1665 shProg
->Geom
.OutputType
= value
;
1668 _mesa_error(ctx
, GL_INVALID_VALUE
,
1669 "glProgramParameteri(geometry output type = %s",
1670 _mesa_lookup_enum_by_nr(value
));
1674 case GL_PROGRAM_BINARY_RETRIEVABLE_HINT
:
1675 /* This enum isn't part of the OES extension for OpenGL ES 2.0, but it
1676 * is part of OpenGL ES 3.0. For the ES2 case, this function shouldn't
1677 * even be in the dispatch table, so we shouldn't need to expclicitly
1680 * On desktop, we ignore the 3.0+ requirement because it is silly.
1683 /* The ARB_get_program_binary extension spec says:
1685 * "An INVALID_VALUE error is generated if the <value> argument to
1686 * ProgramParameteri is not TRUE or FALSE."
1688 if (value
!= GL_TRUE
&& value
!= GL_FALSE
) {
1689 _mesa_error(ctx
, GL_INVALID_VALUE
,
1690 "glProgramParameteri(pname=%s, value=%d): "
1691 "value must be 0 or 1.",
1692 _mesa_lookup_enum_by_nr(pname
),
1697 /* No need to notify the driver. Any changes will actually take effect
1698 * the next time the shader is linked.
1700 * The ARB_get_program_binary extension spec says:
1702 * "To indicate that a program binary is likely to be retrieved,
1703 * ProgramParameteri should be called with <pname>
1704 * PROGRAM_BINARY_RETRIEVABLE_HINT and <value> TRUE. This setting
1705 * will not be in effect until the next time LinkProgram or
1706 * ProgramBinary has been called successfully."
1708 * The resloution of issue 9 in the extension spec also says:
1710 * "The application may use the PROGRAM_BINARY_RETRIEVABLE_HINT hint
1711 * to indicate to the GL implementation that this program will
1712 * likely be saved with GetProgramBinary at some point. This will
1713 * give the GL implementation the opportunity to track any state
1714 * changes made to the program before being saved such that when it
1715 * is loaded again a recompile can be avoided."
1717 shProg
->BinaryRetreivableHint
= value
;
1723 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramParameteri(pname=%s)",
1724 _mesa_lookup_enum_by_nr(pname
));
1728 _mesa_use_shader_program(struct gl_context
*ctx
, GLenum type
,
1729 struct gl_shader_program
*shProg
)
1731 use_shader_program(ctx
, type
, shProg
);
1733 if (ctx
->Driver
.UseProgram
)
1734 ctx
->Driver
.UseProgram(ctx
, shProg
);
1739 * For GL_EXT_separate_shader_objects
1742 _mesa_UseShaderProgramEXT(GLenum type
, GLuint program
)
1744 GET_CURRENT_CONTEXT(ctx
);
1745 struct gl_shader_program
*shProg
= NULL
;
1747 if (!validate_shader_target(ctx
, type
)) {
1748 _mesa_error(ctx
, GL_INVALID_ENUM
, "glUseShaderProgramEXT(type)");
1752 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
1753 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1754 "glUseShaderProgramEXT(transform feedback is active)");
1759 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
1760 "glUseShaderProgramEXT");
1764 if (!shProg
->LinkStatus
) {
1765 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1766 "glUseShaderProgramEXT(program not linked)");
1771 _mesa_use_shader_program(ctx
, type
, shProg
);
1776 * For GL_EXT_separate_shader_objects
1779 _mesa_ActiveProgramEXT(GLuint program
)
1781 GET_CURRENT_CONTEXT(ctx
);
1782 struct gl_shader_program
*shProg
= (program
!= 0)
1783 ? _mesa_lookup_shader_program_err(ctx
, program
, "glActiveProgramEXT")
1786 _mesa_active_program(ctx
, shProg
, "glActiveProgramEXT");
1792 * For GL_EXT_separate_shader_objects
1795 _mesa_CreateShaderProgramEXT(GLenum type
, const GLchar
*string
)
1797 GET_CURRENT_CONTEXT(ctx
);
1798 const GLuint shader
= create_shader(ctx
, type
);
1802 shader_source(ctx
, shader
, _mesa_strdup(string
));
1803 compile_shader(ctx
, shader
);
1805 program
= create_shader_program(ctx
);
1807 struct gl_shader_program
*shProg
;
1808 struct gl_shader
*sh
;
1809 GLint compiled
= GL_FALSE
;
1811 shProg
= _mesa_lookup_shader_program(ctx
, program
);
1812 sh
= _mesa_lookup_shader(ctx
, shader
);
1814 get_shaderiv(ctx
, shader
, GL_COMPILE_STATUS
, &compiled
);
1816 attach_shader(ctx
, program
, shader
);
1817 link_program(ctx
, program
);
1818 detach_shader(ctx
, program
, shader
);
1822 if (active
-user
-defined
-varyings
-in
-linked
-program
) {
1823 append
-error
-to
-info
-log
;
1824 shProg
->LinkStatus
= GL_FALSE
;
1829 ralloc_strcat(&shProg
->InfoLog
, sh
->InfoLog
);
1832 delete_shader(ctx
, shader
);