3DS - Fix corrupted graphics on real hardware

This commit is contained in:
Clownacy 2020-10-13 21:12:46 +01:00
parent a82189b0c9
commit e45ee3c189

View file

@ -251,15 +251,18 @@ void RenderBackend_UploadSurface(RenderBackend_Surface *surface, const unsigned
frame_started = false;
}
unsigned char *abgr_buffer = (unsigned char*)linearAlloc(width * height * 4);
unsigned char *abgr_buffer = (unsigned char*)linearAlloc(surface->texture.width * surface->texture.height * 4);
if (abgr_buffer != NULL)
{
const unsigned char *src = pixels;
unsigned char *dst = abgr_buffer;
// Convert from colour-keyed RGB to ABGR
for (size_t i = 0; i < width * height; ++i)
for (size_t h = 0; h < height; ++h)
{
unsigned char *dst = &abgr_buffer[h * surface->texture.width * 4];
for (size_t w = 0; w < width; ++w)
{
unsigned char r = *src++;
unsigned char g = *src++;
@ -270,11 +273,11 @@ void RenderBackend_UploadSurface(RenderBackend_Surface *surface, const unsigned
*dst++ = g;
*dst++ = r;
}
}
// ensure data is in physical ram
GSPGPU_FlushDataCache(abgr_buffer, width * height * 4);
GSPGPU_FlushDataCache(abgr_buffer, surface->texture.width * surface->texture.height * 4);
C3D_SyncDisplayTransfer((u32*)abgr_buffer, GX_BUFFER_DIM(width, height), (u32*)surface->texture.data, GX_BUFFER_DIM(surface->texture.width, surface->texture.height), TEXTURE_TRANSFER_FLAGS);
C3D_SyncDisplayTransfer((u32*)abgr_buffer, GX_BUFFER_DIM(surface->texture.width, surface->texture.height), (u32*)surface->texture.data, GX_BUFFER_DIM(surface->texture.width, surface->texture.height), TEXTURE_TRANSFER_FLAGS);
linearFree(abgr_buffer);
}