Dynamically load the GL or GLES library
The GL or GLES library is now dynamically loaded by the CoglRenderer so that it can choose between GL, GLES1 and GLES2 at runtime. The library is loaded by the renderer because it needs to be done before calling eglInitialize. There is a new environment variable called COGL_DRIVER to choose between gl, gles1 or gles2. The #ifdefs for HAVE_COGL_GL, HAVE_COGL_GLES and HAVE_COGL_GLES2 have been changed so that they don't assume the ifdefs are mutually exclusive. They haven't been removed entirely so that it's possible to compile the GLES backends without the the enums from the GL headers. When using GLX the winsys additionally dynamically loads libGL because that also contains the GLX API. It can't be linked in directly because that would probably conflict with the GLES API if the EGL is selected. When compiling with EGL support the library links directly to libEGL because it doesn't contain any GL API so it shouldn't have any conflicts. When building for WGL or OSX Cogl still directly links against the GL API so there is a #define in config.h so that Cogl won't try to dlopen the library. Cogl-pango previously had a #ifdef to detect when the GL backend is used so that it can sneakily pass GL_QUADS to cogl_vertex_buffer_draw. This is now changed so that it queries the CoglContext for the backend. However to get this to work Cogl now needs to export the _cogl_context_get_default symbol and cogl-pango needs some extra -I flags to so that it can include cogl-context-private.h
This commit is contained in:
@ -41,11 +41,16 @@ static void _cogl_shader_free (CoglShader *shader);
|
||||
COGL_HANDLE_DEFINE (Shader, shader);
|
||||
COGL_OBJECT_DEFINE_DEPRECATED_REF_COUNTING (shader);
|
||||
|
||||
#ifndef GL_FRAGMENT_SHADER
|
||||
#define GL_FRAGMENT_SHADER 0x8B30
|
||||
#endif
|
||||
#ifndef GL_VERTEX_SHADER
|
||||
#define GL_VERTEX_SHADER 0x8B31
|
||||
#endif
|
||||
|
||||
static void
|
||||
_cogl_shader_free (CoglShader *shader)
|
||||
{
|
||||
#ifndef HAVE_COGL_GLES
|
||||
|
||||
/* Frees shader resources but its handle is not
|
||||
released! Do that separately before this! */
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
@ -61,8 +66,6 @@ _cogl_shader_free (CoglShader *shader)
|
||||
if (shader->gl_handle)
|
||||
GE (ctx, glDeleteShader (shader->gl_handle));
|
||||
|
||||
#endif /* HAVE_COGL_GLES */
|
||||
|
||||
g_slice_free (CoglShader, shader);
|
||||
}
|
||||
|
||||
@ -98,8 +101,6 @@ cogl_create_shader (CoglShaderType type)
|
||||
static void
|
||||
delete_shader (CoglShader *shader)
|
||||
{
|
||||
#ifndef HAVE_COGL_GLES
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
#ifdef HAVE_COGL_GL
|
||||
@ -116,8 +117,6 @@ delete_shader (CoglShader *shader)
|
||||
}
|
||||
|
||||
shader->gl_handle = 0;
|
||||
|
||||
#endif /* HAVE_COGL_GLES */
|
||||
}
|
||||
|
||||
void
|
||||
@ -154,16 +153,15 @@ cogl_shader_source (CoglHandle handle,
|
||||
void
|
||||
cogl_shader_compile (CoglHandle handle)
|
||||
{
|
||||
#ifdef HAVE_COGL_GL
|
||||
CoglShader *shader = handle;
|
||||
#endif
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
if (!cogl_is_shader (handle))
|
||||
return;
|
||||
|
||||
#ifdef HAVE_COGL_GL
|
||||
_cogl_shader_compile_real (shader, 0 /* ignored */);
|
||||
#endif
|
||||
if (ctx->driver == COGL_DRIVER_GL)
|
||||
_cogl_shader_compile_real (shader, 0 /* ignored */);
|
||||
|
||||
/* XXX: For GLES2 we don't actually compile anything until the
|
||||
* shader gets used so we have an opportunity to add some
|
||||
@ -183,43 +181,49 @@ _cogl_shader_set_source_with_boilerplate (GLuint shader_gl_handle,
|
||||
const char **strings_in,
|
||||
const GLint *lengths_in)
|
||||
{
|
||||
#ifndef HAVE_COGL_GLES
|
||||
|
||||
static const char vertex_boilerplate[] = _COGL_VERTEX_SHADER_BOILERPLATE;
|
||||
static const char fragment_boilerplate[] = _COGL_FRAGMENT_SHADER_BOILERPLATE;
|
||||
const char *vertex_boilerplate;
|
||||
const char *fragment_boilerplate;
|
||||
|
||||
const char **strings = g_alloca (sizeof (char *) * (count_in + 3));
|
||||
GLint *lengths = g_alloca (sizeof (GLint) * (count_in + 3));
|
||||
int count = 0;
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
char *tex_coord_declarations = NULL;
|
||||
#endif
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
if (cogl_features_available (COGL_FEATURE_TEXTURE_3D))
|
||||
if (ctx->driver == COGL_DRIVER_GLES2)
|
||||
{
|
||||
vertex_boilerplate = _COGL_VERTEX_SHADER_BOILERPLATE_GLES2;
|
||||
fragment_boilerplate = _COGL_FRAGMENT_SHADER_BOILERPLATE_GLES2;
|
||||
}
|
||||
else
|
||||
{
|
||||
vertex_boilerplate = _COGL_VERTEX_SHADER_BOILERPLATE_GL;
|
||||
fragment_boilerplate = _COGL_FRAGMENT_SHADER_BOILERPLATE_GL;
|
||||
}
|
||||
|
||||
if (ctx->driver == COGL_DRIVER_GLES2 &&
|
||||
cogl_features_available (COGL_FEATURE_TEXTURE_3D))
|
||||
{
|
||||
static const char texture_3d_extension[] =
|
||||
"#extension GL_OES_texture_3D : enable\n";
|
||||
strings[count] = texture_3d_extension;
|
||||
lengths[count++] = sizeof (texture_3d_extension) - 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (shader_gl_type == GL_VERTEX_SHADER)
|
||||
{
|
||||
strings[count] = vertex_boilerplate;
|
||||
lengths[count++] = sizeof (vertex_boilerplate) - 1;
|
||||
lengths[count++] = strlen (vertex_boilerplate);
|
||||
}
|
||||
else if (shader_gl_type == GL_FRAGMENT_SHADER)
|
||||
{
|
||||
strings[count] = fragment_boilerplate;
|
||||
lengths[count++] = sizeof (fragment_boilerplate) - 1;
|
||||
lengths[count++] = strlen (fragment_boilerplate);
|
||||
}
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
if (n_tex_coord_attribs)
|
||||
if (ctx->driver == COGL_DRIVER_GLES2 &&
|
||||
n_tex_coord_attribs)
|
||||
{
|
||||
GString *declarations = g_string_new (NULL);
|
||||
|
||||
@ -245,7 +249,6 @@ _cogl_shader_set_source_with_boilerplate (GLuint shader_gl_handle,
|
||||
strings[count] = tex_coord_declarations;
|
||||
lengths[count++] = -1; /* null terminated */
|
||||
}
|
||||
#endif
|
||||
|
||||
memcpy (strings + count, strings_in, sizeof (char *) * count_in);
|
||||
if (lengths_in)
|
||||
@ -282,19 +285,13 @@ _cogl_shader_set_source_with_boilerplate (GLuint shader_gl_handle,
|
||||
GE( ctx, glShaderSource (shader_gl_handle, count,
|
||||
(const char **) strings, lengths) );
|
||||
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
g_free (tex_coord_declarations);
|
||||
#endif
|
||||
|
||||
#endif /* HAVE_COGL_GLES */
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_shader_compile_real (CoglHandle handle,
|
||||
int n_tex_coord_attribs)
|
||||
{
|
||||
#ifndef HAVE_COGL_GLES
|
||||
|
||||
CoglShader *shader = handle;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
@ -343,7 +340,9 @@ _cogl_shader_compile_real (CoglHandle handle,
|
||||
|
||||
if (shader->gl_handle
|
||||
#ifdef HAVE_COGL_GLES2
|
||||
&& shader->n_tex_coord_attribs >= n_tex_coord_attribs
|
||||
&&
|
||||
(ctx->driver != COGL_DRIVER_GLES2 ||
|
||||
shader->n_tex_coord_attribs >= n_tex_coord_attribs)
|
||||
#endif
|
||||
)
|
||||
return;
|
||||
@ -389,19 +388,11 @@ _cogl_shader_compile_real (CoglHandle handle,
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* HAVE_COGL_GLES */
|
||||
}
|
||||
|
||||
char *
|
||||
cogl_shader_get_info_log (CoglHandle handle)
|
||||
{
|
||||
#ifdef HAVE_COGL_GLES
|
||||
|
||||
return NULL;
|
||||
|
||||
#else /* HAVE_COGL_GLES */
|
||||
|
||||
CoglShader *shader;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NULL);
|
||||
@ -443,8 +434,6 @@ cogl_shader_get_info_log (CoglHandle handle)
|
||||
buffer[len] = '\0';
|
||||
return g_strdup (buffer);
|
||||
}
|
||||
|
||||
#endif /* HAVE_COGL_GLES */
|
||||
}
|
||||
|
||||
CoglShaderType
|
||||
@ -467,12 +456,7 @@ cogl_shader_get_type (CoglHandle handle)
|
||||
gboolean
|
||||
cogl_shader_is_compiled (CoglHandle handle)
|
||||
{
|
||||
#ifdef HAVE_COGL_GLES
|
||||
|
||||
return FALSE;
|
||||
|
||||
#else /* HAVE_COGL_GLES */
|
||||
|
||||
#if defined (HAVE_COGL_GL) || defined (HAVE_COGL_GLES2)
|
||||
GLint status;
|
||||
CoglShader *shader;
|
||||
|
||||
@ -513,6 +497,7 @@ cogl_shader_is_compiled (CoglHandle handle)
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#endif /* HAVE_COGL_GLES */
|
||||
#else
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user