2021-11-30 21:29:18 -06:00
|
|
|
#include "shader.h"
|
|
|
|
|
|
|
|
#include "config.h"
|
2023-05-12 13:22:05 -05:00
|
|
|
#include "font.h"
|
2021-11-30 21:29:18 -06:00
|
|
|
#include "log.h"
|
2023-05-12 13:22:05 -05:00
|
|
|
#include "render.h"
|
2021-11-30 21:29:18 -06:00
|
|
|
#include "resources.h"
|
2022-08-26 09:19:17 -05:00
|
|
|
#include "stb_ds.h"
|
|
|
|
#include "timer.h"
|
2023-05-12 13:22:05 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-12-16 11:54:05 -06:00
|
|
|
#include "time.h"
|
|
|
|
|
2021-11-30 21:29:18 -06:00
|
|
|
#define SHADER_BUF 10000
|
|
|
|
|
2022-11-19 17:13:57 -06:00
|
|
|
static struct shader *shaders;
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
struct shader *MakeShader(const char *vertpath, const char *fragpath) {
|
|
|
|
if (arrcap(shaders) == 0)
|
|
|
|
arrsetcap(shaders, 20);
|
2022-07-02 03:40:50 -05:00
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
struct shader init = {
|
|
|
|
.vertpath = vertpath,
|
|
|
|
.fragpath = fragpath};
|
|
|
|
shader_compile(&init);
|
|
|
|
arrput(shaders, init);
|
|
|
|
return &arrlast(shaders);
|
2021-11-30 21:29:18 -06:00
|
|
|
}
|
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
void shader_compile(struct shader *shader) {
|
|
|
|
YughInfo("Making shader with %s and %s.", shader->vertpath, shader->fragpath);
|
|
|
|
char spath[MAXPATH];
|
|
|
|
sprintf(spath, "%s%s", "shaders/", shader->vertpath);
|
|
|
|
const char *vsrc = slurp_text(spath);
|
|
|
|
sprintf(spath, "%s%s", "shaders/", shader->fragpath);
|
|
|
|
const char *fsrc = slurp_text(spath);
|
|
|
|
|
|
|
|
shader->shd = sg_make_shader(&(sg_shader_desc){
|
2023-05-04 17:07:00 -05:00
|
|
|
.vs.source = vsrc,
|
|
|
|
.fs.source = fsrc,
|
|
|
|
.label = shader->vertpath,
|
2023-05-12 13:22:05 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
free(vsrc);
|
|
|
|
free(fsrc);
|
2021-11-30 21:29:18 -06:00
|
|
|
}
|
|
|
|
|
2023-05-12 13:22:05 -05:00
|
|
|
void shader_compile_all() {
|
|
|
|
for (int i = 0; i < arrlen(shaders); i++)
|
|
|
|
shader_compile(&shaders[i]);
|
2021-11-30 21:29:18 -06:00
|
|
|
}
|
2023-05-24 20:45:50 -05:00
|
|
|
|