4
* An object oriented GL/GLES Abstraction/Utility Layer
6
* Copyright (C) 2008,2009 Intel Corporation.
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public
10
* License as published by the Free Software Foundation; either
11
* version 2 of the License, or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library; if not, write to the
20
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
* Boston, MA 02111-1307, USA.
30
#include "cogl-shader-private.h"
31
#include "cogl-internal.h"
32
#include "cogl-context.h"
33
#include "cogl-handle.h"
35
#ifdef HAVE_COGL_GLES2
37
static void _cogl_shader_free (CoglShader *shader);
39
COGL_HANDLE_DEFINE (Shader, shader);
42
_cogl_shader_free (CoglShader *shader)
44
/* Frees shader resources but its handle is not
45
released! Do that separately before this! */
46
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
47
glDeleteShader (shader->gl_handle);
51
cogl_create_shader (CoglShaderType type)
56
if (type == COGL_SHADER_TYPE_VERTEX)
57
gl_type = GL_VERTEX_SHADER;
58
else if (type == COGL_SHADER_TYPE_FRAGMENT)
59
gl_type = GL_FRAGMENT_SHADER;
62
g_warning ("Unexpected shader type (0x%08lX) given to "
63
"cogl_create_shader", (unsigned long) type);
64
return COGL_INVALID_HANDLE;
67
shader = g_slice_new (CoglShader);
68
shader->gl_handle = glCreateShader (gl_type);
70
return _cogl_shader_handle_new (shader);
74
cogl_shader_source (CoglHandle handle,
78
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
80
if (!cogl_is_shader (handle))
83
shader = _cogl_shader_pointer_from_handle (handle);
85
glShaderSource (shader->gl_handle, 1, &source, NULL);
89
cogl_shader_compile (CoglHandle handle)
92
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
94
if (!cogl_is_shader (handle))
97
shader = _cogl_shader_pointer_from_handle (handle);
99
glCompileShader (shader->gl_handle);
103
cogl_shader_get_info_log (CoglHandle handle)
108
_COGL_GET_CONTEXT (ctx, NULL);
110
if (!cogl_is_shader (handle))
113
shader = _cogl_shader_pointer_from_handle (handle);
115
glGetShaderInfoLog (shader->gl_handle, 511, &len, buffer);
118
return g_strdup (buffer);
122
cogl_shader_get_type (CoglHandle handle)
127
if (!cogl_is_shader (handle))
129
g_warning ("Non shader handle type passed to cogl_shader_get_type");
130
return COGL_SHADER_TYPE_VERTEX;
133
shader = _cogl_shader_pointer_from_handle (handle);
135
GE (glGetShaderiv (shader->gl_handle, GL_SHADER_TYPE, &type));
136
if (type == GL_VERTEX_SHADER)
137
return COGL_SHADER_TYPE_VERTEX;
138
else if (type == GL_FRAGMENT_SHADER)
139
return COGL_SHADER_TYPE_VERTEX;
142
g_warning ("Unexpected shader type 0x%08lX", (unsigned long)type);
143
return COGL_SHADER_TYPE_VERTEX;
148
cogl_shader_is_compiled (CoglHandle handle)
153
if (!cogl_is_shader (handle))
156
shader = _cogl_shader_pointer_from_handle (handle);
158
GE (glGetShaderiv (shader->gl_handle, GL_COMPILE_STATUS, &status));
159
if (status == GL_TRUE)
165
#else /* HAVE_COGL_GLES2 */
167
/* No support on regular OpenGL 1.1 */
170
cogl_create_shader (CoglShaderType type)
172
return COGL_INVALID_HANDLE;
176
cogl_is_shader (CoglHandle handle)
182
cogl_shader_ref (CoglHandle handle)
184
return COGL_INVALID_HANDLE;
188
cogl_shader_unref (CoglHandle handle)
193
cogl_shader_source (CoglHandle shader,
199
cogl_shader_compile (CoglHandle shader_handle)
204
cogl_shader_get_info_log (CoglHandle handle)
210
cogl_shader_get_type (CoglHandle handle)
212
return COGL_SHADER_TYPE_VERTEX;
216
cogl_shader_is_compiled (CoglHandle handle)
221
#endif /* HAVE_COGL_GLES2 */