From 7031791376ddd98c7c1358d07b12871be14bd6c8 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Thu, 22 Jan 2009 17:42:26 +0000 Subject: [PATCH] Fix some failures from the fixed-to-float script in cogl-texture The script converted calls to COGL_FIXED_MUL(x,y) to (x*y). However this fails for cases like this: COGL_FIXED_MUL(a + b, c) which become (a + b * c) The meaning of this is of course different because multiplication has a higher precedence than addition. This was causing breakages in cogl_texture_quad_sw when the vertex coordinates are not in increasing order. This was the case in test-backface-culling when NPOTs are not available. --- gl/cogl-texture.c | 20 ++++++++------------ gles/cogl-texture.c | 20 ++++++++------------ 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/gl/cogl-texture.c b/gl/cogl-texture.c index 84a0dfd16..8516e5fd2 100644 --- a/gl/cogl-texture.c +++ b/gl/cogl-texture.c @@ -2072,8 +2072,8 @@ _cogl_texture_quad_sw (CoglTexture *tex, tw = (float)(tex->bitmap.width); th = (float)(tex->bitmap.height); - tqx = (x2 - x1 / (tw * (tx2 - tx1))); - tqy = (y2 - y1 / (th * (ty2 - ty1))); + tqx = (x2 - x1) / (tw * (tx2 - tx1)); + tqy = (y2 - y1) / (th * (ty2 - ty1)); /* Integral texture coordinate for first tile */ first_tx = (float)(floorf (tx1)); @@ -2088,8 +2088,8 @@ _cogl_texture_quad_sw (CoglTexture *tex, ty2 = (ty2 * th); /* Quad coordinate of the first tile */ - first_qx = x1 - (tx1 - first_tx * tqx); - first_qy = y1 - (ty1 - first_ty * tqy); + first_qx = x1 - (tx1 - first_tx) * tqx; + first_qy = y1 - (ty1 - first_ty) * tqy; /* Iterate until whole quad height covered */ @@ -2102,11 +2102,9 @@ _cogl_texture_quad_sw (CoglTexture *tex, if (!iter_y.intersects) continue; /* Span-quad intersection in quad coordinates */ - slice_qy1 = first_qy + - (iter_y.intersect_start - first_ty * tqy); + slice_qy1 = first_qy + (iter_y.intersect_start - first_ty) * tqy; - slice_qy2 = first_qy + - (iter_y.intersect_end - first_ty * tqy); + slice_qy2 = first_qy + (iter_y.intersect_end - first_ty) * tqy; /* Localize slice texture coordinates */ slice_ty1 = iter_y.intersect_start - iter_y.pos; @@ -2130,11 +2128,9 @@ _cogl_texture_quad_sw (CoglTexture *tex, if (!iter_x.intersects) continue; /* Span-quad intersection in quad coordinates */ - slice_qx1 = first_qx + - (iter_x.intersect_start - first_tx * tqx); + slice_qx1 = first_qx + (iter_x.intersect_start - first_tx) * tqx; - slice_qx2 = first_qx + - (iter_x.intersect_end - first_tx * tqx); + slice_qx2 = first_qx + (iter_x.intersect_end - first_tx) * tqx; /* Localize slice texture coordinates */ slice_tx1 = iter_x.intersect_start - iter_x.pos; diff --git a/gles/cogl-texture.c b/gles/cogl-texture.c index 07ebb23a3..84d51685e 100644 --- a/gles/cogl-texture.c +++ b/gles/cogl-texture.c @@ -2202,8 +2202,8 @@ _cogl_texture_quad_sw (CoglTexture *tex, tw = (float)(tex->bitmap.width); th = (float)(tex->bitmap.height); - tqx = (x2 - x1 / (tw * (tx2 - tx1))); - tqy = (y2 - y1 / (th * (ty2 - ty1))); + tqx = (x2 - x1) / (tw * (tx2 - tx1)); + tqy = (y2 - y1) / (th * (ty2 - ty1)); /* Integral texture coordinate for first tile */ first_tx = (float)(floorf (tx1)); @@ -2218,8 +2218,8 @@ _cogl_texture_quad_sw (CoglTexture *tex, ty2 = (ty2 * th); /* Quad coordinate of the first tile */ - first_qx = x1 - (tx1 - first_tx * tqx); - first_qy = y1 - (ty1 - first_ty * tqy); + first_qx = x1 - (tx1 - first_tx) * tqx; + first_qy = y1 - (ty1 - first_ty) * tqy; /* Iterate until whole quad height covered */ @@ -2232,11 +2232,9 @@ _cogl_texture_quad_sw (CoglTexture *tex, if (!iter_y.intersects) continue; /* Span-quad intersection in quad coordinates */ - slice_qy1 = first_qy + - (iter_y.intersect_start - first_ty * tqy); + slice_qy1 = first_qy + (iter_y.intersect_start - first_ty) * tqy; - slice_qy2 = first_qy + - (iter_y.intersect_end - first_ty * tqy); + slice_qy2 = first_qy + (iter_y.intersect_end - first_ty) * tqy; /* Localize slice texture coordinates */ slice_ty1 = iter_y.intersect_start - iter_y.pos; @@ -2257,11 +2255,9 @@ _cogl_texture_quad_sw (CoglTexture *tex, if (!iter_x.intersects) continue; /* Span-quad intersection in quad coordinates */ - slice_qx1 = first_qx + - (iter_x.intersect_start - first_tx * tqx); + slice_qx1 = first_qx + (iter_x.intersect_start - first_tx) * tqx; - slice_qx2 = first_qx + - (iter_x.intersect_end - first_tx * tqx); + slice_qx2 = first_qx + (iter_x.intersect_end - first_tx) * tqx; /* Localize slice texture coordinates */ slice_tx1 = iter_x.intersect_start - iter_x.pos;