[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.
This commit is contained in:
Robert Bragg 2009-10-26 11:01:33 +00:00
parent eb438dd499
commit 8051596e96
5 changed files with 76 additions and 2 deletions

View File

@ -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);

View File

@ -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

View File

@ -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 <robert@linux.intel.com>
*/
#ifndef __COGL_MATRIX_PRIVATE_H
#define __COGL_MATRIX_PRIVATE_H
#include <glib.h>
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 */

View File

@ -28,6 +28,7 @@
#include <cogl.h>
#include <cogl-matrix.h>
#include <cogl-matrix-private.h>
#ifdef USE_MESA_MATRIX_API
#include <cogl-matrix-mesa.h>
#endif
@ -36,6 +37,16 @@
#include <math.h>
#include <string.h>
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 *

View File

@ -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 *