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 const bool same_type_disallowed
= _mesa_is_gles(ctx
);
212 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glAttachShader");
216 sh
= _mesa_lookup_shader_err(ctx
, shader
, "glAttachShader");
221 n
= shProg
->NumShaders
;
222 for (i
= 0; i
< n
; i
++) {
223 if (shProg
->Shaders
[i
] == sh
) {
224 /* The shader is already attched to this program. The
225 * GL_ARB_shader_objects spec says:
227 * "The error INVALID_OPERATION is generated by AttachObjectARB
228 * if <obj> is already attached to <containerObj>."
230 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glAttachShader");
232 } else if (same_type_disallowed
&&
233 shProg
->Shaders
[i
]->Type
== sh
->Type
) {
234 /* Shader with the same type is already attached to this program,
235 * OpenGL ES 2.0 and 3.0 specs say:
237 * "Multiple shader objects of the same type may not be attached
238 * to a single program object. [...] The error INVALID_OPERATION
239 * is generated if [...] another shader object of the same type
240 * as shader is already attached to program."
242 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glAttachShader");
248 shProg
->Shaders
= (struct gl_shader
**)
249 _mesa_realloc(shProg
->Shaders
,
250 n
* sizeof(struct gl_shader
*),
251 (n
+ 1) * sizeof(struct gl_shader
*));
252 if (!shProg
->Shaders
) {
253 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glAttachShader");
258 shProg
->Shaders
[n
] = NULL
; /* since realloc() didn't zero the new space */
259 _mesa_reference_shader(ctx
, &shProg
->Shaders
[n
], sh
);
260 shProg
->NumShaders
++;
265 create_shader(struct gl_context
*ctx
, GLenum type
)
267 struct gl_shader
*sh
;
270 if (!validate_shader_target(ctx
, type
)) {
271 _mesa_error(ctx
, GL_INVALID_ENUM
, "CreateShader(type)");
275 name
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->ShaderObjects
, 1);
276 sh
= ctx
->Driver
.NewShader(ctx
, name
, type
);
277 _mesa_HashInsert(ctx
->Shared
->ShaderObjects
, name
, sh
);
284 create_shader_program(struct gl_context
*ctx
)
287 struct gl_shader_program
*shProg
;
289 name
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->ShaderObjects
, 1);
291 shProg
= ctx
->Driver
.NewShaderProgram(ctx
, name
);
293 _mesa_HashInsert(ctx
->Shared
->ShaderObjects
, name
, shProg
);
295 assert(shProg
->RefCount
== 1);
302 * Named w/ "2" to indicate OpenGL 2.x vs GL_ARB_fragment_programs's
306 delete_shader_program(struct gl_context
*ctx
, GLuint name
)
309 * NOTE: deleting shaders/programs works a bit differently than
310 * texture objects (and buffer objects, etc). Shader/program
311 * handles/IDs exist in the hash table until the object is really
312 * deleted (refcount==0). With texture objects, the handle/ID is
313 * removed from the hash table in glDeleteTextures() while the tex
314 * object itself might linger until its refcount goes to zero.
316 struct gl_shader_program
*shProg
;
318 shProg
= _mesa_lookup_shader_program_err(ctx
, name
, "glDeleteProgram");
322 if (!shProg
->DeletePending
) {
323 shProg
->DeletePending
= GL_TRUE
;
325 /* effectively, decr shProg's refcount */
326 _mesa_reference_shader_program(ctx
, &shProg
, NULL
);
332 delete_shader(struct gl_context
*ctx
, GLuint shader
)
334 struct gl_shader
*sh
;
336 sh
= _mesa_lookup_shader_err(ctx
, shader
, "glDeleteShader");
340 if (!sh
->DeletePending
) {
341 sh
->DeletePending
= GL_TRUE
;
343 /* effectively, decr sh's refcount */
344 _mesa_reference_shader(ctx
, &sh
, NULL
);
350 detach_shader(struct gl_context
*ctx
, GLuint program
, GLuint shader
)
352 struct gl_shader_program
*shProg
;
356 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glDetachShader");
360 n
= shProg
->NumShaders
;
362 for (i
= 0; i
< n
; i
++) {
363 if (shProg
->Shaders
[i
]->Name
== shader
) {
365 struct gl_shader
**newList
;
368 _mesa_reference_shader(ctx
, &shProg
->Shaders
[i
], NULL
);
370 /* alloc new, smaller array */
372 malloc((n
- 1) * sizeof(struct gl_shader
*));
374 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glDetachShader");
377 for (j
= 0; j
< i
; j
++) {
378 newList
[j
] = shProg
->Shaders
[j
];
381 newList
[j
++] = shProg
->Shaders
[i
];
382 free(shProg
->Shaders
);
384 shProg
->Shaders
= newList
;
385 shProg
->NumShaders
= n
- 1;
390 for (j
= 0; j
< shProg
->NumShaders
; j
++) {
391 assert(shProg
->Shaders
[j
]->Type
== GL_VERTEX_SHADER
||
392 shProg
->Shaders
[j
]->Type
== GL_FRAGMENT_SHADER
);
393 assert(shProg
->Shaders
[j
]->RefCount
> 0);
405 if (is_shader(ctx
, shader
))
406 err
= GL_INVALID_OPERATION
;
407 else if (is_program(ctx
, shader
))
408 err
= GL_INVALID_OPERATION
;
410 err
= GL_INVALID_VALUE
;
411 _mesa_error(ctx
, err
, "glDetachProgram(shader)");
418 * Return list of shaders attached to shader program.
421 get_attached_shaders(struct gl_context
*ctx
, GLuint program
, GLsizei maxCount
,
422 GLsizei
*count
, GLuint
*obj
)
424 struct gl_shader_program
*shProg
=
425 _mesa_lookup_shader_program_err(ctx
, program
, "glGetAttachedShaders");
428 for (i
= 0; i
< (GLuint
) maxCount
&& i
< shProg
->NumShaders
; i
++) {
429 obj
[i
] = shProg
->Shaders
[i
]->Name
;
438 * glGetHandleARB() - return ID/name of currently bound shader program.
441 get_handle(struct gl_context
*ctx
, GLenum pname
)
443 if (pname
== GL_PROGRAM_OBJECT_ARB
) {
444 if (ctx
->Shader
.ActiveProgram
)
445 return ctx
->Shader
.ActiveProgram
->Name
;
450 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetHandleARB");
457 * glGetProgramiv() - get shader program state.
458 * Note that this is for GLSL shader programs, not ARB vertex/fragment
459 * programs (see glGetProgramivARB).
462 get_programiv(struct gl_context
*ctx
, GLuint program
, GLenum pname
, GLint
*params
)
464 struct gl_shader_program
*shProg
465 = _mesa_lookup_shader_program(ctx
, program
);
467 /* Is transform feedback available in this context?
470 (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.EXT_transform_feedback
)
471 || ctx
->API
== API_OPENGL_CORE
472 || _mesa_is_gles3(ctx
);
474 /* Are geometry shaders available in this context?
477 _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_geometry_shader4
;
479 /* Are uniform buffer objects available in this context?
482 (ctx
->API
== API_OPENGL_COMPAT
&& ctx
->Extensions
.ARB_uniform_buffer_object
)
483 || ctx
->API
== API_OPENGL_CORE
484 || _mesa_is_gles3(ctx
);
487 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramiv(program)");
492 case GL_DELETE_STATUS
:
493 *params
= shProg
->DeletePending
;
496 *params
= shProg
->LinkStatus
;
498 case GL_VALIDATE_STATUS
:
499 *params
= shProg
->Validated
;
501 case GL_INFO_LOG_LENGTH
:
502 *params
= shProg
->InfoLog
? strlen(shProg
->InfoLog
) + 1 : 0;
504 case GL_ATTACHED_SHADERS
:
505 *params
= shProg
->NumShaders
;
507 case GL_ACTIVE_ATTRIBUTES
:
508 *params
= _mesa_count_active_attribs(shProg
);
510 case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH
:
511 *params
= _mesa_longest_attribute_name_length(shProg
);
513 case GL_ACTIVE_UNIFORMS
:
514 *params
= shProg
->NumUserUniformStorage
;
516 case GL_ACTIVE_UNIFORM_MAX_LENGTH
: {
520 for (i
= 0; i
< shProg
->NumUserUniformStorage
; i
++) {
521 /* Add one for the terminating NUL character.
523 const GLint len
= strlen(shProg
->UniformStorage
[i
].name
) + 1;
532 case GL_TRANSFORM_FEEDBACK_VARYINGS
:
535 *params
= shProg
->TransformFeedback
.NumVarying
;
537 case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH
: {
543 for (i
= 0; i
< shProg
->TransformFeedback
.NumVarying
; i
++) {
544 /* Add one for the terminating NUL character.
546 const GLint len
= strlen(shProg
->TransformFeedback
.VaryingNames
[i
]) + 1;
555 case GL_TRANSFORM_FEEDBACK_BUFFER_MODE
:
558 *params
= shProg
->TransformFeedback
.BufferMode
;
560 case GL_GEOMETRY_VERTICES_OUT_ARB
:
563 *params
= shProg
->Geom
.VerticesOut
;
565 case GL_GEOMETRY_INPUT_TYPE_ARB
:
568 *params
= shProg
->Geom
.InputType
;
570 case GL_GEOMETRY_OUTPUT_TYPE_ARB
:
573 *params
= shProg
->Geom
.OutputType
;
575 case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH
: {
582 for (i
= 0; i
< shProg
->NumUniformBlocks
; i
++) {
583 /* Add one for the terminating NUL character.
585 const GLint len
= strlen(shProg
->UniformBlocks
[i
].Name
) + 1;
594 case GL_ACTIVE_UNIFORM_BLOCKS
:
598 *params
= shProg
->NumUniformBlocks
;
600 case GL_PROGRAM_BINARY_RETRIEVABLE_HINT
:
601 /* This enum isn't part of the OES extension for OpenGL ES 2.0. It is
602 * only available with desktop OpenGL 3.0+ with the
603 * GL_ARB_get_program_binary extension or OpenGL ES 3.0.
605 * On desktop, we ignore the 3.0+ requirement because it is silly.
607 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
610 *params
= shProg
->BinaryRetreivableHint
;
612 case GL_PROGRAM_BINARY_LENGTH
:
619 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetProgramiv(pname=%s)",
620 _mesa_lookup_enum_by_nr(pname
));
625 * glGetShaderiv() - get GLSL shader state
628 get_shaderiv(struct gl_context
*ctx
, GLuint name
, GLenum pname
, GLint
*params
)
630 struct gl_shader
*shader
=
631 _mesa_lookup_shader_err(ctx
, name
, "glGetShaderiv");
639 *params
= shader
->Type
;
641 case GL_DELETE_STATUS
:
642 *params
= shader
->DeletePending
;
644 case GL_COMPILE_STATUS
:
645 *params
= shader
->CompileStatus
;
647 case GL_INFO_LOG_LENGTH
:
648 *params
= shader
->InfoLog
? strlen(shader
->InfoLog
) + 1 : 0;
650 case GL_SHADER_SOURCE_LENGTH
:
651 *params
= shader
->Source
? strlen((char *) shader
->Source
) + 1 : 0;
654 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetShaderiv(pname)");
661 get_program_info_log(struct gl_context
*ctx
, GLuint program
, GLsizei bufSize
,
662 GLsizei
*length
, GLchar
*infoLog
)
664 struct gl_shader_program
*shProg
665 = _mesa_lookup_shader_program(ctx
, program
);
667 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramInfoLog(program)");
670 _mesa_copy_string(infoLog
, bufSize
, length
, shProg
->InfoLog
);
675 get_shader_info_log(struct gl_context
*ctx
, GLuint shader
, GLsizei bufSize
,
676 GLsizei
*length
, GLchar
*infoLog
)
678 struct gl_shader
*sh
= _mesa_lookup_shader(ctx
, shader
);
680 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetShaderInfoLog(shader)");
683 _mesa_copy_string(infoLog
, bufSize
, length
, sh
->InfoLog
);
688 * Return shader source code.
691 get_shader_source(struct gl_context
*ctx
, GLuint shader
, GLsizei maxLength
,
692 GLsizei
*length
, GLchar
*sourceOut
)
694 struct gl_shader
*sh
;
695 sh
= _mesa_lookup_shader_err(ctx
, shader
, "glGetShaderSource");
699 _mesa_copy_string(sourceOut
, maxLength
, length
, sh
->Source
);
704 * Set/replace shader source code. A helper function used by
705 * glShaderSource[ARB] and glCreateShaderProgramEXT.
708 shader_source(struct gl_context
*ctx
, GLuint shader
, const GLchar
*source
)
710 struct gl_shader
*sh
;
712 sh
= _mesa_lookup_shader_err(ctx
, shader
, "glShaderSource");
716 /* free old shader source string and install new one */
717 free((void *)sh
->Source
);
719 sh
->CompileStatus
= GL_FALSE
;
721 sh
->SourceChecksum
= _mesa_str_checksum(sh
->Source
);
730 compile_shader(struct gl_context
*ctx
, GLuint shaderObj
)
732 struct gl_shader
*sh
;
733 struct gl_shader_compiler_options
*options
;
735 sh
= _mesa_lookup_shader_err(ctx
, shaderObj
, "glCompileShader");
739 options
= &ctx
->ShaderCompilerOptions
[_mesa_shader_type_to_index(sh
->Type
)];
741 /* set default pragma state for shader */
742 sh
->Pragmas
= options
->DefaultPragmas
;
744 /* this call will set the sh->CompileStatus field to indicate if
745 * compilation was successful.
747 _mesa_glsl_compile_shader(ctx
, sh
);
749 if (sh
->CompileStatus
== GL_FALSE
&&
750 (ctx
->Shader
.Flags
& GLSL_REPORT_ERRORS
)) {
751 _mesa_debug(ctx
, "Error compiling shader %u:\n%s\n",
752 sh
->Name
, sh
->InfoLog
);
758 * Link a program's shaders.
761 link_program(struct gl_context
*ctx
, GLuint program
)
763 struct gl_shader_program
*shProg
;
764 struct gl_transform_feedback_object
*obj
=
765 ctx
->TransformFeedback
.CurrentObject
;
767 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glLinkProgram");
772 && (shProg
== ctx
->Shader
.CurrentVertexProgram
773 || shProg
== ctx
->Shader
.CurrentGeometryProgram
774 || shProg
== ctx
->Shader
.CurrentFragmentProgram
)) {
775 _mesa_error(ctx
, GL_INVALID_OPERATION
,
776 "glLinkProgram(transform feedback active)");
780 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
);
782 _mesa_glsl_link_shader(ctx
, shProg
);
784 if (shProg
->LinkStatus
== GL_FALSE
&&
785 (ctx
->Shader
.Flags
& GLSL_REPORT_ERRORS
)) {
786 _mesa_debug(ctx
, "Error linking program %u:\n%s\n",
787 shProg
->Name
, shProg
->InfoLog
);
794 printf("Link %u shaders in program %u: %s\n",
795 shProg
->NumShaders
, shProg
->Name
,
796 shProg
->LinkStatus
? "Success" : "Failed");
798 for (i
= 0; i
< shProg
->NumShaders
; i
++) {
799 printf(" shader %u, type 0x%x\n",
800 shProg
->Shaders
[i
]->Name
,
801 shProg
->Shaders
[i
]->Type
);
808 * Print basic shader info (for debug).
811 print_shader_info(const struct gl_shader_program
*shProg
)
815 printf("Mesa: glUseProgram(%u)\n", shProg
->Name
);
816 for (i
= 0; i
< shProg
->NumShaders
; i
++) {
818 switch (shProg
->Shaders
[i
]->Type
) {
819 case GL_VERTEX_SHADER
:
822 case GL_FRAGMENT_SHADER
:
825 case GL_GEOMETRY_SHADER
:
831 printf(" %s shader %u, checksum %u\n", s
,
832 shProg
->Shaders
[i
]->Name
,
833 shProg
->Shaders
[i
]->SourceChecksum
);
835 if (shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
])
836 printf(" vert prog %u\n",
837 shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
]->Program
->Id
);
838 if (shProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
])
839 printf(" frag prog %u\n",
840 shProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
]->Program
->Id
);
841 if (shProg
->_LinkedShaders
[MESA_SHADER_GEOMETRY
])
842 printf(" geom prog %u\n",
843 shProg
->_LinkedShaders
[MESA_SHADER_GEOMETRY
]->Program
->Id
);
848 * Use the named shader program for subsequent glUniform calls
851 _mesa_active_program(struct gl_context
*ctx
, struct gl_shader_program
*shProg
,
854 if ((shProg
!= NULL
) && !shProg
->LinkStatus
) {
855 _mesa_error(ctx
, GL_INVALID_OPERATION
,
856 "%s(program %u not linked)", caller
, shProg
->Name
);
860 if (ctx
->Shader
.ActiveProgram
!= shProg
) {
861 _mesa_reference_shader_program(ctx
, &ctx
->Shader
.ActiveProgram
, shProg
);
868 use_shader_program(struct gl_context
*ctx
, GLenum type
,
869 struct gl_shader_program
*shProg
)
871 struct gl_shader_program
**target
;
874 case GL_VERTEX_SHADER
:
875 target
= &ctx
->Shader
.CurrentVertexProgram
;
877 || (shProg
->_LinkedShaders
[MESA_SHADER_VERTEX
] == NULL
)) {
881 case GL_GEOMETRY_SHADER_ARB
:
882 target
= &ctx
->Shader
.CurrentGeometryProgram
;
884 || (shProg
->_LinkedShaders
[MESA_SHADER_GEOMETRY
] == NULL
)) {
888 case GL_FRAGMENT_SHADER
:
889 target
= &ctx
->Shader
.CurrentFragmentProgram
;
891 || (shProg
->_LinkedShaders
[MESA_SHADER_FRAGMENT
] == NULL
)) {
899 if (*target
!= shProg
) {
900 FLUSH_VERTICES(ctx
, _NEW_PROGRAM
| _NEW_PROGRAM_CONSTANTS
);
902 /* If the shader is also bound as the current rendering shader, unbind
903 * it from that binding point as well. This ensures that the correct
904 * semantics of glDeleteProgram are maintained.
907 case GL_VERTEX_SHADER
:
910 case GL_GEOMETRY_SHADER_ARB
:
913 case GL_FRAGMENT_SHADER
:
914 if (*target
== ctx
->Shader
._CurrentFragmentProgram
) {
915 _mesa_reference_shader_program(ctx
,
916 &ctx
->Shader
._CurrentFragmentProgram
,
922 _mesa_reference_shader_program(ctx
, target
, shProg
);
930 * Use the named shader program for subsequent rendering.
933 _mesa_use_program(struct gl_context
*ctx
, struct gl_shader_program
*shProg
)
935 use_shader_program(ctx
, GL_VERTEX_SHADER
, shProg
);
936 use_shader_program(ctx
, GL_GEOMETRY_SHADER_ARB
, shProg
);
937 use_shader_program(ctx
, GL_FRAGMENT_SHADER
, shProg
);
938 _mesa_active_program(ctx
, shProg
, "glUseProgram");
940 if (ctx
->Driver
.UseProgram
)
941 ctx
->Driver
.UseProgram(ctx
, shProg
);
946 * Do validation of the given shader program.
947 * \param errMsg returns error message if validation fails.
948 * \return GL_TRUE if valid, GL_FALSE if invalid (and set errMsg)
951 validate_shader_program(const struct gl_shader_program
*shProg
,
954 if (!shProg
->LinkStatus
) {
958 /* From the GL spec, a program is invalid if any of these are true:
960 any two active samplers in the current program object are of
961 different types, but refer to the same texture image unit,
963 any active sampler in the current program object refers to a texture
964 image unit where fixed-function fragment processing accesses a
965 texture target that does not match the sampler type, or
967 the sum of the number of active samplers in the program and the
968 number of texture image units enabled for fixed-function fragment
969 processing exceeds the combined limit on the total number of texture
975 * Check: any two active samplers in the current program object are of
976 * different types, but refer to the same texture image unit,
978 if (!_mesa_sampler_uniforms_are_valid(shProg
, errMsg
, 100))
986 * Called via glValidateProgram()
989 validate_program(struct gl_context
*ctx
, GLuint program
)
991 struct gl_shader_program
*shProg
;
992 char errMsg
[100] = "";
994 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glValidateProgram");
999 shProg
->Validated
= validate_shader_program(shProg
, errMsg
);
1000 if (!shProg
->Validated
) {
1001 /* update info log */
1002 if (shProg
->InfoLog
) {
1003 ralloc_free(shProg
->InfoLog
);
1005 shProg
->InfoLog
= ralloc_strdup(shProg
, errMsg
);
1012 _mesa_AttachObjectARB(GLhandleARB program
, GLhandleARB shader
)
1014 GET_CURRENT_CONTEXT(ctx
);
1015 attach_shader(ctx
, program
, shader
);
1020 _mesa_AttachShader(GLuint program
, GLuint shader
)
1022 GET_CURRENT_CONTEXT(ctx
);
1023 attach_shader(ctx
, program
, shader
);
1028 _mesa_CompileShader(GLhandleARB shaderObj
)
1030 GET_CURRENT_CONTEXT(ctx
);
1031 if (MESA_VERBOSE
& VERBOSE_API
)
1032 _mesa_debug(ctx
, "glCompileShader %u\n", shaderObj
);
1033 compile_shader(ctx
, shaderObj
);
1038 _mesa_CreateShader(GLenum type
)
1040 GET_CURRENT_CONTEXT(ctx
);
1041 if (MESA_VERBOSE
& VERBOSE_API
)
1042 _mesa_debug(ctx
, "glCreateShader %s\n", _mesa_lookup_enum_by_nr(type
));
1043 return create_shader(ctx
, type
);
1047 GLhandleARB GLAPIENTRY
1048 _mesa_CreateShaderObjectARB(GLenum type
)
1050 GET_CURRENT_CONTEXT(ctx
);
1051 return create_shader(ctx
, type
);
1056 _mesa_CreateProgram(void)
1058 GET_CURRENT_CONTEXT(ctx
);
1059 if (MESA_VERBOSE
& VERBOSE_API
)
1060 _mesa_debug(ctx
, "glCreateProgram\n");
1061 return create_shader_program(ctx
);
1065 GLhandleARB GLAPIENTRY
1066 _mesa_CreateProgramObjectARB(void)
1068 GET_CURRENT_CONTEXT(ctx
);
1069 return create_shader_program(ctx
);
1074 _mesa_DeleteObjectARB(GLhandleARB obj
)
1076 if (MESA_VERBOSE
& VERBOSE_API
) {
1077 GET_CURRENT_CONTEXT(ctx
);
1078 _mesa_debug(ctx
, "glDeleteObjectARB(%u)\n", obj
);
1082 GET_CURRENT_CONTEXT(ctx
);
1083 FLUSH_VERTICES(ctx
, 0);
1084 if (is_program(ctx
, obj
)) {
1085 delete_shader_program(ctx
, obj
);
1087 else if (is_shader(ctx
, obj
)) {
1088 delete_shader(ctx
, obj
);
1098 _mesa_DeleteProgram(GLuint name
)
1101 GET_CURRENT_CONTEXT(ctx
);
1102 FLUSH_VERTICES(ctx
, 0);
1103 delete_shader_program(ctx
, name
);
1109 _mesa_DeleteShader(GLuint name
)
1112 GET_CURRENT_CONTEXT(ctx
);
1113 FLUSH_VERTICES(ctx
, 0);
1114 delete_shader(ctx
, name
);
1120 _mesa_DetachObjectARB(GLhandleARB program
, GLhandleARB shader
)
1122 GET_CURRENT_CONTEXT(ctx
);
1123 detach_shader(ctx
, program
, shader
);
1128 _mesa_DetachShader(GLuint program
, GLuint shader
)
1130 GET_CURRENT_CONTEXT(ctx
);
1131 detach_shader(ctx
, program
, shader
);
1136 _mesa_GetAttachedObjectsARB(GLhandleARB container
, GLsizei maxCount
,
1137 GLsizei
* count
, GLhandleARB
* obj
)
1139 GET_CURRENT_CONTEXT(ctx
);
1140 get_attached_shaders(ctx
, container
, maxCount
, count
, obj
);
1145 _mesa_GetAttachedShaders(GLuint program
, GLsizei maxCount
,
1146 GLsizei
*count
, GLuint
*obj
)
1148 GET_CURRENT_CONTEXT(ctx
);
1149 get_attached_shaders(ctx
, program
, maxCount
, count
, obj
);
1154 _mesa_GetInfoLogARB(GLhandleARB object
, GLsizei maxLength
, GLsizei
* length
,
1155 GLcharARB
* infoLog
)
1157 GET_CURRENT_CONTEXT(ctx
);
1158 if (is_program(ctx
, object
)) {
1159 get_program_info_log(ctx
, object
, maxLength
, length
, infoLog
);
1161 else if (is_shader(ctx
, object
)) {
1162 get_shader_info_log(ctx
, object
, maxLength
, length
, infoLog
);
1165 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetInfoLogARB");
1171 _mesa_GetObjectParameterivARB(GLhandleARB object
, GLenum pname
, GLint
*params
)
1173 GET_CURRENT_CONTEXT(ctx
);
1174 /* Implement in terms of GetProgramiv, GetShaderiv */
1175 if (is_program(ctx
, object
)) {
1176 if (pname
== GL_OBJECT_TYPE_ARB
) {
1177 *params
= GL_PROGRAM_OBJECT_ARB
;
1180 get_programiv(ctx
, object
, pname
, params
);
1183 else if (is_shader(ctx
, object
)) {
1184 if (pname
== GL_OBJECT_TYPE_ARB
) {
1185 *params
= GL_SHADER_OBJECT_ARB
;
1188 get_shaderiv(ctx
, object
, pname
, params
);
1192 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetObjectParameterivARB");
1198 _mesa_GetObjectParameterfvARB(GLhandleARB object
, GLenum pname
,
1201 GLint iparams
[1]; /* XXX is one element enough? */
1202 _mesa_GetObjectParameterivARB(object
, pname
, iparams
);
1203 params
[0] = (GLfloat
) iparams
[0];
1208 _mesa_GetProgramiv(GLuint program
, GLenum pname
, GLint
*params
)
1210 GET_CURRENT_CONTEXT(ctx
);
1211 get_programiv(ctx
, program
, pname
, params
);
1216 _mesa_GetShaderiv(GLuint shader
, GLenum pname
, GLint
*params
)
1218 GET_CURRENT_CONTEXT(ctx
);
1219 get_shaderiv(ctx
, shader
, pname
, params
);
1224 _mesa_GetProgramInfoLog(GLuint program
, GLsizei bufSize
,
1225 GLsizei
*length
, GLchar
*infoLog
)
1227 GET_CURRENT_CONTEXT(ctx
);
1228 get_program_info_log(ctx
, program
, bufSize
, length
, infoLog
);
1233 _mesa_GetShaderInfoLog(GLuint shader
, GLsizei bufSize
,
1234 GLsizei
*length
, GLchar
*infoLog
)
1236 GET_CURRENT_CONTEXT(ctx
);
1237 get_shader_info_log(ctx
, shader
, bufSize
, length
, infoLog
);
1242 _mesa_GetShaderSource(GLhandleARB shader
, GLsizei maxLength
,
1243 GLsizei
*length
, GLcharARB
*sourceOut
)
1245 GET_CURRENT_CONTEXT(ctx
);
1246 get_shader_source(ctx
, shader
, maxLength
, length
, sourceOut
);
1250 GLhandleARB GLAPIENTRY
1251 _mesa_GetHandleARB(GLenum pname
)
1253 GET_CURRENT_CONTEXT(ctx
);
1254 return get_handle(ctx
, pname
);
1258 GLboolean GLAPIENTRY
1259 _mesa_IsProgram(GLuint name
)
1261 GET_CURRENT_CONTEXT(ctx
);
1262 return is_program(ctx
, name
);
1266 GLboolean GLAPIENTRY
1267 _mesa_IsShader(GLuint name
)
1269 GET_CURRENT_CONTEXT(ctx
);
1270 return is_shader(ctx
, name
);
1275 _mesa_LinkProgram(GLhandleARB programObj
)
1277 GET_CURRENT_CONTEXT(ctx
);
1278 link_program(ctx
, programObj
);
1284 * Read shader source code from a file.
1285 * Useful for debugging to override an app's shader.
1288 read_shader(const char *fname
)
1290 const int max
= 50*1000;
1291 FILE *f
= fopen(fname
, "r");
1292 GLcharARB
*buffer
, *shader
;
1299 buffer
= malloc(max
);
1300 len
= fread(buffer
, 1, max
, f
);
1305 shader
= _mesa_strdup(buffer
);
1313 * Called via glShaderSource() and glShaderSourceARB() API functions.
1314 * Basically, concatenate the source code strings into one long string
1315 * and pass it to _mesa_shader_source().
1318 _mesa_ShaderSource(GLhandleARB shaderObj
, GLsizei count
,
1319 const GLcharARB
* const * string
, const GLint
* length
)
1321 GET_CURRENT_CONTEXT(ctx
);
1323 GLsizei i
, totalLength
;
1327 if (!shaderObj
|| string
== NULL
) {
1328 _mesa_error(ctx
, GL_INVALID_VALUE
, "glShaderSourceARB");
1333 * This array holds offsets of where the appropriate string ends, thus the
1334 * last element will be set to the total length of the source code.
1336 offsets
= malloc(count
* sizeof(GLint
));
1337 if (offsets
== NULL
) {
1338 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glShaderSourceARB");
1342 for (i
= 0; i
< count
; i
++) {
1343 if (string
[i
] == NULL
) {
1344 free((GLvoid
*) offsets
);
1345 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1346 "glShaderSourceARB(null string)");
1349 if (length
== NULL
|| length
[i
] < 0)
1350 offsets
[i
] = strlen(string
[i
]);
1352 offsets
[i
] = length
[i
];
1353 /* accumulate string lengths */
1355 offsets
[i
] += offsets
[i
- 1];
1358 /* Total length of source string is sum off all strings plus two.
1359 * One extra byte for terminating zero, another extra byte to silence
1360 * valgrind warnings in the parser/grammer code.
1362 totalLength
= offsets
[count
- 1] + 2;
1363 source
= malloc(totalLength
* sizeof(GLcharARB
));
1364 if (source
== NULL
) {
1365 free((GLvoid
*) offsets
);
1366 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glShaderSourceARB");
1370 for (i
= 0; i
< count
; i
++) {
1371 GLint start
= (i
> 0) ? offsets
[i
- 1] : 0;
1372 memcpy(source
+ start
, string
[i
],
1373 (offsets
[i
] - start
) * sizeof(GLcharARB
));
1375 source
[totalLength
- 1] = '\0';
1376 source
[totalLength
- 2] = '\0';
1379 /* Compute the shader's source code checksum then try to open a file
1380 * named newshader_<CHECKSUM>. If it exists, use it in place of the
1381 * original shader source code. For debugging.
1384 GLcharARB
*newSource
;
1386 checksum
= _mesa_str_checksum(source
);
1388 _mesa_snprintf(filename
, sizeof(filename
), "newshader_%d", checksum
);
1390 newSource
= read_shader(filename
);
1392 fprintf(stderr
, "Mesa: Replacing shader %u chksum=%d with %s\n",
1393 shaderObj
, checksum
, filename
);
1399 shader_source(ctx
, shaderObj
, source
);
1402 struct gl_shader
*sh
= _mesa_lookup_shader(ctx
, shaderObj
);
1404 sh
->SourceChecksum
= checksum
; /* save original checksum */
1412 _mesa_UseProgram(GLhandleARB program
)
1414 GET_CURRENT_CONTEXT(ctx
);
1415 struct gl_shader_program
*shProg
;
1417 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
1418 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1419 "glUseProgram(transform feedback active)");
1424 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glUseProgram");
1428 if (!shProg
->LinkStatus
) {
1429 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1430 "glUseProgram(program %u not linked)", program
);
1435 if (ctx
->Shader
.Flags
& GLSL_USE_PROG
) {
1436 print_shader_info(shProg
);
1443 _mesa_use_program(ctx
, shProg
);
1448 _mesa_ValidateProgram(GLhandleARB program
)
1450 GET_CURRENT_CONTEXT(ctx
);
1451 validate_program(ctx
, program
);
1457 _mesa_GetShaderPrecisionFormat(GLenum shadertype
, GLenum precisiontype
,
1458 GLint
* range
, GLint
* precision
)
1460 const struct gl_program_constants
*limits
;
1461 const struct gl_precision
*p
;
1462 GET_CURRENT_CONTEXT(ctx
);
1464 switch (shadertype
) {
1465 case GL_VERTEX_SHADER
:
1466 limits
= &ctx
->Const
.VertexProgram
;
1468 case GL_FRAGMENT_SHADER
:
1469 limits
= &ctx
->Const
.FragmentProgram
;
1472 _mesa_error(ctx
, GL_INVALID_ENUM
,
1473 "glGetShaderPrecisionFormat(shadertype)");
1477 switch (precisiontype
) {
1479 p
= &limits
->LowFloat
;
1481 case GL_MEDIUM_FLOAT
:
1482 p
= &limits
->MediumFloat
;
1485 p
= &limits
->HighFloat
;
1488 p
= &limits
->LowInt
;
1491 p
= &limits
->MediumInt
;
1494 p
= &limits
->HighInt
;
1497 _mesa_error(ctx
, GL_INVALID_ENUM
,
1498 "glGetShaderPrecisionFormat(precisiontype)");
1502 range
[0] = p
->RangeMin
;
1503 range
[1] = p
->RangeMax
;
1504 precision
[0] = p
->Precision
;
1509 _mesa_ReleaseShaderCompiler(void)
1511 _mesa_destroy_shader_compiler_caches();
1516 _mesa_ShaderBinary(GLint n
, const GLuint
* shaders
, GLenum binaryformat
,
1517 const void* binary
, GLint length
)
1519 GET_CURRENT_CONTEXT(ctx
);
1522 (void) binaryformat
;
1525 _mesa_error(ctx
, GL_INVALID_OPERATION
, __FUNCTION__
);
1528 #endif /* FEATURE_ES2 */
1531 _mesa_GetProgramBinary(GLuint program
, GLsizei bufSize
, GLsizei
*length
,
1532 GLenum
*binaryFormat
, GLvoid
*binary
)
1534 struct gl_shader_program
*shProg
;
1535 GET_CURRENT_CONTEXT(ctx
);
1537 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glGetProgramBinary");
1541 if (!shProg
->LinkStatus
) {
1542 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1543 "glGetProgramBinary(program %u not linked)",
1549 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetProgramBinary(bufSize < 0)");
1553 /* The ARB_get_program_binary spec says:
1555 * "If <length> is NULL, then no length is returned."
1560 (void) binaryFormat
;
1565 _mesa_ProgramBinary(GLuint program
, GLenum binaryFormat
,
1566 const GLvoid
*binary
, GLsizei length
)
1568 struct gl_shader_program
*shProg
;
1569 GET_CURRENT_CONTEXT(ctx
);
1571 shProg
= _mesa_lookup_shader_program_err(ctx
, program
, "glProgramBinary");
1575 (void) binaryFormat
;
1578 _mesa_error(ctx
, GL_INVALID_OPERATION
, __FUNCTION__
);
1583 _mesa_ProgramParameteri(GLuint program
, GLenum pname
, GLint value
)
1585 struct gl_shader_program
*shProg
;
1586 GET_CURRENT_CONTEXT(ctx
);
1588 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
1589 "glProgramParameteri");
1594 case GL_GEOMETRY_VERTICES_OUT_ARB
:
1595 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_geometry_shader4
)
1599 (unsigned) value
> ctx
->Const
.MaxGeometryOutputVertices
) {
1600 _mesa_error(ctx
, GL_INVALID_VALUE
,
1601 "glProgramParameteri(GL_GEOMETRY_VERTICES_OUT_ARB=%d",
1605 shProg
->Geom
.VerticesOut
= value
;
1607 case GL_GEOMETRY_INPUT_TYPE_ARB
:
1608 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_geometry_shader4
)
1614 case GL_LINES_ADJACENCY_ARB
:
1616 case GL_TRIANGLES_ADJACENCY_ARB
:
1617 shProg
->Geom
.InputType
= value
;
1620 _mesa_error(ctx
, GL_INVALID_VALUE
,
1621 "glProgramParameteri(geometry input type = %s",
1622 _mesa_lookup_enum_by_nr(value
));
1626 case GL_GEOMETRY_OUTPUT_TYPE_ARB
:
1627 if (!_mesa_is_desktop_gl(ctx
) || !ctx
->Extensions
.ARB_geometry_shader4
)
1633 case GL_TRIANGLE_STRIP
:
1634 shProg
->Geom
.OutputType
= value
;
1637 _mesa_error(ctx
, GL_INVALID_VALUE
,
1638 "glProgramParameteri(geometry output type = %s",
1639 _mesa_lookup_enum_by_nr(value
));
1643 case GL_PROGRAM_BINARY_RETRIEVABLE_HINT
:
1644 /* This enum isn't part of the OES extension for OpenGL ES 2.0, but it
1645 * is part of OpenGL ES 3.0. For the ES2 case, this function shouldn't
1646 * even be in the dispatch table, so we shouldn't need to expclicitly
1649 * On desktop, we ignore the 3.0+ requirement because it is silly.
1652 /* The ARB_get_program_binary extension spec says:
1654 * "An INVALID_VALUE error is generated if the <value> argument to
1655 * ProgramParameteri is not TRUE or FALSE."
1657 if (value
!= GL_TRUE
&& value
!= GL_FALSE
) {
1658 _mesa_error(ctx
, GL_INVALID_VALUE
,
1659 "glProgramParameteri(pname=%s, value=%d): "
1660 "value must be 0 or 1.",
1661 _mesa_lookup_enum_by_nr(pname
),
1666 /* No need to notify the driver. Any changes will actually take effect
1667 * the next time the shader is linked.
1669 * The ARB_get_program_binary extension spec says:
1671 * "To indicate that a program binary is likely to be retrieved,
1672 * ProgramParameteri should be called with <pname>
1673 * PROGRAM_BINARY_RETRIEVABLE_HINT and <value> TRUE. This setting
1674 * will not be in effect until the next time LinkProgram or
1675 * ProgramBinary has been called successfully."
1677 * The resloution of issue 9 in the extension spec also says:
1679 * "The application may use the PROGRAM_BINARY_RETRIEVABLE_HINT hint
1680 * to indicate to the GL implementation that this program will
1681 * likely be saved with GetProgramBinary at some point. This will
1682 * give the GL implementation the opportunity to track any state
1683 * changes made to the program before being saved such that when it
1684 * is loaded again a recompile can be avoided."
1686 shProg
->BinaryRetreivableHint
= value
;
1692 _mesa_error(ctx
, GL_INVALID_ENUM
, "glProgramParameteri(pname=%s)",
1693 _mesa_lookup_enum_by_nr(pname
));
1697 _mesa_use_shader_program(struct gl_context
*ctx
, GLenum type
,
1698 struct gl_shader_program
*shProg
)
1700 use_shader_program(ctx
, type
, shProg
);
1702 if (ctx
->Driver
.UseProgram
)
1703 ctx
->Driver
.UseProgram(ctx
, shProg
);
1708 * For GL_EXT_separate_shader_objects
1711 _mesa_UseShaderProgramEXT(GLenum type
, GLuint program
)
1713 GET_CURRENT_CONTEXT(ctx
);
1714 struct gl_shader_program
*shProg
= NULL
;
1716 if (!validate_shader_target(ctx
, type
)) {
1717 _mesa_error(ctx
, GL_INVALID_ENUM
, "glUseShaderProgramEXT(type)");
1721 if (_mesa_is_xfb_active_and_unpaused(ctx
)) {
1722 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1723 "glUseShaderProgramEXT(transform feedback is active)");
1728 shProg
= _mesa_lookup_shader_program_err(ctx
, program
,
1729 "glUseShaderProgramEXT");
1733 if (!shProg
->LinkStatus
) {
1734 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1735 "glUseShaderProgramEXT(program not linked)");
1740 _mesa_use_shader_program(ctx
, type
, shProg
);
1745 * For GL_EXT_separate_shader_objects
1748 _mesa_ActiveProgramEXT(GLuint program
)
1750 GET_CURRENT_CONTEXT(ctx
);
1751 struct gl_shader_program
*shProg
= (program
!= 0)
1752 ? _mesa_lookup_shader_program_err(ctx
, program
, "glActiveProgramEXT")
1755 _mesa_active_program(ctx
, shProg
, "glActiveProgramEXT");
1761 * For GL_EXT_separate_shader_objects
1764 _mesa_CreateShaderProgramEXT(GLenum type
, const GLchar
*string
)
1766 GET_CURRENT_CONTEXT(ctx
);
1767 const GLuint shader
= create_shader(ctx
, type
);
1771 shader_source(ctx
, shader
, _mesa_strdup(string
));
1772 compile_shader(ctx
, shader
);
1774 program
= create_shader_program(ctx
);
1776 struct gl_shader_program
*shProg
;
1777 struct gl_shader
*sh
;
1778 GLint compiled
= GL_FALSE
;
1780 shProg
= _mesa_lookup_shader_program(ctx
, program
);
1781 sh
= _mesa_lookup_shader(ctx
, shader
);
1783 get_shaderiv(ctx
, shader
, GL_COMPILE_STATUS
, &compiled
);
1785 attach_shader(ctx
, program
, shader
);
1786 link_program(ctx
, program
);
1787 detach_shader(ctx
, program
, shader
);
1791 if (active
-user
-defined
-varyings
-in
-linked
-program
) {
1792 append
-error
-to
-info
-log
;
1793 shProg
->LinkStatus
= GL_FALSE
;
1798 ralloc_strcat(&shProg
->InfoLog
, sh
->InfoLog
);
1801 delete_shader(ctx
, shader
);