4
* An object oriented GL/GLES Abstraction/Utility Layer
6
* Copyright (C) 2007,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/>.
32
#include "cogl-internal.h"
33
#include "cogl-context.h"
34
#include "cogl-feature-private.h"
36
#ifdef HAVE_CLUTTER_OSX
38
really_enable_npot (void)
40
/* OSX backend + ATI Radeon X1600 + NPOT texture + GL_REPEAT seems to crash
41
* http://bugzilla.openedhand.com/show_bug.cgi?id=929
43
* Temporary workaround until post 0.8 we rejig the features set up a
44
* little to allow the backend to overide.
46
const char *gl_renderer;
47
const char *env_string;
49
/* Regardless of hardware, allow user to decide. */
50
env_string = g_getenv ("COGL_ENABLE_NPOT");
51
if (env_string != NULL)
52
return env_string[0] == '1';
54
gl_renderer = (char*)glGetString (GL_RENDERER);
55
if (strstr (gl_renderer, "ATI Radeon X1600") != NULL)
63
_cogl_get_gl_version (int *major_out, int *minor_out)
65
const char *version_string, *major_end, *minor_end;
66
int major = 0, minor = 0;
68
/* Get the OpenGL version number */
69
if ((version_string = (const char *) glGetString (GL_VERSION)) == NULL)
72
/* Extract the major number */
73
for (major_end = version_string; *major_end >= '0'
74
&& *major_end <= '9'; major_end++)
75
major = (major * 10) + *major_end - '0';
76
/* If there were no digits or the major number isn't followed by a
77
dot then it is invalid */
78
if (major_end == version_string || *major_end != '.')
81
/* Extract the minor number */
82
for (minor_end = major_end + 1; *minor_end >= '0'
83
&& *minor_end <= '9'; minor_end++)
84
minor = (minor * 10) + *minor_end - '0';
85
/* If there were no digits or there is an unexpected character then
87
if (minor_end == major_end + 1
88
|| (*minor_end && *minor_end != ' ' && *minor_end != '.'))
98
_cogl_check_driver_valid (GError **error)
101
const char *gl_extensions;
103
if (!_cogl_get_gl_version (&major, &minor))
107
COGL_DRIVER_ERROR_UNKNOWN_VERSION,
108
"The OpenGL version could not be determined");
112
/* GL 1.3 supports all of the required functionality in core */
113
if (COGL_CHECK_GL_VERSION (major, minor, 1, 3))
116
gl_extensions = (const char*) glGetString (GL_EXTENSIONS);
118
/* OpenGL 1.2 is only supported if we have the multitexturing
120
if (!_cogl_check_extension ("GL_ARB_multitexture", gl_extensions))
124
COGL_DRIVER_ERROR_INVALID_VERSION,
125
"The OpenGL driver is missing "
126
"the GL_ARB_multitexture extension");
130
/* OpenGL 1.2 is required */
131
if (!COGL_CHECK_GL_VERSION (major, minor, 1, 2))
135
COGL_DRIVER_ERROR_INVALID_VERSION,
136
"The OpenGL version of your driver (%i.%i) "
137
"is not compatible with Cogl",
145
/* Define a set of arrays containing the functions required from GL
147
#define COGL_FEATURE_BEGIN(name, min_gl_major, min_gl_minor, \
148
namespaces, extension_names, feature_flags) \
149
static const CoglFeatureFunction cogl_feature_ ## name ## _funcs[] = {
150
#define COGL_FEATURE_FUNCTION(ret, name, args) \
151
{ G_STRINGIFY (name), G_STRUCT_OFFSET (CoglContext, drv.pf_ ## name) },
152
#define COGL_FEATURE_END() \
155
#include "cogl-feature-functions.h"
157
/* Define an array of features */
158
#undef COGL_FEATURE_BEGIN
159
#define COGL_FEATURE_BEGIN(name, min_gl_major, min_gl_minor, \
160
namespaces, extension_names, feature_flags) \
161
{ min_gl_major, min_gl_minor, namespaces, \
162
extension_names, feature_flags, \
163
cogl_feature_ ## name ## _funcs },
164
#undef COGL_FEATURE_FUNCTION
165
#define COGL_FEATURE_FUNCTION(ret, name, args)
166
#undef COGL_FEATURE_END
167
#define COGL_FEATURE_END()
169
static const CoglFeatureData cogl_feature_data[] =
171
#include "cogl-feature-functions.h"
175
_cogl_features_init (void)
177
CoglFeatureFlags flags = 0;
178
const char *gl_extensions;
179
GLint max_clip_planes = 0;
180
GLint num_stencil_bits = 0;
181
int gl_major = 0, gl_minor = 0;
184
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
186
_cogl_get_gl_version (&gl_major, &gl_minor);
188
flags = (COGL_FEATURE_TEXTURE_READ_PIXELS
189
| COGL_FEATURE_UNSIGNED_INT_INDICES);
191
gl_extensions = (const char*) glGetString (GL_EXTENSIONS);
193
if (COGL_CHECK_GL_VERSION (gl_major, gl_minor, 2, 0) ||
194
_cogl_check_extension ("GL_ARB_texture_non_power_of_two", gl_extensions))
196
#ifdef HAVE_CLUTTER_OSX
197
if (really_enable_npot ())
199
flags |= COGL_FEATURE_TEXTURE_NPOT;
203
if (_cogl_check_extension ("GL_MESA_ycbcr_texture", gl_extensions))
205
flags |= COGL_FEATURE_TEXTURE_YUV;
209
GE( glGetIntegerv (GL_STENCIL_BITS, &num_stencil_bits) );
210
/* We need at least three stencil bits to combine clips */
211
if (num_stencil_bits > 2)
212
flags |= COGL_FEATURE_STENCIL_BUFFER;
214
GE( glGetIntegerv (GL_MAX_CLIP_PLANES, &max_clip_planes) );
215
if (max_clip_planes >= 4)
216
flags |= COGL_FEATURE_FOUR_CLIP_PLANES;
218
for (i = 0; i < G_N_ELEMENTS (cogl_feature_data); i++)
219
if (_cogl_feature_check (cogl_feature_data + i,
222
flags |= cogl_feature_data[i].feature_flags;
225
ctx->feature_flags = flags;
226
ctx->features_cached = TRUE;