Esempio n. 1
0
static void
_rut_camera_flush_transforms (RutCamera *camera)
{
  const CoglMatrix *projection;
  CoglFramebuffer *fb = camera->fb;
  CameraFlushState *state;

  /* While a camera is in a suspended state then we don't expect to
   * _flush() and use that camera before it is restored. */
  g_return_if_fail (camera->suspended == FALSE);

  state = cogl_object_get_user_data (COGL_OBJECT (fb), &fb_camera_key);
  if (!state)
    {
      state = g_slice_new (CameraFlushState);
      cogl_object_set_user_data (COGL_OBJECT (fb),
                                 &fb_camera_key,
                                 state,
                                 free_camera_flush_state);
    }
  else if (state->current_camera == camera &&
           camera->transform_age == state->transform_age)
    goto done;

  if (camera->in_frame)
    {
      g_warning ("Un-balanced rut_camera_flush/_end calls: "
                 "repeat _flush() calls before _end()");
    }

  cogl_framebuffer_set_viewport (fb,
                                 camera->viewport[0],
                                 camera->viewport[1],
                                 camera->viewport[2],
                                 camera->viewport[3]);

  projection = rut_camera_get_projection (camera);
  cogl_framebuffer_set_projection_matrix (fb, projection);

  cogl_framebuffer_set_modelview_matrix (fb, &camera->view);

  state->current_camera = camera;
  state->transform_age = camera->transform_age;

done:
  camera->in_frame = TRUE;
}
Esempio n. 2
0
void
rut_camera_resume (RutCamera *camera)
{
  CameraFlushState *state;
  CoglFramebuffer *fb = camera->fb;

  g_return_if_fail (camera->in_frame == FALSE);
  g_return_if_fail (camera->suspended == TRUE);

  /* While a camera is in a suspended state we don't expect the camera
   * to be touched so its transforms shouldn't have changed... */
  g_return_if_fail (camera->at_suspend_transform_age == camera->transform_age);

  state = cogl_object_get_user_data (COGL_OBJECT (fb), &fb_camera_key);

  /* We only expect to be restoring a camera that has been flushed
   * before */
  g_return_if_fail (state != NULL);

  cogl_framebuffer_pop_matrix (fb);

  /* If the save turned out to be redundant then we have nothing
   * else to restore... */
  if (state->current_camera == camera)
    goto done;

  cogl_framebuffer_set_viewport (fb,
                                 camera->viewport[0],
                                 camera->viewport[1],
                                 camera->viewport[2],
                                 camera->viewport[3]);

  cogl_framebuffer_set_projection_matrix (fb, &camera->projection);

  state->current_camera = camera;
  state->transform_age = camera->transform_age;

done:
  camera->in_frame = TRUE;
  camera->suspended = FALSE;
}
Esempio n. 3
0
void
cogl_set_projection_matrix (CoglMatrix *matrix)
{
  cogl_framebuffer_set_projection_matrix (cogl_get_draw_framebuffer (), matrix);
}