cogl: Move texture unit state to CoglGLContext

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1194
This commit is contained in:
Adam Jackson 2020-04-09 14:12:31 -04:00
parent e03c75bac7
commit 245977e525
4 changed files with 39 additions and 22 deletions

View File

@ -121,9 +121,6 @@ struct _CoglContext
CoglMatrixEntry identity_entry; CoglMatrixEntry identity_entry;
GArray *texture_units;
int active_texture_unit;
/* Only used for comparing other pipelines when reading pixels. */ /* Only used for comparing other pipelines when reading pixels. */
CoglPipeline *opaque_color_pipeline; CoglPipeline *opaque_color_pipeline;

View File

@ -94,47 +94,51 @@ CoglTextureUnit *
_cogl_get_texture_unit (int index_) _cogl_get_texture_unit (int index_)
{ {
_COGL_GET_CONTEXT (ctx, NULL); _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 i;
int prev_len = ctx->texture_units->len; int prev_len = glctx->texture_units->len;
ctx->texture_units = g_array_set_size (ctx->texture_units, index_ + 1); glctx->texture_units = g_array_set_size (glctx->texture_units,
index_ + 1);
for (i = prev_len; i <= index_; i++) for (i = prev_len; i <= index_; i++)
{ {
CoglTextureUnit *unit = CoglTextureUnit *unit =
&g_array_index (ctx->texture_units, CoglTextureUnit, i); &g_array_index (glctx->texture_units, CoglTextureUnit, i);
texture_unit_init (ctx, unit, 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 void
_cogl_destroy_texture_units (CoglContext *ctx) _cogl_destroy_texture_units (CoglContext *ctx)
{ {
int i; 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 = CoglTextureUnit *unit =
&g_array_index (ctx->texture_units, CoglTextureUnit, i); &g_array_index (glctx->texture_units, CoglTextureUnit, i);
texture_unit_free (unit); texture_unit_free (unit);
} }
g_array_free (ctx->texture_units, TRUE); g_array_free (glctx->texture_units, TRUE);
} }
void void
_cogl_set_active_texture_unit (int unit_index) _cogl_set_active_texture_unit (int unit_index)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _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)); 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; int i;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _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 = CoglTextureUnit *unit =
&g_array_index (ctx->texture_units, CoglTextureUnit, i); &g_array_index (glctx->texture_units, CoglTextureUnit, i);
if (unit->gl_texture == gl_texture) if (unit->gl_texture == gl_texture)
{ {
@ -218,11 +223,12 @@ _cogl_pipeline_texture_storage_change_notify (CoglTexture *texture)
int i; int i;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _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 = CoglTextureUnit *unit =
&g_array_index (ctx->texture_units, CoglTextureUnit, i); &g_array_index (glctx->texture_units, CoglTextureUnit, i);
if (unit->layer && if (unit->layer &&
_cogl_pipeline_layer_get_texture (unit->layer) == texture) _cogl_pipeline_layer_get_texture (unit->layer) == texture)
@ -704,11 +710,12 @@ foreach_texture_unit_update_filter_and_wrap_modes (void)
int i; int i;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _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 = CoglTextureUnit *unit =
&g_array_index (ctx->texture_units, CoglTextureUnit, i); &g_array_index (glctx->texture_units, CoglTextureUnit, i);
if (unit->layer) if (unit->layer)
{ {

View File

@ -76,7 +76,10 @@ _cogl_gl_error_to_string (GLenum error_code);
#endif /* COGL_GL_DEBUG */ #endif /* COGL_GL_DEBUG */
typedef struct _CoglGLContext CoglGLContext; /* opaque for the moment */ typedef struct _CoglGLContext {
GArray *texture_units;
int active_texture_unit;
} CoglGLContext;
CoglGLContext * CoglGLContext *
_cogl_driver_gl_context (CoglContext *context); _cogl_driver_gl_context (CoglContext *context);

View File

@ -84,12 +84,21 @@ _cogl_driver_gl_context (CoglContext *context)
gboolean gboolean
_cogl_driver_gl_context_init (CoglContext *context) _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)); g_array_new (FALSE, FALSE, sizeof (CoglTextureUnit));
/* See cogl-pipeline.c for more details about why we leave texture unit 1 /* See cogl-pipeline.c for more details about why we leave texture unit 1
* active by default... */ * active by default... */
context->active_texture_unit = 1; gl_context->active_texture_unit = 1;
GE (context, glActiveTexture (GL_TEXTURE1)); GE (context, glActiveTexture (GL_TEXTURE1));
return TRUE; return TRUE;
@ -99,6 +108,7 @@ void
_cogl_driver_gl_context_deinit (CoglContext *context) _cogl_driver_gl_context_deinit (CoglContext *context)
{ {
_cogl_destroy_texture_units (context); _cogl_destroy_texture_units (context);
g_free (context->driver_context);
} }
GLenum GLenum