Exemplo n.º 1
0
/* XXX:
 * Operations like scale, translate, rotate etc need to have an
 * initialized state->matrix to work with, so they will pass
 * initialize = TRUE.
 *
 * _cogl_matrix_stack_load_identity and _cogl_matrix_stack_set on the
 * other hand don't so they will pass initialize = FALSE
 *
 * NB: Identity matrices are represented by setting
 * state->is_identity=TRUE in which case state->matrix will be
 * uninitialized.
 */
static CoglMatrixState *
_cogl_matrix_stack_top_mutable (CoglMatrixStack *stack,
                                gboolean initialize)
{
  CoglMatrixState *state;
  CoglMatrixState *new_top;

  state = _cogl_matrix_stack_top (stack);

  if (state->push_count == 0)
    {
      if (state->is_identity && initialize)
        cogl_matrix_init_identity (&state->matrix);
      return state;
    }

  state->push_count -= 1;

  g_array_set_size (stack->stack, stack->stack->len + 1);
  new_top = &g_array_index (stack->stack, CoglMatrixState,
                            stack->stack->len - 1);
  _cogl_matrix_state_init (new_top);

  if (initialize)
    {
      if (state->is_identity)
        cogl_matrix_init_identity (&new_top->matrix);
      else
        new_top->matrix = state->matrix;
    }

  return new_top;
}
Exemplo n.º 2
0
CoglMatrixStack*
_cogl_matrix_stack_new (void)
{
  CoglMatrixStack *stack;
  CoglMatrixState *state;

  stack = g_slice_new0 (CoglMatrixStack);

  stack->stack = g_array_sized_new (FALSE, FALSE,
                                    sizeof (CoglMatrixState), 10);
  g_array_set_size (stack->stack, 1);
  state = &g_array_index (stack->stack, CoglMatrixState, 0);
  _cogl_matrix_state_init (state);
  state->is_identity = TRUE;

  stack->age = 0;

  return _cogl_matrix_stack_object_new (stack);
}