diff --git a/base/tools/icon.png b/base/icon.png similarity index 100% rename from base/tools/icon.png rename to base/icon.png diff --git a/base/sources/iron.h b/base/sources/iron.h index 3acd13a3..c435e1db 100644 --- a/base/sources/iron.h +++ b/base/sources/iron.h @@ -809,7 +809,7 @@ i32 color_set_ab(i32 c, u8 i) { // ██║ ██╗ ██║ ██║ ╚██████╔╝ ██║ ╚═╝ ██║ // ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ -void iron_init(string_t *title, i32 width, i32 height, bool vsync, i32 window_mode, i32 window_features, i32 x, i32 y, i32 frequency) { +void iron_init(string_t *title, i32 width, i32 height, bool vsync, i32 window_mode, i32 window_features, i32 x, i32 y, i32 frequency, bool use_depth) { kinc_window_options_t win; kinc_framebuffer_options_t frame; win.title = title; @@ -825,7 +825,7 @@ void iron_init(string_t *title, i32 width, i32 height, bool vsync, i32 window_mo win.display_index = -1; win.visible = enable_window; frame.color_bits = 32; - frame.depth_bits = 0; + frame.depth_bits = use_depth ? 24 : 0; kinc_init(title, win.width, win.height, &win, &frame); kinc_random_init((int)(kinc_time() * 1000)); diff --git a/base/sources/ts/config.ts b/base/sources/ts/config.ts index 42677dcb..f7d75cc7 100644 --- a/base/sources/ts/config.ts +++ b/base/sources/ts/config.ts @@ -213,7 +213,8 @@ function config_get_options(): kinc_sys_ops_t { mode: window_mode, features: window_features, vsync: config_raw.window_vsync, - frequency: config_raw.window_frequency + frequency: config_raw.window_frequency, + use_depth: false }; return ops; } diff --git a/base/sources/ts/iron/iron.ts b/base/sources/ts/iron/iron.ts index 1aa75a31..80f01e53 100644 --- a/base/sources/ts/iron/iron.ts +++ b/base/sources/ts/iron/iron.ts @@ -180,7 +180,7 @@ declare function color_set_gb(c: i32, i: u8): i32; declare function color_set_bb(c: i32, i: u8): i32; declare function color_set_ab(c: i32, i: u8): i32; -declare function iron_init(title: string, width: i32, height: i32, vsync: bool, window_mode: i32, window_features: i32, x: i32, y: i32, frequency: i32): void; +declare function iron_init(title: string, width: i32, height: i32, vsync: bool, window_mode: i32, window_features: i32, x: i32, y: i32, frequency: i32, use_depth: bool): void; declare function iron_set_app_name(name: string): void; declare function iron_log(v: any): void; declare function iron_g4_clear(flags: i32, color: i32, depth: f32): void; diff --git a/base/sources/ts/iron/sys.ts b/base/sources/ts/iron/sys.ts index 2e261a03..8a2c6ed4 100644 --- a/base/sources/ts/iron/sys.ts +++ b/base/sources/ts/iron/sys.ts @@ -23,7 +23,7 @@ let _sys_window_title: string; let _sys_shaders: map_t = map_create(); function sys_start(ops: kinc_sys_ops_t) { - iron_init(ops.title, ops.width, ops.height, ops.vsync, ops.mode, ops.features, ops.x, ops.y, ops.frequency); + iron_init(ops.title, ops.width, ops.height, ops.vsync, ops.mode, ops.features, ops.x, ops.y, ops.frequency, ops.use_depth); _sys_start_time = iron_get_time(); g2_init(); @@ -419,6 +419,7 @@ type kinc_sys_ops_t = { mode?: window_mode_t; frequency?: i32; vsync?: bool; + use_depth?: bool; }; enum window_features_t { diff --git a/base/tools/tests/cube/assets/cube.arm b/base/tests/cube/assets/cube.arm similarity index 100% rename from base/tools/tests/cube/assets/cube.arm rename to base/tests/cube/assets/cube.arm diff --git a/base/tools/tests/cube/assets/texture.png b/base/tests/cube/assets/texture.png similarity index 100% rename from base/tools/tests/cube/assets/texture.png rename to base/tests/cube/assets/texture.png diff --git a/base/tools/tests/cube/project.js b/base/tests/cube/project.js similarity index 57% rename from base/tools/tests/cube/project.js rename to base/tests/cube/project.js index 0f471eda..3a3a30d4 100644 --- a/base/tools/tests/cube/project.js +++ b/base/tests/cube/project.js @@ -3,11 +3,11 @@ let flags = globalThis.flags; flags.with_iron = true; flags.lite = true; -let project = new Project("Test"); -project.add_project("../../../"); +let project = new Project("test"); +project.add_project("../../"); project.add_tsfiles("sources"); -project.add_tsfiles("../../../sources/ts/iron"); -project.add_shaders("../../../shaders/draw/*.glsl"); +project.add_tsfiles("../../sources/ts/iron"); +project.add_shaders("../../shaders/draw/*.glsl"); project.add_shaders("shaders/*.glsl"); project.add_assets("assets/*", { destination: "data/{name}" }); diff --git a/base/tools/tests/cube/shaders/mesh.frag.glsl b/base/tests/cube/shaders/mesh.frag.glsl similarity index 100% rename from base/tools/tests/cube/shaders/mesh.frag.glsl rename to base/tests/cube/shaders/mesh.frag.glsl diff --git a/base/tools/tests/cube/shaders/mesh.vert.glsl b/base/tests/cube/shaders/mesh.vert.glsl similarity index 100% rename from base/tools/tests/cube/shaders/mesh.vert.glsl rename to base/tests/cube/shaders/mesh.vert.glsl diff --git a/base/tools/tests/cube/sources/main.ts b/base/tests/cube/sources/main.ts similarity index 100% rename from base/tools/tests/cube/sources/main.ts rename to base/tests/cube/sources/main.ts diff --git a/base/tests/fall/assets/cube.arm b/base/tests/fall/assets/cube.arm new file mode 100644 index 00000000..0c9d28da Binary files /dev/null and b/base/tests/fall/assets/cube.arm differ diff --git a/base/tests/fall/assets/sphere.arm b/base/tests/fall/assets/sphere.arm new file mode 100644 index 00000000..f779ebb4 Binary files /dev/null and b/base/tests/fall/assets/sphere.arm differ diff --git a/base/tests/fall/assets/texture.png b/base/tests/fall/assets/texture.png new file mode 100644 index 00000000..87cbe835 Binary files /dev/null and b/base/tests/fall/assets/texture.png differ diff --git a/base/tests/fall/project.js b/base/tests/fall/project.js new file mode 100644 index 00000000..6017b167 --- /dev/null +++ b/base/tests/fall/project.js @@ -0,0 +1,15 @@ + +let flags = globalThis.flags; +flags.with_iron = true; +flags.lite = true; + +let project = new Project("test"); +project.add_project("../../"); +project.add_tsfiles("sources"); +project.add_cfiles("../../sources/libs/asim/asim.c"); +project.add_tsfiles("../../sources/ts/iron"); +project.add_shaders("../../shaders/draw/*.glsl"); +project.add_shaders("shaders/*.glsl"); +project.add_assets("assets/*", { destination: "data/{name}" }); + +return project; diff --git a/base/tests/fall/shaders/mesh.frag.glsl b/base/tests/fall/shaders/mesh.frag.glsl new file mode 100644 index 00000000..f2a1f5f9 --- /dev/null +++ b/base/tests/fall/shaders/mesh.frag.glsl @@ -0,0 +1,18 @@ +#version 450 + +in vec2 tex_coord; +in vec3 normal; + +out vec4 frag_color; + +uniform sampler2D my_texture; + +void main() { + vec3 l = vec3(0.5, 0.0, 0.5); + vec3 base_color = vec3(1.0, 1.0, 1.0); // texture(my_texture, tex_coord).rgb; + vec3 ambient = base_color * 0.5; + vec3 n = normalize(normal); + float dotnl = max(dot(n, l), 0.0); + vec3 diffuse = dotnl * base_color; + frag_color = vec4(ambient + diffuse, 1.0); +} diff --git a/base/tests/fall/shaders/mesh.vert.glsl b/base/tests/fall/shaders/mesh.vert.glsl new file mode 100644 index 00000000..d7de2b2a --- /dev/null +++ b/base/tests/fall/shaders/mesh.vert.glsl @@ -0,0 +1,16 @@ +#version 450 + +in vec4 pos; +in vec2 nor; +in vec2 tex; + +out vec3 normal; +out vec2 tex_coord; + +uniform mat4 WVP; + +void main() { + normal = vec3(nor.xy, pos.w); + tex_coord = tex; + gl_Position = WVP * vec4(pos.xyz, 1.0); +} diff --git a/base/tests/fall/sources/camera.ts b/base/tests/fall/sources/camera.ts new file mode 100644 index 00000000..cbd1abbc --- /dev/null +++ b/base/tests/fall/sources/camera.ts @@ -0,0 +1,47 @@ + +function camera_update() { + let camera: camera_object_t = scene_camera; + let move_forward: bool = keyboard_down("w"); + let move_backward: bool = keyboard_down("s"); + let strafe_left: bool = keyboard_down("a"); + let strafe_right: bool = keyboard_down("d"); + let strafe_up: bool = keyboard_down("e"); + let strafe_down: bool = keyboard_down("q"); + let fast: f32 = keyboard_down("shift") ? 2.0 : 1.0; + let speed: f32 = 5.0; + let dir: vec4_t = vec4_create(); + + if (move_forward || move_backward || strafe_right || strafe_left || strafe_up || strafe_down) { + let clook: vec4_t = camera_object_look(camera); + let cright: vec4_t = camera_object_right(camera); + + if (move_forward) { + dir = vec4_fadd(dir, clook.x, clook.y, clook.z); + } + if (move_backward) { + dir = vec4_fadd(dir, -clook.x, -clook.y, -clook.z); + } + if (strafe_right) { + dir = vec4_fadd(dir, cright.x, cright.y, cright.z); + } + if (strafe_left) { + dir = vec4_fadd(dir, -cright.x, -cright.y, -cright.z); + } + if (strafe_up) { + dir = vec4_fadd(dir, 0, 0, 1); + } + if (strafe_down) { + dir = vec4_fadd(dir, 0, 0, -1); + } + } + + let d: f32 = time_delta() * speed * fast; + if (d > 0.0) { + transform_move(camera.base.transform, dir, d); + } + + if (mouse_down()) { + transform_rotate(camera.base.transform, vec4_z_axis(), -mouse_movement_x / 200); + transform_rotate(camera.base.transform, camera_object_right(camera), -mouse_movement_y / 200); + } +} diff --git a/base/tests/fall/sources/main.ts b/base/tests/fall/sources/main.ts new file mode 100644 index 00000000..f2879a54 --- /dev/null +++ b/base/tests/fall/sources/main.ts @@ -0,0 +1,163 @@ +// ../../../make --graphics vulkan --run + +///include "../../sources/libs/asim/asim.h" + +function main() { + let ops: kinc_sys_ops_t = { + title: "Empty", + width: 1280, + height: 720, + x: -1, + y: -1, + features: window_features_t.RESIZABLE | window_features_t.MINIMIZABLE | window_features_t.MAXIMIZABLE, + mode: window_mode_t.WINDOWED, + frequency: 60, + vsync: true, + use_depth: true + }; + sys_start(ops); + app_init(); + app_ready(); +} + +function render_commands() { + render_path_set_target(""); + render_path_clear_target(0xff6495ed, 1.0, clear_flag_t.COLOR | clear_flag_t.DEPTH); + render_path_draw_meshes("mesh"); +} + +function app_ready() { + render_path_commands = render_commands; + + let scene: scene_t = { + name: "Scene", + objects: [ + { + name: "Cube", + type: "mesh_object", + data_ref: "cube.arm/Cube", + material_refs: ["MyMaterial"], + visible: true, + spawn: true + }, + { + name: "Sphere", + type: "mesh_object", + data_ref: "sphere.arm/Sphere", + material_refs: ["MyMaterial"], + visible: true, + spawn: true + }, + { + name: "Camera", + type: "camera_object", + data_ref: "MyCamera", + visible: true, + spawn: true + } + ], + camera_datas: [ + { + name: "MyCamera", + near_plane: 0.1, + far_plane: 100.0, + fov: 0.85 + } + ], + camera_ref: "Camera", + material_datas: [ + { + name: "MyMaterial", + shader: "MyShader", + contexts: [ + { + name: "mesh", + bind_textures: [ + { + name: "my_texture", + file: "texture.k" + } + ] + } + ] + } + ], + shader_datas: [ + { + name: "MyShader", + contexts: [ + { + name: "mesh", + vertex_shader: "mesh.vert", + fragment_shader: "mesh.frag", + compare_mode: "less", + cull_mode: "clockwise", + depth_write: true, + vertex_elements: [ + { + name: "pos", + data: "short4norm" + }, + { + name: "nor", + data: "short2norm" + }, + { + name: "tex", + data: "short2norm" + } + ], + constants: [ + { + name: "WVP", + type: "mat4", + link: "_world_view_proj_matrix" + } + ], + texture_units: [ + { + name: "my_texture" + } + ] + } + ] + } + ] + }; + map_set(data_cached_scene_raws, scene.name, scene); + + // Instantiate scene + scene_create(scene); + scene_ready(); +} + +function scene_ready() { + // Set camera + let t: transform_t = scene_camera.base.transform; + t.loc = vec4_create(0, -10, 0); + t.rot = quat_from_to(vec4_create(0, 0, 1), vec4_create(0, -1, 0)); + transform_build_matrix(t); + + app_notify_on_update(scene_update); + + let cube: object_t = scene_get_child("Cube"); + let mesh: mesh_object_t = cube.ext; + + asim_init(mesh.data.vertex_arrays[0].values, mesh.data.index_arrays[0].values, mesh.data.scale_pos); +} + +function scene_update() { + asim_update(); + camera_update(); + + if (keyboard_started("space")) { + asim_set_sphere(0, 0, 5); + } + + let sphere: object_t = scene_get_child("Sphere"); + let t: transform_t = sphere.transform; + t.loc.x = asim_get_sphere_x(); + t.loc.y = asim_get_sphere_y(); + t.loc.z = asim_get_sphere_z(); + transform_build_matrix(t); +} diff --git a/base/tools/tests/triangle/main.ts b/base/tests/triangle/main.ts similarity index 100% rename from base/tools/tests/triangle/main.ts rename to base/tests/triangle/main.ts diff --git a/base/tools/tests/triangle/project.js b/base/tests/triangle/project.js similarity index 56% rename from base/tools/tests/triangle/project.js rename to base/tests/triangle/project.js index 38eba89a..09abc2f0 100644 --- a/base/tools/tests/triangle/project.js +++ b/base/tests/triangle/project.js @@ -3,9 +3,9 @@ let flags = globalThis.flags; flags.with_iron = true; flags.lite = true; -let project = new Project("Test"); -project.add_project("../../../"); +let project = new Project("test"); +project.add_project("../../"); project.add_tsfiles("./"); -project.add_tsfiles("../../../sources/ts/iron"); +project.add_tsfiles("../../sources/ts/iron"); project.add_shaders("./*.glsl"); return project; diff --git a/base/tools/tests/triangle/test.frag.glsl b/base/tests/triangle/test.frag.glsl similarity index 100% rename from base/tools/tests/triangle/test.frag.glsl rename to base/tests/triangle/test.frag.glsl diff --git a/base/tools/tests/triangle/test.vert.glsl b/base/tests/triangle/test.vert.glsl similarity index 100% rename from base/tools/tests/triangle/test.vert.glsl rename to base/tests/triangle/test.vert.glsl diff --git a/base/tools/tests/asim/project.js b/base/tools/tests/asim/project.js deleted file mode 100644 index b0eba11c..00000000 --- a/base/tools/tests/asim/project.js +++ /dev/null @@ -1,13 +0,0 @@ -let project = new Project("plugins"); - -project.add_cfiles("plugin_api.c"); -project.add_cfiles("plugins.c"); - -if (flags.physics) { - project.add_cfiles("phys_jolt/phys_jolt.cpp"); - project.add_cfiles("phys_jolt/Jolt/**"); - project.add_include_dir("phys_jolt"); - project.add_define("JPH_NO_DEBUG"); -} - -return project; diff --git a/base/tools/tests/cube/tsconfig.json b/base/tools/tests/cube/tsconfig.json deleted file mode 100644 index 85d99e05..00000000 --- a/base/tools/tests/cube/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "./build/tsconfig.json" -}