mirror of
https://github.com/brl/mutter.git
synced 2024-11-29 19:40:43 -05:00
[stage] Coalesce fog and perspective API
The fog and perspective API is currently split in two parts: - the floating point version, using values - the fixed point version, using structures The relative properties are using the structure types, since they are meant to set multiple values at the same time. Instead of using bare values, the whole API should be coalesced into two simple calls using structures to match the GObject properties. Thus: clutter_stage_set_fog (ClutterStage*, const ClutterFog*) clutter_stage_get_fog (ClutterStage*, ClutterFog*) clutter_stage_set_perspective (ClutterStage*, const ClutterPerspective*) clutter_stage_get_perspective (ClutterStage*, ClutterPerspective*) Which supercedes the fixed point and floating point variants. More importantly, both ClutterFog and ClutterPerspective should using floating point values, since that's what get passed to COGL anyway. ClutterFog should also drop the "density" member, since ClutterStage only allows linear fog; non-linear fog distribution can be achieved using a signal handler and calling cogl_set_fog() directly; this keeps the API compact yet extensible. Finally, there is no ClutterStage:fog so it should be added.
This commit is contained in:
parent
628e54fa9f
commit
52811b240f
@ -156,7 +156,7 @@ _clutter_stage_maybe_setup_viewport (ClutterStage *stage)
|
|||||||
guint width, height;
|
guint width, height;
|
||||||
|
|
||||||
clutter_actor_get_size (CLUTTER_ACTOR (stage), &width, &height);
|
clutter_actor_get_size (CLUTTER_ACTOR (stage), &width, &height);
|
||||||
clutter_stage_get_perspectivex (stage, &perspective);
|
clutter_stage_get_perspective (stage, &perspective);
|
||||||
|
|
||||||
CLUTTER_NOTE (PAINT, "Setting up the viewport");
|
CLUTTER_NOTE (PAINT, "Setting up the viewport");
|
||||||
|
|
||||||
|
@ -106,7 +106,8 @@ enum
|
|||||||
PROP_PERSPECTIVE,
|
PROP_PERSPECTIVE,
|
||||||
PROP_TITLE,
|
PROP_TITLE,
|
||||||
PROP_USER_RESIZE,
|
PROP_USER_RESIZE,
|
||||||
PROP_USE_FOG
|
PROP_USE_FOG,
|
||||||
|
PROP_FOG
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
@ -226,9 +227,13 @@ clutter_stage_paint (ClutterActor *self)
|
|||||||
|
|
||||||
if (priv->use_fog)
|
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_set_fog (&stage_color,
|
||||||
COGL_FOG_MODE_LINEAR,
|
COGL_FOG_MODE_LINEAR,
|
||||||
priv->fog.density,
|
1.0,
|
||||||
priv->fog.z_near,
|
priv->fog.z_near,
|
||||||
priv->fog.z_far);
|
priv->fog.z_far);
|
||||||
}
|
}
|
||||||
@ -400,6 +405,7 @@ clutter_stage_set_property (GObject *object,
|
|||||||
case PROP_COLOR:
|
case PROP_COLOR:
|
||||||
clutter_stage_set_color (stage, clutter_value_get_color (value));
|
clutter_stage_set_color (stage, clutter_value_get_color (value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_OFFSCREEN:
|
case PROP_OFFSCREEN:
|
||||||
if (priv->is_offscreen == g_value_get_boolean (value))
|
if (priv->is_offscreen == g_value_get_boolean (value))
|
||||||
return;
|
return;
|
||||||
@ -420,30 +426,41 @@ clutter_stage_set_property (GObject *object,
|
|||||||
else
|
else
|
||||||
priv->is_offscreen = g_value_get_boolean (value);
|
priv->is_offscreen = g_value_get_boolean (value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_FULLSCREEN:
|
case PROP_FULLSCREEN:
|
||||||
if (g_value_get_boolean (value))
|
if (g_value_get_boolean (value))
|
||||||
clutter_stage_fullscreen (stage);
|
clutter_stage_fullscreen (stage);
|
||||||
else
|
else
|
||||||
clutter_stage_unfullscreen (stage);
|
clutter_stage_unfullscreen (stage);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_CURSOR_VISIBLE:
|
case PROP_CURSOR_VISIBLE:
|
||||||
if (g_value_get_boolean (value))
|
if (g_value_get_boolean (value))
|
||||||
clutter_stage_show_cursor (stage);
|
clutter_stage_show_cursor (stage);
|
||||||
else
|
else
|
||||||
clutter_stage_hide_cursor (stage);
|
clutter_stage_hide_cursor (stage);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_PERSPECTIVE:
|
case PROP_PERSPECTIVE:
|
||||||
clutter_stage_set_perspectivex (stage, g_value_get_boxed (value));
|
clutter_stage_set_perspective (stage, g_value_get_boxed (value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_TITLE:
|
case PROP_TITLE:
|
||||||
clutter_stage_set_title (stage, g_value_get_string (value));
|
clutter_stage_set_title (stage, g_value_get_string (value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_USER_RESIZE:
|
case PROP_USER_RESIZE:
|
||||||
clutter_stage_set_user_resizable (stage, g_value_get_boolean (value));
|
clutter_stage_set_user_resizable (stage, g_value_get_boolean (value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_USE_FOG:
|
case PROP_USE_FOG:
|
||||||
clutter_stage_set_use_fog (stage, g_value_get_boolean (value));
|
clutter_stage_set_use_fog (stage, g_value_get_boolean (value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_FOG:
|
||||||
|
clutter_stage_set_fog (stage, g_value_get_boxed (value));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
@ -451,47 +468,53 @@ clutter_stage_set_property (GObject *object,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
clutter_stage_get_property (GObject *object,
|
clutter_stage_get_property (GObject *gobject,
|
||||||
guint prop_id,
|
guint prop_id,
|
||||||
GValue *value,
|
GValue *value,
|
||||||
GParamSpec *pspec)
|
GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
ClutterStage *stage;
|
ClutterStagePrivate *priv = CLUTTER_STAGE (gobject)->priv;
|
||||||
ClutterStagePrivate *priv;
|
|
||||||
ClutterPerspective perspective;
|
|
||||||
|
|
||||||
stage = CLUTTER_STAGE(object);
|
|
||||||
priv = stage->priv;
|
|
||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
case PROP_COLOR:
|
case PROP_COLOR:
|
||||||
clutter_value_set_color (value, &priv->color);
|
clutter_value_set_color (value, &priv->color);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_OFFSCREEN:
|
case PROP_OFFSCREEN:
|
||||||
g_value_set_boolean (value, priv->is_offscreen);
|
g_value_set_boolean (value, priv->is_offscreen);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_FULLSCREEN:
|
case PROP_FULLSCREEN:
|
||||||
g_value_set_boolean (value, priv->is_fullscreen);
|
g_value_set_boolean (value, priv->is_fullscreen);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_CURSOR_VISIBLE:
|
case PROP_CURSOR_VISIBLE:
|
||||||
g_value_set_boolean (value, priv->is_cursor_visible);
|
g_value_set_boolean (value, priv->is_cursor_visible);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_PERSPECTIVE:
|
case PROP_PERSPECTIVE:
|
||||||
clutter_stage_get_perspectivex (stage, &perspective);
|
g_value_set_boxed (value, &priv->perspective);
|
||||||
g_value_set_boxed (value, &perspective);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_TITLE:
|
case PROP_TITLE:
|
||||||
g_value_set_string (value, priv->title);
|
g_value_set_string (value, priv->title);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_USER_RESIZE:
|
case PROP_USER_RESIZE:
|
||||||
g_value_set_boolean (value, priv->is_user_resizable);
|
g_value_set_boolean (value, priv->is_user_resizable);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PROP_USE_FOG:
|
case PROP_USE_FOG:
|
||||||
g_value_set_boolean (value, priv->use_fog);
|
g_value_set_boolean (value, priv->use_fog);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_FOG:
|
||||||
|
g_value_set_boxed (value, &priv->fog);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -665,6 +688,20 @@ clutter_stage_class_init (ClutterStageClass *klass)
|
|||||||
"Whether to enable depth cueing",
|
"Whether to enable depth cueing",
|
||||||
FALSE,
|
FALSE,
|
||||||
CLUTTER_PARAM_READWRITE));
|
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
|
* ClutterStage::fullscreen
|
||||||
@ -825,13 +862,12 @@ clutter_stage_init (ClutterStage *self)
|
|||||||
|
|
||||||
priv->perspective.fovy = 60.0; /* 60 Degrees */
|
priv->perspective.fovy = 60.0; /* 60 Degrees */
|
||||||
priv->perspective.aspect = 1.0;
|
priv->perspective.aspect = 1.0;
|
||||||
priv->perspective.z_near = CLUTTER_FLOAT_TO_FIXED (0.1);
|
priv->perspective.z_near = 0.1;
|
||||||
priv->perspective.z_far = CLUTTER_FLOAT_TO_FIXED (100.0);
|
priv->perspective.z_far = 100.0;
|
||||||
|
|
||||||
/* depth cueing */
|
/* depth cueing */
|
||||||
priv->fog.density = CLUTTER_FLOAT_TO_FIXED (0.1);
|
priv->fog.z_near = 1.0;
|
||||||
priv->fog.z_near = CLUTTER_FLOAT_TO_FIXED (1.0);
|
priv->fog.z_far = 2.0;
|
||||||
priv->fog.z_far = CLUTTER_FLOAT_TO_FIXED (2.0);
|
|
||||||
|
|
||||||
clutter_actor_set_reactive (CLUTTER_ACTOR (self), TRUE);
|
clutter_actor_set_reactive (CLUTTER_ACTOR (self), TRUE);
|
||||||
clutter_stage_set_key_focus (self, NULL);
|
clutter_stage_set_key_focus (self, NULL);
|
||||||
@ -868,12 +904,12 @@ clutter_stage_get_default (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clutter_stage_set_color
|
* clutter_stage_set_color:
|
||||||
* @stage: A #ClutterStage
|
* @stage: A #ClutterStage
|
||||||
* @color: A #ClutterColor
|
* @color: A #ClutterColor
|
||||||
*
|
*
|
||||||
* Set the stage color.
|
* Sets the stage color.
|
||||||
**/
|
*/
|
||||||
void
|
void
|
||||||
clutter_stage_set_color (ClutterStage *stage,
|
clutter_stage_set_color (ClutterStage *stage,
|
||||||
const ClutterColor *color)
|
const ClutterColor *color)
|
||||||
@ -894,7 +930,7 @@ clutter_stage_set_color (ClutterStage *stage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clutter_stage_get_color
|
* clutter_stage_get_color:
|
||||||
* @stage: A #ClutterStage
|
* @stage: A #ClutterStage
|
||||||
* @color: return location for a #ClutterColor
|
* @color: return location for a #ClutterColor
|
||||||
*
|
*
|
||||||
@ -915,15 +951,14 @@ clutter_stage_get_color (ClutterStage *stage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clutter_stage_set_perspectivex
|
* clutter_stage_set_perspective:
|
||||||
* @stage: A #ClutterStage
|
* @stage: A #ClutterStage
|
||||||
* @perspective: A #ClutterPerspective
|
* @perspective: A #ClutterPerspective
|
||||||
*
|
*
|
||||||
* Set the stage perspective. This is the fixed point version of
|
* Sets the stage perspective.
|
||||||
* clutter_stage_set_perspective().
|
*/
|
||||||
**/
|
|
||||||
void
|
void
|
||||||
clutter_stage_set_perspectivex (ClutterStage *stage,
|
clutter_stage_set_perspective (ClutterStage *stage,
|
||||||
ClutterPerspective *perspective)
|
ClutterPerspective *perspective)
|
||||||
{
|
{
|
||||||
ClutterStagePrivate *priv;
|
ClutterStagePrivate *priv;
|
||||||
@ -942,15 +977,14 @@ clutter_stage_set_perspectivex (ClutterStage *stage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clutter_stage_get_perspectivex
|
* clutter_stage_get_perspective:
|
||||||
* @stage: A #ClutterStage
|
* @stage: A #ClutterStage
|
||||||
* @perspective: return location for a #ClutterPerspective
|
* @perspective: return location for a #ClutterPerspective
|
||||||
*
|
*
|
||||||
* Retrieves the stage perspective. This is the fixed point version of
|
* Retrieves the stage perspective.
|
||||||
* clutter_stage_get_perspective().
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
clutter_stage_get_perspectivex (ClutterStage *stage,
|
clutter_stage_get_perspective (ClutterStage *stage,
|
||||||
ClutterPerspective *perspective)
|
ClutterPerspective *perspective)
|
||||||
{
|
{
|
||||||
g_return_if_fail (CLUTTER_IS_STAGE (stage));
|
g_return_if_fail (CLUTTER_IS_STAGE (stage));
|
||||||
@ -959,85 +993,6 @@ clutter_stage_get_perspectivex (ClutterStage *stage,
|
|||||||
*perspective = stage->priv->perspective;
|
*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)
|
|
||||||
{
|
|
||||||
ClutterStagePrivate *priv;
|
|
||||||
|
|
||||||
g_return_if_fail (CLUTTER_IS_STAGE (stage));
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clutter_stage_fullscreen:
|
* clutter_stage_fullscreen:
|
||||||
* @stage: a #ClutterStage
|
* @stage: a #ClutterStage
|
||||||
@ -1610,87 +1565,56 @@ clutter_stage_set_use_fog (ClutterStage *stage,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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:
|
* clutter_stage_set_fog:
|
||||||
* @stage: the #ClutterStage
|
* @stage: the #ClutterStage
|
||||||
* @density: density of the intensity dampening
|
* @fog: a #ClutterFog structure
|
||||||
* @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
|
* Sets the fog (also known as "depth cueing") settings for the @stage.
|
||||||
* on the @stage.
|
|
||||||
*
|
*
|
||||||
* If the actors are all near the view point you will need a higher @density
|
* A #ClutterStage will only use a linear fog progression, which
|
||||||
* and a smaller interval between @z_near and @z_far. On the other hand, if
|
* depends solely on the distance from the viewer. The cogl_set_fog()
|
||||||
* actors are placed far away from the view point you will need a lower
|
* function in COGL exposes more of the underlying implementation,
|
||||||
* @density but a bigger interval between @z_near and @z_far.
|
* 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
|
* Since: 0.6
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
clutter_stage_set_fog (ClutterStage *stage,
|
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().
|
|
||||||
*
|
|
||||||
* Since: 0.6
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
clutter_stage_set_fogx (ClutterStage *stage,
|
|
||||||
ClutterFog *fog)
|
ClutterFog *fog)
|
||||||
{
|
{
|
||||||
ClutterStagePrivate *priv;
|
ClutterStagePrivate *priv;
|
||||||
@ -1707,17 +1631,16 @@ clutter_stage_set_fogx (ClutterStage *stage,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clutter_stage_get_fogx:
|
* clutter_stage_get_fog:
|
||||||
* @stage: the #ClutterStage
|
* @stage: the #ClutterStage
|
||||||
* @fog: return location for a #ClutterFog structure
|
* @fog: return location for a #ClutterFog structure
|
||||||
*
|
*
|
||||||
* Retrieves the current depth cueing settings from the stage. This is the
|
* Retrieves the current depth cueing settings from the stage.
|
||||||
* fixed point version of clutter_stage_get_fog().
|
|
||||||
*
|
*
|
||||||
* Since: 0.6
|
* Since: 0.6
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
clutter_stage_get_fogx (ClutterStage *stage,
|
clutter_stage_get_fog (ClutterStage *stage,
|
||||||
ClutterFog *fog)
|
ClutterFog *fog)
|
||||||
{
|
{
|
||||||
g_return_if_fail (CLUTTER_IS_STAGE (stage));
|
g_return_if_fail (CLUTTER_IS_STAGE (stage));
|
||||||
@ -1728,24 +1651,20 @@ clutter_stage_get_fogx (ClutterStage *stage,
|
|||||||
|
|
||||||
/*** Perspective boxed type ******/
|
/*** Perspective boxed type ******/
|
||||||
|
|
||||||
static ClutterPerspective *
|
static gpointer
|
||||||
clutter_perspective_copy (const ClutterPerspective *perspective)
|
clutter_perspective_copy (gpointer data)
|
||||||
{
|
{
|
||||||
ClutterPerspective *result;
|
if (G_LIKELY (data))
|
||||||
|
return g_slice_dup (ClutterPerspective, data);
|
||||||
|
|
||||||
g_return_val_if_fail (perspective != NULL, NULL);
|
return NULL;
|
||||||
|
|
||||||
result = g_slice_new (ClutterPerspective);
|
|
||||||
*result = *perspective;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
clutter_perspective_free (ClutterPerspective *perspective)
|
clutter_perspective_free (gpointer data)
|
||||||
{
|
{
|
||||||
if (G_LIKELY (perspective))
|
if (G_LIKELY (data))
|
||||||
g_slice_free (ClutterPerspective, perspective);
|
g_slice_free (ClutterPerspective, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
GType
|
GType
|
||||||
@ -1754,31 +1673,26 @@ clutter_perspective_get_type (void)
|
|||||||
static GType our_type = 0;
|
static GType our_type = 0;
|
||||||
|
|
||||||
if (!our_type)
|
if (!our_type)
|
||||||
our_type =
|
our_type = g_boxed_type_register_static (I_("ClutterPerspective"),
|
||||||
g_boxed_type_register_static (I_("ClutterPerspective"),
|
clutter_perspective_copy,
|
||||||
(GBoxedCopyFunc) clutter_perspective_copy,
|
clutter_perspective_free);
|
||||||
(GBoxedFreeFunc) clutter_perspective_free);
|
|
||||||
return our_type;
|
return our_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ClutterFog *
|
static gpointer
|
||||||
clutter_fog_copy (const ClutterFog *fog)
|
clutter_fog_copy (gpointer data)
|
||||||
{
|
{
|
||||||
ClutterFog *copy;
|
if (G_LIKELY (data))
|
||||||
|
return g_slice_dup (ClutterFog, data);
|
||||||
|
|
||||||
g_return_val_if_fail (fog != NULL, NULL);
|
return NULL;
|
||||||
|
|
||||||
copy = g_slice_new0 (ClutterFog);
|
|
||||||
*copy = *fog;
|
|
||||||
|
|
||||||
return copy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
clutter_fog_free (ClutterFog *fog)
|
clutter_fog_free (gpointer data)
|
||||||
{
|
{
|
||||||
if (G_LIKELY (fog))
|
if (G_LIKELY (data))
|
||||||
g_slice_free (ClutterFog, fog);
|
g_slice_free (ClutterFog, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
GType
|
GType
|
||||||
@ -1787,10 +1701,9 @@ clutter_fog_get_type (void)
|
|||||||
static GType our_type = 0;
|
static GType our_type = 0;
|
||||||
|
|
||||||
if (G_UNLIKELY (our_type == 0))
|
if (G_UNLIKELY (our_type == 0))
|
||||||
our_type =
|
our_type = g_boxed_type_register_static (I_("ClutterFog"),
|
||||||
g_boxed_type_register_static (I_("ClutterFog"),
|
clutter_fog_copy,
|
||||||
(GBoxedCopyFunc) clutter_fog_copy,
|
clutter_fog_free);
|
||||||
(GBoxedFreeFunc) clutter_fog_free);
|
|
||||||
|
|
||||||
return our_type;
|
return our_type;
|
||||||
}
|
}
|
||||||
|
@ -132,30 +132,27 @@ struct _ClutterStageClass
|
|||||||
*/
|
*/
|
||||||
struct _ClutterPerspective
|
struct _ClutterPerspective
|
||||||
{
|
{
|
||||||
ClutterFixed fovy;
|
gfloat fovy;
|
||||||
ClutterFixed aspect;
|
gfloat aspect;
|
||||||
ClutterFixed z_near;
|
gfloat z_near;
|
||||||
ClutterFixed z_far;
|
gfloat z_far;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ClutterFog:
|
* ClutterFog:
|
||||||
* @density: density of the fog
|
|
||||||
* @z_near: starting distance from the viewer to the near clipping
|
* @z_near: starting distance from the viewer to the near clipping
|
||||||
* plane (always positive)
|
* plane (always positive)
|
||||||
* @z_far: final distance from the viewer to the far clipping
|
* @z_far: final distance from the viewer to the far clipping
|
||||||
* plane (always positive)
|
* plane (always positive)
|
||||||
*
|
*
|
||||||
* Fog settings used to create the depth cueing effect. #ClutterFog is
|
* Fog settings used to create the depth cueing effect.
|
||||||
* useful only when using the fixed point API.
|
|
||||||
*
|
*
|
||||||
* Since: 0.6
|
* Since: 0.6
|
||||||
*/
|
*/
|
||||||
struct _ClutterFog
|
struct _ClutterFog
|
||||||
{
|
{
|
||||||
ClutterFixed density;
|
gfloat z_near;
|
||||||
ClutterFixed z_near;
|
gfloat z_far;
|
||||||
ClutterFixed z_far;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GType clutter_perspective_get_type (void) G_GNUC_CONST;
|
GType clutter_perspective_get_type (void) G_GNUC_CONST;
|
||||||
@ -169,20 +166,10 @@ void clutter_stage_set_color (ClutterStage *stage,
|
|||||||
const ClutterColor *color);
|
const ClutterColor *color);
|
||||||
void clutter_stage_get_color (ClutterStage *stage,
|
void clutter_stage_get_color (ClutterStage *stage,
|
||||||
ClutterColor *color);
|
ClutterColor *color);
|
||||||
void clutter_stage_set_perspectivex (ClutterStage *stage,
|
|
||||||
ClutterPerspective *perspective);
|
|
||||||
void clutter_stage_get_perspectivex (ClutterStage *stage,
|
|
||||||
ClutterPerspective *perspective);
|
|
||||||
void clutter_stage_set_perspective (ClutterStage *stage,
|
void clutter_stage_set_perspective (ClutterStage *stage,
|
||||||
gfloat fovy,
|
ClutterPerspective *perspective);
|
||||||
gfloat aspect,
|
|
||||||
gfloat z_near,
|
|
||||||
gfloat z_far);
|
|
||||||
void clutter_stage_get_perspective (ClutterStage *stage,
|
void clutter_stage_get_perspective (ClutterStage *stage,
|
||||||
gfloat *fovy,
|
ClutterPerspective *perspective);
|
||||||
gfloat *aspect,
|
|
||||||
gfloat *z_near,
|
|
||||||
gfloat *z_far);
|
|
||||||
void clutter_stage_fullscreen (ClutterStage *stage);
|
void clutter_stage_fullscreen (ClutterStage *stage);
|
||||||
void clutter_stage_unfullscreen (ClutterStage *stage);
|
void clutter_stage_unfullscreen (ClutterStage *stage);
|
||||||
void clutter_stage_show_cursor (ClutterStage *stage);
|
void clutter_stage_show_cursor (ClutterStage *stage);
|
||||||
@ -209,16 +196,8 @@ void clutter_stage_set_use_fog (ClutterStage *stage,
|
|||||||
gboolean fog);
|
gboolean fog);
|
||||||
gboolean clutter_stage_get_use_fog (ClutterStage *stage);
|
gboolean clutter_stage_get_use_fog (ClutterStage *stage);
|
||||||
void clutter_stage_set_fog (ClutterStage *stage,
|
void clutter_stage_set_fog (ClutterStage *stage,
|
||||||
gdouble density,
|
|
||||||
gdouble z_near,
|
|
||||||
gdouble z_far);
|
|
||||||
void clutter_stage_get_fog (ClutterStage *stage,
|
|
||||||
gdouble *density,
|
|
||||||
gdouble *z_near,
|
|
||||||
gdouble *z_far);
|
|
||||||
void clutter_stage_set_fogx (ClutterStage *stage,
|
|
||||||
ClutterFog *fog);
|
ClutterFog *fog);
|
||||||
void clutter_stage_get_fogx (ClutterStage *stage,
|
void clutter_stage_get_fog (ClutterStage *stage,
|
||||||
ClutterFog *fog);
|
ClutterFog *fog);
|
||||||
|
|
||||||
void clutter_stage_set_key_focus (ClutterStage *stage,
|
void clutter_stage_set_key_focus (ClutterStage *stage,
|
||||||
|
@ -438,12 +438,12 @@ clutter_texture_set_fbo_projection (ClutterActor *self)
|
|||||||
{
|
{
|
||||||
ClutterTexturePrivate *priv = CLUTTER_TEXTURE (self)->priv;
|
ClutterTexturePrivate *priv = CLUTTER_TEXTURE (self)->priv;
|
||||||
ClutterVertex verts[4];
|
ClutterVertex verts[4];
|
||||||
ClutterFixed viewport[4];
|
gfloat viewport[4];
|
||||||
ClutterUnit x_min, x_max, y_min, y_max;
|
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;
|
ClutterPerspective perspective;
|
||||||
ClutterStage *stage;
|
ClutterStage *stage;
|
||||||
ClutterFixed tan_angle, near_size;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Get the bounding rectangle of the source as drawn in screen
|
/* Get the bounding rectangle of the source as drawn in screen
|
||||||
@ -469,30 +469,31 @@ clutter_texture_set_fbo_projection (ClutterActor *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
stage = CLUTTER_STAGE (clutter_actor_get_stage (self));
|
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 */
|
/* Convert the coordinates back to [-1,1] range */
|
||||||
cogl_get_viewport (viewport);
|
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;
|
* 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;
|
* 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;
|
* 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;
|
* 2 - 1.0;
|
||||||
|
|
||||||
/* Set up a projection matrix so that the actor will be projected as
|
/* Set up a projection matrix so that the actor will be projected as
|
||||||
if it was drawn at its original location */
|
if it was drawn at its original location */
|
||||||
tan_angle = tanf ((perspective.fovy / 2) * (G_PI / 180.0));
|
tan_angle = tanf ((perspective.fovy / 2) * (G_PI / 180.0));
|
||||||
near_size = CLUTTER_FIXED_MUL (perspective.z_near, tan_angle);
|
near_size = perspective.z_near * tan_angle;
|
||||||
|
|
||||||
cogl_frustum (CLUTTER_FIXED_MUL (tx_min, near_size),
|
cogl_frustum ((tx_min * near_size),
|
||||||
CLUTTER_FIXED_MUL (tx_max, near_size),
|
(tx_max * near_size),
|
||||||
CLUTTER_FIXED_MUL (-ty_min, near_size),
|
(-ty_min * near_size),
|
||||||
CLUTTER_FIXED_MUL (-ty_max, near_size),
|
(-ty_max * near_size),
|
||||||
perspective.z_near, perspective.z_far);
|
perspective.z_near,
|
||||||
|
perspective.z_far);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -502,10 +503,10 @@ clutter_texture_paint (ClutterActor *self)
|
|||||||
ClutterTexturePrivate *priv = texture->priv;
|
ClutterTexturePrivate *priv = texture->priv;
|
||||||
gint x_1, y_1, x_2, y_2;
|
gint x_1, y_1, x_2, y_2;
|
||||||
CoglColor transparent_col;
|
CoglColor transparent_col;
|
||||||
ClutterFixed t_w, t_h;
|
gfloat t_w, t_h;
|
||||||
guint8 paint_opacity = clutter_actor_get_paint_opacity (self);
|
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
|
/* 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.
|
* might cause a lot of work/state changes should all do this.
|
||||||
@ -542,7 +543,7 @@ clutter_texture_paint (ClutterActor *self)
|
|||||||
guint stage_width, stage_height;
|
guint stage_width, stage_height;
|
||||||
ClutterActor *source_parent;
|
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);
|
clutter_actor_get_size (stage, &stage_width, &stage_height);
|
||||||
|
|
||||||
/* Use below to set the modelview matrix as if the viewport
|
/* Use below to set the modelview matrix as if the viewport
|
||||||
@ -614,14 +615,12 @@ clutter_texture_paint (ClutterActor *self)
|
|||||||
clutter_actor_get_opacity (self));
|
clutter_actor_get_opacity (self));
|
||||||
|
|
||||||
if (priv->repeat_x && priv->width > 0)
|
if (priv->repeat_x && priv->width > 0)
|
||||||
t_w = CLUTTER_FIXED_DIV ((float)(x_2 - x_1),
|
t_w = (float) (x_2 - x_1) / (float) (priv->width);
|
||||||
(float)(priv->width));
|
|
||||||
else
|
else
|
||||||
t_w = 1.0;
|
t_w = 1.0;
|
||||||
|
|
||||||
if (priv->repeat_y && priv->height > 0)
|
if (priv->repeat_y && priv->height > 0)
|
||||||
t_h = CLUTTER_FIXED_DIV ((float)(y_2 - y_1),
|
t_h = (float) (y_2 - y_1) / (float) (priv->height);
|
||||||
(float)(priv->height));
|
|
||||||
else
|
else
|
||||||
t_h = 1.0;
|
t_h = 1.0;
|
||||||
|
|
||||||
|
@ -117,14 +117,15 @@ test_depth_main (int argc, char *argv[])
|
|||||||
ClutterActor *group, *hand, *label, *rect, *janus, *box;
|
ClutterActor *group, *hand, *label, *rect, *janus, *box;
|
||||||
ClutterColor stage_color = { 0xcc, 0xcc, 0xcc, 0xff };
|
ClutterColor stage_color = { 0xcc, 0xcc, 0xcc, 0xff };
|
||||||
ClutterColor rect_color = { 0, 0, 0, 0x88 };
|
ClutterColor rect_color = { 0, 0, 0, 0x88 };
|
||||||
|
ClutterFog stage_fog = { 10.0, -50.0 };
|
||||||
GError *error;
|
GError *error;
|
||||||
|
|
||||||
clutter_init (&argc, &argv);
|
clutter_init (&argc, &argv);
|
||||||
|
|
||||||
stage = clutter_stage_get_default ();
|
stage = clutter_stage_get_default ();
|
||||||
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
|
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
|
||||||
|
clutter_stage_set_fog (CLUTTER_STAGE (stage), &stage_fog);
|
||||||
clutter_stage_set_use_fog (CLUTTER_STAGE (stage), TRUE);
|
clutter_stage_set_use_fog (CLUTTER_STAGE (stage), TRUE);
|
||||||
clutter_stage_set_fog (CLUTTER_STAGE (stage), 1.0, 10, -50);
|
|
||||||
|
|
||||||
g_signal_connect (stage,
|
g_signal_connect (stage,
|
||||||
"button-press-event", G_CALLBACK (clutter_main_quit),
|
"button-press-event", G_CALLBACK (clutter_main_quit),
|
||||||
|
@ -48,6 +48,7 @@ test_texture_quality_main (int argc, char *argv[])
|
|||||||
ClutterActor *stage;
|
ClutterActor *stage;
|
||||||
ClutterActor *image;
|
ClutterActor *image;
|
||||||
ClutterColor stage_color = { 0x12, 0x34, 0x56, 0xff };
|
ClutterColor stage_color = { 0x12, 0x34, 0x56, 0xff };
|
||||||
|
ClutterFog stage_fog = { 10.0, -50.0 };
|
||||||
GError *error;
|
GError *error;
|
||||||
|
|
||||||
clutter_init (&argc, &argv);
|
clutter_init (&argc, &argv);
|
||||||
@ -55,7 +56,7 @@ test_texture_quality_main (int argc, char *argv[])
|
|||||||
stage = clutter_stage_get_default ();
|
stage = clutter_stage_get_default ();
|
||||||
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
|
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
|
||||||
clutter_stage_set_use_fog (CLUTTER_STAGE (stage), TRUE);
|
clutter_stage_set_use_fog (CLUTTER_STAGE (stage), TRUE);
|
||||||
clutter_stage_set_fog (CLUTTER_STAGE (stage), 1.0, 10, -50);
|
clutter_stage_set_fog (CLUTTER_STAGE (stage), &stage_fog);
|
||||||
|
|
||||||
g_signal_connect (stage,
|
g_signal_connect (stage,
|
||||||
"button-press-event", G_CALLBACK (clutter_main_quit),
|
"button-press-event", G_CALLBACK (clutter_main_quit),
|
||||||
|
Loading…
Reference in New Issue
Block a user