From 5e5d94dfbed18bf2b4c8c7a7ff9847952b2c4ae2 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Tue, 13 Oct 2009 23:09:42 +0100 Subject: [PATCH] [cogl] Removes the cogl-current-matrix abstraction The indirection through this API isn't necessary since we no longer arbitrate between the OpenGL matrix API and Cogl's client side API. Also it doesn't help to maintain an OpenGL style matrix mode API for internal use since it's awkward to keep restoring the MODELVIEW mode and easy enough to directly work with the matrix stacks of interest. This replaces use of the _cogl_current_matrix API with direct use of the _cogl_matrix_stack API. All the unused cogl_current_matrix API is removed and the matrix utility code left in cogl-current-matrix.c was moved to cogl.c. --- clutter/cogl/cogl/Makefile.am | 2 - clutter/cogl/cogl/cogl-clip-stack.c | 15 +- clutter/cogl/cogl/cogl-context.c | 8 +- clutter/cogl/cogl/cogl-context.h | 4 +- clutter/cogl/cogl/cogl-current-matrix.h | 95 -------- clutter/cogl/cogl/cogl-internal.h | 14 +- clutter/cogl/cogl/cogl-material.c | 2 + clutter/cogl/cogl/cogl-texture.c | 28 +-- clutter/cogl/cogl/cogl-util.c | 1 - clutter/cogl/cogl/cogl.c | 228 +++++++++++++++--- clutter/cogl/cogl/driver/gl/cogl-fbo.c | 26 +- clutter/cogl/cogl/driver/gl/cogl-primitives.c | 22 +- clutter/cogl/cogl/driver/gles/cogl-fbo.c | 27 +-- .../cogl/cogl/driver/gles/cogl-primitives.c | 24 +- doc/reference/cogl/Makefile.am | 1 - 15 files changed, 270 insertions(+), 227 deletions(-) delete mode 100644 clutter/cogl/cogl/cogl-current-matrix.h diff --git a/clutter/cogl/cogl/Makefile.am b/clutter/cogl/cogl/Makefile.am index 84fdb097c..ba87deb0c 100644 --- a/clutter/cogl/cogl/Makefile.am +++ b/clutter/cogl/cogl/Makefile.am @@ -94,8 +94,6 @@ libclutter_cogl_la_SOURCES = \ cogl-bitmap-private.h \ cogl-bitmap.c \ cogl-bitmap-fallback.c \ - cogl-current-matrix.c \ - cogl-current-matrix.h \ cogl-primitives.h \ cogl-primitives.c \ cogl-bitmap-pixbuf.c \ diff --git a/clutter/cogl/cogl/cogl-clip-stack.c b/clutter/cogl/cogl/cogl-clip-stack.c index 9efa5c22d..a0dc3bc49 100644 --- a/clutter/cogl/cogl/cogl-clip-stack.c +++ b/clutter/cogl/cogl/cogl-clip-stack.c @@ -321,9 +321,12 @@ _cogl_clip_stack_rebuild (void) gint scissor_y0 = 0; gint scissor_x1 = G_MAXINT; gint scissor_y1 = G_MAXINT; + CoglMatrixStack *modelview_stack; _COGL_GET_CONTEXT (ctx, NO_RETVAL); + modelview_stack = ctx->modelview_stack; + /* The current primitive journal does not support tracking changes to the * clip stack... */ _cogl_journal_flush (); @@ -354,8 +357,8 @@ _cogl_clip_stack_rebuild (void) { CoglClipStackEntryPath *path = (CoglClipStackEntryPath *) entry; - cogl_push_matrix (); - _cogl_set_matrix (&path->matrix); + _cogl_matrix_stack_push (modelview_stack); + _cogl_matrix_stack_set (modelview_stack, &path->matrix); _cogl_add_path_to_stencil_buffer (path->path_nodes_min, path->path_nodes_max, @@ -363,7 +366,7 @@ _cogl_clip_stack_rebuild (void) path->path, using_stencil_buffer); - cogl_pop_matrix (); + _cogl_matrix_stack_pop (modelview_stack); using_stencil_buffer = TRUE; @@ -374,8 +377,8 @@ _cogl_clip_stack_rebuild (void) { CoglClipStackEntryRect *rect = (CoglClipStackEntryRect *) entry; - cogl_push_matrix (); - _cogl_set_matrix (&rect->matrix); + _cogl_matrix_stack_push (modelview_stack); + _cogl_matrix_stack_set (modelview_stack, &rect->matrix); /* If this is the first entry and we support clip planes then use that instead */ @@ -399,7 +402,7 @@ _cogl_clip_stack_rebuild (void) using_stencil_buffer = TRUE; } - cogl_pop_matrix (); + _cogl_matrix_stack_pop (modelview_stack); } else { diff --git a/clutter/cogl/cogl/cogl-context.c b/clutter/cogl/cogl/cogl-context.c index 248fbc077..6cbc7b7c2 100644 --- a/clutter/cogl/cogl/cogl-context.c +++ b/clutter/cogl/cogl/cogl-context.c @@ -66,6 +66,8 @@ cogl_create_context (void) _context->indirect = gl_is_indirect; _context->flushed_matrix_mode = COGL_MATRIX_MODELVIEW; + _context->modelview_stack = _cogl_matrix_stack_new (); + _context->projection_stack = _cogl_matrix_stack_new (); _context->texture_units = NULL; _context->default_material = cogl_material_new (); @@ -109,9 +111,6 @@ cogl_create_context (void) /* Initialise the clip stack */ _cogl_clip_stack_state_init (); - /* Initialise matrix stack */ - _cogl_current_matrix_state_init (); - /* Initialise the driver specific state */ _cogl_create_context_driver (_context); @@ -152,7 +151,8 @@ _cogl_destroy_context () _cogl_clip_stack_state_destroy (); - _cogl_current_matrix_state_destroy (); + _cogl_matrix_stack_destroy (_context->modelview_stack); + _cogl_matrix_stack_destroy (_context->projection_stack); _cogl_destroy_texture_units (); diff --git a/clutter/cogl/cogl/cogl-context.h b/clutter/cogl/cogl/cogl-context.h index 1ee36d1f2..cf8e3ad84 100644 --- a/clutter/cogl/cogl/cogl-context.h +++ b/clutter/cogl/cogl/cogl-context.h @@ -24,11 +24,11 @@ #ifndef __COGL_CONTEXT_H #define __COGL_CONTEXT_H +#include "cogl-internal.h" #include "cogl-context-driver.h" #include "cogl-primitives.h" #include "cogl-clip-stack.h" #include "cogl-matrix-stack.h" -#include "cogl-current-matrix.h" #include "cogl-material-private.h" typedef struct @@ -58,7 +58,7 @@ typedef struct gboolean indirect; - CoglMatrixMode matrix_mode; + /* Client-side matrix stack or NULL if none */ CoglMatrixMode flushed_matrix_mode; CoglMatrixStack *projection_stack; CoglMatrixStack *modelview_stack; diff --git a/clutter/cogl/cogl/cogl-current-matrix.h b/clutter/cogl/cogl/cogl-current-matrix.h deleted file mode 100644 index eb2464888..000000000 --- a/clutter/cogl/cogl/cogl-current-matrix.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Cogl - * - * An object oriented GL/GLES Abstraction/Utility Layer - * - * Copyright (C) 2009 Intel Corporation. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Authors: - * Havoc Pennington for litl - */ - -#ifndef __COGL_CURRENT_MATRIX_H -#define __COGL_CURRENT_MATRIX_H - -#include - -/** - * CoglMatrixMode: - * @COGL_MATRIX_MODELVIEW: Select model-view matrix stack - * @COGL_MATRIX_PROJECTION: Select projection matrix stack - * @COGL_MATRIX_TEXTURE: Select texture matrix stack - * - * There are several matrix stacks affected by the COGL current matrix - * operations (which are private). Code should always leave the - * model-view matrix active, switching to the projection matrix stack - * only temporarily in order to modify the projection matrix. Most - * COGL and Clutter APIs (other than the current matrix operations) - * will assume the model-view matrix is active when the API is - * invoked. - * - * Since: 1.0 - */ -typedef enum -{ - COGL_MATRIX_MODELVIEW = 1, - COGL_MATRIX_PROJECTION = 2, - COGL_MATRIX_TEXTURE = 3 -} CoglMatrixMode; - -#define COGL_TYPE_MATRIX_MODE (cogl_matrix_mode_get_type ()) -GType cogl_matrix_mode_get_type (void) G_GNUC_CONST; - -void _cogl_set_current_matrix (CoglMatrixMode mode); -void _cogl_current_matrix_push (void); -void _cogl_current_matrix_pop (void); -void _cogl_current_matrix_identity (void); -void _cogl_current_matrix_load (const CoglMatrix *matrix); -void _cogl_current_matrix_multiply (const CoglMatrix *matrix); -void _cogl_current_matrix_rotate (float angle, - float x, - float y, - float z); -void _cogl_current_matrix_scale (float x, - float y, - float z); -void _cogl_current_matrix_translate (float x, - float y, - float z); -void _cogl_current_matrix_frustum (float left, - float right, - float bottom, - float top, - float near_val, - float far_val); -void _cogl_current_matrix_ortho (float left, - float right, - float bottom, - float top, - float near_val, - float far_val); -void _cogl_get_matrix (CoglMatrixMode mode, - CoglMatrix *matrix); -void _cogl_current_matrix_state_init (void); -void _cogl_current_matrix_state_destroy (void); -void _cogl_current_matrix_state_flush (void); -void _cogl_current_matrix_state_dirty (void); - -void _cogl_flush_matrix_stacks (void); - -#endif /* __COGL_CURRENT_MATRIX_H */ diff --git a/clutter/cogl/cogl/cogl-internal.h b/clutter/cogl/cogl/cogl-internal.h index 65c213b65..1f84e0d05 100644 --- a/clutter/cogl/cogl/cogl-internal.h +++ b/clutter/cogl/cogl/cogl-internal.h @@ -24,9 +24,15 @@ #ifndef __COGL_INTERNAL_H #define __COGL_INTERNAL_H -#include "cogl-debug.h" -#include "cogl-types.h" -#include "cogl-context.h" +#include "cogl.h" +#include "cogl-matrix-stack.h" + +typedef enum +{ + COGL_MATRIX_MODELVIEW, + COGL_MATRIX_PROJECTION, + COGL_MATRIX_TEXTURE +} CoglMatrixMode; #ifdef HAVE_COGL_GLES2 typedef enum { @@ -97,4 +103,6 @@ _cogl_get_texture_unit (int index_); void _cogl_destroy_texture_units (void); +void _cogl_flush_matrix_stacks (void); + #endif /* __COGL_INTERNAL_H */ diff --git a/clutter/cogl/cogl/cogl-material.c b/clutter/cogl/cogl/cogl-material.c index 8ef18027c..a050e1a11 100644 --- a/clutter/cogl/cogl/cogl-material.c +++ b/clutter/cogl/cogl/cogl-material.c @@ -1179,6 +1179,8 @@ _cogl_material_layer_flush_gl_sampler_state (CoglMaterialLayer *layer, int n_rgb_func_args; int n_alpha_func_args; + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + #ifndef DISABLE_MATERIAL_CACHE if (!(gl_layer_info && gl_layer_info->flags & COGL_MATERIAL_LAYER_FLAG_DEFAULT_COMBINE && diff --git a/clutter/cogl/cogl/cogl-texture.c b/clutter/cogl/cogl/cogl-texture.c index d1c561a0f..fa33f047d 100644 --- a/clutter/cogl/cogl/cogl-texture.c +++ b/clutter/cogl/cogl/cogl-texture.c @@ -670,6 +670,8 @@ _cogl_texture_draw_and_read (CoglTexture *tex, GLint viewport[4]; CoglBitmap alpha_bmp; CoglHandle prev_source; + CoglMatrixStack *projection_stack; + CoglMatrixStack *modelview_stack; _COGL_GET_CONTEXT (ctx, FALSE); @@ -686,18 +688,16 @@ _cogl_texture_draw_and_read (CoglTexture *tex, * works) */ - _cogl_set_current_matrix (COGL_MATRIX_PROJECTION); - _cogl_current_matrix_push (); - _cogl_current_matrix_identity (); + _cogl_matrix_stack_push (ctx->projection_stack); + _cogl_matrix_stack_load_identity (ctx->projection_stack); + _cogl_matrix_stack_ortho (ctx->projection_stack, + 0, (float)(viewport[2]), + 0, (float)(viewport[3]), + (float)(0), + (float)(100)); - _cogl_current_matrix_ortho (0, (float)(viewport[2]), - 0, (float)(viewport[3]), - (float)(0), - (float)(100)); - - _cogl_set_current_matrix (COGL_MATRIX_MODELVIEW); - _cogl_current_matrix_push (); - _cogl_current_matrix_identity (); + _cogl_matrix_stack_push (ctx->modelview_stack); + _cogl_matrix_stack_load_identity (ctx->modelview_stack); /* Direct copy operation */ @@ -778,10 +778,8 @@ _cogl_texture_draw_and_read (CoglTexture *tex, } /* Restore old state */ - _cogl_set_current_matrix (COGL_MATRIX_PROJECTION); - _cogl_current_matrix_pop (); - _cogl_set_current_matrix (COGL_MATRIX_MODELVIEW); - _cogl_current_matrix_pop (); + _cogl_matrix_stack_pop (modelview_stack); + _cogl_matrix_stack_pop (projection_stack); /* restore the original material */ cogl_set_source (prev_source); diff --git a/clutter/cogl/cogl/cogl-util.c b/clutter/cogl/cogl/cogl-util.c index 2d86f73f3..6debb5599 100644 --- a/clutter/cogl/cogl/cogl-util.c +++ b/clutter/cogl/cogl/cogl-util.c @@ -33,7 +33,6 @@ #include "cogl-fixed.h" #include "cogl-internal.h" #include "cogl-material.h" -#include "cogl-current-matrix.h" #include "cogl-offscreen.h" #include "cogl-shader.h" #include "cogl-texture.h" diff --git a/clutter/cogl/cogl/cogl.c b/clutter/cogl/cogl/cogl.c index c096d4450..5399310ad 100644 --- a/clutter/cogl/cogl/cogl.c +++ b/clutter/cogl/cogl/cogl.c @@ -334,20 +334,22 @@ set_clip_plane (GLint plane_num, angle = atan2f (vertex_b[1] - vertex_a[1], vertex_b[0] - vertex_a[0]) * (180.0/G_PI); - _cogl_current_matrix_push (); + _cogl_matrix_stack_push (ctx->modelview_stack); /* Load the identity matrix and multiply by the reverse of the projection matrix so we can specify the plane in screen coordinates */ - _cogl_current_matrix_identity (); + _cogl_matrix_stack_load_identity (ctx->modelview_stack); cogl_matrix_init_from_array (&inverse_projection, ctx->inverse_projection); - _cogl_current_matrix_multiply (&inverse_projection); + _cogl_matrix_stack_multiply (ctx->modelview_stack, &inverse_projection); /* Rotate about point a */ - _cogl_current_matrix_translate (vertex_a[0], vertex_a[1], vertex_a[2]); + _cogl_matrix_stack_translate (ctx->modelview_stack, + vertex_a[0], vertex_a[1], vertex_a[2]); /* Rotate the plane by the calculated angle so that it will connect the two points */ - _cogl_current_matrix_rotate (angle, 0.0f, 0.0f, 1.0f); - _cogl_current_matrix_translate (-vertex_a[0], -vertex_a[1], -vertex_a[2]); + _cogl_matrix_stack_rotate (ctx->modelview_stack, angle, 0.0f, 0.0f, 1.0f); + _cogl_matrix_stack_translate (ctx->modelview_stack, + -vertex_a[0], -vertex_a[1], -vertex_a[2]); _cogl_flush_matrix_stacks (); @@ -361,7 +363,7 @@ set_clip_plane (GLint plane_num, GE( glClipPlane (plane_num, plane) ); #endif - _cogl_current_matrix_pop (); + _cogl_matrix_stack_pop (ctx->modelview_stack); } void @@ -373,16 +375,16 @@ _cogl_set_clip_planes (float x_offset, CoglMatrix modelview_matrix; CoglMatrix projection_matrix; + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + float vertex_tl[4] = { x_offset, y_offset, 0, 1.0 }; float vertex_tr[4] = { x_offset + width, y_offset, 0, 1.0 }; float vertex_bl[4] = { x_offset, y_offset + height, 0, 1.0 }; float vertex_br[4] = { x_offset + width, y_offset + height, 0, 1.0 }; - _cogl_get_matrix (COGL_MATRIX_PROJECTION, - &projection_matrix); - _cogl_get_matrix (COGL_MATRIX_MODELVIEW, - &modelview_matrix); + _cogl_matrix_stack_get (ctx->projection_stack, &projection_matrix); + _cogl_matrix_stack_get (ctx->modelview_stack, &modelview_matrix); project_vertex (&modelview_matrix, &projection_matrix, vertex_tl); project_vertex (&modelview_matrix, &projection_matrix, vertex_tr); @@ -423,6 +425,8 @@ _cogl_add_stencil_clip (float x_offset, _COGL_GET_CONTEXT (ctx, NO_RETVAL); + /* We don't log changes to the stencil buffer so need to flush any + * batched geometry before we start... */ _cogl_journal_flush (); /* temporarily swap in our special stenciling material */ @@ -453,31 +457,25 @@ _cogl_add_stencil_clip (float x_offset, cogl_rectangle (x_offset, y_offset, x_offset + width, y_offset + height); + /* make sure our rectangle hits the stencil buffer before we + * change the stencil operation */ + _cogl_journal_flush (); + /* Subtract one from all pixels in the stencil buffer so that only pixels where both the original stencil buffer and the rectangle are set will be valid */ GE( glStencilOp (GL_DECR, GL_DECR, GL_DECR) ); - _cogl_set_current_matrix (COGL_MATRIX_PROJECTION); - _cogl_current_matrix_push (); - _cogl_current_matrix_identity (); + _cogl_matrix_stack_push (ctx->projection_stack); + _cogl_matrix_stack_load_identity (ctx->projection_stack); - /* Cogl generally assumes the modelview matrix is current, so since - * cogl_rectangle will be flushing GL state and emitting geometry - * to OpenGL it will be confused if we leave the projection matrix - * active... */ - _cogl_set_current_matrix (COGL_MATRIX_MODELVIEW); - _cogl_current_matrix_push (); - _cogl_current_matrix_identity (); + _cogl_matrix_stack_push (ctx->modelview_stack); + _cogl_matrix_stack_load_identity (ctx->modelview_stack); cogl_rectangle (-1.0, -1.0, 1.0, 1.0); - _cogl_current_matrix_pop (); - - _cogl_set_current_matrix (COGL_MATRIX_PROJECTION); - _cogl_current_matrix_pop (); - - _cogl_set_current_matrix (COGL_MATRIX_MODELVIEW); + _cogl_matrix_stack_pop (ctx->modelview_stack); + _cogl_matrix_stack_pop (ctx->projection_stack); } /* make sure our rectangles hit the stencil buffer before we restore @@ -543,10 +541,12 @@ _cogl_setup_viewport (guint width, float z_camera; CoglMatrix projection_matrix; + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + cogl_viewport (width, height); /* For Ortho projection. - * _cogl_current_matrix_ortho (0, width, 0, height, -1, 1); + * _cogl_matrix_stack_ortho (projection_stack, 0, width, 0, height, -1, 1); */ cogl_perspective (fovy, aspect, z_near, z_far); @@ -593,11 +593,12 @@ _cogl_setup_viewport (guint width, cogl_get_projection_matrix (&projection_matrix); z_camera = 0.5 * projection_matrix.xx; - _cogl_set_current_matrix (COGL_MATRIX_MODELVIEW); - _cogl_current_matrix_identity (); - _cogl_current_matrix_translate (-0.5f, -0.5f, -z_camera); - _cogl_current_matrix_scale (1.0f / width, -1.0f / height, 1.0f / width); - _cogl_current_matrix_translate (0.0f, -1.0 * height, 0.0f); + _cogl_matrix_stack_load_identity (ctx->modelview_stack); + _cogl_matrix_stack_translate (ctx->modelview_stack, -0.5f, -0.5f, -z_camera); + _cogl_matrix_stack_scale (ctx->modelview_stack, + 1.0f / width, -1.0f / height, 1.0f / width); + _cogl_matrix_stack_translate (ctx->modelview_stack, + 0.0f, -1.0 * height, 0.0f); } CoglFeatureFlags @@ -936,3 +937,164 @@ _cogl_destroy_texture_units (void) g_list_free (ctx->texture_units); } +void +cogl_push_matrix (void) +{ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + _cogl_matrix_stack_push (ctx->modelview_stack); +} + +void +cogl_pop_matrix (void) +{ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + _cogl_matrix_stack_pop (ctx->modelview_stack); +} + +void +cogl_scale (float x, float y, float z) +{ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + _cogl_matrix_stack_scale (ctx->modelview_stack, x, y, z); +} + +void +cogl_translate (float x, float y, float z) +{ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + _cogl_matrix_stack_translate (ctx->modelview_stack, x, y, z); +} + +void +cogl_rotate (float angle, float x, float y, float z) +{ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + _cogl_matrix_stack_rotate (ctx->modelview_stack, angle, x, y, z); +} + +void +cogl_perspective (float fov_y, + float aspect, + float z_near, + float z_far) +{ + float ymax = z_near * tanf (fov_y * G_PI / 360.0); + + cogl_frustum (-ymax * aspect, /* left */ + ymax * aspect, /* right */ + -ymax, /* bottom */ + ymax, /* top */ + z_near, + z_far); +} + +void +cogl_frustum (float left, + float right, + float bottom, + float top, + float z_near, + float z_far) +{ + float c, d; + + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + + _cogl_matrix_stack_load_identity (ctx->projection_stack); + + _cogl_matrix_stack_frustum (ctx->projection_stack, + left, + right, + bottom, + top, + z_near, + z_far); + + /* Calculate and store the inverse of the matrix */ + memset (ctx->inverse_projection, 0, sizeof (float) * 16); + + c = - (z_far + z_near) / (z_far - z_near); + d = - (2 * (z_far * z_near)) / (z_far - z_near); + +#define M(row,col) ctx->inverse_projection[col*4+row] + M(0,0) = (right - left) / (2 * z_near); + M(0,3) = (right + left) / (2 * z_near); + M(1,1) = (top - bottom) / (2 * z_near); + M(1,3) = (top + bottom) / (2 * z_near); + M(2,3) = -1.0; + M(3,2) = 1.0 / d; + M(3,3) = c / d; +#undef M +} + +void +cogl_ortho (float left, + float right, + float bottom, + float top, + float z_near, + float z_far) +{ + CoglMatrix ortho; + + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + + cogl_matrix_init_identity (&ortho); + cogl_matrix_ortho (&ortho, left, right, bottom, top, z_near, z_far); + _cogl_matrix_stack_set (ctx->projection_stack, &ortho); + + /* Calculate and store the inverse of the matrix */ + memset (ctx->inverse_projection, 0, sizeof (float) * 16); + +#define M(row,col) ctx->inverse_projection[col*4+row] + M(0,0) = 1.0 / ortho.xx; + M(0,3) = -ortho.xw; + M(1,1) = 1.0 / ortho.yy; + M(1,3) = -ortho.yw; + M(2,2) = 1.0 / ortho.zz; + M(2,3) = -ortho.zw; + M(3,3) = 1.0; +#undef M +} + +void +cogl_get_modelview_matrix (CoglMatrix *matrix) +{ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + _cogl_matrix_stack_get (ctx->modelview_stack, matrix); +} + +void +cogl_set_modelview_matrix (CoglMatrix *matrix) +{ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + _cogl_matrix_stack_set (ctx->modelview_stack, matrix); +} + +void +cogl_get_projection_matrix (CoglMatrix *matrix) +{ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + _cogl_matrix_stack_get (ctx->projection_stack, matrix); +} + +void +cogl_set_projection_matrix (CoglMatrix *matrix) +{ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + _cogl_matrix_stack_set (ctx->projection_stack, matrix); + + /* FIXME: Update the inverse projection matrix!! Presumably use + * of clip planes must currently be broken if this API is used. */ +} + +void +_cogl_flush_matrix_stacks (void) +{ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + _cogl_matrix_stack_flush_to_gl (ctx->projection_stack, + COGL_MATRIX_PROJECTION); + _cogl_matrix_stack_flush_to_gl (ctx->modelview_stack, + COGL_MATRIX_MODELVIEW); +} + diff --git a/clutter/cogl/cogl/driver/gl/cogl-fbo.c b/clutter/cogl/cogl/driver/gl/cogl-fbo.c index 375a67363..1bd88aeea 100644 --- a/clutter/cogl/cogl/driver/gl/cogl-fbo.c +++ b/clutter/cogl/cogl/driver/gl/cogl-fbo.c @@ -202,29 +202,25 @@ cogl_set_draw_buffer (CoglBufferTarget target, CoglHandle offscreen) from a non-screen buffer */ GE( glPushAttrib (GL_VIEWPORT_BIT) ); - _cogl_set_current_matrix (COGL_MATRIX_PROJECTION); - _cogl_current_matrix_push (); - _cogl_current_matrix_identity (); + _cogl_matrix_stack_push (ctx->projection_stack); + _cogl_matrix_stack_load_identity (ctx->projection_stack); - _cogl_set_current_matrix (COGL_MATRIX_MODELVIEW); - _cogl_current_matrix_push (); - _cogl_current_matrix_identity (); + _cogl_matrix_stack_push (ctx->modelview_stack); + _cogl_matrix_stack_load_identity (ctx->modelview_stack); } else { /* Override viewport and matrix setup if redirecting from another offscreen buffer */ - _cogl_set_current_matrix (COGL_MATRIX_PROJECTION); - _cogl_current_matrix_identity (); + _cogl_matrix_stack_load_identity (ctx->projection_stack); - _cogl_set_current_matrix (COGL_MATRIX_MODELVIEW); - _cogl_current_matrix_identity (); + _cogl_matrix_stack_load_identity (ctx->modelview_stack); } /* Setup new viewport and matrices */ cogl_viewport (fbo->width, fbo->height); - _cogl_current_matrix_translate (-1.0f, -1.0f, 0.0f); - _cogl_current_matrix_scale (2.0f / fbo->width, 2.0f / fbo->height, 1.0f); + _cogl_matrix_stack_translate (ctx->modelview_stack, -1.0f, -1.0f, 0.0f); + _cogl_matrix_stack_scale (ctx->modelview_stack, 2.0f / fbo->width, 2.0f / fbo->height, 1.0f); /* Bind offscreen framebuffer object */ GE( glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, fbo->gl_handle) ); @@ -249,11 +245,9 @@ cogl_set_draw_buffer (CoglBufferTarget target, CoglHandle offscreen) from an offscreen buffer */ GE( glPopAttrib () ); - _cogl_set_current_matrix (COGL_MATRIX_PROJECTION); - _cogl_current_matrix_pop (); + _cogl_matrix_stack_pop (ctx->projection_stack); - _cogl_set_current_matrix (COGL_MATRIX_MODELVIEW); - _cogl_current_matrix_pop (); + _cogl_matrix_stack_pop (ctx->modelview_stack); } /* Bind window framebuffer object */ diff --git a/clutter/cogl/cogl/driver/gl/cogl-primitives.c b/clutter/cogl/cogl/driver/gl/cogl-primitives.c index 934fe1372..3c1c9e656 100644 --- a/clutter/cogl/cogl/driver/gl/cogl-primitives.c +++ b/clutter/cogl/cogl/driver/gl/cogl-primitives.c @@ -216,29 +216,19 @@ _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min, /* Decrement all of the bits twice so that only pixels where the value is 3 will remain */ - _cogl_set_current_matrix (COGL_MATRIX_PROJECTION); - _cogl_current_matrix_push (); - _cogl_current_matrix_identity (); + _cogl_matrix_stack_push (ctx->projection_stack); + _cogl_matrix_stack_load_identity (ctx->projection_stack); - /* Cogl generally assumes the modelview matrix is current, so since - * cogl_rectangle will be flushing GL state and emitting geometry - * to OpenGL it will be confused if we leave the projection matrix - * active... */ - _cogl_set_current_matrix (COGL_MATRIX_MODELVIEW); - _cogl_current_matrix_push (); - _cogl_current_matrix_identity (); + _cogl_matrix_stack_push (ctx->modelview_stack); + _cogl_matrix_stack_load_identity (ctx->modelview_stack); _cogl_flush_matrix_stacks (); glRectf (-1.0, -1.0, 1.0, 1.0); glRectf (-1.0, -1.0, 1.0, 1.0); - _cogl_current_matrix_pop (); - - _cogl_set_current_matrix (COGL_MATRIX_PROJECTION); - _cogl_current_matrix_pop (); - - _cogl_set_current_matrix (COGL_MATRIX_MODELVIEW); + _cogl_matrix_stack_pop (ctx->modelview_stack); + _cogl_matrix_stack_pop (ctx->projection_stack); } GE( glStencilMask (~(GLuint) 0) ); diff --git a/clutter/cogl/cogl/driver/gles/cogl-fbo.c b/clutter/cogl/cogl/driver/gles/cogl-fbo.c index 53604a10e..0b1006970 100644 --- a/clutter/cogl/cogl/driver/gles/cogl-fbo.c +++ b/clutter/cogl/cogl/driver/gles/cogl-fbo.c @@ -173,29 +173,26 @@ cogl_set_draw_buffer (CoglBufferTarget target, CoglHandle offscreen) from a non-screen buffer */ GE( glGetIntegerv (GL_VIEWPORT, ctx->drv.viewport_store) ); - _cogl_set_current_matrix (COGL_MATRIX_PROJECTION); - _cogl_current_matrix_push (); - _cogl_current_matrix_identity (); + _cogl_matrix_stack_push (ctx->projection_stack); + _cogl_matrix_stack_load_identity (ctx->projection_stack); - _cogl_set_current_matrix (COGL_MATRIX_MODELVIEW); - _cogl_current_matrix_push (); - _cogl_current_matrix_identity (); + _cogl_matrix_stack_push (ctx->modelview_stack); + _cogl_matrix_stack_load_identity (ctx->modelview_stack); } else { /* Override viewport and matrix setup if redirecting from another offscreen buffer */ - _cogl_set_current_matrix (COGL_MATRIX_PROJECTION); - _cogl_current_matrix_identity (); + _cogl_matrix_stack_load_identity (ctx->projection_stack); - _cogl_set_current_matrix (COGL_MATRIX_MODELVIEW); - _cogl_current_matrix_identity (); + _cogl_matrix_stack_load_identity (ctx->modelview_stack); } /* Setup new viewport and matrices */ GE( glViewport (0, 0, fbo->width, fbo->height) ); - _cogl_current_matrix_translate (-1.0f, -1.0f, 0.0f); - _cogl_current_matrix_scale (2.0f / fbo->width, 2.0f / fbo->height, 1.0f); + _cogl_matrix_stack_translate (ctx->modelview_stack, -1.0f, -1.0f, 0.0f); + _cogl_matrix_stack_scale (ctx->modelview_stack, + 2.0f / fbo->width, 2.0f / fbo->height, 1.0f); /* Bind offscreen framebuffer object */ GE( glBindFramebuffer (GL_FRAMEBUFFER, fbo->gl_handle) ); @@ -229,11 +226,9 @@ cogl_set_draw_buffer (CoglBufferTarget target, CoglHandle offscreen) ctx->drv.viewport_store[2], ctx->drv.viewport_store[3]) ); - _cogl_set_current_matrix (COGL_MATRIX_PROJECTION); - _cogl_current_matrix_pop (); + _cogl_matrix_stack_pop (ctx->projection_stack); - _cogl_set_current_matrix (COGL_MATRIX_MODELVIEW); - _cogl_current_matrix_pop (); + _cogl_matrix_stack_pop (ctx->modelview_stack); } /* Bind window framebuffer object */ diff --git a/clutter/cogl/cogl/driver/gles/cogl-primitives.c b/clutter/cogl/cogl/driver/gles/cogl-primitives.c index 65705a4c1..f31bd2143 100644 --- a/clutter/cogl/cogl/driver/gles/cogl-primitives.c +++ b/clutter/cogl/cogl/driver/gles/cogl-primitives.c @@ -167,7 +167,7 @@ _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min, GE( glColorMask (FALSE, FALSE, FALSE, FALSE) ); GE( glDepthMask (FALSE) ); - _cogl_current_matrix_state_flush (); + _cogl_matrix_stack_flush_to_gl (ctx->modelview_stack, COGL_MATRIX_MODELVIEW); while (path_start < path_size) { GE( glVertexPointer (2, GL_FLOAT, sizeof (CoglPathNode), @@ -204,27 +204,17 @@ _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min, /* Decrement all of the bits twice so that only pixels where the value is 3 will remain */ - _cogl_set_current_matrix (COGL_MATRIX_PROJECTION); - _cogl_current_matrix_push (); - _cogl_current_matrix_identity (); + _cogl_matrix_stack_push (ctx->projection_stack); + _cogl_matrix_stack_load_identity (ctx->projection_stack); - /* Cogl generally assumes the modelview matrix is current, so since - * cogl_rectangle will be flushing GL state and emitting geometry - * to OpenGL it will be confused if we leave the projection matrix - * active... */ - _cogl_set_current_matrix (COGL_MATRIX_MODELVIEW); - _cogl_current_matrix_push (); - _cogl_current_matrix_identity (); + _cogl_matrix_stack_push (ctx->modelview_stack); + _cogl_matrix_stack_load_identity (ctx->modelview_stack); cogl_rectangle (-1.0, -1.0, 1.0, 1.0); cogl_rectangle (-1.0, -1.0, 1.0, 1.0); - _cogl_current_matrix_pop (); - - _cogl_set_current_matrix (COGL_MATRIX_PROJECTION); - _cogl_current_matrix_pop (); - - _cogl_set_current_matrix (COGL_MATRIX_MODELVIEW); + _cogl_matrix_stack_pop (ctx->modelview_stack); + _cogl_matrix_stack_pop (ctx->projection_stack); } GE( glStencilMask (~(GLuint) 0) ); diff --git a/doc/reference/cogl/Makefile.am b/doc/reference/cogl/Makefile.am index 89389e3d7..764d48142 100644 --- a/doc/reference/cogl/Makefile.am +++ b/doc/reference/cogl/Makefile.am @@ -57,7 +57,6 @@ IGNORE_HFILES=\ cogl-defines-gles.h \ cogl-internal.h \ cogl-material-private.h \ - cogl-current-matrix.h \ cogl-bitmap-private.h \ cogl-blend-string.h \ cogl-vertex-buffer-private.h \