Remove some 3DS stuff

This commit is contained in:
John Lorentzson 2025-04-06 22:20:56 +02:00
parent d9cfb85346
commit 33b59f8219

View file

@ -40,13 +40,8 @@ RenderBackend_Surface* RenderBackend_Init(const char *window_title, size_t scree
if (WindowBackend_Software_CreateWindow(window_title, screen_width, screen_height, fullscreen)) if (WindowBackend_Software_CreateWindow(window_title, screen_width, screen_height, fullscreen))
{ {
framebuffer.pixels = WindowBackend_Software_GetFramebuffer(&framebuffer.pitch); framebuffer.pixels = WindowBackend_Software_GetFramebuffer(&framebuffer.pitch);
#ifdef __3DS__
framebuffer.width = screen_height;
framebuffer.height = screen_width;
#else
framebuffer.width = screen_width; framebuffer.width = screen_width;
framebuffer.height = screen_height; framebuffer.height = screen_height;
#endif
return &framebuffer; return &framebuffer;
} }
@ -88,15 +83,9 @@ RenderBackend_Surface* RenderBackend_CreateSurface(size_t width, size_t height,
return NULL; return NULL;
} }
#ifdef __3DS__
surface->width = height;
surface->height = width;
surface->pitch = height * 3;
#else
surface->width = width; surface->width = width;
surface->height = height; surface->height = height;
surface->pitch = width * 3; surface->pitch = width * 3;
#endif
return surface; return surface;
} }
@ -121,48 +110,19 @@ void RenderBackend_RestoreSurface(RenderBackend_Surface *surface)
void RenderBackend_UploadSurface(RenderBackend_Surface *surface, const unsigned char *pixels, size_t width, size_t height) void RenderBackend_UploadSurface(RenderBackend_Surface *surface, const unsigned char *pixels, size_t width, size_t height)
{ {
#ifdef __3DS__ for (size_t y = 0; y < height; ++y) {
// Rotate 90 degrees clockwise, and convert from RGB to BGR
const unsigned char *source_pointer = pixels;
for (size_t y = 0; y < height; ++y)
{
for (size_t x = 0; x < width; ++x)
{
unsigned char *destination_pixel = &surface->pixels[x * surface->pitch + (surface->width - y - 1) * 3];
destination_pixel[2] = *source_pointer++;
destination_pixel[1] = *source_pointer++;
destination_pixel[0] = *source_pointer++;
}
}
#else
for (size_t y = 0; y < height; ++y)
memcpy(&surface->pixels[y * surface->pitch], &pixels[y * width * 3], width * 3); memcpy(&surface->pixels[y * surface->pitch], &pixels[y * width * 3], width * 3);
#endif }
} }
ATTRIBUTE_HOT void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RenderBackend_Rect *rect, RenderBackend_Surface *destination_surface, long x, long y, bool colour_key) ATTRIBUTE_HOT void RenderBackend_Blit(RenderBackend_Surface *source_surface, const RenderBackend_Rect *rect, RenderBackend_Surface *destination_surface, long x, long y, bool colour_key)
{ {
RenderBackend_Rect rect_clamped; RenderBackend_Rect rect_clamped;
#ifdef __3DS__
// Rotate
rect_clamped.left = source_surface->width - rect->bottom;
rect_clamped.top = rect->left;
rect_clamped.right = source_surface->width - rect->top;
rect_clamped.bottom = rect->right;
const long new_x = (destination_surface->width - y) - (rect_clamped.right - rect_clamped.left);
const long new_y = x;
x = new_x;
y = new_y;
#else
rect_clamped.left = rect->left; rect_clamped.left = rect->left;
rect_clamped.top = rect->top; rect_clamped.top = rect->top;
rect_clamped.right = rect->right; rect_clamped.right = rect->right;
rect_clamped.bottom = rect->bottom; rect_clamped.bottom = rect->bottom;
#endif
// Clamp the rect and coordinates so we don't write outside the pixel buffer // Clamp the rect and coordinates so we don't write outside the pixel buffer
long overflow; long overflow;
@ -282,15 +242,9 @@ ATTRIBUTE_HOT void RenderBackend_ColourFill(RenderBackend_Surface *surface, cons
for (long i = 0; i < rect_clamped.right - rect_clamped.left; ++i) for (long i = 0; i < rect_clamped.right - rect_clamped.left; ++i)
{ {
#ifdef __3DS__
*destination_pointer++ = blue;
*destination_pointer++ = green;
*destination_pointer++ = red;
#else
*destination_pointer++ = red; *destination_pointer++ = red;
*destination_pointer++ = green; *destination_pointer++ = green;
*destination_pointer++ = blue; *destination_pointer++ = blue;
#endif
} }
} }
} }
@ -305,13 +259,8 @@ RenderBackend_GlyphAtlas* RenderBackend_CreateGlyphAtlas(size_t width, size_t he
if (atlas->pixels != NULL) if (atlas->pixels != NULL)
{ {
#ifdef __3DS__
atlas->width = height;
atlas->height = width;
#else
atlas->width = width; atlas->width = width;
atlas->height = height; atlas->height = height;
#endif
return atlas; return atlas;
} }
@ -330,19 +279,9 @@ void RenderBackend_DestroyGlyphAtlas(RenderBackend_GlyphAtlas *atlas)
void RenderBackend_UploadGlyph(RenderBackend_GlyphAtlas *atlas, size_t x, size_t y, const unsigned char *pixels, size_t width, size_t height, size_t pitch) void RenderBackend_UploadGlyph(RenderBackend_GlyphAtlas *atlas, size_t x, size_t y, const unsigned char *pixels, size_t width, size_t height, size_t pitch)
{ {
#ifdef __3DS__ for (size_t i = 0; i < height; ++i) {
// Rotate
for (size_t h = 0; h < height; ++h)
{
const unsigned char *source_pointer = &pixels[h * pitch];
for (size_t w = 0; w < width; ++w)
atlas->pixels[(x + w) * atlas->width + (atlas->width - (y + h) - 1)] = *source_pointer++;
}
#else
for (size_t i = 0; i < height; ++i)
memcpy(&atlas->pixels[(y + i) * atlas->width + x], &pixels[i * pitch], width); memcpy(&atlas->pixels[(y + i) * atlas->width + x], &pixels[i * pitch], width);
#endif }
} }
void RenderBackend_PrepareToDrawGlyphs(RenderBackend_GlyphAtlas *atlas, RenderBackend_Surface *destination_surface, unsigned char red, unsigned char green, unsigned char blue) void RenderBackend_PrepareToDrawGlyphs(RenderBackend_GlyphAtlas *atlas, RenderBackend_Surface *destination_surface, unsigned char red, unsigned char green, unsigned char blue)
@ -350,37 +289,13 @@ void RenderBackend_PrepareToDrawGlyphs(RenderBackend_GlyphAtlas *atlas, RenderBa
glyph_atlas = atlas; glyph_atlas = atlas;
glyph_destination_surface = destination_surface; glyph_destination_surface = destination_surface;
#ifdef __3DS__
glyph_colour_channels[0] = blue;
glyph_colour_channels[1] = green;
glyph_colour_channels[2] = red;
#else
glyph_colour_channels[0] = red; glyph_colour_channels[0] = red;
glyph_colour_channels[1] = green; glyph_colour_channels[1] = green;
glyph_colour_channels[2] = blue; glyph_colour_channels[2] = blue;
#endif
} }
void RenderBackend_DrawGlyph(long x, long y, size_t glyph_x, size_t glyph_y, size_t glyph_width, size_t glyph_height) void RenderBackend_DrawGlyph(long x, long y, size_t glyph_x, size_t glyph_y, size_t glyph_width, size_t glyph_height)
{ {
#ifdef __3DS__
// Rotate
const size_t new_glyph_width = glyph_height;
const size_t new_glyph_height = glyph_width;
glyph_width = new_glyph_width;
glyph_height = new_glyph_height;
const long new_x = (glyph_destination_surface->width - y) - glyph_width;
const long new_y = x;
x = new_x;
y = new_y;
const long new_glyph_x = (glyph_atlas->width - glyph_y) - glyph_width;
const long new_glyph_y = glyph_x;
glyph_x = new_glyph_x;
glyph_y = new_glyph_y;
#endif
size_t surface_x; size_t surface_x;
size_t surface_y; size_t surface_y;