Compare commits

...

6 Commits

50 changed files with 3506 additions and 2605 deletions

2
.gitignore vendored
View File

@ -15,3 +15,5 @@ vgcore.*
GRAPH*.gv
GRAPH*.png
SICK_JOKE*
*.hi
*_stub.h

View File

@ -19,9 +19,9 @@ execute_process(
#add_compile_options("-I/nix/store/2hm4rjvywd00p417y43i9rzx8v793qi0-pipewire-1.4.5-dev/include/pipewire-0.3 -I/nix/store/2hm4rjvywd00p417y43i9rzx8v793qi0-pipewire-1.4.5-dev/include/spa-0.2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
-I /nix/store/2hm4rjvywd00p417y43i9rzx8v793qi0-pipewire-1.4.5-dev/include/pipewire-0.3 \
-I /nix/store/2hm4rjvywd00p417y43i9rzx8v793qi0-pipewire-1.4.5-dev/include/spa-0.2 ")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
# -I /nix/store/2hm4rjvywd00p417y43i9rzx8v793qi0-pipewire-1.4.5-dev/include/pipewire-0.3 \
# -I /nix/store/2hm4rjvywd00p417y43i9rzx8v793qi0-pipewire-1.4.5-dev/include/spa-0.2 ")
add_compile_definitions(_POSIX_C_SOURCE=200112L)
add_compile_definitions(_GNU_SOURCE)
@ -40,12 +40,6 @@ target_link_libraries(3_test -lm)
add_executable(codegen_l1_5 src/l1_5/anne/codegen.c)
add_executable(0_render_test src/l2/tests/r0/r0.c gen/l_wl_protocols/xdg-shell-private.c)
target_link_libraries(0_render_test -lvulkan -lwayland-client -lm -lxkbcommon -lpng -lfreetype)
add_executable(0r_tex_init_prep src/l2/tests/r0/r0_tex_init_prep.c)
target_link_libraries(0r_tex_init_prep -lm -lpng)
#add_executable(1_render_test src/l2/tests/r1/r1.c gen/l_wl_protocols/xdg-shell-private.c)
#target_link_libraries(1_render_test -lwayland-client -lrt -lm -lxkbcommon)
#
@ -56,13 +50,15 @@ target_link_libraries(0r_tex_init_prep -lm -lpng)
#target_link_libraries(3_render_test -lwayland-client -lm -lvulkan -lxkbcommon)
#add_executable(l2t0_2 src/l2/tests/data_structures/t0_2.c) // todo: I will get back
add_executable(l2t0 src/l2/tests/data_structures/t0.c)
add_executable(l2t0_3 src/l2/tests/data_structures/t0_3.c)
#add_executable(l2t0 src/l2/tests/data_structures/t0.c)
#add_executable(l2t0_3 src/l2/tests/data_structures/t0_3.c)
#add_executable(l2t2 src/l2/tests/data_structures/t2.c)
#add_executable(l2t0 src/l2/tests/data_structures/t0.c)
#add_executable(l2t1 src/l2/tests/data_structures/t1.c)
#add_executable(H src/l2/tests/r_alg/H.c)
#add_executable(I src/l2/tests/r_alg/I.c)
#add_executable(J src/l2/tests/r_alg/J.c)
add_executable(l2_tex_gen src/l2/anne/codegen.c)
target_link_libraries(l2_tex_gen -lm -lpng)
add_executable(l2_r4 src/l3/r4/r4.c gen/l_wl_protocols/xdg-shell-private.c)
target_link_libraries(l2_r4 -lvulkan -lwayland-client -lm -lxkbcommon -lpng -lfreetype)

View File

@ -24,8 +24,15 @@ cc := gcc
wl_protocols := $(shell pkg-config --variable=pkgdatadir wayland-protocols)
libpipewire_flags := $(shell pkg-config --cflags --libs libpipewire-0.3)
xdg_shell_private := gen/l_wl_protocols/xdg-shell-private.c
l_wl_protocols := gen/l_wl_protocols/xdg-shell-client.h $(xdg_shell_private)
xdg_shell_private_c := gen/l_wl_protocols/xdg-shell-private.c
xdg_shell_client_h := gen/l_wl_protocols/xdg-shell-client.h
xdg_shell_private_o := out/l_wl_protocols/xdg-shell-private.o
l_wl_protocols := $(xdg_shell_client_h) $(xdg_shell_private_c)
$(xdg_shell_private_o): $(l_wl_protocols)
mkdir -p out/l_wl_protocols
$(cc) $(cflags) -o $@ -c $(xdg_shell_private_c) -lwayland-client
out/l1/codegen: src/l1/anne/codegen.c $(HEADERS_src_l1)
mkdir -p out/l1
@ -63,18 +70,29 @@ gen/l_wl_protocols/xdg-shell-private.c: $(wl_protocols)/stable/xdg-shell/xdg-she
.PHONY: gen/l_wl_protocols
gen/l_wl_protocols : $(l_wl_protocols)
out/l2/codegen: src/l2/anne/codegen.c $(HEADERS_src_l2)
mkdir -p out/l2
$(cc) $(cflags) -o $@ $< -lm -lpng
compile_vert_shader = glslc -o gen/l_adele/$(1)/vert.spv src/l_adele/$(1)/$(1).vert
compile_frag_shader = glslc -o gen/l_adele/$(1)/frag.spv src/l_adele/$(1)/$(1).frag
gen/l2/dorothy.txt: out/l2/codegen
mkdir -p gen
cd gen && ../out/l2/codegen
# First argument is path (relative to src/l_adele), second argument is a name of shader files in shader folder
compile_vert_shader = glslc -o gen/l_adele/$(1)/vert.spv src/l_adele/$(1)/$(2).vert
compile_frag_shader = glslc -o gen/l_adele/$(1)/frag.spv src/l_adele/$(1)/$(2).frag
define compile_shader
mkdir -p gen/l_adele/$(1)
$(call compile_vert_shader,$(1))
$(call compile_frag_shader,$(1))
$(call compile_vert_shader,$(1),$(2))
$(call compile_frag_shader,$(1),$(2))
endef
gen/l_adele/dorothy.txt: $(ASSETS_src_l_adele)
$(call compile_shader,lucy)
$(call compile_shader,lucy,lucy)
$(call compile_shader,alice/0gen,0gen)
$(call compile_shader,alice/0sh,0sh)
$(call compile_shader,alice/1,1)
touch gen/l_adele/dorothy.txt
out/l2/t0: src/l2/tests/data_structures/t0.c $(HEADERS_gen_l1_5)
@ -85,26 +103,10 @@ out/l2/t0: src/l2/tests/data_structures/t0.c $(HEADERS_gen_l1_5)
run_l2_t0: out/l2/t0
cd src/l2/tests/data_structures && ../../../../out/l2/t0
out/l2/r0: src/l2/tests/r0/r0.c $(HEADERS_src_l2) $(l_wl_protocols)
mkdir -p out/l2
$(cc) $(cflags) -o $@ $< $(xdg_shell_private) -lvulkan -lm -lxkbcommon -lwayland-client -lpng
out/l2/r0_tex_init_prep: src/l2/tests/r0/r0_tex_init_prep.c $(HEADERS_src_l2)
mkdir -p out/l2
$(cc) $(cflags) -o $@ $< -lm -lpng
.PHONY: run_r0
run_r0: out/l2/r0
cd src/l2/tests/r0 && ../../../../out/l2/r0
.PHONY: run_r0_tex_init_prep
run_r0_tex_init_prep: out/l2/r0_tex_init_prep
cd src/l2/tests/r0 && ../../../../out/l2/r0_tex_init_prep
out/l2/r1: src/l2/tests/r1/r1.c $(HEADERS_src_l2) $(l_wl_protocols)
mkdir -p out/l2
$(cc) $(cflags) -o $@ $< $(xdg_shell_private) -lwayland-client -lrt -lxkbcommon -lm
$(cc) $(cflags) -o $@ $< $(xdg_shell_private_c) -lwayland-client -lrt -lxkbcommon -lm
.PHONY: run_r1
run_r1: out/l2/r1
@ -113,21 +115,35 @@ run_r1: out/l2/r1
out/l2/r2: src/l2/tests/r2/r2a.c $(HEADERS_src_l2) $(l_wl_protocols)
mkdir -p out/l2
$(cc) $(cflags) -o $@ $< $(xdg_shell_private) -lwayland-client -lrt -lxkbcommon -lm $(libpipewire_flags)
$(cc) $(cflags) -o $@ $< $(xdg_shell_private_c) -lwayland-client -lrt -lxkbcommon -lm $(libpipewire_flags)
.PHONY: run_r2
run_r2: out/l2/r2
./out/l2/r2
out/l2/r3: src/l2/tests/r3/r3.c $(HEADERS_src_l2) $(l_wl_protocols)
mkdir -p out/l2
$(cc) $(cflags) -o $@ $< $(xdg_shell_private) -lwayland-client -lrt -lxkbcommon -lm -lvulkan
$(cc) $(cflags) -o $@ $< $(xdg_shell_private_c) -lwayland-client -lrt -lxkbcommon -lm -lvulkan
.PHONY: run_r3
run_r3: out/l2/r3
./out/l2/r3
# Whoever needs this will also need out/l_wl_protocols
out/l2/allie.o: src/l2/allie/allie.c $(HEADERS_src_l2) $(xdg_shell_client_h) gen/l_adele/dorothy.txt $(HEADERS_gen_l2)
mkdir -p out/l2
$(cc) $(cflags) -o $@ -c $< -lvulkan -lm -lxkbcommon -lwayland-client -lpng -lfreetype
full_allie_obj := out/l2/allie.o $(xdg_shell_private_o)
out/l3/r4: src/l3/r4/R4.hs src/l2/allie/Allie.hs $(full_allie_obj)
mkdir -p out/l3
ghc -isrc/l2/allie -hidir out/l3/ -odir out/l3 -o $@ $< $(full_allie_obj) \
-lvulkan -lm -lxkbcommon -lwayland-client -lpng -lfreetype
.PHONY: run_r4
run_r4: out/l3/r4
./out/l3/r4
.PHONY: clean
clean:

25
src/l1/anne/alice.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef prototype1_src_l1_anne_alice_h
#define prototype1_src_l1_anne_alice_h
#include "../codegen/codegen.h"
void generate_code_for_alice_on_l1(){
mkdir_nofail("l1/eve/alice");
mkdir_nofail("l1/eve/alice");
SpanU8 l = cstr("l1"), ns = cstr("alice");
/* Assets: model topology */
generate_eve_span_company_for_primitive(l, ns, cstr("GenericMeshVertexInc"), true, true);
generate_eve_span_company_for_primitive(l, ns, cstr("ShinyMeshVertexInc"), true, true);
/* Engine stuff */
// todo: yes, maybe right now it is not primitive but I surely will make it primitive someday. Right now I don't care
generate_List_templ_inst_eve_header(l, ns, (list_instantiation_op){
.T = cstr("AliceGenericMeshHand"), .t_primitive = true}, true);
generate_List_templ_inst_eve_header(l, ns, (list_instantiation_op){
.T = cstr("AliceShinyMeshHand"), .t_primitive = true}, true);
generate_eve_span_company_for_primitive(l, ns, cstr("RefListNodeAliceGenericMeshHand"), true, false);
generate_eve_span_company_for_primitive(l, ns, cstr("RefListNodeAliceShinyMeshHand"), true, false);
}
#endif

View File

@ -13,6 +13,7 @@
#include "embassy_l1_5.h"
#include "margaret/png_pixel_masses.h"
#include "lucy.h"
#include "alice.h"
int main() {
mkdir_nofail("l1");
@ -26,10 +27,10 @@ int main() {
generate_marie_headers_for_graphics_geom();
generate_liza_l1_headers();
generate_l1_headers_for_l1_5();
mkdir_nofail("l1/margaret");
generate_margaret_eve_for_vulkan_utils(); /* margaret misc */
generate_margaret_png_pixel_masses_header();
generate_l1_lucy_headers();
generate_code_for_alice_on_l1();
finish_layer(cstr("l1"));
return 0;
}

View File

@ -179,7 +179,7 @@ NODISCARD VecU8 generate_xmatnm_struct_and_methods(
for (int x = 0; x < cols; x++) {
VecU8_append_vec(&res, VecU8_fmt(SPACE "%s %s;\n", xvecm, vec_field_name(x)));
if (sv) {
VecU8_append_vec(&res, VecU8_format(SPACE "char _padding_%d[%d];\n", x, 16 - sv));
VecU8_append_vec(&res, VecU8_fmt(SPACE "char _padding_%u[%u];\n", (U64)x, (U64)(16 - sv)));
}
}
VecU8_append_vec(&res, VecU8_fmt("} %s;\n\n", xmatnm));

View File

@ -7,6 +7,7 @@
void generate_margaret_eve_for_vulkan_utils() {
SpanU8 l = cstr("l1");
SpanU8 ns = cstr("margaret");
mkdir_nofail("l1/margaret");
mkdir_nofail("l1/eve/margaret");
generate_util_templ_inst_eve_header(l, ns, (util_templates_instantiation_options){
.T = cstr("MargaretScoredPhysicalDevice"), .t_primitive = true, .vec = true, .sort = true
@ -16,7 +17,7 @@ void generate_margaret_eve_for_vulkan_utils() {
generate_eve_span_company_for_primitive(l, ns, cstr("MargaretIAFreeSegment"), true, false);
generate_Option_templ_inst_eve_header(l, ns, (option_template_instantiation_op){
.T = cstr("MargaretIAFreeSegment"), .t_primitive = true});
// todo: add to BufRBTree instantiator option to create necessary shit by itself
// todo: add to BufRBTree instantiator option to create necessary crrp by itself
generate_eve_span_company_for_primitive(l, ns, cstr("MargaretBAFreeSegment"), true, false);
generate_Option_templ_inst_eve_header(l, ns, (option_template_instantiation_op){
.T = cstr("MargaretBAFreeSegment"), .t_primitive = true});

View File

@ -29,7 +29,8 @@ NODISCARD VecU8 generate_texture_data_struct_and_necc_methods(SpanU8 tex, SpanU8
/* Method _new() */
VecU8_append_vec(&res, VecU8_fmt(
"%s %s_new(U32 width, U32 height) {\n"
SPACE "assert(!(SIZE_MAX / width / height < 100 || UINT32_MAX / width < 10 || UINT32_MAX / height < 10));\n"
SPACE "assert(width == 0 || height == 0 ||\n"
SPACE SPACE "!(SIZE_MAX / width / height < 100 || UINT32_MAX / width < 10 || UINT32_MAX / height < 10));\n"
SPACE "return (%s){.pixels = %s_new_zeroinit((size_t)width * height), .width = width, .height = height};\n"
"}\n\n", tex, tex, tex, pixvec));
/* Method _drop() */

View File

@ -5,22 +5,12 @@
void generate_headers_for_r0_r1_r2_r3() {
SpanU8 l = cstr("l1");
mkdir_nofail("l1/eve");
mkdir_nofail("l1/eve/r0");
{ /* Needed in r0_assets.h */
SpanU8 ns = cstr("r0");
generate_eve_span_company_for_primitive(l, ns, cstr("GenericMeshVertexInc"), true, true);
generate_eve_span_company_for_non_primitive_clonable(l, ns, cstr("GenericMeshInSceneTemplate"), true, false);
generate_eve_span_company_for_primitive(l, ns, cstr("ShinyMeshVertexInc"), true, true);
generate_eve_span_company_for_non_primitive_clonable(l, ns, cstr("ShinyMeshTopology"), true, false);
generate_eve_span_company_for_primitive(l, ns, cstr("Wimbzle"), true, false);
generate_eve_span_company_for_primitive(l, ns, cstr("Nibzle"), true, false);
/* r0_scene.h */
generate_eve_span_company_for_primitive(l, ns, cstr("GenericModelOnSceneMem"), true, false);
generate_eve_span_company_for_primitive(l, ns, cstr("ShinyModelOnSceneMem"), true, false);
generate_eve_span_company_for_primitive(l, ns, cstr("ObjectInfo"), true, false);
/* r0 */
generate_eve_span_company_for_primitive(l, ns, cstr("GenericModelTexVulkPointers"), true, false);
}
mkdir_nofail("l1/eve/r2");
{ /* r2 */
@ -29,12 +19,6 @@ void generate_headers_for_r0_r1_r2_r3() {
.T = cstr("PlayingSound"), .vec_extended = true
});
}
mkdir_nofail("l1/eve/r_alg");
{ /* r_alg. Wow! Even these freaks are here! */
SpanU8 ns = cstr("r_alg");
generate_eve_span_company_for_primitive(l, ns, cstr("I_FishNode"), true, false);
generate_eve_span_company_for_primitive(l, ns, cstr("J_AlphaVertex"), true, false);
}
mkdir_nofail("l1/eve/ds_test");
{ /* This structure is needed for testing purposes only */
generate_eve_span_company_for_primitive(l, cstr("ds_test"), cstr("RefRBTreeNode_S64"), true, false);

View File

@ -77,7 +77,7 @@ def parse_second_symbol(s):
p.skip_word()
if start == p.index:
raise ValueError("This is just fucking disappointing")
raise ValueError("This is just chucking disappointing")
return s[start:p.index]
@ -182,7 +182,7 @@ def process_part_of_file(tokens: List[LineToken], defined_symbols_outside: Set[s
if in_if and (t == token_type_if or t == token_type_ifdef or t == token_type_ifndef or
t == token_type_include_local or t == token_type_define or
t == token_type_regular):
raise ValueError("Okay, listen here, you little fuck")
raise ValueError("Okay, listen here, you little chuck")
# When saw_else is true, we are definitely in_if
if saw_else and t != token_type_endif:

View File

@ -49,7 +49,7 @@ void codegen_append_rbtree_map__structure_and_simplest_methods(
set, set, op.guest_data_T.len == 0 ? vcstr("") : VecU8_fmt("%s guest", op.guest_data_T),
set, op.guest_data_T.len == 0 ? cstr("") : cstr(", .guest = guest")));
// todo: figure out mutability restrictions shit later
// todo: figure out mutability restrictions crrp later
VecU8_append_vec(res, VecU8_fmt(
"RBTreeNode_%s* %s_find_min(const %s* self) {\n" /* TT, set, set */
SPACE "if (self->root == self->NIL)\n"

138
src/l2/alice/assets.h Normal file
View File

@ -0,0 +1,138 @@
#ifndef prototype1_src_l2_alice_assets_h
#define prototype1_src_l2_alice_assets_h
#include "../marie/graphics_geom.h"
#include "../../../gen/l1/VecAndSpan_U32.h"
#include "../../../gen/l1/VecAndSpan_U8.h"
typedef struct {
vec3 pos;
vec2 tex;
} GenericMeshVertexInc;
#include "../../../gen/l1/eve/alice/VecAndSpan_GenericMeshVertexInc.h"
typedef struct {
GenericMeshVertexInc base;
vec3 norm;
vec3 tang_U;
vec3 tang_V;
} GenericMeshVertex;
typedef struct {
VecGenericMeshVertexInc vertices;
VecU32 indexes;
} GenericMeshTopology;
void GenericMeshTopology_drop(GenericMeshTopology self) {
VecGenericMeshVertexInc_drop(self.vertices);
VecU32_drop(self.indexes);
}
GenericMeshTopology GenericMeshTopology_clone(const GenericMeshTopology* self) {
return (GenericMeshTopology){.vertices = VecGenericMeshVertexInc_clone(&self->vertices), .indexes = VecU32_clone(&self->indexes)};
}
typedef struct {
VecU8 topology_path;
VecU8 diffuse_texture_path;
VecU8 normal_texture_path;
VecU8 specular_texture_path;
} AliceGenericMeshPath;
void AliceGenericMeshPath_drop(AliceGenericMeshPath self) {
VecU8_drop(self.topology_path);
VecU8_drop(self.diffuse_texture_path);
VecU8_drop(self.normal_texture_path);
VecU8_drop(self.specular_texture_path);
}
typedef struct {
mat4 model_t;
} GenericMeshInstanceInc;
typedef struct {
GenericMeshInstanceInc base;
mat3 normal_t;
} GenericMeshInstance;
typedef struct {
vec3 pos;
} ShinyMeshVertexInc;
typedef struct {
ShinyMeshVertexInc base;
vec3 normal;
} ShinyMeshVertex;
#include "../../../gen/l1/eve/alice/VecAndSpan_ShinyMeshVertexInc.h"
typedef struct {
VecShinyMeshVertexInc vertices;
VecU32 indexes;
} ShinyMeshTopology;
void ShinyMeshTopology_drop(ShinyMeshTopology self) {
VecShinyMeshVertexInc_drop(self.vertices);
VecU32_drop(self.indexes);
}
ShinyMeshTopology ShinyMeshTopology_clone(const ShinyMeshTopology* self) {
return (ShinyMeshTopology){.vertices = VecShinyMeshVertexInc_clone(&self->vertices),
VecU32_clone(&self->indexes)};
}
typedef struct{
mat4 model_t;
vec3 color_off;
vec3 color_on;
} ShinyMeshInstanceInc;
typedef struct {
ShinyMeshInstanceInc base;
mat3 normal_t;
} ShinyMeshInstance;
typedef struct {
vec2 win_scale;
} Pipeline1PushRangeVertex;
typedef struct {
float gamma_correction_factor;
float hdr_factor;
float lsd_factor;
float anim_time;
} Pipeline1PushRangeFragment;
typedef struct {
vec3 pos;
char _padding_0[4];
vec3 dir;
char _padding_1[4];
vec3 color;
char _padding_2[4];
float d;
char _padding_3[12];
} Pipeline0Spotlight;
typedef struct {
vec3 pos;
char _padding_0[4];
vec3 color;
char _padding_1[4];
} Pipeline0PointLight;
#define pipeline_0_ubo_point_light_max_count 120
#define pipeline_0_ubo_spotlight_max_count 20
typedef struct {
int point_light_count;
int spotlight_count;
char _padding_1[8];
Pipeline0PointLight point_light_arr[pipeline_0_ubo_point_light_max_count];
Pipeline0Spotlight spotlight_arr[pipeline_0_ubo_spotlight_max_count];
} Pipeline0UBO;
#endif

108
src/l2/alice/model_file.h Normal file
View File

@ -0,0 +1,108 @@
#ifndef prototype1_src_l2_alice_model_file_h
#define prototype1_src_l2_alice_model_file_h
#include "../../l1/system/fileio.h"
#include "assets.h"
#include "stdalign.h"
static_assert(sizeof(float) == 4, "...");
static_assert(sizeof(GenericMeshVertexInc) == 4 * (3 + 2), "...");
static_assert(alignof(GenericMeshVertexInc) == 4, "...");
static_assert(sizeof(ShinyMeshVertexInc) == 4 * (3), "...");
static_assert(alignof(ShinyMeshVertexInc) == 4, "...");
/* Yes, at this point I really started thinking that maybe I should have written Alice as a template */
/* Works only within one machine. todo: rewrite to use .obj after the session is over */
void alice_write_generic_mesh_to_file(GenericMeshTopology model, VecU8 file_path){
U64 byte_size = sizeof(U64) * 2 +
sizeof(GenericMeshVertexInc) * model.vertices.len + sizeof(U32) * model.indexes.len;
VecU8 res = VecU8_new_zeroinit(byte_size);
U8* buf = res.buf;
*(U64*)buf = model.vertices.len;
buf += sizeof(U64);
*(U64*)buf = model.indexes.len;
buf += sizeof(U64);
memcpy(buf, model.vertices.buf, model.vertices.len * sizeof(GenericMeshVertexInc));
buf += model.vertices.len * sizeof(GenericMeshVertexInc);
memcpy(buf, model.indexes.buf, model.indexes.len * sizeof(U32));
VecU8_append(&file_path, 0);
write_whole_file_or_abort((const char*)file_path.buf, VecU8_to_span(&res));
GenericMeshTopology_drop(model);
VecU8_drop(file_path);
VecU8_drop(res);
}
GenericMeshTopology alice_expect_read_generic_mesh_from_file(VecU8 file_path){
VecU8 read = read_file_by_path(file_path);
U8* buf = read.buf;
U64 remaining = read.len;
if (remaining < sizeof(U64) * 2) {
abortf("Too short\n");
}
U64 vertices_len = *(U64*)buf;
buf += sizeof(U64);
U64 indexes_len = *(U64*)buf;
buf += sizeof(U64);
if (vertices_len > 1000000 || indexes_len > 1000000) {
abortf("Model is too big\n");
}
remaining -= sizeof(U64) * 2;
if (remaining != vertices_len * sizeof(GenericMeshVertexInc) + indexes_len * sizeof(U32)) {
abortf("Incorrect file size\n");
}
VecGenericMeshVertexInc vertices = VecGenericMeshVertexInc_new_zeroinit(vertices_len);
memcpy(vertices.buf, buf, vertices_len * sizeof(GenericMeshVertexInc));
buf += vertices_len * sizeof(GenericMeshVertexInc);
VecU32 indexes = VecU32_new_zeroinit(indexes_len);
memcpy(indexes.buf, buf, indexes_len * sizeof(U32));
return (GenericMeshTopology){.vertices = vertices, .indexes = indexes};
}
void alice_write_shiny_mesh_to_file(ShinyMeshTopology model, VecU8 file_path){
U64 byte_size = sizeof(U64) * 2 +
sizeof(ShinyMeshVertexInc) * model.vertices.len + sizeof(U32) * model.indexes.len;
VecU8 res = VecU8_new_zeroinit(byte_size);
U8* buf = res.buf;
*(U64*)buf = model.vertices.len;
buf += sizeof(U64);
*(U64*)buf = model.indexes.len;
buf += sizeof(U64);
memcpy(buf, model.vertices.buf, model.vertices.len * sizeof(ShinyMeshVertexInc));
buf += model.vertices.len * sizeof(ShinyMeshVertexInc);
memcpy(buf, model.indexes.buf, model.indexes.len * sizeof(U32));
VecU8_append(&file_path, 0);
write_whole_file_or_abort((const char*)file_path.buf, VecU8_to_span(&res));
ShinyMeshTopology_drop(model);
VecU8_drop(file_path);
VecU8_drop(res);
}
ShinyMeshTopology alice_expect_read_shiny_mesh_from_file(VecU8 file_path){
VecU8 read = read_file_by_path(file_path);
U8* buf = read.buf;
U64 remaining = read.len;
if (remaining < sizeof(U64) * 2) {
abortf("Too short\n");
}
U64 vertices_len = *(U64*)buf;
buf += sizeof(U64);
U64 indexes_len = *(U64*)buf;
buf += sizeof(U64);
if (vertices_len > 10000 || indexes_len > 10000)
abortf("Model is too big\n");
remaining -= sizeof(U64) * 2;
if (remaining != vertices_len * sizeof(ShinyMeshVertexInc) + indexes_len * sizeof(U32)) {
abortf("Incorrect file size\n");
}
VecShinyMeshVertexInc vertices = VecShinyMeshVertexInc_new_zeroinit(vertices_len);
memcpy(vertices.buf, buf, vertices_len * sizeof(ShinyMeshVertexInc));
buf += vertices_len * sizeof(ShinyMeshVertexInc);
VecU32 indexes = VecU32_new_zeroinit(indexes_len);
memcpy(indexes.buf, buf, indexes_len * sizeof(U32));
return (ShinyMeshTopology){.vertices = vertices, .indexes = indexes};
}
/* No beauty, just pure brute force */
#endif

207
src/l2/allie/Allie.hs Normal file
View File

@ -0,0 +1,207 @@
{-# LANGUAGE ForeignFunctionInterface #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE DisambiguateRecordFields #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
module Allie (WlKeyboardKeyState, LucyFace, LucyFaceFixedSize, AliceGenericMeshHand, AliceShinyMeshHand,
AliceGenericMeshInstance(..), AliceShinyMeshInstance(..), AlicePointLight(..), alicePipeline0PointLightMaxCount,
Callbacks(..), aliceMainloop, newAlice, aliceSetSkyColor, aliceNewLucyFace,
aliceLucyFaceOfSize, lucyFaceAddGlyphs, aliceClearText, aliceAddText,
aliceAddGenericMeshHand, aliceGenericMeshResizeInstanceArr, aliceGenericMeshSetInst,
aliceAddShinyMeshHand, aliceShinyMeshResizeInstanceArr, aliceShinyMeshSetInst, aliceGetCamBack,
aliceGetCamPos, aliceSetCamPos, aliceSetPointLightCount, aliceSetPointLight,
aliceIsPressed
) where
import Geom
import Data.Word (Word8, Word16, Word32, Word64)
import Data.Int (Int8, Int16, Int32, Int64)
import Foreign.Ptr (Ptr, FunPtr, nullPtr, plusPtr, castPtr)
import Foreign.Marshal.Alloc (alloca)
import Foreign.Storable (Storable(..))
import Data.IORef (newIORef, readIORef, writeIORef, modifyIORef)
import qualified Data.Text
import Data.Text.Encoding (encodeUtf8)
import Data.ByteString (useAsCStringLen)
type Alice = Ptr Word8
-- Ready
foreign import ccall "allie_alice_new" newAlice :: IO Alice
data WlKeyboardKeyState = WlKeyboardKeyStateReleased | WlKeyboardKeyStatePressed | WlKeyboardKeyStateRepeated
-- data AliceAnotherFrameCap s = AliceAnotherFrameCap Alice
foreign import ccall "wrapper" allieMkAliceOnWaylandKeyboardKey ::
(Ptr () -> Word32 -> Word32 -> IO ()) -> IO (FunPtr (Ptr () -> Word32 -> Word32 -> IO ()))
foreign import ccall "wrapper" allieMkAliceOnAnotherFrame ::
(Ptr () -> Float -> IO ()) -> IO (FunPtr (Ptr () -> Float -> IO ()))
-- All of that is inside Alice. They hold pointers to Alice
type LucyFace = Ptr Word8
-- Actually stores a pointer to rb-tree node in LucyFace tree. Must not be deleted by without caution
type LucyFaceFixedSize = Ptr Word8
type AliceGenericMeshHand = Ptr Word8
type AliceShinyMeshHand = Ptr Word8
data AliceGenericMeshInstance = AliceGenericMeshInstance Mat4
instance Storable AliceGenericMeshInstance where
sizeOf _ = sizeOf (undefined :: Mat4)
alignment _ = 4
peek _ = error "Please don't"
poke ptr (AliceGenericMeshInstance modelT) = poke (castPtr ptr :: Ptr Mat4) modelT
-- model_t color_off color_on
data AliceShinyMeshInstance = AliceShinyMeshInstance Mat4 Vec3 Vec3
instance Storable AliceShinyMeshInstance where
sizeOf _ = sizeOf (undefined :: Mat4)
alignment _ = 4
peek _ = error "Don't do that, please"
poke ptr (AliceShinyMeshInstance modelT colorOff colorOn) = do
poke (castPtr ptr :: Ptr Mat4) modelT
poke (castPtr (ptr `plusPtr` (sizeOf (undefined :: Mat4)) ) :: Ptr Vec3) colorOff
poke (castPtr (ptr `plusPtr` (sizeOf (undefined :: Mat4)) `plusPtr` (sizeOf (undefined :: Vec3))) :: Ptr Vec3) colorOn
-- pos color
data AlicePointLight = AlicePointLight Vec3 Vec3
alicePipeline0PointLightMaxCount :: Int
alicePipeline0PointLightMaxCount = 120
data Callbacks = Callbacks {
onWaylandKeyboardKey :: (Word32 -> Word32 -> IO ()),
onAnotherFrame :: (Float -> IO ())
-- onAnotherFrame :: (forall s. AliceAnotherFrameCap s -> IO ())
}
instance Storable Callbacks where
sizeOf _ = 8 + 8
alignment _ = 8
peek _ = error "Зачем тебе?"
poke ptr Callbacks{..} = do
poke (castPtr ptr) =<< allieMkAliceOnWaylandKeyboardKey (\_ -> onWaylandKeyboardKey)
poke (castPtr ptr `plusPtr` 8) =<< allieMkAliceOnAnotherFrame (\_ -> onAnotherFrame)
foreign import ccall "allie_alice_mainloop" allieAliceMainloop :: Alice -> Ptr Callbacks -> IO ()
aliceMainloop :: Alice -> Callbacks -> IO ()
aliceMainloop alice cb = alloca $ \ptr -> do
poke ptr cb
allieAliceMainloop alice ptr
--aliceClearScreenTextLabel :: AliceAnotherFrameCap s -> IO ()
--aliceClearScreenTextLabel (AliceAnotherFrameCap alice) = allieAliceClearScreenText alice
--aliceAddScreenTextLabel :: AliceAnotherFrameCap s -> String -> IO ()
--aliceAddScreenTextLabel (AliceAnotherFrameCap alice) str = useAsCStringLen
-- (encodeUtf8 $ Data.Text.pack $ str) $ \(cstr, len) ->
-- allieAliceAddScreenTextLabel alice (castPtr cstr) (fromIntegral len)
--allieRunAlice :: Callbacks ->
useAsUtf8StringLen :: String -> (Ptr Word8 -> Word64 -> IO a) -> IO a
useAsUtf8StringLen str cb = useAsCStringLen (encodeUtf8 $ Data.Text.pack $ str) $ \(cstr, len) -> cb (castPtr cstr) (fromIntegral len)
foreign import ccall "allie_alice_set_sky_color" allieAliceSetSkyColor :: Alice -> Float -> Float -> Float -> Float -> IO ()
aliceSetSkyColor :: Alice -> Vec4 -> IO ()
aliceSetSkyColor alice (Vec4 x y z w) = allieAliceSetSkyColor alice x y z w
foreign import ccall "allie_alice_new_lucy_face" allieAliceNewLucyFace :: Alice -> Ptr Word8 -> Word64 -> IO LucyFace
aliceNewLucyFace :: Alice -> String -> IO LucyFace
aliceNewLucyFace alice str = useAsUtf8StringLen str $ \dt len -> allieAliceNewLucyFace alice dt len
-- Maps one to one. Fine
foreign import ccall "allie_alice_lucy_face_of_size" aliceLucyFaceOfSize :: LucyFace -> Word32 -> IO LucyFaceFixedSize
-- Mapsone to one. Good. Too bad right now this only works with one range at a time
-- (which means one range per image)
foreign import ccall "allie_lucy_face_add_glyphs" lucyFaceAddGlyphs :: LucyFaceFixedSize -> Word32 -> Word32 -> IO ()
-- Maps one to one
foreign import ccall "allie_alice_clear_text" aliceClearText :: Alice -> IO ()
foreign import ccall "allie_alice_add_text" allieAliceAddText :: Alice -> LucyFaceFixedSize -> Float -> Float -> Float -> Float ->
Ptr Word8 -> Word64 -> Int32 -> Int32 -> IO ()
aliceAddText :: Alice -> LucyFaceFixedSize -> Vec4 -> String -> Int32 -> Int32 -> IO ()
aliceAddText alice ffs (Vec4 cx cy cz cw) str startPosX startPosY = useAsUtf8StringLen str $ \dt len ->
allieAliceAddText alice ffs cx cy cz cw dt len startPosX startPosY
foreign import ccall "allie_alice_add_generic_mesh_hand" allieAliceAddGenericMeshHand :: Alice ->
Ptr Word8 -> Word64 -> Ptr Word8 -> Word64 -> Ptr Word8 -> Word64 -> Ptr Word8 -> Word64 -> IO AliceGenericMeshHand
-- Path to mesh topology file, path to diffuse texture, path to normal texture, path to specular texture
aliceAddGenericMeshHand :: Alice -> String -> String -> String -> String -> IO AliceGenericMeshHand
aliceAddGenericMeshHand alice p1 p2 p3 p4 = useAsUtf8StringLen p1 $ \d1 l1 ->
(useAsUtf8StringLen p2 $ \d2 l2 -> (useAsUtf8StringLen p3 $ \d3 l3 -> (useAsUtf8StringLen p4 $ \d4 l4 ->
allieAliceAddGenericMeshHand alice d1 l1 d2 l2 d3 l3 d4 l4)))
foreign import ccall "allie_alice_add_shiny_mesh_hand" allie_alice_add_shiny_mesh_hand :: Alice -> Ptr Word8 -> Word64 -> IO AliceShinyMeshHand
aliceAddShinyMeshHand :: Alice -> String -> IO AliceShinyMeshHand
aliceAddShinyMeshHand alice p = useAsUtf8StringLen p $ \dt len -> allie_alice_add_shiny_mesh_hand alice dt len
-- Maps well
foreign import ccall "allie_alice_generic_mesh_resize_instance_arr" aliceGenericMeshResizeInstanceArr :: Alice -> AliceGenericMeshHand -> Word64 -> IO ()
foreign import ccall "allie_alice_shiny_mesh_resize_instance_arr" aliceShinyMeshResizeInstanceArr :: Alice -> AliceShinyMeshHand -> Word64 -> IO ()
foreign import ccall "allie_alice_generic_mesh_set_inst" allieAliceGenericMeshSetInst :: AliceGenericMeshHand -> Word64 -> Ptr AliceGenericMeshInstance -> IO ()
aliceGenericMeshSetInst :: AliceGenericMeshHand -> Word64 -> AliceGenericMeshInstance -> IO ()
aliceGenericMeshSetInst mesh index obj = alloca $ \ptr -> do
poke ptr obj
allieAliceGenericMeshSetInst mesh index ptr
foreign import ccall "allie_alice_shiny_mesh_set_inst" allie_alice_shiny_mesh_set_inst :: AliceShinyMeshHand -> Word64 -> Ptr AliceShinyMeshInstance -> IO ()
aliceShinyMeshSetInst :: AliceShinyMeshHand -> Word64 -> AliceShinyMeshInstance -> IO ()
aliceShinyMeshSetInst mesh index obj = alloca $ \ptr -> do
poke ptr obj
allie_alice_shiny_mesh_set_inst mesh index ptr
foreign import ccall "allie_alice_get_cam_back" allie_alice_get_cam_back :: Alice -> Ptr Vec3 -> IO ()
aliceGetCamBack :: Alice -> IO Vec3
aliceGetCamBack alice = alloca $ \ptr -> do
allie_alice_get_cam_back alice ptr
peek ptr
-- todo: add right and up
foreign import ccall "allie_alice_get_cam_pos" allie_alice_get_cam_pos :: Alice -> Ptr Vec3 -> IO ()
aliceGetCamPos :: Alice -> IO Vec3
aliceGetCamPos alice = alloca $ \ptr -> do
allie_alice_get_cam_pos alice ptr
peek ptr
foreign import ccall "allie_alice_set_cam_pos" allie_alice_set_cam_pos :: Alice -> Float -> Float -> Float -> IO ()
aliceSetCamPos :: Alice -> Vec3 -> IO ()
aliceSetCamPos alice (Vec3 x y z) = allie_alice_set_cam_pos alice x y z
-- Maps well
foreign import ccall "allie_alice_set_point_light_count" aliceSetPointLightCount :: Alice -> Int -> IO ()
foreign import ccall "allie_alice_set_point_light" allie_alice_set_point_light :: Alice -> Int
-> Float -> Float -> Float -> Float -> Float -> Float -> IO ()
aliceSetPointLight :: Alice -> Int -> AlicePointLight -> IO ()
aliceSetPointLight alice index (AlicePointLight (Vec3 px py pz) (Vec3 cx cy cz)) =
allie_alice_set_point_light alice index px py pz cx cy cz
foreign import ccall "alice_is_pressed" aliceIsPressed :: Alice -> Word32 -> IO Bool

115
src/l2/allie/Geom.hs Normal file
View File

@ -0,0 +1,115 @@
module Geom(Vec2(..), Vec3(..), Vec4(..), Mat4(..), Addable(..), Multipliable(..), mat4Transit) where
import Foreign.Storable(Storable(..))
import Foreign.Ptr (Ptr, castPtr, plusPtr)
data Vec2 = Vec2 !Float !Float
deriving (Eq, Show)
data Vec3 = Vec3 !Float !Float !Float
deriving (Eq, Show)
data Vec4 = Vec4 !Float !Float !Float !Float
deriving (Eq, Show)
infixl 6 ^+^
class Addable a where
(^+^) :: a -> a -> a
instance Addable Vec2 where
(Vec2 ax ay) ^+^ (Vec2 bx by) = Vec2 (ax + bx) (ay + by)
instance Addable Vec3 where
(Vec3 ax ay az) ^+^ (Vec3 bx by bz) =
Vec3 (ax + bx) (ay + by) (az + bz)
instance Addable Vec4 where
(Vec4 a1 a2 a3 a4) ^+^ (Vec4 b1 b2 b3 b4) =
Vec4 (a1 + b1) (a2 + b2) (a3 + b3) (a4 + b4)
infixl 7 ^*^
class Multipliable a b c where
(^*^) :: a -> b -> c
instance Multipliable Vec2 Float Vec2 where
(Vec2 ax ay) ^*^ b = Vec2 (ax * b) (ay * b)
instance Multipliable Vec3 Float Vec3 where
(Vec3 ax ay az) ^*^ b = Vec3 (ax * b) (ay * b) (az * b)
instance Multipliable Vec4 Float Vec4 where
(Vec4 ax ay az aw) ^*^ b = Vec4 (ax * b) (ay * b) (az * b) (aw * b)
data Mat4 = Mat4 !Vec4 !Vec4 !Vec4 !Vec4
mat4Transit :: Vec3 -> Mat4
mat4Transit (Vec3 x y z) = Mat4 (Vec4 1 0 0 0) (Vec4 0 1 0 0) (Vec4 0 0 1 0) (Vec4 x y z 1)
instance Storable Vec2 where
sizeOf _ = 2 * sizeOf (undefined :: Float)
alignment _ = 4
peek ptr = do
let fptr = castPtr ptr :: Ptr Float
x <- peek fptr
y <- peek (fptr `plusPtr` sizeOf (undefined :: Float))
return $ Vec2 x y
poke ptr (Vec2 x y) = do
let fptr = castPtr ptr :: Ptr Float
poke fptr x
poke (fptr `plusPtr` sizeOf (undefined :: Float)) y
instance Storable Vec3 where
sizeOf _ = 3 * sizeOf (undefined :: Float)
alignment _ = 4
peek ptr = do
let fptr = castPtr ptr :: Ptr Float
let floatSize = sizeOf (undefined :: Float)
x <- peek fptr
y <- peek (fptr `plusPtr` floatSize)
z <- peek (fptr `plusPtr` (2 * floatSize))
return $ Vec3 x y z
poke ptr (Vec3 x y z) = do
let fptr = castPtr ptr :: Ptr Float
let floatSize = sizeOf (undefined :: Float)
poke fptr x
poke (fptr `plusPtr` floatSize) y
poke (fptr `plusPtr` (2 * floatSize)) z
instance Storable Vec4 where
sizeOf _ = 4 * sizeOf (undefined :: Float)
alignment _ = 4
peek ptr = do
let fptr = castPtr ptr :: Ptr Float
let floatSize = sizeOf (undefined :: Float)
x <- peek fptr
y <- peek (fptr `plusPtr` floatSize)
z <- peek (fptr `plusPtr` (2 * floatSize))
w <- peek (fptr `plusPtr` (3 * floatSize))
return $ Vec4 x y z w
poke ptr (Vec4 x y z w) = do
let fptr = castPtr ptr :: Ptr Float
let floatSize = sizeOf (undefined :: Float)
poke fptr x
poke (fptr `plusPtr` floatSize) y
poke (fptr `plusPtr` (2 * floatSize)) z
poke (fptr `plusPtr` (3 * floatSize)) w
instance Storable Mat4 where
sizeOf _ = 4 * sizeOf (undefined :: Vec4)
alignment _ = 4
peek ptr = do
let vec4Size = sizeOf (undefined :: Vec4)
v1 <- peek (castPtr ptr)
v2 <- peek (ptr `plusPtr` vec4Size)
v3 <- peek (ptr `plusPtr` (2 * vec4Size))
v4 <- peek (ptr `plusPtr` (3 * vec4Size))
return $ Mat4 v1 v2 v3 v4
poke ptr (Mat4 v1 v2 v3 v4) = do
let vec4Size = sizeOf (undefined :: Vec4)
poke (castPtr ptr) v1
poke (ptr `plusPtr` vec4Size) v2
poke (ptr `plusPtr` (2 * vec4Size)) v3
poke (ptr `plusPtr` (3 * vec4Size)) v4

2306
src/l2/allie/allie.c Normal file

File diff suppressed because it is too large Load Diff

10
src/l2/anne/codegen.c Normal file
View File

@ -0,0 +1,10 @@
/* This file generates l2 stuff, but not code. It generates assets. For example: normal textures for simple models */
#include "r4.h"
#include "../../l1/codegen/codegen.h"
int main(){
mkdir_nofail("l2");
gen_assets_for_r4();
finish_layer(cstr("l2"));
}

View File

@ -1,165 +1,16 @@
#ifndef SPLITTER_DRAFT_SRC_L2_TESTS_R0_ASSETS_H
#define SPLITTER_DRAFT_SRC_L2_TESTS_R0_ASSETS_H
#ifndef prototype1_src_l2_anne_r4_h
#define prototype1_src_l2_anne_r4_h
#include "../../marie/graphics_geom.h"
#include "../../../../gen/l1/VecAndSpan_U32.h"
#include "../../../l1/system/fileio.h"
#include "../alice/assets.h"
#include "../../../gen/l1/pixel_masses.h"
#include "../marie/rasterization.h"
#include "../marie/texture_processing.h"
#include <math.h>
#include "../../../../gen/l1/VecAndSpan_vec2.h"
#include "../../../../gen/l1/pixel_masses.h"
#include "../../marie/rasterization.h"
#include "../../marie/texture_processing.h"
typedef struct {
vec3 pos;
vec2 tex;
} GenericMeshVertexInc;
#include "../../../../gen/l1/eve/r0/VecAndSpan_GenericMeshVertexInc.h"
typedef struct {
GenericMeshVertexInc base;
vec3 norm;
vec3 tang_U;
vec3 tang_V;
} GenericMeshVertex;
typedef struct {
VecGenericMeshVertexInc vertices;
VecU32 indexes;
} GenericMeshTopology;
void GenericMeshTopology_drop(GenericMeshTopology self) {
VecGenericMeshVertexInc_drop(self.vertices);
VecU32_drop(self.indexes);
}
GenericMeshTopology GenericMeshTopology_clone(const GenericMeshTopology* self) {
return (GenericMeshTopology){.vertices = VecGenericMeshVertexInc_clone(&self->vertices), .indexes = VecU32_clone(&self->indexes)};
}
typedef struct {
GenericMeshTopology topology;
VecU8 diffuse_texture_path;
VecU8 normal_texture_path;
VecU8 specular_texture_path;
} GenericMeshInSceneTemplate;
void GenericMeshInSceneTemplate_drop(GenericMeshInSceneTemplate self) {
GenericMeshTopology_drop(self.topology);
VecU8_drop(self.diffuse_texture_path);
VecU8_drop(self.normal_texture_path);
VecU8_drop(self.specular_texture_path);
}
GenericMeshInSceneTemplate GenericMeshInSceneTemplate_clone(const GenericMeshInSceneTemplate* self) {
return (GenericMeshInSceneTemplate){.topology = GenericMeshTopology_clone(&self->topology),
.diffuse_texture_path = VecU8_clone(&self->diffuse_texture_path),
.normal_texture_path = VecU8_clone(&self->normal_texture_path),
.specular_texture_path = VecU8_clone(&self->specular_texture_path)};
}
#include "../../../../gen/l1/eve/r0/VecGenericMeshInSceneTemplate.h"
typedef struct {
mat4 model_t;
} GenericMeshInstanceInc;
typedef struct {
GenericMeshInstanceInc base;
mat3 normal_t;
} GenericMeshInstance;
typedef struct {
vec3 pos;
} ShinyMeshVertexInc;
typedef struct {
ShinyMeshVertexInc base;
vec3 normal;
} ShinyMeshVertex;
#include "../../../../gen/l1/eve/r0/VecAndSpan_ShinyMeshVertexInc.h"
typedef struct {
VecShinyMeshVertexInc vertices;
VecU32 indexes;
} ShinyMeshTopology;
void ShinyMeshTopology_drop(ShinyMeshTopology self) {
VecShinyMeshVertexInc_drop(self.vertices);
VecU32_drop(self.indexes);
}
ShinyMeshTopology ShinyMeshTopology_clone(const ShinyMeshTopology* self) {
return (ShinyMeshTopology){.vertices = VecShinyMeshVertexInc_clone(&self->vertices),
VecU32_clone(&self->indexes)};
}
#include "../../../../gen/l1/eve/r0/VecShinyMeshTopology.h"
typedef struct{
mat4 model_t;
vec3 color_off;
vec3 color_on;
} ShinyMeshInstanceInc;
typedef struct {
ShinyMeshInstanceInc base;
mat3 normal_t;
} ShinyMeshInstance;
typedef struct {
vec2 win_scale;
} Pipeline1PushRangeVertex;
typedef struct {
float gamma_correction_factor;
float hdr_factor;
float lsd_factor;
float anim_time;
} Pipeline1PushRangeFragment;
typedef struct {
vec3 pos;
char _padding_0[4];
vec3 dir;
char _padding_1[4];
vec3 color;
char _padding_2[4];
float d;
char _padding_3[12];
} Pipeline0Spotlight;
typedef struct {
vec3 pos;
char _padding_0[4];
vec3 color;
char _padding_1[4];
} Pipeline0PointLight;
typedef struct {
VecGenericMeshInSceneTemplate generic_models;
VecShinyMeshTopology shiny_models;
} SceneTemplate;
void SceneTemplate_drop(SceneTemplate self) {
VecGenericMeshInSceneTemplate_drop(self.generic_models);
}
#define pipeline_0_ubo_point_light_max_count 120
#define pipeline_0_ubo_spotlight_max_count 20
typedef struct {
int point_light_count;
int spotlight_count;
char _padding_1[8];
Pipeline0PointLight point_light_arr[pipeline_0_ubo_point_light_max_count];
Pipeline0Spotlight spotlight_arr[pipeline_0_ubo_spotlight_max_count];
} Pipeline0UBO;
/* generating my cool textures2 */
#include "../../../gen/l1/VecAndSpan_vec2.h"
// todo: move to marie
void TextureDataR8_pixel_maxing(TextureDataR8* self, S32 x, S32 y, U8 val) {
if (x < 0 || y < 0 || (size_t)x >= self->width)
return;
@ -170,10 +21,12 @@ void TextureDataR8_pixel_maxing(TextureDataR8* self, S32 x, S32 y, U8 val) {
*TextureDataR8_mat(self, x, y) = MAX_U8(b, val);
}
// todo: move to marie
U8 a_small_cute_gradient(float r_cut, float r_decay, float dist) {
return dist > r_cut ? 0 : (dist < r_decay) ? 255 : (U8)roundf( 255.f * (r_cut - dist) / (r_cut - r_decay) );
}
// todo: move it to marie
void TextureDataR8_draw_spot_maxing(TextureDataR8* self, vec2 v, float r_cut, float r_decay) {
S32 sx = (S32)roundf(v.x - .5f);
S32 sy = (S32)roundf(v.y - .5f);
@ -188,72 +41,8 @@ void TextureDataR8_draw_spot_maxing(TextureDataR8* self, vec2 v, float r_cut, fl
}
}
GenericMeshTopology generate_one_fourth_of_a_cylinder(float w, float r, U32 k) {
assert(k >= 1);
const float a = M_PI_2f / (float)k;
const float l = 2 * r * sinf(M_PI_4f / (float)k);
float tex_width = 2 * r + w;
float tex_height = 2 * r + (float)k * l;
const vec2 v0tex = {r / tex_width, r / tex_height};
const vec2 v1tex = {(r + w) / tex_width, r / tex_height};
const vec2 v2tex = {r / tex_width, 2 * r / tex_height};
const vec2 v3tex = {(r + w) / tex_width, 2 * r / tex_height};
VecGenericMeshVertexInc vertices = VecGenericMeshVertexInc_new_reserved(8 + 4 * k + (k + 2) * 2);
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {0, 0, 0}, .tex = v0tex});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {w, 0, 0}, .tex = v1tex});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {0, r, 0}, .tex = v2tex});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {w, r, 0}, .tex = v3tex});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {0, 0, 0}, .tex = v0tex});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {w, 0, 0}, .tex = v1tex});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {0, 0, -r}, .tex = {r / tex_width, 0}});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {w, 0, -r}, .tex = {(r + w) / tex_width, 0}});
for (U32 i = 0; i < k; i++) {
for (int j = 0; j < 2; j++) {
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){
.pos = {0, cosf(a * (float)(i + j)) * r, -sinf(a * (float)(i + j)) * r},
.tex = {v2tex.x, v2tex.y + (float)(i + j) * l / tex_height}
});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){
.pos = {w, cosf(a * (float)(i + j)) * r, -sinf(a * (float)(i + j)) * r},
.tex = {v3tex.x, v3tex.y + (float)(i + j) * l / tex_height}
});
}
}
assert(vertices.len == 8 + 4 * k);
for (U32 i = 0; i <= k; i++) {
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){
.pos = {0, cosf(a * (float)i) * r, -sinf(a * (float)i) * r},
.tex = (vec2){ (r - r *sinf(a * (float)i)) / tex_width, (r + r * cosf(a * (float)i)) / tex_height},
});
}
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {0, 0, 0}, .tex = v0tex});
for (U32 i = 0; i <= k; i++) {
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){
.pos = {w, cosf(a * (float)i) * r, -sinf(a * (float)i) * r},
.tex = (vec2){ (r + w + r * sinf(a * (float)i)) / tex_width, (r + r * cosf(a * (float)i)) / tex_height},
});
}
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {w, 0, 0}, .tex = v1tex});
assert(vertices.len == 8 + 4 * k + (k + 2) * 2);
VecU32 indexes = VecU32_new_reserved(3*(4+2*k+2*k));
U32 _span_0[] = {7, 5, 4, 7, 4, 6, 1, 3, 0, 3, 2, 0};
VecU32_append_span(&indexes, (SpanU32){.data = _span_0, .len = ARRAY_SIZE(_span_0)});
for (U32 i = 0; i < k; i++) {
U32 _span_1[] = {
8 + 4 * k + k + 1, 8 + 4 * k + i, 8 + 4 * k + i + 1,
8 + 4 * k + 2 * k + 3, 8 + 4 * k + (k + 2) + i + 1, 8 + 4 * k + (k + 2) + i,
8 + 4 * i + 0, 8 + 4 * i + 1, 8 + 4 * i + 3,
8 + 4 * i + 0, 8 + 4 * i + 3, 8 + 4 * i + 2,
};
VecU32_append_span(&indexes, (SpanU32){.data = _span_1, .len = ARRAY_SIZE(_span_1)});
}
return (GenericMeshTopology){.vertices = vertices, .indexes = indexes};
}
// todo: move to marie, not used here
vec2 perimeter_line_get_thorn_on_vertex(Spanvec2 P, size_t i, float thickness) {
assert(P.len >= 3 && i < P.len);
vec2 A = *Spanvec2_at(P, i ? i - 1 : P.len - 1);
@ -268,6 +57,7 @@ vec2 perimeter_line_get_thorn_on_vertex(Spanvec2 P, size_t i, float thickness) {
return vec2_mul_scal(mat2_mul_vec2(marie_2d_rot_mat2(t), b), thickness / sinf(t));
}
// todo: move to marie
/* It is assumed that A != B */
float distance_to_segment(vec2 A, vec2 B, vec2 P) {
vec2 seg = vec2_minus_vec2(B, A);
@ -279,6 +69,7 @@ float distance_to_segment(vec2 A, vec2 B, vec2 P) {
return len;
}
// todo: move to marie
typedef struct {
TextureDataR8* texture;
vec2 A;
@ -287,6 +78,7 @@ typedef struct {
float r_decay;
} TextureDataR8_draw_perimeter_maxing_H_DrawGuest;
// todo: move to marie
void TextureDataR8_draw_perimeter_maxing_h_draw_guest(void* ug, S32 x, S32 y, vec4 attr) {
TextureDataR8_draw_perimeter_maxing_H_DrawGuest* g = ug;
if (TextureDataR8_is_inside(g->texture, x, y)) {
@ -296,6 +88,7 @@ void TextureDataR8_draw_perimeter_maxing_h_draw_guest(void* ug, S32 x, S32 y, ve
}
}
// todo: move to marie
void TextureDataR8_draw_perimeter_maxing_h_draw_triangle(
TextureDataR8_draw_perimeter_maxing_H_DrawGuest* aboba, vec2 a, vec2 b, vec2 c
) {
@ -304,6 +97,8 @@ void TextureDataR8_draw_perimeter_maxing_h_draw_triangle(
(FnMarieRasterizerCallback){TextureDataR8_draw_perimeter_maxing_h_draw_guest, aboba});
}
// todo: move to marie
/* It is assumed that P[i] != P[i + 1] foreach i from 0 to P.len - 1 */
void TextureDataR8_draw_perimeter_maxing(TextureDataR8* self, Spanvec2 P) {
float r_cut = 5;
@ -331,7 +126,7 @@ typedef struct {
float brd;
} Wimbzle;
#include "../../../../gen/l1/eve/r0/VecWimbzle.h"
#include "../../../gen/l1/eve/r0/VecWimbzle.h"
typedef struct {
vec2 center;
@ -339,7 +134,7 @@ typedef struct {
float hc;
} Nibzle;
#include "../../../../gen/l1/eve/r0/VecNibzle.h"
#include "../../../gen/l1/eve/r0/VecNibzle.h"
typedef struct {
VecWimbzle wimbzles;
@ -627,7 +422,7 @@ void TextureDataR8G8B8A8_draw_triang_part_bublazhuzhka(
// todo: rewrite this crrp (again)
TextureDataR8G8B8A8 generate_tex_template_for_one_fourth_of_a_cylinder(float s_resol, float w, float r, U32 k) {
assert(k >= 1);
const float a = M_PI_2f / (float)k;
@ -637,16 +432,14 @@ TextureDataR8G8B8A8 generate_tex_template_for_one_fourth_of_a_cylinder(float s_r
vec2 cord_resol = {(float)width_pix / (2 * r + w), (float)height_pix / (2 * r + (float)k * l)};
const vec2 v0tex = {r, r};
const vec2 v1tex = {r + w, r};
const vec2 v2tex = {r, 2 * r};
const vec2 v3tex = {r + w, 2 * r};
const vec2 v4tex = {r, 0};
const vec2 v5tex = {r + w, 0};
TextureDataR8G8B8A8 res = TextureDataR8G8B8A8_new(width_pix, height_pix);
mat3x2 cord_resol_trop = (mat3x2){.x.x = cord_resol.x, .y.y = cord_resol.y};
vec3 color_1 = (vec3){0.3f, 0.5f, 0.1f};
TextureDataR8G8B8A8_draw_triangle_of_one_color(&res, color_1, (MarieTriangle){v0tex, v4tex, v5tex}, cord_resol_trop);
TextureDataR8G8B8A8_draw_triangle_of_one_color(&res, color_1, (MarieTriangle){v0tex, v5tex, v1tex}, cord_resol_trop);
TextureDataR8G8B8A8_draw_parametrized_triangle_of_one_color(&res, color_1, (MarieTriangle){v0tex, v4tex, v5tex}, cord_resol_trop);
TextureDataR8G8B8A8_draw_parametrized_triangle_of_one_color(&res, color_1, (MarieTriangle){v0tex, v5tex, v1tex}, cord_resol_trop);
vec3 color_2 = (vec3){0.1f, 0.2f, 0.8f};
vec3 color_3 = (vec3){0.2f, 0.3f, 0.9f};
vec3 color_4 = (vec3){0.1f, 0.5f, 0.7f};
@ -654,12 +447,12 @@ TextureDataR8G8B8A8 generate_tex_template_for_one_fourth_of_a_cylinder(float s_r
for (size_t i = 1; i <= k; i++) {
vec2 A = (vec2){r - r * sinf(a * (float)i), r + r * cosf(a * (float)i)};
vec2 B = (vec2){r - r * sinf(a * (float)(i-1)), r + r * cosf(a * (float)(i-1))};
TextureDataR8G8B8A8_draw_triangle_of_one_color(&res, color_2, (MarieTriangle){v0tex, B, A}, cord_resol_trop);
TextureDataR8G8B8A8_draw_parametrized_triangle_of_one_color(&res, color_2, (MarieTriangle){v0tex, B, A}, cord_resol_trop);
}
for (size_t i = 1; i <= k; i++) {
vec2 A = (vec2){r + w + r * sinf(a * (float)i), r + r * cosf(a * (float)i)};
vec2 B = (vec2){r + w + r * sinf(a * (float)(i-1)), r + r * cosf(a * (float)(i-1))};
TextureDataR8G8B8A8_draw_triangle_of_one_color(&res, color_3, (MarieTriangle){v1tex, A, B}, cord_resol_trop);
TextureDataR8G8B8A8_draw_parametrized_triangle_of_one_color(&res, color_3, (MarieTriangle){v1tex, A, B}, cord_resol_trop);
}
for (size_t i = 1; i <= k; i++) {
vec2 A = (vec2){r, 2 * r + (float)(i) * l};
@ -667,8 +460,9 @@ TextureDataR8G8B8A8 generate_tex_template_for_one_fourth_of_a_cylinder(float s_r
vec2 C = (vec2){r + w, 2 * r + (float)(i-1) * l};
vec2 D = (vec2){r + w, 2 * r + (float)(i) * l};
vec3 c = i % 2 ? color_4 : color_5;
TextureDataR8G8B8A8_draw_triangle_of_one_color(&res, c, (MarieTriangle){A, B, C}, cord_resol_trop);
TextureDataR8G8B8A8_draw_triangle_of_one_color(&res, c, (MarieTriangle){A, C, D}, cord_resol_trop);
// todo: replace this crrp with something more normal
TextureDataR8G8B8A8_draw_parametrized_triangle_of_one_color(&res, c, (MarieTriangle){A, B, C}, cord_resol_trop);
TextureDataR8G8B8A8_draw_parametrized_triangle_of_one_color(&res, c, (MarieTriangle){A, C, D}, cord_resol_trop);
}
Bublazhuzhka crap_on_back_side = fill_rectangle_with_crap(w, r);
@ -686,6 +480,7 @@ vec2 height_map_cb_that_uses_bublazhuzhka(void* ug, vec2 v) {
return Bublazhuzhka_get_derivative(bzh, v);
}
// todo: rewrite this crrp and merge it with other one-fourth-of-a-cylinder generiting functions
TextureDataR8G8B8A8 generate_normal_tex_for_one_fourth_of_a_cylinder(float s_resol, float w, float r, U32 k) {
assert(k >= 1);
const float a = M_PI_2f / (float)k;
@ -733,6 +528,74 @@ TextureDataR8G8B8A8 generate_normal_tex_for_one_fourth_of_a_cylinder(float s_res
return res;
}
GenericMeshTopology generate_one_fourth_of_a_cylinder(float w, float r, U32 k) {
assert(k >= 1);
const float a = M_PI_2f / (float)k;
const float l = 2 * r * sinf(M_PI_4f / (float)k);
float tex_width = 2 * r + w;
float tex_height = 2 * r + (float)k * l;
const vec2 v0tex = {r / tex_width, r / tex_height};
const vec2 v1tex = {(r + w) / tex_width, r / tex_height};
const vec2 v2tex = {r / tex_width, 2 * r / tex_height};
const vec2 v3tex = {(r + w) / tex_width, 2 * r / tex_height};
VecGenericMeshVertexInc vertices = VecGenericMeshVertexInc_new_reserved(8 + 4 * k + (k + 2) * 2);
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {0, 0, 0}, .tex = v0tex});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {w, 0, 0}, .tex = v1tex});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {0, r, 0}, .tex = v2tex});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {w, r, 0}, .tex = v3tex});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {0, 0, 0}, .tex = v0tex});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {w, 0, 0}, .tex = v1tex});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {0, 0, -r}, .tex = {r / tex_width, 0}});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {w, 0, -r}, .tex = {(r + w) / tex_width, 0}});
for (U32 i = 0; i < k; i++) {
for (int j = 0; j < 2; j++) {
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){
.pos = {0, cosf(a * (float)(i + j)) * r, -sinf(a * (float)(i + j)) * r},
.tex = {v2tex.x, v2tex.y + (float)(i + j) * l / tex_height}
});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){
.pos = {w, cosf(a * (float)(i + j)) * r, -sinf(a * (float)(i + j)) * r},
.tex = {v3tex.x, v3tex.y + (float)(i + j) * l / tex_height}
});
}
}
assert(vertices.len == 8 + 4 * k);
for (U32 i = 0; i <= k; i++) {
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){
.pos = {0, cosf(a * (float)i) * r, -sinf(a * (float)i) * r},
.tex = (vec2){ (r - r *sinf(a * (float)i)) / tex_width, (r + r * cosf(a * (float)i)) / tex_height},
});
}
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {0, 0, 0}, .tex = v0tex});
for (U32 i = 0; i <= k; i++) {
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){
.pos = {w, cosf(a * (float)i) * r, -sinf(a * (float)i) * r},
.tex = (vec2){ (r + w + r * sinf(a * (float)i)) / tex_width, (r + r * cosf(a * (float)i)) / tex_height},
});
}
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){.pos = {w, 0, 0}, .tex = v1tex});
assert(vertices.len == 8 + 4 * k + (k + 2) * 2);
VecU32 indexes = VecU32_new_reserved(3*(4+2*k+2*k));
U32 _span_0[] = {7, 5, 4, 7, 4, 6, 1, 3, 0, 3, 2, 0};
VecU32_append_span(&indexes, (SpanU32){.data = _span_0, .len = ARRAY_SIZE(_span_0)});
for (U32 i = 0; i < k; i++) {
U32 _span_1[] = {
8 + 4 * k + k + 1, 8 + 4 * k + i, 8 + 4 * k + i + 1,
8 + 4 * k + 2 * k + 3, 8 + 4 * k + (k + 2) + i + 1, 8 + 4 * k + (k + 2) + i,
8 + 4 * i + 0, 8 + 4 * i + 1, 8 + 4 * i + 3,
8 + 4 * i + 0, 8 + 4 * i + 3, 8 + 4 * i + 2,
};
VecU32_append_span(&indexes, (SpanU32){.data = _span_1, .len = ARRAY_SIZE(_span_1)});
}
return (GenericMeshTopology){.vertices = vertices, .indexes = indexes};
}
U32 quad_to_triangles_conv_arr[6] = {0, 1, 2, 0, 2, 3};
ShinyMeshTopology generate_shiny_cube(float r) {
@ -803,12 +666,233 @@ CubeVertOfFace CubeVertOfFace_next(CubeVertOfFace vert) {
return (CubeVertOfFace){vert.face, (vert.vert_on_it + 1) % 4};
}
GenericMeshInSceneTemplate GenericMeshInSceneTemplate_for_log(U32 w, U32 r, U32 k) {
return (GenericMeshInSceneTemplate){.topology = generate_one_fourth_of_a_cylinder((float)w, (float)r, k),
.diffuse_texture_path = VecU8_format("textures/log_%u_%u_%u_diffuse.png", w, r, k),
.normal_texture_path = VecU8_format("textures/log_%u_%u_%u_NORMAL.png", w, r, k),
.specular_texture_path = VecU8_format("textures/log_%u_%u_%u_specular.png", w, r, k),
#include "../../../gen/l1/margaret/png_pixel_masses.h"
#include "../marie/texture_processing.h"
#include "../../l1/system/fsmanip.h"
#include "../alice/model_file.h"
/* Situation: we generated vertices array of generic mesh, we filled .tex attribute (scaled pixel pos)
* Now I want the normally scaled stuff back */
MarieTriangle restore_triangle_from_mesh_topology(const VecGenericMeshVertexInc* vertices,
U32 texture_width, U32 texture_height, U32 vi1, U32 vi2, U32 vi3){
vec2 tex1 = VecGenericMeshVertexInc_at(vertices, vi1)->tex;
vec2 tex2 = VecGenericMeshVertexInc_at(vertices, vi2)->tex;
vec2 tex3 = VecGenericMeshVertexInc_at(vertices, vi3)->tex;
return (MarieTriangle){
.v0 = {tex1.x * (float)texture_width, tex1.y * (float)texture_height},
.v1 = {tex2.x * (float)texture_width, tex2.y * (float)texture_height},
.v2 = {tex3.x * (float)texture_width, tex3.y * (float)texture_height},
};
}
#endif
/* r is radius, w is length of cylinder. Will write everything into files for us */
void r4_asset_gen_generic_mesh_cylinder(float s_resol, float r, float w, U32 k,
VecU8 path_to_mesh, VecU8 path_to_template_tex, VecU8 path_to_normal_tex){
assert(k >= 3);
VecGenericMeshVertexInc vertices = VecGenericMeshVertexInc_new_reserved(6 * k);
VecU32 indexes = VecU32_new_reserved(3 * (2 * (k - 2) + 2 * k));
U32 uber_square_takes_px = (U32)ceilf(2 * r * s_resol);
float r_px = (float)uber_square_takes_px / 2;
vec2 ubs_front_center = (vec2){r_px, r_px};
U32 back_ubs_x = uber_square_takes_px + 1;
vec2 ubs_back_center = (vec2){(float)back_ubs_x + r_px, r_px};
U32 belt_y = uber_square_takes_px + 1;
/* l is a length of a side. I am 100 % that there is a simpler formula for that */
float l = r * sqrtf(2 - 2 * cosf(2 * M_PIf / (float)k));
U32 belt_takes_px = (U32)ceilf(l * (float)k * s_resol);
float l_px = (float)belt_takes_px / (float)k;
U32 cyl_length_takes_px = (U32)ceilf(w * s_resol);
U32 texture_width = MAX_U32(back_ubs_x + uber_square_takes_px, belt_takes_px);
U32 texture_height = belt_y + cyl_length_takes_px;
for (U32 i = 0; i < k; i++) {
float angle = (float)i * 2 * M_PIf / (float)k;
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){
.pos = {r * cosf(angle), r * sinf(angle), w / 2},
.tex = {
(ubs_front_center.x + cosf(angle) * r_px) / (float)texture_width,
(ubs_front_center.y - sinf(angle) * r_px) / (float)texture_height},
});
}
for (U32 i = 0; i < k; i++) {
float angle = (float)i * 2 * M_PIf / (float)k;
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){
.pos = {r * cosf(angle), r * sinf(angle), -w / 2},
.tex = {
(ubs_back_center.x - cosf(angle) * r_px) / (float)texture_width,
(ubs_back_center.y - sinf(angle) * r_px) / (float)texture_height},
});
}
for (U32 i = 0; i < k; i++) {
float angle = (float)i * 2 * M_PIf / (float)k;
float anext = (float)(i + 1) * 2 * M_PIf / (float)k;
vec2 tex0 = {l_px * (float)i / (float)texture_width, (float)belt_y / (float)texture_height};
vec2 tex4 = {l_px * (float)(i + 1) / (float)texture_width,
(float)(belt_y + cyl_length_takes_px) / (float)texture_height};
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){
.pos = {r * cosf(angle), r * sinf(angle), w / 2},
.tex = tex0
});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){
.pos = {r * cosf(anext), r * sinf(anext), w / 2},
.tex = (vec2){tex4.x, tex0.y}
});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){
.pos = {r * cosf(angle), r * sinf(angle), -w / 2},
.tex = (vec2){tex0.x, tex4.y}
});
VecGenericMeshVertexInc_append(&vertices, (GenericMeshVertexInc){
.pos = {r * cosf(anext), r * sinf(anext), -w / 2},
.tex = tex4
});
}
TextureDataR8G8B8A8 template = TextureDataR8G8B8A8_new(texture_width, texture_height);
for (U32 i = 1; i + 1 < k; i++) {
U32 vis = i;
U32 vin = i + 1;
U32 vic = 0;
VecU32_append_span(&indexes, (SpanU32){.data = (U32[]){vis, vin, vic}, .len = 3});
MarieTriangle tex_trig = restore_triangle_from_mesh_topology(&vertices, texture_width, texture_height,
vis, vin, vic);
TextureDataR8G8B8A8_draw_triangle_of_one_color(&template, (vec3){0.5f, 0.9f, 0.5f}, tex_trig);
}
for (U32 i = 1; i + 1 < k; i++) {
U32 vis = k + i;
U32 vin = k + i + 1;
U32 vic = k;
VecU32_append_span(&indexes, (SpanU32){.data = (U32[]){vin, vis, vic}, .len = 3});
MarieTriangle tex_trig = restore_triangle_from_mesh_topology(&vertices, texture_width, texture_height,
vis, vin, vic);
TextureDataR8G8B8A8_draw_triangle_of_one_color(&template, (vec3){0.2f, 0.1f, 0.9f}, tex_trig);
}
for (U32 i = 0; i < k; i++) {
vec3 color = (i % 3 == 0) ? (vec3){0.8f, 0.8f, 0} :
((i % 3 == 1) ? (vec3){0.6f, 0.2f, 0.7f} : (vec3){0.3f, 0, 0.95f});
U32 v0 = 2 * k + 4 * i;
VecU32_append_span(&indexes, (SpanU32){.data = (U32[]){v0 + 1, v0, v0 + 2, v0 + 1, v0 + 2, v0 + 3}, .len = 6});
MarieTriangle tex_trig_1 = restore_triangle_from_mesh_topology(&vertices, texture_width, texture_height,
v0 + 1, v0, v0 + 2);
TextureDataR8G8B8A8_draw_triangle_of_one_color(&template, color, tex_trig_1);
MarieTriangle tex_trig_2 = restore_triangle_from_mesh_topology(&vertices, texture_width, texture_height,
v0 + 1, v0 + 2, v0 + 3);
TextureDataR8G8B8A8_draw_triangle_of_one_color(&template, color, tex_trig_2);
}
alice_write_generic_mesh_to_file((GenericMeshTopology){.vertices = vertices, .indexes = indexes}, path_to_mesh);
TextureDataR8G8B8A8_write_to_png_nofail(&template, VecU8_to_span(&path_to_template_tex));
VecU8_drop(path_to_template_tex);
TextureDataR8G8B8A8_drop(template);
/* Here I generate normal tex trivially. */
TextureDataR8G8B8A8 normal = TextureDataR8G8B8A8_new(1, 1);
*TextureDataR8G8B8A8_mat(&normal, 0, 0) = compress_normal_vec_into_norm_texel((vec3){0, 1, 0});
/* Right now it's just a pixel... */
TextureDataR8G8B8A8_write_to_png_nofail(&normal, VecU8_to_span(&path_to_normal_tex));
VecU8_drop(path_to_normal_tex);
TextureDataR8G8B8A8_drop(normal);
}
void r4_asset_gen_generic_mesh_quad(float width, float length, VecU8 path_to_save){
VecGenericMeshVertexInc vert = VecGenericMeshVertexInc_from_span((SpanGenericMeshVertexInc){
.data = (GenericMeshVertexInc[]){
{.pos = {0, 0, 0}, .tex = {0, 0}},
{.pos = {width, 0, 0}, .tex = {1, 0}},
{.pos = {0, 0, length}, .tex = {0, 1}},
{.pos = {width, 0, length}, .tex = {1, 1}}
}, .len = 4});
VecU32 indexes = VecU32_from_span((SpanU32){.data = (U32[]){1, 0, 2, 1, 2, 3}, .len = 6});
alice_write_generic_mesh_to_file((GenericMeshTopology){.vertices = vert, .indexes = indexes}, path_to_save);
}
/* a is r at bottom, b is r on top. y is in [0, height]. Shape is symmetrical from Oy */
ShinyMeshTopology generate_shiny_lamp(float height, float a, float b){
ShinyMeshVertexInc vert[24] = {
{{+b, height, +b}},
{{+b, 0, +b}},
{{+b, 0, -b}},
{{+b, height, -b}},
{{-b, 0, -b}},
{{-b, 0, +b}},
{{-b, height, +b}},
{{-b, height, -b}},
{{+b, height, +b}},
{{+b, height, -b}},
{{-b, height, -b}},
{{-b, height, +b}},
{{-b, 0, -b}},
{{+b, 0, -b}},
{{+b, 0, +b}},
{{-b, 0, +b}},
{{+b, height, +b}},
{{-b, height, +b}},
{{-b, 0, +b}},
{{+b, 0, +b}},
{{-b, 0, -b}},
{{-b, height, -b}},
{{+b, height, -b}},
{{+b, 0, -b}},
};
VecShinyMeshVertexInc vertices = VecShinyMeshVertexInc_from_span(
(SpanShinyMeshVertexInc){ .data = vert, .len = ARRAY_SIZE(vert) });
VecU32 indexes = VecU32_new_reserved(36);
for (U32 f = 0; f < 6; f++) {
for (U32 j = 0; j < 6; j++)
VecU32_append(&indexes, f * 4 + quad_to_triangles_conv_arr[j]);
}
return (ShinyMeshTopology){ .vertices = vertices, .indexes = indexes};
}
void generate_one_forth_of_a_cylinder_with_bublazhuzhka(U64 w, U64 r, U64 k) {
{
TextureDataR8G8B8A8 tex = generate_tex_template_for_one_fourth_of_a_cylinder(120, (float)w, (float)r, k);
TextureDataR8G8B8A8 fixed_tex = TextureDataR8G8B8A8_expand_nontransparent_1px(&tex);
VecU8 name = VecU8_fmt("l2/textures/log_%u_%u_%u_TEMPLATE.png", w, r, k);
TextureDataR8G8B8A8_write_to_png_nofail(&fixed_tex, VecU8_to_span(&name));
VecU8_drop(name);
TextureDataR8G8B8A8_drop(fixed_tex);
TextureDataR8G8B8A8_drop(tex);
}
{
TextureDataR8G8B8A8 tex = generate_normal_tex_for_one_fourth_of_a_cylinder(120, (float)w, (float)r, k);
TextureDataR8G8B8A8 fixed_tex = TextureDataR8G8B8A8_expand_nontransparent_1px(&tex);
VecU8 name = VecU8_fmt("l2/textures/log_%u_%u_%u_NORMAL.png", w, r, k);
TextureDataR8G8B8A8_write_to_png_nofail(&fixed_tex, VecU8_to_span(&name));
VecU8_drop(name);
TextureDataR8G8B8A8_drop(fixed_tex);
TextureDataR8G8B8A8_drop(tex);
}
GenericMeshTopology top = generate_one_fourth_of_a_cylinder((float)w, (float)r, k);
alice_write_generic_mesh_to_file(top, VecU8_fmt("l2/models/log_%u_%u_%u.AliceGenericMesh", w, r, k));
}
/* We are on l2 */
int gen_assets_for_r4() {
mkdir_nofail("l2/models");
mkdir_nofail("l2/textures");
mkdir_nofail("l2/textures/r4");
generate_one_forth_of_a_cylinder_with_bublazhuzhka(10, 2, 6);
alice_write_shiny_mesh_to_file(generate_shiny_cube(0.3f), vcstr("l2/models/cube.AliceShinyMesh"));
alice_write_shiny_mesh_to_file(generate_shiny_lamp(0.3f, 0.13f, 0.19f), vcstr("l2/models/lamp.AliceShinyMesh"));
r4_asset_gen_generic_mesh_quad(10, 10, vcstr("l2/models/quad.AliceGenericMesh"));
r4_asset_gen_generic_mesh_cylinder(200, 0.4f, 0.06f, 5, vcstr("l2/models/puck.AliceGenericMesh"),
vcstr("l2/textures/puck_TEMPLATE.png"), vcstr("l2/textures/puck_NORMAL.png"));
r4_asset_gen_generic_mesh_cylinder(80, 0.13f, 1.5f, 4, vcstr("l2/models/stick.AliceGenericMesh"),
vcstr("l2/textures/stick_TEMPLATE.png"), vcstr("l2/textures/stick_NORMAL.png"));
return 0;
}
#endif

View File

@ -6,6 +6,7 @@
#include FT_FREETYPE_H
#include "../../../gen/l1/VecAndSpan_U32Segment.h"
#include "../../../gen/l1/vulkan/VecVkDescriptorImageInfo.h"
#include "../../../gen/l1/pixel_masses.h"
#include "../../l1_5/core/buff_rb_tree_node.h"
#include "../../l1_5/core/rb_tree_node.h"
@ -361,13 +362,15 @@ void LucyGlyphCache_another_frame(LucyGlyphCache* self){
}
/* This function does not check font file for correctness, use only with trusted fonts */
LucyFace LucyFace_new(FT_Library lib, LucyGlyphCache* cache, VecU8 path){
LucyFace* LucyFace_new(FT_Library lib, LucyGlyphCache* cache, VecU8 path){
VecU8_append(&path, 0); // Making it null-terminated
FT_Face face;
FT_Error ret = FT_New_Face(lib, (const char*)path.buf, 0, &face);
check(ret == 0);
VecU8_drop(path);
return (LucyFace){.p = cache, .ft_face = face, .sizes = RBTree_MapU32ToLucyFaceFixedSize_new()};
LucyFace* hand = safe_malloc(sizeof(LucyFace));
*hand = (LucyFace){.p = cache, .ft_face = face, .sizes = RBTree_MapU32ToLucyFaceFixedSize_new()};
return hand;
}
RBTreeNodeLucyFaceFixedSize* LucyFace_of_size(LucyFace* self, U32 size){

View File

@ -5,7 +5,7 @@
#include "../../../gen/l1/pixel_masses.h"
#include "../../../gen/l1/geom.h"
// todo: rewrite this shit crap using instances
// todo: rewrite this crrp crap using instances
typedef struct{
vec4 color;
vec2 pos;
@ -178,7 +178,7 @@ void LucyRenderer_another_frame(LucyRenderer* self){
}
}
// todo: merge with the function above. In the future all the shit will be recorded simultaneously
// todo: merge with the function above. In the future all the crrp will be recorded simultaneously
void LucyRenderer_another_frame_rec_drawing(
LucyRenderer* self, VkCommandBuffer drawing_cmd_buf, VkExtent2D image_extent){
vkCmdBindPipeline(drawing_cmd_buf, VK_PIPELINE_BIND_POINT_GRAPHICS, self->pipeline);

View File

@ -192,20 +192,10 @@ void MargaretBufAllocator_drop(MargaretBufAllocator self){
BufRBTreeByLen_SetMargaretBAFreeSegment_drop(self.mem_free_space);
}
/* Free one subbuffer, not a whole MBA :) */
void MargaretBufAllocator_free(MargaretBufAllocator* self, MargaretSubbuf allocation){
U64Segment left_free_space = MargaretBufAllocator__get_left_free_space(self, &allocation);
U64Segment right_free_space = MargaretBufAllocator__get_right_free_space(self, &allocation);
MargaretBufAllocator__erase_gap(self, allocation.block, left_free_space.start, left_free_space.len);
MargaretBufAllocator__erase_gap(self, allocation.block, right_free_space.start, right_free_space.len);
MargaretBufAllocator__insert_gap(self, allocation.block,
left_free_space.start,
right_free_space.start + right_free_space.len - left_free_space.start);
}
/* Idk how to hide this monster */
void MargaretBufAllocator_debug(const MargaretBufAllocator* self){
if (!self->host_visible)
return;
printf(" ======== MargaretBufAllocator state ======== \n");
int n_segments = (int)self->mem_free_space.el.len;
printf("Blocks:\n");
@ -238,7 +228,24 @@ void MargaretBufAllocator_debug(const MargaretBufAllocator* self){
}
}
/* Free one subbuffer, not a whole MBA :) */
void MargaretBufAllocator_free(MargaretBufAllocator* self, MargaretSubbuf allocation){
U64Segment left_free_space = MargaretBufAllocator__get_left_free_space(self, &allocation);
U64Segment right_free_space = MargaretBufAllocator__get_right_free_space(self, &allocation);
MargaretBufAllocator__erase_gap(self, allocation.block, left_free_space.start, left_free_space.len);
MargaretBufAllocator__erase_gap(self, allocation.block, right_free_space.start, right_free_space.len);
MargaretBufAllocator__insert_gap(self, allocation.block,
left_free_space.start,
right_free_space.start + right_free_space.len - left_free_space.start);
bool eret = BufRBTree_MapU64ToU64_erase(&allocation.block->occupants, allocation.start);
assert(eret);
MargaretBufAllocator_debug(self);
}
NODISCARD MargaretSubbuf MargaretBufAllocator_alloc(MargaretBufAllocator* self, U64 req_size){
MargaretBufAllocator_debug(self);
req_size = margaret_bump_buffer_size_to_alignment(req_size, self->alignment_exp);
VkPhysicalDeviceMaintenance3Properties maintenance3_properties = {
@ -263,9 +270,11 @@ NODISCARD MargaretSubbuf MargaretBufAllocator_alloc(MargaretBufAllocator* self,
new_block->occupation_counter = req_size;
bool iret = BufRBTree_MapU64ToU64_insert(&new_block->occupants, 0, req_size);
assert(iret);
MargaretBufAllocator_debug(self);
return (MargaretSubbuf){.block = &self->blocks.first->el, 0, req_size};
}
MargaretBufAllocator__put_buf_to_a_gap(self, free_gap.some, req_size);
MargaretBufAllocator_debug(self);
return (MargaretSubbuf){.block = free_gap.some.block, .start = free_gap.some.start, req_size};
}
@ -296,12 +305,17 @@ NODISCARD MargaretSubbuf MargaretBufAllocator_expand(
if (allocation->start + bigger_size > right_free_space.start + right_free_space.len){
return MargaretBufAllocator_alloc(self, bigger_size);
}
MargaretBufAllocator_debug(self);
MargaretBufAllocator__erase_gap(self, allocation->block, right_free_space.start, right_free_space.len);
MargaretBufAllocator__insert_gap(self, allocation->block,
allocation->start + bigger_size,
right_free_space.len + (allocation->len - bigger_size));
allocation->len = bigger_size;
U64 my_it = BufRBTree_MapU64ToU64_find(&allocation->block->occupants, allocation->start);
assert(my_it > 0 && my_it <= allocation->block->occupants.el.len);
allocation->block->occupants.el.buf[my_it - 1].value = bigger_size;
MargaretBufAllocator_debug(self);
return (MargaretSubbuf){0};
}
@ -328,7 +342,9 @@ void MargaretBufAllocator_expand_or_move_old_host_visible(
memcpy(MargaretSubbuf_get_mapped(&maybe_bigger), MargaretSubbuf_get_mapped(allocation), allocation->len);
MargaretBufAllocator_free(self, *allocation);
*allocation = maybe_bigger;
MargaretBufAllocator_debug(self);
}
MargaretBufAllocator_debug(self);
}
/* It tries to expand buffer, but if it fails, it creates a freshly-new buffer. It

View File

@ -176,7 +176,7 @@
// todo: for staging buffers you better use MargaretBufferAllocator. Ou, yeah, I have yet to write them
// todo: fucking rewrite all of this. Yes, I want all of this shit rewritten
// todo: chucking rewrite all of this. Yes, I want all of this crrp rewritten
#include "../../l1/core/util.h"
#include "../../l1_5/core/buff_rb_tree_node.h"
@ -442,6 +442,10 @@ void MargaretImgAllocator_free(MargaretImgAllocator* self, MargaretImgAllocation
MargaretImgAllocator__insert_gap(self, allocation.block,
left_free_space.start,
right_free_space.start + right_free_space.len - left_free_space.start);
MargaretImgAllocatorOneBlock* block = VecMargaretImgAllocatorOneBlock_mat(&self->blocks, allocation.block);
bool eret = BufRBTree_MapU64ToU64_erase(&block->images, allocation.start);
assert(eret);
}
NODISCARD MargaretImgAllocation MargaretImgAllocator__alloc(

View File

@ -269,12 +269,12 @@ NODISCARD VecU8 margaret_stringify_device_memory_properties(VkPhysicalDevice phy
vkGetPhysicalDeviceMemoryProperties(physical_device, &properties);
VecU8 result = VecU8_new();
for (size_t h = 0; h < properties.memoryHeapCount; h++) {
VecU8_append_vec(&result, VecU8_format("-+ Heap %ld of %lu bytes [ ", h, properties.memoryHeaps[h].size));
VecU8_append_vec(&result, VecU8_fmt("-+ Heap %u of %u bytes [ ", (U64)h, (U64)properties.memoryHeaps[h].size));
VecU8_append_vec(&result, margaret_stringify_memory_heap_flags(properties.memoryHeaps[h].flags));
VecU8_append_span(&result, cstr(" ], mem types below\n"));
for (size_t t = 0; t < properties.memoryTypeCount; t++) {
if (properties.memoryTypes->heapIndex == h) {
VecU8_append_vec(&result, VecU8_format("----> Mem type %lu [ ", t));
VecU8_append_vec(&result, VecU8_fmt("----> Mem type %u [ ", (U64)t));
VecU8_append_vec(&result, margaret_stringify_memory_property_flags(properties.memoryTypes[t].propertyFlags));
VecU8_append_span(&result, cstr(" ]\n"));
}

View File

@ -64,7 +64,7 @@ void TextureDataR8G8B8A8_draw_triangle_of_one_color_h_draw_guest(void* ug, S32 x
}
/* Given triangle is not natural : it is from parameter space */
void TextureDataR8G8B8A8_draw_triangle_of_one_color(
void TextureDataR8G8B8A8_draw_parametrized_triangle_of_one_color(
TextureDataR8G8B8A8* self, vec3 color, MarieTriangle param_triang, mat3x2 trop
) {
TextureDataR8G8B8A8_draw_triangle_of_one_color_H_DrawGuest aboba =
@ -76,4 +76,13 @@ void TextureDataR8G8B8A8_draw_triangle_of_one_color(
.guest = &aboba});
}
void TextureDataR8G8B8A8_draw_triangle_of_one_color(TextureDataR8G8B8A8* self, vec3 color, MarieTriangle trig){
TextureDataR8G8B8A8_draw_triangle_of_one_color_H_DrawGuest aboba =
{ self, marie_color_vec4_to_cvec4(vec3_and_one(color)) };
marie_rasterize_triangle_with_attr(
(MariePlaneVertAttr){trig.v0, {}}, (MariePlaneVertAttr){trig.v1, {}}, (MariePlaneVertAttr){trig.v2, {}},
(FnMarieRasterizerCallback){.fn = TextureDataR8G8B8A8_draw_triangle_of_one_color_h_draw_guest,
.guest = &aboba});
}
#endif

View File

@ -459,7 +459,7 @@ void chaos(){
check(BufRBTree_SetS64_erase(&set, to_delete));
printf("Deleted from i=%d\n", i);
check_only_structure(&set);
// save_tree_to_file(&set, cstr("fucked_tree"));
// save_tree_to_file(&set, cstr("chucked_tree"));
check_correctness(&set);
VecS64_drop(seq_to_insert);
BufRBTree_SetS64_drop(set);

File diff suppressed because it is too large Load Diff

View File

@ -1,328 +0,0 @@
#ifndef PROTOTYPE1_SRC_L2_TESTS_R0_SCENE_H
#define PROTOTYPE1_SRC_L2_TESTS_R0_SCENE_H
#include "r0_assets.h"
#include "../../margaret/vulkan_utils.h"
#include "../../lucy/glyph_render.h"
typedef struct {
U64 count;
MargaretSubbuf staging_busy;
MargaretSubbuf staging_updatable;
MargaretSubbuf device_local;
U64 cap;
// todo: delete this crap. This crap turned out to be completely useless. It is another one of my very very dumb ideas
// todo: remove updatable buffer, fill staging buffer in main thread
} PatriciaBuf;
void PatriciaBuf_swap_staging(PatriciaBuf* self){
MargaretSubbuf t = self->staging_updatable;
self->staging_updatable = self->staging_busy;
self->staging_busy = t;
}
typedef struct {
size_t indexes;
MargaretSubbuf staging_vbo;
MargaretSubbuf staging_ebo;
// todo: replace TextureDataXXX with MargaretPngPromises
TextureDataR8G8B8A8 pixels_diffuse;
TextureDataR8G8B8A8 pixels_normal;
TextureDataR8 pixels_specular;
MargaretSubbuf staging_diffuse_tex_buf;
MargaretSubbuf staging_normal_tex_buf;
MargaretSubbuf staging_specular_tex_buf;
MargaretSubbuf vbo;
MargaretSubbuf ebo;
PatriciaBuf instance_attr;
// todo: store dimensions of these images
MargaretImg diffuse_texture;
MargaretImg normal_texture;
MargaretImg specular_texture;
} GenericModelOnSceneMem;
#include "../../../../gen/l1/eve/r0/VecGenericModelOnSceneMem.h"
void GenericModelOnSceneMem_set(GenericModelOnSceneMem* self, size_t instance, GenericMeshInstanceInc uncomp){
assert(instance < self->instance_attr.count);
GenericMeshInstance* staging = (GenericMeshInstance*)MargaretSubbuf_get_mapped(&self->instance_attr.staging_updatable);
staging[instance].base = uncomp;
mat4 tr_inv = mat4_transpose(mat4_inverse(uncomp.model_t));
staging[instance].normal_t = mat3_new(
tr_inv.x.x, tr_inv.y.x, tr_inv.z.x,
tr_inv.x.y, tr_inv.y.y, tr_inv.z.y,
tr_inv.x.z, tr_inv.y.z, tr_inv.z.z );
}
typedef struct {
size_t indexes;
MargaretSubbuf staging_vbo;
MargaretSubbuf staging_ebo;
MargaretSubbuf vbo;
MargaretSubbuf ebo;
PatriciaBuf instance_attr;
} ShinyModelOnSceneMem;
#include "../../../../gen/l1/eve/r0/VecShinyModelOnSceneMem.h"
void ShinyModelOnSceneMem_set(ShinyModelOnSceneMem* self, size_t instance, ShinyMeshInstanceInc uncomp){
assert(instance < self->instance_attr.count);
ShinyMeshInstance* staging = (ShinyMeshInstance*)MargaretSubbuf_get_mapped(&self->instance_attr.staging_updatable);
staging[instance].base = uncomp;
mat4 tr_inv = mat4_transpose(mat4_inverse(uncomp.model_t));
staging[instance].normal_t = mat3_new(
tr_inv.x.x, tr_inv.y.x, tr_inv.z.x,
tr_inv.x.y, tr_inv.y.y, tr_inv.z.y,
tr_inv.x.z, tr_inv.y.z, tr_inv.z.z );
}
typedef struct {
float fov;
mat3 cam_basis;
vec3 pos;
float speed;
float sensitivity;
float pitch_cap;
} CamControlInfo;
void CamControlInfo_forward(CamControlInfo* self, float fl) {
self->pos = vec3_add_vec3(self->pos, vec3_mul_scal(self->cam_basis.z, -self->speed * fl));
}
void CamControlInfo_backward(CamControlInfo* self, float fl) {
self->pos = vec3_add_vec3(self->pos, vec3_mul_scal(self->cam_basis.z, self->speed * fl));
}
void CamControlInfo_left(CamControlInfo* self, float fl) {
self->pos = vec3_add_vec3(self->pos, vec3_mul_scal(self->cam_basis.x, -self->speed * fl));
}
void CamControlInfo_right(CamControlInfo* self, float fl) {
self->pos = vec3_add_vec3(self->pos, vec3_mul_scal(self->cam_basis.x, self->speed * fl));
}
void CamControlInfo_down(CamControlInfo* self, float fl) {
self->pos = vec3_add_vec3(self->pos, vec3_mul_scal((vec3){0, -1, 0}, self->speed * fl));
}
void CamControlInfo_up(CamControlInfo* self, float fl) {
self->pos = vec3_add_vec3(self->pos, vec3_mul_scal((vec3){0, 1, 0}, self->speed * fl));
}
CamControlInfo CamControlInfo_new() {
return (CamControlInfo){
.fov = 1.5f, .cam_basis = marie_simple_camera_rot_m_basis_in_cols(0, 0, 0), .pos = {0, 0, 0},
.speed = 6.7f, .sensitivity = 0.5f * M_PIf / 180, .pitch_cap = M_PIf * 0.49f
};
}
void CamControlInfo_update_direction(CamControlInfo* self, int win_width, int win_height, int pointer_x, int pointer_y) {
float yaw = ((float)win_width / 2 - (float)pointer_x) * self->sensitivity;
float pitch = marie_clamp_float(
((float)win_height / 2 - (float)pointer_y) * self->sensitivity,
-self->pitch_cap, self->pitch_cap
);
self->cam_basis = marie_simple_camera_rot_m_basis_in_cols(yaw, pitch, 0);
}
typedef struct {
MargaretSubbuf staging_busy;
MargaretSubbuf staging_updatable;
MargaretSubbuf device_local;
} Pipeline0Transfer;
// Just for a test in r0
typedef struct {
mat3 rotation;
vec3 pos;
float scale;
vec3 color_on;
} ObjectInfo;
#include "../../../../gen/l1/eve/r0/VecObjectInfo.h"
/* Non copyable */
typedef struct {
VecGenericModelOnSceneMem generic_models;
VecShinyModelOnSceneMem shiny_models;
VkClearColorValue color;
float gamma_correction_factor;
float hdr_factor;
float lsd_factor;
float anim_time; // A timer, passed to functions that push push constants
/* point_light_vec_len and spotlight_vec_len are stored in staging (and also device local) buffers */
Pipeline0Transfer pipeline0_ubo;
CamControlInfo cam;
VecObjectInfo smeshnyavka_1;
VecObjectInfo smeshnyavka_3;
VecU8 text_on_screen;
} Scene;
ShinyMeshInstanceInc ShinyMeshInstanceInc_from_ObjectInfo(const ObjectInfo* oi){
return (ShinyMeshInstanceInc){
.model_t = mat4_mul_mat4(marie_translation_mat4(oi->pos),
mat4_mul_mat4(marie_3d_scal_mat4(oi->scale), marie_mat3_to_mat4(oi->rotation))),
.color_on = oi->color_on, .color_off = {1, 0.4f, 0.5f}
};
}
// todo: remove this shit
void Scene_add_smeshnyavka_3(Scene* self, ObjectInfo oi){
ShinyModelOnSceneMem* model_sh = VecShinyModelOnSceneMem_mat(&self->shiny_models, 0);
size_t ni = self->smeshnyavka_3.len;
assert(ni < model_sh->instance_attr.cap);
VecObjectInfo_append(&self->smeshnyavka_3, oi);
model_sh->instance_attr.count = ni + 1;
ShinyModelOnSceneMem_set(model_sh, ni, ShinyMeshInstanceInc_from_ObjectInfo(&oi));
}
// todo: remove this shit (and rewrite everything in haskell)
void Scene_update_smeshnyavka_3(Scene* self, size_t sh_id){
assert(sh_id < self->smeshnyavka_3.len);
const ObjectInfo* oi = VecObjectInfo_at(&self->smeshnyavka_3, sh_id);
ShinyModelOnSceneMem* model_sh = VecShinyModelOnSceneMem_mat(&self->shiny_models, 0);
ShinyModelOnSceneMem_set(model_sh, sh_id, ShinyMeshInstanceInc_from_ObjectInfo(oi));
}
GenericMeshInstanceInc GenericMeshInstanceInc_from_ObjectInfo(const ObjectInfo* oi){
return (GenericMeshInstanceInc){
.model_t = mat4_mul_mat4(marie_translation_mat4(oi->pos),
mat4_mul_mat4(marie_3d_scal_mat4(oi->scale), marie_mat3_to_mat4(oi->rotation))),
};
}
// todo: remove this shit
void Scene_add_smeshnyavka_1(Scene* self, ObjectInfo oi){
GenericModelOnSceneMem* model = VecGenericModelOnSceneMem_mat(&self->generic_models, 0);
size_t ni = self->smeshnyavka_1.len;
assert(ni < model->instance_attr.cap);
VecObjectInfo_append(&self->smeshnyavka_1, oi);
model->instance_attr.count = ni + 1;
GenericModelOnSceneMem_set(model, ni, GenericMeshInstanceInc_from_ObjectInfo(&oi));
}
// todo: remove this shit
void Scene_update_smeshnyavka_1(Scene* self, size_t sh_id){
assert(sh_id < self->smeshnyavka_1.len);
const ObjectInfo* oi = VecObjectInfo_at(&self->smeshnyavka_1, sh_id);
GenericModelOnSceneMem* model = VecGenericModelOnSceneMem_mat(&self->generic_models, 0);
GenericModelOnSceneMem_set(model, sh_id, GenericMeshInstanceInc_from_ObjectInfo(oi));
}
Scene Scene_new(VecGenericModelOnSceneMem generic_models, VecShinyModelOnSceneMem shiny_models,
Pipeline0Transfer pipeline0_ubo) {
return (Scene){.generic_models = generic_models, .shiny_models = shiny_models,
.color = {.float32 = {0, 0, 0, 1}},
.gamma_correction_factor = 2.2f, .hdr_factor = 1, .lsd_factor = 0, .anim_time = 0,
.pipeline0_ubo = pipeline0_ubo, .cam = CamControlInfo_new(),
.smeshnyavka_1 = VecObjectInfo_new(),
.smeshnyavka_3 = VecObjectInfo_new(), // todo: remove this shit and rewrite everything in haskell
.text_on_screen = VecU8_new(),
};
}
void Scene_drop(Scene self) {
VecGenericModelOnSceneMem_drop(self.generic_models);
VecShinyModelOnSceneMem_drop(self.shiny_models);
}
/* No buffer rerecording, no buffer beginning, no buffer ending */
void SceneTemplate_copy_initial_model_topology_cmd_buf_recording(
const SceneTemplate* scene_template, const Scene* scene, VkCommandBuffer command_buffer) {
assert(scene_template->generic_models.len == scene->generic_models.len);
assert(scene_template->shiny_models.len == scene->shiny_models.len);
assert(scene_template->generic_models.len == scene->generic_models.len);
for (size_t mi = 0; mi < scene_template->generic_models.len; mi++) {
const GenericMeshInSceneTemplate* mt = VecGenericMeshInSceneTemplate_at(&scene_template->generic_models, mi);
const GenericModelOnSceneMem *mm = VecGenericModelOnSceneMem_at(&scene->generic_models, mi);
assert(mm->staging_vbo.len >= mt->topology.vertices.len * sizeof(GenericMeshVertex));
assert(mm->vbo.len >= mt->topology.vertices.len * sizeof(GenericMeshVertex));
GenericMeshVertex* staging_vbo = (GenericMeshVertex*)MargaretSubbuf_get_mapped(&mm->staging_vbo);
for (U64 i = 0; i < mt->topology.vertices.len; i++) {
staging_vbo[i].base = mt->topology.vertices.buf[i];
}
assert(mt->topology.indexes.len % 3 == 0);
for (size_t ti = 0; ti * 3 < mt->topology.indexes.len; ti++) {
U32 v0 = mt->topology.indexes.buf[ti * 3 + 0];
U32 v1 = mt->topology.indexes.buf[ti * 3 + 1];
U32 v2 = mt->topology.indexes.buf[ti * 3 + 2];
const GenericMeshVertexInc* A0 = VecGenericMeshVertexInc_at(&mt->topology.vertices, v0);
const GenericMeshVertexInc* A1 = VecGenericMeshVertexInc_at(&mt->topology.vertices, v1);
const GenericMeshVertexInc* A2 = VecGenericMeshVertexInc_at(&mt->topology.vertices, v2);
vec3 dp1 = vec3_minus_vec3(A1->pos, A0->pos);
vec3 dp2 = vec3_minus_vec3(A2->pos, A0->pos);
float du1 = A1->tex.x - A0->tex.x;
float dv1 = A1->tex.y - A0->tex.y;
float du2 = A2->tex.x - A0->tex.x;
float dv2 = A2->tex.y - A0->tex.y;
vec3 norm = vec3_normalize(vec3_cross(dp1, dp2));
mat2x3 tang_U_V = mat3x2_transpose(mat2_mul_mat3x2(
mat2_inverse(mat2_new(du1, dv1, du2, dv2)),
mat2x3_transpose((mat2x3){.x = dp1, .y = dp2})
));
staging_vbo[v0].norm = staging_vbo[v1].norm = staging_vbo[v2].norm = norm;
staging_vbo[v0].tang_U = staging_vbo[v1].tang_U = staging_vbo[v2].tang_U = tang_U_V.x;
staging_vbo[v0].tang_V = staging_vbo[v1].tang_V = staging_vbo[v2].tang_V = tang_U_V.y;
}
margaret_rec_cmd_copy_buffer_one_to_one(command_buffer, &mm->staging_vbo, &mm->vbo);
assert(mt->topology.indexes.len == mm->indexes);
size_t ebo_len = mt->topology.indexes.len * sizeof(U32);
assert(mm->ebo.len >= ebo_len);
U32* staging_ebo = (U32*)MargaretSubbuf_get_mapped(&mm->staging_ebo);
memcpy(staging_ebo, mt->topology.indexes.buf, ebo_len);
margaret_rec_cmd_copy_buffer_one_to_one(command_buffer, &mm->staging_ebo, &mm->ebo);
}
for (size_t mi = 0; mi < scene_template->shiny_models.len; mi++) {
const ShinyMeshTopology* mt = VecShinyMeshTopology_at(&scene_template->shiny_models, mi);
const ShinyModelOnSceneMem *mm = VecShinyModelOnSceneMem_at(&scene->shiny_models, mi);
assert(mm->staging_vbo.len >= mt->vertices.len * sizeof(ShinyMeshVertex));
assert(mm->vbo.len >= mt->vertices.len * sizeof(ShinyMeshVertex));
ShinyMeshVertex* staging_vbo = (ShinyMeshVertex*)MargaretSubbuf_get_mapped(&mm->staging_vbo);
for (U64 i = 0; i < mt->vertices.len; i++) {
staging_vbo[i].base = mt->vertices.buf[i];
}
assert(mt->indexes.len % 3 == 0);
for (size_t ti = 0; ti * 3 < mt->indexes.len; ti++) {
U32 v0 = mt->indexes.buf[ti * 3 + 0];
U32 v1 = mt->indexes.buf[ti * 3 + 1];
U32 v2 = mt->indexes.buf[ti * 3 + 2];
vec3 p0 = VecShinyMeshVertexInc_at(&mt->vertices, v0)->pos;
vec3 p1 = VecShinyMeshVertexInc_at(&mt->vertices, v1)->pos;
vec3 p2 = VecShinyMeshVertexInc_at(&mt->vertices, v2)->pos;
vec3 norm = vec3_normalize(vec3_cross(vec3_minus_vec3(p1, p0), vec3_minus_vec3(p2, p0)));
staging_vbo[v0].normal = staging_vbo[v1].normal = staging_vbo[v2].normal = norm;
}
margaret_rec_cmd_copy_buffer_one_to_one(command_buffer, &mm->staging_vbo, &mm->vbo);
assert(mt->indexes.len == mm->indexes);
size_t ebo_len = mt->indexes.len * sizeof(U32);
assert(mm->ebo.len >= ebo_len);
U32* staging_ebo = (U32*)MargaretSubbuf_get_mapped(&mm->staging_ebo);
memcpy(staging_ebo, mt->indexes.buf, ebo_len);
margaret_rec_cmd_copy_buffer_one_to_one(command_buffer, &mm->staging_ebo, &mm->ebo);
}
}
#endif

View File

@ -1,45 +0,0 @@
#include "r0_assets.h"
#include "../../marie/rasterization.h"
#include "../../../../gen/l1/margaret/png_pixel_masses.h"
#include "../../marie/texture_processing.h"
void for_log(U32 w, U32 r, U32 k) {
{
TextureDataR8G8B8A8 tex = generate_tex_template_for_one_fourth_of_a_cylinder(120, (float)w, (float)r, k);
TextureDataR8G8B8A8 fixed_tex = TextureDataR8G8B8A8_expand_nontransparent_1px(&tex);
VecU8 name = VecU8_format("textures/log_%u_%u_%u_TEMPLATE.png", w, r, k);
TextureDataR8G8B8A8_write_to_png_nofail(&fixed_tex, VecU8_to_span(&name));
VecU8_drop(name);
TextureDataR8G8B8A8_drop(fixed_tex);
TextureDataR8G8B8A8_drop(tex);
}
{
TextureDataR8G8B8A8 tex = generate_normal_tex_for_one_fourth_of_a_cylinder(120, (float)w, (float)r, k);
TextureDataR8G8B8A8 fixed_tex = TextureDataR8G8B8A8_expand_nontransparent_1px(&tex);
VecU8 name = VecU8_format("textures/log_%u_%u_%u_NORMAL.png", w, r, k);
TextureDataR8G8B8A8_write_to_png_nofail(&fixed_tex, VecU8_to_span(&name));
VecU8_drop(name);
TextureDataR8G8B8A8_drop(fixed_tex);
TextureDataR8G8B8A8_drop(tex);
}
}
int main() {
// TextureDataR8G8B8A8 tex = TextureDataR8G8B8A8_read_from_png_nofail(cstr("/home/gregory/test/basn3p04.png"));
// TextureDataR8G8B8A8_print(&tex);
// TextureDataR8G8B8A8_drop(tex);
//
// TextureDataR8G8B8 TEX = TextureDataR8G8B8_read_from_png_nofail(cstr("/home/gregory/test/basn3p04.png"));
// TextureDataR8G8B8_print(&TEX);
// TextureDataR8G8B8_drop(TEX);
// TextureDataR8 tex = TextureDataR8_read_from_png_nofail(cstr("textures/log_5_5_10_TEMPLATE.png"));
// TextureDataR8_print(&tex);
// TextureDataR8_drop(tex);
for_log(10, 2, 6);
for_log(5, 5, 10);
for_log(1, 10, 4);
for_log(2, 1, 6);
return 0;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

View File

@ -608,7 +608,7 @@ int main() {
}
printf("Finished!\n");
vkDeviceWaitIdle(state.device);
// todo: destroy instance and all the shit
// todo: destroy instance and all the crrp
if (state.wl_callback)

56
src/l3/r4/R4.hs Normal file
View File

@ -0,0 +1,56 @@
import Allie
import Geom
import Control.Monad (forM_)
goodColorOfCube :: (Integral a) => a -> Vec3
goodColorOfCube i = ((Vec3 100 0 0) ^*^ t) ^+^ ((Vec3 0 50 90) ^*^ (1 - t)) where t = ((fromIntegral i :: Float) / 4)
goodLightPos :: (Integral a) => a -> Vec3
goodLightPos i = ((Vec3 0 2 1) ^*^ t) ^+^ ((Vec3 5 1 1) ^*^ (1 - t)) where t = ((fromIntegral i :: Float) / 4)
main :: IO()
main = do
alice <- newAlice
aliceSetSkyColor alice (Vec4 0.9 0 0.6 1)
face <- aliceNewLucyFace alice "src/l3/fonts/DMSerifText-Regular.ttf"
faceOf40 <- aliceLucyFaceOfSize face 40
lucyFaceAddGlyphs faceOf40 32 (126 - 32 + 1)
aliceAddText alice faceOf40 (Vec4 1 1 0 1) "Privet" 100 200
weirdStructure <- aliceAddGenericMeshHand alice "gen/l2/models/log_10_2_6.AliceGenericMesh"
"src/l3/textures/log_10_2_6_diffuse.png" "gen/l2/textures/log_10_2_6_NORMAL.png" "src/l3/textures/log_10_2_6_specular.png"
aliceGenericMeshResizeInstanceArr alice weirdStructure 1
aliceGenericMeshSetInst weirdStructure 0 (AliceGenericMeshInstance (mat4Transit (Vec3 (-3.0) (-2.0) (-5.0))))
cube <- aliceAddShinyMeshHand alice "gen/l2/models/cube.AliceShinyMesh"
aliceShinyMeshResizeInstanceArr alice cube 5
aliceSetPointLightCount alice 5
forM_ [0..4] $ \i -> do
aliceShinyMeshSetInst cube i (AliceShinyMeshInstance (mat4Transit (goodLightPos i)) (Vec3 1 1 1) (goodColorOfCube i))
aliceSetPointLight alice (fromIntegral i) (AlicePointLight (goodLightPos i) (goodColorOfCube i))
-- state <- newIORef 67
-- Create the Callbacks structure.
let callbacks = Callbacks myonKeyboardKey myonAnotherFrame where
myonKeyboardKey keysym keyAction = do
-- old <- readIORef state
-- writeIORef state (old + 1)
putStrLn ("Got a keypress")
myonAnotherFrame fl = do
oldPos <- aliceGetCamPos alice
goForward <- aliceIsPressed alice 0x77
if goForward
then do
backDir <- aliceGetCamBack alice
aliceSetCamPos alice (oldPos ^+^ (backDir ^*^ (-fl * 10)))
else return ()
--cur <- readIORef state
--aliceClearScreenTextLabel alicePerm
--aliceAddScreenTextLabel alicePerm ("Current value is = " ++ show cur)
-- Allocate space for the struct, poke it, and pass to C.
aliceMainloop alice callbacks

98
src/l3/r4/r4.c Normal file
View File

@ -0,0 +1,98 @@
#include "../../l2/allie/allie.c"
AliceGenericMeshPath AliceGenericMeshPath_for_log(SpanU8 root_dir, U64 w, U64 r, U64 k) {
return (AliceGenericMeshPath){
.topology_path = VecU8_fmt("%s/gen/l2/models/log_%u_%u_%u.AliceGenericMesh", root_dir, w, r, k),
.diffuse_texture_path = VecU8_fmt("%s/src/l3/textures/log_%u_%u_%u_diffuse.png", root_dir, w, r, k),
.normal_texture_path = VecU8_fmt("%s/gen/l2/textures/log_%u_%u_%u_NORMAL.png", root_dir, w, r, k),
.specular_texture_path = VecU8_fmt("%s/src/l3/textures/log_%u_%u_%u_specular.png", root_dir, w, r, k),
};
}
AliceGenericMeshPath AliceGenericMeshPath_for_puck(){
return (AliceGenericMeshPath){
.topology_path = VecU8_fmt("gen/l2/models/puck.AliceGenericMesh"),
.diffuse_texture_path = VecU8_fmt("src/l3/textures/puck_diffuse.png"),
.normal_texture_path = VecU8_fmt("gen/l2/textures/puck_NORMAL.png"),
.specular_texture_path = VecU8_fmt("src/l3/textures/puck_specular.png"),
};
}
void main_h_on_wayland_keyboard_key(void* data, U32 keysym, U32 act){
}
void main_h_on_another_frame(void* data, float fl){
}
int main(){
Alice* alice = Alice_new();
LucyFace* font_face = LucyFace_new(alice->ft_library, &alice->lucy_cache,
VecU8_fmt("%s/src/l3/fonts/DMSerifText-Regular.ttf", cstr(".")));
RBTreeNodeLucyFaceFixedSize* font_face_of_size_40 = LucyFace_of_size(font_face, 40);
VecLucyGlyphCachingRequest lucy_requests = VecLucyGlyphCachingRequest_new();
VecU32Segment ranges_needed = VecU32Segment_new();
VecU32Segment_append(&ranges_needed, (U32Segment){.start = 32, .len = 126 - 32 + 1});
VecLucyGlyphCachingRequest_append(&lucy_requests, (LucyGlyphCachingRequest){
.sized_face = font_face_of_size_40, .codepoint_ranges = ranges_needed,
});
LucyGlyphCache_add_glyphs(lucy_requests);
LucyRenderer_add_text(&alice->lucy_renderer, font_face_of_size_40, (vec4){1, 0, 0, 1}, 0,
cstr("Bebra budet\notnyahana"), (ivec2){10, 10});
ListNodeAliceGenericMeshHand* model_gen = Alice_add_generic_mesh(alice, AliceGenericMeshPath_for_log(cstr("."), 10, 2, 6));
AliceGenericMeshHand_resize_instance_arr(alice, &model_gen->el, 1);
for (int X = 0; X < 1; X++) {
for (int Z = 0; Z < 1; Z++) {
AliceGenericMeshHand_set_inst(&model_gen->el, X * 10 + Z, (GenericMeshInstanceInc){
.model_t = marie_translation_mat4((vec3){11.f * (float)X, -6, 4.f * (float)Z}),
});
}
}
// ListNodeAliceShinyMeshHand *model_sh = Alice_add_shiny_mesh(alice, vcstr("./gen/l2/models/cube.AliceShinyMesh"));
// AliceShinyMeshHand_resize_instance_arr(alice, &model_sh->el, 100);
// for (int X = 0; X < 10; X++) {
// for (int Z = 0; Z < 10; Z++) {
// AliceShinyMeshHand_set_inst(&model_sh->el, X * 10 + Z, (ShinyMeshInstanceInc){
// .color_on = {0, 1, 0}, .color_off = {0.3f, 0.6f, 0.3f},
// .model_t = marie_translation_mat4((vec3){11.f * (float)X - 20, 10, 4.f * (float)Z - 10}),
// });
// }
// }
// Pipeline0UBO* ubo = (Pipeline0UBO*)MargaretSubbuf_get_mapped(&alice->pipeline0_ubo.staging);
// assert(pipeline_0_ubo_point_light_max_count >= 100);
// ubo->point_light_count = 100;
// ubo->spotlight_count = 0;
// for (int X = 0; X < 10; X++) {
// for (int Z = 0; Z < 10; Z++) {
// ubo->point_light_arr[X * 10 + Z] = (Pipeline0PointLight){
// .pos = (vec3){11.f * (float)X - 20, 10, 4.f * (float)Z - 10},
// .color = {5, 5, 5}
// };
// }
// }
// ubo->point_light_arr[0].color = (vec3){100, 100, 100};
// ListNodeAliceGenericMeshHand* model_puck = Alice_add_generic_mesh(alice, AliceGenericMeshPath_for_puck());
// AliceGenericMeshHand_resize_instance_arr(alice, &model_puck->el, 100);
// for (int X = 0; X < 10; X++) {
// for (int Z = 0; Z < 10; Z++) {
// AliceGenericMeshHand_set_inst(&model_puck->el, X * 10 + Z, (GenericMeshInstanceInc){
// .model_t = marie_translation_mat4((vec3){11.f * (float)X - 20, -1, 4.f * (float)Z - 10}),
// });
// }
// }
Alice_mainloop(alice, &(AliceCallbacks){
.on_wl_keyboard_key = main_h_on_wayland_keyboard_key,
.on_another_frame = main_h_on_another_frame,
});
return 0;
}

BIN
src/l3/textures/asphalt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 860 B

View File

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 106 KiB

View File

Before

Width:  |  Height:  |  Size: 91 KiB

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB