diff --git a/cogl/cogl/cogl-context-private.h b/cogl/cogl/cogl-context-private.h index 594b80c30..79d4f7b5e 100644 --- a/cogl/cogl/cogl-context-private.h +++ b/cogl/cogl/cogl-context-private.h @@ -121,9 +121,6 @@ struct _CoglContext CoglMatrixEntry identity_entry; - GArray *texture_units; - int active_texture_unit; - /* Only used for comparing other pipelines when reading pixels. */ CoglPipeline *opaque_color_pipeline; diff --git a/cogl/cogl/driver/gl/cogl-pipeline-opengl.c b/cogl/cogl/driver/gl/cogl-pipeline-opengl.c index 44a968a2c..df1ce13e2 100644 --- a/cogl/cogl/driver/gl/cogl-pipeline-opengl.c +++ b/cogl/cogl/driver/gl/cogl-pipeline-opengl.c @@ -94,47 +94,51 @@ CoglTextureUnit * _cogl_get_texture_unit (int index_) { _COGL_GET_CONTEXT (ctx, NULL); + CoglGLContext *glctx = _cogl_driver_gl_context(ctx); - if (ctx->texture_units->len < (index_ + 1)) + if (glctx->texture_units->len < (index_ + 1)) { int i; - int prev_len = ctx->texture_units->len; - ctx->texture_units = g_array_set_size (ctx->texture_units, index_ + 1); + int prev_len = glctx->texture_units->len; + glctx->texture_units = g_array_set_size (glctx->texture_units, + index_ + 1); for (i = prev_len; i <= index_; i++) { CoglTextureUnit *unit = - &g_array_index (ctx->texture_units, CoglTextureUnit, i); + &g_array_index (glctx->texture_units, CoglTextureUnit, i); texture_unit_init (ctx, unit, i); } } - return &g_array_index (ctx->texture_units, CoglTextureUnit, index_); + return &g_array_index (glctx->texture_units, CoglTextureUnit, index_); } void _cogl_destroy_texture_units (CoglContext *ctx) { int i; + CoglGLContext *glctx = _cogl_driver_gl_context(ctx); - for (i = 0; i < ctx->texture_units->len; i++) + for (i = 0; i < glctx->texture_units->len; i++) { CoglTextureUnit *unit = - &g_array_index (ctx->texture_units, CoglTextureUnit, i); + &g_array_index (glctx->texture_units, CoglTextureUnit, i); texture_unit_free (unit); } - g_array_free (ctx->texture_units, TRUE); + g_array_free (glctx->texture_units, TRUE); } void _cogl_set_active_texture_unit (int unit_index) { _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglGLContext *glctx = _cogl_driver_gl_context(ctx); - if (ctx->active_texture_unit != unit_index) + if (glctx->active_texture_unit != unit_index) { GE (ctx, glActiveTexture (GL_TEXTURE0 + unit_index)); - ctx->active_texture_unit = unit_index; + glctx->active_texture_unit = unit_index; } } @@ -190,11 +194,12 @@ _cogl_delete_gl_texture (GLuint gl_texture) int i; _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglGLContext *glctx = _cogl_driver_gl_context(ctx); - for (i = 0; i < ctx->texture_units->len; i++) + for (i = 0; i < glctx->texture_units->len; i++) { CoglTextureUnit *unit = - &g_array_index (ctx->texture_units, CoglTextureUnit, i); + &g_array_index (glctx->texture_units, CoglTextureUnit, i); if (unit->gl_texture == gl_texture) { @@ -218,11 +223,12 @@ _cogl_pipeline_texture_storage_change_notify (CoglTexture *texture) int i; _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglGLContext *glctx = _cogl_driver_gl_context(ctx); - for (i = 0; i < ctx->texture_units->len; i++) + for (i = 0; i < glctx->texture_units->len; i++) { CoglTextureUnit *unit = - &g_array_index (ctx->texture_units, CoglTextureUnit, i); + &g_array_index (glctx->texture_units, CoglTextureUnit, i); if (unit->layer && _cogl_pipeline_layer_get_texture (unit->layer) == texture) @@ -704,11 +710,12 @@ foreach_texture_unit_update_filter_and_wrap_modes (void) int i; _COGL_GET_CONTEXT (ctx, NO_RETVAL); + CoglGLContext *glctx = _cogl_driver_gl_context(ctx); - for (i = 0; i < ctx->texture_units->len; i++) + for (i = 0; i < glctx->texture_units->len; i++) { CoglTextureUnit *unit = - &g_array_index (ctx->texture_units, CoglTextureUnit, i); + &g_array_index (glctx->texture_units, CoglTextureUnit, i); if (unit->layer) { diff --git a/cogl/cogl/driver/gl/cogl-util-gl-private.h b/cogl/cogl/driver/gl/cogl-util-gl-private.h index fb3f8534c..0d23da1a8 100644 --- a/cogl/cogl/driver/gl/cogl-util-gl-private.h +++ b/cogl/cogl/driver/gl/cogl-util-gl-private.h @@ -76,7 +76,10 @@ _cogl_gl_error_to_string (GLenum error_code); #endif /* COGL_GL_DEBUG */ -typedef struct _CoglGLContext CoglGLContext; /* opaque for the moment */ +typedef struct _CoglGLContext { + GArray *texture_units; + int active_texture_unit; +} CoglGLContext; CoglGLContext * _cogl_driver_gl_context (CoglContext *context); diff --git a/cogl/cogl/driver/gl/cogl-util-gl.c b/cogl/cogl/driver/gl/cogl-util-gl.c index afd6d3a8a..c49c5289f 100644 --- a/cogl/cogl/driver/gl/cogl-util-gl.c +++ b/cogl/cogl/driver/gl/cogl-util-gl.c @@ -84,12 +84,21 @@ _cogl_driver_gl_context (CoglContext *context) gboolean _cogl_driver_gl_context_init (CoglContext *context) { - context->texture_units = + CoglGLContext *gl_context; + + if (!context->driver_context) + context->driver_context = g_new0 (CoglContext, 1); + + gl_context = _cogl_driver_gl_context (context); + if (!gl_context) + return FALSE; + + gl_context->texture_units = g_array_new (FALSE, FALSE, sizeof (CoglTextureUnit)); /* See cogl-pipeline.c for more details about why we leave texture unit 1 * active by default... */ - context->active_texture_unit = 1; + gl_context->active_texture_unit = 1; GE (context, glActiveTexture (GL_TEXTURE1)); return TRUE; @@ -99,6 +108,7 @@ void _cogl_driver_gl_context_deinit (CoglContext *context) { _cogl_destroy_texture_units (context); + g_free (context->driver_context); } GLenum