Don't access CoglMatrix struct fields

Instead, use the new cogl_matrix_get_value() API.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1439
This commit is contained in:
Georges Basile Stavracas Neto 2020-09-09 22:16:25 -03:00
parent 8e125fbab6
commit 55b05e5631
3 changed files with 31 additions and 15 deletions

View File

@ -673,6 +673,7 @@ _cogl_util_get_eye_planes_for_screen_poly (float *polygon,
Vector4 *poly;
graphene_vec3_t b;
graphene_vec3_t c;
float wz, ww;
int count;
tmp_poly = g_alloca (sizeof (Vector4) * n_vertices * 2);
@ -693,7 +694,9 @@ _cogl_util_get_eye_planes_for_screen_poly (float *polygon,
* frustum; coordinates range from [-Wc,Wc] left to right on the
* x-axis and [Wc,-Wc] top to bottom on the y-axis.
*/
Wc = DEPTH * projection->wz + projection->ww;
wz = cogl_matrix_get_value (projection, 3, 2);
ww = cogl_matrix_get_value (projection, 3, 3);
Wc = DEPTH * wz + ww;
#define CLIP_X(X) ((((float)X - viewport[0]) * (2.0 / viewport[2])) - 1) * Wc
#define CLIP_Y(Y) ((((float)Y - viewport[1]) * (2.0 / viewport[3])) - 1) * -Wc
@ -706,7 +709,7 @@ _cogl_util_get_eye_planes_for_screen_poly (float *polygon,
tmp_poly[i].w = Wc;
}
Wc = DEPTH * 2 * projection->wz + projection->ww;
Wc = DEPTH * 2 * wz + ww;
/* FIXME: technically we don't need to project all of the points
* twice, it would be enough project every other point since

View File

@ -249,6 +249,9 @@ get_paint_level (ClutterPaintContext *paint_context,
{
CoglFramebuffer *framebuffer;
CoglMatrix projection, modelview, pm;
float xx, xy, xw;
float yx, yy, yw;
float wx, wy, ww;
float v[4];
double viewport_width, viewport_height;
double u0, v0;
@ -280,6 +283,16 @@ get_paint_level (ClutterPaintContext *paint_context,
cogl_matrix_multiply (&pm, &projection, &modelview);
xx = cogl_matrix_get_value (&pm, 0, 0);
xy = cogl_matrix_get_value (&pm, 0, 1);
xw = cogl_matrix_get_value (&pm, 0, 3);
yx = cogl_matrix_get_value (&pm, 1, 0);
yy = cogl_matrix_get_value (&pm, 1, 1);
yw = cogl_matrix_get_value (&pm, 1, 3);
wx = cogl_matrix_get_value (&pm, 3, 0);
wy = cogl_matrix_get_value (&pm, 3, 1);
ww = cogl_matrix_get_value (&pm, 3, 3);
cogl_framebuffer_get_viewport4fv (framebuffer, v);
viewport_width = v[2];
viewport_height = v[3];
@ -287,9 +300,9 @@ get_paint_level (ClutterPaintContext *paint_context,
u0 = width / 2.;
v0 = height / 2.;
xc = pm.xx * u0 + pm.xy * v0 + pm.xw;
yc = pm.yx * u0 + pm.yy * v0 + pm.yw;
wc = pm.wx * u0 + pm.wy * v0 + pm.ww;
xc = xx * u0 + xy * v0 + xw;
yc = yx * u0 + yy * v0 + yw;
wc = wx * u0 + wy * v0 + ww;
/* We'll simplify the equations below for a bit of micro-optimization.
* The commented out code is the unsimplified version.
@ -302,10 +315,10 @@ get_paint_level (ClutterPaintContext *paint_context,
// with respect to u, v, using
// d(a/b)/dx = da/dx * (1/b) - a * db/dx / (b^2)
dxdu = 0.5 * viewport_width * (pm.xx - pm.wx * (xc/wc)) / wc;
dxdv = 0.5 * viewport_width * (pm.xy - pm.wy * (xc/wc)) / wc;
dydu = 0.5 * viewport_height * (pm.yx - pm.wx * (yc/wc)) / wc;
dydv = 0.5 * viewport_height * (pm.yy - pm.wy * (yc/wc)) / wc;
dxdu = 0.5 * viewport_width * (xx - wx * (xc/wc)) / wc;
dxdv = 0.5 * viewport_width * (xy - wy * (xc/wc)) / wc;
dydu = 0.5 * viewport_height * (yx - wx * (yc/wc)) / wc;
dydv = 0.5 * viewport_height * (yy - wy * (yc/wc)) / wc;
// Compute the inverse partials as the matrix inverse
det = dxdu * dydv - dxdv * dydu;
@ -324,10 +337,10 @@ get_paint_level (ClutterPaintContext *paint_context,
*/
/* dxdu * wc, etc */
dxdu_ = 0.5 * viewport_width * (pm.xx - pm.wx * (xc/wc));
dxdv_ = 0.5 * viewport_width * (pm.xy - pm.wy * (xc/wc));
dydu_ = 0.5 * viewport_height * (pm.yx - pm.wx * (yc/wc));
dydv_ = 0.5 * viewport_height * (pm.yy - pm.wy * (yc/wc));
dxdu_ = 0.5 * viewport_width * (xx - wx * (xc/wc));
dxdv_ = 0.5 * viewport_width * (xy - wy * (xc/wc));
dydu_ = 0.5 * viewport_height * (yx - wx * (yc/wc));
dydv_ = 0.5 * viewport_height * (yy - wy * (yc/wc));
/* det * wc^2 */
det_ = dxdu_ * dydv_ - dxdv_ * dydu_;
@ -340,7 +353,7 @@ get_paint_level (ClutterPaintContext *paint_context,
lambda = 0.5 * M_LOG2E * log (rho_sq * wc * wc / det_sq) + LOD_BIAS;
#if 0
g_print ("%g %g %g\n", 0.5 * viewport_width * pm.xx / pm.ww, 0.5 * viewport_height * pm.yy / pm.ww, lambda);
g_print ("%g %g %g\n", 0.5 * viewport_width * xx / ww, 0.5 * viewport_height * yy / ww, lambda);
#endif
if (lambda <= 0.)

View File

@ -232,7 +232,7 @@ setup_viewport (CoglFramebuffer *framebuffer,
*/
cogl_framebuffer_get_projection_matrix (framebuffer, &projection_matrix);
z_camera = 0.5 * projection_matrix.xx;
z_camera = 0.5 * cogl_matrix_get_value (&projection_matrix, 0, 0);
cogl_matrix_init_identity (&mv_matrix);
cogl_matrix_translate (&mv_matrix, -0.5f, -0.5f, -z_camera);