@@ -157,14 +157,17 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
157157
158158 for (uint32_t i = 0 ; i < mYCount ; i++) {
159159 float stepY = mYDivs [i];
160+ const float segment = stepY - previousStepY;
160161
161162 if (i & 1 ) {
162- const float segment = stepY - previousStepY;
163163 y2 = y1 + floorf (segment * stretchY + 0 .5f );
164164 } else {
165- y2 = y1 + stepY - previousStepY ;
165+ y2 = y1 + segment ;
166166 }
167- float v2 = fmax (0 .0f , stepY - 0 .5f ) / bitmapHeight;
167+
168+ float vOffset = y1 == y2 ? 0 .0f : 0.5 - (0.5 * segment / (y2 - y1));
169+ float v2 = fmax (0 .0f , stepY - vOffset) / bitmapHeight;
170+ v1 += vOffset / bitmapHeight;
168171
169172 if (stepY > 0 .0f ) {
170173#if DEBUG_EXPLODE_PATCHES
@@ -179,7 +182,7 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
179182 }
180183
181184 y1 = y2;
182- v1 = ( stepY + 0 . 5f ) / bitmapHeight;
185+ v1 = stepY / bitmapHeight;
183186
184187 previousStepY = stepY;
185188 }
@@ -190,8 +193,7 @@ void Patch::updateVertices(const float bitmapWidth, const float bitmapHeight,
190193 y1 += mYCount * EXPLODE_GAP;
191194 y2 += mYCount * EXPLODE_GAP;
192195#endif
193- generateRow (vertex, y1, y2, v1, 1 .0f , stretchX, right - left,
194- bitmapWidth, quadCount);
196+ generateRow (vertex, y1, y2, v1, 1 .0f , stretchX, right - left, bitmapWidth, quadCount);
195197 }
196198
197199 if (verticesCount > 0 ) {
@@ -220,14 +222,17 @@ void Patch::generateRow(TextureVertex*& vertex, float y1, float y2, float v1, fl
220222 // Generate the row quad by quad
221223 for (uint32_t i = 0 ; i < mXCount ; i++) {
222224 float stepX = mXDivs [i];
225+ const float segment = stepX - previousStepX;
223226
224227 if (i & 1 ) {
225- const float segment = stepX - previousStepX;
226228 x2 = x1 + floorf (segment * stretchX + 0 .5f );
227229 } else {
228- x2 = x1 + stepX - previousStepX ;
230+ x2 = x1 + segment ;
229231 }
230- float u2 = fmax (0 .0f , stepX - 0 .5f ) / bitmapWidth;
232+
233+ float uOffset = x1 == x2 ? 0 .0f : 0.5 - (0.5 * segment / (x2 - x1));
234+ float u2 = fmax (0 .0f , stepX - uOffset) / bitmapWidth;
235+ u1 += uOffset / bitmapWidth;
231236
232237 if (stepX > 0 .0f ) {
233238#if DEBUG_EXPLODE_PATCHES
@@ -241,7 +246,7 @@ void Patch::generateRow(TextureVertex*& vertex, float y1, float y2, float v1, fl
241246 }
242247
243248 x1 = x2;
244- u1 = ( stepX + 0 . 5f ) / bitmapWidth;
249+ u1 = stepX / bitmapWidth;
245250
246251 previousStepX = stepX;
247252 }
@@ -265,8 +270,8 @@ void Patch::generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, f
265270 if ((mColorKey >> oldQuadCount) & 0x1 ) {
266271#if DEBUG_PATCHES_EMPTY_VERTICES
267272 PATCH_LOGD (" quad %d (empty)" , oldQuadCount);
268- PATCH_LOGD (" left, top = %.2f, %.2f\t\t u1, v1 = %.2f , %.2f " , x1, y1, u1, v1);
269- PATCH_LOGD (" right, bottom = %.2f, %.2f\t\t u2, v2 = %.2f , %.2f " , x2, y2, u2, v2);
273+ PATCH_LOGD (" left, top = %.2f, %.2f\t\t u1, v1 = %.4f , %.4f " , x1, y1, u1, v1);
274+ PATCH_LOGD (" right, bottom = %.2f, %.2f\t\t u2, v2 = %.4f , %.4f " , x2, y2, u2, v2);
270275#endif
271276 return ;
272277 }
@@ -294,8 +299,8 @@ void Patch::generateQuad(TextureVertex*& vertex, float x1, float y1, float x2, f
294299
295300#if DEBUG_PATCHES_VERTICES
296301 PATCH_LOGD (" quad %d" , oldQuadCount);
297- PATCH_LOGD (" left, top = %.2f, %.2f\t\t u1, v1 = %.2f , %.2f " , x1, y1, u1, v1);
298- PATCH_LOGD (" right, bottom = %.2f, %.2f\t\t u2, v2 = %.2f , %.2f " , x2, y2, u2, v2);
302+ PATCH_LOGD (" left, top = %.2f, %.2f\t\t u1, v1 = %.4f , %.4f " , x1, y1, u1, v1);
303+ PATCH_LOGD (" right, bottom = %.2f, %.2f\t\t u2, v2 = %.4f , %.4f " , x2, y2, u2, v2);
299304#endif
300305}
301306
0 commit comments