static void set_clip_planes (CoglFramebuffer *framebuffer, CoglMatrixEntry *modelview_entry, float x_1, float y_1, float x_2, float y_2) { CoglMatrix modelview_matrix; CoglMatrixStack *projection_stack = _cogl_framebuffer_get_projection_stack (framebuffer); CoglMatrix projection_matrix; CoglMatrix modelview_projection; float signed_area; float vertex_tl[4] = { x_1, y_1, 0, 1.0 }; float vertex_tr[4] = { x_2, y_1, 0, 1.0 }; float vertex_bl[4] = { x_1, y_2, 0, 1.0 }; float vertex_br[4] = { x_2, y_2, 0, 1.0 }; cogl_matrix_stack_get (projection_stack, &projection_matrix); cogl_matrix_entry_get (modelview_entry, &modelview_matrix); cogl_matrix_multiply (&modelview_projection, &projection_matrix, &modelview_matrix); project_vertex (&modelview_projection, vertex_tl); project_vertex (&modelview_projection, vertex_tr); project_vertex (&modelview_projection, vertex_bl); project_vertex (&modelview_projection, vertex_br); /* Calculate the signed area of the polygon formed by the four vertices so that we can know its orientation */ signed_area = (vertex_tl[0] * (vertex_tr[1] - vertex_bl[1]) + vertex_tr[0] * (vertex_br[1] - vertex_tl[1]) + vertex_br[0] * (vertex_bl[1] - vertex_tr[1]) + vertex_bl[0] * (vertex_tl[1] - vertex_br[1])); /* Set the clip planes to form lines between all of the vertices using the same orientation as we calculated */ if (signed_area > 0.0f) { /* counter-clockwise */ set_clip_plane (framebuffer, GL_CLIP_PLANE0, vertex_tl, vertex_bl); set_clip_plane (framebuffer, GL_CLIP_PLANE1, vertex_bl, vertex_br); set_clip_plane (framebuffer, GL_CLIP_PLANE2, vertex_br, vertex_tr); set_clip_plane (framebuffer, GL_CLIP_PLANE3, vertex_tr, vertex_tl); } else { /* clockwise */ set_clip_plane (framebuffer, GL_CLIP_PLANE0, vertex_tl, vertex_tr); set_clip_plane (framebuffer, GL_CLIP_PLANE1, vertex_tr, vertex_br); set_clip_plane (framebuffer, GL_CLIP_PLANE2, vertex_br, vertex_bl); set_clip_plane (framebuffer, GL_CLIP_PLANE3, vertex_bl, vertex_tl); } }
CoglBool cogl_matrix_stack_get_inverse (CoglMatrixStack *stack, CoglMatrix *inverse) { CoglMatrix matrix; CoglMatrix *internal = cogl_matrix_stack_get (stack, &matrix); if (internal) return cogl_matrix_get_inverse (internal, inverse); else return cogl_matrix_get_inverse (&matrix, inverse); }