From 652c8c31cfdd98ef38803b88325d76aee187ea5e Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Sun, 20 Nov 2011 18:50:29 +0000 Subject: [PATCH] avoid touching fb matrix stack directly This ensures we don't touch a framebuffer's matrix stack directly if we are also relying on _cogl_framebuffer_flush_state(). We want to get to the point where we can set dirty flags against framebuffer state at the point it changes but that means we can't allow direct access to the matrix stack. _cogl_texture_draw_and_read() has now been changed so it uses cogl_framebuffer_ methods to update the matrix stacks including adding new internal _cogl_framebuffer_push/pop_projection() functions that allow us to set transient projections. Reviewed-by: Neil Roberts --- cogl/cogl-framebuffer-private.h | 6 ++++++ cogl/cogl-framebuffer.c | 21 +++++++++++++++++++++ cogl/cogl-texture.c | 24 +++++++++--------------- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/cogl/cogl-framebuffer-private.h b/cogl/cogl-framebuffer-private.h index e168b6e0c..6499c80a8 100644 --- a/cogl/cogl-framebuffer-private.h +++ b/cogl/cogl-framebuffer-private.h @@ -334,4 +334,10 @@ _cogl_blit_framebuffer (unsigned int src_x, unsigned int width, unsigned int height); +void +_cogl_framebuffer_push_projection (CoglFramebuffer *framebuffer); + +void +_cogl_framebuffer_pop_projection (CoglFramebuffer *framebuffer); + #endif /* __COGL_FRAMEBUFFER_PRIVATE_H */ diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c index f5cc87786..c372963c4 100644 --- a/cogl/cogl-framebuffer.c +++ b/cogl/cogl-framebuffer.c @@ -1915,6 +1915,27 @@ cogl_framebuffer_orthographic (CoglFramebuffer *framebuffer, _cogl_matrix_stack_set (projection_stack, &ortho); } +void +_cogl_framebuffer_push_projection (CoglFramebuffer *framebuffer) +{ + CoglMatrixStack *projection_stack = + _cogl_framebuffer_get_projection_stack (framebuffer); + _cogl_matrix_stack_push (projection_stack); + + framebuffer->context->current_draw_buffer_changes |= + COGL_FRAMEBUFFER_STATE_PROJECTION; +} + +void +_cogl_framebuffer_pop_projection (CoglFramebuffer *framebuffer) +{ + CoglMatrixStack *projection_stack = + _cogl_framebuffer_get_projection_stack (framebuffer); + _cogl_matrix_stack_pop (projection_stack); + framebuffer->context->current_draw_buffer_changes |= + COGL_FRAMEBUFFER_STATE_PROJECTION; +} + void cogl_framebuffer_get_modelview_matrix (CoglFramebuffer *framebuffer, CoglMatrix *matrix) diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c index 23fcf8c49..a072d911d 100644 --- a/cogl/cogl-texture.c +++ b/cogl/cogl-texture.c @@ -874,8 +874,6 @@ _cogl_texture_draw_and_read (CoglTexture *texture, CoglFramebuffer *framebuffer; float viewport[4]; CoglBitmap *alpha_bmp; - CoglMatrixStack *projection_stack; - CoglMatrixStack *modelview_stack; int target_width = _cogl_bitmap_get_width (target_bmp); int target_height = _cogl_bitmap_get_height (target_bmp); int target_rowstride = _cogl_bitmap_get_rowstride (target_bmp); @@ -896,18 +894,14 @@ _cogl_texture_draw_and_read (CoglTexture *texture, * works) */ - projection_stack = _cogl_framebuffer_get_projection_stack (framebuffer); - _cogl_matrix_stack_push (projection_stack); - _cogl_matrix_stack_load_identity (projection_stack); - _cogl_matrix_stack_ortho (projection_stack, - 0, viewport[2], - viewport[3], 0, - 0, - 100); + _cogl_framebuffer_push_projection (framebuffer); + cogl_framebuffer_orthographic (framebuffer, + 0, 0, + viewport[2], viewport[3], + 0, 100); - modelview_stack = _cogl_framebuffer_get_modelview_stack (framebuffer); - _cogl_matrix_stack_push (modelview_stack); - _cogl_matrix_stack_load_identity (modelview_stack); + cogl_framebuffer_push_matrix (framebuffer); + cogl_framebuffer_identity_matrix (framebuffer); /* Direct copy operation */ @@ -999,8 +993,8 @@ _cogl_texture_draw_and_read (CoglTexture *texture, } /* Restore old state */ - _cogl_matrix_stack_pop (modelview_stack); - _cogl_matrix_stack_pop (projection_stack); + cogl_framebuffer_pop_matrix (framebuffer); + _cogl_framebuffer_pop_projection (framebuffer); /* restore the original pipeline */ cogl_pop_source ();