Skip to content

Commit

Permalink
ogc: support rendering to transparent textures (#47)
Browse files Browse the repository at this point in the history
Switch the EFB format to an alpha-enabled one when the texture we are
asked to render to has an alpha channel. This fixes handling of
transparency in the VVVVVV game, which makes extensive use of rendering
to textures.
  • Loading branch information
mardy authored Jan 22, 2024
1 parent b5387b7 commit 223d7c5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/render/ogc/SDL_render_ogc.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef struct
GXColor clear_color;
int ops_after_present;
bool vsync;
u8 efb_pixel_format;
} OGC_RenderData;

typedef struct
Expand Down Expand Up @@ -187,6 +188,7 @@ static void OGC_SetTextureScaleMode(SDL_Renderer *renderer,
static int OGC_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
{
OGC_RenderData *data = renderer->driverdata;
u8 desired_efb_pixel_format = GX_PF_RGB8_Z24;

if (texture) {
if (texture->w > MAX_EFB_WIDTH || texture->h > MAX_EFB_HEIGHT) {
Expand All @@ -205,7 +207,17 @@ static int OGC_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture)
SDL_LogWarn(SDL_LOG_CATEGORY_RENDER,
"Render target set after drawing!");
}

if (SDL_ISPIXELFORMAT_ALPHA(texture->format)) {
desired_efb_pixel_format = GX_PF_RGBA6_Z24;
}
}

if (desired_efb_pixel_format != data->efb_pixel_format) {
data->efb_pixel_format = desired_efb_pixel_format;
GX_SetPixelFmt(data->efb_pixel_format, GX_ZC_LINEAR);
}

return 0;
}

Expand Down Expand Up @@ -581,6 +593,7 @@ static SDL_Renderer *OGC_CreateRenderer(SDL_Window *window, Uint32 flags)
return NULL;
}

data->efb_pixel_format = GX_PF_RGB8_Z24;
data->current_blend_mode = SDL_BLENDMODE_NONE;
data->vsync = true;

Expand Down

0 comments on commit 223d7c5

Please sign in to comment.