2007-03-27 17:09:11 -04:00
|
|
|
/*
|
|
|
|
* Clutter COGL
|
|
|
|
*
|
|
|
|
* A basic GL/GLES Abstraction/Utility Layer
|
|
|
|
*
|
|
|
|
* Authored By Matthew Allum <mallum@openedhand.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 OpenedHand
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2007-10-12 04:17:00 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2007-04-27 20:37:11 -04:00
|
|
|
#include "config.h"
|
2007-10-12 04:17:00 -04:00
|
|
|
#endif
|
|
|
|
|
2007-03-27 17:09:11 -04:00
|
|
|
#include "cogl.h"
|
2007-04-27 20:37:11 -04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
#include "cogl-internal.h"
|
|
|
|
#include "cogl-util.h"
|
|
|
|
#include "cogl-context.h"
|
2007-04-27 17:13:06 -04:00
|
|
|
|
2008-05-27 13:42:50 -04:00
|
|
|
#include "cogl-gles2-wrapper.h"
|
2007-05-01 11:26:12 -04:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
/* GL error to string conversion */
|
2007-04-27 17:13:06 -04:00
|
|
|
#if COGL_DEBUG
|
|
|
|
struct token_string
|
|
|
|
{
|
|
|
|
GLuint Token;
|
|
|
|
const char *String;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct token_string Errors[] = {
|
|
|
|
{ GL_NO_ERROR, "no error" },
|
|
|
|
{ GL_INVALID_ENUM, "invalid enumerant" },
|
|
|
|
{ GL_INVALID_VALUE, "invalid value" },
|
|
|
|
{ GL_INVALID_OPERATION, "invalid operation" },
|
|
|
|
{ GL_STACK_OVERFLOW, "stack overflow" },
|
|
|
|
{ GL_STACK_UNDERFLOW, "stack underflow" },
|
|
|
|
{ GL_OUT_OF_MEMORY, "out of memory" },
|
|
|
|
#ifdef GL_INVALID_FRAMEBUFFER_OPERATION_EXT
|
|
|
|
{ GL_INVALID_FRAMEBUFFER_OPERATION_EXT, "invalid framebuffer operation" },
|
|
|
|
#endif
|
|
|
|
{ ~0, NULL }
|
|
|
|
};
|
|
|
|
|
2008-05-21 09:20:33 -04:00
|
|
|
const char*
|
|
|
|
_cogl_error_string(GLenum errorCode)
|
2007-04-27 17:13:06 -04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; Errors[i].String; i++) {
|
|
|
|
if (Errors[i].Token == errorCode)
|
|
|
|
return Errors[i].String;
|
|
|
|
}
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-03-27 17:09:11 -04:00
|
|
|
CoglFuncPtr
|
|
|
|
cogl_get_proc_address (const gchar* name)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
cogl_check_extension (const gchar *name, const gchar *ext)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-05-28 14:49:34 -04:00
|
|
|
cogl_paint_init (const ClutterColor *color)
|
2007-03-27 17:09:11 -04:00
|
|
|
{
|
2007-05-01 11:26:12 -04:00
|
|
|
#if COGL_DEBUG
|
|
|
|
fprintf(stderr, "\n ============== Paint Start ================ \n");
|
|
|
|
#endif
|
|
|
|
|
2008-05-27 13:42:50 -04:00
|
|
|
cogl_wrap_glClearColorx ((color->red << 16) / 0xff,
|
|
|
|
(color->green << 16) / 0xff,
|
|
|
|
(color->blue << 16) / 0xff,
|
|
|
|
0xff);
|
2007-03-27 17:09:11 -04:00
|
|
|
|
|
|
|
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
2008-05-27 13:42:50 -04:00
|
|
|
cogl_wrap_glDisable (GL_LIGHTING);
|
|
|
|
cogl_wrap_glDisable (GL_FOG);
|
2007-03-27 17:09:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: inline most of these */
|
|
|
|
void
|
|
|
|
cogl_push_matrix (void)
|
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glPushMatrix() );
|
2007-03-27 17:09:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_pop_matrix (void)
|
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glPopMatrix() );
|
2007-03-27 17:09:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-04-27 20:37:11 -04:00
|
|
|
cogl_scale (ClutterFixed x, ClutterFixed y)
|
2007-03-27 17:09:11 -04:00
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glScalex (x, y, CFX_ONE) );
|
2007-03-27 17:09:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_translatex (ClutterFixed x, ClutterFixed y, ClutterFixed z)
|
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glTranslatex (x, y, z) );
|
2007-03-27 17:09:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_translate (gint x, gint y, gint z)
|
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glTranslatex (CLUTTER_INT_TO_FIXED(x),
|
|
|
|
CLUTTER_INT_TO_FIXED(y),
|
|
|
|
CLUTTER_INT_TO_FIXED(z)) );
|
2007-03-27 17:09:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_rotatex (ClutterFixed angle,
|
|
|
|
ClutterFixed x,
|
|
|
|
ClutterFixed y,
|
|
|
|
ClutterFixed z)
|
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glRotatex (angle,x,y,z) );
|
2007-03-27 17:09:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_rotate (gint angle, gint x, gint y, gint z)
|
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glRotatex (CLUTTER_INT_TO_FIXED(angle),
|
2007-04-27 17:13:06 -04:00
|
|
|
CLUTTER_INT_TO_FIXED(x),
|
|
|
|
CLUTTER_INT_TO_FIXED(y),
|
|
|
|
CLUTTER_INT_TO_FIXED(z)) );
|
2007-03-27 17:09:11 -04:00
|
|
|
}
|
2007-04-27 20:37:11 -04:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
static inline gboolean
|
|
|
|
cogl_toggle_flag (CoglContext *ctx,
|
|
|
|
gulong new_flags,
|
|
|
|
gulong flag,
|
|
|
|
GLenum gl_flag)
|
2007-04-27 20:37:11 -04:00
|
|
|
{
|
2008-04-25 09:37:36 -04:00
|
|
|
/* Toggles and caches a single enable flag on or off
|
|
|
|
* by comparing to current state
|
|
|
|
*/
|
|
|
|
if (new_flags & flag)
|
2007-04-27 20:37:11 -04:00
|
|
|
{
|
2008-04-25 09:37:36 -04:00
|
|
|
if (!(ctx->enable_flags & flag))
|
2007-04-27 20:37:11 -04:00
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glEnable (gl_flag) );
|
2008-04-25 09:37:36 -04:00
|
|
|
ctx->enable_flags |= flag;
|
|
|
|
return TRUE;
|
2007-04-27 20:37:11 -04:00
|
|
|
}
|
|
|
|
}
|
2008-04-25 09:37:36 -04:00
|
|
|
else if (ctx->enable_flags & flag)
|
2007-04-27 20:37:11 -04:00
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glDisable (gl_flag) );
|
2008-04-25 09:37:36 -04:00
|
|
|
ctx->enable_flags &= ~flag;
|
2007-04-27 20:37:11 -04:00
|
|
|
}
|
2008-04-25 09:37:36 -04:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-04-27 20:37:11 -04:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
static inline gboolean
|
|
|
|
cogl_toggle_client_flag (CoglContext *ctx,
|
|
|
|
gulong new_flags,
|
|
|
|
gulong flag,
|
|
|
|
GLenum gl_flag)
|
|
|
|
{
|
|
|
|
/* Toggles and caches a single client-side enable flag
|
|
|
|
* on or off by comparing to current state
|
|
|
|
*/
|
|
|
|
if (new_flags & flag)
|
2007-04-27 20:37:11 -04:00
|
|
|
{
|
2008-04-25 09:37:36 -04:00
|
|
|
if (!(ctx->enable_flags & flag))
|
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glEnableClientState (gl_flag) );
|
2008-04-25 09:37:36 -04:00
|
|
|
ctx->enable_flags |= flag;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-04-27 20:37:11 -04:00
|
|
|
}
|
2008-04-25 09:37:36 -04:00
|
|
|
else if (ctx->enable_flags & flag)
|
2007-04-27 20:37:11 -04:00
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glDisableClientState (gl_flag) );
|
2008-04-25 09:37:36 -04:00
|
|
|
ctx->enable_flags &= ~flag;
|
2007-04-27 20:37:11 -04:00
|
|
|
}
|
2008-04-25 09:37:36 -04:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-04-27 20:37:11 -04:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
void
|
|
|
|
cogl_enable (gulong flags)
|
|
|
|
{
|
|
|
|
/* This function essentially caches glEnable state() in the
|
|
|
|
* hope of lessening number GL traffic.
|
|
|
|
*/
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2008-05-19 11:02:27 -04:00
|
|
|
cogl_toggle_flag (ctx, flags,
|
|
|
|
COGL_ENABLE_BLEND,
|
|
|
|
GL_BLEND);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
|
|
|
cogl_toggle_flag (ctx, flags,
|
|
|
|
COGL_ENABLE_TEXTURE_2D,
|
|
|
|
GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
cogl_toggle_client_flag (ctx, flags,
|
|
|
|
COGL_ENABLE_VERTEX_ARRAY,
|
|
|
|
GL_VERTEX_ARRAY);
|
|
|
|
|
|
|
|
cogl_toggle_client_flag (ctx, flags,
|
|
|
|
COGL_ENABLE_TEXCOORD_ARRAY,
|
|
|
|
GL_TEXTURE_COORD_ARRAY);
|
|
|
|
|
|
|
|
cogl_toggle_client_flag (ctx, flags,
|
|
|
|
COGL_ENABLE_COLOR_ARRAY,
|
|
|
|
GL_COLOR_ARRAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
gulong
|
|
|
|
cogl_get_enable ()
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, 0);
|
|
|
|
|
|
|
|
return ctx->enable_flags;
|
2008-02-01 13:14:54 -05:00
|
|
|
}
|
2007-04-27 20:37:11 -04:00
|
|
|
|
2008-05-19 11:02:27 -04:00
|
|
|
void
|
|
|
|
cogl_blend_func (COGLenum src_factor, COGLenum dst_factor)
|
|
|
|
{
|
|
|
|
/* This function caches the blending setup in the
|
|
|
|
* hope of lessening GL traffic.
|
|
|
|
*/
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if (ctx->blend_src_factor != src_factor ||
|
|
|
|
ctx->blend_dst_factor != dst_factor)
|
|
|
|
{
|
|
|
|
glBlendFunc (src_factor, dst_factor);
|
|
|
|
ctx->blend_src_factor = src_factor;
|
|
|
|
ctx->blend_dst_factor = dst_factor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-01 13:14:54 -05:00
|
|
|
void
|
|
|
|
cogl_enable_depth_test (gboolean setting)
|
|
|
|
{
|
|
|
|
if (setting)
|
2007-04-27 20:37:11 -04:00
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
cogl_wrap_glEnable (GL_DEPTH_TEST);
|
|
|
|
cogl_wrap_glEnable (GL_ALPHA_TEST);
|
2008-02-01 13:14:54 -05:00
|
|
|
glDepthFunc (GL_LEQUAL);
|
2008-05-27 13:42:50 -04:00
|
|
|
cogl_wrap_glAlphaFunc (GL_GREATER, 0.1);
|
2007-04-27 20:37:11 -04:00
|
|
|
}
|
2008-02-01 13:14:54 -05:00
|
|
|
else
|
2007-04-27 20:37:11 -04:00
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
cogl_wrap_glDisable (GL_DEPTH_TEST);
|
|
|
|
cogl_wrap_glDisable (GL_ALPHA_TEST);
|
2007-04-27 20:37:11 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-05-28 14:49:34 -04:00
|
|
|
cogl_color (const ClutterColor *color)
|
2007-04-27 20:37:11 -04:00
|
|
|
{
|
2008-04-25 09:37:36 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2008-04-14 11:10:22 -04:00
|
|
|
#if 0 /*HAVE_GLES_COLOR4UB*/
|
|
|
|
|
|
|
|
/* NOTE: seems SDK_OGLES-1.1_LINUX_PCEMULATION_2.02.22.0756 has this call
|
|
|
|
* but is broken - see #857. Therefor disabling.
|
|
|
|
*/
|
|
|
|
|
2007-11-08 16:23:53 -05:00
|
|
|
/*
|
|
|
|
* GLES 1.1 does actually have this function, it's in the header file but
|
2007-11-15 09:45:27 -05:00
|
|
|
* missing in the reference manual (and SDK):
|
2007-11-08 16:23:53 -05:00
|
|
|
*
|
|
|
|
* http://www.khronos.org/egl/headers/1_1/gl.h
|
|
|
|
*/
|
|
|
|
GE( glColor4ub (color->red,
|
|
|
|
color->green,
|
|
|
|
color->blue,
|
|
|
|
color->alpha) );
|
2008-04-14 11:10:22 -04:00
|
|
|
|
|
|
|
|
2007-11-15 09:45:27 -05:00
|
|
|
#else
|
|
|
|
/* conversion can cause issues with picking on some gles implementations */
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glColor4x ((color->red << 16) / 0xff,
|
|
|
|
(color->green << 16) / 0xff,
|
|
|
|
(color->blue << 16) / 0xff,
|
|
|
|
(color->alpha << 16) / 0xff));
|
2007-11-15 09:45:27 -05:00
|
|
|
#endif
|
2008-04-25 09:37:36 -04:00
|
|
|
|
|
|
|
/* Store alpha for proper blending enables */
|
|
|
|
ctx->color_alpha = color->alpha;
|
2007-12-24 07:53:04 -05:00
|
|
|
}
|
|
|
|
|
2007-05-28 14:49:34 -04:00
|
|
|
void
|
2007-12-24 07:53:04 -05:00
|
|
|
cogl_clip_set (ClutterFixed x_offset,
|
|
|
|
ClutterFixed y_offset,
|
|
|
|
ClutterFixed width,
|
|
|
|
ClutterFixed height)
|
2007-05-28 14:49:34 -04:00
|
|
|
{
|
2008-04-25 09:37:36 -04:00
|
|
|
if (cogl_features_available (COGL_FEATURE_FOUR_CLIP_PLANES))
|
|
|
|
{
|
|
|
|
GLfixed eqn_left[4] = { CFX_ONE, 0, 0, -x_offset };
|
|
|
|
GLfixed eqn_right[4] = { -CFX_ONE, 0, 0, x_offset + width };
|
|
|
|
GLfixed eqn_top[4] = { 0, CFX_ONE, 0, -y_offset };
|
|
|
|
GLfixed eqn_bottom[4] = { 0, -CFX_ONE, 0, y_offset + height };
|
|
|
|
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glClipPlanex (GL_CLIP_PLANE0, eqn_left) );
|
|
|
|
GE( cogl_wrap_glClipPlanex (GL_CLIP_PLANE1, eqn_right) );
|
|
|
|
GE( cogl_wrap_glClipPlanex (GL_CLIP_PLANE2, eqn_top) );
|
|
|
|
GE( cogl_wrap_glClipPlanex (GL_CLIP_PLANE3, eqn_bottom) );
|
|
|
|
GE( cogl_wrap_glEnable (GL_CLIP_PLANE0) );
|
|
|
|
GE( cogl_wrap_glEnable (GL_CLIP_PLANE1) );
|
|
|
|
GE( cogl_wrap_glEnable (GL_CLIP_PLANE2) );
|
|
|
|
GE( cogl_wrap_glEnable (GL_CLIP_PLANE3) );
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
else if (cogl_features_available (COGL_FEATURE_STENCIL_BUFFER))
|
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glEnable (GL_STENCIL_TEST) );
|
2007-05-28 14:49:34 -04:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
GE( glClearStencil (0) );
|
|
|
|
GE( glClear (GL_STENCIL_BUFFER_BIT) );
|
2007-05-28 14:49:34 -04:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
GE( glStencilFunc (GL_NEVER, 0x1, 0x1) );
|
|
|
|
GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) );
|
2007-05-28 14:49:34 -04:00
|
|
|
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glColor4x (CFX_ONE, CFX_ONE, CFX_ONE, CFX_ONE ) );
|
2007-05-28 14:49:34 -04:00
|
|
|
|
2008-04-29 11:41:34 -04:00
|
|
|
cogl_rectanglex (x_offset, y_offset, width, height);
|
2007-12-24 07:53:04 -05:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
GE( glStencilFunc (GL_EQUAL, 0x1, 0x1) );
|
|
|
|
GE( glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP) );
|
|
|
|
}
|
2007-05-28 14:49:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_clip_unset (void)
|
|
|
|
{
|
2008-04-25 09:37:36 -04:00
|
|
|
if (cogl_features_available (COGL_FEATURE_FOUR_CLIP_PLANES))
|
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glDisable (GL_CLIP_PLANE3) );
|
|
|
|
GE( cogl_wrap_glDisable (GL_CLIP_PLANE2) );
|
|
|
|
GE( cogl_wrap_glDisable (GL_CLIP_PLANE1) );
|
|
|
|
GE( cogl_wrap_glDisable (GL_CLIP_PLANE0) );
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
else if (cogl_features_available (COGL_FEATURE_STENCIL_BUFFER))
|
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glDisable (GL_STENCIL_TEST) );
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
2007-04-27 20:37:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_alpha_func (COGLenum func,
|
|
|
|
ClutterFixed ref)
|
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glAlphaFunc (func, CLUTTER_FIXED_TO_FLOAT(ref)) );
|
2007-04-27 20:37:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fixed point implementation of the perspective function
|
|
|
|
*/
|
|
|
|
void
|
2007-06-25 09:43:13 -04:00
|
|
|
cogl_perspective (ClutterFixed fovy,
|
2007-04-27 20:37:11 -04:00
|
|
|
ClutterFixed aspect,
|
|
|
|
ClutterFixed zNear,
|
|
|
|
ClutterFixed zFar)
|
|
|
|
{
|
|
|
|
ClutterFixed xmax, ymax;
|
|
|
|
ClutterFixed x, y, c, d;
|
2007-06-25 09:43:13 -04:00
|
|
|
ClutterFixed fovy_rad_half = CFX_MUL (fovy, CFX_PI) / 360;
|
2007-04-27 20:37:11 -04:00
|
|
|
|
|
|
|
GLfixed m[16];
|
|
|
|
|
|
|
|
memset (&m[0], 0, sizeof (m));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Based on the original algorithm in perspective():
|
|
|
|
*
|
|
|
|
* 1) xmin = -xmax => xmax + xmin == 0 && xmax - xmin == 2 * xmax
|
|
|
|
* same true for y, hence: a == 0 && b == 0;
|
|
|
|
*
|
|
|
|
* 2) When working with small numbers, we can are loosing significant
|
|
|
|
* precision, hence we use clutter_qmulx() here, not the fast macro.
|
|
|
|
*/
|
2007-06-25 09:43:13 -04:00
|
|
|
ymax = clutter_qmulx (zNear, CFX_DIV (clutter_sinx (fovy_rad_half),
|
|
|
|
clutter_cosx (fovy_rad_half)));
|
2007-04-27 20:37:11 -04:00
|
|
|
xmax = clutter_qmulx (ymax, aspect);
|
|
|
|
|
|
|
|
x = CFX_DIV (zNear, xmax);
|
|
|
|
y = CFX_DIV (zNear, ymax);
|
|
|
|
c = CFX_DIV (-(zFar + zNear), ( zFar - zNear));
|
|
|
|
d = CFX_DIV (-(clutter_qmulx (2*zFar, zNear)), (zFar - zNear));
|
|
|
|
|
|
|
|
#define M(row,col) m[col*4+row]
|
|
|
|
M(0,0) = x;
|
|
|
|
M(1,1) = y;
|
|
|
|
M(2,2) = c;
|
|
|
|
M(2,3) = d;
|
|
|
|
M(3,2) = 1 + ~CFX_ONE;
|
2007-05-01 11:26:12 -04:00
|
|
|
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glMultMatrixx (m) );
|
2007-04-27 20:37:11 -04:00
|
|
|
#undef M
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-06-25 09:43:13 -04:00
|
|
|
cogl_setup_viewport (guint w,
|
|
|
|
guint h,
|
|
|
|
ClutterFixed fovy,
|
2007-04-27 20:37:11 -04:00
|
|
|
ClutterFixed aspect,
|
|
|
|
ClutterFixed z_near,
|
|
|
|
ClutterFixed z_far)
|
|
|
|
{
|
2007-05-01 16:13:15 -04:00
|
|
|
gint width = (gint) w;
|
|
|
|
gint height = (gint) h;
|
2007-05-25 08:07:24 -04:00
|
|
|
ClutterFixed z_camera;
|
|
|
|
|
2007-04-27 20:37:11 -04:00
|
|
|
GE( glViewport (0, 0, width, height) );
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glMatrixMode (GL_PROJECTION) );
|
|
|
|
GE( cogl_wrap_glLoadIdentity () );
|
2007-04-27 20:37:11 -04:00
|
|
|
|
2007-05-02 05:01:11 -04:00
|
|
|
/* For Ortho projection.
|
2008-05-27 13:42:50 -04:00
|
|
|
* cogl_wrap_glOrthox (0, width << 16, 0, height << 16, -1 << 16, 1 << 16);
|
2007-05-01 11:26:12 -04:00
|
|
|
*/
|
|
|
|
|
2007-04-27 20:37:11 -04:00
|
|
|
cogl_perspective (fovy, aspect, z_near, z_far);
|
|
|
|
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) );
|
|
|
|
GE( cogl_wrap_glLoadIdentity () );
|
2007-04-27 20:37:11 -04:00
|
|
|
|
2007-06-26 12:07:14 -04:00
|
|
|
/*
|
|
|
|
* camera distance from screen, 0.5 * tan (FOV)
|
|
|
|
*
|
|
|
|
* See comments in ../gl/cogl.c
|
|
|
|
*/
|
2007-06-29 07:54:31 -04:00
|
|
|
#define DEFAULT_Z_CAMERA 0.869f
|
2007-06-26 12:07:14 -04:00
|
|
|
z_camera = CLUTTER_FLOAT_TO_FIXED (DEFAULT_Z_CAMERA);
|
|
|
|
|
|
|
|
if (fovy != CFX_60)
|
|
|
|
{
|
|
|
|
ClutterFixed fovy_rad = CFX_MUL (fovy, CFX_PI) / 180;
|
|
|
|
|
|
|
|
z_camera = CFX_DIV (clutter_sinx (fovy_rad),
|
|
|
|
clutter_cosx (fovy_rad)) >> 1;
|
|
|
|
}
|
|
|
|
|
2007-05-28 14:49:34 -04:00
|
|
|
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glTranslatex (-1 << 15, -1 << 15, -z_camera));
|
2007-05-01 11:26:12 -04:00
|
|
|
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glScalex ( CFX_ONE / width,
|
2007-05-02 05:01:11 -04:00
|
|
|
-CFX_ONE / height,
|
2007-05-01 11:26:12 -04:00
|
|
|
CFX_ONE / width));
|
|
|
|
|
2008-05-27 13:42:50 -04:00
|
|
|
GE( cogl_wrap_glTranslatex (0, -CFX_ONE * height, 0) );
|
2007-05-16 05:08:30 -04:00
|
|
|
}
|
2007-05-01 11:26:12 -04:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
static void
|
|
|
|
_cogl_features_init ()
|
|
|
|
{
|
|
|
|
ClutterFeatureFlags flags = 0;
|
|
|
|
int stencil_bits = 0;
|
|
|
|
int max_clip_planes = 0;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
GE( glGetIntegerv (GL_STENCIL_BITS, &stencil_bits) );
|
|
|
|
if (stencil_bits > 0)
|
|
|
|
flags |= COGL_FEATURE_STENCIL_BUFFER;
|
|
|
|
|
|
|
|
GE( glGetIntegerv (GL_MAX_CLIP_PLANES, &max_clip_planes) );
|
|
|
|
if (max_clip_planes >= 4)
|
|
|
|
flags |= COGL_FEATURE_FOUR_CLIP_PLANES;
|
|
|
|
|
|
|
|
ctx->feature_flags = flags;
|
|
|
|
ctx->features_cached = TRUE;
|
|
|
|
}
|
|
|
|
|
2007-05-16 05:08:30 -04:00
|
|
|
ClutterFeatureFlags
|
|
|
|
cogl_get_features ()
|
|
|
|
{
|
2008-04-25 09:37:36 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, 0);
|
|
|
|
|
|
|
|
if (!ctx->features_cached)
|
|
|
|
_cogl_features_init ();
|
|
|
|
|
|
|
|
return ctx->feature_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
cogl_features_available (CoglFeatureFlags features)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, 0);
|
|
|
|
|
|
|
|
if (!ctx->features_cached)
|
|
|
|
_cogl_features_init ();
|
|
|
|
|
|
|
|
return (ctx->feature_flags & features) == features;
|
2007-04-27 20:37:11 -04:00
|
|
|
}
|
2007-06-12 07:42:29 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
cogl_get_modelview_matrix (ClutterFixed m[16])
|
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
cogl_wrap_glGetFixedv(GL_MODELVIEW_MATRIX, &m[0]);
|
2007-06-12 07:42:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_get_projection_matrix (ClutterFixed m[16])
|
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
cogl_wrap_glGetFixedv(GL_PROJECTION_MATRIX, &m[0]);
|
2007-06-12 07:42:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_get_viewport (ClutterFixed v[4])
|
|
|
|
{
|
2008-05-27 13:42:50 -04:00
|
|
|
cogl_wrap_glGetFixedv(GL_VIEWPORT, &v[0]);
|
2007-06-12 07:42:29 -04:00
|
|
|
}
|
2007-07-12 06:15:19 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
cogl_get_bitmasks (gint *red, gint *green, gint *blue, gint *alpha)
|
|
|
|
{
|
|
|
|
if (red)
|
2007-07-24 08:17:42 -04:00
|
|
|
GE( glGetIntegerv(GL_RED_BITS, red) );
|
2007-07-12 06:15:19 -04:00
|
|
|
if (green)
|
2007-07-24 08:17:42 -04:00
|
|
|
GE( glGetIntegerv(GL_GREEN_BITS, green) );
|
2007-07-12 06:15:19 -04:00
|
|
|
if (blue)
|
2007-07-24 08:17:42 -04:00
|
|
|
GE( glGetIntegerv(GL_BLUE_BITS, blue) );
|
2007-07-12 06:15:19 -04:00
|
|
|
if (alpha)
|
2007-07-24 08:17:42 -04:00
|
|
|
GE( glGetIntegerv(GL_ALPHA_BITS, alpha ) );
|
2007-07-12 06:15:19 -04:00
|
|
|
}
|
2007-11-21 06:55:26 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
cogl_fog_set (const ClutterColor *fog_color,
|
|
|
|
ClutterFixed density,
|
|
|
|
ClutterFixed z_near,
|
|
|
|
ClutterFixed z_far)
|
|
|
|
{
|
|
|
|
GLfixed fogColor[4];
|
|
|
|
|
|
|
|
fogColor[0] = (fog_color->red << 16) / 0xff;
|
|
|
|
fogColor[1] = (fog_color->green << 16) / 0xff;
|
|
|
|
fogColor[2] = (fog_color->blue << 16) / 0xff;
|
|
|
|
fogColor[3] = (fog_color->alpha << 16) / 0xff;
|
|
|
|
|
2008-05-27 13:42:50 -04:00
|
|
|
cogl_wrap_glEnable (GL_FOG);
|
2007-11-21 06:55:26 -05:00
|
|
|
|
2008-05-27 13:42:50 -04:00
|
|
|
cogl_wrap_glFogxv (GL_FOG_COLOR, fogColor);
|
2007-11-21 06:55:26 -05:00
|
|
|
|
2008-05-27 13:42:50 -04:00
|
|
|
cogl_wrap_glFogx (GL_FOG_MODE, GL_LINEAR);
|
2007-11-21 06:55:26 -05:00
|
|
|
glHint (GL_FOG_HINT, GL_NICEST);
|
|
|
|
|
2008-05-27 13:42:50 -04:00
|
|
|
cogl_wrap_glFogx (GL_FOG_DENSITY, (GLfixed) density);
|
|
|
|
cogl_wrap_glFogx (GL_FOG_START, (GLfixed) z_near);
|
|
|
|
cogl_wrap_glFogx (GL_FOG_END, (GLfixed) z_far);
|
2007-11-21 06:55:26 -05:00
|
|
|
}
|
2007-12-03 11:29:18 -05:00
|
|
|
|
2008-02-01 10:29:00 -05:00
|
|
|
/* Shaders, no support on regular OpenGL 1.1 */
|
|
|
|
|
2008-04-29 12:10:37 -04:00
|
|
|
CoglHandle
|
2008-01-16 05:02:56 -05:00
|
|
|
cogl_create_program (void)
|
2007-12-03 11:29:18 -05:00
|
|
|
{
|
2008-04-29 12:10:37 -04:00
|
|
|
return COGL_INVALID_HANDLE;
|
2007-12-03 11:29:18 -05:00
|
|
|
}
|
|
|
|
|
2008-04-29 12:10:37 -04:00
|
|
|
gboolean
|
|
|
|
cogl_is_program (CoglHandle handle)
|
2007-12-03 11:29:18 -05:00
|
|
|
{
|
2008-04-29 12:10:37 -04:00
|
|
|
return FALSE;
|
2007-12-03 11:29:18 -05:00
|
|
|
}
|
|
|
|
|
2008-04-29 12:10:37 -04:00
|
|
|
CoglHandle
|
|
|
|
cogl_program_ref (CoglHandle handle)
|
2007-12-03 11:29:18 -05:00
|
|
|
{
|
2008-04-29 12:10:37 -04:00
|
|
|
return COGL_INVALID_HANDLE;
|
2007-12-03 11:29:18 -05:00
|
|
|
}
|
|
|
|
|
2008-01-16 05:02:56 -05:00
|
|
|
void
|
2008-04-29 12:10:37 -04:00
|
|
|
cogl_program_unref (CoglHandle handle)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglHandle
|
|
|
|
cogl_create_shader (COGLenum shaderType)
|
|
|
|
{
|
|
|
|
return COGL_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
cogl_is_shader (CoglHandle handle)
|
2007-12-03 11:29:18 -05:00
|
|
|
{
|
2008-04-29 12:10:37 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglHandle
|
|
|
|
cogl_shader_ref (CoglHandle handle)
|
|
|
|
{
|
|
|
|
return COGL_INVALID_HANDLE;
|
2007-12-03 11:29:18 -05:00
|
|
|
}
|
|
|
|
|
2008-01-16 05:02:56 -05:00
|
|
|
void
|
2008-04-29 12:10:37 -04:00
|
|
|
cogl_shader_unref (CoglHandle handle)
|
2007-12-03 11:29:18 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-01-16 05:02:56 -05:00
|
|
|
void
|
2008-04-29 12:10:37 -04:00
|
|
|
cogl_shader_source (CoglHandle shader,
|
|
|
|
const gchar *source)
|
2007-12-03 11:29:18 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-01-16 05:02:56 -05:00
|
|
|
void
|
2008-04-29 12:10:37 -04:00
|
|
|
cogl_shader_compile (CoglHandle shader_handle)
|
2007-12-03 11:29:18 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-29 12:10:37 -04:00
|
|
|
void
|
|
|
|
cogl_program_attach_shader (CoglHandle program_handle,
|
|
|
|
CoglHandle shader_handle)
|
2007-12-03 11:29:18 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-01-16 05:02:56 -05:00
|
|
|
void
|
2008-04-29 12:10:37 -04:00
|
|
|
cogl_program_link (CoglHandle program_handle)
|
2007-12-03 11:29:18 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-01-16 05:02:56 -05:00
|
|
|
void
|
2008-04-29 12:10:37 -04:00
|
|
|
cogl_program_use (CoglHandle program_handle)
|
2007-12-03 11:29:18 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-29 12:10:37 -04:00
|
|
|
COGLint
|
|
|
|
cogl_program_get_uniform_location (CoglHandle program_handle,
|
|
|
|
const gchar *uniform_name)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-16 05:02:56 -05:00
|
|
|
void
|
2008-04-29 12:10:37 -04:00
|
|
|
cogl_shader_get_info_log (CoglHandle handle,
|
2008-01-16 05:38:05 -05:00
|
|
|
guint size,
|
|
|
|
gchar *buffer)
|
2007-12-03 11:29:18 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-01-16 05:02:56 -05:00
|
|
|
void
|
2008-04-29 12:10:37 -04:00
|
|
|
cogl_shader_get_parameteriv (CoglHandle handle,
|
2008-01-16 05:38:05 -05:00
|
|
|
COGLenum pname,
|
|
|
|
COGLint *dest)
|
2007-12-03 11:29:18 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-16 05:02:56 -05:00
|
|
|
void
|
|
|
|
cogl_program_uniform_1f (COGLint uniform_no,
|
2007-12-03 11:29:18 -05:00
|
|
|
gfloat value)
|
|
|
|
{
|
|
|
|
}
|