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 * 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.
29 * Implementation of GLSL-related API functions.
30 * The glUniform* functions are in uniforms.c
34 * 1. Check that the right error code is generated for all _mesa_error() calls.
35 * 2. Insert FLUSH_VERTICES calls in various places
39 #include "main/glheader.h"
40 #include "main/context.h"
41 #include "main/dispatch.h"
42 #include "main/enums.h"
43 #include "main/hash.h"
44 #include "main/mfeatures.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_parameter.h"
54 #include "../glsl/glsl_parser_extras.h"
55 #include "../glsl/ir_uniform.h"
57 /** Define this to enable shader substitution (see below) */
58 #define SHADER_SUBST 0
62 * Return mask of GLSL_x flags by examining the MESA_GLSL env var.
65 get_shader_flags(void)
67 GLbitfield flags
= 0x0;
68 const char *env
= _mesa_getenv("MESA_GLSL");
71 if (strstr(env
, "dump"))
73 if (strstr(env
, "log"))
75 if (strstr(env
, "nopvert"))
76 flags
|= GLSL_NOP_VERT
;
77 if (strstr(env
, "nopfrag"))
78 flags
|= GLSL_NOP_FRAG
;
79 if (strstr(env
, "nopt"))
81 else if (strstr(env
, "opt"))
83 if (strstr(env
, "uniform"))
84 flags
|= GLSL_UNIFORMS
;
85 if (strstr(env
, "useprog"))
86 flags
|= GLSL_USE_PROG
;
87 if (strstr(env
, "errors"))
88 flags
|= GLSL_REPORT_ERRORS
;
96 * Initialize context's shader state.
99 _mesa_init_shader_state(struct gl_context
*ctx
)
101 /* Device drivers may override these to control what kind of instructions
102 * are generated by the GLSL compiler.
104 struct gl_shader_compiler_options options
;
107 memset(&options
, 0, sizeof(options
));
108 options
.MaxUnrollIterations
= 32;
109 options
.MaxIfDepth
= UINT_MAX
;
111 /* Default pragma settings */
112 options
.DefaultPragmas
.Optimize
= GL_TRUE
;
114 for (sh
= 0; sh
< MESA_SHADER_TYPES
; ++sh
)
115 memcpy(&ctx
->ShaderCompilerOptions
[sh
], &options
, sizeof(options
));
117 ctx
->Shader
.Flags
= get_shader_flags();
122 * Free the per-context shader-related state.
125 _mesa_free_shader_state(struct gl_context
*ctx
)
127 _mesa_reference_shader_program(ctx
, &ctx
->Shader
.CurrentVertexProgram
, NULL
);
128 _mesa_reference_shader_program(ctx
, &ctx
->Shader
.CurrentGeometryProgram
,
130 _mesa_reference_shader_program(ctx
, &ctx
->Shader
.CurrentFragmentProgram
,
132 _mesa_reference_shader_program(ctx
, &ctx
->Shader
._CurrentFragmentProgram
,
134 _mesa_reference_shader_program(ctx
, &ctx
->Shader
.ActiveProgram
, NULL
);
139 * Copy string from <src> to <dst>, up to maxLength characters, returning
140 * length of <dst> in <length>.
141 * \param src the strings source
142 * \param maxLength max chars to copy
143 * \param length returns number of chars copied
144 * \param dst the string destination
147 _mesa_copy_string(GLchar
*dst
, GLsizei maxLength
,
148 GLsizei
*length
, const GLchar
*src
)
151 for (len
= 0; len
< maxLength
- 1 && src
&& src
[len
]; len
++)
162 * Confirm that the a shader type is valid and supported by the implementation
164 * \param ctx Current GL context
165 * \param type Shader target
169 validate_shader_target(const struct gl_context
*ctx
, GLenum type
)
172 case GL_FRAGMENT_SHADER
:
173 return ctx
->Extensions
.ARB_fragment_shader
;
174 case GL_VERTEX_SHADER
:
175 return ctx
->Extensions
.ARB_vertex_shader
;
176 case GL_GEOMETRY_SHADER_ARB
:
177 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_geometry_shader4
;
185 is_program(struct gl_context
*ctx
, GLuint name
)
187 struct gl_shader_program
*shProg
= _mesa_lookup_shader_program(ctx
, name
);
188 return shProg
? GL_TRUE
: GL_FALSE
;
193 is_shader(struct gl_context
*ctx
, GLuint name
)
195 struct gl_shader
*shader
= _mesa_lookup_shader(ctx
, name
);
196 return shader
? GL_TRUE
: GL_FALSE
;
201 * Attach shader to a shader program.
204 attach_shader(struct gl_context
*ctx
, GLuint program
, GLuint shader
)
206 struct gl_shader_program
*shProg
;
207 struct gl_shader
*sh
;
210 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glAttachShader");
214 sh
= _mesa_lookup_shader_err(ctx
, shader
, "glAttachShader");
219 n
= shProg
->NumShaders
;
220 for (i
= 0; i
< n
; i
++) {
221 if (shProg
->Shaders
[i
] == sh
) {
222 /* The shader is already attched to this program. The
223 * GL_ARB_shader_objects spec says:
225 * "The error INVALID_OPERATION is generated by AttachObjectARB
226 * if <obj> is already attached to <containerObj>."
228 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glAttachShader");
234 shProg
->Shaders
= (struct gl_shader
**)
235 _mesa_realloc(shProg
->Shaders
,
236 n
* sizeof(struct gl_shader
*),
237 (n
+ 1) * sizeof(struct gl_shader
*));
238 if (!shProg
->Shaders
) {
239 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glAttachShader");
244 shProg
->Shaders
[n
] = NULL
; /* since realloc() didn't zero the new space */
245 _mesa_reference_shader(ctx
, &shProg
->Shaders
[n
], sh
);
246 shProg
->NumShaders
++;
251 create_shader(struct gl_context
*ctx
, GLenum type
)
253 struct gl_shader
*sh
;
256 if (!validate_shader_target(ctx
, type
)) {
257 _mesa_error(ctx
, GL_INVALID_ENUM
, "CreateShader(type)");
261 name
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->ShaderObjects
, 1);
262 sh
= ctx
->Driver
.NewShader(ctx
, name
, type
);
263 _mesa_HashInsert(ctx
->Shared
->ShaderObjects
, name
, sh
);
270 create_shader_program(struct gl_context
*ctx
)
273 struct gl_shader_program
*shProg
;
275 name
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->ShaderObjects
, 1);
277 shProg
= ctx
->Driver
.NewShaderProgram(ctx
, name
);
279 _mesa_HashInsert(ctx
->Shared
->ShaderObjects
, name
, shProg
);
281 assert(shProg
->RefCount
== 1);
288 * Named w/ "2" to indicate OpenGL 2.x vs GL_ARB_fragment_programs's
292 delete_shader_program(struct gl_context
*ctx
, GLuint name
)
295 * NOTE: deleting shaders/programs works a bit differently than
296 * texture objects (and buffer objects, etc). Shader/program
297 * handles/IDs exist in the hash table until the object is really
298 * deleted (refcount==0). With texture objects, the handle/ID is
299 * removed from the hash table in glDeleteTextures() while the tex
300 * object itself might linger until its refcount goes to zero.
302 struct gl_shader_program
*shProg
;
304 shProg
= _mesa_lookup_shader_program_err(ctx
, name
, "glDeleteProgram");
308 if (!shProg
->DeletePending
) {
309 shProg
->DeletePending
= GL_TRUE
;
311 /* effectively, decr shProg's refcount */
312 _mesa_reference_shader_program(ctx
, &shProg
, NULL
);
318 delete_shader(struct gl_context
*ctx
, GLuint shader
)
320 struct gl_shader
*sh
;
322 sh
= _mesa_lookup_shader_err(ctx
, shader
, "glDeleteShader");
326 if (!sh
->DeletePending
) {
327 sh
->DeletePending
= GL_TRUE
;
329 /* effectively, decr sh's refcount */
330 _mesa_reference_shader(ctx
, &sh
, NULL
);
336 detach_shader(struct gl_context
*ctx
, GLuint program
, GLuint shader
)
338 struct gl_shader_program
*shProg
;
342 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glDetachShader");
346 n
= shProg
->NumShaders
;
348 for (i
= 0; i
< n
; i
++) {
349 if (shProg
->Shaders
[i
]->Name
== shader
) {
351 struct gl_shader
**newList
;
354 _mesa_reference_shader(ctx
, &shProg
->Shaders
[i
], NULL
);
356 /* alloc new, smaller array */
358 malloc((n
- 1) * sizeof(struct gl_shader
*));
360 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glDetachShader");
363 for (j
= 0; j
< i
; j
++) {
364 newList
[j
] = shProg
->Shaders
[j
];
367 newList
[j
++] = shProg
->Shaders
[i
];
368 free(shProg
->Shaders
);
370 shProg
->Shaders
= newList
;
371 shProg
->NumShaders
= n
- 1;
376 for (j
= 0; j
< shProg
->NumShaders
; j
++) {
377 assert(shProg
->Shaders
[j
]->Type
== GL_VERTEX_SHADER
||
378 shProg
->Shaders
[j
]->Type
== GL_FRAGMENT_SHADER
);
379 assert(shProg
->Shaders
[j
]->RefCount
> 0);
391 if (is_shader(ctx
, shader
))
392 err
= GL_INVALID_OPERATION
;
393 else if (is_program(ctx
, shader
))
394 err
= GL_INVALID_OPERATION
;
396 err
= GL_INVALID_VALUE
;
397 _mesa_error(ctx
, err
, "glDetachProgram(shader)");
404 * Return list of shaders attached to shader program.
407 get_attached_shaders(struct gl_context
*ctx
, GLuint program
, GLsizei maxCount
,
408 GLsizei
*count
, GLuint
*obj
)
410 struct gl_shader_program
*shProg
=
411 _mesa_lookup_shader_program_err(ctx
, program
, "glGetAttachedShaders");
414 for (i
= 0; i
< (GLuint
) maxCount
&& i
< shProg
->NumShaders
; i
++) {
415 obj
[i
] = shProg
->Shaders
[i
]->Name
;
424 * glGetHandleARB() - return ID/name of currently bound shader program.
427 get_handle(struct gl_context
*ctx
, GLenum pname
)
429 if (pname
== GL_PROGRAM_OBJECT_ARB
) {
430 if (ctx
->Shader
.ActiveProgram
)
431 return ctx
->Shader
.ActiveProgram
->Name
;
436 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetHandleARB");
443 * glGetProgramiv() - get shader program state.
444 * Note that this is for GLSL shader programs, not ARB vertex/fragment
445 * programs (see glGetProgramivARB).
448 get_programiv(struct gl_context
*ctx
, GLuint program
, GLenum pname
, GLint
*params
)
450 struct gl_shader_program
*shProg
451 = _mesa_lookup_shader_program(ctx
, program
);
453 /* Is transform feedback available in this context?
456 (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.EXT_transform_feedback
)
457 || ctx
->API
== API_OPENGL_CORE
458 || _mesa_is_gles3(ctx
);
460 /* Are geometry shaders available in this context?
463 _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_geometry_shader4
;
465 /* Are uniform buffer objects available in this context?
468 (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_uniform_buffer_object
)
469 || ctx
->API
== API_OPENGL_CORE
470 || _mesa_is_gles3(ctx
);
473 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramiv(program)");
478 case GL_DELETE_STATUS
:
479 *params
= shProg
->DeletePending
;
482 *params
= shProg
->LinkStatus
;
484 case GL_VALIDATE_STATUS
:
485 *params
= shProg
->Validated
;
487 case GL_INFO_LOG_LENGTH
:
488 *params
= shProg
->InfoLog
? strlen(shProg
->InfoLog
) + 1 : 0;
490 case GL_ATTACHED_SHADERS
:
491 *params
= shProg
->NumShaders
;
493 case GL_ACTIVE_ATTRIBUTES
:
494 *params
= _mesa_count_active_attribs(shProg
);
496 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
:
497 *params
= _mesa_longest_attribute_name_length(shProg
);
499 case GL_ACTIVE_UNIFORMS
:
500 *params
= shProg
->NumUserUniformStorage
;
502 case GL_ACTIVE_UNIFORM_MAX_LENGTH
: {
506 for (i
= 0; i
< shProg
->NumUserUniformStorage
; i
++) {
507 /* Add one for the terminating NUL character.
509 const GLint len
= strlen(shProg
->UniformStorage
[i
].name
) + 1;
518 case GL_TRANSFORM_FEEDBACK_VARYINGS
:
521 *params
= shProg
->TransformFeedback
.NumVarying
;
523 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH
: {
529 for (i
= 0; i
< shProg
->TransformFeedback
.NumVarying
; i
++) {
530 /* Add one for the terminating NUL character.
532 const GLint len
= strlen(shProg
->TransformFeedback
.VaryingNames
[i
]) + 1;
541 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE
:
544 *params
= shProg
->TransformFeedback
.BufferMode
;
546 case GL_GEOMETRY_VERTICES_OUT_ARB
:
549 *params
= shProg
->Geom
.VerticesOut
;
551 case GL_GEOMETRY_INPUT_TYPE_ARB
:
554 *params
= shProg
->Geom
.InputType
;
556 case GL_GEOMETRY_OUTPUT_TYPE_ARB
:
559 *params
= shProg
->Geom
.OutputType
;
561 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH
: {
568 for (i
= 0; i
< shProg
->NumUniformBlocks
; i
++) {
569 /* Add one for the terminating NUL character.
571 const GLint len
= strlen(shProg
->UniformBlocks
[i
].Name
) + 1;
580 case GL_ACTIVE_UNIFORM_BLOCKS
:
584 *params
= shProg
->NumUniformBlocks
;
586 case GL_PROGRAM_BINARY_RETRIEVABLE_HINT
:
587 /* This enum isn't part of the OES extension for OpenGL ES 2.0. It is
588 * only available with desktop OpenGL 3.0+ with the
589 * GL_ARB_get_program_binary extension or OpenGL ES 3.0.
591 * On desktop, we ignore the 3.0+ requirement because it is silly.
593 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
596 *params
= shProg
->BinaryRetreivableHint
;
598 case GL_PROGRAM_BINARY_LENGTH
:
605 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramiv(pname=%s)",
606 _mesa_lookup_enum_by_nr(pname
));
611 * glGetShaderiv() - get GLSL shader state
614 get_shaderiv(struct gl_context
*ctx
, GLuint name
, GLenum pname
, GLint
*params
)
616 struct gl_shader
*shader
=
617 _mesa_lookup_shader_err(ctx
, name
, "glGetShaderiv");
625 *params
= shader
->Type
;
627 case GL_DELETE_STATUS
:
628 *params
= shader
->DeletePending
;
630 case GL_COMPILE_STATUS
:
631 *params
= shader
->CompileStatus
;
633 case GL_INFO_LOG_LENGTH
:
634 *params
= shader
->InfoLog
? strlen(shader
->InfoLog
) + 1 : 0;
636 case GL_SHADER_SOURCE_LENGTH
:
637 *params
= shader
->Source
? strlen((char *) shader
->Source
) + 1 : 0;
640 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetShaderiv(pname)");
647 get_program_info_log(struct gl_context
*ctx
, GLuint program
, GLsizei bufSize
,
648 GLsizei
*length
, GLchar
*infoLog
)
650 struct gl_shader_program
*shProg
651 = _mesa_lookup_shader_program(ctx
, program
);
653 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramInfoLog(program)");
656 _mesa_copy_string(infoLog
, bufSize
, length
, shProg
->InfoLog
);
661 get_shader_info_log(struct gl_context
*ctx
, GLuint shader
, GLsizei bufSize
,
662 GLsizei
*length
, GLchar
*infoLog
)
664 struct gl_shader
*sh
= _mesa_lookup_shader(ctx
, shader
);
666 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetShaderInfoLog(shader)");
669 _mesa_copy_string(infoLog
, bufSize
, length
, sh
->InfoLog
);
674 * Return shader source code.
677 get_shader_source(struct gl_context
*ctx
, GLuint shader
, GLsizei maxLength
,
678 GLsizei
*length
, GLchar
*sourceOut
)
680 struct gl_shader
*sh
;
681 sh
= _mesa_lookup_shader_err(ctx
, shader
, "glGetShaderSource");
685 _mesa_copy_string(sourceOut
, maxLength
, length
, sh
->Source
);
690 * Set/replace shader source code. A helper function used by
691 * glShaderSource[ARB] and glCreateShaderProgramEXT.
694 shader_source(struct gl_context
*ctx
, GLuint shader
, const GLchar
*source
)
696 struct gl_shader
*sh
;
698 sh
= _mesa_lookup_shader_err(ctx
, shader
, "glShaderSource");
702 /* free old shader source string and install new one */
703 free((void *)sh
->Source
);
705 sh
->CompileStatus
= GL_FALSE
;
707 sh
->SourceChecksum
= _mesa_str_checksum(sh
->Source
);
716 compile_shader(struct gl_context
*ctx
, GLuint shaderObj
)
718 struct gl_shader
*sh
;
719 struct gl_shader_compiler_options
*options
;
721 sh
= _mesa_lookup_shader_err(ctx
, shaderObj
, "glCompileShader");
725 options
= &ctx
->ShaderCompilerOptions
[_mesa_shader_type_to_index(sh
->Type
)];
727 /* set default pragma state for shader */
728 sh
->Pragmas
= options
->DefaultPragmas
;
730 /* this call will set the sh->CompileStatus field to indicate if
731 * compilation was successful.
733 _mesa_glsl_compile_shader(ctx
, sh
);
735 if (sh
->CompileStatus
== GL_FALSE
&&
736 (ctx
->Shader
.Flags
& GLSL_REPORT_ERRORS
)) {
737 _mesa_debug(ctx
, "Error compiling shader %u:\n%s\n",
738 sh
->Name
, sh
->InfoLog
);
744 * Link a program's shaders.
747 link_program(struct gl_context
*ctx
, GLuint program
)
749 struct gl_shader_program
*shProg
;
750 struct gl_transform_feedback_object
*obj
=
751 ctx
->TransformFeedback
.CurrentObject
;
753 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glLinkProgram");
758 && (shProg
== ctx
->Shader
.CurrentVertexProgram
759 || shProg
== ctx
->Shader
.CurrentGeometryProgram
760 || shProg
== ctx
->Shader
.CurrentFragmentProgram
)) {
761 _mesa_error(ctx
, GL_INVALID_OPERATION
,
762 "glLinkProgram(transform feedback active)");
766 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
768 _mesa_glsl_link_shader(ctx
, shProg
);
770 if (shProg
->LinkStatus
== GL_FALSE
&&
771 (ctx
->Shader
.Flags
& GLSL_REPORT_ERRORS
)) {
772 _mesa_debug(ctx
, "Error linking program %u:\n%s\n",
773 shProg
->Name
, shProg
->InfoLog
);
780 printf("Link %u shaders in program %u: %s\n",
781 shProg
->NumShaders
, shProg
->Name
,
782 shProg
->LinkStatus
? "Success" : "Failed");
784 for (i
= 0; i
< shProg
->NumShaders
; i
++) {
785 printf(" shader %u, type 0x%x\n",
786 shProg
->Shaders
[i
]->Name
,
787 shProg
->Shaders
[i
]->Type
);
794 * Print basic shader info (for debug).
797 print_shader_info(const struct gl_shader_program
*shProg
)
801 printf("Mesa: glUseProgram(%u)\n", shProg
->Name
);
802 for (i
= 0; i
< shProg
->NumShaders
; i
++) {
804 switch (shProg
->Shaders
[i
]->Type
) {
805 case GL_VERTEX_SHADER
:
808 case GL_FRAGMENT_SHADER
:
811 case GL_GEOMETRY_SHADER
:
817 printf(" %s shader %u, checksum %u\n", s
,
818 shProg
->Shaders
[i
]->Name
,
819 shProg
->Shaders
[i
]->SourceChecksum
);
821 if (shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
])
822 printf(" vert prog %u\n",
823 shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
]->Program
->Id
);
824 if (shProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
])
825 printf(" frag prog %u\n",
826 shProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
]->Program
->Id
);
827 if (shProg
->_LinkedShaders
[MESA_SHADER_GEOMETRY
])
828 printf(" geom prog %u\n",
829 shProg
->_LinkedShaders
[MESA_SHADER_GEOMETRY
]->Program
->Id
);
834 * Use the named shader program for subsequent glUniform calls
837 _mesa_active_program(struct gl_context
*ctx
, struct gl_shader_program
*shProg
,
840 if ((shProg
!= NULL
) && !shProg
->LinkStatus
) {
841 _mesa_error(ctx
, GL_INVALID_OPERATION
,
842 "%s(program %u not linked)", caller
, shProg
->Name
);
846 if (ctx
->Shader
.ActiveProgram
!= shProg
) {
847 _mesa_reference_shader_program(ctx
, &ctx
->Shader
.ActiveProgram
, shProg
);
854 use_shader_program(struct gl_context
*ctx
, GLenum type
,
855 struct gl_shader_program
*shProg
)
857 struct gl_shader_program
**target
;
860 case GL_VERTEX_SHADER
:
861 target
= &ctx
->Shader
.CurrentVertexProgram
;
863 || (shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
)) {
867 case GL_GEOMETRY_SHADER_ARB
:
868 target
= &ctx
->Shader
.CurrentGeometryProgram
;
870 || (shProg
->_LinkedShaders
[MESA_SHADER_GEOMETRY
] == NULL
)) {
874 case GL_FRAGMENT_SHADER
:
875 target
= &ctx
->Shader
.CurrentFragmentProgram
;
877 || (shProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
] == NULL
)) {
885 if (*target
!= shProg
) {
886 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
| _NEW_PROGRAM_CONSTANTS
);
888 /* If the shader is also bound as the current rendering shader, unbind
889 * it from that binding point as well. This ensures that the correct
890 * semantics of glDeleteProgram are maintained.
893 case GL_VERTEX_SHADER
:
896 case GL_GEOMETRY_SHADER_ARB
:
899 case GL_FRAGMENT_SHADER
:
900 if (*target
== ctx
->Shader
._CurrentFragmentProgram
) {
901 _mesa_reference_shader_program(ctx
,
902 &ctx
->Shader
._CurrentFragmentProgram
,
908 _mesa_reference_shader_program(ctx
, target
, shProg
);
916 * Use the named shader program for subsequent rendering.
919 _mesa_use_program(struct gl_context
*ctx
, struct gl_shader_program
*shProg
)
921 use_shader_program(ctx
, GL_VERTEX_SHADER
, shProg
);
922 use_shader_program(ctx
, GL_GEOMETRY_SHADER_ARB
, shProg
);
923 use_shader_program(ctx
, GL_FRAGMENT_SHADER
, shProg
);
924 _mesa_active_program(ctx
, shProg
, "glUseProgram");
926 if (ctx
->Driver
.UseProgram
)
927 ctx
->Driver
.UseProgram(ctx
, shProg
);
932 * Do validation of the given shader program.
933 * \param errMsg returns error message if validation fails.
934 * \return GL_TRUE if valid, GL_FALSE if invalid (and set errMsg)
937 validate_shader_program(const struct gl_shader_program
*shProg
,
940 if (!shProg
->LinkStatus
) {
944 /* From the GL spec, a program is invalid if any of these are true:
946 any two active samplers in the current program object are of
947 different types, but refer to the same texture image unit,
949 any active sampler in the current program object refers to a texture
950 image unit where fixed-function fragment processing accesses a
951 texture target that does not match the sampler type, or
953 the sum of the number of active samplers in the program and the
954 number of texture image units enabled for fixed-function fragment
955 processing exceeds the combined limit on the total number of texture
961 * Check: any two active samplers in the current program object are of
962 * different types, but refer to the same texture image unit,
964 if (!_mesa_sampler_uniforms_are_valid(shProg
, errMsg
, 100))
972 * Called via glValidateProgram()
975 validate_program(struct gl_context
*ctx
, GLuint program
)
977 struct gl_shader_program
*shProg
;
978 char errMsg
[100] = "";
980 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glValidateProgram");
985 shProg
->Validated
= validate_shader_program(shProg
, errMsg
);
986 if (!shProg
->Validated
) {
987 /* update info log */
988 if (shProg
->InfoLog
) {
989 ralloc_free(shProg
->InfoLog
);
991 shProg
->InfoLog
= ralloc_strdup(shProg
, errMsg
);
998 _mesa_AttachObjectARB(GLhandleARB program
, GLhandleARB shader
)
1000 GET_CURRENT_CONTEXT(ctx
);
1001 attach_shader(ctx
, program
, shader
);
1006 _mesa_AttachShader(GLuint program
, GLuint shader
)
1008 GET_CURRENT_CONTEXT(ctx
);
1009 attach_shader(ctx
, program
, shader
);
1014 _mesa_CompileShader(GLhandleARB shaderObj
)
1016 GET_CURRENT_CONTEXT(ctx
);
1017 if (MESA_VERBOSE
& VERBOSE_API
)
1018 _mesa_debug(ctx
, "glCompileShader %u\n", shaderObj
);
1019 compile_shader(ctx
, shaderObj
);
1024 _mesa_CreateShader(GLenum type
)
1026 GET_CURRENT_CONTEXT(ctx
);
1027 if (MESA_VERBOSE
& VERBOSE_API
)
1028 _mesa_debug(ctx
, "glCreateShader %s\n", _mesa_lookup_enum_by_nr(type
));
1029 return create_shader(ctx
, type
);
1033 GLhandleARB GLAPIENTRY
1034 _mesa_CreateShaderObjectARB(GLenum type
)
1036 GET_CURRENT_CONTEXT(ctx
);
1037 return create_shader(ctx
, type
);
1042 _mesa_CreateProgram(void)
1044 GET_CURRENT_CONTEXT(ctx
);
1045 if (MESA_VERBOSE
& VERBOSE_API
)
1046 _mesa_debug(ctx
, "glCreateProgram\n");
1047 return create_shader_program(ctx
);
1051 GLhandleARB GLAPIENTRY
1052 _mesa_CreateProgramObjectARB(void)
1054 GET_CURRENT_CONTEXT(ctx
);
1055 return create_shader_program(ctx
);
1060 _mesa_DeleteObjectARB(GLhandleARB obj
)
1062 if (MESA_VERBOSE
& VERBOSE_API
) {
1063 GET_CURRENT_CONTEXT(ctx
);
1064 _mesa_debug(ctx
, "glDeleteObjectARB(%u)\n", obj
);
1068 GET_CURRENT_CONTEXT(ctx
);
1069 FLUSH_VERTICES(ctx
, 0);
1070 if (is_program(ctx
, obj
)) {
1071 delete_shader_program(ctx
, obj
);
1073 else if (is_shader(ctx
, obj
)) {
1074 delete_shader(ctx
, obj
);
1084 _mesa_DeleteProgram(GLuint name
)
1087 GET_CURRENT_CONTEXT(ctx
);
1088 FLUSH_VERTICES(ctx
, 0);
1089 delete_shader_program(ctx
, name
);
1095 _mesa_DeleteShader(GLuint name
)
1098 GET_CURRENT_CONTEXT(ctx
);
1099 FLUSH_VERTICES(ctx
, 0);
1100 delete_shader(ctx
, name
);
1106 _mesa_DetachObjectARB(GLhandleARB program
, GLhandleARB shader
)
1108 GET_CURRENT_CONTEXT(ctx
);
1109 detach_shader(ctx
, program
, shader
);
1114 _mesa_DetachShader(GLuint program
, GLuint shader
)
1116 GET_CURRENT_CONTEXT(ctx
);
1117 detach_shader(ctx
, program
, shader
);
1122 _mesa_GetAttachedObjectsARB(GLhandleARB container
, GLsizei maxCount
,
1123 GLsizei
* count
, GLhandleARB
* obj
)
1125 GET_CURRENT_CONTEXT(ctx
);
1126 get_attached_shaders(ctx
, container
, maxCount
, count
, obj
);
1131 _mesa_GetAttachedShaders(GLuint program
, GLsizei maxCount
,
1132 GLsizei
*count
, GLuint
*obj
)
1134 GET_CURRENT_CONTEXT(ctx
);
1135 get_attached_shaders(ctx
, program
, maxCount
, count
, obj
);
1140 _mesa_GetInfoLogARB(GLhandleARB object
, GLsizei maxLength
, GLsizei
* length
,
1141 GLcharARB
* infoLog
)
1143 GET_CURRENT_CONTEXT(ctx
);
1144 if (is_program(ctx
, object
)) {
1145 get_program_info_log(ctx
, object
, maxLength
, length
, infoLog
);
1147 else if (is_shader(ctx
, object
)) {
1148 get_shader_info_log(ctx
, object
, maxLength
, length
, infoLog
);
1151 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInfoLogARB");
1157 _mesa_GetObjectParameterivARB(GLhandleARB object
, GLenum pname
, GLint
*params
)
1159 GET_CURRENT_CONTEXT(ctx
);
1160 /* Implement in terms of GetProgramiv, GetShaderiv */
1161 if (is_program(ctx
, object
)) {
1162 if (pname
== GL_OBJECT_TYPE_ARB
) {
1163 *params
= GL_PROGRAM_OBJECT_ARB
;
1166 get_programiv(ctx
, object
, pname
, params
);
1169 else if (is_shader(ctx
, object
)) {
1170 if (pname
== GL_OBJECT_TYPE_ARB
) {
1171 *params
= GL_SHADER_OBJECT_ARB
;
1174 get_shaderiv(ctx
, object
, pname
, params
);
1178 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetObjectParameterivARB");
1184 _mesa_GetObjectParameterfvARB(GLhandleARB object
, GLenum pname
,
1187 GLint iparams
[1]; /* XXX is one element enough? */
1188 _mesa_GetObjectParameterivARB(object
, pname
, iparams
);
1189 params
[0] = (GLfloat
) iparams
[0];
1194 _mesa_GetProgramiv(GLuint program
, GLenum pname
, GLint
*params
)
1196 GET_CURRENT_CONTEXT(ctx
);
1197 get_programiv(ctx
, program
, pname
, params
);
1202 _mesa_GetShaderiv(GLuint shader
, GLenum pname
, GLint
*params
)
1204 GET_CURRENT_CONTEXT(ctx
);
1205 get_shaderiv(ctx
, shader
, pname
, params
);
1210 _mesa_GetProgramInfoLog(GLuint program
, GLsizei bufSize
,
1211 GLsizei
*length
, GLchar
*infoLog
)
1213 GET_CURRENT_CONTEXT(ctx
);
1214 get_program_info_log(ctx
, program
, bufSize
, length
, infoLog
);
1219 _mesa_GetShaderInfoLog(GLuint shader
, GLsizei bufSize
,
1220 GLsizei
*length
, GLchar
*infoLog
)
1222 GET_CURRENT_CONTEXT(ctx
);
1223 get_shader_info_log(ctx
, shader
, bufSize
, length
, infoLog
);
1228 _mesa_GetShaderSource(GLhandleARB shader
, GLsizei maxLength
,
1229 GLsizei
*length
, GLcharARB
*sourceOut
)
1231 GET_CURRENT_CONTEXT(ctx
);
1232 get_shader_source(ctx
, shader
, maxLength
, length
, sourceOut
);
1236 GLhandleARB GLAPIENTRY
1237 _mesa_GetHandleARB(GLenum pname
)
1239 GET_CURRENT_CONTEXT(ctx
);
1240 return get_handle(ctx
, pname
);
1244 GLboolean GLAPIENTRY
1245 _mesa_IsProgram(GLuint name
)
1247 GET_CURRENT_CONTEXT(ctx
);
1248 return is_program(ctx
, name
);
1252 GLboolean GLAPIENTRY
1253 _mesa_IsShader(GLuint name
)
1255 GET_CURRENT_CONTEXT(ctx
);
1256 return is_shader(ctx
, name
);
1261 _mesa_LinkProgram(GLhandleARB programObj
)
1263 GET_CURRENT_CONTEXT(ctx
);
1264 link_program(ctx
, programObj
);
1270 * Read shader source code from a file.
1271 * Useful for debugging to override an app's shader.
1274 read_shader(const char *fname
)
1276 const int max
= 50*1000;
1277 FILE *f
= fopen(fname
, "r");
1278 GLcharARB
*buffer
, *shader
;
1285 buffer
= malloc(max
);
1286 len
= fread(buffer
, 1, max
, f
);
1291 shader
= _mesa_strdup(buffer
);
1299 * Called via glShaderSource() and glShaderSourceARB() API functions.
1300 * Basically, concatenate the source code strings into one long string
1301 * and pass it to _mesa_shader_source().
1304 _mesa_ShaderSource(GLhandleARB shaderObj
, GLsizei count
,
1305 const GLcharARB
* const * string
, const GLint
* length
)
1307 GET_CURRENT_CONTEXT(ctx
);
1309 GLsizei i
, totalLength
;
1313 if (!shaderObj
|| string
== NULL
) {
1314 _mesa_error(ctx
, GL_INVALID_VALUE
, "glShaderSourceARB");
1319 * This array holds offsets of where the appropriate string ends, thus the
1320 * last element will be set to the total length of the source code.
1322 offsets
= malloc(count
* sizeof(GLint
));
1323 if (offsets
== NULL
) {
1324 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glShaderSourceARB");
1328 for (i
= 0; i
< count
; i
++) {
1329 if (string
[i
] == NULL
) {
1330 free((GLvoid
*) offsets
);
1331 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1332 "glShaderSourceARB(null string)");
1335 if (length
== NULL
|| length
[i
] < 0)
1336 offsets
[i
] = strlen(string
[i
]);
1338 offsets
[i
] = length
[i
];
1339 /* accumulate string lengths */
1341 offsets
[i
] += offsets
[i
- 1];
1344 /* Total length of source string is sum off all strings plus two.
1345 * One extra byte for terminating zero, another extra byte to silence
1346 * valgrind warnings in the parser/grammer code.
1348 totalLength
= offsets
[count
- 1] + 2;
1349 source
= malloc(totalLength
* sizeof(GLcharARB
));
1350 if (source
== NULL
) {
1351 free((GLvoid
*) offsets
);
1352 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glShaderSourceARB");
1356 for (i
= 0; i
< count
; i
++) {
1357 GLint start
= (i
> 0) ? offsets
[i
- 1] : 0;
1358 memcpy(source
+ start
, string
[i
],
1359 (offsets
[i
] - start
) * sizeof(GLcharARB
));
1361 source
[totalLength
- 1] = '\0';
1362 source
[totalLength
- 2] = '\0';
1365 /* Compute the shader's source code checksum then try to open a file
1366 * named newshader_<CHECKSUM>. If it exists, use it in place of the
1367 * original shader source code. For debugging.
1370 GLcharARB
*newSource
;
1372 checksum
= _mesa_str_checksum(source
);
1374 _mesa_snprintf(filename
, sizeof(filename
), "newshader_%d", checksum
);
1376 newSource
= read_shader(filename
);
1378 fprintf(stderr
, "Mesa: Replacing shader %u chksum=%d with %s\n",
1379 shaderObj
, checksum
, filename
);
1385 shader_source(ctx
, shaderObj
, source
);
1388 struct gl_shader
*sh
= _mesa_lookup_shader(ctx
, shaderObj
);
1390 sh
->SourceChecksum
= checksum
; /* save original checksum */
1398 _mesa_UseProgram(GLhandleARB program
)
1400 GET_CURRENT_CONTEXT(ctx
);
1401 struct gl_shader_program
*shProg
;
1403 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
1404 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1405 "glUseProgram(transform feedback active)");
1410 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glUseProgram");
1414 if (!shProg
->LinkStatus
) {
1415 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1416 "glUseProgram(program %u not linked)", program
);
1421 if (ctx
->Shader
.Flags
& GLSL_USE_PROG
) {
1422 print_shader_info(shProg
);
1429 _mesa_use_program(ctx
, shProg
);
1434 _mesa_ValidateProgram(GLhandleARB program
)
1436 GET_CURRENT_CONTEXT(ctx
);
1437 validate_program(ctx
, program
);
1443 _mesa_GetShaderPrecisionFormat(GLenum shadertype
, GLenum precisiontype
,
1444 GLint
* range
, GLint
* precision
)
1446 const struct gl_program_constants
*limits
;
1447 const struct gl_precision
*p
;
1448 GET_CURRENT_CONTEXT(ctx
);
1450 switch (shadertype
) {
1451 case GL_VERTEX_SHADER
:
1452 limits
= &ctx
->Const
.VertexProgram
;
1454 case GL_FRAGMENT_SHADER
:
1455 limits
= &ctx
->Const
.FragmentProgram
;
1458 _mesa_error(ctx
, GL_INVALID_ENUM
,
1459 "glGetShaderPrecisionFormat(shadertype)");
1463 switch (precisiontype
) {
1465 p
= &limits
->LowFloat
;
1467 case GL_MEDIUM_FLOAT
:
1468 p
= &limits
->MediumFloat
;
1471 p
= &limits
->HighFloat
;
1474 p
= &limits
->LowInt
;
1477 p
= &limits
->MediumInt
;
1480 p
= &limits
->HighInt
;
1483 _mesa_error(ctx
, GL_INVALID_ENUM
,
1484 "glGetShaderPrecisionFormat(precisiontype)");
1488 range
[0] = p
->RangeMin
;
1489 range
[1] = p
->RangeMax
;
1490 precision
[0] = p
->Precision
;
1495 _mesa_ReleaseShaderCompiler(void)
1497 _mesa_destroy_shader_compiler_caches();
1502 _mesa_ShaderBinary(GLint n
, const GLuint
* shaders
, GLenum binaryformat
,
1503 const void* binary
, GLint length
)
1505 GET_CURRENT_CONTEXT(ctx
);
1508 (void) binaryformat
;
1511 _mesa_error(ctx
, GL_INVALID_OPERATION
, __FUNCTION__
);
1514 #endif /* FEATURE_ES2 */
1517 _mesa_GetProgramBinary(GLuint program
, GLsizei bufSize
, GLsizei
*length
,
1518 GLenum
*binaryFormat
, GLvoid
*binary
)
1520 struct gl_shader_program
*shProg
;
1521 GET_CURRENT_CONTEXT(ctx
);
1523 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glGetProgramBinary");
1527 if (!shProg
->LinkStatus
) {
1528 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1529 "glGetProgramBinary(program %u not linked)",
1535 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramBinary(bufSize < 0)");
1539 /* The ARB_get_program_binary spec says:
1541 * "If <length> is NULL, then no length is returned."
1546 (void) binaryFormat
;
1551 _mesa_ProgramBinary(GLuint program
, GLenum binaryFormat
,
1552 const GLvoid
*binary
, GLsizei length
)
1554 struct gl_shader_program
*shProg
;
1555 GET_CURRENT_CONTEXT(ctx
);
1557 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glProgramBinary");
1561 (void) binaryFormat
;
1564 _mesa_error(ctx
, GL_INVALID_OPERATION
, __FUNCTION__
);
1569 _mesa_ProgramParameteri(GLuint program
, GLenum pname
, GLint value
)
1571 struct gl_shader_program
*shProg
;
1572 GET_CURRENT_CONTEXT(ctx
);
1574 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
1575 "glProgramParameteri");
1580 case GL_GEOMETRY_VERTICES_OUT_ARB
:
1581 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_geometry_shader4
)
1585 (unsigned) value
> ctx
->Const
.MaxGeometryOutputVertices
) {
1586 _mesa_error(ctx
, GL_INVALID_VALUE
,
1587 "glProgramParameteri(GL_GEOMETRY_VERTICES_OUT_ARB=%d",
1591 shProg
->Geom
.VerticesOut
= value
;
1593 case GL_GEOMETRY_INPUT_TYPE_ARB
:
1594 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_geometry_shader4
)
1600 case GL_LINES_ADJACENCY_ARB
:
1602 case GL_TRIANGLES_ADJACENCY_ARB
:
1603 shProg
->Geom
.InputType
= value
;
1606 _mesa_error(ctx
, GL_INVALID_VALUE
,
1607 "glProgramParameteri(geometry input type = %s",
1608 _mesa_lookup_enum_by_nr(value
));
1612 case GL_GEOMETRY_OUTPUT_TYPE_ARB
:
1613 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_geometry_shader4
)
1619 case GL_TRIANGLE_STRIP
:
1620 shProg
->Geom
.OutputType
= value
;
1623 _mesa_error(ctx
, GL_INVALID_VALUE
,
1624 "glProgramParameteri(geometry output type = %s",
1625 _mesa_lookup_enum_by_nr(value
));
1629 case GL_PROGRAM_BINARY_RETRIEVABLE_HINT
:
1630 /* This enum isn't part of the OES extension for OpenGL ES 2.0, but it
1631 * is part of OpenGL ES 3.0. For the ES2 case, this function shouldn't
1632 * even be in the dispatch table, so we shouldn't need to expclicitly
1635 * On desktop, we ignore the 3.0+ requirement because it is silly.
1638 /* The ARB_get_program_binary extension spec says:
1640 * "An INVALID_VALUE error is generated if the <value> argument to
1641 * ProgramParameteri is not TRUE or FALSE."
1643 if (value
!= GL_TRUE
&& value
!= GL_FALSE
) {
1644 _mesa_error(ctx
, GL_INVALID_VALUE
,
1645 "glProgramParameteri(pname=%s, value=%d): "
1646 "value must be 0 or 1.",
1647 _mesa_lookup_enum_by_nr(pname
),
1652 /* No need to notify the driver. Any changes will actually take effect
1653 * the next time the shader is linked.
1655 * The ARB_get_program_binary extension spec says:
1657 * "To indicate that a program binary is likely to be retrieved,
1658 * ProgramParameteri should be called with <pname>
1659 * PROGRAM_BINARY_RETRIEVABLE_HINT and <value> TRUE. This setting
1660 * will not be in effect until the next time LinkProgram or
1661 * ProgramBinary has been called successfully."
1663 * The resloution of issue 9 in the extension spec also says:
1665 * "The application may use the PROGRAM_BINARY_RETRIEVABLE_HINT hint
1666 * to indicate to the GL implementation that this program will
1667 * likely be saved with GetProgramBinary at some point. This will
1668 * give the GL implementation the opportunity to track any state
1669 * changes made to the program before being saved such that when it
1670 * is loaded again a recompile can be avoided."
1672 shProg
->BinaryRetreivableHint
= value
;
1678 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramParameteri(pname=%s)",
1679 _mesa_lookup_enum_by_nr(pname
));
1683 _mesa_use_shader_program(struct gl_context
*ctx
, GLenum type
,
1684 struct gl_shader_program
*shProg
)
1686 use_shader_program(ctx
, type
, shProg
);
1688 if (ctx
->Driver
.UseProgram
)
1689 ctx
->Driver
.UseProgram(ctx
, shProg
);
1694 * For GL_EXT_separate_shader_objects
1697 _mesa_UseShaderProgramEXT(GLenum type
, GLuint program
)
1699 GET_CURRENT_CONTEXT(ctx
);
1700 struct gl_shader_program
*shProg
= NULL
;
1702 if (!validate_shader_target(ctx
, type
)) {
1703 _mesa_error(ctx
, GL_INVALID_ENUM
, "glUseShaderProgramEXT(type)");
1707 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
1708 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1709 "glUseShaderProgramEXT(transform feedback is active)");
1714 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
1715 "glUseShaderProgramEXT");
1719 if (!shProg
->LinkStatus
) {
1720 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1721 "glUseShaderProgramEXT(program not linked)");
1726 _mesa_use_shader_program(ctx
, type
, shProg
);
1731 * For GL_EXT_separate_shader_objects
1734 _mesa_ActiveProgramEXT(GLuint program
)
1736 GET_CURRENT_CONTEXT(ctx
);
1737 struct gl_shader_program
*shProg
= (program
!= 0)
1738 ? _mesa_lookup_shader_program_err(ctx
, program
, "glActiveProgramEXT")
1741 _mesa_active_program(ctx
, shProg
, "glActiveProgramEXT");
1747 * For GL_EXT_separate_shader_objects
1750 _mesa_CreateShaderProgramEXT(GLenum type
, const GLchar
*string
)
1752 GET_CURRENT_CONTEXT(ctx
);
1753 const GLuint shader
= create_shader(ctx
, type
);
1757 shader_source(ctx
, shader
, _mesa_strdup(string
));
1758 compile_shader(ctx
, shader
);
1760 program
= create_shader_program(ctx
);
1762 struct gl_shader_program
*shProg
;
1763 struct gl_shader
*sh
;
1764 GLint compiled
= GL_FALSE
;
1766 shProg
= _mesa_lookup_shader_program(ctx
, program
);
1767 sh
= _mesa_lookup_shader(ctx
, shader
);
1769 get_shaderiv(ctx
, shader
, GL_COMPILE_STATUS
, &compiled
);
1771 attach_shader(ctx
, program
, shader
);
1772 link_program(ctx
, program
);
1773 detach_shader(ctx
, program
, shader
);
1777 if (active
-user
-defined
-varyings
-in
-linked
-program
) {
1778 append
-error
-to
-info
-log
;
1779 shProg
->LinkStatus
= GL_FALSE
;
1784 ralloc_strcat(&shProg
->InfoLog
, sh
->InfoLog
);
1787 delete_shader(ctx
, shader
);