Skip to content

Commit f8f5c8a

Browse files
committed
Render to target looks to work fine now
1 parent fd95e72 commit f8f5c8a

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

src/render/psp/SDL_render_psp.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ typedef struct
4545
void *frontbuffer; /**< main screen buffer */
4646
void *backbuffer; /**< buffer presented to display */
4747
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 */
4849
uint64_t drawColor;
4950
PSP_BlendInfo blendInfo; /**< current blend info */
5051
uint8_t vsync; /* 0 (Disabled), 1 (Enabled), 2 (Dynamic) */
@@ -184,6 +185,16 @@ static inline int calculatePitchForTextureFormat(int width, int format)
184185
}
185186
}
186187

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+
187198
static inline int calculateHeightForSwizzledTexture(int height, int format)
188199
{
189200
switch (format) {
@@ -215,7 +226,7 @@ static inline int calculateBestSliceSizeForSprite(SDL_Renderer *renderer, const
215226
// We split in blocks of (64 x destiny height) when 16 bits per color
216227
// or (32 x destiny height) when 32 bits per color
217228

218-
switch (data->drawBufferFormat) {
229+
switch (data->currentDrawBufferFormat) {
219230
case GU_PSM_5650:
220231
case GU_PSM_5551:
221232
case GU_PSM_4444:
@@ -384,7 +395,7 @@ static int PSP_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
384395
psp_tex->format = pixelFormatToPSPFMT(texture->format);
385396
psp_tex->textureWidth = calculateNextPow2(texture->w);
386397
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);
388399
psp_tex->height = texture->h;
389400
psp_tex->pitch = psp_tex->width * SDL_BYTESPERPIXEL(texture->format);
390401
psp_tex->swizzledWidth = psp_tex->textureWidth;
@@ -476,6 +487,22 @@ static void PSP_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture
476487
psp_tex->filter = guScaleMode;
477488
}
478489

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+
479506
static int PSP_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
480507
{
481508
return 0; /* nothing to do in this backend. */
@@ -1037,6 +1064,7 @@ static int PSP_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32
10371064

10381065
// Forcing for now using GU_PSM_4444
10391066
data->drawBufferFormat = GU_PSM_4444;
1067+
data->currentDrawBufferFormat = data->drawBufferFormat;
10401068

10411069
/* Specific GU init */
10421070
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
10481076
sceGuStart(GU_DIRECT, list);
10491077
sceGuDrawBuffer(data->drawBufferFormat, vrelptr(data->frontbuffer), PSP_FRAME_BUFFER_WIDTH);
10501078
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
10511080

10521081
sceGuOffset(2048 - (PSP_SCREEN_WIDTH >> 1), 2048 - (PSP_SCREEN_HEIGHT >> 1));
10531082
sceGuViewport(2048, 2048, PSP_SCREEN_WIDTH, PSP_SCREEN_HEIGHT);
@@ -1084,6 +1113,7 @@ static int PSP_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, Uint32
10841113
renderer->LockTexture = PSP_LockTexture;
10851114
renderer->UnlockTexture = PSP_UnlockTexture;
10861115
renderer->SetTextureScaleMode = PSP_SetTextureScaleMode;
1116+
renderer->SetRenderTarget = PSP_SetRenderTarget;
10871117
renderer->QueueSetViewport = PSP_QueueSetViewport;
10881118
renderer->QueueSetDrawColor = PSP_QueueSetViewport;
10891119
renderer->QueueDrawPoints = PSP_QueueDrawPoints;

0 commit comments

Comments
 (0)