@@ -132,6 +132,20 @@ static int PixelFormatToPSPFMT(Uint32 format)
132
132
}
133
133
}
134
134
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
+
135
149
/* Return next power of 2 */
136
150
static int TextureNextPow2 (unsigned int w )
137
151
{
@@ -159,11 +173,11 @@ static int PSP_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
159
173
return SDL_OutOfMemory ();
160
174
}
161
175
162
- psp_tex -> width = texture -> w ;
176
+ psp_tex -> format = PixelFormatToPSPFMT (texture -> format );
177
+ psp_tex -> width = calculatePitchForTextureFormat (texture -> w , psp_tex -> format );
163
178
psp_tex -> height = texture -> h ;
164
179
psp_tex -> textureWidth = TextureNextPow2 (texture -> w );
165
180
psp_tex -> textureHeight = TextureNextPow2 (texture -> h );
166
- psp_tex -> format = PixelFormatToPSPFMT (texture -> format );
167
181
psp_tex -> data = SDL_calloc (1 , getMemorySize (psp_tex -> width , psp_tex -> height , psp_tex -> format ));
168
182
169
183
if (!psp_tex -> data ) {
@@ -468,7 +482,7 @@ static int PSP_RenderGeometry(SDL_Renderer *renderer, void *vertices, SDL_Render
468
482
sceGuEnable (GU_TEXTURE_2D );
469
483
sceGuTexMode (psp_tex -> format , 0 , 0 , GU_FALSE );
470
484
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 );
472
486
sceGuDrawArray (GU_TRIANGLES , GU_TEXTURE_32BITF | GU_COLOR_8888 | GU_VERTEX_32BITF | GU_TRANSFORM_2D , count , 0 , verts );
473
487
sceGuDisable (GU_TEXTURE_2D );
474
488
} else {
0 commit comments