Update Wii U renderer

This commit is contained in:
Clownacy 2020-09-14 23:16:45 +01:00
parent 98f66444d7
commit e18ec87f99

View file

@ -41,7 +41,6 @@ typedef struct RenderBackend_Surface
size_t width; size_t width;
size_t height; size_t height;
bool render_target; bool render_target;
unsigned char *lock_buffer; // TODO - Dumb
} RenderBackend_Surface; } RenderBackend_Surface;
typedef struct RenderBackend_GlyphAtlas typedef struct RenderBackend_GlyphAtlas
@ -538,35 +537,18 @@ void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
(void)surface; (void)surface;
} }
unsigned char* RenderBackend_LockSurface(RenderBackend_Surface *surface, size_t *pitch, size_t width, size_t height) void RenderBackend_UploadSurface(RenderBackend_Surface *surface, const unsigned char *pixels, size_t width, size_t height)
{ {
if (surface != NULL)
{
// Create a temporary RGB24 buffer (this backend uses RGBA32
// internally, so we can't just use a locked texture)
surface->lock_buffer = (unsigned char*)malloc(width * height * 3);
*pitch = width * 3;
return surface->lock_buffer;
}
return NULL;
}
void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, size_t width, size_t height)
{
if (surface != NULL)
{
if (surface->lock_buffer != NULL)
{
// Convert from RGB24 to RGBA32, and upload it to the GPU texture // Convert from RGB24 to RGBA32, and upload it to the GPU texture
unsigned char *buffer = (unsigned char*)GX2RLockSurfaceEx(&surface->texture.surface, 0, (GX2RResourceFlags)0); unsigned char *buffer = (unsigned char*)GX2RLockSurfaceEx(&surface->texture.surface, 0, (GX2RResourceFlags)0);
const unsigned char *in_pointer = surface->lock_buffer; if (buffer != NULL)
{
const unsigned char *in_pointer = pixels;
for (size_t y = 0; y < height; ++y) for (size_t y = 0; y < height; ++y)
{ {
unsigned char *out_pointer = &buffer[surface->texture.surface.pitch * 4 * y]; unsigned char *out_pointer = &buffer[y * surface->texture.surface.pitch * 4];
for (size_t x = 0; x < width; ++x) for (size_t x = 0; x < width; ++x)
{ {
@ -577,11 +559,8 @@ void RenderBackend_UnlockSurface(RenderBackend_Surface *surface, size_t width, s
} }
} }
free(surface->lock_buffer);
GX2RUnlockSurfaceEx(&surface->texture.surface, 0, (GX2RResourceFlags)0); GX2RUnlockSurfaceEx(&surface->texture.surface, 0, (GX2RResourceFlags)0);
} }
}
} }
void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RenderBackend_Rect *rect, RenderBackend_Surface *destination_surface, long x, long y, bool colour_key) void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RenderBackend_Rect *rect, RenderBackend_Surface *destination_surface, long x, long y, bool colour_key)