PROP_PERSPECTIVE,
PROP_TITLE,
PROP_USER_RESIZE,
- PROP_USE_FOG
+ PROP_USE_FOG,
+ PROP_FOG
};
enum
if (priv->use_fog)
{
+ /* we only expose the linear progression of the fog in
+ * the ClutterStage API, and that ignores the fog density.
+ * thus, we pass 1.0 as the density parameter
+ */
cogl_set_fog (&stage_color,
COGL_FOG_MODE_LINEAR,
- priv->fog.density,
+ 1.0,
priv->fog.z_near,
priv->fog.z_far);
}
case PROP_COLOR:
clutter_stage_set_color (stage, clutter_value_get_color (value));
break;
+
case PROP_OFFSCREEN:
if (priv->is_offscreen == g_value_get_boolean (value))
return;
else
priv->is_offscreen = g_value_get_boolean (value);
break;
+
case PROP_FULLSCREEN:
if (g_value_get_boolean (value))
clutter_stage_fullscreen (stage);
else
clutter_stage_unfullscreen (stage);
break;
+
case PROP_CURSOR_VISIBLE:
if (g_value_get_boolean (value))
clutter_stage_show_cursor (stage);
else
clutter_stage_hide_cursor (stage);
break;
+
case PROP_PERSPECTIVE:
- clutter_stage_set_perspectivex (stage, g_value_get_boxed (value));
+ clutter_stage_set_perspective (stage, g_value_get_boxed (value));
break;
+
case PROP_TITLE:
clutter_stage_set_title (stage, g_value_get_string (value));
break;
+
case PROP_USER_RESIZE:
clutter_stage_set_user_resizable (stage, g_value_get_boolean (value));
break;
+
case PROP_USE_FOG:
clutter_stage_set_use_fog (stage, g_value_get_boolean (value));
break;
+
+ case PROP_FOG:
+ clutter_stage_set_fog (stage, g_value_get_boxed (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
static void
-clutter_stage_get_property (GObject *object,
+clutter_stage_get_property (GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
- ClutterStage *stage;
- ClutterStagePrivate *priv;
- ClutterPerspective perspective;
-
- stage = CLUTTER_STAGE(object);
- priv = stage->priv;
+ ClutterStagePrivate *priv = CLUTTER_STAGE (gobject)->priv;
switch (prop_id)
{
case PROP_COLOR:
clutter_value_set_color (value, &priv->color);
break;
+
case PROP_OFFSCREEN:
g_value_set_boolean (value, priv->is_offscreen);
break;
+
case PROP_FULLSCREEN:
g_value_set_boolean (value, priv->is_fullscreen);
break;
+
case PROP_CURSOR_VISIBLE:
g_value_set_boolean (value, priv->is_cursor_visible);
break;
+
case PROP_PERSPECTIVE:
- clutter_stage_get_perspectivex (stage, &perspective);
- g_value_set_boxed (value, &perspective);
+ g_value_set_boxed (value, &priv->perspective);
break;
+
case PROP_TITLE:
g_value_set_string (value, priv->title);
break;
+
case PROP_USER_RESIZE:
g_value_set_boolean (value, priv->is_user_resizable);
break;
+
case PROP_USE_FOG:
g_value_set_boolean (value, priv->use_fog);
break;
+
+ case PROP_FOG:
+ g_value_set_boxed (value, &priv->fog);
+ break;
+
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
}
}
"Whether to enable depth cueing",
FALSE,
CLUTTER_PARAM_READWRITE));
+ /**
+ * ClutterStage:fog:
+ *
+ * The settings for the GL "fog", used only if #ClutterStage:use-fog
+ * is set to %TRUE
+ *
+ * Since: 1.0
+ */
+ pspec = g_param_spec_boxed ("fog",
+ "Fog",
+ "Settings for the depth cueing",
+ CLUTTER_TYPE_FOG,
+ CLUTTER_PARAM_READWRITE);
+ g_object_class_install_property (gobject_class, PROP_FOG, pspec);
/**
* ClutterStage::fullscreen
priv->perspective.fovy = 60.0; /* 60 Degrees */
priv->perspective.aspect = 1.0;
- priv->perspective.z_near = CLUTTER_FLOAT_TO_FIXED (0.1);
- priv->perspective.z_far = CLUTTER_FLOAT_TO_FIXED (100.0);
+ priv->perspective.z_near = 0.1;
+ priv->perspective.z_far = 100.0;
/* depth cueing */
- priv->fog.density = CLUTTER_FLOAT_TO_FIXED (0.1);
- priv->fog.z_near = CLUTTER_FLOAT_TO_FIXED (1.0);
- priv->fog.z_far = CLUTTER_FLOAT_TO_FIXED (2.0);
+ priv->fog.z_near = 1.0;
+ priv->fog.z_far = 2.0;
clutter_actor_set_reactive (CLUTTER_ACTOR (self), TRUE);
clutter_stage_set_key_focus (self, NULL);
}
/**
- * clutter_stage_set_color
+ * clutter_stage_set_color:
* @stage: A #ClutterStage
* @color: A #ClutterColor
*
- * Set the stage color.
- **/
+ * Sets the stage color.
+ */
void
clutter_stage_set_color (ClutterStage *stage,
const ClutterColor *color)
}
/**
- * clutter_stage_get_color
+ * clutter_stage_get_color:
* @stage: A #ClutterStage
* @color: return location for a #ClutterColor
*
}
/**
- * clutter_stage_set_perspectivex
+ * clutter_stage_set_perspective:
* @stage: A #ClutterStage
* @perspective: A #ClutterPerspective
*
- * Set the stage perspective. This is the fixed point version of
- * clutter_stage_set_perspective().
- **/
+ * Sets the stage perspective.
+ */
void
-clutter_stage_set_perspectivex (ClutterStage *stage,
- ClutterPerspective *perspective)
+clutter_stage_set_perspective (ClutterStage *stage,
+ ClutterPerspective *perspective)
{
ClutterStagePrivate *priv;
}
/**
- * clutter_stage_get_perspectivex
+ * clutter_stage_get_perspective:
* @stage: A #ClutterStage
* @perspective: return location for a #ClutterPerspective
*
- * Retrieves the stage perspective. This is the fixed point version of
- * clutter_stage_get_perspective().
- */
-void
-clutter_stage_get_perspectivex (ClutterStage *stage,
- ClutterPerspective *perspective)
-{
- g_return_if_fail (CLUTTER_IS_STAGE (stage));
- g_return_if_fail (perspective != NULL);
-
- *perspective = stage->priv->perspective;
-}
-
-/**
- * clutter_stage_set_perspective
- * @stage: A #ClutterStage
- * @fovy: the field of view angle, in degrees, in the y direction
- * @aspect: the aspect ratio that determines the field of view in the x
- * direction. The aspect ratio is the ratio of x (width) to y (height)
- * @z_near: the distance from the viewer to the near clipping
- * plane (always positive)
- * @z_far: the distance from the viewer to the far clipping
- * plane (always positive)
- *
- * Sets the stage perspective.
- *
- * Since: 0.4
- */
-void
-clutter_stage_set_perspective (ClutterStage *stage,
- gfloat fovy,
- gfloat aspect,
- gfloat z_near,
- gfloat z_far)
-{
- ClutterStagePrivate *priv;
-
- g_return_if_fail (CLUTTER_IS_STAGE (stage));
-
- priv = stage->priv;
-
- priv->perspective.fovy = CLUTTER_FLOAT_TO_FIXED (fovy);
- priv->perspective.aspect = CLUTTER_FLOAT_TO_FIXED (aspect);
- priv->perspective.z_near = CLUTTER_FLOAT_TO_FIXED (z_near);
- priv->perspective.z_far = CLUTTER_FLOAT_TO_FIXED (z_far);
-
- /* this will cause the viewport to be reset; see
- * clutter_maybe_setup_viewport() inside clutter-main.c
- */
- CLUTTER_SET_PRIVATE_FLAGS (stage, CLUTTER_ACTOR_SYNC_MATRICES);
-}
-
-/**
- * clutter_stage_get_perspective
- * @stage: A #ClutterStage
- * @fovy: return location for the field of view, in degrees, or %NULL
- * @aspect: return location for the aspect ratio, or %NULL
- * @z_near: return location for the distance of the viewer from the
- * near clipping plane, or %NULL
- * @z_far: return location for the distance of the viewer from the
- * far clipping plane, or %NULL
- *
* Retrieves the stage perspective.
- *
- * Since: 0.4
*/
void
clutter_stage_get_perspective (ClutterStage *stage,
- gfloat *fovy,
- gfloat *aspect,
- gfloat *z_near,
- gfloat *z_far)
+ ClutterPerspective *perspective)
{
- ClutterStagePrivate *priv;
-
g_return_if_fail (CLUTTER_IS_STAGE (stage));
+ g_return_if_fail (perspective != NULL);
- priv = stage->priv;
-
- if (fovy)
- *fovy = CLUTTER_FIXED_TO_FLOAT (priv->perspective.fovy);
-
- if (aspect)
- *aspect = CLUTTER_FIXED_TO_FLOAT (priv->perspective.aspect);
-
- if (z_near)
- *z_near = CLUTTER_FIXED_TO_FLOAT (priv->perspective.z_near);
-
- if (z_far)
- *z_far = CLUTTER_FIXED_TO_FLOAT (priv->perspective.z_far);
+ *perspective = stage->priv->perspective;
}
/**
}
/**
- * clutter_stage_get_fog:
- * @stage: a #ClutterStage
- * @density: return location for the intensity dampening
- * @z_near: return location for the starting point of the depth cueing
- * @z_far: return location for the ending point of the depth cueing
- *
- * Retrieves the settings used by the GL fog to create the
- * depth cueing effect on the @stage.
- *
- * Since: 0.6
- */
-void
-clutter_stage_get_fog (ClutterStage *stage,
- gdouble *density,
- gdouble *z_near,
- gdouble *z_far)
-{
- ClutterStagePrivate *priv;
-
- g_return_if_fail (CLUTTER_IS_STAGE (stage));
-
- priv = stage->priv;
-
- if (density)
- *density = CLUTTER_FIXED_TO_FLOAT (priv->fog.density);
- if (z_near)
- *z_near = CLUTTER_FIXED_TO_FLOAT (priv->fog.z_near);
- if (z_far)
- *z_far = CLUTTER_FIXED_TO_FLOAT (priv->fog.z_far);
-}
-
-/**
* clutter_stage_set_fog:
* @stage: the #ClutterStage
- * @density: density of the intensity dampening
- * @z_near: starting point of the depth cueing
- * @z_far: ending point of the depth cueing
- *
- * Sets the GL fog settings used to create the depth cueing effect
- * on the @stage.
- *
- * If the actors are all near the view point you will need a higher @density
- * and a smaller interval between @z_near and @z_far. On the other hand, if
- * actors are placed far away from the view point you will need a lower
- * @density but a bigger interval between @z_near and @z_far.
- *
- * Since: 0.6
- */
-void
-clutter_stage_set_fog (ClutterStage *stage,
- gdouble density,
- gdouble z_near,
- gdouble z_far)
-{
- ClutterStagePrivate *priv;
-
- g_return_if_fail (CLUTTER_IS_STAGE (stage));
-
- priv = stage->priv;
-
- priv->fog.density = CLUTTER_FLOAT_TO_FIXED (density);
- priv->fog.z_near = CLUTTER_FLOAT_TO_FIXED (z_near);
- priv->fog.z_far = CLUTTER_FLOAT_TO_FIXED (z_far);
-
- if (priv->use_fog && CLUTTER_ACTOR_IS_VISIBLE (stage))
- clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
-}
-
-/**
- * clutter_stage_set_fogx:
- * @stage: the #ClutterStage
* @fog: a #ClutterFog structure
*
- * Sets the depth cueing settings for the @stage. This is the fixed point
- * version of clutter_stage_set_fog().
+ * Sets the fog (also known as "depth cueing") settings for the @stage.
+ *
+ * A #ClutterStage will only use a linear fog progression, which
+ * depends solely on the distance from the viewer. The cogl_set_fog()
+ * function in COGL exposes more of the underlying implementation,
+ * and allows changing the for progression function. It can be directly
+ * used by disabling the #ClutterStage:use-fog property and connecting
+ * a signal handler to the #ClutterActor::paint signal on the @stage,
+ * like:
+ *
+ * |[
+ * clutter_stage_set_use_fog (stage, FALSE);
+ * g_signal_connect (stage, "paint", G_CALLBACK (on_stage_paint), NULL);
+ * ]|
+ *
+ * The paint signal handler will call cogl_set_fog() with the
+ * desired settings:
+ *
+ * |[
+ * static void
+ * on_stage_paint (ClutterActor *actor)
+ * {
+ * ClutterColor stage_color = { 0, };
+ * CoglColor fog_color = { 0, };
+ *
+ * /* set the fog color to the stage background color */
+ * clutter_stage_get_color (CLUTTER_STAGE (actor), &stage_color);
+ * cogl_color_set_from_4ub (&fog_color,
+ * stage_color.red,
+ * stage_color.green,
+ * stage_color.blue,
+ * stage_color.alpha);
+ *
+ * /* enable fog */
+ * cogl_set_fog (&fog_color,
+ * COGL_FOG_MODE_EXPONENTIAL, /* mode */
+ * 0.5, /* density */
+ * 5.0, 30.0); /* z_near and z_far */
+ * }
+ * ]|
*
* Since: 0.6
*/
void
-clutter_stage_set_fogx (ClutterStage *stage,
- ClutterFog *fog)
+clutter_stage_set_fog (ClutterStage *stage,
+ ClutterFog *fog)
{
ClutterStagePrivate *priv;
}
/**
- * clutter_stage_get_fogx:
+ * clutter_stage_get_fog:
* @stage: the #ClutterStage
* @fog: return location for a #ClutterFog structure
*
- * Retrieves the current depth cueing settings from the stage. This is the
- * fixed point version of clutter_stage_get_fog().
+ * Retrieves the current depth cueing settings from the stage.
*
* Since: 0.6
*/
void
-clutter_stage_get_fogx (ClutterStage *stage,
+clutter_stage_get_fog (ClutterStage *stage,
ClutterFog *fog)
{
g_return_if_fail (CLUTTER_IS_STAGE (stage));
/*** Perspective boxed type ******/
-static ClutterPerspective *
-clutter_perspective_copy (const ClutterPerspective *perspective)
+static gpointer
+clutter_perspective_copy (gpointer data)
{
- ClutterPerspective *result;
-
- g_return_val_if_fail (perspective != NULL, NULL);
+ if (G_LIKELY (data))
+ return g_slice_dup (ClutterPerspective, data);
- result = g_slice_new (ClutterPerspective);
- *result = *perspective;
-
- return result;
+ return NULL;
}
static void
-clutter_perspective_free (ClutterPerspective *perspective)
+clutter_perspective_free (gpointer data)
{
- if (G_LIKELY (perspective))
- g_slice_free (ClutterPerspective, perspective);
+ if (G_LIKELY (data))
+ g_slice_free (ClutterPerspective, data);
}
GType
static GType our_type = 0;
if (!our_type)
- our_type =
- g_boxed_type_register_static (I_("ClutterPerspective"),
- (GBoxedCopyFunc) clutter_perspective_copy,
- (GBoxedFreeFunc) clutter_perspective_free);
+ our_type = g_boxed_type_register_static (I_("ClutterPerspective"),
+ clutter_perspective_copy,
+ clutter_perspective_free);
return our_type;
}
-static ClutterFog *
-clutter_fog_copy (const ClutterFog *fog)
+static gpointer
+clutter_fog_copy (gpointer data)
{
- ClutterFog *copy;
-
- g_return_val_if_fail (fog != NULL, NULL);
-
- copy = g_slice_new0 (ClutterFog);
- *copy = *fog;
+ if (G_LIKELY (data))
+ return g_slice_dup (ClutterFog, data);
- return copy;
+ return NULL;
}
static void
-clutter_fog_free (ClutterFog *fog)
+clutter_fog_free (gpointer data)
{
- if (G_LIKELY (fog))
- g_slice_free (ClutterFog, fog);
+ if (G_LIKELY (data))
+ g_slice_free (ClutterFog, data);
}
GType
static GType our_type = 0;
if (G_UNLIKELY (our_type == 0))
- our_type =
- g_boxed_type_register_static (I_("ClutterFog"),
- (GBoxedCopyFunc) clutter_fog_copy,
- (GBoxedFreeFunc) clutter_fog_free);
+ our_type = g_boxed_type_register_static (I_("ClutterFog"),
+ clutter_fog_copy,
+ clutter_fog_free);
return our_type;
}
{
ClutterTexturePrivate *priv = CLUTTER_TEXTURE (self)->priv;
ClutterVertex verts[4];
- ClutterFixed viewport[4];
+ gfloat viewport[4];
ClutterUnit x_min, x_max, y_min, y_max;
- ClutterFixed tx_min, tx_max, ty_min, ty_max;
+ gfloat tx_min, tx_max, ty_min, ty_max;
+ gfloat tan_angle, near_size;
ClutterPerspective perspective;
ClutterStage *stage;
- ClutterFixed tan_angle, near_size;
int i;
/* Get the bounding rectangle of the source as drawn in screen
}
stage = CLUTTER_STAGE (clutter_actor_get_stage (self));
- clutter_stage_get_perspectivex (stage, &perspective);
+ clutter_stage_get_perspective (stage, &perspective);
/* Convert the coordinates back to [-1,1] range */
cogl_get_viewport (viewport);
- tx_min = CLUTTER_FIXED_DIV (CLUTTER_UNITS_TO_FIXED (x_min), viewport[2])
+ tx_min = (CLUTTER_UNITS_TO_FLOAT (x_min) / viewport[2])
* 2 - 1.0;
- tx_max = CLUTTER_FIXED_DIV (CLUTTER_UNITS_TO_FIXED (x_max), viewport[2])
+ tx_max = (CLUTTER_UNITS_TO_FLOAT (x_max) / viewport[2])
* 2 - 1.0;
- ty_min = CLUTTER_FIXED_DIV (CLUTTER_UNITS_TO_FIXED (y_min), viewport[3])
+ ty_min = (CLUTTER_UNITS_TO_FLOAT (y_min) / viewport[3])
* 2 - 1.0;
- ty_max = CLUTTER_FIXED_DIV (CLUTTER_UNITS_TO_FIXED (y_max), viewport[3])
+ ty_max = (CLUTTER_UNITS_TO_FLOAT (y_max) / viewport[3])
* 2 - 1.0;
/* Set up a projection matrix so that the actor will be projected as
if it was drawn at its original location */
- tan_angle = tanf ((perspective.fovy / 2) * (G_PI/180.0));
- near_size = CLUTTER_FIXED_MUL (perspective.z_near, tan_angle);
-
- cogl_frustum (CLUTTER_FIXED_MUL (tx_min, near_size),
- CLUTTER_FIXED_MUL (tx_max, near_size),
- CLUTTER_FIXED_MUL (-ty_min, near_size),
- CLUTTER_FIXED_MUL (-ty_max, near_size),
- perspective.z_near, perspective.z_far);
+ tan_angle = tanf ((perspective.fovy / 2) * (G_PI / 180.0));
+ near_size = perspective.z_near * tan_angle;
+
+ cogl_frustum ((tx_min * near_size),
+ (tx_max * near_size),
+ (-ty_min * near_size),
+ (-ty_max * near_size),
+ perspective.z_near,
+ perspective.z_far);
}
static void
ClutterTexturePrivate *priv = texture->priv;
gint x_1, y_1, x_2, y_2;
CoglColor transparent_col;
- ClutterFixed t_w, t_h;
+ gfloat t_w, t_h;
guint8 paint_opacity = clutter_actor_get_paint_opacity (self);
- if (clutter_actor_get_paint_opacity (self) == 0)
+ if (paint_opacity == 0)
{
/* Bail early if painting the actor would be a no-op, custom actors that
* might cause a lot of work/state changes should all do this.
guint stage_width, stage_height;
ClutterActor *source_parent;
- clutter_stage_get_perspectivex (CLUTTER_STAGE (stage), &perspective);
+ clutter_stage_get_perspective (CLUTTER_STAGE (stage), &perspective);
clutter_actor_get_size (stage, &stage_width, &stage_height);
/* Use below to set the modelview matrix as if the viewport
clutter_actor_get_opacity (self));
if (priv->repeat_x && priv->width > 0)
- t_w = CLUTTER_FIXED_DIV ((float)(x_2 - x_1),
- (float)(priv->width));
+ t_w = (float) (x_2 - x_1) / (float) (priv->width);
else
t_w = 1.0;
if (priv->repeat_y && priv->height > 0)
- t_h = CLUTTER_FIXED_DIV ((float)(y_2 - y_1),
- (float)(priv->height));
+ t_h = (float) (y_2 - y_1) / (float) (priv->height);
else
t_h = 1.0;