[cogl-fixed] Implement the CoglFixed fundamental GType
The type machinery for CoglFixed should be implemented by COGL itself, now that COGL exports the GType of its types. This allows moving most of what ClutterFixed did directly to CoglFixed where it belongs.
This commit is contained in:
parent
198dcef728
commit
84229fa13c
44
cogl-types.h
44
cogl-types.h
@ -1,4 +1,5 @@
|
||||
/* cogl-types.h: Shared COGL types
|
||||
*
|
||||
* This file is part of Clutter
|
||||
*
|
||||
* Copyright (C) 2008 Intel Corporation.
|
||||
@ -6,7 +7,7 @@
|
||||
* 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.
|
||||
* version 2.1 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
|
||||
@ -73,6 +74,9 @@ typedef void (* CoglFuncPtr) (void);
|
||||
*/
|
||||
typedef gint32 CoglFixed;
|
||||
|
||||
#define COGL_TYPE_FIXED (cogl_fixed_get_type ())
|
||||
GType cogl_fixed_get_type (void) G_GNUC_CONST;
|
||||
|
||||
/**
|
||||
* CoglAngle:
|
||||
*
|
||||
@ -307,6 +311,44 @@ typedef enum {
|
||||
#define COGL_TYPE_TEXTURE_FLAGS (cogl_texture_flags_get_type ())
|
||||
GType cogl_texture_flags_get_type (void) G_GNUC_CONST;
|
||||
|
||||
/**
|
||||
* CoglFogMode:
|
||||
* @COGL_FOG_MODE_LINEAR: Calculates the fog blend factor as:
|
||||
* |[
|
||||
* f = end - eye_distance / end - start
|
||||
* ]|
|
||||
* @COGL_FOG_MODE_EXPONENTIAL: Calculates the fog blend factor as:
|
||||
* |[
|
||||
* f = e ^ -(density * eye_distance)
|
||||
* ]|
|
||||
* @COGL_FOG_MODE_EXPONENTIAL_SQUARED: Calculates the fog blend factor as:
|
||||
* |[
|
||||
* f = e ^ -(density * eye_distance)^2
|
||||
* ]|
|
||||
*
|
||||
* The fog mode determines the equation used to calculate the fogging blend
|
||||
* factor while fogging is enabled. The simplest %COGL_FOG_MODE_LINEAR mode
|
||||
* determines f as:
|
||||
*
|
||||
* |[
|
||||
* f = end - eye_distance / end - start
|
||||
* ]|
|
||||
*
|
||||
* Where eye_distance is the distance of the current fragment in eye
|
||||
* coordinates from the origin.
|
||||
*
|
||||
* Since: 1.0
|
||||
*/
|
||||
typedef enum _CoglFogMode
|
||||
{
|
||||
COGL_FOG_MODE_LINEAR,
|
||||
COGL_FOG_MODE_EXPONENTIAL,
|
||||
COGL_FOG_MODE_EXPONENTIAL_SQUARED
|
||||
} CoglFogMode;
|
||||
|
||||
#define COGL_TYPE_FOG_MODE (cogl_fog_mode_get_type ())
|
||||
GType cogl_fog_mode_get_type (void) G_GNUC_CONST;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __COGL_TYPES_H__ */
|
||||
|
33
cogl.h.in
33
cogl.h.in
@ -331,37 +331,6 @@ void cogl_enable_depth_test (gboolean setting);
|
||||
*/
|
||||
void cogl_enable_backface_culling (gboolean setting);
|
||||
|
||||
/**
|
||||
* CoglFogMode:
|
||||
* @COGL_FOG_MODE_LINEAR: Calculates the fog blend factor as:
|
||||
* <programlisting>
|
||||
* f = end - eye_distance / end - start
|
||||
* </programlisting>
|
||||
* @COGL_FOG_MODE_EXPONENTIAL: Calculates the fog blend factor as:
|
||||
* <programlisting>
|
||||
* f = e ^ -(density * eye_distance)
|
||||
* </programlisting>
|
||||
* @COGL_FOG_MODE_EXPONENTIAL_SQUARED: Calculates the fog blend factor as:
|
||||
* <programlisting>
|
||||
* f = e ^ -(density * eye_distance)^2
|
||||
* </programlisting>
|
||||
*
|
||||
* The fog mode determines the equation used to calculate the fogging blend
|
||||
* factor while fogging is enabled. The simplest COGL_FOG_MODE_LINEAR mode
|
||||
* determines f as:
|
||||
* <programlisting>
|
||||
* f = end - eye_distance / end - start
|
||||
* </programlisting>
|
||||
* Where eye_distance is the distance of the current fragment in eye
|
||||
* coordinates from the origin.
|
||||
*/
|
||||
typedef enum _CoglFogMode
|
||||
{
|
||||
COGL_FOG_MODE_LINEAR,
|
||||
COGL_FOG_MODE_EXPONENTIAL,
|
||||
COGL_FOG_MODE_EXPONENTIAL_SQUARED,
|
||||
} CoglFogMode;
|
||||
|
||||
/**
|
||||
* cogl_set_fog:
|
||||
* @fog_color: The color of the fog
|
||||
@ -594,8 +563,6 @@ void cogl_clip_stack_save (void);
|
||||
*/
|
||||
void cogl_clip_stack_restore (void);
|
||||
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#undef __COGL_H_INSIDE__
|
||||
|
@ -3,14 +3,16 @@
|
||||
*
|
||||
* A basic GL/GLES Abstraction/Utility Layer
|
||||
*
|
||||
* Authored By Matthew Allum <mallum@openedhand.com>
|
||||
* Authored By: Matthew Allum <mallum@openedhand.com>
|
||||
* Emmanuele Bassi <ebassi@linux.intel.com>
|
||||
*
|
||||
* Copyright (C) 2007 OpenedHand
|
||||
* Copyright (C) 2007, 2008 OpenedHand
|
||||
* Copyright (C) 2009 Intel Corp.
|
||||
*
|
||||
* 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.
|
||||
* version 2.1 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
|
||||
@ -18,17 +20,19 @@
|
||||
* 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.
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <gobject/gvaluecollector.h>
|
||||
|
||||
#include "cogl.h"
|
||||
|
||||
#include "cogl-fixed.h"
|
||||
#include "cogl-internal.h"
|
||||
#include "cogl-material.h"
|
||||
#include "cogl-offscreen.h"
|
||||
@ -224,3 +228,173 @@ cogl_texture_flags_get_type (void)
|
||||
|
||||
return gtype;
|
||||
}
|
||||
|
||||
GType
|
||||
cogl_fog_mode_get_type (void)
|
||||
{
|
||||
static GType gtype = 0;
|
||||
|
||||
if (G_UNLIKELY (gtype == 0))
|
||||
{
|
||||
static const GEnumValue values[] = {
|
||||
{ COGL_FOG_MODE_LINEAR, "COGL_FOG_MODE_LINEAR", "linear" },
|
||||
{ COGL_FOG_MODE_EXPONENTIAL, "COGL_FOG_MODE_EXPONENTIAL", "exponential" },
|
||||
{ COGL_FOG_MODE_EXPONENTIAL_SQUARED, "COGL_FOG_MODE_EXPONENTIAL_SQUARED", "exponential-squared" },
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
|
||||
gtype =
|
||||
g_enum_register_static (g_intern_static_string ("CoglFogMode"),
|
||||
values);
|
||||
}
|
||||
|
||||
return gtype;
|
||||
}
|
||||
|
||||
/*
|
||||
* CoglFixed
|
||||
*/
|
||||
|
||||
static GTypeInfo _info = {
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static GTypeFundamentalInfo _finfo = { 0, };
|
||||
|
||||
static void
|
||||
cogl_value_init_fixed (GValue *value)
|
||||
{
|
||||
value->data[0].v_int = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
cogl_value_copy_fixed (const GValue *src,
|
||||
GValue *dest)
|
||||
{
|
||||
dest->data[0].v_int = src->data[0].v_int;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
cogl_value_collect_fixed (GValue *value,
|
||||
guint n_collect_values,
|
||||
GTypeCValue *collect_values,
|
||||
guint collect_flags)
|
||||
{
|
||||
value->data[0].v_int = collect_values[0].v_int;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
cogl_value_lcopy_fixed (const GValue *value,
|
||||
guint n_collect_values,
|
||||
GTypeCValue *collect_values,
|
||||
guint collect_flags)
|
||||
{
|
||||
gint32 *fixed_p = collect_values[0].v_pointer;
|
||||
|
||||
if (!fixed_p)
|
||||
return g_strdup_printf ("value location for `%s' passed as NULL",
|
||||
G_VALUE_TYPE_NAME (value));
|
||||
|
||||
*fixed_p = value->data[0].v_int;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
cogl_value_transform_fixed_int (const GValue *src,
|
||||
GValue *dest)
|
||||
{
|
||||
dest->data[0].v_int = COGL_FIXED_TO_INT (src->data[0].v_int);
|
||||
}
|
||||
|
||||
static void
|
||||
cogl_value_transform_fixed_double (const GValue *src,
|
||||
GValue *dest)
|
||||
{
|
||||
dest->data[0].v_double = COGL_FIXED_TO_DOUBLE (src->data[0].v_int);
|
||||
}
|
||||
|
||||
static void
|
||||
cogl_value_transform_fixed_float (const GValue *src,
|
||||
GValue *dest)
|
||||
{
|
||||
dest->data[0].v_float = COGL_FIXED_TO_FLOAT (src->data[0].v_int);
|
||||
}
|
||||
|
||||
static void
|
||||
cogl_value_transform_int_fixed (const GValue *src,
|
||||
GValue *dest)
|
||||
{
|
||||
dest->data[0].v_int = COGL_FIXED_FROM_INT (src->data[0].v_int);
|
||||
}
|
||||
|
||||
static void
|
||||
cogl_value_transform_double_fixed (const GValue *src,
|
||||
GValue *dest)
|
||||
{
|
||||
dest->data[0].v_int = COGL_FIXED_FROM_DOUBLE (src->data[0].v_double);
|
||||
}
|
||||
|
||||
static void
|
||||
cogl_value_transform_float_fixed (const GValue *src,
|
||||
GValue *dest)
|
||||
{
|
||||
dest->data[0].v_int = COGL_FIXED_FROM_FLOAT (src->data[0].v_float);
|
||||
}
|
||||
|
||||
|
||||
static const GTypeValueTable _cogl_fixed_value_table = {
|
||||
cogl_value_init_fixed,
|
||||
NULL,
|
||||
cogl_value_copy_fixed,
|
||||
NULL,
|
||||
"i",
|
||||
cogl_value_collect_fixed,
|
||||
"p",
|
||||
cogl_value_lcopy_fixed
|
||||
};
|
||||
|
||||
GType
|
||||
cogl_fixed_get_type (void)
|
||||
{
|
||||
static GType _cogl_fixed_type = 0;
|
||||
|
||||
if (G_UNLIKELY (_cogl_fixed_type == 0))
|
||||
{
|
||||
_info.value_table = & _cogl_fixed_value_table;
|
||||
_cogl_fixed_type =
|
||||
g_type_register_fundamental (g_type_fundamental_next (),
|
||||
g_intern_static_string ("CoglFixed"),
|
||||
&_info, &_finfo, 0);
|
||||
|
||||
g_value_register_transform_func (_cogl_fixed_type, G_TYPE_INT,
|
||||
cogl_value_transform_fixed_int);
|
||||
g_value_register_transform_func (G_TYPE_INT, _cogl_fixed_type,
|
||||
cogl_value_transform_int_fixed);
|
||||
|
||||
g_value_register_transform_func (_cogl_fixed_type, G_TYPE_FLOAT,
|
||||
cogl_value_transform_fixed_float);
|
||||
g_value_register_transform_func (G_TYPE_FLOAT, _cogl_fixed_type,
|
||||
|
||||
cogl_value_transform_float_fixed);
|
||||
g_value_register_transform_func (_cogl_fixed_type, G_TYPE_DOUBLE,
|
||||
cogl_value_transform_fixed_double);
|
||||
g_value_register_transform_func (G_TYPE_DOUBLE, _cogl_fixed_type,
|
||||
cogl_value_transform_double_fixed);
|
||||
}
|
||||
|
||||
return _cogl_fixed_type;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user