major gfx refactor
This commit is contained in:
parent
0c0aa792c1
commit
3c3e961995
58 changed files with 3681 additions and 2982 deletions
66
src/gfx/pxl8_shader_runtime.c
Normal file
66
src/gfx/pxl8_shader_runtime.c
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#include "pxl8_shader_runtime.h"
|
||||
#include "pxl8_log.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct pxl8_shader_lib {
|
||||
void* handle;
|
||||
char path[256];
|
||||
};
|
||||
|
||||
pxl8_shader_lib* pxl8_shader_lib_load(const char* path) {
|
||||
void* handle = dlopen(path, RTLD_NOW);
|
||||
if (!handle) {
|
||||
pxl8_error("Failed to load shader library: %s - %s", path, dlerror());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pxl8_shader_lib* lib = malloc(sizeof(pxl8_shader_lib));
|
||||
lib->handle = handle;
|
||||
strncpy(lib->path, path, sizeof(lib->path) - 1);
|
||||
lib->path[sizeof(lib->path) - 1] = '\0';
|
||||
|
||||
return lib;
|
||||
}
|
||||
|
||||
void pxl8_shader_lib_unload(pxl8_shader_lib* lib) {
|
||||
if (!lib) return;
|
||||
if (lib->handle) {
|
||||
dlclose(lib->handle);
|
||||
}
|
||||
free(lib);
|
||||
}
|
||||
|
||||
bool pxl8_shader_lib_reload(pxl8_shader_lib* lib) {
|
||||
if (!lib) return false;
|
||||
|
||||
if (lib->handle) {
|
||||
dlclose(lib->handle);
|
||||
}
|
||||
|
||||
lib->handle = dlopen(lib->path, RTLD_NOW);
|
||||
if (!lib->handle) {
|
||||
pxl8_error("Failed to reload shader library: %s - %s", lib->path, dlerror());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
pxl8_shader_fn pxl8_shader_lib_get(pxl8_shader_lib* lib, const char* name) {
|
||||
if (!lib || !lib->handle) return NULL;
|
||||
|
||||
char symbol[128];
|
||||
snprintf(symbol, sizeof(symbol), "pxl8_shader_%s", name);
|
||||
|
||||
void* fn = dlsym(lib->handle, symbol);
|
||||
if (!fn) {
|
||||
pxl8_error("Failed to find shader: %s - %s", symbol, dlerror());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (pxl8_shader_fn)fn;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue