Skip to content

Commit b31b288

Browse files
committed
Fix the slice calculation
1 parent f2df1b2 commit b31b288

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/render/psp/SDL_render_psp.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,37 +260,39 @@ static int calculateBestSliceSizeForTexture(SDL_Texture *texture, SliceSize *uvS
260260
static void fillSpriteVertices(VertTV *vertices, SliceSize *dimensions, SliceSize *sliceSize,
261261
const SDL_Rect *srcrect, const SDL_FRect *dstrect) {
262262
int i, j;
263-
float dstrectSlizeWidth = dstrect->w / dimensions->width;
264-
float dstrectSlizeHeight = dstrect->h / dimensions->height;
265263
int remainingWidth = srcrect->w % sliceSize->width;
266264
int remainingHeight = srcrect->h % sliceSize->height;
267265
int hasRemainingWidth = remainingWidth > 0;
268266
int hasRemainingHeight = remainingHeight > 0;
267+
float dstrectRateWidth = (float)(abs(dstrect->w - dimensions->width)) / (float)(abs(srcrect->w - dimensions->width));
268+
float dstrectRateHeight = (float)(abs(dstrect->h - dimensions->height)) / (float)(abs(srcrect->h - dimensions->height));
269269

270270
int verticesCount = dimensions->width * dimensions->height * 2;
271271
for (i = 0; i < dimensions->width; i++) {
272272
for (j = 0; j < dimensions->height; j++) {
273273
uint8_t currentIndex = (i * dimensions->height + j) * 2;
274274
vertices[currentIndex].u = srcrect->x + i * sliceSize->width;
275275
vertices[currentIndex].v = srcrect->y + j * sliceSize->height;
276-
vertices[currentIndex].x = dstrect->x + i * dstrectSlizeWidth;
277-
vertices[currentIndex].y = dstrect->y + j * dstrectSlizeHeight;
276+
vertices[currentIndex].x = dstrect->x + i * sliceSize->width * dstrectRateWidth;
277+
vertices[currentIndex].y = dstrect->y + j * sliceSize->height * dstrectRateHeight;
278278
vertices[currentIndex].z = 0;
279279

280280
if (i == dimensions->width - 1 && hasRemainingWidth) {
281281
vertices[currentIndex + 1].u = srcrect->x + i * sliceSize->width + remainingWidth;
282+
vertices[currentIndex + 1].x = dstrect->x + i * (sliceSize->width * dstrectRateWidth) + remainingWidth * dstrectRateWidth;
282283
} else {
283284
vertices[currentIndex + 1].u = (srcrect->x + (i +1) * sliceSize->width);
285+
vertices[currentIndex + 1].x = dstrect->x + (i + 1) * sliceSize->width * dstrectRateWidth;
284286
}
285287

286288
if (j == dimensions->height - 1 && hasRemainingHeight) {
287289
vertices[currentIndex + 1].v = srcrect->y + j * sliceSize->height + remainingHeight;
290+
vertices[currentIndex + 1].y = dstrect->y + j * sliceSize->height * dstrectRateHeight + remainingHeight * dstrectRateHeight;
288291
} else {
289292
vertices[currentIndex + 1].v = (srcrect->y + (j + 1) * sliceSize->height);
293+
vertices[currentIndex + 1].y = dstrect->y + (j + 1) * sliceSize->height * dstrectRateHeight;
290294
}
291295

292-
vertices[currentIndex + 1].x = dstrect->x + (i + 1) * dstrectSlizeWidth;
293-
vertices[currentIndex + 1].y = dstrect->y + (j + 1) * dstrectSlizeHeight;
294296
vertices[currentIndex + 1].z = 0;
295297
}
296298
}
@@ -518,8 +520,8 @@ static int PSP_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Tex
518520
// We need to split in slices because we have a texture bigger than 64 pixel width
519521
if (texture) {
520522
SliceSize sliceSize, sliceDimension, uvSize;
521-
uvSize.width = abs(u1) - abs(u0);
522-
uvSize.height = abs(v1) - abs(v0);
523+
uvSize.width = abs(u1 - u0);
524+
uvSize.height = abs(v1 - v0);
523525
if (calculateBestSliceSizeForTexture(texture, &uvSize, &sliceSize, &sliceDimension))
524526
return -1;
525527

0 commit comments

Comments
 (0)