1
0
Fork 0

clutter: Align all screen transformations to 1/256th of a stage unit.

So as to eliminate floating point precision errors that creep in
during matrix operations.

1/256th is chosen as a reasonable maximum resolution to cover any
realistic fractional scaling factor. Floats can represent such
a fraction losslessly because it is a small power of 2.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1403

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1429
This commit is contained in:
Daniel van Vugt 2020-09-08 16:40:54 +08:00
parent 3a273028ae
commit 67cc60cbda

View file

@ -47,6 +47,8 @@
#define MTX_GL_SCALE_Y(y,w,v1,v2) ((v1) - (((((y) / (w)) + 1.0f) / 2.0f) * (v1)) + (v2)) #define MTX_GL_SCALE_Y(y,w,v1,v2) ((v1) - (((((y) / (w)) + 1.0f) / 2.0f) * (v1)) + (v2))
#define MTX_GL_SCALE_Z(z,w,v1,v2) (MTX_GL_SCALE_X ((z), (w), (v1), (v2))) #define MTX_GL_SCALE_Z(z,w,v1,v2) (MTX_GL_SCALE_X ((z), (w), (v1), (v2)))
#define ROUND_TO_256THS(x) (roundf ((x) * 256) / 256)
void void
_clutter_util_fully_transform_vertices (const CoglMatrix *modelview, _clutter_util_fully_transform_vertices (const CoglMatrix *modelview,
const CoglMatrix *projection, const CoglMatrix *projection,
@ -99,10 +101,14 @@ _clutter_util_fully_transform_vertices (const CoglMatrix *modelview,
ClutterVertex4 vertex_tmp = vertices_tmp[i]; ClutterVertex4 vertex_tmp = vertices_tmp[i];
graphene_point3d_t *vertex_out = &vertices_out[i]; graphene_point3d_t *vertex_out = &vertices_out[i];
/* Finally translate from OpenGL coords to window coords */ /* Finally translate from OpenGL coords to window coords */
vertex_out->x = MTX_GL_SCALE_X (vertex_tmp.x, vertex_tmp.w, vertex_out->x = ROUND_TO_256THS (MTX_GL_SCALE_X (vertex_tmp.x,
viewport[2], viewport[0]); vertex_tmp.w,
vertex_out->y = MTX_GL_SCALE_Y (vertex_tmp.y, vertex_tmp.w, viewport[2],
viewport[3], viewport[1]); viewport[0]));
vertex_out->y = ROUND_TO_256THS (MTX_GL_SCALE_Y (vertex_tmp.y,
vertex_tmp.w,
viewport[3],
viewport[1]));
} }
} }