mewwww
This commit is contained in:
parent
e1f41b09ff
commit
398ad2879b
10 changed files with 131 additions and 4 deletions
14
nob.c
14
nob.c
|
@ -11,7 +11,7 @@
|
|||
|
||||
const char *cflags[] = {"-g", "-rdynamic", "-lm", "-lwayland-client",
|
||||
"-lxkbcommon", "-lvulkan", "-lglfw"};
|
||||
const char *blacklist[] = {"parser.c"};
|
||||
const char *blacklist[] = {"parser.c", "paw_shh_gen.c"};
|
||||
const char *comp = "cc";
|
||||
const char *scomp = "glslc";
|
||||
|
||||
|
@ -169,7 +169,17 @@ int main(int argc, char **argv) {
|
|||
for (int j = 0; j < len(cflags); j++) {
|
||||
cmd_append(&cmd, cflags[j]);
|
||||
}
|
||||
cmd_append(&cmd, "-o", "main_layer", "main_layer.c");
|
||||
cmd_append(&cmd, "-o", "main", "main.c");
|
||||
for (int i = 0; i < src_cpaths.count; i++) {
|
||||
cmd_append(&cmd, src_cpaths.items[i]);
|
||||
}
|
||||
cmd_run_sync_and_reset(&cmd);
|
||||
|
||||
cmd_append(&cmd, comp);
|
||||
for (int j = 0; j < len(cflags); j++) {
|
||||
cmd_append(&cmd, cflags[j]);
|
||||
}
|
||||
cmd_append(&cmd, "-o", "test", "./src/test/paw_shh_gen.c");
|
||||
for (int i = 0; i < src_cpaths.count; i++) {
|
||||
cmd_append(&cmd, src_cpaths.items[i]);
|
||||
}
|
||||
|
|
23
shader.glsl
Normal file
23
shader.glsl
Normal file
|
@ -0,0 +1,23 @@
|
|||
#version 450
|
||||
|
||||
layout(location = 0) in vec2 inPosition;
|
||||
layout(location = 1) in vec3 inColor;
|
||||
layout(location = 2) in uint index;
|
||||
|
||||
layout(set = 0, binding = 0) uniform UBO {
|
||||
mat3 view;
|
||||
mat3 proj;
|
||||
} ubo;
|
||||
|
||||
layout(set = 0, binding = 1) uniform UBO_INST {
|
||||
mat3 model[1000];
|
||||
} ubo_inst;
|
||||
|
||||
layout(location = 0) out vec3 fragColor;
|
||||
layout(location = 1) out vec2 fragUV;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(ubo.proj * ubo.view * ubo_inst.model[index] * vec3(inPosition, 1.0), 1.0);
|
||||
fragColor = inColor;
|
||||
fragUV = inPosition + vec2(0.5, 0.5);
|
||||
}
|
BIN
shader.glslinfo
Normal file
BIN
shader.glslinfo
Normal file
Binary file not shown.
|
@ -9,7 +9,7 @@
|
|||
fprintf(stderr, "[%s:%d] " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__)
|
||||
#define crash(fmt, ...) \
|
||||
fprintf(stderr, "[%s:%d] " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
|
||||
*(int *)0 = 0;
|
||||
abort();
|
||||
|
||||
void paw_print_backtrace();
|
||||
const char *paw_b_to_s(bool b);
|
||||
|
|
21
src/string.c
21
src/string.c
|
@ -7,6 +7,18 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
struct PawSB paw_sb_make() {
|
||||
char *string = malloc(1);
|
||||
*string = 0x0;
|
||||
return (struct PawSB){string};
|
||||
}
|
||||
void paw_sb_append(struct PawSB *sb, char *string) {
|
||||
char *new = realloc(sb->string, strlen(sb->string) + strlen(string) + 1);
|
||||
memmove(new, sb->string, strlen(sb->string) + 1);
|
||||
memcpy(new + strlen(new), string, strlen(string) + 1);
|
||||
}
|
||||
char *paw_sb_get(struct PawSB *sb) { return sb->string; }
|
||||
|
||||
struct da_string split(struct PawMem *mem, char *string, char needle) {
|
||||
struct da_string items;
|
||||
paw_da_make_inplace_mem(&items, mem);
|
||||
|
@ -54,7 +66,7 @@ char *extract_brackets(struct PawMem *mem, char *start, char open, char close) {
|
|||
return res;
|
||||
}
|
||||
|
||||
// before: asddasasd(aslfaddf)
|
||||
// before: asdasasd(aslfaddf)
|
||||
// ^
|
||||
// after: asddasasd(aslfaddf)
|
||||
// ^
|
||||
|
@ -198,3 +210,10 @@ char *skip_after_char(char *string, char n) {
|
|||
}
|
||||
return string + 1;
|
||||
}
|
||||
|
||||
char *skip_after_string(char *string, char *n) {
|
||||
while (!start_matches(string, n)) {
|
||||
string++;
|
||||
}
|
||||
return string + strlen(n);
|
||||
}
|
||||
|
|
|
@ -6,6 +6,13 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct PawSB {
|
||||
char *string;
|
||||
};
|
||||
struct PawSB paw_sb_make();
|
||||
void paw_sb_append(struct PawSB *sb, char *string);
|
||||
char *paw_sb_get(struct PawSB *sb);
|
||||
|
||||
struct da_string split(struct PawMem *mem, char *string, char needle);
|
||||
bool start_matches(char *string, char *match);
|
||||
char *extract_brackets(struct PawMem *mem, char *start, char open, char close);
|
||||
|
@ -25,5 +32,6 @@ char *mem_strdup_reg(char *start, char *end, struct PawMem *mem);
|
|||
char *strdup_reg(char *start, char *end);
|
||||
char *skip_to_char(char *string, char n);
|
||||
char *skip_after_char(char *string, char n);
|
||||
char *skip_after_string(char *string, char *n);
|
||||
|
||||
#endif // INCLUDE_SRC_STRING_H_
|
||||
|
|
64
src/test/paw_shh_gen.c
Normal file
64
src/test/paw_shh_gen.c
Normal file
|
@ -0,0 +1,64 @@
|
|||
#include "../io.h"
|
||||
#include "../paw_da.h"
|
||||
#include "../paw_log.h"
|
||||
#include "../string.h"
|
||||
|
||||
struct Prop {
|
||||
char *name;
|
||||
char *type;
|
||||
};
|
||||
paw_da_define(da_Prop, struct Prop);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char *path;
|
||||
char *output;
|
||||
if (argc < 2) {
|
||||
path = "shader.glsl";
|
||||
} else {
|
||||
path = argv[1];
|
||||
}
|
||||
|
||||
if (argc < 3) {
|
||||
output = "shader.glslinfo";
|
||||
} else {
|
||||
output = argv[2];
|
||||
}
|
||||
char *file = read_text_file(path);
|
||||
meow("%s", file);
|
||||
|
||||
struct da_Prop props;
|
||||
paw_da_make_inplace(&props);
|
||||
|
||||
char *mark =
|
||||
skip_after_string(file, "layout(set = 0, binding = 0) uniform UBO {\n");
|
||||
*skip_to_char(mark, '}') = 0;
|
||||
|
||||
while (*mark != 0x0) {
|
||||
mark = trim_start(mark);
|
||||
char *middle = skip_to_char(mark, ' ');
|
||||
char *end = skip_to_char(middle, ';');
|
||||
*middle = 0x0;
|
||||
*end = 0x0;
|
||||
paw_da_append(&props, ((struct Prop){
|
||||
.type = mark,
|
||||
.name = middle + 1,
|
||||
}));
|
||||
mark = trim_start(end + 1);
|
||||
}
|
||||
|
||||
struct PawSB sb = paw_sb_make();
|
||||
for (int i = 0; i < props.count; i++) {
|
||||
paw_sb_append(&sb, props.items[i].type);
|
||||
paw_sb_append(&sb, " ");
|
||||
paw_sb_append(&sb, props.items[i].name);
|
||||
paw_sb_append(&sb, "\n");
|
||||
}
|
||||
char *res = paw_sb_get(&sb);
|
||||
write_binary_file(output, res, strlen(res) + 1);
|
||||
|
||||
paw_da_free(&props);
|
||||
free(res);
|
||||
|
||||
free(file);
|
||||
return 0;
|
||||
}
|
0
src/test/shader.glsl
Normal file
0
src/test/shader.glsl
Normal file
|
@ -335,6 +335,9 @@ struct cat_Wl *cat_init_wl_layer(const char *name, struct Vk **vk) {
|
|||
|
||||
state->wl_surface = wl_compositor_create_surface(state->compositor);
|
||||
|
||||
if (state->layer_shell == NULL) {
|
||||
crash("your compositor does not support layer shell :[");
|
||||
}
|
||||
state->layer_surface = zwlr_layer_shell_v1_get_layer_surface(
|
||||
state->layer_shell, state->wl_surface, NULL,
|
||||
ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND, "wlroots");
|
||||
|
|
BIN
test
Executable file
BIN
test
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue