2009-02-24 13:51:25 -05:00
|
|
|
/*
|
2009-04-27 10:48:12 -04:00
|
|
|
* Cogl
|
2009-02-24 13:51:25 -05:00
|
|
|
*
|
2009-04-27 10:48:12 -04:00
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
2009-02-24 13:51:25 -05:00
|
|
|
*
|
2009-04-27 10:48:12 -04:00
|
|
|
* Copyright (C) 2009 Intel Corporation.
|
2009-02-24 13:51:25 -05:00
|
|
|
*
|
|
|
|
* 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.
|
2009-04-27 10:48:12 -04:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Havoc Pennington <hp@pobox.com> for litl
|
2009-02-24 13:51:25 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "cogl.h"
|
|
|
|
#include "cogl-context.h"
|
|
|
|
#include "cogl-internal.h"
|
|
|
|
#include "cogl-current-matrix.h"
|
|
|
|
#include "cogl-matrix-stack.h"
|
|
|
|
|
2009-03-12 09:34:36 -04:00
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
#include "cogl-gles2-wrapper.h"
|
|
|
|
|
|
|
|
#define glFrustum(L,R,B,T,N,F) \
|
|
|
|
cogl_wrap_glFrustumf((GLfloat)L, (GLfloat)R, (GLfloat)B, \
|
|
|
|
(GLfloat)T, (GLfloat)N, (GLfloat)F)
|
|
|
|
#elif defined (HAVE_COGL_GLES)
|
|
|
|
|
|
|
|
#define glFrustum(L,R,B,T,N,F) \
|
|
|
|
glFrustumf((GLfloat)L, (GLfloat)R, (GLfloat)B, \
|
|
|
|
(GLfloat)T, (GLfloat)N, (GLfloat)F)
|
2009-05-26 06:33:54 -04:00
|
|
|
|
|
|
|
#define glOrtho glOrthof
|
|
|
|
|
2009-03-12 09:34:36 -04:00
|
|
|
#endif
|
|
|
|
|
2009-02-24 13:51:25 -05:00
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_set_current_matrix (CoglMatrixMode mode)
|
|
|
|
{
|
|
|
|
GLenum gl_mode;
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if (mode == ctx->matrix_mode)
|
|
|
|
return;
|
|
|
|
ctx->matrix_mode = mode;
|
|
|
|
|
|
|
|
gl_mode = 0; /* silence compiler warning */
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case COGL_MATRIX_MODELVIEW:
|
|
|
|
gl_mode = GL_MODELVIEW;
|
|
|
|
break;
|
|
|
|
case COGL_MATRIX_PROJECTION:
|
|
|
|
gl_mode = GL_PROJECTION;
|
|
|
|
break;
|
|
|
|
case COGL_MATRIX_TEXTURE:
|
|
|
|
gl_mode = GL_TEXTURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
GE (glMatrixMode (gl_mode));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_get_client_stack (CoglContext *ctx,
|
|
|
|
CoglMatrixStack **current_stack_p)
|
|
|
|
{
|
|
|
|
if (ctx->modelview_stack &&
|
|
|
|
ctx->matrix_mode == COGL_MATRIX_MODELVIEW)
|
|
|
|
*current_stack_p = ctx->modelview_stack;
|
|
|
|
else
|
|
|
|
*current_stack_p = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define _COGL_GET_CONTEXT_AND_STACK(contextvar, stackvar, rval) \
|
|
|
|
CoglMatrixStack *stackvar; \
|
|
|
|
_COGL_GET_CONTEXT (contextvar, rval); \
|
|
|
|
_cogl_get_client_stack (contextvar, &stackvar)
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_current_matrix_push (void)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT_AND_STACK (ctx, current_stack, NO_RETVAL);
|
|
|
|
|
|
|
|
if (current_stack != NULL)
|
|
|
|
_cogl_matrix_stack_push (current_stack);
|
|
|
|
else
|
|
|
|
GE (glPushMatrix ());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_current_matrix_pop (void)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT_AND_STACK (ctx, current_stack, NO_RETVAL);
|
|
|
|
|
|
|
|
if (current_stack != NULL)
|
|
|
|
_cogl_matrix_stack_pop (current_stack);
|
|
|
|
else
|
|
|
|
GE (glPopMatrix ());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_current_matrix_identity (void)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT_AND_STACK (ctx, current_stack, NO_RETVAL);
|
|
|
|
|
|
|
|
if (current_stack != NULL)
|
|
|
|
_cogl_matrix_stack_load_identity (current_stack);
|
|
|
|
else
|
|
|
|
GE (glLoadIdentity ());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_current_matrix_load (const CoglMatrix *matrix)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT_AND_STACK (ctx, current_stack, NO_RETVAL);
|
|
|
|
|
|
|
|
if (current_stack != NULL)
|
|
|
|
_cogl_matrix_stack_set (current_stack, matrix);
|
|
|
|
else
|
|
|
|
GE (glLoadMatrixf (cogl_matrix_get_array (matrix)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_current_matrix_multiply (const CoglMatrix *matrix)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT_AND_STACK (ctx, current_stack, NO_RETVAL);
|
|
|
|
|
|
|
|
if (current_stack != NULL)
|
|
|
|
_cogl_matrix_stack_multiply (current_stack, matrix);
|
|
|
|
else
|
|
|
|
GE (glMultMatrixf (cogl_matrix_get_array (matrix)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_current_matrix_rotate (float angle,
|
|
|
|
float x,
|
|
|
|
float y,
|
|
|
|
float z)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT_AND_STACK (ctx, current_stack, NO_RETVAL);
|
|
|
|
|
|
|
|
if (current_stack != NULL)
|
|
|
|
_cogl_matrix_stack_rotate (current_stack, angle, x, y, z);
|
|
|
|
else
|
|
|
|
GE (glRotatef (angle, x, y, z));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_current_matrix_scale (float x,
|
|
|
|
float y,
|
|
|
|
float z)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT_AND_STACK (ctx, current_stack, NO_RETVAL);
|
|
|
|
|
|
|
|
if (current_stack != NULL)
|
|
|
|
_cogl_matrix_stack_scale (current_stack, x, y, z);
|
|
|
|
else
|
|
|
|
GE (glScalef (x, y, z));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_current_matrix_translate (float x,
|
|
|
|
float y,
|
|
|
|
float z)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT_AND_STACK (ctx, current_stack, NO_RETVAL);
|
|
|
|
|
|
|
|
if (current_stack != NULL)
|
|
|
|
_cogl_matrix_stack_translate (current_stack, x, y, z);
|
|
|
|
else
|
|
|
|
GE (glTranslatef (x, y, z));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_current_matrix_frustum (float left,
|
|
|
|
float right,
|
|
|
|
float bottom,
|
|
|
|
float top,
|
|
|
|
float near_val,
|
|
|
|
float far_val)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT_AND_STACK (ctx, current_stack, NO_RETVAL);
|
|
|
|
|
|
|
|
if (current_stack != NULL)
|
|
|
|
_cogl_matrix_stack_frustum (current_stack,
|
|
|
|
left, right,
|
|
|
|
top, bottom,
|
|
|
|
near_val,
|
|
|
|
far_val);
|
|
|
|
else
|
|
|
|
GE (glFrustum (left, right, bottom, top, near_val, far_val));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-26 06:33:54 -04:00
|
|
|
_cogl_current_matrix_perspective (float fov_y,
|
|
|
|
float aspect,
|
|
|
|
float z_near,
|
|
|
|
float z_far)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT_AND_STACK (ctx, current_stack, NO_RETVAL);
|
|
|
|
|
|
|
|
if (current_stack != NULL)
|
|
|
|
_cogl_matrix_stack_perspective (current_stack,
|
|
|
|
fov_y, aspect, z_near, z_far);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* NB: There is no glPerspective() (only gluPerspective()) so we use
|
|
|
|
* cogl_matrix_perspective: */
|
|
|
|
CoglMatrix matrix;
|
|
|
|
_cogl_get_matrix (ctx->matrix_mode, &matrix);
|
|
|
|
cogl_matrix_perspective (&matrix,
|
|
|
|
fov_y, aspect, z_near, z_far);
|
|
|
|
_cogl_current_matrix_load (&matrix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_current_matrix_ortho (float left,
|
|
|
|
float right,
|
|
|
|
float bottom,
|
|
|
|
float top,
|
2009-06-04 06:48:51 -04:00
|
|
|
float near_val,
|
|
|
|
float far_val)
|
2009-02-24 13:51:25 -05:00
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT_AND_STACK (ctx, current_stack, NO_RETVAL);
|
|
|
|
|
|
|
|
if (current_stack != NULL)
|
|
|
|
_cogl_matrix_stack_ortho (current_stack,
|
|
|
|
left, right,
|
2009-05-26 06:33:54 -04:00
|
|
|
bottom, top,
|
2009-06-04 06:48:51 -04:00
|
|
|
near_val,
|
|
|
|
far_val);
|
2009-02-24 13:51:25 -05:00
|
|
|
else
|
2009-05-26 06:33:54 -04:00
|
|
|
{
|
|
|
|
#ifdef HAVE_COGL_GLES2
|
|
|
|
/* NB: GLES 2 has no glOrtho(): */
|
|
|
|
CoglMatrix matrix;
|
|
|
|
_cogl_get_matrix (ctx->matrix_mode, &matrix);
|
|
|
|
cogl_matrix_ortho (&matrix,
|
2009-06-04 06:48:51 -04:00
|
|
|
left, right, bottom, top, near_val, far_val);
|
2009-05-26 06:33:54 -04:00
|
|
|
_cogl_current_matrix_load (&matrix);
|
2009-02-24 13:51:25 -05:00
|
|
|
#else
|
2009-06-04 06:48:51 -04:00
|
|
|
GE (glOrtho (left, right, bottom, top, near_val, far_val));
|
2009-02-24 13:51:25 -05:00
|
|
|
#endif
|
2009-05-26 06:33:54 -04:00
|
|
|
}
|
2009-02-24 13:51:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_get_matrix (CoglMatrixMode mode,
|
|
|
|
CoglMatrix *matrix)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if (ctx->modelview_stack != NULL &&
|
|
|
|
mode == COGL_MATRIX_MODELVIEW)
|
|
|
|
{
|
|
|
|
_cogl_matrix_stack_get (ctx->modelview_stack, matrix);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GLenum gl_mode;
|
2009-03-05 22:29:51 -05:00
|
|
|
GLfloat gl_matrix[16];
|
2009-02-24 13:51:25 -05:00
|
|
|
|
|
|
|
gl_mode = 0; /* silence compiler warning */
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case COGL_MATRIX_MODELVIEW:
|
|
|
|
gl_mode = GL_MODELVIEW_MATRIX;
|
|
|
|
break;
|
|
|
|
case COGL_MATRIX_PROJECTION:
|
|
|
|
gl_mode = GL_PROJECTION_MATRIX;
|
|
|
|
break;
|
|
|
|
case COGL_MATRIX_TEXTURE:
|
|
|
|
gl_mode = GL_TEXTURE_MATRIX;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-03-05 22:29:51 -05:00
|
|
|
/* Note: we have a redundant copy happening here. If that turns out to be
|
|
|
|
* a problem then, since this is internal to Cogl, we could pass the
|
|
|
|
* CoglMatrix pointer directly to glGetFloatv; the only problem with that
|
|
|
|
* is that if we later add internal flags to CoglMatrix they will need to
|
|
|
|
* be initialized seperatly.
|
2009-02-24 13:51:25 -05:00
|
|
|
*/
|
2009-03-05 22:29:51 -05:00
|
|
|
GE (glGetFloatv (gl_mode, gl_matrix));
|
|
|
|
cogl_matrix_init_from_array (matrix, gl_matrix);
|
2009-02-24 13:51:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-26 06:33:54 -04:00
|
|
|
void
|
|
|
|
_cogl_set_matrix (const CoglMatrix *matrix)
|
|
|
|
{
|
|
|
|
_cogl_current_matrix_load (matrix);
|
|
|
|
}
|
|
|
|
|
2009-02-24 13:51:25 -05:00
|
|
|
void
|
|
|
|
_cogl_current_matrix_state_init (void)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
ctx->matrix_mode = COGL_MATRIX_MODELVIEW;
|
|
|
|
ctx->modelview_stack = NULL;
|
|
|
|
|
2009-06-05 08:50:00 -04:00
|
|
|
if (ctx->indirect ||
|
|
|
|
cogl_debug_flags & COGL_DEBUG_FORCE_CLIENT_SIDE_MATRICES)
|
2009-02-24 13:51:25 -05:00
|
|
|
{
|
|
|
|
ctx->modelview_stack =
|
|
|
|
_cogl_matrix_stack_new ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_current_matrix_state_destroy (void)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if (ctx->modelview_stack)
|
|
|
|
_cogl_matrix_stack_destroy (ctx->modelview_stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_current_matrix_state_flush (void)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if (ctx->matrix_mode != COGL_MATRIX_MODELVIEW)
|
|
|
|
{
|
|
|
|
g_warning ("matrix state must be flushed in MODELVIEW mode");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->modelview_stack)
|
|
|
|
{
|
|
|
|
_cogl_matrix_stack_flush_to_gl (ctx->modelview_stack,
|
|
|
|
GL_MODELVIEW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-16 21:08:31 -04:00
|
|
|
void
|
|
|
|
_cogl_current_matrix_state_dirty (void)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if (ctx->matrix_mode != COGL_MATRIX_MODELVIEW)
|
|
|
|
{
|
|
|
|
g_warning ("matrix state must be dirtied in MODELVIEW mode");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->modelview_stack)
|
|
|
|
_cogl_matrix_stack_dirty (ctx->modelview_stack);
|
|
|
|
}
|
|
|
|
|
2009-02-24 13:51:25 -05:00
|
|
|
void
|
|
|
|
cogl_push_matrix (void)
|
|
|
|
{
|
2009-03-12 09:32:10 -04:00
|
|
|
_cogl_set_current_matrix (COGL_MATRIX_MODELVIEW);
|
2009-02-24 13:51:25 -05:00
|
|
|
_cogl_current_matrix_push ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pop_matrix (void)
|
|
|
|
{
|
2009-03-12 09:32:10 -04:00
|
|
|
_cogl_set_current_matrix (COGL_MATRIX_MODELVIEW);
|
2009-02-24 13:51:25 -05:00
|
|
|
_cogl_current_matrix_pop ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_scale (float x, float y, float z)
|
|
|
|
{
|
2009-03-12 09:32:10 -04:00
|
|
|
_cogl_set_current_matrix (COGL_MATRIX_MODELVIEW);
|
2009-02-24 13:51:25 -05:00
|
|
|
_cogl_current_matrix_scale (x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_translate (float x, float y, float z)
|
|
|
|
{
|
2009-03-12 09:32:10 -04:00
|
|
|
_cogl_set_current_matrix (COGL_MATRIX_MODELVIEW);
|
2009-02-24 13:51:25 -05:00
|
|
|
_cogl_current_matrix_translate (x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_rotate (float angle, float x, float y, float z)
|
|
|
|
{
|
2009-03-12 09:32:10 -04:00
|
|
|
_cogl_set_current_matrix (COGL_MATRIX_MODELVIEW);
|
2009-02-24 13:51:25 -05:00
|
|
|
_cogl_current_matrix_rotate (angle, x, y, z);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-05-26 06:33:54 -04:00
|
|
|
cogl_perspective (float fov_y,
|
2009-02-24 13:51:25 -05:00
|
|
|
float aspect,
|
2009-05-26 06:33:54 -04:00
|
|
|
float z_near,
|
|
|
|
float z_far)
|
2009-02-24 13:51:25 -05:00
|
|
|
{
|
2009-05-26 06:33:54 -04:00
|
|
|
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);
|
2009-02-24 13:51:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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_set_current_matrix (COGL_MATRIX_PROJECTION);
|
|
|
|
_cogl_current_matrix_identity ();
|
|
|
|
|
|
|
|
_cogl_current_matrix_frustum (left,
|
|
|
|
right,
|
|
|
|
bottom,
|
|
|
|
top,
|
|
|
|
z_near,
|
|
|
|
z_far);
|
|
|
|
|
|
|
|
_cogl_set_current_matrix (COGL_MATRIX_MODELVIEW);
|
|
|
|
|
|
|
|
/* 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
|
2009-05-26 06:33:54 -04:00
|
|
|
|
|
|
|
_cogl_set_current_matrix (COGL_MATRIX_MODELVIEW);
|
2009-02-24 13:51:25 -05:00
|
|
|
}
|
2009-05-26 06:33:54 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
cogl_ortho (float left,
|
|
|
|
float right,
|
|
|
|
float bottom,
|
|
|
|
float top,
|
2009-06-04 06:48:51 -04:00
|
|
|
float z_near,
|
|
|
|
float z_far)
|
2009-05-26 06:33:54 -04:00
|
|
|
{
|
|
|
|
CoglMatrix ortho;
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
cogl_matrix_init_identity (&ortho);
|
2009-06-04 06:48:51 -04:00
|
|
|
cogl_matrix_ortho (&ortho, left, right, bottom, top, z_near, z_far);
|
2009-05-26 06:33:54 -04:00
|
|
|
_cogl_set_current_matrix (COGL_MATRIX_PROJECTION);
|
|
|
|
_cogl_current_matrix_load (&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_matrix (COGL_MATRIX_MODELVIEW,
|
|
|
|
matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_modelview_matrix (CoglMatrix *matrix)
|
|
|
|
{
|
|
|
|
_cogl_set_current_matrix (COGL_MATRIX_MODELVIEW);
|
|
|
|
_cogl_current_matrix_load (matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_get_projection_matrix (CoglMatrix *matrix)
|
|
|
|
{
|
|
|
|
_cogl_get_matrix (COGL_MATRIX_PROJECTION,
|
|
|
|
matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_set_projection_matrix (CoglMatrix *matrix)
|
|
|
|
{
|
|
|
|
_cogl_set_current_matrix (COGL_MATRIX_PROJECTION);
|
|
|
|
_cogl_current_matrix_load (matrix);
|
|
|
|
}
|
|
|
|
|