Moved r0 to r4. Which means now we run tests using HASKELL. YAY

This commit is contained in:
Андреев Григорий 2025-12-25 02:09:28 +03:00
parent 93f618f957
commit e5a7e4e567
31 changed files with 795 additions and 777 deletions

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_allie_in_r4 src/l2/allie/allie.c gen/l_wl_protocols/xdg-shell-private.c)
target_link_libraries(l2_allie_in_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:

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

@ -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

@ -29,12 +29,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);

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

@ -0,0 +1,157 @@
#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/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;
#endif

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

@ -0,0 +1,5 @@
{-# LANGUAGE ForeignFunctionInterface #-}
module Allie (allieRun) where
foreign import ccall "allie_run" allieRun :: IO ()

View File

@ -1,17 +1,341 @@
#include "../../margaret/vulkan_utils.h"
#include "../../../../gen/l1/geom.h"
#include <math.h>
#include <sys/mman.h>
#include "../../../l1/system/fileio.h"
#include <time.h>
#include "r0_scene.h"
#include "../alice/assets.h"
#include "../anne/r4_models.h" // todo: this is very illegal, this is very-very illegal. Please, don't do this
#include "../../l1/marie/geom_alg_utils.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);
}
}
/* Here ends the old r0_scene.h file
* And begins old r0.c file */
#include <sys/wait.h>
#include "../../../l1/system/fsmanip.h"
#include "../../../../gen/l_wl_protocols/xdg-shell-client.h"
#include "../../../gen/l1/margaret/png_pixel_masses.h"
#include "../lucy/glyph_cache.h"
#include <sys/mman.h>
//#include "../../l1/system/fileio.h"
#include <math.h>
#include <xkbcommon/xkbcommon.h>
#include "../../../l1/system/creating_child_proc.h"
#include "../../../../gen/l1/margaret/png_pixel_masses.h"
#include "../../lucy/glyph_cache.h"
#include "../../../gen/l_wl_protocols/xdg-shell-client.h"
typedef struct {
VkPipelineLayout pipeline_layout;
@ -96,7 +420,7 @@ VkRenderPass create_render_pass_0(VkDevice logical_device, VkFormat colorbuffer_
}
PipelineHands create_graphics_pipeline_0(
VkDevice device, VkRenderPass render_pass, uint32_t subpass
VkDevice device, SpanU8 root_dir, VkRenderPass render_pass, uint32_t subpass
) {
VkDescriptorSetLayoutBinding bindings_for_my_descr_set_layout[] = {
{
@ -158,8 +482,8 @@ PipelineHands create_graphics_pipeline_0(
abortf("vkCreatePipelineLayout");
VecU8 vert_bin_code = read_whole_file_or_abort(cstr("shaders/spv/0/vert.spv"));
VecU8 frag_bin_code = read_whole_file_or_abort(cstr("shaders/spv/0/frag.spv"));
VecU8 vert_bin_code = read_file_by_path(VecU8_fmt("%s/gen/l_adele/alice/0gen/vert.spv", root_dir));
VecU8 frag_bin_code = read_file_by_path(VecU8_fmt("%s/gen/l_adele/alice/0gen/frag.spv", root_dir));
VkVertexInputBindingDescription vertex_bindings[2] = {
{
@ -250,7 +574,7 @@ PipelineHands create_graphics_pipeline_0(
}
PipelineHands create_graphics_pipeline_0_b(
VkDevice device, VkRenderPass render_pass, uint32_t subpass
VkDevice device, SpanU8 root_dir, VkRenderPass render_pass, uint32_t subpass
) {
VkDescriptorSetLayout my_descriptor_set_layout;
check(vkCreateDescriptorSetLayout(device, &(VkDescriptorSetLayoutCreateInfo){
@ -284,8 +608,8 @@ PipelineHands create_graphics_pipeline_0_b(
}, NULL, &pipeline_layout) == VK_SUCCESS);
VecU8 vert_bin_code = read_whole_file_or_abort(cstr("shaders/spv/0b/vert.spv"));
VecU8 frag_bin_code = read_whole_file_or_abort(cstr("shaders/spv/0b/frag.spv"));
VecU8 vert_bin_code = read_file_by_path(VecU8_fmt("%s/gen/l_adele/alice/0sh/vert.spv", root_dir));
VecU8 frag_bin_code = read_file_by_path(VecU8_fmt("%s/gen/l_adele/alice/0sh/frag.spv", root_dir));
VkVertexInputBindingDescription vertex_bindings[2] = {
{
@ -425,7 +749,7 @@ VkRenderPass create_render_pass_1(VkDevice logical_device, VkFormat image_format
PipelineHands create_graphics_pipeline_1(
VkDevice device, VkRenderPass render_pass, uint32_t subpass
VkDevice device, SpanU8 root_dir, VkRenderPass render_pass, uint32_t subpass
) {
VkDescriptorSetLayoutBinding bindings_for_my_descr_set_layout[] = {
@ -460,8 +784,8 @@ PipelineHands create_graphics_pipeline_1(
}, NULL, &pipeline_layout) == VK_SUCCESS);
VecU8 vert_bin_code = read_whole_file_or_abort(cstr("shaders/spv/1/vert.spv"));
VecU8 frag_bin_code = read_whole_file_or_abort(cstr("shaders/spv/1/frag.spv"));
VecU8 vert_bin_code = read_file_by_path(VecU8_fmt("%s/gen/l_adele/alice/1/vert.spv", root_dir));
VecU8 frag_bin_code = read_file_by_path(VecU8_fmt("%s/gen/l_adele/alice/1/frag.spv", root_dir));
VkPipeline pipeline = margaret_create_triangle_pipeline_one_attachment(device, render_pass, subpass,
(MargaretMostImportantPipelineOptions){
@ -542,7 +866,7 @@ typedef struct {
* Because I am to lazy to create two set layouts for generic model pipeline */
VkDescriptorSet p_0a_set_0;
} GenericModelTexVulkPointers;
#include "../../../../gen/l1/eve/r0/VecGenericModelTexVulkPointers.h"
#include "../../../gen/l1/eve/r0/VecGenericModelTexVulkPointers.h"
void reset_and_record_command_buffer_0(
VkCommandBuffer command_buffer, VkRenderPass render_pass_0,
@ -1478,32 +1802,8 @@ static const struct wl_callback_listener main_h_wl_surface_frame_listener = {
.done = main_h_wl_surface_frame_done,
};
void compile_shader_dir(SpanU8 name, bool have_geom) {
mkdir_nofail("shaders/spv");
VecU8 spv_shader_dir_name = VecU8_fmt("shaders/spv/%s%c", name, 0);
mkdir_nofail((CSTR)spv_shader_dir_name.buf);
VecU8_drop(spv_shader_dir_name);
// todo: write a function that takes a SpanU8
VecU8 vert_cmd = VecU8_fmt("glslc -o shaders/spv/%s/vert.spv shaders/glsl/%s/%s.vert%c", name, name, name, 0);
calling_system_func_nofail((CSTR)vert_cmd.buf);
VecU8_drop(vert_cmd);
if (have_geom) {
VecU8 geom_cmd = VecU8_fmt("glslc -o shaders/spv/%s/geom.spv shaders/glsl/%s/%s.geom%c", name, name, name, 0);
calling_system_func_nofail((CSTR)geom_cmd.buf);
VecU8_drop(geom_cmd);
}
VecU8 frag_cmd = VecU8_fmt("glslc -o shaders/spv/%s/frag.spv shaders/glsl/%s/%s.frag%c", name, name, name, 0);
calling_system_func_nofail((CSTR)frag_cmd.buf);
VecU8_drop(frag_cmd);
}
int main() {
compile_shader_dir(cstr("0"), false);
compile_shader_dir(cstr("0b"), false);
compile_shader_dir(cstr("1"), false);
SpanU8 root_dir = cstr("../../../..");
void allie_run() {
SpanU8 root_dir = cstr(".");
SpanU8 GPU = cstr("nvidia");
SpanU8 bugged_GPU = cstr("nothere");
bool ENABLE_VALIDATION_LAYERS = true;
@ -1585,11 +1885,11 @@ int main() {
vk->IT1_format = OptionVkFormat_expect(IT1_format_found);
vk->render_pass_0 = create_render_pass_0(vk->device, vk->IT1_format, vk->zbuffer_format);
vk->pipeline_hands_0a = create_graphics_pipeline_0(vk->device, vk->render_pass_0, 0);
vk->pipeline_hands_0b = create_graphics_pipeline_0_b(vk->device, vk->render_pass_0, 0);
vk->pipeline_hands_0a = create_graphics_pipeline_0(vk->device, root_dir, vk->render_pass_0, 0);
vk->pipeline_hands_0b = create_graphics_pipeline_0_b(vk->device, root_dir, vk->render_pass_0, 0);
vk->render_pass_1 = create_render_pass_1(vk->device, swapchain_details_res.ok.surface_format.format);
vk->pipeline_hands_1 = create_graphics_pipeline_1(vk->device, vk->render_pass_1, 0);
vk->pipeline_hands_1 = create_graphics_pipeline_1(vk->device, root_dir, vk->render_pass_1, 0);
// These samplers are global for a lot of my future textures
vk->linear_sampler = margaret_create_sampler(vk->physical_device, vk->device, true);
@ -1659,9 +1959,7 @@ int main() {
};
VecGenericMeshInSceneTemplate_append(&vk->scene_template.generic_models,
GenericMeshInSceneTemplate_for_log(10, 2, 6));
// VecGenericMeshInSceneTemplate_append(&vk->scene_template.generic_models,
// GenericMeshInSceneTemplate_for_log(5, 5, 10));
GenericMeshInSceneTemplate_for_log(root_dir, 10, 2, 6));
VecShinyMeshTopology_append(&vk->scene_template.shiny_models, generate_shiny_cube(0.3f));
VecGenericModelOnSceneMem generic_model_mem = VecGenericModelOnSceneMem_new();
@ -1770,7 +2068,8 @@ int main() {
abortf("Can't init free type library\n");
vk->lucy_cache = LucyGlyphCache_new(engine_reference);
vk->font_face = LucyFace_new(vk->ft_library, &vk->lucy_cache, vcstr("fonts/DMSerifText-Regular.ttf"));
vk->font_face = LucyFace_new(vk->ft_library, &vk->lucy_cache,
VecU8_fmt("%s/src/l3/fonts/DMSerifText-Regular.ttf", root_dir));
vk->font_face_of_size_40 = LucyFace_of_size(&vk->font_face, 40);
{
VecLucyGlyphCachingRequest lucy_requests = VecLucyGlyphCachingRequest_new();

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 "r4_models.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;
@ -637,8 +432,6 @@ 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);
@ -733,82 +526,41 @@ TextureDataR8G8B8A8 generate_normal_tex_for_one_fourth_of_a_cylinder(float s_res
return res;
}
U32 quad_to_triangles_conv_arr[6] = {0, 1, 2, 0, 2, 3};
#include "../../../gen/l1/margaret/png_pixel_masses.h"
#include "../marie/texture_processing.h"
#include "../../l1/system/fsmanip.h"
ShinyMeshTopology generate_shiny_cube(float r) {
ShinyMeshVertexInc vert[24] = {
{{+r, +r, +r}},
{{+r, -r, +r}},
{{+r, -r, -r}},
{{+r, +r, -r}},
{{-r, -r, -r}},
{{-r, -r, +r}},
{{-r, +r, +r}},
{{-r, +r, -r}},
{{+r, +r, +r}},
{{+r, +r, -r}},
{{-r, +r, -r}},
{{-r, +r, +r}},
{{-r, -r, -r}},
{{+r, -r, -r}},
{{+r, -r, +r}},
{{-r, -r, +r}},
{{+r, +r, +r}},
{{-r, +r, +r}},
{{-r, -r, +r}},
{{+r, -r, +r}},
{{-r, -r, -r}},
{{-r, +r, -r}},
{{+r, +r, -r}},
{{+r, -r, -r}},
};
VecShinyMeshVertexInc vertices_vec = VecShinyMeshVertexInc_from_span(
(SpanShinyMeshVertexInc){ .data = vert, .len = ARRAY_SIZE(vert) });
VecU32 indexes_vec = VecU32_new_reserved(36);
for (U32 f = 0; f < 6; f++) {
for (U32 j = 0; j < 6; j++)
VecU32_append(&indexes_vec, f * 4 + quad_to_triangles_conv_arr[j]);
void for_log(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/r4/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/r4/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);
}
return (ShinyMeshTopology){ .vertices = vertices_vec, .indexes = indexes_vec};
}
typedef struct {
int face;
/* There is a counterclockwise one-to-one correspondence between vertexes of face and edges of face */
int vert_on_it;
} CubeVertOfFace;
CubeVertOfFace CubeVertOfFace_jump(CubeVertOfFace vert) {
const CubeVertOfFace cube_detour_get_neighbour_face[6][4] = {
{{4, 3}, {3, 1}, {5, 2}, {2, 0}},
{{3, 3}, {4, 1}, {2, 2}, {5, 0}},
{{0, 3}, {5, 1}, {1, 2}, {4, 0}},
{{5, 3}, {0, 1}, {4, 2}, {1, 0}},
{{2, 3}, {1, 1}, {3, 2}, {0, 0}},
{{1, 3}, {2, 1}, {0, 2}, {3, 0}}
};
return cube_detour_get_neighbour_face[vert.face][vert.vert_on_it];
/* We are on l2 */
int gen_assets_for_r4() {
mkdir_nofail("l2/textures");
mkdir_nofail("l2/textures/r4");
for_log(10, 2, 6);
// for_log(5, 5, 10);
// for_log(1, 10, 4);
// for_log(2, 1, 6);
return 0;
}
U32 CubeVertOfFace_to_vid(CubeVertOfFace vert) {
return 4 * vert.face + vert.vert_on_it;
}
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),
};
}
#endif
#endif

156
src/l2/anne/r4_models.h Normal file
View File

@ -0,0 +1,156 @@
#ifndef prototype1_src_l2_anne_r4_models_h
#define prototype1_src_l2_anne_r4_models_h
#include "../alice/assets.h"
#include "../../l1/core/VecU8_as_str.h"
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) {
ShinyMeshVertexInc vert[24] = {
{{+r, +r, +r}},
{{+r, -r, +r}},
{{+r, -r, -r}},
{{+r, +r, -r}},
{{-r, -r, -r}},
{{-r, -r, +r}},
{{-r, +r, +r}},
{{-r, +r, -r}},
{{+r, +r, +r}},
{{+r, +r, -r}},
{{-r, +r, -r}},
{{-r, +r, +r}},
{{-r, -r, -r}},
{{+r, -r, -r}},
{{+r, -r, +r}},
{{-r, -r, +r}},
{{+r, +r, +r}},
{{-r, +r, +r}},
{{-r, -r, +r}},
{{+r, -r, +r}},
{{-r, -r, -r}},
{{-r, +r, -r}},
{{+r, +r, -r}},
{{+r, -r, -r}},
};
VecShinyMeshVertexInc vertices_vec = VecShinyMeshVertexInc_from_span(
(SpanShinyMeshVertexInc){ .data = vert, .len = ARRAY_SIZE(vert) });
VecU32 indexes_vec = VecU32_new_reserved(36);
for (U32 f = 0; f < 6; f++) {
for (U32 j = 0; j < 6; j++)
VecU32_append(&indexes_vec, f * 4 + quad_to_triangles_conv_arr[j]);
}
return (ShinyMeshTopology){ .vertices = vertices_vec, .indexes = indexes_vec};
}
typedef struct {
int face;
/* There is a counterclockwise one-to-one correspondence between vertexes of face and edges of face */
int vert_on_it;
} CubeVertOfFace;
CubeVertOfFace CubeVertOfFace_jump(CubeVertOfFace vert) {
const CubeVertOfFace cube_detour_get_neighbour_face[6][4] = {
{{4, 3}, {3, 1}, {5, 2}, {2, 0}},
{{3, 3}, {4, 1}, {2, 2}, {5, 0}},
{{0, 3}, {5, 1}, {1, 2}, {4, 0}},
{{5, 3}, {0, 1}, {4, 2}, {1, 0}},
{{2, 3}, {1, 1}, {3, 2}, {0, 0}},
{{1, 3}, {2, 1}, {0, 2}, {3, 0}}
};
return cube_detour_get_neighbour_face[vert.face][vert.vert_on_it];
}
U32 CubeVertOfFace_to_vid(CubeVertOfFace vert) {
return 4 * vert.face + vert.vert_on_it;
}
CubeVertOfFace CubeVertOfFace_next(CubeVertOfFace vert) {
return (CubeVertOfFace){vert.face, (vert.vert_on_it + 1) % 4};
}
// todo: yes, it is AGAINST THE RULES to take from l3 when being on l2, but we fjsdafklj lI WILL REMOVE THIS OK, MAN CALM DOWN
GenericMeshInSceneTemplate GenericMeshInSceneTemplate_for_log(SpanU8 root_dir, U64 w, U64 r, U64 k) {
return (GenericMeshInSceneTemplate){.topology = generate_one_fourth_of_a_cylinder((float)w, (float)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/r4/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),
};
}
// todo: separate model data generation and create a function that writes it to .obj file
// todo numero 2: stop generating model data on the fly in r4 and start loading it from generated file
#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"

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

@ -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

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

@ -0,0 +1,4 @@
import Allie
main :: IO()
main = allieRun

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