@@ -330,9 +330,10 @@ static inline int unswizzle(PSP_Texture *psp_tex)
330
330
return 1 ;
331
331
}
332
332
333
- static inline void prepareTextureForUpload (PSP_Texture * psp_tex )
333
+ static inline void prepareTextureForUpload (SDL_Texture * texture )
334
334
{
335
- if (psp_tex -> swizzled )
335
+ PSP_Texture * psp_tex = (PSP_Texture * )texture -> driverdata ;
336
+ if (texture -> access != SDL_TEXTUREACCESS_STATIC || psp_tex -> swizzled )
336
337
return ;
337
338
338
339
psp_tex -> swizzledData = vramalloc (psp_tex -> swizzledSize );
@@ -348,9 +349,11 @@ static inline void prepareTextureForUpload(PSP_Texture *psp_tex)
348
349
sceKernelDcacheWritebackRange (psp_tex -> swizzledData , psp_tex -> swizzledSize );
349
350
}
350
351
351
- static inline void prepareTextureForDownload (PSP_Texture * psp_tex )
352
+ static inline void prepareTextureForDownload (SDL_Texture * texture )
352
353
{
353
- if (!psp_tex -> swizzled )
354
+ PSP_Texture * psp_tex = (PSP_Texture * )texture -> driverdata ;
355
+
356
+ if (texture -> access != SDL_TEXTUREACCESS_STATIC || !psp_tex -> swizzled )
354
357
return ;
355
358
356
359
psp_tex -> data = SDL_malloc (psp_tex -> size );
@@ -389,13 +392,21 @@ static int PSP_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
389
392
psp_tex -> swizzledPitch = psp_tex -> swizzledWidth * SDL_BYTESPERPIXEL (texture -> format );
390
393
psp_tex -> size = getMemorySize (psp_tex -> width , psp_tex -> height , psp_tex -> format );
391
394
psp_tex -> swizzledSize = getMemorySize (psp_tex -> swizzledWidth , psp_tex -> swizzledHeight , psp_tex -> format );
392
- psp_tex -> data = SDL_calloc (1 , psp_tex -> size );
393
- psp_tex -> swizzled = GU_FALSE ;
394
395
395
- if (!psp_tex -> data ) {
396
- SDL_free (psp_tex );
397
- return SDL_OutOfMemory ();
396
+ if (texture -> access != SDL_TEXTUREACCESS_STATIC ) {
397
+ psp_tex -> data = vramalloc (psp_tex -> size );
398
+ if (!psp_tex -> data ) {
399
+ vfree (psp_tex );
400
+ return SDL_OutOfMemory ();
401
+ }
402
+ } else {
403
+ psp_tex -> data = SDL_calloc (1 , psp_tex -> size );
404
+ if (!psp_tex -> data ) {
405
+ SDL_free (psp_tex );
406
+ return SDL_OutOfMemory ();
407
+ }
398
408
}
409
+ psp_tex -> swizzled = GU_FALSE ;
399
410
400
411
texture -> driverdata = psp_tex ;
401
412
@@ -408,7 +419,7 @@ static int PSP_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
408
419
PSP_Texture * psp_tex = (PSP_Texture * )texture -> driverdata ;
409
420
410
421
// How a pointer to the texture data is returned it need to be unswizzled before it can be used
411
- prepareTextureForDownload (psp_tex );
422
+ prepareTextureForDownload (texture );
412
423
413
424
* pixels =
414
425
(void * )((Uint8 * )psp_tex -> data + rect -> y * psp_tex -> width * SDL_BYTESPERPIXEL (texture -> format ) +
@@ -741,6 +752,7 @@ static inline int PSP_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd
741
752
static inline int PSP_RenderGeometry (SDL_Renderer * renderer , void * vertices , SDL_RenderCommand * cmd )
742
753
{
743
754
PSP_RenderData * data = (PSP_RenderData * )renderer -> driverdata ;
755
+ SDL_Texture * texture = cmd -> data .draw .texture ;
744
756
const size_t count = cmd -> data .draw .count ;
745
757
PSP_BlendInfo blendInfo = {
746
758
.mode = cmd -> data .draw .blend ,
@@ -749,12 +761,13 @@ static inline int PSP_RenderGeometry(SDL_Renderer *renderer, void *vertices, SDL
749
761
750
762
PSP_SetBlendMode (data , blendInfo );
751
763
752
- if (cmd -> data . draw . texture ) {
764
+ if (texture ) {
753
765
uint32_t tbw , twp ;
754
766
const VertTCV * verts = (VertTCV * )(vertices + cmd -> data .draw .first );
755
- PSP_Texture * psp_tex = (PSP_Texture * )cmd -> data .draw .texture -> driverdata ;
767
+
768
+ PSP_Texture * psp_tex = (PSP_Texture * )texture -> driverdata ;
756
769
757
- prepareTextureForUpload (psp_tex );
770
+ prepareTextureForUpload (texture );
758
771
759
772
tbw = psp_tex -> swizzled ? psp_tex -> swizzledWidth : psp_tex -> width ;
760
773
twp = psp_tex -> swizzled ? psp_tex -> swizzledData : psp_tex -> data ;
@@ -826,7 +839,8 @@ static inline int PSP_RenderCopy(SDL_Renderer *renderer, void *vertices, SDL_Ren
826
839
{
827
840
uint32_t tbw , twp ;
828
841
PSP_RenderData * data = (PSP_RenderData * )renderer -> driverdata ;
829
- PSP_Texture * psp_tex = (PSP_Texture * )cmd -> data .draw .texture -> driverdata ;
842
+ SDL_Texture * texture = cmd -> data .draw .texture ;
843
+ PSP_Texture * psp_tex = (PSP_Texture * )texture -> driverdata ;
830
844
const size_t count = cmd -> data .draw .count ;
831
845
const VertTV * verts = (VertTV * )(vertices + cmd -> data .draw .first );
832
846
const PSP_BlendInfo blendInfo = {
@@ -836,7 +850,7 @@ static inline int PSP_RenderCopy(SDL_Renderer *renderer, void *vertices, SDL_Ren
836
850
837
851
PSP_SetBlendMode (data , blendInfo );
838
852
839
- prepareTextureForUpload (psp_tex );
853
+ prepareTextureForUpload (texture );
840
854
841
855
tbw = psp_tex -> swizzled ? psp_tex -> textureWidth : psp_tex -> width ;
842
856
twp = psp_tex -> swizzled ? psp_tex -> swizzledData : psp_tex -> data ;
@@ -965,7 +979,11 @@ static void PSP_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture)
965
979
}
966
980
967
981
vfree (psp_tex -> swizzledData );
968
- SDL_free (psp_tex -> data );
982
+ if (texture -> access != SDL_TEXTUREACCESS_STATIC ) {
983
+ vfree (psp_tex -> data );
984
+ } else {
985
+ SDL_free (psp_tex -> data );
986
+ }
969
987
SDL_free (psp_tex );
970
988
texture -> driverdata = NULL ;
971
989
}
0 commit comments