[matrix-stack] Adds ctx->flushed_matrix_mode to cache the gl matrix mode

This cache of the gl matrix mode lets us avoid repeat calls to glMatrixMode
in _cogl_matrix_stack_flush_to_gl when we have lots of sequential modelview
matrix modifications.
This commit is contained in:
Robert Bragg 2009-10-14 10:53:48 +01:00
parent 43f8032a7f
commit 01887460f6
3 changed files with 20 additions and 12 deletions

View File

@ -65,6 +65,7 @@ cogl_create_context (void)
_context->indirect = gl_is_indirect; _context->indirect = gl_is_indirect;
_context->flushed_matrix_mode = COGL_MATRIX_MODELVIEW;
_context->texture_units = NULL; _context->texture_units = NULL;
_context->default_material = cogl_material_new (); _context->default_material = cogl_material_new ();

View File

@ -59,6 +59,7 @@ typedef struct
gboolean indirect; gboolean indirect;
CoglMatrixMode matrix_mode; CoglMatrixMode matrix_mode;
CoglMatrixMode flushed_matrix_mode;
CoglMatrixStack *projection_stack; CoglMatrixStack *projection_stack;
CoglMatrixStack *modelview_stack; CoglMatrixStack *modelview_stack;

View File

@ -385,13 +385,17 @@ _cogl_matrix_stack_flush_to_gl (CoglMatrixStack *stack,
CoglMatrixMode mode) CoglMatrixMode mode)
{ {
CoglMatrixState *state; CoglMatrixState *state;
GLenum gl_mode;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
state = _cogl_matrix_stack_top (stack); state = _cogl_matrix_stack_top (stack);
if (stack->flushed_state == state) if (stack->flushed_state == state)
return; return;
if (ctx->flushed_matrix_mode != mode)
{
GLenum gl_mode;
switch (mode) switch (mode)
{ {
case COGL_MATRIX_MODELVIEW: case COGL_MATRIX_MODELVIEW:
@ -405,6 +409,8 @@ _cogl_matrix_stack_flush_to_gl (CoglMatrixStack *stack,
break; break;
} }
GE (glMatrixMode (gl_mode)); GE (glMatrixMode (gl_mode));
ctx->flushed_matrix_mode = mode;
}
/* In theory it might help the GL implementation if we used our /* In theory it might help the GL implementation if we used our
* local analysis of the matrix and called Translate/Scale rather * local analysis of the matrix and called Translate/Scale rather