From c68280556ee762c840bb8c73da16d505b6efe1ac Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Mon, 22 Nov 2010 15:51:15 +0000 Subject: [PATCH] clip-stack: combine modelview-projection in set_clip_planes When using clip planes and we we have to project some vertices into screen coordinates we used to transform those by the modelview and then the projection matrix separately. Now we combine the modelview and projection matrix and then use that to transform the vertices in one step instead. --- clutter/cogl/cogl/cogl-clip-stack.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/clutter/cogl/cogl/cogl-clip-stack.c b/clutter/cogl/cogl/cogl-clip-stack.c index 22cdce3f7..13498728e 100644 --- a/clutter/cogl/cogl/cogl-clip-stack.c +++ b/clutter/cogl/cogl/cogl-clip-stack.c @@ -145,20 +145,15 @@ struct _CoglClipStackPath }; static void -project_vertex (const CoglMatrix *modelview_matrix, - const CoglMatrix *projection_matrix, +project_vertex (const CoglMatrix *modelview_projection, float *vertex) { int i; - /* Apply the modelview matrix */ - cogl_matrix_transform_point (modelview_matrix, - &vertex[0], &vertex[1], - &vertex[2], &vertex[3]); - /* Apply the projection matrix */ - cogl_matrix_transform_point (projection_matrix, + cogl_matrix_transform_point (modelview_projection, &vertex[0], &vertex[1], &vertex[2], &vertex[3]); + /* Convert from homogenized coordinates */ for (i = 0; i < 4; i++) vertex[i] /= vertex[3]; @@ -234,6 +229,7 @@ set_clip_planes (float x_1, 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 }; @@ -244,10 +240,14 @@ set_clip_planes (float x_1, _cogl_matrix_stack_get (projection_stack, &projection_matrix); _cogl_matrix_stack_get (modelview_stack, &modelview_matrix); - project_vertex (&modelview_matrix, &projection_matrix, vertex_tl); - project_vertex (&modelview_matrix, &projection_matrix, vertex_tr); - project_vertex (&modelview_matrix, &projection_matrix, vertex_bl); - project_vertex (&modelview_matrix, &projection_matrix, vertex_br); + 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 */