From 4976d229405c7010a6ef1e621bcfb581b7eff99a Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Fri, 10 Dec 2010 11:13:09 +0000 Subject: [PATCH] matrix-stack: Adds a stack age counter Sometimes it would be useful if we could efficiently track when a matrix stack has been modified. For example on GLES2 we have to upload the modelview as a uniform to our glsl programs but because the modelview state is part of the framebuffer state it becomes a bit more tricky to know when to re-sync the value of the uniform with the framebuffer state. This adds an "age" counter to CoglMatrixStack which is incremented for any operation that effectively modifies the top of the stack so now we can save the age of the stack inside the pipeline whenever we update modelview uniform and later compare that with the stack to determine if it has changed. --- clutter/cogl/cogl/cogl-matrix-stack.c | 18 ++++++++++++++++++ clutter/cogl/cogl/cogl-matrix-stack.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/clutter/cogl/cogl/cogl-matrix-stack.c b/clutter/cogl/cogl/cogl-matrix-stack.c index c65ec74ea..ff4898749 100644 --- a/clutter/cogl/cogl/cogl-matrix-stack.c +++ b/clutter/cogl/cogl/cogl-matrix-stack.c @@ -58,6 +58,8 @@ struct _CoglMatrixStack /* which state does GL have, NULL if unknown */ CoglMatrixState *flushed_state; gboolean flushed_identity; + + unsigned int age; }; /* XXX: this doesn't initialize the matrix! */ @@ -138,6 +140,8 @@ _cogl_matrix_stack_new (void) _cogl_matrix_state_init (state); state->is_identity = TRUE; + stack->age = 0; + return stack; } @@ -185,6 +189,7 @@ _cogl_matrix_stack_pop (CoglMatrixStack *stack) stack->flushed_state = NULL; } + stack->age++; g_array_set_size (stack->stack, stack->stack->len - 1); } } @@ -209,6 +214,7 @@ _cogl_matrix_stack_load_identity (CoglMatrixStack *stack) /* mark dirty */ stack->flushed_state = NULL; + stack->age++; } } @@ -225,6 +231,7 @@ _cogl_matrix_stack_scale (CoglMatrixStack *stack, /* mark dirty */ stack->flushed_state = NULL; state->is_identity = FALSE; + stack->age++; } void @@ -240,6 +247,7 @@ _cogl_matrix_stack_translate (CoglMatrixStack *stack, /* mark dirty */ stack->flushed_state = NULL; state->is_identity = FALSE; + stack->age++; } void @@ -256,6 +264,7 @@ _cogl_matrix_stack_rotate (CoglMatrixStack *stack, /* mark dirty */ stack->flushed_state = NULL; state->is_identity = FALSE; + stack->age++; } void @@ -269,6 +278,7 @@ _cogl_matrix_stack_multiply (CoglMatrixStack *stack, /* mark dirty */ stack->flushed_state = NULL; state->is_identity = FALSE; + stack->age++; } void @@ -289,6 +299,7 @@ _cogl_matrix_stack_frustum (CoglMatrixStack *stack, /* mark dirty */ stack->flushed_state = NULL; state->is_identity = FALSE; + stack->age++; } void @@ -306,6 +317,7 @@ _cogl_matrix_stack_perspective (CoglMatrixStack *stack, /* mark dirty */ stack->flushed_state = NULL; state->is_identity = FALSE; + stack->age++; } void @@ -325,6 +337,7 @@ _cogl_matrix_stack_ortho (CoglMatrixStack *stack, /* mark dirty */ stack->flushed_state = NULL; state->is_identity = FALSE; + stack->age++; } gboolean @@ -448,3 +461,8 @@ _cogl_matrix_stack_dirty (CoglMatrixStack *stack) stack->flushed_identity = FALSE; } +unsigned int +_cogl_matrix_stack_get_age (CoglMatrixStack *stack) +{ + return stack->age; +} diff --git a/clutter/cogl/cogl/cogl-matrix-stack.h b/clutter/cogl/cogl/cogl-matrix-stack.h index bfbac0f42..8aca102c0 100644 --- a/clutter/cogl/cogl/cogl-matrix-stack.h +++ b/clutter/cogl/cogl/cogl-matrix-stack.h @@ -87,4 +87,6 @@ void _cogl_matrix_stack_flush_to_gl (CoglMatrixStack *stack, CoglMatrixMode mode); void _cogl_matrix_stack_dirty (CoglMatrixStack *stack); +unsigned int _cogl_matrix_stack_get_age (CoglMatrixStack *stack); + #endif /* __COGL_MATRIX_STACK_H */