@@ -45,6 +45,7 @@ typedef struct
45
45
void * frontbuffer ; /**< main screen buffer */
46
46
void * backbuffer ; /**< buffer presented to display */
47
47
uint8_t drawBufferFormat ; /**< GU_PSM_8888 or GU_PSM_5650 or GU_PSM_4444 */
48
+ uint8_t currentDrawBufferFormat ; /**< GU_PSM_8888 or GU_PSM_5650 or GU_PSM_4444 */
48
49
uint64_t drawColor ;
49
50
PSP_BlendInfo blendInfo ; /**< current blend info */
50
51
uint8_t vsync ; /* 0 (Disabled), 1 (Enabled), 2 (Dynamic) */
@@ -184,6 +185,16 @@ static inline int calculatePitchForTextureFormat(int width, int format)
184
185
}
185
186
}
186
187
188
+ static inline int calculatePitchForTextureFormatAndAccess (int width , int format , int access )
189
+ {
190
+ if (access == SDL_TEXTUREACCESS_TARGET ) {
191
+ // Round up to 64 bytes because it is required to be used by sceGuDrawBufferList
192
+ return (width + 63 ) & ~63 ;
193
+ } else {
194
+ return calculatePitchForTextureFormat (width , format );
195
+ }
196
+ }
197
+
187
198
static inline int calculateHeightForSwizzledTexture (int height , int format )
188
199
{
189
200
switch (format ) {
@@ -215,7 +226,7 @@ static inline int calculateBestSliceSizeForSprite(SDL_Renderer *renderer, const
215
226
// We split in blocks of (64 x destiny height) when 16 bits per color
216
227
// or (32 x destiny height) when 32 bits per color
217
228
218
- switch (data -> drawBufferFormat ) {
229
+ switch (data -> currentDrawBufferFormat ) {
219
230
case GU_PSM_5650 :
220
231
case GU_PSM_5551 :
221
232
case GU_PSM_4444 :
@@ -384,7 +395,7 @@ static int PSP_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
384
395
psp_tex -> format = pixelFormatToPSPFMT (texture -> format );
385
396
psp_tex -> textureWidth = calculateNextPow2 (texture -> w );
386
397
psp_tex -> textureHeight = calculateNextPow2 (texture -> h );
387
- psp_tex -> width = calculatePitchForTextureFormat (texture -> w , psp_tex -> format );
398
+ psp_tex -> width = calculatePitchForTextureFormatAndAccess (texture -> w , psp_tex -> format , texture -> access );
388
399
psp_tex -> height = texture -> h ;
389
400
psp_tex -> pitch = psp_tex -> width * SDL_BYTESPERPIXEL (texture -> format );
390
401
psp_tex -> swizzledWidth = psp_tex -> textureWidth ;
@@ -476,6 +487,22 @@ static void PSP_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture
476
487
psp_tex -> filter = guScaleMode ;
477
488
}
478
489
490
+ static int PSP_SetRenderTarget (SDL_Renderer * renderer , SDL_Texture * texture )
491
+ {
492
+ PSP_RenderData * data = (PSP_RenderData * )renderer -> driverdata ;
493
+
494
+ if (texture ) {
495
+ PSP_Texture * psp_tex = (PSP_Texture * )texture -> driverdata ;
496
+ sceGuDrawBufferList (psp_tex -> format , vrelptr (psp_tex -> data ), psp_tex -> width );
497
+ data -> currentDrawBufferFormat = psp_tex -> format ;
498
+ } else {
499
+ sceGuDrawBufferList (data -> drawBufferFormat , vrelptr (data -> frontbuffer ), PSP_FRAME_BUFFER_WIDTH );
500
+ data -> currentDrawBufferFormat = data -> drawBufferFormat ;
501
+ }
502
+
503
+ return 0 ;
504
+ }
505
+
479
506
static int PSP_QueueSetViewport (SDL_Renderer * renderer , SDL_RenderCommand * cmd )
480
507
{
481
508
return 0 ; /* nothing to do in this backend. */
@@ -1037,6 +1064,7 @@ static int PSP_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32
1037
1064
1038
1065
// Forcing for now using GU_PSM_4444
1039
1066
data -> drawBufferFormat = GU_PSM_4444 ;
1067
+ data -> currentDrawBufferFormat = data -> drawBufferFormat ;
1040
1068
1041
1069
/* Specific GU init */
1042
1070
bufferSize = getMemorySize (PSP_FRAME_BUFFER_WIDTH , PSP_SCREEN_HEIGHT , data -> drawBufferFormat );
@@ -1048,6 +1076,7 @@ static int PSP_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32
1048
1076
sceGuStart (GU_DIRECT , list );
1049
1077
sceGuDrawBuffer (data -> drawBufferFormat , vrelptr (data -> frontbuffer ), PSP_FRAME_BUFFER_WIDTH );
1050
1078
sceGuDispBuffer (PSP_SCREEN_WIDTH , PSP_SCREEN_HEIGHT , vrelptr (data -> backbuffer ), PSP_FRAME_BUFFER_WIDTH );
1079
+ sceGuDepthBuffer (vrelptr (data -> backbuffer ), 0 ); // Set the depth buffer to the same space as the framebuffer
1051
1080
1052
1081
sceGuOffset (2048 - (PSP_SCREEN_WIDTH >> 1 ), 2048 - (PSP_SCREEN_HEIGHT >> 1 ));
1053
1082
sceGuViewport (2048 , 2048 , PSP_SCREEN_WIDTH , PSP_SCREEN_HEIGHT );
@@ -1084,6 +1113,7 @@ static int PSP_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32
1084
1113
renderer -> LockTexture = PSP_LockTexture ;
1085
1114
renderer -> UnlockTexture = PSP_UnlockTexture ;
1086
1115
renderer -> SetTextureScaleMode = PSP_SetTextureScaleMode ;
1116
+ renderer -> SetRenderTarget = PSP_SetRenderTarget ;
1087
1117
renderer -> QueueSetViewport = PSP_QueueSetViewport ;
1088
1118
renderer -> QueueSetDrawColor = PSP_QueueSetViewport ;
1089
1119
renderer -> QueueDrawPoints = PSP_QueueDrawPoints ;
0 commit comments