From 8051596e96a296cf30887f6e522a288895b628f8 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Mon, 26 Oct 2009 11:01:33 +0000 Subject: [PATCH] [debug] Adds a COGL_DEBUG=matrices debug option This adds a COGL_DEBUG=matrices debug option that can be used to trace all matrix manipulation done using the Cogl API. This can be handy when you break something in such a way that a trace is still comparable with a previous working version since you can simply diff a log of the broken version vs the working version to home in on the bug. --- clutter/cogl/cogl/cogl-debug.c | 3 +- clutter/cogl/cogl/cogl-debug.h | 3 +- clutter/cogl/cogl/cogl-matrix-private.h | 47 +++++++++++++++++++++++++ clutter/cogl/cogl/cogl-matrix.c | 20 +++++++++++ clutter/cogl/cogl/cogl.c | 5 +++ 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 clutter/cogl/cogl/cogl-matrix-private.h diff --git a/clutter/cogl/cogl/cogl-debug.c b/clutter/cogl/cogl/cogl-debug.c index 6ca99c5b3..efc0146a3 100644 --- a/clutter/cogl/cogl/cogl-debug.c +++ b/clutter/cogl/cogl/cogl-debug.c @@ -46,7 +46,8 @@ static const GDebugKey cogl_debug_keys[] = { { "disable-vbos", COGL_DEBUG_DISABLE_VBOS }, { "journal", COGL_DEBUG_JOURNAL }, { "batching", COGL_DEBUG_BATCHING }, - { "disable-software-transform", COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM } + { "disable-software-transform", COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM }, + { "matrices", COGL_DEBUG_MATRICES } }; static const gint n_cogl_debug_keys = G_N_ELEMENTS (cogl_debug_keys); diff --git a/clutter/cogl/cogl/cogl-debug.h b/clutter/cogl/cogl/cogl-debug.h index a1e5a358c..86d3b57db 100644 --- a/clutter/cogl/cogl/cogl-debug.h +++ b/clutter/cogl/cogl/cogl-debug.h @@ -44,7 +44,8 @@ typedef enum { COGL_DEBUG_DISABLE_VBOS = 1 << 12, COGL_DEBUG_JOURNAL = 1 << 13, COGL_DEBUG_BATCHING = 1 << 14, - COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM = 1 << 15 + COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM = 1 << 15, + COGL_DEBUG_MATRICES = 1 << 16 } CoglDebugFlags; #ifdef COGL_ENABLE_DEBUG diff --git a/clutter/cogl/cogl/cogl-matrix-private.h b/clutter/cogl/cogl/cogl-matrix-private.h new file mode 100644 index 000000000..4323815e9 --- /dev/null +++ b/clutter/cogl/cogl/cogl-matrix-private.h @@ -0,0 +1,47 @@ +/* + * Cogl + * + * An object oriented GL/GLES Abstraction/Utility Layer + * + * Copyright (C) 2008,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: + * Robert Bragg + */ + +#ifndef __COGL_MATRIX_PRIVATE_H +#define __COGL_MATRIX_PRIVATE_H + +#include + +G_BEGIN_DECLS + +#define _COGL_MATRIX_DEBUG_PRINT(MATRIX) \ + if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_MATRICES)) \ + { \ + g_print ("%s:\n", G_STRFUNC); \ + _cogl_matrix_print (MATRIX); \ + } + +void +_cogl_matrix_print (CoglMatrix *matrix); + +G_END_DECLS + +#endif /* __COGL_MATRIX_PRIVATE_H */ + diff --git a/clutter/cogl/cogl/cogl-matrix.c b/clutter/cogl/cogl/cogl-matrix.c index 5cb121b53..4a4fccf31 100644 --- a/clutter/cogl/cogl/cogl-matrix.c +++ b/clutter/cogl/cogl/cogl-matrix.c @@ -28,6 +28,7 @@ #include #include +#include #ifdef USE_MESA_MATRIX_API #include #endif @@ -36,6 +37,16 @@ #include #include +void +_cogl_matrix_print (CoglMatrix *matrix) +{ + float *m = (float *)matrix; + int y; + + for (y = 0; y < 4; y++) + g_print ("\t%6.4f %6.4f %6.4f %6.4f\n", m[y], m[4+y], m[8+y], m[12+y]); +} + void cogl_matrix_init_identity (CoglMatrix *matrix) { @@ -47,6 +58,7 @@ cogl_matrix_init_identity (CoglMatrix *matrix) #else _math_matrix_init_identity (matrix); #endif + _COGL_MATRIX_DEBUG_PRINT (matrix); } void @@ -90,6 +102,7 @@ cogl_matrix_multiply (CoglMatrix *result, #else _math_matrix_multiply (result, a, b); #endif + _COGL_MATRIX_DEBUG_PRINT (result); } void @@ -133,6 +146,7 @@ cogl_matrix_rotate (CoglMatrix *matrix, #else _math_matrix_rotate (matrix, angle, x, y, z); #endif + _COGL_MATRIX_DEBUG_PRINT (matrix); } void @@ -149,6 +163,7 @@ cogl_matrix_translate (CoglMatrix *matrix, #else _math_matrix_translate (matrix, x, y, z); #endif + _COGL_MATRIX_DEBUG_PRINT (matrix); } void @@ -165,6 +180,7 @@ cogl_matrix_scale (CoglMatrix *matrix, #else _math_matrix_scale (matrix, sx, sy, sz); #endif + _COGL_MATRIX_DEBUG_PRINT (matrix); } #if 0 @@ -223,6 +239,7 @@ cogl_matrix_frustum (CoglMatrix *matrix, #else _math_matrix_frustum (matrix, left, right, bottom, top, z_near, z_far); #endif + _COGL_MATRIX_DEBUG_PRINT (matrix); } void @@ -241,6 +258,7 @@ cogl_matrix_perspective (CoglMatrix *matrix, ymax, /* top */ z_near, z_far); + _COGL_MATRIX_DEBUG_PRINT (matrix); } void @@ -283,6 +301,7 @@ cogl_matrix_ortho (CoglMatrix *matrix, #else _math_matrix_ortho (matrix, left, right, bottom, top, near_val, far_val); #endif + _COGL_MATRIX_DEBUG_PRINT (matrix); } void @@ -293,6 +312,7 @@ cogl_matrix_init_from_array (CoglMatrix *matrix, const float *array) #else _math_matrix_init_from_array (matrix, array); #endif + _COGL_MATRIX_DEBUG_PRINT (matrix); } const float * diff --git a/clutter/cogl/cogl/cogl.c b/clutter/cogl/cogl/cogl.c index b1cef8b5b..7f556155a 100644 --- a/clutter/cogl/cogl/cogl.c +++ b/clutter/cogl/cogl/cogl.c @@ -39,6 +39,7 @@ #include "cogl-material-private.h" #include "cogl-winsys.h" #include "cogl-draw-buffer-private.h" +#include "cogl-matrix-private.h" #if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES) #include "cogl-gles2-wrapper.h" @@ -1165,6 +1166,7 @@ cogl_get_modelview_matrix (CoglMatrix *matrix) CoglMatrixStack *modelview_stack = _cogl_draw_buffer_get_modelview_stack (_cogl_get_draw_buffer ()); _cogl_matrix_stack_get (modelview_stack, matrix); + _COGL_MATRIX_DEBUG_PRINT (matrix); } void @@ -1173,6 +1175,7 @@ cogl_set_modelview_matrix (CoglMatrix *matrix) CoglMatrixStack *modelview_stack = _cogl_draw_buffer_get_modelview_stack (_cogl_get_draw_buffer ()); _cogl_matrix_stack_set (modelview_stack, matrix); + _COGL_MATRIX_DEBUG_PRINT (matrix); } void @@ -1181,6 +1184,7 @@ cogl_get_projection_matrix (CoglMatrix *matrix) CoglMatrixStack *projection_stack = _cogl_draw_buffer_get_projection_stack (_cogl_get_draw_buffer ()); _cogl_matrix_stack_get (projection_stack, matrix); + _COGL_MATRIX_DEBUG_PRINT (matrix); } void @@ -1192,6 +1196,7 @@ cogl_set_projection_matrix (CoglMatrix *matrix) /* FIXME: Update the inverse projection matrix!! Presumably use * of clip planes must currently be broken if this API is used. */ + _COGL_MATRIX_DEBUG_PRINT (matrix); } CoglClipStackState *