2026-01-21 23:19:50 -06:00
|
|
|
#include "pxl8_lights.h"
|
|
|
|
|
#include "pxl8_mem.h"
|
|
|
|
|
|
|
|
|
|
struct pxl8_lights {
|
|
|
|
|
pxl8_light* data;
|
|
|
|
|
u32 capacity;
|
|
|
|
|
u32 count;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pxl8_lights* pxl8_lights_create(u32 capacity) {
|
|
|
|
|
if (capacity > PXL8_LIGHTS_MAX) capacity = PXL8_LIGHTS_MAX;
|
|
|
|
|
|
|
|
|
|
pxl8_lights* lights = pxl8_calloc(1, sizeof(pxl8_lights));
|
|
|
|
|
if (!lights) return NULL;
|
|
|
|
|
|
|
|
|
|
lights->data = pxl8_calloc(capacity, sizeof(pxl8_light));
|
|
|
|
|
if (!lights->data) {
|
|
|
|
|
pxl8_free(lights);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lights->capacity = capacity;
|
|
|
|
|
lights->count = 0;
|
|
|
|
|
|
|
|
|
|
return lights;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pxl8_lights_destroy(pxl8_lights* lights) {
|
|
|
|
|
if (!lights) return;
|
|
|
|
|
pxl8_free(lights->data);
|
|
|
|
|
pxl8_free(lights);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-05 03:27:35 -06:00
|
|
|
void pxl8_lights_add(pxl8_lights* lights, f32 x, f32 y, f32 z, u8 color, u8 intensity, f32 radius) {
|
2026-01-21 23:19:50 -06:00
|
|
|
if (!lights || lights->count >= lights->capacity) return;
|
|
|
|
|
|
|
|
|
|
f32 radius_sq = radius * radius;
|
|
|
|
|
pxl8_light* l = &lights->data[lights->count++];
|
2026-02-05 03:27:35 -06:00
|
|
|
l->color = color;
|
|
|
|
|
l->intensity = (f32)intensity / 255.0f;
|
|
|
|
|
l->inv_radius_sq = radius_sq > 0.0f ? 1.0f / radius_sq : 0.0f;
|
2026-02-05 02:42:58 -06:00
|
|
|
l->position = (pxl8_vec3){{x, y, z}};
|
2026-01-21 23:19:50 -06:00
|
|
|
l->radius_sq = radius_sq;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pxl8_lights_clear(pxl8_lights* lights) {
|
|
|
|
|
if (!lights) return;
|
|
|
|
|
lights->count = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u32 pxl8_lights_count(const pxl8_lights* lights) {
|
|
|
|
|
return lights ? lights->count : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const pxl8_light* pxl8_lights_data(const pxl8_lights* lights) {
|
|
|
|
|
return lights ? lights->data : NULL;
|
|
|
|
|
}
|