improve glow rendering

This commit is contained in:
asrael 2026-01-23 11:12:37 -06:00
parent 28c3e7ee04
commit 27c6fa628d
7 changed files with 145 additions and 48 deletions

59
src/gfx/pxl8_glows.c Normal file
View file

@ -0,0 +1,59 @@
#include "pxl8_glows.h"
#include <stdlib.h>
struct pxl8_glows {
pxl8_glow_source* data;
u32 capacity;
u32 count;
};
pxl8_glows* pxl8_glows_create(u32 capacity) {
pxl8_glows* glows = calloc(1, sizeof(pxl8_glows));
if (!glows) return NULL;
glows->data = calloc(capacity, sizeof(pxl8_glow_source));
if (!glows->data) {
free(glows);
return NULL;
}
glows->capacity = capacity;
glows->count = 0;
return glows;
}
void pxl8_glows_destroy(pxl8_glows* glows) {
if (!glows) return;
free(glows->data);
free(glows);
}
void pxl8_glows_add(pxl8_glows* glows, i16 x, i16 y, u8 radius, u16 intensity, u8 color, u8 shape) {
if (!glows || glows->count >= glows->capacity) return;
pxl8_glow_source* g = &glows->data[glows->count++];
g->x = x;
g->y = y;
g->radius = radius;
g->intensity = intensity;
g->color = color;
g->shape = shape;
g->depth = 0xFFFF;
g->height = 0;
}
void pxl8_glows_clear(pxl8_glows* glows) {
if (!glows) return;
glows->count = 0;
}
u32 pxl8_glows_count(const pxl8_glows* glows) {
return glows ? glows->count : 0;
}
void pxl8_glows_render(pxl8_glows* glows, pxl8_gfx* gfx) {
if (!glows || !gfx || glows->count == 0) return;
pxl8_gfx_apply_effect(gfx, PXL8_GFX_EFFECT_GLOWS, glows->data, glows->count);
}

22
src/gfx/pxl8_glows.h Normal file
View file

@ -0,0 +1,22 @@
#pragma once
#include "pxl8_gfx.h"
#include "pxl8_types.h"
typedef struct pxl8_glows pxl8_glows;
#ifdef __cplusplus
extern "C" {
#endif
pxl8_glows* pxl8_glows_create(u32 capacity);
void pxl8_glows_destroy(pxl8_glows* glows);
void pxl8_glows_add(pxl8_glows* glows, i16 x, i16 y, u8 radius, u16 intensity, u8 color, u8 shape);
void pxl8_glows_clear(pxl8_glows* glows);
u32 pxl8_glows_count(const pxl8_glows* glows);
void pxl8_glows_render(pxl8_glows* glows, pxl8_gfx* gfx);
#ifdef __cplusplus
}
#endif