Use all core GL functions through indirect pointers

cogl-ext-functions.h now contains definitions for all of the core GL
and GLES functions that we would normally link to directly. All of the
code has changed to access them through the cogl context pointer. The
GE macro now takes an extra parameter to specify the context because
the macro itself needs to make GL calls but various points in the Cogl
source use different names for the context variable.
This commit is contained in:
Neil Roberts
2011-07-06 21:51:00 +01:00
parent dae02a99a5
commit 2b119b07da
31 changed files with 989 additions and 828 deletions

View File

@ -154,6 +154,8 @@ _cogl_texture_rectangle_set_wrap_mode_parameters (CoglTexture *tex,
{
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
/* Only set the wrap mode if it's different from the current value
to avoid too many GL calls. Texture rectangle doesn't make use of
the r coordinate so we can ignore its wrap mode */
@ -163,13 +165,13 @@ _cogl_texture_rectangle_set_wrap_mode_parameters (CoglTexture *tex,
g_assert (can_use_wrap_mode (wrap_mode_s));
g_assert (can_use_wrap_mode (wrap_mode_t));
GE( _cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
tex_rect->gl_texture,
tex_rect->is_foreign) );
GE( glTexParameteri (GL_TEXTURE_RECTANGLE_ARB,
GL_TEXTURE_WRAP_S, wrap_mode_s) );
GE( glTexParameteri (GL_TEXTURE_RECTANGLE_ARB,
GL_TEXTURE_WRAP_T, wrap_mode_t) );
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
tex_rect->gl_texture,
tex_rect->is_foreign);
GE( ctx, glTexParameteri (GL_TEXTURE_RECTANGLE_ARB,
GL_TEXTURE_WRAP_S, wrap_mode_s) );
GE( ctx, glTexParameteri (GL_TEXTURE_RECTANGLE_ARB,
GL_TEXTURE_WRAP_T, wrap_mode_t) );
tex_rect->wrap_mode_s = wrap_mode_s;
tex_rect->wrap_mode_t = wrap_mode_t;
@ -251,6 +253,8 @@ _cogl_texture_rectangle_new_with_size (unsigned int width,
GLenum gl_format;
GLenum gl_type;
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
/* Since no data, we need some internal format */
if (internal_format == COGL_PIXEL_FORMAT_ANY)
internal_format = COGL_PIXEL_FORMAT_RGBA_8888_PRE;
@ -267,11 +271,11 @@ _cogl_texture_rectangle_new_with_size (unsigned int width,
internal_format);
_cogl_texture_driver_gen (GL_TEXTURE_RECTANGLE_ARB, 1, &tex_rect->gl_texture);
GE( _cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
tex_rect->gl_texture,
tex_rect->is_foreign) );
GE( glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, gl_intformat,
width, height, 0, gl_format, gl_type, NULL) );
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
tex_rect->gl_texture,
tex_rect->is_foreign);
GE( ctx, glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, gl_intformat,
width, height, 0, gl_format, gl_type, NULL) );
return _cogl_texture_rectangle_handle_new (tex_rect);
}
@ -344,35 +348,37 @@ _cogl_texture_rectangle_new_from_foreign (GLuint gl_handle,
GLenum gl_int_format = 0;
CoglTextureRectangle *tex_rect;
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);
if (!_cogl_texture_driver_allows_foreign_gl_target (GL_TEXTURE_RECTANGLE_ARB))
return COGL_INVALID_HANDLE;
/* Make sure it is a valid GL texture object */
if (!glIsTexture (gl_handle))
if (!ctx->glIsTexture (gl_handle))
return COGL_INVALID_HANDLE;
/* Make sure binding succeeds */
while ((gl_error = glGetError ()) != GL_NO_ERROR)
while ((gl_error = ctx->glGetError ()) != GL_NO_ERROR)
;
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB, gl_handle, TRUE);
if (glGetError () != GL_NO_ERROR)
if (ctx->glGetError () != GL_NO_ERROR)
return COGL_INVALID_HANDLE;
/* Obtain texture parameters */
#if HAVE_COGL_GL
GE( glGetTexLevelParameteriv (GL_TEXTURE_RECTANGLE_ARB, 0,
GL_TEXTURE_COMPRESSED,
&gl_compressed) );
GE( ctx, glGetTexLevelParameteriv (GL_TEXTURE_RECTANGLE_ARB, 0,
GL_TEXTURE_COMPRESSED,
&gl_compressed) );
{
GLint val;
GE( glGetTexLevelParameteriv (GL_TEXTURE_RECTANGLE_ARB, 0,
GL_TEXTURE_INTERNAL_FORMAT,
&val) );
GE( ctx, glGetTexLevelParameteriv (GL_TEXTURE_RECTANGLE_ARB, 0,
GL_TEXTURE_INTERNAL_FORMAT,
&val) );
gl_int_format = val;
}
@ -499,6 +505,8 @@ _cogl_texture_rectangle_set_filters (CoglTexture *tex,
{
CoglTextureRectangle *tex_rect = COGL_TEXTURE_RECTANGLE (tex);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
if (min_filter == tex_rect->min_filter
&& mag_filter == tex_rect->mag_filter)
return;
@ -511,13 +519,13 @@ _cogl_texture_rectangle_set_filters (CoglTexture *tex,
tex_rect->mag_filter = mag_filter;
/* Apply new filters to the texture */
GE( _cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
tex_rect->gl_texture,
tex_rect->is_foreign) );
GE( glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
mag_filter) );
GE( glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
min_filter) );
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
tex_rect->gl_texture,
tex_rect->is_foreign);
GE( ctx, glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
mag_filter) );
GE( ctx, glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
min_filter) );
}
static void
@ -580,6 +588,8 @@ _cogl_texture_rectangle_get_data (CoglTexture *tex,
GLenum gl_format;
GLenum gl_type;
_COGL_GET_CONTEXT (ctx, FALSE);
bpp = _cogl_get_format_bpp (format);
_cogl_pixel_format_to_gl (format,
@ -589,9 +599,9 @@ _cogl_texture_rectangle_get_data (CoglTexture *tex,
_cogl_texture_driver_prep_gl_for_pixels_download (rowstride, bpp);
GE( _cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
tex_rect->gl_texture,
tex_rect->is_foreign) );
_cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB,
tex_rect->gl_texture,
tex_rect->is_foreign);
return _cogl_texture_driver_gl_get_tex_image (GL_TEXTURE_RECTANGLE_ARB,
gl_format,
gl_type,