Skip to content

Commit 6e831bc

Browse files
committed
Fixed some textures not being renderer properly
1 parent c4ee32b commit 6e831bc

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/render/psp/SDL_render_psp.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ static int PixelFormatToPSPFMT(Uint32 format)
132132
}
133133
}
134134

135+
static int calculatePitchForTextureFormat(int width, int format)
136+
{
137+
switch (format) {
138+
case GU_PSM_5650:
139+
case GU_PSM_5551:
140+
case GU_PSM_4444:
141+
return (width + 7) & ~7;
142+
case GU_PSM_8888:
143+
return (width + 3) & ~3;
144+
default:
145+
return width;
146+
}
147+
}
148+
135149
/* Return next power of 2 */
136150
static int TextureNextPow2(unsigned int w)
137151
{
@@ -159,11 +173,11 @@ static int PSP_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
159173
return SDL_OutOfMemory();
160174
}
161175

162-
psp_tex->width = texture->w;
176+
psp_tex->format = PixelFormatToPSPFMT(texture->format);
177+
psp_tex->width = calculatePitchForTextureFormat(texture->w, psp_tex->format);
163178
psp_tex->height = texture->h;
164179
psp_tex->textureWidth = TextureNextPow2(texture->w);
165180
psp_tex->textureHeight = TextureNextPow2(texture->h);
166-
psp_tex->format = PixelFormatToPSPFMT(texture->format);
167181
psp_tex->data = SDL_calloc(1, getMemorySize(psp_tex->width, psp_tex->height, psp_tex->format));
168182

169183
if (!psp_tex->data) {
@@ -468,7 +482,7 @@ static int PSP_RenderGeometry(SDL_Renderer *renderer, void *vertices, SDL_Render
468482
sceGuEnable(GU_TEXTURE_2D);
469483
sceGuTexMode(psp_tex->format, 0, 0, GU_FALSE);
470484
sceGuTexFilter(psp_tex->filter, psp_tex->filter);
471-
sceGuTexImage(0, psp_tex->textureWidth, psp_tex->textureHeight, psp_tex->textureWidth, psp_tex->data);
485+
sceGuTexImage(0, psp_tex->textureWidth, psp_tex->textureHeight, psp_tex->width, psp_tex->data);
472486
sceGuDrawArray(GU_TRIANGLES, GU_TEXTURE_32BITF | GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_2D, count, 0, verts);
473487
sceGuDisable(GU_TEXTURE_2D);
474488
} else {

0 commit comments

Comments
 (0)