Embeddable shaders
This commit is contained in:
parent
6025a5a614
commit
39dbf40cd3
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,3 +2,5 @@
|
|||||||
compile_commands.json
|
compile_commands.json
|
||||||
zoomer
|
zoomer
|
||||||
zoomer.o
|
zoomer.o
|
||||||
|
fshader.h
|
||||||
|
vshader.h
|
||||||
|
23
Makefile
23
Makefile
@ -1,32 +1,39 @@
|
|||||||
.PHONY: all clean run
|
.PHONY: all clean run bear build
|
||||||
VERSION = 0.0.1
|
VERSION = 0.0.2
|
||||||
|
|
||||||
PREFIX=/usr/local
|
PREFIX=/usr/local
|
||||||
|
|
||||||
LIBS = sdl2 glew
|
LIBS = sdl2 glew
|
||||||
CMACRO = -DVERSION=\"$(VERSION)\"
|
CMACRO = -DVERSION=\"$(VERSION)\" $(if $(EMBED_SHADER),-DEMBED_SHADER,)
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -g -Wall -Wextra -pedantic $(shell pkg-config $(LIBS) --cflags) $(CMACRO)
|
CFLAGS = -g -Wall -Wextra -pedantic $(shell pkg-config $(LIBS) --cflags) $(CMACRO)
|
||||||
LDFLAGS = $(shell pkg-config $(LIBS) --libs) -lm
|
LDFLAGS = $(shell pkg-config $(LIBS) --libs) -lm
|
||||||
|
|
||||||
all: zoomer
|
all: zoomer
|
||||||
|
|
||||||
zoomer: zoomer.o
|
zoomer: $(if $(EMBED_SHADER),fshader.h vshader.h,) zoomer.o
|
||||||
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
$(CC) $(CFLAGS) -c -o $@ $<
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
%.h: %.glsl
|
||||||
|
xxd -i $< $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
rm -f fshader.h vshader.h
|
||||||
rm -f *.o
|
rm -f *.o
|
||||||
rm -f zoomer
|
rm -f zoomer
|
||||||
|
|
||||||
install: zoomer
|
install: build
|
||||||
install -Dm755 $< $(DESTDIR)$(PREFIX)/bin/$<
|
install -Dm755 zoomer $(DESTDIR)$(PREFIX)/bin/zoomer
|
||||||
|
|
||||||
bear: clean
|
bear: clean
|
||||||
bear -- make
|
bear -- make
|
||||||
|
|
||||||
run: zoomer
|
build:
|
||||||
|
EMBED_SHADER=y $(MAKE) zoomer
|
||||||
|
|
||||||
|
run: zoomer
|
||||||
./$<
|
./$<
|
||||||
|
10
tutils.h
10
tutils.h
@ -9,16 +9,16 @@ const char* pullArg(int *argc, char** argv[]){
|
|||||||
return *argv[0]++;
|
return *argv[0]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *readFile(const char* filename){
|
const char* readFile(const char* filename, long *size){
|
||||||
FILE *fd = fopen(filename, "r");
|
FILE *fd = fopen(filename, "r");
|
||||||
|
|
||||||
fseek(fd, 0, SEEK_END);
|
fseek(fd, 0, SEEK_END);
|
||||||
long size = ftell(fd);
|
*size = ftell(fd);
|
||||||
rewind(fd);
|
rewind(fd);
|
||||||
|
|
||||||
char* ret = malloc(size+1);
|
char* ret = malloc(*size+1);
|
||||||
fread(ret, sizeof(char), size, fd);
|
fread(ret, sizeof(char), *size, fd);
|
||||||
ret[size] = 0;
|
ret[*size] = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
zoomer.c
17
zoomer.c
@ -68,11 +68,20 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
GLuint vshader = glCreateShader(GL_VERTEX_SHADER),
|
GLuint vshader = glCreateShader(GL_VERTEX_SHADER),
|
||||||
fshader = glCreateShader(GL_FRAGMENT_SHADER);
|
fshader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
const char *vshadersrc = readFile("vshader.glsl"),
|
|
||||||
*fshadersrc = readFile("fshader.glsl");
|
|
||||||
|
|
||||||
glShaderSource(vshader, 1, &vshadersrc, NULL);
|
#ifndef EMBED_SHADER
|
||||||
glShaderSource(fshader, 1, &fshadersrc, NULL);
|
long vshader_glsl_len, fshader_glsl_len;
|
||||||
|
const char *vshadersrc = readFile("vshader.glsl", &vshader_glsl_len),
|
||||||
|
*fshadersrc = readFile("fshader.glsl", &fshader_glsl_len);
|
||||||
|
#else
|
||||||
|
#include "vshader.h"
|
||||||
|
#include "fshader.h"
|
||||||
|
const char *vshadersrc = vshader_glsl,
|
||||||
|
*fshadersrc = fshader_glsl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
glShaderSource(vshader, 1, &vshadersrc, (int *)&vshader_glsl_len);
|
||||||
|
glShaderSource(fshader, 1, &fshadersrc, (int *)&fshader_glsl_len);
|
||||||
|
|
||||||
glCompileShader(vshader);
|
glCompileShader(vshader);
|
||||||
glCompileShader(fshader);
|
glCompileShader(fshader);
|
||||||
|
Loading…
Reference in New Issue
Block a user