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, see <http://www.gnu.org/licenses/>.
29
#include "cogl-program.h"
30
#include "cogl-shader-private.h"
31
#include "cogl-internal.h"
32
#include "cogl-handle.h"
33
#include "cogl-context.h"
34
#include "cogl-journal-private.h"
38
#define glCreateProgramObject ctx->drv.pf_glCreateProgramObject
39
#define glAttachObject ctx->drv.pf_glAttachObject
40
#define glUseProgramObject ctx->drv.pf_glUseProgramObject
41
#define glLinkProgram ctx->drv.pf_glLinkProgram
42
#define glGetUniformLocation ctx->drv.pf_glGetUniformLocation
43
#define glUniform1f ctx->drv.pf_glUniform1f
44
#define glUniform2f ctx->drv.pf_glUniform2f
45
#define glUniform3f ctx->drv.pf_glUniform3f
46
#define glUniform4f ctx->drv.pf_glUniform4f
47
#define glUniform1fv ctx->drv.pf_glUniform1fv
48
#define glUniform2fv ctx->drv.pf_glUniform2fv
49
#define glUniform3fv ctx->drv.pf_glUniform3fv
50
#define glUniform4fv ctx->drv.pf_glUniform4fv
51
#define glUniform1i ctx->drv.pf_glUniform1i
52
#define glUniform2i ctx->drv.pf_glUniform2i
53
#define glUniform3i ctx->drv.pf_glUniform3i
54
#define glUniform4i ctx->drv.pf_glUniform4i
55
#define glUniform1iv ctx->drv.pf_glUniform1iv
56
#define glUniform2iv ctx->drv.pf_glUniform2iv
57
#define glUniform3iv ctx->drv.pf_glUniform3iv
58
#define glUniform4iv ctx->drv.pf_glUniform4iv
59
#define glUniformMatrix2fv ctx->drv.pf_glUniformMatrix2fv
60
#define glUniformMatrix3fv ctx->drv.pf_glUniformMatrix3fv
61
#define glUniformMatrix4fv ctx->drv.pf_glUniformMatrix4fv
62
#define glDeleteObject ctx->drv.pf_glDeleteObject
64
static void _cogl_program_free (CoglProgram *program);
66
COGL_HANDLE_DEFINE (Program, program);
69
_cogl_program_free (CoglProgram *program)
71
/* Frees program resources but its handle is not
72
released! Do that separately before this! */
73
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
74
glDeleteObject (program->gl_handle);
78
cogl_create_program (void)
81
_COGL_GET_CONTEXT (ctx, 0);
83
program = g_slice_new (CoglProgram);
84
program->gl_handle = glCreateProgramObject ();
86
return _cogl_program_handle_new (program);
90
cogl_program_attach_shader (CoglHandle program_handle,
91
CoglHandle shader_handle)
96
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
98
if (!cogl_is_program (program_handle) || !cogl_is_shader (shader_handle))
101
program = _cogl_program_pointer_from_handle (program_handle);
102
shader = _cogl_shader_pointer_from_handle (shader_handle);
104
glAttachObject (program->gl_handle, shader->gl_handle);
108
cogl_program_link (CoglHandle handle)
110
CoglProgram *program;
111
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
113
if (!cogl_is_program (handle))
116
program = _cogl_program_pointer_from_handle (handle);
118
glLinkProgram (program->gl_handle);
122
cogl_program_use (CoglHandle handle)
124
CoglProgram *program;
125
GLhandleARB gl_handle;
126
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
128
if (handle != COGL_INVALID_HANDLE && !cogl_is_program (handle))
131
/* The Cogl journal doesn't currently cope with the use of
132
* shaders so we have to flush all priitives whenever the
133
* current shader changes... */
134
_cogl_journal_flush ();
136
if (handle == COGL_INVALID_HANDLE)
140
program = _cogl_program_pointer_from_handle (handle);
141
gl_handle = program->gl_handle;
144
glUseProgramObject (gl_handle);
148
cogl_program_get_uniform_location (CoglHandle handle,
149
const char *uniform_name)
151
CoglProgram *program;
152
_COGL_GET_CONTEXT (ctx, 0);
154
if (!cogl_is_program (handle))
157
program = _cogl_program_pointer_from_handle (handle);
159
return glGetUniformLocation (program->gl_handle, uniform_name);
163
cogl_program_uniform_1f (int uniform_no,
166
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
167
glUniform1f (uniform_no, value);
171
cogl_program_uniform_1i (int uniform_no,
174
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
175
glUniform1i (uniform_no, value);
179
cogl_program_uniform_float (int uniform_no,
182
const GLfloat *value)
184
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
189
glUniform1fv (uniform_no, count, value);
192
glUniform2fv (uniform_no, count, value);
195
glUniform3fv (uniform_no, count, value);
198
glUniform4fv (uniform_no, count, value);
201
g_warning ("%s called with invalid size parameter", G_STRFUNC);
206
cogl_program_uniform_int (int uniform_no,
211
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
216
glUniform1iv (uniform_no, count, value);
219
glUniform2iv (uniform_no, count, value);
222
glUniform3iv (uniform_no, count, value);
225
glUniform4iv (uniform_no, count, value);
228
g_warning ("%s called with invalid size parameter", G_STRFUNC);
233
cogl_program_uniform_matrix (int uniform_no,
237
const GLfloat *value)
239
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
244
glUniformMatrix2fv (uniform_no, count, transpose, value);
247
glUniformMatrix3fv (uniform_no, count, transpose, value);
250
glUniformMatrix4fv (uniform_no, count, transpose, value);
253
g_warning ("%s called with invalid size parameter", G_STRFUNC);