From eaad06863fcf4c7edc685cb06e2fe5f78be231b2 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Sat, 4 May 2024 22:10:40 +0200 Subject: [PATCH] "fix" compile errs --- Cargo.lock | 146 ++------- Cargo.toml | 7 +- kubi-logging/src/lib.rs | 128 ++++---- kubi/Cargo.toml | 4 +- kubi/src/cursor_lock.rs | 9 +- kubi/src/events.rs | 2 +- kubi/src/hui_integration.rs | 16 +- kubi/src/lib.rs | 69 ++-- kubi/src/prefabs.rs | 76 +++-- kubi/src/prefabs/texture.rs | 91 +++--- kubi/src/rendering.rs | 115 ++++++- kubi/src/rendering/entities.rs | 116 +++---- kubi/src/rendering/primitives.rs | 50 +-- kubi/src/rendering/primitives/cube.rs | 170 +++++----- kubi/src/rendering/primitives/rect.rs | 62 ++-- kubi/src/rendering/primitives/stri.rs | 54 ++-- kubi/src/rendering/selection_box.rs | 118 +++---- kubi/src/rendering/sumberge.rs | 74 ++--- kubi/src/rendering/world.rs | 441 +++++++++++++------------- kubi/src/ui/loading_screen.rs | 8 +- kubi/src/ui/settings_ui.rs | 4 +- kubi/src/world/chunk.rs | 9 +- kubi/src/world/loading.rs | 31 +- 23 files changed, 886 insertions(+), 914 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6c2f356..91cadc2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -244,32 +244,13 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" -[[package]] -name = "block-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae85a0696e7ea3b835a453750bf002770776609115e6d25c6d2ff28a8200f7e7" -dependencies = [ - "objc-sys", -] - -[[package]] -name = "block2" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15b55663a85f33501257357e6421bb33e769d5c9ffb5ba0921c975a123e35e68" -dependencies = [ - "block-sys", - "objc2 0.4.1", -] - [[package]] name = "block2" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43ff7d91d3c1d568065b06c899777d1e48dcf76103a672a0adbc238a7f247f1e" dependencies = [ - "objc2 0.5.1", + "objc2", ] [[package]] @@ -1027,8 +1008,8 @@ checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" [[package]] name = "hui" -version = "0.1.0-alpha.4" -source = "git+https://github.com/griffi-gh/hui?rev=dd5af8b9e2#dd5af8b9e2dc4cb2beb0b130d82167258ea2bd4e" +version = "0.1.0-alpha.5" +source = "git+https://github.com/griffi-gh/hui?rev=3a50d2d0dde#3a50d2d0dde7044d02860dac9ab059bd353657a2" dependencies = [ "derive_more", "derive_setters", @@ -1041,13 +1022,14 @@ dependencies = [ "log", "nohash-hasher", "rect_packer", + "rustc-hash", "tinyset", ] [[package]] name = "hui-derive" -version = "0.1.0-alpha.4" -source = "git+https://github.com/griffi-gh/hui?rev=dd5af8b9e2#dd5af8b9e2dc4cb2beb0b130d82167258ea2bd4e" +version = "0.1.0-alpha.5" +source = "git+https://github.com/griffi-gh/hui?rev=3a50d2d0dde#3a50d2d0dde7044d02860dac9ab059bd353657a2" dependencies = [ "quote", "syn 2.0.60", @@ -1055,13 +1037,13 @@ dependencies = [ [[package]] name = "hui-winit" -version = "0.1.0-alpha.4" -source = "git+https://github.com/griffi-gh/hui?rev=dd5af8b9e2#dd5af8b9e2dc4cb2beb0b130d82167258ea2bd4e" +version = "0.1.0-alpha.5" +source = "git+https://github.com/griffi-gh/hui?rev=3a50d2d0dde#3a50d2d0dde7044d02860dac9ab059bd353657a2" dependencies = [ "glam", "hui", "log", - "winit 0.29.15", + "winit", ] [[package]] @@ -1093,17 +1075,6 @@ dependencies = [ "cc", ] -[[package]] -name = "icrate" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d3aaff8a54577104bafdf686ff18565c3b6903ca5782a2026ef06e2c7aa319" -dependencies = [ - "block2 0.3.0", - "dispatch", - "objc2 0.4.1", -] - [[package]] name = "ident_case" version = "1.0.1" @@ -1281,7 +1252,7 @@ dependencies = [ "uflow", "wgpu", "winapi", - "winit 0.30.0", + "winit", ] [[package]] @@ -1649,16 +1620,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "da284c198fb9b7b0603f8635185e85fbd5b64ee154b1ed406d489077de2d6d60" -[[package]] -name = "objc2" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "559c5a40fdd30eb5e344fbceacf7595a81e242529fb4e21cf5f43fb4f11ff98d" -dependencies = [ - "objc-sys", - "objc2-encode 3.0.0", -] - [[package]] name = "objc2" version = "0.5.1" @@ -1666,7 +1627,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4b25e1034d0e636cd84707ccdaa9f81243d399196b8a773946dcffec0401659" dependencies = [ "objc-sys", - "objc2-encode 4.0.1", + "objc2-encode", ] [[package]] @@ -1675,8 +1636,8 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb79768a710a9a1798848179edb186d1af7e8a8679f369e4b8d201dd2a034047" dependencies = [ - "block2 0.5.0", - "objc2 0.5.1", + "block2", + "objc2", "objc2-core-data", "objc2-foundation", ] @@ -1687,17 +1648,11 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e092bc42eaf30a08844e6a076938c60751225ec81431ab89f5d1ccd9f958d6c" dependencies = [ - "block2 0.5.0", - "objc2 0.5.1", + "block2", + "objc2", "objc2-foundation", ] -[[package]] -name = "objc2-encode" -version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d079845b37af429bfe5dfa76e6d087d788031045b25cfc6fd898486fd9847666" - [[package]] name = "objc2-encode" version = "4.0.1" @@ -1710,9 +1665,9 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfaefe14254871ea16c7d88968c0ff14ba554712a20d76421eec52f0a7fb8904" dependencies = [ - "block2 0.5.0", + "block2", "dispatch", - "objc2 0.5.1", + "objc2", ] [[package]] @@ -2000,15 +1955,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8ffb4dfda4b01cc420847665dc480760d596ce186f2772a66ed32fe9acb1c45" -[[package]] -name = "redox_syscall" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.4.1" @@ -2815,16 +2761,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "web-time" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa30049b1c872b72c89866d458eae9f20380ab280ffd1b1e18df2d3e2d98cfe0" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "web-time" version = "1.1.0" @@ -3009,15 +2945,6 @@ dependencies = [ "windows-targets 0.42.2", ] -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - [[package]] name = "windows-sys" version = "0.52.0" @@ -3205,41 +3132,6 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" -[[package]] -name = "winit" -version = "0.29.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d59ad965a635657faf09c8f062badd885748428933dad8e8bdd64064d92e5ca" -dependencies = [ - "android-activity 0.5.2", - "atomic-waker", - "bitflags 2.5.0", - "calloop", - "cfg_aliases 0.1.1", - "core-foundation", - "core-graphics", - "cursor-icon", - "icrate", - "js-sys", - "libc", - "log", - "ndk 0.8.0", - "ndk-sys 0.5.0+25.2.9519653", - "objc2 0.4.1", - "once_cell", - "orbclient", - "redox_syscall 0.3.5", - "rustix", - "smol_str", - "unicode-segmentation", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "web-time 0.2.4", - "windows-sys 0.48.0", - "xkbcommon-dl", -] - [[package]] name = "winit" version = "0.30.0" @@ -3262,7 +3154,7 @@ dependencies = [ "libc", "memmap2", "ndk 0.9.0", - "objc2 0.5.1", + "objc2", "objc2-app-kit", "objc2-foundation", "orbclient", @@ -3283,7 +3175,7 @@ dependencies = [ "wayland-protocols", "wayland-protocols-plasma", "web-sys", - "web-time 1.1.0", + "web-time", "windows-sys 0.52.0", "x11-dl", "x11rb", diff --git a/Cargo.toml b/Cargo.toml index ae628a0..1a981bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,10 +21,13 @@ opt-level = 1 [profile.dev.package.uflow] opt-level = 3 -[profile.dev.package.glium] +[profile.dev.package.wgpu] opt-level = 3 -[profile.dev.package.bracket-noise] +[profile.dev.package.wgpu-core] +opt-level = 3 + +[profile.dev.package.wgpu-hal] opt-level = 3 [profile.dev.package.fastnoise-lite] diff --git a/kubi-logging/src/lib.rs b/kubi-logging/src/lib.rs index 34b8a89..71242dc 100644 --- a/kubi-logging/src/lib.rs +++ b/kubi-logging/src/lib.rs @@ -1,64 +1,64 @@ -//! Custom env_logger options and styling - -/// Custom env_logger options and styling -#[inline] -#[cfg(not(target_os = "android"))] -pub fn init() { - use log::Level; - use std::io::Write; - use env_logger::{fmt::Color, Builder, Env}; - - let env = Env::default() - .filter_or("RUST_LOG", "trace,gilrs=warn,rusty_xinput=warn"); - Builder::from_env(env) - .format(|buf, record| { - let mut level_style = buf.style(); - level_style.set_color(match record.level() { - Level::Error => Color::Red, - Level::Warn => Color::Yellow, - Level::Debug | Level::Trace => Color::Cyan, - _ => Color::Blue - }).set_bold(true); - - let mut bold_style = buf.style(); - bold_style.set_bold(true); - - let mut location_style = buf.style(); - location_style.set_bold(true); - location_style.set_dimmed(true); - - let mut location_line_style = buf.style(); - location_line_style.set_dimmed(true); - - let text = format!("{}", record.args()); - - writeln!( - buf, - "{} {:<50}\t{}{}{}{}", - level_style.value(match record.level() { - Level::Error => "[e]", - Level::Warn => "[w]", - Level::Info => "[i]", - Level::Debug => "[d]", - Level::Trace => "[t]", - }), - text, - bold_style.value((text.len() > 50).then_some("\n ╰─ ").unwrap_or_default()), - location_style.value(record.target()), - location_line_style.value(" :"), - location_line_style.value(record.line().unwrap_or(0)) - ) - }) - .init(); -} - -/// Custom env_logger options and styling -#[inline] -#[cfg(target_os = "android")] -pub fn init() { - use log::LevelFilter; - use android_logger::Config; - android_logger::init_once( - Config::default().with_max_level(LevelFilter::Trace), - ); -} +//! Custom env_logger options and styling + +/// Custom env_logger options and styling +#[inline] +#[cfg(not(target_os = "android"))] +pub fn init() { + use log::Level; + use std::io::Write; + use env_logger::{fmt::Color, Builder, Env}; + + let env = Env::default() + .filter_or("RUST_LOG", "trace,gilrs=warn,rusty_xinput=warn,wgpu=warn,wgpu_core=warn,wgpu_hal=warn,hui=info,hui-winit=info,hui-glium=info,hui-wgpu=info"); + Builder::from_env(env) + .format(|buf, record| { + let mut level_style = buf.style(); + level_style.set_color(match record.level() { + Level::Error => Color::Red, + Level::Warn => Color::Yellow, + Level::Debug | Level::Trace => Color::Cyan, + _ => Color::Blue + }).set_bold(true); + + let mut bold_style = buf.style(); + bold_style.set_bold(true); + + let mut location_style = buf.style(); + location_style.set_bold(true); + location_style.set_dimmed(true); + + let mut location_line_style = buf.style(); + location_line_style.set_dimmed(true); + + let text = format!("{}", record.args()); + + writeln!( + buf, + "{} {:<50}\t{}{}{}{}", + level_style.value(match record.level() { + Level::Error => "[e]", + Level::Warn => "[w]", + Level::Info => "[i]", + Level::Debug => "[d]", + Level::Trace => "[t]", + }), + text, + bold_style.value((text.len() > 50).then_some("\n ╰─ ").unwrap_or_default()), + location_style.value(record.target()), + location_line_style.value(" :"), + location_line_style.value(record.line().unwrap_or(0)) + ) + }) + .init(); +} + +/// Custom env_logger options and styling +#[inline] +#[cfg(target_os = "android")] +pub fn init() { + use log::LevelFilter; + use android_logger::Config; + android_logger::init_once( + Config::default().with_max_level(LevelFilter::Trace), + ); +} diff --git a/kubi/Cargo.toml b/kubi/Cargo.toml index 057fcc7..27e7864 100644 --- a/kubi/Cargo.toml +++ b/kubi/Cargo.toml @@ -11,8 +11,8 @@ crate-type = ["lib", "cdylib"] [dependencies] kubi-shared = { path = "../kubi-shared" } kubi-logging = { path = "../kubi-logging" } -hui = { version = "0.1.0-alpha.4", git = "https://github.com/griffi-gh/hui", rev = "dd5af8b9e2" } -hui-winit = { version = "0.1.0-alpha.4", git = "https://github.com/griffi-gh/hui", rev = "dd5af8b9e2" } +hui = { git = "https://github.com/griffi-gh/hui", rev = "3a50d2d0dde" } +hui-winit = { git = "https://github.com/griffi-gh/hui", rev = "3a50d2d0dde", features = ["winit_30"] } log = "0.4" wgpu = { version = "0.20", features = ["webgl"] } pollster = "0.3" diff --git a/kubi/src/cursor_lock.rs b/kubi/src/cursor_lock.rs index 11c572a..8e195d7 100644 --- a/kubi/src/cursor_lock.rs +++ b/kubi/src/cursor_lock.rs @@ -1,5 +1,5 @@ use shipyard::{AllStoragesView, IntoIter, NonSendSync, Unique, UniqueView, UniqueViewMut, View}; -use crate::{events::InputDeviceEvent, rendering::{Renderer, WindowSize}}; +use crate::{events::InputDeviceEvent, rendering::Renderer}; use winit::{ dpi::PhysicalPosition, event::{DeviceEvent, ElementState, RawKeyEvent}, keyboard::{KeyCode, PhysicalKey}, window::CursorGrabMode }; @@ -16,7 +16,7 @@ pub fn update_cursor_lock_state( } if lock.is_inserted_or_modified() { //TODO MIGRATION - let window = &display.window; + let window = display.window(); window.set_cursor_grab(match lock.0 { true => CursorGrabMode::Confined, false => CursorGrabMode::None, @@ -42,7 +42,6 @@ pub fn debug_toggle_lock( mut lock: UniqueViewMut, device_events: View, ren: NonSendSync>, - size: UniqueView, ) { for evt in device_events.iter() { if let DeviceEvent::Key(RawKeyEvent { @@ -51,8 +50,8 @@ pub fn debug_toggle_lock( }) = evt.event { lock.0 = !lock.0; if !lock.0 { - let center = PhysicalPosition::new(size.0.x as f64 / 2., size.0.y as f64 / 2.); - let _ = ren.window.set_cursor_position(center); + let center = PhysicalPosition::new(ren.size().width as f64 / 2., ren.size().height as f64 / 2.); + let _ = ren.window().set_cursor_position(center); } } } diff --git a/kubi/src/events.rs b/kubi/src/events.rs index fe03a7b..84bad45 100644 --- a/kubi/src/events.rs +++ b/kubi/src/events.rs @@ -91,7 +91,7 @@ pub fn initial_resize_event( ) { let (w, h) = { let renderer = storages.borrow::>>().unwrap(); - renderer.display.get_framebuffer_dimensions() + (renderer.size().width, renderer.size().height) }; storages.add_entity(( EventComponent, diff --git a/kubi/src/hui_integration.rs b/kubi/src/hui_integration.rs index f28c05e..15b862c 100644 --- a/kubi/src/hui_integration.rs +++ b/kubi/src/hui_integration.rs @@ -1,7 +1,7 @@ use hui::UiInstance; //use hui_glium::GliumUiRenderer; use shipyard::{AllStoragesView, Unique, UniqueView, NonSendSync, UniqueViewMut}; -use crate::rendering::{RenderTarget, Renderer, WindowSize}; +use crate::rendering::{Renderer, WindowSize}; #[derive(Unique)] pub struct UiState { @@ -34,13 +34,13 @@ pub fn kubi_ui_end( //renderer.update(hui); } -pub fn kubi_ui_draw( - ui: NonSendSync>, - mut target: NonSendSync>, - size: UniqueView -) { - //ui.renderer.draw(&mut target.0, size.0.as_vec2()); -} +// pub fn kubi_ui_draw( +// ui: NonSendSync>, +// mut target: NonSendSync>, +// size: UniqueView +// ) { +// ui.renderer.draw(&mut target.0, size.0.as_vec2()); +// } pub fn hui_process_winit_events( event: &winit::event::Event<()>, diff --git a/kubi/src/lib.rs b/kubi/src/lib.rs index 8d1b5bc..90b3559 100644 --- a/kubi/src/lib.rs +++ b/kubi/src/lib.rs @@ -75,18 +75,12 @@ use events::{ }; use input::{init_input, process_inputs}; use player_controller::{debug_switch_ctl_type, update_player_controllers}; +// use rendering::{ +// clear_background, entities::render_entities, init_window_size, primitives::init_primitives, resize_renderer, selection_box::render_selection_box, sumberge::render_submerged_view, update_window_size, world::{draw_current_chunk_border, draw_world, draw_world_trans, init_trans_chunk_queue}, BackgroundColor, RenderTarget, Renderer +// }; use rendering::{ - Renderer, - RenderTarget, - BackgroundColor, - clear_background, - init_window_size, - update_window_size, - primitives::init_primitives, - world::{init_trans_chunk_queue, draw_world, draw_world_trans, draw_current_chunk_border}, - selection_box::render_selection_box, - entities::render_entities, - sumberge::render_submerged_view, + init_window_size, resize_renderer, update_window_size, + BackgroundColor, Renderer }; use block_placement::update_block_placement; use delta_time::{DeltaTime, init_delta_time}; @@ -95,7 +89,7 @@ use control_flow::{exit_on_esc, insert_control_flow_unique, RequestExit}; use state::{is_ingame, is_ingame_or_loading, is_loading, init_state, update_state, is_connecting}; use networking::{update_networking, update_networking_late, is_multiplayer, disconnect_on_exit, is_singleplayer}; use init::initialize_from_args; -use hui_integration::{kubi_ui_begin, kubi_ui_draw, kubi_ui_end, kubi_ui_init}; +use hui_integration::{kubi_ui_begin, /*kubi_ui_draw,*/ kubi_ui_end, kubi_ui_init}; use loading_screen::update_loading_screen; use connecting_screen::update_connecting_screen; use fixed_timestamp::init_fixed_timestamp_storage; @@ -121,7 +115,7 @@ fn startup() -> Workload { init_window_size, kubi_ui_init, load_prefabs, - init_primitives, + //init_primitives, insert_lock_state, init_state, initialize_from_args, @@ -132,7 +126,7 @@ fn startup() -> Workload { init_client_physics, init_chat_manager, init_crosshair_image, - init_trans_chunk_queue, + //init_trans_chunk_queue, ).into_sequential_workload() } @@ -140,6 +134,7 @@ fn update() -> Workload { ( debug_toggle_lock, update_window_size, + resize_renderer, update_cursor_lock_state, process_inputs, kubi_ui_begin, @@ -181,20 +176,20 @@ fn update() -> Workload { ).into_sequential_workload() } -fn render() -> Workload { - ( - clear_background, - ( - draw_world, - draw_current_chunk_border, - render_selection_box, - render_entities, - draw_world_trans, - render_submerged_view, - ).into_sequential_workload().run_if(is_ingame), - kubi_ui_draw, - ).into_sequential_workload() -} +// fn render() -> Workload { +// ( +// clear_background, +// ( +// draw_world, +// draw_current_chunk_border, +// render_selection_box, +// render_entities, +// draw_world_trans, +// render_submerged_view, +// ).into_sequential_workload().run_if(is_ingame), +// kubi_ui_draw, +// ).into_sequential_workload() +// } fn after_frame_end() -> Workload { ( @@ -244,7 +239,7 @@ pub fn kubi_main( world.add_workload(pre_startup); world.add_workload(startup); world.add_workload(update); - world.add_workload(render); + //world.add_workload(render); world.add_workload(after_frame_end); //Save _visualizer.json @@ -326,18 +321,18 @@ pub fn kubi_main( world.run_workload(update).unwrap(); //Start rendering (maybe use custom views for this?) - let target = { - let renderer = world.borrow::>>().unwrap(); - renderer.display.draw() - }; - world.add_unique_non_send_sync(RenderTarget(target)); + // let target = { + // let renderer = world.borrow::>>().unwrap(); + // renderer.display.draw() + // }; + // world.add_unique_non_send_sync(RenderTarget(target)); //Run render workflow - world.run_workload(render).unwrap(); + //world.run_workload(render).unwrap(); //Finish rendering - let target = world.remove_unique::().unwrap(); - target.0.finish().unwrap(); + // let target = world.remove_unique::().unwrap(); + // target.0.finish().unwrap(); //After frame end world.run_workload(after_frame_end).unwrap(); diff --git a/kubi/src/prefabs.rs b/kubi/src/prefabs.rs index 4f5d9be..7b9583e 100644 --- a/kubi/src/prefabs.rs +++ b/kubi/src/prefabs.rs @@ -1,15 +1,13 @@ use std::{io::{BufReader, Read}, path::Path}; use hui::text::FontHandle; use shipyard::{AllStoragesView, NonSendSync, Unique, UniqueView, UniqueViewMut}; -use glium::{texture::{SrgbTexture2dArray, MipmapsOption}, Program}; use kubi_shared::block::BlockTexture; use crate::{filesystem::AssetManager, hui_integration::UiState, rendering::Renderer}; mod texture; mod shaders; -use texture::load_texture2darray_prefab; -use shaders::include_shader_prefab; +//use texture::load_texture2darray_prefab; pub trait AssetPaths { fn file_name(self) -> &'static str; @@ -41,7 +39,7 @@ impl AssetPaths for BlockTexture { #[derive(Unique)] #[repr(transparent)] -pub struct BlockTexturesPrefab(pub SrgbTexture2dArray); +pub struct BlockTexturesPrefab(pub wgpu::Texture); // #[derive(Unique)] // #[repr(transparent)] @@ -65,15 +63,15 @@ pub fn load_prefabs( mut ui: NonSendSync>, assman: UniqueView ) { - log::info!("Loading textures..."); - storages.add_unique_non_send_sync(BlockTexturesPrefab( - load_texture2darray_prefab::( - &assman, - "blocks".into(), - &renderer.display, - MipmapsOption::AutoGeneratedMipmaps - ) - )); + // log::info!("Loading textures..."); + // storages.add_unique_non_send_sync(BlockTexturesPrefab( + // load_texture2darray_prefab::( + // &assman, + // "blocks".into(), + // &renderer.display, + // MipmapsOption::AutoGeneratedMipmaps + // ) + // )); log::info!("Loading the UI stuff..."); { @@ -85,33 +83,33 @@ pub fn load_prefabs( storages.add_unique(UiFontPrefab(font_handle)); } - log::info!("Compiling shaders..."); - storages.add_unique_non_send_sync(ChunkShaderPrefab( - include_shader_prefab!( - "world", - "../shaders/world.vert", - "../shaders/world.frag", - &renderer.display - ) - )); - storages.add_unique_non_send_sync(ColoredShaderPrefab( - include_shader_prefab!( - "colored", - "../shaders/colored.vert", - "../shaders/colored.frag", - &renderer.display - ) - )); - storages.add_unique_non_send_sync(Colored2ShaderPrefab( - include_shader_prefab!( - "colored", - "../shaders/colored2.vert", - "../shaders/colored2.frag", - &renderer.display - ) - )); + //log::info!("Compiling shaders..."); + // storages.add_unique_non_send_sync(ChunkShaderPrefab( + // include_shader_prefab!( + // "world", + // "../shaders/world.vert", + // "../shaders/world.frag", + // &renderer.display + // ) + // )); + // storages.add_unique_non_send_sync(ColoredShaderPrefab( + // include_shader_prefab!( + // "colored", + // "../shaders/colored.vert", + // "../shaders/colored.frag", + // &renderer.display + // ) + // )); + // storages.add_unique_non_send_sync(Colored2ShaderPrefab( + // include_shader_prefab!( + // "colored", + // "../shaders/colored2.vert", + // "../shaders/colored2.frag", + // &renderer.display + // ) + // )); - log::info!("releasing shader compiler"); + //log::info!("releasing shader compiler"); //renderer.display.release_shader_compiler(); } diff --git a/kubi/src/prefabs/texture.rs b/kubi/src/prefabs/texture.rs index 0bd7e8d..c10c71c 100644 --- a/kubi/src/prefabs/texture.rs +++ b/kubi/src/prefabs/texture.rs @@ -1,46 +1,45 @@ -use strum::IntoEnumIterator; -use rayon::prelude::*; -use std::{path::PathBuf, io::BufReader}; -use glium::{texture::{SrgbTexture2dArray, RawImage2d, MipmapsOption}, backend::Facade}; -use crate::filesystem::AssetManager; -use super::AssetPaths; - -pub fn load_texture2darray_prefab< - T: AssetPaths + IntoEnumIterator, - E: Facade ->( - assman: &AssetManager, - directory: PathBuf, - facade: &E, - mipmaps: MipmapsOption, -) -> SrgbTexture2dArray { - log::info!("started loading {}", directory.as_os_str().to_str().unwrap()); - //Load raw images - let tex_files: Vec<&'static str> = T::iter().map(|x| x.file_name()).collect(); - let raw_images: Vec> = tex_files.par_iter().map(|&file_name| { - log::info!("loading texture {}", file_name); - //Get path to the image and open the file - let reader = { - let path = directory.join(file_name); - BufReader::new(assman.open_asset(&path).expect("Failed to open texture file")) - }; - //Parse image data - let (image_data, dimensions) = { - let image = image::load( - reader, - image::ImageFormat::Png - ).unwrap().to_rgba8(); - let dimensions = image.dimensions(); - (image.into_raw(), dimensions) - }; - //Create a glium RawImage - RawImage2d::from_raw_rgba_reversed( - &image_data, - dimensions - ) - }).collect(); - log::info!("done loading texture files, uploading to the gpu"); - //Upload images to the GPU - SrgbTexture2dArray::with_mipmaps(facade, raw_images, mipmaps) - .expect("Failed to upload texture array to GPU") -} +// use strum::IntoEnumIterator; +// use rayon::prelude::*; +// use std::{path::PathBuf, io::BufReader}; +// use crate::filesystem::AssetManager; +// use super::AssetPaths; + +// pub fn load_texture2darray_prefab< +// T: AssetPaths + IntoEnumIterator, +// E: Facade +// >( +// assman: &AssetManager, +// directory: PathBuf, +// facade: &E, +// mipmaps: MipmapsOption, +// ) -> SrgbTexture2dArray { +// log::info!("started loading {}", directory.as_os_str().to_str().unwrap()); +// //Load raw images +// let tex_files: Vec<&'static str> = T::iter().map(|x| x.file_name()).collect(); +// let raw_images: Vec> = tex_files.par_iter().map(|&file_name| { +// log::info!("loading texture {}", file_name); +// //Get path to the image and open the file +// let reader = { +// let path = directory.join(file_name); +// BufReader::new(assman.open_asset(&path).expect("Failed to open texture file")) +// }; +// //Parse image data +// let (image_data, dimensions) = { +// let image = image::load( +// reader, +// image::ImageFormat::Png +// ).unwrap().to_rgba8(); +// let dimensions = image.dimensions(); +// (image.into_raw(), dimensions) +// }; +// //Create a glium RawImage +// RawImage2d::from_raw_rgba_reversed( +// &image_data, +// dimensions +// ) +// }).collect(); +// log::info!("done loading texture files, uploading to the gpu"); +// //Upload images to the GPU +// SrgbTexture2dArray::with_mipmaps(facade, raw_images, mipmaps) +// .expect("Failed to upload texture array to GPU") +// } diff --git a/kubi/src/rendering.rs b/kubi/src/rendering.rs index 1da5fd0..409fbf0 100644 --- a/kubi/src/rendering.rs +++ b/kubi/src/rendering.rs @@ -1,5 +1,7 @@ use pollster::FutureExt; -use shipyard::{Unique, NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, AllStoragesView}; +use raw_window_handle::HasRawWindowHandle; +use shipyard::{AllStoragesView, AllStoragesViewMut, IntoIter, NonSendSync, Unique, UniqueView, UniqueViewMut, View}; +use wgpu::SurfaceTargetUnsafe; use winit::{ event_loop::ActiveEventLoop, window::{WindowAttributes, Fullscreen, Window}, @@ -14,6 +16,11 @@ pub mod selection_box; pub mod entities; pub mod sumberge; +pub struct BufferPair { + pub index: wgpu::Buffer, + pub vertex: wgpu::Buffer, +} + #[derive(Unique)] #[repr(transparent)] pub struct BackgroundColor(pub Vec3); @@ -26,14 +33,16 @@ pub struct WindowSize(pub UVec2); #[derive(Unique)] pub struct Renderer { - pub window: Window, - pub instance: wgpu::Instance, - pub surface: wgpu::Surface<'static>, - pub device: wgpu::Device, - pub queue: wgpu::Queue, - pub surface_config: wgpu::SurfaceConfiguration, - pub size: PhysicalSize, + instance: wgpu::Instance, + surface: wgpu::Surface<'static>, + device: wgpu::Device, + queue: wgpu::Queue, + surface_config: wgpu::SurfaceConfiguration, + size: PhysicalSize, // pub depth_texture: wgpu::Texture, + + //must be last due to drop order + window: Window, } impl Renderer { @@ -95,7 +104,11 @@ impl Renderer { ..Default::default() }); - let surface = instance.create_surface(window).unwrap(); + // Create a surface with `create_surface_unsafe` to get a surface with 'static lifetime + // It should never outlive the window it's created from + let surface = unsafe { + instance.create_surface_unsafe(SurfaceTargetUnsafe::from_window(&window).unwrap()).unwrap() + }; let adapter = instance.request_adapter( &wgpu::RequestAdapterOptions { @@ -139,13 +152,89 @@ impl Renderer { pub fn reconfigure(&self) { self.surface.configure(&self.device, &self.surface_config); } + + //getters: + pub fn size(&self) -> PhysicalSize { + self.size + } + + pub fn window(&self) -> &Window { + &self.window + } + + pub fn surface(&self) -> &wgpu::Surface<'static> { + &self.surface + } + + pub fn device(&self) -> &wgpu::Device { + &self.device + } + + pub fn queue(&self) -> &wgpu::Queue { + &self.queue + } + + pub fn surface_config(&self) -> &wgpu::SurfaceConfiguration { + &self.surface_config + } } -pub fn clear_background( - mut target: NonSendSync>, - color: UniqueView, +pub fn render_master(storages: AllStoragesViewMut) { + let renderer = storages.borrow::>().unwrap(); + + let mut encoder = renderer.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: Some("main_encoder"), + }); + let surface_texture = renderer.surface().get_current_texture().unwrap(); + let surface_view = surface_texture.texture.create_view(&wgpu::TextureViewDescriptor::default()); + + { + let bg_color = storages.borrow::>().unwrap(); + let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + label: Some("main0_pass"), + color_attachments: &[Some(wgpu::RenderPassColorAttachment { + view: &surface_view, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::Clear(wgpu::Color { + r: bg_color.0.x as f64, + g: bg_color.0.y as f64, + b: bg_color.0.z as f64, + a: 1.0, + }), + store: wgpu::StoreOp::Store, + }, + })], + depth_stencil_attachment: None, + ..Default::default() + }); + + // render_pass.set_pipeline(&renderer.pipeline); + // render_pass.set_bind_group(0, &renderer.bind_group, &[]); + // render_pass.set_vertex_buffer(0, renderer.vertex_buffer.slice(..)); + // render_pass.set_index_buffer(renderer.index_buffer.slice(..)); + // render_pass.draw_indexed(0..renderer.num_indices, 0, 0..1); + } + + renderer.queue().submit(Some(encoder.finish())); +} + +// pub fn clear_background( +// mut target: NonSendSync>, +// color: UniqueView, +// ) { +// target.0.clear_color_srgb_and_depth((color.0.x, color.0.y, color.0.z, 1.), 1.); +// } + +//Resize the renderer + +pub fn resize_renderer( + mut renderer: UniqueViewMut, + resize: View, ) { - target.0.clear_color_srgb_and_depth((color.0.x, color.0.y, color.0.z, 1.), 1.); + if let Some(size) = resize.iter().last() { + renderer.resize(PhysicalSize::new(size.0.x, size.0.y)); + } } //not sure if this belongs here diff --git a/kubi/src/rendering/entities.rs b/kubi/src/rendering/entities.rs index 0135edf..3282cc9 100644 --- a/kubi/src/rendering/entities.rs +++ b/kubi/src/rendering/entities.rs @@ -1,58 +1,58 @@ -use shipyard::{NonSendSync, UniqueViewMut, UniqueView, View, IntoIter, IntoWithId}; -use glium::{DepthTest, Depth, PolygonMode, BackfaceCullingMode, DrawParameters, Surface, uniform}; -use kubi_shared::{entity::Entity, transform::Transform}; -use crate::{ - prefabs::ColoredShaderPrefab, - camera::Camera, - settings::GameSettings -}; -use super::{ - RenderTarget, - primitives::cube::CenteredCubePrimitive -}; - -// TODO: entity models -pub fn render_entities( - mut target: NonSendSync>, - buffers: NonSendSync>, - program: NonSendSync>, - camera: View, - settings: UniqueView, - entities: View, - transform: View, -) { - let (camera_id, camera) = camera.iter().with_id().next().expect("No cameras in the scene"); - - let draw_parameters = DrawParameters { - depth: Depth { - test: DepthTest::IfLess, - write: true, - ..Default::default() - }, - multisampling: settings.msaa.is_some(), - polygon_mode: PolygonMode::Fill, - backface_culling: BackfaceCullingMode::CullClockwise, - ..Default::default() - }; - let view = camera.view_matrix.to_cols_array_2d(); - let perspective = camera.perspective_matrix.to_cols_array_2d(); - - for (entity_id, (_, trans)) in (&entities, &transform).iter().with_id() { - //skip rendering camera holder (as the entity would block the view) - if entity_id == camera_id { continue } - - //render entity - target.0.draw( - &buffers.0, - &buffers.1, - &program.0, - &uniform! { - color: [1.0, 1.0, 1.0, 1.0_f32], - model: trans.0.to_cols_array_2d(), - view: view, - perspective: perspective, - }, - &draw_parameters - ).unwrap(); - } -} +// use shipyard::{NonSendSync, UniqueViewMut, UniqueView, View, IntoIter, IntoWithId}; +// use glium::{DepthTest, Depth, PolygonMode, BackfaceCullingMode, DrawParameters, Surface, uniform}; +// use kubi_shared::{entity::Entity, transform::Transform}; +// use crate::{ +// prefabs::ColoredShaderPrefab, +// camera::Camera, +// settings::GameSettings +// }; +// use super::{ +// RenderTarget, +// primitives::cube::CenteredCubePrimitive +// }; + +// // TODO: entity models +// pub fn render_entities( +// mut target: NonSendSync>, +// buffers: NonSendSync>, +// program: NonSendSync>, +// camera: View, +// settings: UniqueView, +// entities: View, +// transform: View, +// ) { +// let (camera_id, camera) = camera.iter().with_id().next().expect("No cameras in the scene"); + +// let draw_parameters = DrawParameters { +// depth: Depth { +// test: DepthTest::IfLess, +// write: true, +// ..Default::default() +// }, +// multisampling: settings.msaa.is_some(), +// polygon_mode: PolygonMode::Fill, +// backface_culling: BackfaceCullingMode::CullClockwise, +// ..Default::default() +// }; +// let view = camera.view_matrix.to_cols_array_2d(); +// let perspective = camera.perspective_matrix.to_cols_array_2d(); + +// for (entity_id, (_, trans)) in (&entities, &transform).iter().with_id() { +// //skip rendering camera holder (as the entity would block the view) +// if entity_id == camera_id { continue } + +// //render entity +// target.0.draw( +// &buffers.0, +// &buffers.1, +// &program.0, +// &uniform! { +// color: [1.0, 1.0, 1.0, 1.0_f32], +// model: trans.0.to_cols_array_2d(), +// view: view, +// perspective: perspective, +// }, +// &draw_parameters +// ).unwrap(); +// } +// } diff --git a/kubi/src/rendering/primitives.rs b/kubi/src/rendering/primitives.rs index 26666bd..115ff49 100644 --- a/kubi/src/rendering/primitives.rs +++ b/kubi/src/rendering/primitives.rs @@ -1,30 +1,30 @@ -use shipyard::{Workload, IntoWorkload}; -use glium::implement_vertex; +// use shipyard::{Workload, IntoWorkload}; +// use glium::implement_vertex; -pub mod cube; -pub mod rect; -pub mod stri; +// pub mod cube; +// pub mod rect; +// pub mod stri; -use cube::init_cube_primitive; -use rect::init_rect_primitive; -use stri::init_stri_primitive; +// use cube::init_cube_primitive; +// use rect::init_rect_primitive; +// use stri::init_stri_primitive; -#[derive(Clone, Copy, Default)] -pub struct PositionOnlyVertex { - pub position: [f32; 3], -} -implement_vertex!(PositionOnlyVertex, position); +// #[derive(Clone, Copy, Default)] +// pub struct PositionOnlyVertex { +// pub position: [f32; 3], +// } +// implement_vertex!(PositionOnlyVertex, position); -#[derive(Clone, Copy, Default)] -pub struct PositionOnlyVertex2d { - pub position: [f32; 2], -} -implement_vertex!(PositionOnlyVertex2d, position); +// #[derive(Clone, Copy, Default)] +// pub struct PositionOnlyVertex2d { +// pub position: [f32; 2], +// } +// implement_vertex!(PositionOnlyVertex2d, position); -pub fn init_primitives() -> Workload { - ( - init_cube_primitive, - init_rect_primitive, - init_stri_primitive, - ).into_workload() -} +// pub fn init_primitives() -> Workload { +// ( +// init_cube_primitive, +// init_rect_primitive, +// init_stri_primitive, +// ).into_workload() +// } diff --git a/kubi/src/rendering/primitives/cube.rs b/kubi/src/rendering/primitives/cube.rs index 20f8616..2e3b5c8 100644 --- a/kubi/src/rendering/primitives/cube.rs +++ b/kubi/src/rendering/primitives/cube.rs @@ -1,85 +1,85 @@ -use shipyard::{AllStoragesView, NonSendSync, UniqueView, Unique}; -use glium::{VertexBuffer, IndexBuffer, index::PrimitiveType}; -use crate::rendering::Renderer; -use super::PositionOnlyVertex; - -#[derive(Unique)] -pub struct CubePrimitive(pub VertexBuffer, pub IndexBuffer); - -#[derive(Unique)] -pub struct CenteredCubePrimitive(pub VertexBuffer, pub IndexBuffer); - -const CENTERED_CUBE_VERTICES: &[PositionOnlyVertex] = &[ - // front - PositionOnlyVertex { position: [-0.5, -0.5, 0.5] }, - PositionOnlyVertex { position: [ 0.5, -0.5, 0.5] }, - PositionOnlyVertex { position: [ 0.5, 0.5, 0.5] }, - PositionOnlyVertex { position: [-0.5, 0.5, 0.5] }, - // back - PositionOnlyVertex { position: [-0.5, -0.5, -0.5] }, - PositionOnlyVertex { position: [ 0.5, -0.5, -0.5] }, - PositionOnlyVertex { position: [ 0.5, 0.5, -0.5] }, - PositionOnlyVertex { position: [-0.5, 0.5, -0.5] }, -]; -const CUBE_VERTICES: &[PositionOnlyVertex] = &[ - // front - PositionOnlyVertex { position: [0.0, 0.0, 1.0] }, - PositionOnlyVertex { position: [1.0, 0.0, 1.0] }, - PositionOnlyVertex { position: [1.0, 1.0, 1.0] }, - PositionOnlyVertex { position: [0.0, 1.0, 1.0] }, - // back - PositionOnlyVertex { position: [0.0, 0.0, 0.0] }, - PositionOnlyVertex { position: [1.0, 0.0, 0.0] }, - PositionOnlyVertex { position: [1.0, 1.0, 0.0] }, - PositionOnlyVertex { position: [0.0, 1.0, 0.0] }, -]; -const CUBE_INDICES: &[u16] = &[ - // front - 0, 1, 2, - 2, 3, 0, - // right - 1, 5, 6, - 6, 2, 1, - // back - 7, 6, 5, - 5, 4, 7, - // left - 4, 0, 3, - 3, 7, 4, - // bottom - 4, 5, 1, - 1, 0, 4, - // top - 3, 2, 6, - 6, 7, 3 -]; - -pub(super) fn init_cube_primitive( - storages: AllStoragesView, - display: NonSendSync> -) { - { - let vert = VertexBuffer::immutable( - &display.display, - CUBE_VERTICES - ).unwrap(); - let index = IndexBuffer::immutable( - &display.display, - PrimitiveType::TrianglesList, - CUBE_INDICES - ).unwrap(); - storages.add_unique_non_send_sync(CubePrimitive(vert, index)); - } - { - let vert = VertexBuffer::immutable( - &display.display, - CENTERED_CUBE_VERTICES - ).unwrap(); - let index = IndexBuffer::immutable( - &display.display, - PrimitiveType::TrianglesList, - CUBE_INDICES - ).unwrap(); - storages.add_unique_non_send_sync(CenteredCubePrimitive(vert, index)); - } -} +// use shipyard::{AllStoragesView, NonSendSync, UniqueView, Unique}; +// use glium::{VertexBuffer, IndexBuffer, index::PrimitiveType}; +// use crate::rendering::Renderer; +// use super::PositionOnlyVertex; + +// #[derive(Unique)] +// pub struct CubePrimitive(pub VertexBuffer, pub IndexBuffer); + +// #[derive(Unique)] +// pub struct CenteredCubePrimitive(pub VertexBuffer, pub IndexBuffer); + +// const CENTERED_CUBE_VERTICES: &[PositionOnlyVertex] = &[ +// // front +// PositionOnlyVertex { position: [-0.5, -0.5, 0.5] }, +// PositionOnlyVertex { position: [ 0.5, -0.5, 0.5] }, +// PositionOnlyVertex { position: [ 0.5, 0.5, 0.5] }, +// PositionOnlyVertex { position: [-0.5, 0.5, 0.5] }, +// // back +// PositionOnlyVertex { position: [-0.5, -0.5, -0.5] }, +// PositionOnlyVertex { position: [ 0.5, -0.5, -0.5] }, +// PositionOnlyVertex { position: [ 0.5, 0.5, -0.5] }, +// PositionOnlyVertex { position: [-0.5, 0.5, -0.5] }, +// ]; +// const CUBE_VERTICES: &[PositionOnlyVertex] = &[ +// // front +// PositionOnlyVertex { position: [0.0, 0.0, 1.0] }, +// PositionOnlyVertex { position: [1.0, 0.0, 1.0] }, +// PositionOnlyVertex { position: [1.0, 1.0, 1.0] }, +// PositionOnlyVertex { position: [0.0, 1.0, 1.0] }, +// // back +// PositionOnlyVertex { position: [0.0, 0.0, 0.0] }, +// PositionOnlyVertex { position: [1.0, 0.0, 0.0] }, +// PositionOnlyVertex { position: [1.0, 1.0, 0.0] }, +// PositionOnlyVertex { position: [0.0, 1.0, 0.0] }, +// ]; +// const CUBE_INDICES: &[u16] = &[ +// // front +// 0, 1, 2, +// 2, 3, 0, +// // right +// 1, 5, 6, +// 6, 2, 1, +// // back +// 7, 6, 5, +// 5, 4, 7, +// // left +// 4, 0, 3, +// 3, 7, 4, +// // bottom +// 4, 5, 1, +// 1, 0, 4, +// // top +// 3, 2, 6, +// 6, 7, 3 +// ]; + +// pub(super) fn init_cube_primitive( +// storages: AllStoragesView, +// display: NonSendSync> +// ) { +// { +// let vert = VertexBuffer::immutable( +// &display.display, +// CUBE_VERTICES +// ).unwrap(); +// let index = IndexBuffer::immutable( +// &display.display, +// PrimitiveType::TrianglesList, +// CUBE_INDICES +// ).unwrap(); +// storages.add_unique_non_send_sync(CubePrimitive(vert, index)); +// } +// { +// let vert = VertexBuffer::immutable( +// &display.display, +// CENTERED_CUBE_VERTICES +// ).unwrap(); +// let index = IndexBuffer::immutable( +// &display.display, +// PrimitiveType::TrianglesList, +// CUBE_INDICES +// ).unwrap(); +// storages.add_unique_non_send_sync(CenteredCubePrimitive(vert, index)); +// } +// } diff --git a/kubi/src/rendering/primitives/rect.rs b/kubi/src/rendering/primitives/rect.rs index 3a30575..4eca75c 100644 --- a/kubi/src/rendering/primitives/rect.rs +++ b/kubi/src/rendering/primitives/rect.rs @@ -1,31 +1,31 @@ -use shipyard::{Unique, AllStoragesView, NonSendSync, UniqueView}; -use glium::{VertexBuffer, IndexBuffer, index::PrimitiveType}; -use crate::rendering::Renderer; -use super::PositionOnlyVertex2d; - -#[derive(Unique)] -pub struct RectPrimitive(pub VertexBuffer, pub IndexBuffer); - -const RECT_VERTEX: &[PositionOnlyVertex2d] = &[ - PositionOnlyVertex2d { position: [0., 0.] }, - PositionOnlyVertex2d { position: [1., 0.] }, - PositionOnlyVertex2d { position: [0., 1.] }, - PositionOnlyVertex2d { position: [1., 1.] }, -]; -const RECT_INDEX: &[u16] = &[0, 1, 2, 1, 3, 2]; - -pub(super) fn init_rect_primitive( - storages: AllStoragesView, - display: NonSendSync> -) { - let vert = VertexBuffer::immutable( - &display.display, - RECT_VERTEX - ).unwrap(); - let index = IndexBuffer::immutable( - &display.display, - PrimitiveType::TrianglesList, - RECT_INDEX - ).unwrap(); - storages.add_unique_non_send_sync(RectPrimitive(vert, index)); -} +// use shipyard::{Unique, AllStoragesView, NonSendSync, UniqueView}; +// use glium::{VertexBuffer, IndexBuffer, index::PrimitiveType}; +// use crate::rendering::Renderer; +// use super::PositionOnlyVertex2d; + +// #[derive(Unique)] +// pub struct RectPrimitive(pub VertexBuffer, pub IndexBuffer); + +// const RECT_VERTEX: &[PositionOnlyVertex2d] = &[ +// PositionOnlyVertex2d { position: [0., 0.] }, +// PositionOnlyVertex2d { position: [1., 0.] }, +// PositionOnlyVertex2d { position: [0., 1.] }, +// PositionOnlyVertex2d { position: [1., 1.] }, +// ]; +// const RECT_INDEX: &[u16] = &[0, 1, 2, 1, 3, 2]; + +// pub(super) fn init_rect_primitive( +// storages: AllStoragesView, +// display: NonSendSync> +// ) { +// let vert = VertexBuffer::immutable( +// &display.display, +// RECT_VERTEX +// ).unwrap(); +// let index = IndexBuffer::immutable( +// &display.display, +// PrimitiveType::TrianglesList, +// RECT_INDEX +// ).unwrap(); +// storages.add_unique_non_send_sync(RectPrimitive(vert, index)); +// } diff --git a/kubi/src/rendering/primitives/stri.rs b/kubi/src/rendering/primitives/stri.rs index dbc5c40..2cafaf9 100644 --- a/kubi/src/rendering/primitives/stri.rs +++ b/kubi/src/rendering/primitives/stri.rs @@ -1,30 +1,30 @@ -use shipyard::{Unique, AllStoragesView, NonSendSync, UniqueView}; -use glium::{VertexBuffer, IndexBuffer, index::PrimitiveType}; -use crate::rendering::Renderer; -use super::PositionOnlyVertex2d; +// use shipyard::{Unique, AllStoragesView, NonSendSync, UniqueView}; +// use glium::{VertexBuffer, IndexBuffer, index::PrimitiveType}; +// use crate::rendering::Renderer; +// use super::PositionOnlyVertex2d; -#[derive(Unique)] -pub struct STriPrimitive(pub VertexBuffer, pub IndexBuffer); +// #[derive(Unique)] +// pub struct STriPrimitive(pub VertexBuffer, pub IndexBuffer); -const STRI_VERTEX: &[PositionOnlyVertex2d] = &[ - PositionOnlyVertex2d { position: [-1., -1.] }, - PositionOnlyVertex2d { position: [ 3., -1.] }, - PositionOnlyVertex2d { position: [-1., 3.] }, -]; -const STRI_INDEX: &[u16] = &[0, 1, 2]; +// const STRI_VERTEX: &[PositionOnlyVertex2d] = &[ +// PositionOnlyVertex2d { position: [-1., -1.] }, +// PositionOnlyVertex2d { position: [ 3., -1.] }, +// PositionOnlyVertex2d { position: [-1., 3.] }, +// ]; +// const STRI_INDEX: &[u16] = &[0, 1, 2]; -pub(super) fn init_stri_primitive( - storages: AllStoragesView, - display: NonSendSync> -) { - let vert = VertexBuffer::immutable( - &display.display, - STRI_VERTEX - ).unwrap(); - let index = IndexBuffer::immutable( - &display.display, - PrimitiveType::TrianglesList, - STRI_INDEX - ).unwrap(); - storages.add_unique_non_send_sync(STriPrimitive(vert, index)); -} +// pub(super) fn init_stri_primitive( +// storages: AllStoragesView, +// display: NonSendSync> +// ) { +// let vert = VertexBuffer::immutable( +// &display.display, +// STRI_VERTEX +// ).unwrap(); +// let index = IndexBuffer::immutable( +// &display.display, +// PrimitiveType::TrianglesList, +// STRI_INDEX +// ).unwrap(); +// storages.add_unique_non_send_sync(STriPrimitive(vert, index)); +// } diff --git a/kubi/src/rendering/selection_box.rs b/kubi/src/rendering/selection_box.rs index 8f0e2eb..ad89716 100644 --- a/kubi/src/rendering/selection_box.rs +++ b/kubi/src/rendering/selection_box.rs @@ -1,59 +1,59 @@ -use glam::{Mat4, Vec3, Quat}; -use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut, UniqueView}; -use glium::{ - Surface, - DrawParameters, - BackfaceCullingMode, - Blend, Depth, DepthTest, - uniform, -}; -use crate::{ - world::raycast::LookingAtBlock, - camera::Camera, - prefabs::ColoredShaderPrefab -}; -use super::{ - RenderTarget, - primitives::cube::CubePrimitive, -}; - -const SMOL: f32 = 0.0025; - -pub fn render_selection_box( - lookat: View, - camera: View, - mut target: NonSendSync>, - program: NonSendSync>, - buffers: NonSendSync>, -) { - let camera = camera.iter().next().unwrap(); - let Some(lookat) = lookat.iter().next() else { return }; - let Some(lookat) = lookat.0 else { return }; - - //Darken block - target.0.draw( - &buffers.0, - &buffers.1, - &program.0, - &uniform! { - color: [0., 0., 0., 0.5_f32], - model: Mat4::from_scale_rotation_translation( - Vec3::splat(1. + SMOL * 2.), - Quat::default(), - lookat.block_position.as_vec3() - Vec3::splat(SMOL) - ).to_cols_array_2d(), - perspective: camera.perspective_matrix.to_cols_array_2d(), - view: camera.view_matrix.to_cols_array_2d(), - }, - &DrawParameters { - backface_culling: BackfaceCullingMode::CullClockwise, - blend: Blend::alpha_blending(), - depth: Depth { - //this may be unreliable... unless scale is applied! hacky... - test: DepthTest::IfLessOrEqual, - ..Default::default() - }, - ..Default::default() - } - ).unwrap(); -} +// use glam::{Mat4, Vec3, Quat}; +// use shipyard::{View, IntoIter, NonSendSync, UniqueViewMut, UniqueView}; +// use glium::{ +// Surface, +// DrawParameters, +// BackfaceCullingMode, +// Blend, Depth, DepthTest, +// uniform, +// }; +// use crate::{ +// world::raycast::LookingAtBlock, +// camera::Camera, +// prefabs::ColoredShaderPrefab +// }; +// use super::{ +// RenderTarget, +// primitives::cube::CubePrimitive, +// }; + +// const SMOL: f32 = 0.0025; + +// pub fn render_selection_box( +// lookat: View, +// camera: View, +// mut target: NonSendSync>, +// program: NonSendSync>, +// buffers: NonSendSync>, +// ) { +// let camera = camera.iter().next().unwrap(); +// let Some(lookat) = lookat.iter().next() else { return }; +// let Some(lookat) = lookat.0 else { return }; + +// //Darken block +// target.0.draw( +// &buffers.0, +// &buffers.1, +// &program.0, +// &uniform! { +// color: [0., 0., 0., 0.5_f32], +// model: Mat4::from_scale_rotation_translation( +// Vec3::splat(1. + SMOL * 2.), +// Quat::default(), +// lookat.block_position.as_vec3() - Vec3::splat(SMOL) +// ).to_cols_array_2d(), +// perspective: camera.perspective_matrix.to_cols_array_2d(), +// view: camera.view_matrix.to_cols_array_2d(), +// }, +// &DrawParameters { +// backface_culling: BackfaceCullingMode::CullClockwise, +// blend: Blend::alpha_blending(), +// depth: Depth { +// //this may be unreliable... unless scale is applied! hacky... +// test: DepthTest::IfLessOrEqual, +// ..Default::default() +// }, +// ..Default::default() +// } +// ).unwrap(); +// } diff --git a/kubi/src/rendering/sumberge.rs b/kubi/src/rendering/sumberge.rs index b947b9c..a44da40 100644 --- a/kubi/src/rendering/sumberge.rs +++ b/kubi/src/rendering/sumberge.rs @@ -1,39 +1,39 @@ -use glium::{uniform, Blend, DrawParameters, Surface}; -use kubi_shared::transform::Transform; -use shipyard::{IntoIter, NonSendSync, UniqueView, UniqueViewMut, View}; -use crate::{ - player::MainPlayer, - prefabs::Colored2ShaderPrefab, - rendering::primitives::stri::STriPrimitive, - world::ChunkStorage, -}; -use super::RenderTarget; +// use glium::{uniform, Blend, DrawParameters, Surface}; +// use kubi_shared::transform::Transform; +// use shipyard::{IntoIter, NonSendSync, UniqueView, UniqueViewMut, View}; +// use crate::{ +// player::MainPlayer, +// prefabs::Colored2ShaderPrefab, +// rendering::primitives::stri::STriPrimitive, +// world::ChunkStorage, +// }; +// use super::RenderTarget; -pub fn render_submerged_view( - mut target: NonSendSync>, - primitive: NonSendSync>, - program: NonSendSync>, - plr: View, - trans: View, - world: UniqueView, -) { - let (_, plr_trans) = (&plr, &trans).iter().next().expect("Main player MIA"); - let plr_pos = plr_trans.0.to_scale_rotation_translation().2; - let block_at_pos = world.get_block(plr_pos.floor().as_ivec3()); - let Some(block_at_pos) = block_at_pos else { return }; - let Some(color) = block_at_pos.descriptor().submerge else { return }; +// pub fn render_submerged_view( +// mut target: NonSendSync>, +// primitive: NonSendSync>, +// program: NonSendSync>, +// plr: View, +// trans: View, +// world: UniqueView, +// ) { +// let (_, plr_trans) = (&plr, &trans).iter().next().expect("Main player MIA"); +// let plr_pos = plr_trans.0.to_scale_rotation_translation().2; +// let block_at_pos = world.get_block(plr_pos.floor().as_ivec3()); +// let Some(block_at_pos) = block_at_pos else { return }; +// let Some(color) = block_at_pos.descriptor().submerge else { return }; - let draw_parameters = DrawParameters { - blend: Blend::alpha_blending(), - ..Default::default() - }; - target.0.draw( - &primitive.0, - &primitive.1, - &program.0, - &uniform! { - color: color.to_array(), - }, - &draw_parameters, - ).unwrap(); -} +// let draw_parameters = DrawParameters { +// blend: Blend::alpha_blending(), +// ..Default::default() +// }; +// target.0.draw( +// &primitive.0, +// &primitive.1, +// &program.0, +// &uniform! { +// color: color.to_array(), +// }, +// &draw_parameters, +// ).unwrap(); +// } diff --git a/kubi/src/rendering/world.rs b/kubi/src/rendering/world.rs index 3deb600..9f3dffc 100644 --- a/kubi/src/rendering/world.rs +++ b/kubi/src/rendering/world.rs @@ -1,28 +1,28 @@ -use glam::{ivec3, IVec3, Mat4, Quat, Vec3}; -use shipyard::{track, AllStoragesView, IntoIter, NonSendSync, Unique, UniqueView, UniqueViewMut, View}; -use glium::{ - draw_parameters::{ - BackfaceCullingMode, Depth, DepthTest, PolygonMode - }, implement_vertex, uniform, uniforms::{ - MagnifySamplerFilter, MinifySamplerFilter, Sampler, SamplerBehavior, SamplerWrapFunction - }, Blend, DrawParameters, Smooth, Surface -}; -use crate::{ - camera::Camera, - player::MainPlayer, - transform::Transform, - prefabs::{ - ChunkShaderPrefab, - BlockTexturesPrefab, - ColoredShaderPrefab, - }, - world::{ - ChunkStorage, - ChunkMeshStorage, - chunk::CHUNK_SIZE, - }, settings::GameSettings, -}; -use super::{RenderTarget, primitives::cube::CubePrimitive}; +// use glam::{ivec3, IVec3, Mat4, Quat, Vec3}; +// use shipyard::{track, AllStoragesView, IntoIter, NonSendSync, Unique, UniqueView, UniqueViewMut, View}; +// use glium::{ +// draw_parameters::{ +// BackfaceCullingMode, Depth, DepthTest, PolygonMode +// }, implement_vertex, uniform, uniforms::{ +// MagnifySamplerFilter, MinifySamplerFilter, Sampler, SamplerBehavior, SamplerWrapFunction +// }, Blend, DrawParameters, Smooth, Surface +// }; +// use crate::{ +// camera::Camera, +// player::MainPlayer, +// transform::Transform, +// prefabs::{ +// ChunkShaderPrefab, +// BlockTexturesPrefab, +// ColoredShaderPrefab, +// }, +// world::{ +// ChunkStorage, +// ChunkMeshStorage, +// chunk::CHUNK_SIZE, +// }, settings::GameSettings, +// }; +// use super::{RenderTarget, primitives::cube::CubePrimitive}; #[derive(Clone, Copy)] #[repr(C)] @@ -32,217 +32,216 @@ pub struct ChunkVertex { pub uv: [f32; 2], pub tex_index: u8, } -implement_vertex!(ChunkVertex, position, normal, uv, tex_index); -#[derive(Unique)] -pub struct TransChunkQueue(pub Vec); +// #[derive(Unique)] +// pub struct TransChunkQueue(pub Vec); -pub fn init_trans_chunk_queue(storages: AllStoragesView) { - storages.add_unique(TransChunkQueue(Vec::with_capacity(512))); -} +// pub fn init_trans_chunk_queue(storages: AllStoragesView) { +// storages.add_unique(TransChunkQueue(Vec::with_capacity(512))); +// } -fn draw_params(settings: &GameSettings) -> DrawParameters { - DrawParameters { - depth: Depth { - test: DepthTest::IfLess, - write: true, - ..Default::default() - }, - multisampling: settings.msaa.is_some(), - polygon_mode: PolygonMode::Fill, //Change to Line for wireframe - backface_culling: BackfaceCullingMode::CullClockwise, - ..Default::default() - } -} +// fn draw_params(settings: &GameSettings) -> DrawParameters { +// DrawParameters { +// depth: Depth { +// test: DepthTest::IfLess, +// write: true, +// ..Default::default() +// }, +// multisampling: settings.msaa.is_some(), +// polygon_mode: PolygonMode::Fill, //Change to Line for wireframe +// backface_culling: BackfaceCullingMode::CullClockwise, +// ..Default::default() +// } +// } -fn texture_sampler<'a, T>(texture: &'a T, settings: &GameSettings) -> Sampler<'a, T> { - Sampler(texture, SamplerBehavior { - minify_filter: MinifySamplerFilter::LinearMipmapLinear, - magnify_filter: MagnifySamplerFilter::Nearest, - max_anisotropy: settings.max_anisotropy.unwrap_or_default(), - wrap_function: (SamplerWrapFunction::Clamp, SamplerWrapFunction::Clamp, SamplerWrapFunction::Clamp), - depth_texture_comparison: None, - }) -} +// fn texture_sampler<'a, T>(texture: &'a T, settings: &GameSettings) -> Sampler<'a, T> { +// Sampler(texture, SamplerBehavior { +// minify_filter: MinifySamplerFilter::LinearMipmapLinear, +// magnify_filter: MagnifySamplerFilter::Nearest, +// max_anisotropy: settings.max_anisotropy.unwrap_or_default(), +// wrap_function: (SamplerWrapFunction::Clamp, SamplerWrapFunction::Clamp, SamplerWrapFunction::Clamp), +// depth_texture_comparison: None, +// }) +// } -pub fn draw_world( - mut target: NonSendSync>, - chunks: UniqueView, - meshes: NonSendSync>, - program: NonSendSync>, - texture: NonSendSync>, - transform: View, - camera: View, - settings: UniqueView, - mut trans_queue: UniqueViewMut, -) { - // let (camera, transform) = (&camera, &transform).iter().next().expect("No cameras in the scene"); - // let camera_position = transform.0.to_scale_rotation_translation().2; +// pub fn draw_world( +// mut target: NonSendSync>, +// chunks: UniqueView, +// meshes: NonSendSync>, +// program: NonSendSync>, +// texture: NonSendSync>, +// transform: View, +// camera: View, +// settings: UniqueView, +// mut trans_queue: UniqueViewMut, +// ) { +// // let (camera, transform) = (&camera, &transform).iter().next().expect("No cameras in the scene"); +// // let camera_position = transform.0.to_scale_rotation_translation().2; - let camera = camera.iter().next().expect("No cameras in the scene"); - let view = camera.view_matrix.to_cols_array_2d(); - let perspective = camera.perspective_matrix.to_cols_array_2d(); +// let camera = camera.iter().next().expect("No cameras in the scene"); +// let view = camera.view_matrix.to_cols_array_2d(); +// let perspective = camera.perspective_matrix.to_cols_array_2d(); - let draw_parameters = draw_params(&settings); - let texture_sampler = texture_sampler(&texture.0, &settings); +// let draw_parameters = draw_params(&settings); +// let texture_sampler = texture_sampler(&texture.0, &settings); - for (&position, chunk) in &chunks.chunks { - if let Some(key) = chunk.mesh_index { - let mesh = meshes.get(key).expect("Mesh index pointing to nothing"); - let world_position = position.as_vec3() * CHUNK_SIZE as f32; +// for (&position, chunk) in &chunks.chunks { +// if let Some(key) = chunk.mesh_index { +// let mesh = meshes.get(key).expect("Mesh index pointing to nothing"); +// let world_position = position.as_vec3() * CHUNK_SIZE as f32; - //Skip mesh if its empty - if mesh.index_buffer.len() == 0 && mesh.trans_index_buffer.len() == 0 { - continue - } +// //Skip mesh if its empty +// if mesh.index_buffer.len() == 0 && mesh.trans_index_buffer.len() == 0 { +// continue +// } - //Frustum culling - { - let minp = world_position; - let maxp = world_position + Vec3::splat(CHUNK_SIZE as f32); - if !camera.frustum.is_box_visible(minp, maxp) { - continue - } - } +// //Frustum culling +// { +// let minp = world_position; +// let maxp = world_position + Vec3::splat(CHUNK_SIZE as f32); +// if !camera.frustum.is_box_visible(minp, maxp) { +// continue +// } +// } - //Draw chunk mesh - if mesh.index_buffer.len() > 0 { - target.0.draw( - &mesh.vertex_buffer, - &mesh.index_buffer, - &program.0, - &uniform! { - position_offset: world_position.to_array(), - view: view, - perspective: perspective, - tex: texture_sampler, - discard_alpha: true, - }, - &draw_parameters - ).unwrap(); - } +// //Draw chunk mesh +// if mesh.index_buffer.len() > 0 { +// target.0.draw( +// &mesh.vertex_buffer, +// &mesh.index_buffer, +// &program.0, +// &uniform! { +// position_offset: world_position.to_array(), +// view: view, +// perspective: perspective, +// tex: texture_sampler, +// discard_alpha: true, +// }, +// &draw_parameters +// ).unwrap(); +// } - if mesh.trans_index_buffer.len() > 0 { - trans_queue.0.push(position); - } - } - } +// if mesh.trans_index_buffer.len() > 0 { +// trans_queue.0.push(position); +// } +// } +// } - // const HALF_CHUNK_SIZE: IVec3 = IVec3::splat((CHUNK_SIZE >> 1) as i32); - // trans_queue.0.sort_by_cached_key(|&pos| -( - // (pos + HALF_CHUNK_SIZE).distance_squared(camera_position.as_ivec3()) - // )); -} +// // const HALF_CHUNK_SIZE: IVec3 = IVec3::splat((CHUNK_SIZE >> 1) as i32); +// // trans_queue.0.sort_by_cached_key(|&pos| -( +// // (pos + HALF_CHUNK_SIZE).distance_squared(camera_position.as_ivec3()) +// // )); +// } -pub fn draw_world_trans( - mut target: NonSendSync>, - chunks: UniqueView, - meshes: NonSendSync>, - program: NonSendSync>, - texture: NonSendSync>, - camera: View, - settings: UniqueView, - mut trans_queue: UniqueViewMut, -) { - let camera = camera.iter().next().expect("No cameras in the scene"); - let view = camera.view_matrix.to_cols_array_2d(); - let perspective = camera.perspective_matrix.to_cols_array_2d(); +// pub fn draw_world_trans( +// mut target: NonSendSync>, +// chunks: UniqueView, +// meshes: NonSendSync>, +// program: NonSendSync>, +// texture: NonSendSync>, +// camera: View, +// settings: UniqueView, +// mut trans_queue: UniqueViewMut, +// ) { +// let camera = camera.iter().next().expect("No cameras in the scene"); +// let view = camera.view_matrix.to_cols_array_2d(); +// let perspective = camera.perspective_matrix.to_cols_array_2d(); - let mut draw_parameters = draw_params(&settings); - draw_parameters.blend = Blend::alpha_blending(); - draw_parameters.backface_culling = BackfaceCullingMode::CullingDisabled; - draw_parameters.smooth = Some(Smooth::Fastest); +// let mut draw_parameters = draw_params(&settings); +// draw_parameters.blend = Blend::alpha_blending(); +// draw_parameters.backface_culling = BackfaceCullingMode::CullingDisabled; +// draw_parameters.smooth = Some(Smooth::Fastest); - let texture_sampler = texture_sampler(&texture.0, &settings); +// let texture_sampler = texture_sampler(&texture.0, &settings); - for position in trans_queue.0.drain(..).rev() { - let world_position = position.as_vec3() * CHUNK_SIZE as f32; - let mesh_idx = chunks.chunks[&position].mesh_index.expect("No mesh index"); - let mesh = meshes.get(mesh_idx).expect("Mesh index pointing to nothing"); - target.0.draw( - &mesh.trans_vertex_buffer, - &mesh.trans_index_buffer, - &program.0, - &uniform! { - position_offset: world_position.to_array(), - view: view, - perspective: perspective, - tex: texture_sampler, - discard_alpha: false, - }, - &draw_parameters - ).unwrap(); - } -} +// for position in trans_queue.0.drain(..).rev() { +// let world_position = position.as_vec3() * CHUNK_SIZE as f32; +// let mesh_idx = chunks.chunks[&position].mesh_index.expect("No mesh index"); +// let mesh = meshes.get(mesh_idx).expect("Mesh index pointing to nothing"); +// target.0.draw( +// &mesh.trans_vertex_buffer, +// &mesh.trans_index_buffer, +// &program.0, +// &uniform! { +// position_offset: world_position.to_array(), +// view: view, +// perspective: perspective, +// tex: texture_sampler, +// discard_alpha: false, +// }, +// &draw_parameters +// ).unwrap(); +// } +// } -pub fn draw_current_chunk_border( - mut target: NonSendSync>, - player: View, - transforms: View, - buffers: NonSendSync>, - program: NonSendSync>, - camera: View, - settings: UniqueView, -) { - if cfg!(target_os = "android") { - return - } - if !settings.debug_draw_current_chunk_border { - return - } - let camera = camera.iter().next().expect("No cameras in the scene"); - let view = camera.view_matrix.to_cols_array_2d(); - let perspective = camera.perspective_matrix.to_cols_array_2d(); - let (_, &player_transform) = (&player, &transforms).iter().next().expect("No player"); - let (_, _, player_position) = player_transform.0.to_scale_rotation_translation(); - let player_in_chunk = ivec3( - (player_position.x as i32).div_euclid(CHUNK_SIZE as i32), - (player_position.y as i32).div_euclid(CHUNK_SIZE as i32), - (player_position.z as i32).div_euclid(CHUNK_SIZE as i32), - ); - let world_position = player_in_chunk.as_vec3() * CHUNK_SIZE as f32; - target.0.draw( - &buffers.0, - &buffers.1, - &program.0, - &uniform! { - model: Mat4::from_scale_rotation_translation( - Vec3::splat(CHUNK_SIZE as f32), - Quat::default(), - world_position - ).to_cols_array_2d(), - color: [0.25f32; 4], - view: view, - perspective: perspective, - }, - &DrawParameters { - depth: Depth { - test: DepthTest::IfLess, - ..Default::default() - }, - blend: Blend::alpha_blending(), - ..Default::default() - } - ).unwrap(); - target.0.draw( - &buffers.0, - &buffers.1, - &program.0, - &uniform! { - model: Mat4::from_scale_rotation_translation( - Vec3::splat(CHUNK_SIZE as f32), - Quat::default(), - world_position - ).to_cols_array_2d(), - color: [0.0f32; 4], - view: view, - perspective: perspective, - }, - &DrawParameters { - polygon_mode: PolygonMode::Point, - line_width: Some(2.), - point_size: Some(5.), - ..Default::default() - } - ).unwrap(); -} +// pub fn draw_current_chunk_border( +// mut target: NonSendSync>, +// player: View, +// transforms: View, +// buffers: NonSendSync>, +// program: NonSendSync>, +// camera: View, +// settings: UniqueView, +// ) { +// if cfg!(target_os = "android") { +// return +// } +// if !settings.debug_draw_current_chunk_border { +// return +// } +// let camera = camera.iter().next().expect("No cameras in the scene"); +// let view = camera.view_matrix.to_cols_array_2d(); +// let perspective = camera.perspective_matrix.to_cols_array_2d(); +// let (_, &player_transform) = (&player, &transforms).iter().next().expect("No player"); +// let (_, _, player_position) = player_transform.0.to_scale_rotation_translation(); +// let player_in_chunk = ivec3( +// (player_position.x as i32).div_euclid(CHUNK_SIZE as i32), +// (player_position.y as i32).div_euclid(CHUNK_SIZE as i32), +// (player_position.z as i32).div_euclid(CHUNK_SIZE as i32), +// ); +// let world_position = player_in_chunk.as_vec3() * CHUNK_SIZE as f32; +// target.0.draw( +// &buffers.0, +// &buffers.1, +// &program.0, +// &uniform! { +// model: Mat4::from_scale_rotation_translation( +// Vec3::splat(CHUNK_SIZE as f32), +// Quat::default(), +// world_position +// ).to_cols_array_2d(), +// color: [0.25f32; 4], +// view: view, +// perspective: perspective, +// }, +// &DrawParameters { +// depth: Depth { +// test: DepthTest::IfLess, +// ..Default::default() +// }, +// blend: Blend::alpha_blending(), +// ..Default::default() +// } +// ).unwrap(); +// target.0.draw( +// &buffers.0, +// &buffers.1, +// &program.0, +// &uniform! { +// model: Mat4::from_scale_rotation_translation( +// Vec3::splat(CHUNK_SIZE as f32), +// Quat::default(), +// world_position +// ).to_cols_array_2d(), +// color: [0.0f32; 4], +// view: view, +// perspective: perspective, +// }, +// &DrawParameters { +// polygon_mode: PolygonMode::Point, +// line_width: Some(2.), +// point_size: Some(5.), +// ..Default::default() +// } +// ).unwrap(); +// } diff --git a/kubi/src/ui/loading_screen.rs b/kubi/src/ui/loading_screen.rs index 805c641..be71392 100644 --- a/kubi/src/ui/loading_screen.rs +++ b/kubi/src/ui/loading_screen.rs @@ -7,7 +7,7 @@ use hui::{ UiElementExt, }, layout::{Alignment, Direction}, - frame_rect, size, + rect_frame, size, }; use shipyard::{UniqueView, UniqueViewMut, Workload, NonSendSync, IntoWorkload}; use winit::keyboard::KeyCode; @@ -28,7 +28,7 @@ pub fn loading_screen_base(bg_alpha: f32, xui: impl FnOnce(&mut ElementList)) -> .with_children(|ui| { Container::default() .with_size(size!(400, auto)) - .with_background(frame_rect! { + .with_background(rect_frame! { color: (0.2, 0.2, 0.2), corner_radius: 8. }) @@ -63,11 +63,11 @@ fn render_loading_ui( ProgressBar::default() .with_value(value) .with_size(size!(100%, 15)) - .with_background(frame_rect! { + .with_background(rect_frame! { color: (0.1, 0.1, 0.1), corner_radius: 2. }) - .with_foreground(frame_rect! { + .with_foreground(rect_frame! { color: (0.4, 0.4, 1.0), corner_radius: 2. }) diff --git a/kubi/src/ui/settings_ui.rs b/kubi/src/ui/settings_ui.rs index 640e393..b863da8 100644 --- a/kubi/src/ui/settings_ui.rs +++ b/kubi/src/ui/settings_ui.rs @@ -2,7 +2,7 @@ use hui::{ element::{br::Break, container::Container, slider::Slider, text::Text, UiElementExt}, layout::{Alignment, Direction}, signal::Signal, - frame_rect, size, + rect_frame, size, }; use shipyard::{NonSendSync, UniqueView, UniqueViewMut}; use winit::keyboard::KeyCode; @@ -34,7 +34,7 @@ pub fn render_settings_ui( .with_align(Alignment::Center) .with_children(|ui| { Container::default() - .with_background(frame_rect! { + .with_background(rect_frame! { color: (0.2, 0.2, 0.2), corner_radius: 8. }) diff --git a/kubi/src/world/chunk.rs b/kubi/src/world/chunk.rs index e8ddd3a..27c52a9 100644 --- a/kubi/src/world/chunk.rs +++ b/kubi/src/world/chunk.rs @@ -1,9 +1,8 @@ use std::sync::Arc; use glam::IVec3; use atomic::Atomic; -use glium::{VertexBuffer, IndexBuffer}; use kubi_shared::worldgen::AbortState; -use crate::rendering::world::ChunkVertex; +use crate::rendering::{world::ChunkVertex, BufferPair}; pub use kubi_shared::chunk::{CHUNK_SIZE, BlockData}; @@ -18,10 +17,8 @@ impl ChunkData { } pub struct ChunkMesh { - pub vertex_buffer: VertexBuffer, - pub index_buffer: IndexBuffer, - pub trans_vertex_buffer: VertexBuffer, - pub trans_index_buffer: IndexBuffer, + pub main: BufferPair, + pub trans: BufferPair, } #[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] diff --git a/kubi/src/world/loading.rs b/kubi/src/world/loading.rs index aa0d774..c0b2f85 100644 --- a/kubi/src/world/loading.rs +++ b/kubi/src/world/loading.rs @@ -1,7 +1,6 @@ use std::sync::Arc; use atomic::{Atomic, Ordering}; use glam::{IVec3, ivec3}; -use glium::{VertexBuffer, IndexBuffer, index::PrimitiveType}; use kubi_shared::{networking::{channels::Channel, messages::ClientToServerMessage}, worldgen::AbortState}; use shipyard::{View, UniqueView, UniqueViewMut, IntoIter, Workload, IntoWorkload, NonSendSync, track}; use uflow::SendMode; @@ -327,21 +326,23 @@ fn process_completed_tasks( //apply the mesh //TODO: Skip if mesh is empty? (i.e. set to None) - let mesh = ChunkMesh { - vertex_buffer: VertexBuffer::immutable(&renderer.display, &vertices).unwrap(), - index_buffer: IndexBuffer::immutable(&renderer.display, PrimitiveType::TrianglesList, &indices).unwrap(), - trans_vertex_buffer: VertexBuffer::immutable(&renderer.display, &trans_vertices).unwrap(), - trans_index_buffer: IndexBuffer::immutable(&renderer.display, PrimitiveType::TrianglesList, &trans_indices).unwrap(), - }; - if let Some(index) = chunk.mesh_index { - meshes.update(index, mesh).expect("Mesh update failed"); - } else { - let mesh_index = meshes.insert(mesh); - chunk.mesh_index = Some(mesh_index); - } + unimplemented!(); - //update chunk state - chunk.current_state = CurrentChunkState::Rendered; + // let mesh = ChunkMesh { + // vertex_buffer: VertexBuffer::immutable(&renderer.display, &vertices).unwrap(), + // index_buffer: IndexBuffer::immutable(&renderer.display, PrimitiveType::TrianglesList, &indices).unwrap(), + // trans_vertex_buffer: VertexBuffer::immutable(&renderer.display, &trans_vertices).unwrap(), + // trans_index_buffer: IndexBuffer::immutable(&renderer.display, PrimitiveType::TrianglesList, &trans_indices).unwrap(), + // }; + // if let Some(index) = chunk.mesh_index { + // meshes.update(index, mesh).expect("Mesh update failed"); + // } else { + // let mesh_index = meshes.insert(mesh); + // chunk.mesh_index = Some(mesh_index); + // } + + // //update chunk state + // chunk.current_state = CurrentChunkState::Rendered; //increase ops counter ops += 1;