mirror of
https://github.com/brl/mutter.git
synced 2024-11-23 08:30:42 -05:00
e42d756a69
The previous patch broke some of the normalization done before the sine value gets multiplied with CLUTTER_ALPHA_MAX. This e.g. broke test-actors when sine values went through to -1, as the o-hands were scaled so large all you saw was the red 'O'.
271 lines
7.8 KiB
Diff
271 lines
7.8 KiB
Diff
diff --git a/clutter/clutter-alpha.c b/clutter/clutter-alpha.c
|
|
index 3e4df4d..d508631 100644
|
|
--- a/clutter/clutter-alpha.c
|
|
+++ b/clutter/clutter-alpha.c
|
|
@@ -694,6 +694,11 @@ clutter_ramp_func (ClutterAlpha *alpha,
|
|
}
|
|
}
|
|
|
|
+#if 0
|
|
+/*
|
|
+ * The following three functions are left in place for reference
|
|
+ * purposes.
|
|
+ */
|
|
static guint32
|
|
sincx1024_func (ClutterAlpha *alpha,
|
|
ClutterAngle angle,
|
|
@@ -713,7 +718,7 @@ sincx1024_func (ClutterAlpha *alpha,
|
|
|
|
x -= (512 * 512 / angle);
|
|
|
|
- sine = ((sinf (x) + offset) / 2)
|
|
+ sine = ((cogl_angle_sin (x) + offset) / 2)
|
|
* CLUTTER_ALPHA_MAX_ALPHA;
|
|
|
|
sine = sine >> COGL_FIXED_Q;
|
|
@@ -721,11 +726,6 @@ sincx1024_func (ClutterAlpha *alpha,
|
|
return sine;
|
|
}
|
|
|
|
-#if 0
|
|
-/*
|
|
- * The following two functions are left in place for reference
|
|
- * purposes.
|
|
- */
|
|
static guint32
|
|
sincx_func (ClutterAlpha *alpha,
|
|
ClutterFixed angle,
|
|
@@ -744,7 +744,7 @@ sincx_func (ClutterAlpha *alpha,
|
|
x = CLUTTER_FIXED_MUL (x, CFX_PI)
|
|
- CLUTTER_FIXED_DIV (CFX_PI, angle);
|
|
|
|
- sine = (sinf (x) + offset) / 2;
|
|
+ sine = (cogl_angle_sin (x) + offset) / 2;
|
|
|
|
CLUTTER_NOTE (ALPHA, "sine: %2f\n", CLUTTER_FIXED_TO_DOUBLE (sine));
|
|
|
|
@@ -803,9 +803,28 @@ guint32
|
|
clutter_sine_func (ClutterAlpha *alpha,
|
|
gpointer dummy)
|
|
{
|
|
-#if 0
|
|
+#if 1
|
|
+ ClutterTimeline *timeline;
|
|
+ gint current_frame_num, n_frames;
|
|
+ float radians, sine;
|
|
+
|
|
+ timeline = clutter_alpha_get_timeline (alpha);
|
|
+
|
|
+ current_frame_num = clutter_timeline_get_current_frame (timeline);
|
|
+ n_frames = clutter_timeline_get_n_frames (timeline);
|
|
+
|
|
+ radians = ((float)current_frame_num / n_frames) * (2.0 * G_PI);
|
|
+ sine = sinf (radians);
|
|
+
|
|
+ /* shift from range [-1, 1] -> [0, 1] */
|
|
+ sine = (sine + 1.0) / 2.0;
|
|
+
|
|
+ CLUTTER_NOTE (ALPHA, "sine: %2f\n", sine);
|
|
+
|
|
+ return sine * CLUTTER_ALPHA_MAX_ALPHA;
|
|
+#elif 0
|
|
return sinc_func (alpha, 2.0, 1.0);
|
|
-#else
|
|
+#elif 0
|
|
/* 2.0 above represents full circle */
|
|
return sincx1024_func (alpha, 1024, 1.0);
|
|
#endif
|
|
@@ -839,18 +858,17 @@ clutter_sine_inc_func (ClutterAlpha *alpha,
|
|
ClutterTimeline * timeline;
|
|
gint frame;
|
|
gint n_frames;
|
|
- ClutterAngle x;
|
|
- ClutterFixed sine;
|
|
+ float radians;
|
|
+ float sine;
|
|
|
|
timeline = clutter_alpha_get_timeline (alpha);
|
|
frame = clutter_timeline_get_current_frame (timeline);
|
|
n_frames = clutter_timeline_get_n_frames (timeline);
|
|
|
|
- x = 256 * frame / n_frames;
|
|
+ radians = ((float)frame / n_frames) * (G_PI / 2);
|
|
+ sine = sinf (radians);
|
|
|
|
- sine = sinf (x) * CLUTTER_ALPHA_MAX_ALPHA;
|
|
-
|
|
- return ((guint32) sine) >> COGL_FIXED_Q;
|
|
+ return (guint32) (sine * CLUTTER_ALPHA_MAX_ALPHA);
|
|
}
|
|
|
|
/**
|
|
@@ -881,18 +899,17 @@ clutter_sine_dec_func (ClutterAlpha *alpha,
|
|
ClutterTimeline * timeline;
|
|
gint frame;
|
|
gint n_frames;
|
|
- ClutterAngle x;
|
|
- ClutterFixed sine;
|
|
+ float radians;
|
|
+ float sine;
|
|
|
|
timeline = clutter_alpha_get_timeline (alpha);
|
|
frame = clutter_timeline_get_current_frame (timeline);
|
|
n_frames = clutter_timeline_get_n_frames (timeline);
|
|
|
|
- x = 256 * frame / n_frames + 256;
|
|
-
|
|
- sine = sinf (x) * CLUTTER_ALPHA_MAX_ALPHA;
|
|
+ radians = ((float)frame / n_frames) * (G_PI / 2);
|
|
+ sine = sinf (radians + (G_PI / 2));
|
|
|
|
- return ((guint32) sine) >> COGL_FIXED_Q;
|
|
+ return (guint32) (sine * CLUTTER_ALPHA_MAX_ALPHA);
|
|
}
|
|
|
|
/**
|
|
@@ -923,18 +940,17 @@ clutter_sine_half_func (ClutterAlpha *alpha,
|
|
ClutterTimeline *timeline;
|
|
gint frame;
|
|
gint n_frames;
|
|
- ClutterAngle x;
|
|
- ClutterFixed sine;
|
|
+ float radians;
|
|
+ float sine;
|
|
|
|
timeline = clutter_alpha_get_timeline (alpha);
|
|
frame = clutter_timeline_get_current_frame (timeline);
|
|
n_frames = clutter_timeline_get_n_frames (timeline);
|
|
|
|
- x = 512 * frame / n_frames;
|
|
-
|
|
- sine = sinf (x) * CLUTTER_ALPHA_MAX_ALPHA;
|
|
+ radians = ((float)frame / n_frames) * G_PI;
|
|
+ sine = sinf (radians);
|
|
|
|
- return ((guint32) sine) >> COGL_FIXED_Q;
|
|
+ return (guint32) (sine * CLUTTER_ALPHA_MAX_ALPHA);
|
|
}
|
|
|
|
/**
|
|
@@ -959,19 +975,20 @@ clutter_sine_in_func (ClutterAlpha *alpha,
|
|
ClutterTimeline *timeline;
|
|
gint frame;
|
|
gint n_frames;
|
|
- ClutterAngle x;
|
|
- ClutterFixed sine;
|
|
+ float radians;
|
|
+ float sine;
|
|
|
|
timeline = clutter_alpha_get_timeline (alpha);
|
|
frame = clutter_timeline_get_current_frame (timeline);
|
|
n_frames = clutter_timeline_get_n_frames (timeline);
|
|
|
|
- /* XXX- if we use 768 we overflow */
|
|
- x = 256 * frame / n_frames + 767;
|
|
+ radians = ((float)frame / n_frames) * (G_PI / 2);
|
|
+ sine = sinf (radians - (G_PI / 2));
|
|
|
|
- sine = (sinf (x) + 1) * CLUTTER_ALPHA_MAX_ALPHA;
|
|
+ /* shift from range [-1, 0] -> [0, 1] */
|
|
+ sine = sine + 1.0;
|
|
|
|
- return ((guint32) sine) >> COGL_FIXED_Q;
|
|
+ return (guint32) (sine * CLUTTER_ALPHA_MAX_ALPHA);
|
|
}
|
|
|
|
/**
|
|
@@ -995,18 +1012,17 @@ clutter_sine_out_func (ClutterAlpha *alpha,
|
|
ClutterTimeline *timeline;
|
|
gint frame;
|
|
gint n_frames;
|
|
- ClutterAngle x;
|
|
- ClutterFixed sine;
|
|
+ float radians;
|
|
+ float sine;
|
|
|
|
timeline = clutter_alpha_get_timeline (alpha);
|
|
frame = clutter_timeline_get_current_frame (timeline);
|
|
n_frames = clutter_timeline_get_n_frames (timeline);
|
|
|
|
- x = 256 * frame / n_frames;
|
|
+ radians = ((float)frame / n_frames) * (G_PI / 2);
|
|
+ sine = sinf (radians);
|
|
|
|
- sine = sinf (x) * CLUTTER_ALPHA_MAX_ALPHA;
|
|
-
|
|
- return ((guint32) sine) >> COGL_FIXED_Q;
|
|
+ return (guint32) (sine * CLUTTER_ALPHA_MAX_ALPHA);
|
|
}
|
|
|
|
/**
|
|
@@ -1031,18 +1047,20 @@ clutter_sine_in_out_func (ClutterAlpha *alpha,
|
|
ClutterTimeline *timeline;
|
|
gint frame;
|
|
gint n_frames;
|
|
- ClutterAngle x;
|
|
- ClutterFixed sine;
|
|
+ float radians;
|
|
+ float sine;
|
|
|
|
timeline = clutter_alpha_get_timeline (alpha);
|
|
frame = clutter_timeline_get_current_frame (timeline);
|
|
n_frames = clutter_timeline_get_n_frames (timeline);
|
|
|
|
- x = -256 * frame / n_frames + 256;
|
|
+ radians = ((float)frame / n_frames) * G_PI;
|
|
+ sine = sinf (radians - (G_PI / 2));
|
|
|
|
- sine = (sinf (x) + 1) / 2 * CLUTTER_ALPHA_MAX_ALPHA;
|
|
+ /* shift from range [-1, 1] -> [0, 1] */
|
|
+ sine = (sine + 1.0) / 2.0;
|
|
|
|
- return ((guint32) sine) >> COGL_FIXED_Q;
|
|
+ return (guint32) (sine * CLUTTER_ALPHA_MAX_ALPHA);
|
|
}
|
|
|
|
/**
|
|
@@ -1201,9 +1219,9 @@ clutter_exp_inc_func (ClutterAlpha *alpha,
|
|
*
|
|
* (2^x_alpha_max) - 1 == CLUTTER_ALPHA_MAX_ALPHA
|
|
*/
|
|
-#if CLUTTER_ALPHA_MAX_ALPHA != 0xffff
|
|
-#error Adjust x_alpha_max to match CLUTTER_ALPHA_MAX_ALPHA
|
|
-#endif
|
|
+ /* XXX: If this fails:
|
|
+ * Adjust x_alpha_max to match CLUTTER_ALPHA_MAX_ALPHA */
|
|
+ g_assert (CLUTTER_ALPHA_MAX_ALPHA == 65535.0);
|
|
|
|
timeline = clutter_alpha_get_timeline (alpha);
|
|
frame = clutter_timeline_get_current_frame (timeline);
|
|
@@ -1211,7 +1229,7 @@ clutter_exp_inc_func (ClutterAlpha *alpha,
|
|
|
|
x = x_alpha_max * frame / n_frames;
|
|
|
|
- result = CLAMP (pow2f (x) - 1, 0, CLUTTER_ALPHA_MAX_ALPHA);
|
|
+ result = CLAMP (powf (2, x) - 1, 0, CLUTTER_ALPHA_MAX_ALPHA);
|
|
|
|
return result;
|
|
}
|
|
@@ -1252,9 +1270,9 @@ clutter_exp_dec_func (ClutterAlpha *alpha,
|
|
*
|
|
* (2^x_alpha_max) - 1 == CLUTTER_ALPHA_MAX_ALPHA
|
|
*/
|
|
-#if CLUTTER_ALPHA_MAX_ALPHA != 0xffff
|
|
-#error Adjust x_alpha_max to match CLUTTER_ALPHA_MAX_ALPHA
|
|
-#endif
|
|
+ /* XXX: If this fails:
|
|
+ * Adjust x_alpha_max to match CLUTTER_ALPHA_MAX_ALPHA */
|
|
+ g_assert (CLUTTER_ALPHA_MAX_ALPHA == 65535.0);
|
|
|
|
timeline = clutter_alpha_get_timeline (alpha);
|
|
frame = clutter_timeline_get_current_frame (timeline);
|
|
@@ -1262,7 +1280,7 @@ clutter_exp_dec_func (ClutterAlpha *alpha,
|
|
|
|
x = (x_alpha_max * (n_frames - frame)) / n_frames;
|
|
|
|
- result = CLAMP (pow2f (x) - 1, 0, CLUTTER_ALPHA_MAX_ALPHA);
|
|
+ result = CLAMP (powf (2, x) - 1, 0, CLUTTER_ALPHA_MAX_ALPHA);
|
|
|
|
return result;
|
|
}
|