~oem-solutions-group/unity-2d/clutter-1.0

« back to all changes in this revision

Viewing changes to clutter/cogl/gles/cogl-shader.c

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort
  • Date: 2010-03-21 13:27:56 UTC
  • mto: (2.1.3 experimental)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20100321132756-nf8yd30yxo3zzwcm
Tags: upstream-1.2.2
ImportĀ upstreamĀ versionĀ 1.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Cogl
3
 
 *
4
 
 * An object oriented GL/GLES Abstraction/Utility Layer
5
 
 *
6
 
 * Copyright (C) 2008,2009 Intel Corporation.
7
 
 *
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.
12
 
 *
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.
17
 
 *
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.
22
 
 */
23
 
 
24
 
#ifdef HAVE_CONFIG_H
25
 
#include "config.h"
26
 
#endif
27
 
 
28
 
#include "cogl.h"
29
 
 
30
 
#include "cogl-shader-private.h"
31
 
#include "cogl-internal.h"
32
 
#include "cogl-context.h"
33
 
#include "cogl-handle.h"
34
 
 
35
 
#ifdef HAVE_COGL_GLES2
36
 
 
37
 
static void _cogl_shader_free (CoglShader *shader);
38
 
 
39
 
COGL_HANDLE_DEFINE (Shader, shader);
40
 
 
41
 
static void
42
 
_cogl_shader_free (CoglShader *shader)
43
 
{
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);
48
 
}
49
 
 
50
 
CoglHandle
51
 
cogl_create_shader (CoglShaderType type)
52
 
{
53
 
  CoglShader *shader;
54
 
  GLenum gl_type;
55
 
 
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;
60
 
  else
61
 
    {
62
 
      g_warning ("Unexpected shader type (0x%08lX) given to "
63
 
                 "cogl_create_shader", (unsigned long) type);
64
 
      return COGL_INVALID_HANDLE;
65
 
    }
66
 
 
67
 
  shader = g_slice_new (CoglShader);
68
 
  shader->gl_handle = glCreateShader (gl_type);
69
 
 
70
 
  return _cogl_shader_handle_new (shader);
71
 
}
72
 
 
73
 
void
74
 
cogl_shader_source (CoglHandle   handle,
75
 
                    const char  *source)
76
 
{
77
 
  CoglShader *shader;
78
 
  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
79
 
 
80
 
  if (!cogl_is_shader (handle))
81
 
    return;
82
 
 
83
 
  shader = _cogl_shader_pointer_from_handle (handle);
84
 
 
85
 
  glShaderSource (shader->gl_handle, 1, &source, NULL);
86
 
}
87
 
 
88
 
void
89
 
cogl_shader_compile (CoglHandle handle)
90
 
{
91
 
  CoglShader *shader;
92
 
  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
93
 
 
94
 
  if (!cogl_is_shader (handle))
95
 
    return;
96
 
 
97
 
  shader = _cogl_shader_pointer_from_handle (handle);
98
 
 
99
 
  glCompileShader (shader->gl_handle);
100
 
}
101
 
 
102
 
gchar *
103
 
cogl_shader_get_info_log (CoglHandle handle)
104
 
{
105
 
  CoglShader *shader;
106
 
  char buffer[512];
107
 
  int len = 0;
108
 
  _COGL_GET_CONTEXT (ctx, NULL);
109
 
 
110
 
  if (!cogl_is_shader (handle))
111
 
    return NULL;
112
 
 
113
 
  shader = _cogl_shader_pointer_from_handle (handle);
114
 
 
115
 
  glGetShaderInfoLog (shader->gl_handle, 511, &len, buffer);
116
 
  buffer[len] = '\0';
117
 
 
118
 
  return g_strdup (buffer);
119
 
}
120
 
 
121
 
CoglShaderType
122
 
cogl_shader_get_type (CoglHandle  handle)
123
 
{
124
 
  GLint type;
125
 
  CoglShader *shader;
126
 
 
127
 
  if (!cogl_is_shader (handle))
128
 
    {
129
 
      g_warning ("Non shader handle type passed to cogl_shader_get_type");
130
 
      return COGL_SHADER_TYPE_VERTEX;
131
 
    }
132
 
 
133
 
  shader = _cogl_shader_pointer_from_handle (handle);
134
 
 
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;
140
 
  else
141
 
    {
142
 
      g_warning ("Unexpected shader type 0x%08lX", (unsigned long)type);
143
 
      return COGL_SHADER_TYPE_VERTEX;
144
 
    }
145
 
}
146
 
 
147
 
gboolean
148
 
cogl_shader_is_compiled (CoglHandle handle)
149
 
{
150
 
  GLint status;
151
 
  CoglShader *shader;
152
 
 
153
 
  if (!cogl_is_shader (handle))
154
 
    return FALSE;
155
 
 
156
 
  shader = _cogl_shader_pointer_from_handle (handle);
157
 
 
158
 
  GE (glGetShaderiv (shader->gl_handle, GL_COMPILE_STATUS, &status));
159
 
  if (status == GL_TRUE)
160
 
    return TRUE;
161
 
  else
162
 
    return FALSE;
163
 
}
164
 
 
165
 
#else /* HAVE_COGL_GLES2 */
166
 
 
167
 
/* No support on regular OpenGL 1.1 */
168
 
 
169
 
CoglHandle
170
 
cogl_create_shader (CoglShaderType type)
171
 
{
172
 
  return COGL_INVALID_HANDLE;
173
 
}
174
 
 
175
 
gboolean
176
 
cogl_is_shader (CoglHandle handle)
177
 
{
178
 
  return FALSE;
179
 
}
180
 
 
181
 
CoglHandle
182
 
cogl_shader_ref (CoglHandle handle)
183
 
{
184
 
  return COGL_INVALID_HANDLE;
185
 
}
186
 
 
187
 
void
188
 
cogl_shader_unref (CoglHandle handle)
189
 
{
190
 
}
191
 
 
192
 
void
193
 
cogl_shader_source (CoglHandle  shader,
194
 
                    const char   *source)
195
 
{
196
 
}
197
 
 
198
 
void
199
 
cogl_shader_compile (CoglHandle shader_handle)
200
 
{
201
 
}
202
 
 
203
 
gchar *
204
 
cogl_shader_get_info_log (CoglHandle handle)
205
 
{
206
 
  return NULL;
207
 
}
208
 
 
209
 
CoglShaderType
210
 
cogl_shader_get_type (CoglHandle  handle)
211
 
{
212
 
  return COGL_SHADER_TYPE_VERTEX;
213
 
}
214
 
 
215
 
gboolean
216
 
cogl_shader_is_compiled (CoglHandle handle)
217
 
{
218
 
  return FALSE;
219
 
}
220
 
 
221
 
#endif /* HAVE_COGL_GLES2 */