mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 11:32:04 +00:00
Do not modify parameters in place
When the apply_transform_to_point() and its relative variant landed in Clutter 0.3, the initial approach was to modify the passed vertex as an in-out parameter. This was later dropped in favour of a more consistent out parameter. Unfortunately, the implementation never changed: both methods where modifying the passed vertex with the partial results of the computations. This commit copies the contents of the "point" ClutterVertex argument inside a stack variable and, for good measure, constifies the argument. Thanks to Thomas Steinacher for catching this in Python.
This commit is contained in:
parent
dc6545ccd1
commit
bc6a107ff6
@ -893,18 +893,23 @@ clutter_actor_transform_point (ClutterActor *actor,
|
||||
void
|
||||
clutter_actor_apply_relative_transform_to_point (ClutterActor *self,
|
||||
ClutterActor *ancestor,
|
||||
ClutterVertex *point,
|
||||
const ClutterVertex *point,
|
||||
ClutterVertex *vertex)
|
||||
{
|
||||
ClutterVertex tmp = { 0, };
|
||||
ClutterFixed v[4];
|
||||
ClutterFixed w = COGL_FIXED_1;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_ACTOR (self));
|
||||
g_return_if_fail (ancestor == NULL || CLUTTER_IS_ACTOR (ancestor));
|
||||
g_return_if_fail (point != NULL);
|
||||
g_return_if_fail (vertex != NULL);
|
||||
|
||||
tmp = *point;
|
||||
|
||||
/* First we tranform the point using the OpenGL modelview matrix */
|
||||
clutter_actor_transform_point_relative (self, ancestor,
|
||||
&point->x, &point->y, &point->z,
|
||||
&tmp.x, &tmp.y, &tmp.z,
|
||||
&w);
|
||||
|
||||
cogl_get_viewport (v);
|
||||
@ -913,9 +918,9 @@ clutter_actor_apply_relative_transform_to_point (ClutterActor *self,
|
||||
* The w[3] parameter should always be 1.0 here, so we ignore it; otherwise
|
||||
* we would have to divide the original verts with it.
|
||||
*/
|
||||
vertex->x = COGL_FIXED_MUL ((point->x + COGL_FIXED_0_5), v[2]);
|
||||
vertex->y = COGL_FIXED_MUL ((COGL_FIXED_0_5 - point->y), v[3]);
|
||||
vertex->z = COGL_FIXED_MUL ((point->z + COGL_FIXED_0_5), v[2]);
|
||||
vertex->x = COGL_FIXED_MUL ((tmp.x + COGL_FIXED_0_5), v[2]);
|
||||
vertex->y = COGL_FIXED_MUL ((COGL_FIXED_0_5 - tmp.y), v[3]);
|
||||
vertex->z = COGL_FIXED_MUL ((tmp.z + COGL_FIXED_0_5), v[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -932,28 +937,33 @@ clutter_actor_apply_relative_transform_to_point (ClutterActor *self,
|
||||
**/
|
||||
void
|
||||
clutter_actor_apply_transform_to_point (ClutterActor *self,
|
||||
ClutterVertex *point,
|
||||
const ClutterVertex *point,
|
||||
ClutterVertex *vertex)
|
||||
{
|
||||
ClutterVertex tmp = { 0, };
|
||||
ClutterFixed mtx_p[16];
|
||||
ClutterFixed v[4];
|
||||
ClutterFixed w = COGL_FIXED_1;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_ACTOR (self));
|
||||
g_return_if_fail (point != NULL);
|
||||
g_return_if_fail (vertex != NULL);
|
||||
|
||||
tmp = *point;
|
||||
|
||||
/* First we tranform the point using the OpenGL modelview matrix */
|
||||
clutter_actor_transform_point (self, &point->x, &point->y, &point->z, &w);
|
||||
clutter_actor_transform_point (self, &tmp.x, &tmp.y, &tmp.z, &w);
|
||||
|
||||
cogl_get_projection_matrix (mtx_p);
|
||||
cogl_get_viewport (v);
|
||||
|
||||
/* Now, transform it again with the projection matrix */
|
||||
mtx_transform (mtx_p, &point->x, &point->y, &point->z, &w);
|
||||
mtx_transform (mtx_p, &tmp.x, &tmp.y, &tmp.z, &w);
|
||||
|
||||
/* Finaly translate from OpenGL coords to window coords */
|
||||
vertex->x = MTX_GL_SCALE_X (point->x, w, v[2], v[0]);
|
||||
vertex->y = MTX_GL_SCALE_Y (point->y, w, v[3], v[1]);
|
||||
vertex->z = MTX_GL_SCALE_Z (point->z, w, v[2], v[0]);
|
||||
vertex->x = MTX_GL_SCALE_X (tmp.x, w, v[2], v[0]);
|
||||
vertex->y = MTX_GL_SCALE_Y (tmp.y, w, v[3], v[1]);
|
||||
vertex->z = MTX_GL_SCALE_Z (tmp.z, w, v[2], v[0]);
|
||||
}
|
||||
|
||||
/* Recursively tranform supplied vertices with the tranform for the current
|
||||
|
@ -552,11 +552,11 @@ void clutter_actor_get_abs_allocation_vertices (ClutterActor *self,
|
||||
ClutterVertex verts[4]);
|
||||
|
||||
void clutter_actor_apply_transform_to_point (ClutterActor *self,
|
||||
ClutterVertex *point,
|
||||
const ClutterVertex *point,
|
||||
ClutterVertex *vertex);
|
||||
void clutter_actor_apply_relative_transform_to_point (ClutterActor *self,
|
||||
ClutterActor *ancestor,
|
||||
ClutterVertex *point,
|
||||
const ClutterVertex *point,
|
||||
ClutterVertex *vertex);
|
||||
|
||||
gboolean clutter_actor_get_paint_visibility (ClutterActor *self);
|
||||
|
Loading…
Reference in New Issue
Block a user