true 16-bit color... glorious
This commit is contained in:
parent
3dccce8a81
commit
b1e8525c3e
30 changed files with 678 additions and 652 deletions
|
|
@ -5,7 +5,9 @@
|
|||
#include <SDL3/SDL_main.h>
|
||||
|
||||
#include "pxl8_atlas.h"
|
||||
#include "pxl8_color.h"
|
||||
#include "pxl8_macros.h"
|
||||
#include "pxl8_rec.h"
|
||||
#include "pxl8_sys.h"
|
||||
|
||||
typedef struct pxl8_sdl3_context {
|
||||
|
|
@ -122,28 +124,29 @@ static void sdl3_upload_framebuffer(void* platform_data, const u8* fb,
|
|||
if (!platform_data || !fb) return;
|
||||
|
||||
pxl8_sdl3_context* ctx = (pxl8_sdl3_context*)platform_data;
|
||||
size_t needed_size = w * h;
|
||||
|
||||
if (ctx->rgba_buffer_size < needed_size) {
|
||||
u32* new_buffer = (u32*)SDL_realloc(ctx->rgba_buffer, needed_size * 4);
|
||||
if (!new_buffer) return;
|
||||
ctx->rgba_buffer = new_buffer;
|
||||
ctx->rgba_buffer_size = needed_size;
|
||||
}
|
||||
|
||||
if (mode == PXL8_COLOR_MODE_HICOLOR) {
|
||||
SDL_UpdateTexture(ctx->framebuffer_texture, NULL, fb, w * 4);
|
||||
} else {
|
||||
size_t needed_size = w * h;
|
||||
|
||||
if (ctx->rgba_buffer_size < needed_size) {
|
||||
ctx->rgba_buffer = (u32*)SDL_realloc(ctx->rgba_buffer, needed_size * 4);
|
||||
ctx->rgba_buffer_size = needed_size;
|
||||
const u16* fb16 = (const u16*)fb;
|
||||
for (i32 i = 0; i < w * h; i++) {
|
||||
ctx->rgba_buffer[i] = pxl8_rgb565_to_rgba32(fb16[i]);
|
||||
}
|
||||
|
||||
if (!ctx->rgba_buffer) return;
|
||||
|
||||
} else {
|
||||
u32 palette_size = pxl8_get_palette_size(mode);
|
||||
|
||||
for (i32 i = 0; i < w * h; i++) {
|
||||
u8 index = fb[i];
|
||||
ctx->rgba_buffer[i] = (index < palette_size) ? palette[index] : 0xFF000000;
|
||||
}
|
||||
|
||||
SDL_UpdateTexture(ctx->framebuffer_texture, NULL, ctx->rgba_buffer, w * 4);
|
||||
}
|
||||
|
||||
SDL_UpdateTexture(ctx->framebuffer_texture, NULL, ctx->rgba_buffer, w * 4);
|
||||
}
|
||||
|
||||
static void sdl3_upload_atlas(void* platform_data, const pxl8_atlas* atlas,
|
||||
|
|
@ -183,27 +186,30 @@ static void sdl3_upload_atlas(void* platform_data, const pxl8_atlas* atlas,
|
|||
ctx->atlas_height = atlas_h;
|
||||
}
|
||||
|
||||
size_t needed_size = atlas_w * atlas_h;
|
||||
|
||||
if (ctx->rgba_buffer_size < needed_size) {
|
||||
u32* new_buffer = (u32*)SDL_realloc(ctx->rgba_buffer, needed_size * 4);
|
||||
if (!new_buffer) return;
|
||||
ctx->rgba_buffer = new_buffer;
|
||||
ctx->rgba_buffer_size = needed_size;
|
||||
}
|
||||
|
||||
if (mode == PXL8_COLOR_MODE_HICOLOR) {
|
||||
SDL_UpdateTexture(ctx->atlas_texture, NULL, atlas_pixels, atlas_w * 4);
|
||||
} else {
|
||||
size_t needed_size = atlas_w * atlas_h;
|
||||
|
||||
if (ctx->rgba_buffer_size < needed_size) {
|
||||
ctx->rgba_buffer = (u32*)SDL_realloc(ctx->rgba_buffer, needed_size * 4);
|
||||
ctx->rgba_buffer_size = needed_size;
|
||||
const u16* atlas16 = (const u16*)atlas_pixels;
|
||||
for (u32 i = 0; i < atlas_w * atlas_h; i++) {
|
||||
u16 pixel = atlas16[i];
|
||||
ctx->rgba_buffer[i] = (pixel != 0) ? pxl8_rgb565_to_rgba32(pixel) : 0x00000000;
|
||||
}
|
||||
|
||||
if (!ctx->rgba_buffer) return;
|
||||
|
||||
} else {
|
||||
u32 palette_size = pxl8_get_palette_size(mode);
|
||||
|
||||
for (u32 i = 0; i < atlas_w * atlas_h; i++) {
|
||||
u8 index = atlas_pixels[i];
|
||||
ctx->rgba_buffer[i] = (index < palette_size) ? palette[index] : 0x00000000;
|
||||
}
|
||||
|
||||
SDL_UpdateTexture(ctx->atlas_texture, NULL, ctx->rgba_buffer, atlas_w * 4);
|
||||
}
|
||||
|
||||
SDL_UpdateTexture(ctx->atlas_texture, NULL, ctx->rgba_buffer, atlas_w * 4);
|
||||
}
|
||||
|
||||
SDL_AppResult SDL_AppInit(void** appstate, int argc, char* argv[]) {
|
||||
|
|
@ -267,7 +273,7 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {
|
|||
|
||||
case SDL_EVENT_KEY_DOWN: {
|
||||
SDL_Scancode scancode = event->key.scancode;
|
||||
if (scancode < 256) {
|
||||
if (scancode < PXL8_MAX_KEYS) {
|
||||
if (!input->keys_down[scancode]) {
|
||||
input->keys_pressed[scancode] = true;
|
||||
}
|
||||
|
|
@ -279,7 +285,7 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {
|
|||
|
||||
case SDL_EVENT_KEY_UP: {
|
||||
SDL_Scancode scancode = event->key.scancode;
|
||||
if (scancode < 256) {
|
||||
if (scancode < PXL8_MAX_KEYS) {
|
||||
input->keys_down[scancode] = false;
|
||||
input->keys_pressed[scancode] = false;
|
||||
input->keys_released[scancode] = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue