mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 19:42:05 +00:00
[Cogl] the cogl_get_*_matrix functions now work with CoglMatrix types
Since the CoglMatrix type was added for supporting texture matrices recently it made sense to be consistent accross the Cogl API and use the Cogl type over the GL style GLfloat m[16] arrays.
This commit is contained in:
parent
e6a7a70d54
commit
e91fe8817d
@ -140,6 +140,42 @@ void cogl_matrix_scale (CoglMatrix *matrix,
|
||||
float sy,
|
||||
float sz);
|
||||
|
||||
/**
|
||||
* cogl_matrix_transform_point:
|
||||
* @matrix: A 4x4 transformation matrix
|
||||
* @x: The X component of your points position [in:out]
|
||||
* @y: The Y component of your points position [in:out]
|
||||
* @z: The Z component of your points position [in:out]
|
||||
* @w: The W component of your points position [in:out]
|
||||
*
|
||||
* This transforms a point whos position is given and returned
|
||||
* as four float components.
|
||||
*/
|
||||
void
|
||||
cogl_matrix_transform_point (const CoglMatrix *matrix,
|
||||
float *x,
|
||||
float *y,
|
||||
float *z,
|
||||
float *w);
|
||||
|
||||
/**
|
||||
* cogl_matrix_init_from_gl_matrix:
|
||||
* @matrix: A 4x4 transformation matrix
|
||||
* @gl_matrix: A linear array of 16 Glfloats (column-major)
|
||||
*
|
||||
* This initialises @matrix with the contents of @gl_matrix
|
||||
*/
|
||||
void cogl_matrix_init_from_gl_matrix (CoglMatrix *matrix, const float *gl_matrix);
|
||||
|
||||
/**
|
||||
* cogl_matrix_get_gl_matrix:
|
||||
* @matrix: A 4x4 transformation matrix
|
||||
*
|
||||
* This casts a CoglMatrix to a GLfloat array which can be directly passed to
|
||||
* OpenGL.
|
||||
*/
|
||||
const float *cogl_matrix_get_gl_matrix (const CoglMatrix *matrix);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_MATRIX_H */
|
||||
|
14
cogl.h.in
14
cogl.h.in
@ -268,21 +268,19 @@ void cogl_rotate (float angle,
|
||||
|
||||
/**
|
||||
* cogl_get_modelview_matrix:
|
||||
* @m: pointer to a 4x4 array of #float<!-- -->s to receive the matrix
|
||||
* @matrix: pointer to a CoglMatrix to recieve the matrix
|
||||
*
|
||||
* Stores the current model-view matrix in @m. The matrix is in
|
||||
* column-major order.
|
||||
* Stores the current model-view matrix in @matrix.
|
||||
*/
|
||||
void cogl_get_modelview_matrix (float m[16]);
|
||||
void cogl_get_modelview_matrix (CoglMatrix *matrix);
|
||||
|
||||
/**
|
||||
* cogl_get_projection_matrix:
|
||||
* @m: pointer to a 4x4 array of #float<!-- -->s to receive the matrix
|
||||
* @matrix: pointer to a CoglMatrix to recieve the matrix
|
||||
*
|
||||
* Stores the current projection matrix in @m. The matrix is in
|
||||
* column-major order.
|
||||
* Stores the current projection matrix in @matrix.
|
||||
*/
|
||||
void cogl_get_projection_matrix (float m[16]);
|
||||
void cogl_get_projection_matrix (CoglMatrix *matrix);
|
||||
|
||||
/**
|
||||
* cogl_get_viewport:
|
||||
|
@ -52,7 +52,7 @@ void _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min,
|
||||
void _cogl_enable_clip_planes (void);
|
||||
void _cogl_disable_clip_planes (void);
|
||||
void _cogl_disable_stencil_buffer (void);
|
||||
void _cogl_set_matrix (const float *matrix);
|
||||
void _cogl_set_matrix (const CoglMatrix *matrix);
|
||||
|
||||
typedef struct _CoglClipStack CoglClipStack;
|
||||
|
||||
@ -81,7 +81,7 @@ struct _CoglClipStackEntryRect
|
||||
float height;
|
||||
|
||||
/* The matrix that was current when the clip was set */
|
||||
float matrix[16];
|
||||
CoglMatrix matrix;
|
||||
};
|
||||
|
||||
struct _CoglClipStackEntryPath
|
||||
@ -89,7 +89,7 @@ struct _CoglClipStackEntryPath
|
||||
CoglClipStackEntryType type;
|
||||
|
||||
/* The matrix that was current when the clip was set */
|
||||
float matrix[16];
|
||||
CoglMatrix matrix;
|
||||
|
||||
floatVec2 path_nodes_min;
|
||||
floatVec2 path_nodes_max;
|
||||
@ -120,7 +120,7 @@ cogl_clip_push (float x_offset,
|
||||
entry->width = width;
|
||||
entry->height = height;
|
||||
|
||||
cogl_get_modelview_matrix (entry->matrix);
|
||||
cogl_get_modelview_matrix (&entry->matrix);
|
||||
|
||||
/* Store it in the stack */
|
||||
stack->stack_top = g_list_prepend (stack->stack_top, entry);
|
||||
@ -148,7 +148,7 @@ cogl_clip_push_from_path_preserve (void)
|
||||
memcpy (entry->path, ctx->path_nodes->data,
|
||||
sizeof (CoglPathNode) * ctx->path_nodes->len);
|
||||
|
||||
cogl_get_modelview_matrix (entry->matrix);
|
||||
cogl_get_modelview_matrix (&entry->matrix);
|
||||
|
||||
/* Store it in the stack */
|
||||
stack->stack_top = g_list_prepend (stack->stack_top, entry);
|
||||
@ -226,7 +226,7 @@ _cogl_clip_stack_rebuild (void)
|
||||
CoglClipStackEntryPath *path = (CoglClipStackEntryPath *) entry;
|
||||
|
||||
cogl_push_matrix ();
|
||||
_cogl_set_matrix (path->matrix);
|
||||
_cogl_set_matrix (&path->matrix);
|
||||
|
||||
_cogl_add_path_to_stencil_buffer (path->path_nodes_min,
|
||||
path->path_nodes_max,
|
||||
@ -246,7 +246,7 @@ _cogl_clip_stack_rebuild (void)
|
||||
CoglClipStackEntryRect *rect = (CoglClipStackEntryRect *) entry;
|
||||
|
||||
cogl_push_matrix ();
|
||||
_cogl_set_matrix (rect->matrix);
|
||||
_cogl_set_matrix (&rect->matrix);
|
||||
|
||||
/* If this is the first entry and we support clip planes then use
|
||||
that instead */
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <glib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
cogl_matrix_init_identity (CoglMatrix *matrix)
|
||||
@ -42,7 +43,7 @@ cogl_matrix_multiply (CoglMatrix *result,
|
||||
r.wy = a->wx * b->xy + a->wy * b->yy + a->wz * b->zy + a->ww * b->wy;
|
||||
r.wz = a->wx * b->xz + a->wy * b->yz + a->wz * b->zz + a->ww * b->wz;
|
||||
r.ww = a->wx * b->xw + a->wy * b->yw + a->wz * b->zw + a->ww * b->ww;
|
||||
|
||||
|
||||
/* The idea was that having this unrolled; it might be easier for the
|
||||
* compiler to vectorize, but that's probably not true. Mesa does it
|
||||
* using a single for (i=0; i<4; i++) approach, may that's better...
|
||||
@ -51,19 +52,6 @@ cogl_matrix_multiply (CoglMatrix *result,
|
||||
*result = r;
|
||||
}
|
||||
|
||||
/**
|
||||
* cogl_3dmatrix_rotate:
|
||||
* @matrix: A 3D Affine transformation matrix
|
||||
* @angle: The angle in degrees you want to rotate by
|
||||
* @x: The X component of your rotation vector
|
||||
* @y: The Y component of your rotation vector
|
||||
* @z: The Z component of your rotation vector
|
||||
*
|
||||
* The matrix is multiplied with a rotation matrix representing a rotation
|
||||
* of angle degress around the vector (x,y,z)
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
void
|
||||
cogl_matrix_rotate (CoglMatrix *matrix,
|
||||
float angle,
|
||||
@ -76,7 +64,7 @@ cogl_matrix_rotate (CoglMatrix *matrix,
|
||||
angle *= G_PI / 180.0f;
|
||||
float c = cosf (angle);
|
||||
float s = sinf (angle);
|
||||
|
||||
|
||||
rotation.xx = x * x * (1.0f - c) + c;
|
||||
rotation.yx = y * x * (1.0f - c) + z * s;
|
||||
rotation.zx = x * z * (1.0f - c) - y * s;
|
||||
@ -96,7 +84,7 @@ cogl_matrix_rotate (CoglMatrix *matrix,
|
||||
rotation.yw = 0.0f;
|
||||
rotation.zw = 0.0f;
|
||||
rotation.ww = 1.0f;
|
||||
|
||||
|
||||
cogl_matrix_multiply (&result, matrix, &rotation);
|
||||
*matrix = result;
|
||||
}
|
||||
@ -137,4 +125,30 @@ cogl_matrix_invert (CoglMatrix *matrix)
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
cogl_matrix_transform_point (const CoglMatrix *matrix,
|
||||
float *x,
|
||||
float *y,
|
||||
float *z,
|
||||
float *w)
|
||||
{
|
||||
float _x = *x, _y = *y, _z = *z, _w = *w;
|
||||
|
||||
*x = matrix->xx * _x + matrix->xy * _y + matrix->xz * _z + matrix->xw * _w;
|
||||
*y = matrix->yx * _x + matrix->yy * _y + matrix->yz * _z + matrix->yw * _w;
|
||||
*z = matrix->zx * _x + matrix->zy * _y + matrix->zz * _z + matrix->zw * _w;
|
||||
*w = matrix->wx * _x + matrix->wy * _y + matrix->wz * _z + matrix->ww * _w;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_matrix_init_from_gl_matrix (CoglMatrix *matrix, const float *gl_matrix)
|
||||
{
|
||||
memcpy (matrix, gl_matrix, sizeof (float) * 16);
|
||||
}
|
||||
|
||||
const float *
|
||||
cogl_matrix_get_gl_matrix (const CoglMatrix *matrix)
|
||||
{
|
||||
return (float *)matrix;
|
||||
}
|
||||
|
||||
|
27
gl/cogl.c
27
gl/cogl.c
@ -530,10 +530,11 @@ _cogl_add_stencil_clip (float x_offset,
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_set_matrix (const float *matrix)
|
||||
_cogl_set_matrix (const CoglMatrix *matrix)
|
||||
{
|
||||
GE( glLoadIdentity () );
|
||||
GE( glMultMatrixf (matrix) );
|
||||
const GLfloat *gl_matrix = cogl_matrix_get_gl_matrix (matrix);
|
||||
|
||||
GE (glLoadMatrixf (gl_matrix));
|
||||
}
|
||||
|
||||
void
|
||||
@ -678,7 +679,7 @@ cogl_setup_viewport (guint width,
|
||||
float z_far)
|
||||
{
|
||||
float z_camera;
|
||||
float projection_matrix[16];
|
||||
CoglMatrix projection_matrix;
|
||||
|
||||
GE( glViewport (0, 0, width, height) );
|
||||
|
||||
@ -727,8 +728,8 @@ cogl_setup_viewport (guint width,
|
||||
* doesn't make sense.
|
||||
*/
|
||||
|
||||
cogl_get_projection_matrix (projection_matrix);
|
||||
z_camera = 0.5 * projection_matrix[0];
|
||||
cogl_get_projection_matrix (&projection_matrix);
|
||||
z_camera = 0.5 * projection_matrix.xx;
|
||||
|
||||
GE( glLoadIdentity () );
|
||||
|
||||
@ -1122,15 +1123,25 @@ cogl_features_available (CoglFeatureFlags features)
|
||||
}
|
||||
|
||||
void
|
||||
cogl_get_modelview_matrix (float m[16])
|
||||
cogl_get_modelview_matrix (CoglMatrix *matrix)
|
||||
{
|
||||
float m[16];
|
||||
glGetFloatv (GL_MODELVIEW_MATRIX, m);
|
||||
/* Since it's internal to Cogl and CoglMatrix doesn't currently have
|
||||
* any flag members, we could avoid this extra copy if it really
|
||||
* bothers anyone */
|
||||
cogl_matrix_init_from_gl_matrix (matrix, m);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_get_projection_matrix (float m[16])
|
||||
cogl_get_projection_matrix (CoglMatrix *matrix)
|
||||
{
|
||||
float m[16];
|
||||
glGetFloatv (GL_PROJECTION_MATRIX, m);
|
||||
/* Since it's internal to Cogl and CoglMatrix doesn't currently have
|
||||
* any flag members, we could avoid this extra copy if it really
|
||||
* bothers anyone */
|
||||
cogl_matrix_init_from_gl_matrix (matrix, m);
|
||||
}
|
||||
|
||||
void
|
||||
|
27
gles/cogl.c
27
gles/cogl.c
@ -453,10 +453,11 @@ _cogl_add_stencil_clip (float x_offset,
|
||||
}
|
||||
|
||||
void
|
||||
_cogl_set_matrix (const float *matrix)
|
||||
_cogl_set_matrix (const CoglMatrix *matrix)
|
||||
{
|
||||
GE( glLoadIdentity () );
|
||||
GE( glMultMatrixf (matrix) );
|
||||
const GLfloat *gl_matrix = cogl_matrix_get_gl_matrix (matrix);
|
||||
|
||||
GE (glLoadMatrixf (gl_matrix));
|
||||
}
|
||||
|
||||
void
|
||||
@ -601,7 +602,7 @@ cogl_setup_viewport (guint width,
|
||||
float z_far)
|
||||
{
|
||||
float z_camera;
|
||||
float projection_matrix[16];
|
||||
CoglMatrix projection_matrix;
|
||||
|
||||
GE( glViewport (0, 0, width, height) );
|
||||
|
||||
@ -617,8 +618,8 @@ cogl_setup_viewport (guint width,
|
||||
* See comments in ../gl/cogl.c
|
||||
*/
|
||||
|
||||
cogl_get_projection_matrix (projection_matrix);
|
||||
z_camera = 0.5 * projection_matrix[0];
|
||||
cogl_get_projection_matrix (&projection_matrix);
|
||||
z_camera = 0.5 * projection_matrix.xx;
|
||||
|
||||
GE( glLoadIdentity () );
|
||||
|
||||
@ -679,15 +680,25 @@ cogl_features_available (CoglFeatureFlags features)
|
||||
}
|
||||
|
||||
void
|
||||
cogl_get_modelview_matrix (float m[16])
|
||||
cogl_get_modelview_matrix (CoglMatrix *matrix)
|
||||
{
|
||||
float m[16];
|
||||
glGetFloatv (GL_MODELVIEW_MATRIX, m);
|
||||
/* Since it's internal to Cogl and CoglMatrix doesn't currently have
|
||||
* any flag members, we could avoid this extra copy if it really
|
||||
* bothers anyone */
|
||||
cogl_matrix_init_from_gl_matrix (matrix, m);
|
||||
}
|
||||
|
||||
void
|
||||
cogl_get_projection_matrix (float m[16])
|
||||
cogl_get_projection_matrix (CoglMatrix *matrix)
|
||||
{
|
||||
float m[16];
|
||||
glGetFloatv (GL_PROJECTION_MATRIX, m);
|
||||
/* Since it's internal to Cogl and CoglMatrix doesn't currently have
|
||||
* any flag members, we could avoid this extra copy if it really
|
||||
* bothers anyone */
|
||||
cogl_matrix_init_from_gl_matrix (matrix, m);
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user