matrix-stack: Avoid referencing the default CoglContext

This removes the use of _COGL_GET_CONTEXT() from cogl-matrix-stack.c
as part of the ongoing effort to evolve cogl to get rid of the need for
a default context.

Reviewed-by: Neil Roberts <neil@linux.intel.com>
This commit is contained in:
Robert Bragg 2011-11-21 14:22:01 +00:00
parent 5156365eae
commit 39a7bcff67
7 changed files with 88 additions and 74 deletions

View File

@ -109,7 +109,7 @@ set_clip_plane (CoglFramebuffer *framebuffer,
_cogl_matrix_stack_translate (modelview_stack, _cogl_matrix_stack_translate (modelview_stack,
-vertex_a[0], -vertex_a[1], -vertex_a[2]); -vertex_a[0], -vertex_a[1], -vertex_a[2]);
_cogl_matrix_stack_flush_to_gl (modelview_stack, COGL_MATRIX_MODELVIEW); _cogl_matrix_stack_flush_to_gl (ctx, modelview_stack, COGL_MATRIX_MODELVIEW);
planef[0] = 0; planef[0] = 0;
planef[1] = -1.0; planef[1] = -1.0;
@ -210,8 +210,7 @@ add_stencil_clip_rectangle (CoglFramebuffer *framebuffer,
_cogl_framebuffer_get_modelview_stack (framebuffer); _cogl_framebuffer_get_modelview_stack (framebuffer);
CoglMatrixStack *projection_stack = CoglMatrixStack *projection_stack =
_cogl_framebuffer_get_projection_stack (framebuffer); _cogl_framebuffer_get_projection_stack (framebuffer);
CoglContext *ctx = cogl_framebuffer_get_context (framebuffer);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
/* temporarily swap in our special stenciling pipeline */ /* temporarily swap in our special stenciling pipeline */
_cogl_push_source (ctx->stencil_pipeline, FALSE); _cogl_push_source (ctx->stencil_pipeline, FALSE);
@ -219,9 +218,11 @@ add_stencil_clip_rectangle (CoglFramebuffer *framebuffer,
/* This can be called from the journal code which doesn't flush /* This can be called from the journal code which doesn't flush
the matrix stacks between calls so we need to ensure they're the matrix stacks between calls so we need to ensure they're
flushed now */ flushed now */
_cogl_matrix_stack_flush_to_gl (modelview_stack, _cogl_matrix_stack_flush_to_gl (ctx,
modelview_stack,
COGL_MATRIX_MODELVIEW); COGL_MATRIX_MODELVIEW);
_cogl_matrix_stack_flush_to_gl (projection_stack, _cogl_matrix_stack_flush_to_gl (ctx,
projection_stack,
COGL_MATRIX_PROJECTION); COGL_MATRIX_PROJECTION);
if (first) if (first)
@ -257,9 +258,11 @@ add_stencil_clip_rectangle (CoglFramebuffer *framebuffer,
_cogl_matrix_stack_push (modelview_stack); _cogl_matrix_stack_push (modelview_stack);
_cogl_matrix_stack_load_identity (modelview_stack); _cogl_matrix_stack_load_identity (modelview_stack);
_cogl_matrix_stack_flush_to_gl (modelview_stack, _cogl_matrix_stack_flush_to_gl (ctx,
modelview_stack,
COGL_MATRIX_MODELVIEW); COGL_MATRIX_MODELVIEW);
_cogl_matrix_stack_flush_to_gl (projection_stack, _cogl_matrix_stack_flush_to_gl (ctx,
projection_stack,
COGL_MATRIX_PROJECTION); COGL_MATRIX_PROJECTION);
_cogl_rectangle_immediate (-1.0, -1.0, 1.0, 1.0); _cogl_rectangle_immediate (-1.0, -1.0, 1.0, 1.0);
@ -298,9 +301,11 @@ add_stencil_clip_silhouette (CoglFramebuffer *framebuffer,
/* This can be called from the clip stack code which doesn't flush /* This can be called from the clip stack code which doesn't flush
the matrix stacks between calls so we need to ensure they're the matrix stacks between calls so we need to ensure they're
flushed now */ flushed now */
_cogl_matrix_stack_flush_to_gl (modelview_stack, _cogl_matrix_stack_flush_to_gl (ctx,
modelview_stack,
COGL_MATRIX_MODELVIEW); COGL_MATRIX_MODELVIEW);
_cogl_matrix_stack_flush_to_gl (projection_stack, _cogl_matrix_stack_flush_to_gl (ctx,
projection_stack,
COGL_MATRIX_PROJECTION); COGL_MATRIX_PROJECTION);
/* Just setup a simple pipeline that doesn't use texturing... */ /* Just setup a simple pipeline that doesn't use texturing... */
@ -361,12 +366,14 @@ add_stencil_clip_silhouette (CoglFramebuffer *framebuffer,
_cogl_matrix_stack_push (projection_stack); _cogl_matrix_stack_push (projection_stack);
_cogl_matrix_stack_load_identity (projection_stack); _cogl_matrix_stack_load_identity (projection_stack);
_cogl_matrix_stack_flush_to_gl (projection_stack, _cogl_matrix_stack_flush_to_gl (ctx,
projection_stack,
COGL_MATRIX_PROJECTION); COGL_MATRIX_PROJECTION);
_cogl_matrix_stack_push (modelview_stack); _cogl_matrix_stack_push (modelview_stack);
_cogl_matrix_stack_load_identity (modelview_stack); _cogl_matrix_stack_load_identity (modelview_stack);
_cogl_matrix_stack_flush_to_gl (modelview_stack, _cogl_matrix_stack_flush_to_gl (ctx,
modelview_stack,
COGL_MATRIX_MODELVIEW); COGL_MATRIX_MODELVIEW);
_cogl_rectangle_immediate (-1.0, -1.0, 1.0, 1.0); _cogl_rectangle_immediate (-1.0, -1.0, 1.0, 1.0);

View File

@ -292,7 +292,8 @@ _cogl_journal_flush_modelview_and_entries (CoglJournalEntry *batch_start,
{ {
_cogl_matrix_stack_set (state->modelview_stack, _cogl_matrix_stack_set (state->modelview_stack,
&batch_start->model_view); &batch_start->model_view);
_cogl_matrix_stack_flush_to_gl (state->modelview_stack, _cogl_matrix_stack_flush_to_gl (ctx,
state->modelview_stack,
COGL_MATRIX_MODELVIEW); COGL_MATRIX_MODELVIEW);
} }
@ -718,14 +719,16 @@ _cogl_journal_flush_clip_stacks_and_entries (CoglJournalEntry *batch_start,
if (G_LIKELY (!(COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM)))) if (G_LIKELY (!(COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM))))
{ {
_cogl_matrix_stack_load_identity (state->modelview_stack); _cogl_matrix_stack_load_identity (state->modelview_stack);
_cogl_matrix_stack_flush_to_gl (state->modelview_stack, _cogl_matrix_stack_flush_to_gl (ctx,
state->modelview_stack,
COGL_MATRIX_MODELVIEW); COGL_MATRIX_MODELVIEW);
} }
/* Setting up the clip state can sometimes also flush the projection /* Setting up the clip state can sometimes also flush the projection
matrix so we should flush it again. This will be a no-op if the matrix so we should flush it again. This will be a no-op if the
clip code didn't modify the projection */ clip code didn't modify the projection */
_cogl_matrix_stack_flush_to_gl (state->projection_stack, _cogl_matrix_stack_flush_to_gl (ctx,
state->projection_stack,
COGL_MATRIX_PROJECTION); COGL_MATRIX_PROJECTION);
batch_and_call (batch_start, batch_and_call (batch_start,

View File

@ -396,23 +396,22 @@ _cogl_matrix_stack_set (CoglMatrixStack *stack,
#if defined (HAVE_COGL_GL) || defined (HAVE_COGL_GLES) #if defined (HAVE_COGL_GL) || defined (HAVE_COGL_GLES)
static void static void
flush_to_fixed_api_gl (gboolean is_identity, flush_to_fixed_api_gl (CoglContext *context,
gboolean is_identity,
const CoglMatrix *matrix, const CoglMatrix *matrix,
void *user_data) void *user_data)
{ {
CoglMatrixStack *stack = user_data; CoglMatrixStack *stack = user_data;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
if (is_identity) if (is_identity)
{ {
if (!stack->flushed_identity) if (!stack->flushed_identity)
GE (ctx, glLoadIdentity ()); GE (context, glLoadIdentity ());
stack->flushed_identity = TRUE; stack->flushed_identity = TRUE;
} }
else else
{ {
GE (ctx, glLoadMatrixf (cogl_matrix_get_array (matrix)) ); GE (context, glLoadMatrixf (cogl_matrix_get_array (matrix)) );
stack->flushed_identity = FALSE; stack->flushed_identity = FALSE;
} }
} }
@ -420,16 +419,13 @@ flush_to_fixed_api_gl (gboolean is_identity,
#endif #endif
void void
_cogl_matrix_stack_prepare_for_flush (CoglMatrixStack *stack, _cogl_prepare_matrix_stack_for_flush (CoglContext *context,
CoglMatrixStack *stack,
CoglMatrixMode mode, CoglMatrixMode mode,
CoglMatrixStackFlushFunc callback, CoglMatrixStackFlushFunc callback,
void *user_data) void *user_data)
{ {
CoglMatrixState *state; CoglMatrixState *state = _cogl_matrix_stack_top (stack);
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
state = _cogl_matrix_stack_top (stack);
/* Because Cogl defines texture coordinates to have a top left origin and /* Because Cogl defines texture coordinates to have a top left origin and
* because offscreen framebuffers may be used for rendering to textures we * because offscreen framebuffers may be used for rendering to textures we
@ -440,29 +436,28 @@ _cogl_matrix_stack_prepare_for_flush (CoglMatrixStack *stack,
{ {
CoglMatrix flipped_projection; CoglMatrix flipped_projection;
CoglMatrix *projection = CoglMatrix *projection =
state->is_identity ? &ctx->identity_matrix : &state->matrix; state->is_identity ? &context->identity_matrix : &state->matrix;
cogl_matrix_multiply (&flipped_projection, cogl_matrix_multiply (&flipped_projection,
&ctx->y_flip_matrix, projection); &context->y_flip_matrix, projection);
callback (FALSE, &flipped_projection, user_data); callback (context, FALSE, &flipped_projection, user_data);
} }
else else
callback (state->is_identity, {
state->is_identity ? &ctx->identity_matrix : &state->matrix, CoglMatrix *modelview =
user_data); state->is_identity ? &context->identity_matrix : &state->matrix;
callback (context, state->is_identity, modelview, user_data);
}
} }
void void
_cogl_matrix_stack_flush_to_gl (CoglMatrixStack *stack, _cogl_matrix_stack_flush_to_gl (CoglContext *context,
CoglMatrixMode mode) CoglMatrixStack *stack,
CoglMatrixMode mode)
{ {
CoglMatrixState *state; CoglMatrixState *state = _cogl_matrix_stack_top (stack);
_COGL_GET_CONTEXT (ctx, NO_RETVAL); if (context->driver == COGL_DRIVER_GLES2)
state = _cogl_matrix_stack_top (stack);
if (ctx->driver == COGL_DRIVER_GLES2)
{ {
/* Under GLES2 we need to flush the matrices differently because /* Under GLES2 we need to flush the matrices differently because
they are stored in uniforms attached to the program instead of they are stored in uniforms attached to the program instead of
@ -475,16 +470,16 @@ _cogl_matrix_stack_flush_to_gl (CoglMatrixStack *stack,
{ {
case COGL_MATRIX_MODELVIEW: case COGL_MATRIX_MODELVIEW:
cogl_object_ref (stack); cogl_object_ref (stack);
if (ctx->flushed_modelview_stack) if (context->flushed_modelview_stack)
cogl_object_unref (ctx->flushed_modelview_stack); cogl_object_unref (context->flushed_modelview_stack);
ctx->flushed_modelview_stack = stack; context->flushed_modelview_stack = stack;
break; break;
case COGL_MATRIX_PROJECTION: case COGL_MATRIX_PROJECTION:
cogl_object_ref (stack); cogl_object_ref (stack);
if (ctx->flushed_projection_stack) if (context->flushed_projection_stack)
cogl_object_unref (ctx->flushed_projection_stack); cogl_object_unref (context->flushed_projection_stack);
ctx->flushed_projection_stack = stack; context->flushed_projection_stack = stack;
break; break;
case COGL_MATRIX_TEXTURE: case COGL_MATRIX_TEXTURE:
@ -501,7 +496,7 @@ _cogl_matrix_stack_flush_to_gl (CoglMatrixStack *stack,
if (stack->flushed_state == state) if (stack->flushed_state == state)
return; return;
if (ctx->flushed_matrix_mode != mode) if (context->flushed_matrix_mode != mode)
{ {
GLenum gl_mode = 0; GLenum gl_mode = 0;
@ -520,11 +515,12 @@ _cogl_matrix_stack_flush_to_gl (CoglMatrixStack *stack,
break; break;
} }
GE (ctx, glMatrixMode (gl_mode)); GE (context, glMatrixMode (gl_mode));
ctx->flushed_matrix_mode = mode; context->flushed_matrix_mode = mode;
} }
_cogl_matrix_stack_prepare_for_flush (stack, _cogl_prepare_matrix_stack_for_flush (context,
stack,
mode, mode,
flush_to_fixed_api_gl, flush_to_fixed_api_gl,
stack); stack);

View File

@ -30,6 +30,7 @@
#define __COGL_MATRIX_STACK_H #define __COGL_MATRIX_STACK_H
#include "cogl-matrix.h" #include "cogl-matrix.h"
#include "cogl-context.h"
typedef struct _CoglMatrixStack CoglMatrixStack; typedef struct _CoglMatrixStack CoglMatrixStack;
@ -39,7 +40,8 @@ typedef enum {
COGL_MATRIX_TEXTURE COGL_MATRIX_TEXTURE
} CoglMatrixMode; } CoglMatrixMode;
typedef void (* CoglMatrixStackFlushFunc) (gboolean is_identity, typedef void (* CoglMatrixStackFlushFunc) (CoglContext *context,
gboolean is_identity,
const CoglMatrix *matrix, const CoglMatrix *matrix,
void *user_data); void *user_data);
@ -106,7 +108,8 @@ void
_cogl_matrix_stack_set (CoglMatrixStack *stack, _cogl_matrix_stack_set (CoglMatrixStack *stack,
const CoglMatrix *matrix); const CoglMatrix *matrix);
void void
_cogl_matrix_stack_flush_to_gl (CoglMatrixStack *stack, _cogl_matrix_stack_flush_to_gl (CoglContext *ctx,
CoglMatrixStack *stack,
CoglMatrixMode mode); CoglMatrixMode mode);
void void
_cogl_matrix_stack_dirty (CoglMatrixStack *stack); _cogl_matrix_stack_dirty (CoglMatrixStack *stack);
@ -122,7 +125,8 @@ gboolean
_cogl_matrix_stack_has_identity_flag (CoglMatrixStack *stack); _cogl_matrix_stack_has_identity_flag (CoglMatrixStack *stack);
void void
_cogl_matrix_stack_prepare_for_flush (CoglMatrixStack *stack, _cogl_prepare_matrix_stack_for_flush (CoglContext *context,
CoglMatrixStack *stack,
CoglMatrixMode mode, CoglMatrixMode mode,
CoglMatrixStackFlushFunc callback, CoglMatrixStackFlushFunc callback,
void *user_data); void *user_data);

View File

@ -994,27 +994,25 @@ _cogl_pipeline_progend_glsl_layer_pre_change_notify (
#ifdef HAVE_COGL_GLES2 #ifdef HAVE_COGL_GLES2
static void static void
flush_modelview_cb (gboolean is_identity, flush_modelview_cb (CoglContext *ctx,
gboolean is_identity,
const CoglMatrix *matrix, const CoglMatrix *matrix,
void *user_data) void *user_data)
{ {
CoglPipelineProgramState *program_state = user_data; CoglPipelineProgramState *program_state = user_data;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
GE( ctx, glUniformMatrix4fv (program_state->modelview_uniform, 1, FALSE, GE( ctx, glUniformMatrix4fv (program_state->modelview_uniform, 1, FALSE,
cogl_matrix_get_array (matrix)) ); cogl_matrix_get_array (matrix)) );
} }
static void static void
flush_projection_cb (gboolean is_identity, flush_projection_cb (CoglContext *ctx,
const CoglMatrix *matrix, gboolean is_identity,
void *user_data) const CoglMatrix *matrix,
void *user_data)
{ {
CoglPipelineProgramState *program_state = user_data; CoglPipelineProgramState *program_state = user_data;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
GE( ctx, glUniformMatrix4fv (program_state->projection_uniform, 1, FALSE, GE( ctx, glUniformMatrix4fv (program_state->projection_uniform, 1, FALSE,
cogl_matrix_get_array (matrix)) ); cogl_matrix_get_array (matrix)) );
} }
@ -1026,15 +1024,14 @@ typedef struct
} FlushCombinedData; } FlushCombinedData;
static void static void
flush_combined_step_two_cb (gboolean is_identity, flush_combined_step_two_cb (CoglContext *ctx,
gboolean is_identity,
const CoglMatrix *matrix, const CoglMatrix *matrix,
void *user_data) void *user_data)
{ {
FlushCombinedData *data = user_data; FlushCombinedData *data = user_data;
CoglMatrix mvp_matrix; CoglMatrix mvp_matrix;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
/* If the modelview is the identity then we can bypass the matrix /* If the modelview is the identity then we can bypass the matrix
multiplication */ multiplication */
if (is_identity) if (is_identity)
@ -1055,18 +1052,18 @@ flush_combined_step_two_cb (gboolean is_identity,
} }
static void static void
flush_combined_step_one_cb (gboolean is_identity, flush_combined_step_one_cb (CoglContext *ctx,
gboolean is_identity,
const CoglMatrix *matrix, const CoglMatrix *matrix,
void *user_data) void *user_data)
{ {
FlushCombinedData data; FlushCombinedData data;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
data.program_state = user_data; data.program_state = user_data;
data.projection_matrix = matrix; data.projection_matrix = matrix;
_cogl_matrix_stack_prepare_for_flush (ctx->flushed_modelview_stack, _cogl_prepare_matrix_stack_for_flush (ctx,
ctx->flushed_modelview_stack,
COGL_MATRIX_MODELVIEW, COGL_MATRIX_MODELVIEW,
flush_combined_step_two_cb, flush_combined_step_two_cb,
&data); &data);
@ -1127,8 +1124,9 @@ _cogl_pipeline_progend_glsl_pre_paint (CoglPipeline *pipeline)
_cogl_matrix_stack_has_identity_flag (ctx->flushed_modelview_stack); _cogl_matrix_stack_has_identity_flag (ctx->flushed_modelview_stack);
if (program_state->modelview_uniform != -1) if (program_state->modelview_uniform != -1)
_cogl_matrix_stack_prepare_for_flush (program_state _cogl_prepare_matrix_stack_for_flush (ctx,
->flushed_modelview_stack, program_state
->flushed_modelview_stack,
COGL_MATRIX_MODELVIEW, COGL_MATRIX_MODELVIEW,
flush_modelview_cb, flush_modelview_cb,
program_state); program_state);
@ -1144,8 +1142,9 @@ _cogl_pipeline_progend_glsl_pre_paint (CoglPipeline *pipeline)
_cogl_matrix_stack_get_age (ctx->flushed_projection_stack); _cogl_matrix_stack_get_age (ctx->flushed_projection_stack);
if (program_state->projection_uniform != -1) if (program_state->projection_uniform != -1)
_cogl_matrix_stack_prepare_for_flush (program_state _cogl_prepare_matrix_stack_for_flush (ctx,
->flushed_projection_stack, program_state
->flushed_projection_stack,
COGL_MATRIX_PROJECTION, COGL_MATRIX_PROJECTION,
flush_projection_cb, flush_projection_cb,
program_state); program_state);
@ -1153,7 +1152,8 @@ _cogl_pipeline_progend_glsl_pre_paint (CoglPipeline *pipeline)
if (program_state->mvp_uniform != -1 && if (program_state->mvp_uniform != -1 &&
(modelview_changed || projection_changed)) (modelview_changed || projection_changed))
_cogl_matrix_stack_prepare_for_flush (ctx->flushed_projection_stack, _cogl_prepare_matrix_stack_for_flush (ctx,
ctx->flushed_projection_stack,
COGL_MATRIX_PROJECTION, COGL_MATRIX_PROJECTION,
flush_combined_step_one_cb, flush_combined_step_one_cb,
program_state); program_state);

View File

@ -81,6 +81,8 @@ _cogl_pipeline_vertend_fixed_add_layer (CoglPipeline *pipeline,
int unit_index = _cogl_pipeline_layer_get_unit_index (layer); int unit_index = _cogl_pipeline_layer_get_unit_index (layer);
CoglTextureUnit *unit = _cogl_get_texture_unit (unit_index); CoglTextureUnit *unit = _cogl_get_texture_unit (unit_index);
_COGL_GET_CONTEXT (ctx, FALSE);
if (layers_difference & COGL_PIPELINE_LAYER_STATE_USER_MATRIX) if (layers_difference & COGL_PIPELINE_LAYER_STATE_USER_MATRIX)
{ {
CoglPipelineLayerState state = COGL_PIPELINE_LAYER_STATE_USER_MATRIX; CoglPipelineLayerState state = COGL_PIPELINE_LAYER_STATE_USER_MATRIX;
@ -92,7 +94,8 @@ _cogl_pipeline_vertend_fixed_add_layer (CoglPipeline *pipeline,
_cogl_set_active_texture_unit (unit_index); _cogl_set_active_texture_unit (unit_index);
_cogl_matrix_stack_flush_to_gl (unit->matrix_stack, COGL_MATRIX_TEXTURE); _cogl_matrix_stack_flush_to_gl (ctx, unit->matrix_stack,
COGL_MATRIX_TEXTURE);
} }
return TRUE; return TRUE;

View File

@ -306,7 +306,8 @@ _cogl_pipeline_vertend_glsl_add_layer (CoglPipeline *pipeline,
_cogl_set_active_texture_unit (unit_index); _cogl_set_active_texture_unit (unit_index);
_cogl_matrix_stack_flush_to_gl (unit->matrix_stack, _cogl_matrix_stack_flush_to_gl (ctx,
unit->matrix_stack,
COGL_MATRIX_TEXTURE); COGL_MATRIX_TEXTURE);
} }
} }