From 098c1686398850c11dbdcd882d030696bfeabdc0 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Wed, 12 Jul 2023 17:24:07 +0200 Subject: [PATCH] wgpu wip --- Cargo.lock | 7 + kubi/Cargo.toml | 4 +- kubi/src/block_placement.rs | 2 +- kubi/src/camera/matrices.rs | 12 +- kubi/src/control_flow.rs | 2 +- kubi/src/cursor_lock.rs | 8 +- kubi/src/events.rs | 11 +- kubi/src/gui.rs | 7 +- kubi/src/gui/progressbar.rs | 31 +++-- kubi/src/gui/text_widget.rs | 1 - kubi/src/input.rs | 8 +- kubi/src/lib.rs | 26 ++-- kubi/src/loading_screen.rs | 2 +- kubi/src/networking.rs | 2 +- kubi/src/prefabs.rs | 1 - kubi/src/prefabs/shaders.rs | 17 +-- kubi/src/prefabs/texture.rs | 1 - kubi/src/rendering.rs | 183 ++++++++++++-------------- kubi/src/rendering/entities.rs | 25 ++-- kubi/src/rendering/primitives.rs | 5 +- kubi/src/rendering/primitives/rect.rs | 1 - kubi/src/rendering/world.rs | 20 +-- kubi/src/world/loading.rs | 1 - 23 files changed, 169 insertions(+), 208 deletions(-) delete mode 100644 kubi/src/gui/text_widget.rs diff --git a/Cargo.lock b/Cargo.lock index c99a31b..216818a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -908,6 +908,7 @@ dependencies = [ "log", "lz4_flex", "nohash-hasher", + "pollster", "postcard", "rayon", "serde_json", @@ -1486,6 +1487,12 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "pollster" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22686f4785f02a4fcc856d3b3bb19bf6c8160d103f7a99cc258bddd0251dc7f2" + [[package]] name = "postcard" version = "1.0.4" diff --git a/kubi/Cargo.toml b/kubi/Cargo.toml index a05beda..4f757c7 100644 --- a/kubi/Cargo.toml +++ b/kubi/Cargo.toml @@ -26,9 +26,10 @@ flume = "0.10" gilrs = { version = "0.10", default_features = false, features = ["xinput"] } uflow = "0.7" postcard = { version = "1.0", features = ["alloc"] } +serde_json = { version = "1.0", optional = true } #only used for `generate_visualizer_data` lz4_flex = { version = "0.11", default-features = false, features = ["std"] } tinyset = "0.4" -serde_json = { version = "1.0", optional = true } #only used for `generate_visualizer_data` +pollster = "0.3" [target.'cfg(target_os = "android")'.dependencies] android-activity = { version = "0.4", features = ["native-activity"] } @@ -43,6 +44,7 @@ generate_visualizer_data = ["dep:serde_json", "shipyard/serde1"] safe_lz4 = ["lz4_flex/safe-encode", "lz4_flex/safe-decode"] parallel = ["shipyard/parallel"] # causes some serious issues! nightly = ["hashbrown/nightly", "glam/core-simd", "lz4_flex/nightly", "kubi-shared/nightly"] +dx12-dxc = [] #Requires dlls from https://github.com/microsoft/DirectXShaderCompiler #part of wip android support [package.metadata.android] diff --git a/kubi/src/block_placement.rs b/kubi/src/block_placement.rs index 18eb313..2f7ce1f 100644 --- a/kubi/src/block_placement.rs +++ b/kubi/src/block_placement.rs @@ -1,5 +1,5 @@ use shipyard::{UniqueViewMut, UniqueView, View, IntoIter, ViewMut, EntitiesViewMut, Workload, IntoWorkload}; -use glium::glutin::event::VirtualKeyCode; +use winit::event::VirtualKeyCode; use kubi_shared::{ block::Block, queue::QueuedBlock, diff --git a/kubi/src/camera/matrices.rs b/kubi/src/camera/matrices.rs index 847be29..50fcde6 100644 --- a/kubi/src/camera/matrices.rs +++ b/kubi/src/camera/matrices.rs @@ -1,6 +1,6 @@ use glam::{Vec3, Mat4}; use shipyard::{ViewMut, View, IntoIter, Workload, IntoWorkload, track, UniqueView, SystemModificator}; -use crate::{transform::Transform, rendering::WindowSize, events::WindowResizedEvent}; +use crate::{transform::Transform, events::WindowResizedEvent, rendering::Renderer}; use super::Camera; //maybe parallelize these two? @@ -18,14 +18,14 @@ fn update_view_matrix( fn update_perspective_matrix( mut vm_camera: ViewMut, - size: UniqueView, + renderer: UniqueView ) { + let size = renderer.size; for mut camera in (&mut vm_camera).iter() { camera.perspective_matrix = Mat4::perspective_rh_gl( - camera.fov, - size.0.x as f32 / size.0.y as f32, - camera.z_near, - camera.z_far, + camera.fov, + size.width as f32 / size.height as f32, + camera.z_near, camera.z_far ) } } diff --git a/kubi/src/control_flow.rs b/kubi/src/control_flow.rs index 4a4b0c3..673ff6f 100644 --- a/kubi/src/control_flow.rs +++ b/kubi/src/control_flow.rs @@ -1,5 +1,5 @@ use shipyard::{UniqueView, UniqueViewMut, Unique, AllStoragesView}; -use glium::glutin::{event::VirtualKeyCode, event_loop::ControlFlow}; +use winit::{event::VirtualKeyCode, event_loop::ControlFlow}; use crate::input::RawKbmInputState; #[derive(Unique)] diff --git a/kubi/src/cursor_lock.rs b/kubi/src/cursor_lock.rs index 428230a..7118166 100644 --- a/kubi/src/cursor_lock.rs +++ b/kubi/src/cursor_lock.rs @@ -1,6 +1,6 @@ use shipyard::{AllStoragesView, Unique, NonSendSync, UniqueView, UniqueViewMut}; use crate::rendering::Renderer; -use glium::glutin::window::CursorGrabMode; +use winit::window::CursorGrabMode; #[derive(Unique)] pub struct CursorLock(pub bool); @@ -13,13 +13,11 @@ pub fn update_cursor_lock_state( return } if lock.is_inserted_or_modified() { - let gl_window = display.display.gl_window(); - let window = gl_window.window(); - window.set_cursor_grab(match lock.0 { + display.window.set_cursor_grab(match lock.0 { true => CursorGrabMode::Confined, false => CursorGrabMode::None, }).expect("Failed to change cursor grab state"); - window.set_cursor_visible(!lock.0); + display.window.set_cursor_visible(!lock.0); } } diff --git a/kubi/src/events.rs b/kubi/src/events.rs index ba919f8..2ccedb4 100644 --- a/kubi/src/events.rs +++ b/kubi/src/events.rs @@ -1,6 +1,6 @@ use glam::UVec2; use shipyard::{World, Component, AllStoragesViewMut, SparseSet, NonSendSync, UniqueView}; -use glium::glutin::event::{Event, DeviceEvent, DeviceId, WindowEvent, Touch}; +use winit::event::{Event, DeviceEvent, DeviceId, WindowEvent, Touch}; use crate::rendering::Renderer; pub mod player_actions; @@ -81,13 +81,10 @@ pub fn process_glutin_events(world: &mut World, event: &Event<'_, ()>) { pub fn initial_resize_event( mut storages: AllStoragesViewMut, ) { - let (w, h) = { - let renderer = storages.borrow::>>().unwrap(); - renderer.display.get_framebuffer_dimensions() - }; + let renderer = storages.borrow::>>().unwrap(); storages.add_entity(( - EventComponent, - WindowResizedEvent(UVec2::new(w, h)) + EventComponent, + WindowResizedEvent(UVec2::new(renderer.size.width, renderer.size.height)) )); } diff --git a/kubi/src/gui.rs b/kubi/src/gui.rs index 3a57db1..210e850 100644 --- a/kubi/src/gui.rs +++ b/kubi/src/gui.rs @@ -2,7 +2,6 @@ use shipyard::{Component, Unique, Workload, IntoWorkload, AllStoragesView, View, use glam::{Vec4, Mat4}; use crate::{color::color_hex, events::WindowResizedEvent}; -pub mod text_widget; pub mod progressbar; use progressbar::render_progressbars; @@ -41,18 +40,24 @@ fn update_gui_view( view.0 = Mat4::orthographic_rh_gl(0.0, w as f32, h as f32, 0.0, -1.0, 1.0); } +#[deprecated="will be replaced by an immediate-mode ui soon, currently a no-op"] +#[allow(deprecated)] pub fn init_gui( storages: AllStoragesView ) { storages.add_unique(GuiView::default()); } +#[deprecated="will be replaced by an immediate-mode ui soon, currently a no-op"] +#[allow(deprecated)] pub fn update_gui() -> Workload { ( update_gui_view ).into_sequential_workload() } +#[deprecated="will be replaced by an immediate-mode ui soon, currently a no-op"] +#[allow(deprecated)] pub fn render_gui() -> Workload { ( render_progressbars diff --git a/kubi/src/gui/progressbar.rs b/kubi/src/gui/progressbar.rs index b5f59d1..8d155cf 100644 --- a/kubi/src/gui/progressbar.rs +++ b/kubi/src/gui/progressbar.rs @@ -1,11 +1,10 @@ use shipyard::{UniqueView, UniqueViewMut, NonSendSync, View, Component, IntoIter, IntoWithId, Get, track}; -use glium::{Surface, uniform, DrawParameters}; use crate::{ prefabs::ProgressbarShaderPrefab, rendering::{ - RenderTarget, + RenderTarget, primitives::rect::RectPrimitive - }, + }, transform::Transform2d, }; use super::{GuiComponent, PrimaryColor, SecondaryColor, GuiView}; @@ -29,18 +28,18 @@ pub fn render_progressbars( for (eid, (_, transform, progress)) in (&components, &transforms, &progressbars).iter().with_id() { let primary_color = primary.get(eid).copied().unwrap_or_default(); let secondary_color = secondary.get(eid).copied().unwrap_or_default(); - target.0.draw( - &rect.0, - &rect.1, - &program.0, - &uniform! { - transform: transform.0.to_cols_array_2d(), - ui_view: view.0.to_cols_array_2d(), - progress: progress.progress, - color: primary_color.0.to_array(), - bg_color: secondary_color.0.to_array(), - }, - &DrawParameters::default() - ).unwrap(); + // target.0.draw( + // &rect.0, + // &rect.1, + // &program.0, + // &uniform! { + // transform: transform.0.to_cols_array_2d(), + // ui_view: view.0.to_cols_array_2d(), + // progress: progress.progress, + // color: primary_color.0.to_array(), + // bg_color: secondary_color.0.to_array(), + // }, + // &DrawParameters::default() + // ).unwrap(); } } diff --git a/kubi/src/gui/text_widget.rs b/kubi/src/gui/text_widget.rs deleted file mode 100644 index 31c4422..0000000 --- a/kubi/src/gui/text_widget.rs +++ /dev/null @@ -1 +0,0 @@ -//TODO text widget diff --git a/kubi/src/input.rs b/kubi/src/input.rs index d1e65b5..f4d40ed 100644 --- a/kubi/src/input.rs +++ b/kubi/src/input.rs @@ -1,13 +1,13 @@ use gilrs::{Gilrs, GamepadId, Button, Event, Axis}; use glam::{Vec2, DVec2, vec2, dvec2}; -use glium::glutin::event::{DeviceEvent, DeviceId, VirtualKeyCode, ElementState, TouchPhase}; +use winit::event::{DeviceEvent, DeviceId, VirtualKeyCode, ElementState, TouchPhase}; use hashbrown::HashMap; use tinyset::{SetU32, SetU64}; use nohash_hasher::BuildNoHashHasher; use shipyard::{AllStoragesView, Unique, View, IntoIter, UniqueViewMut, Workload, IntoWorkload, UniqueView, NonSendSync}; use crate::{ events::{InputDeviceEvent, TouchEvent}, - rendering::WindowSize + rendering::Renderer }; #[derive(Unique, Clone, Copy, Default, Debug)] @@ -202,10 +202,10 @@ fn update_input_state_gamepad ( fn update_input_state_touch ( touch_state: UniqueView, - win_size: UniqueView, + renderer: UniqueView, mut inputs: UniqueViewMut, ) { - let w = win_size.0.as_dvec2(); + let w = dvec2(renderer.size.width as _, renderer.size.height as _); //Movement if let Some(finger) = touch_state.query_area( diff --git a/kubi/src/lib.rs b/kubi/src/lib.rs index c43306c..bc6c304 100644 --- a/kubi/src/lib.rs +++ b/kubi/src/lib.rs @@ -6,11 +6,9 @@ use shipyard::{ NonSendSync, WorkloadModificator, SystemModificator }; -use glium::{ - glutin::{ - event_loop::{EventLoop, ControlFlow}, - event::{Event, WindowEvent} - } +use winit::{ + event_loop::{EventLoop, ControlFlow}, + event::{Event, WindowEvent} }; use glam::vec3; use std::time::Instant; @@ -31,6 +29,8 @@ pub(crate) mod delta_time; pub(crate) mod cursor_lock; pub(crate) mod control_flow; pub(crate) mod state; +#[deprecated="will be replaced by an immediate-mode ui soon, currently a no-op"] +#[allow(deprecated)] pub(crate) mod gui; pub(crate) mod networking; pub(crate) mod init; @@ -45,7 +45,7 @@ use world::{ loading::update_loaded_world_around_player, raycast::update_raycasts, queue::apply_queued_blocks, - tasks::{ChunkTaskManager}, + tasks::ChunkTaskManager, }; use player::{spawn_player, MainPlayer}; use prefabs::load_prefabs; @@ -64,8 +64,6 @@ use rendering::{ RenderTarget, BackgroundColor, clear_background, - init_window_size, - update_window_size, primitives::init_primitives, world::{draw_world, draw_current_chunk_border}, selection_box::render_selection_box, @@ -94,7 +92,6 @@ fn startup() -> Workload { ( init_fixed_timestamp_storage, initial_resize_event, - init_window_size, load_prefabs, init_primitives, insert_lock_state, @@ -110,7 +107,6 @@ fn startup() -> Workload { fn update() -> Workload { ( - update_window_size, update_cursor_lock_state, process_inputs, ( @@ -170,15 +166,19 @@ fn attach_console() { unsafe { AttachConsole(ATTACH_PARENT_PROCESS); } } +#[cfg(target_os = "android")] #[no_mangle] -#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on"))] +pub fn android_main(app: AndroidApp) { + kubi_main() +} + pub fn kubi_main() { //Attach console on release builds on windows #[cfg(all(windows, not(debug_assertions)))] attach_console(); //Print version println!("{:─^54}", format!("[ ▄▀ Kubi client v. {} ]", env!("CARGO_PKG_VERSION"))); - + //Init env_logger kubi_logging::init(); @@ -201,7 +201,7 @@ pub fn kubi_main() { //Initialize renderer { let settings = world.borrow::>().unwrap(); - world.add_unique_non_send_sync(Renderer::init(&event_loop, &settings)); + world.add_unique_non_send_sync(Renderer::init_blocking(&event_loop, &settings)); } world.add_unique(BackgroundColor(vec3(0.5, 0.5, 1.))); diff --git a/kubi/src/loading_screen.rs b/kubi/src/loading_screen.rs index e3e3e99..3774295 100644 --- a/kubi/src/loading_screen.rs +++ b/kubi/src/loading_screen.rs @@ -1,5 +1,5 @@ use shipyard::{UniqueView, UniqueViewMut, Workload, IntoWorkload, EntityId, Unique, AllStoragesViewMut, ViewMut, Get, SystemModificator, track}; -use glium::glutin::event::VirtualKeyCode; +use winit::event::VirtualKeyCode; use glam::{Mat3, vec2}; use crate::{ world::ChunkStorage, diff --git a/kubi/src/networking.rs b/kubi/src/networking.rs index a0afa00..b422cb7 100644 --- a/kubi/src/networking.rs +++ b/kubi/src/networking.rs @@ -1,5 +1,5 @@ use shipyard::{Unique, AllStoragesView, UniqueView, UniqueViewMut, Workload, IntoWorkload, EntitiesViewMut, Component, ViewMut, SystemModificator, View, IntoIter, WorkloadModificator}; -use glium::glutin::event_loop::ControlFlow; +use winit::event_loop::ControlFlow; use std::net::SocketAddr; use uflow::{ client::{Client, Config as ClientConfig, Event as ClientEvent}, diff --git a/kubi/src/prefabs.rs b/kubi/src/prefabs.rs index 6802f54..f44598c 100644 --- a/kubi/src/prefabs.rs +++ b/kubi/src/prefabs.rs @@ -1,5 +1,4 @@ use shipyard::{NonSendSync, UniqueView, Unique, AllStoragesView}; -use glium::{texture::{SrgbTexture2dArray, MipmapsOption}, Program}; use kubi_shared::block::BlockTexture; use crate::rendering::Renderer; diff --git a/kubi/src/prefabs/shaders.rs b/kubi/src/prefabs/shaders.rs index 7496a2f..7eb81eb 100644 --- a/kubi/src/prefabs/shaders.rs +++ b/kubi/src/prefabs/shaders.rs @@ -1,19 +1,6 @@ macro_rules! include_shader_prefab { ($name: literal, $vert: literal, $frag: literal, $facade: expr) => { - { - use ::glium::{Program, program::ProgramCreationInput}; - log::info!("compiling shader {}", $name); - Program::new(&*$facade, ProgramCreationInput::SourceCode { - vertex_shader: include_str!($vert), - fragment_shader: include_str!($frag), - geometry_shader: None, - tessellation_control_shader: None, - tessellation_evaluation_shader: None, - transform_feedback_varyings: None, - outputs_srgb: false, - uses_point_size: false, - }).expect("Failed to compile gpu program") - } - }; + compile_error!("`include_shader_prefab` is not implemented yet") + } } pub(crate) use include_shader_prefab; diff --git a/kubi/src/prefabs/texture.rs b/kubi/src/prefabs/texture.rs index 845f1b6..6107ffc 100644 --- a/kubi/src/prefabs/texture.rs +++ b/kubi/src/prefabs/texture.rs @@ -1,7 +1,6 @@ use strum::IntoEnumIterator; use rayon::prelude::*; use std::{path::PathBuf, io::BufReader}; -use glium::{texture::{SrgbTexture2dArray, RawImage2d, MipmapsOption}, backend::Facade}; use crate::filesystem::open_asset; use super::AssetPaths; diff --git a/kubi/src/rendering.rs b/kubi/src/rendering.rs index 8b620c4..92bbae3 100644 --- a/kubi/src/rendering.rs +++ b/kubi/src/rendering.rs @@ -1,14 +1,11 @@ use shipyard::{Unique, NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, AllStoragesView}; -use glium::{ - Display, Surface, - Version, Api, - glutin::{ - event_loop::EventLoop, - window::{WindowBuilder, Fullscreen}, - ContextBuilder, GlProfile, GlRequest, dpi::PhysicalSize - }, +use winit::{ + event_loop::EventLoop, + window::{Window, WindowBuilder, Fullscreen}, + dpi::PhysicalSize, }; use glam::{Vec3, UVec2}; +use pollster::FutureExt as _; use crate::{events::WindowResizedEvent, settings::{GameSettings, FullscreenMode}}; pub mod primitives; @@ -18,93 +15,104 @@ pub mod entities; #[derive(Unique)] #[repr(transparent)] -pub struct RenderTarget(pub glium::Frame); +pub struct RenderTarget(pub ()); +impl Drop for RenderTarget { + +} #[derive(Unique)] #[repr(transparent)] pub struct BackgroundColor(pub Vec3); -#[derive(Unique, Clone, Copy)] -#[repr(transparent)] -pub struct WindowSize(pub UVec2); - #[derive(Unique)] pub struct Renderer { - pub display: Display + pub window: Window, + pub instance: wgpu::Instance, + pub surface: wgpu::Surface, + pub adapter: wgpu::Adapter, + pub device: wgpu::Device, + pub queue: wgpu::Queue, + pub size: PhysicalSize, } impl Renderer { - pub fn init(event_loop: &EventLoop<()>, settings: &GameSettings) -> Self { + pub async fn init(event_loop: &EventLoop<()>, settings: &GameSettings) -> Self { log::info!("initializing display"); - let wb = WindowBuilder::new() + //Build window + let window = WindowBuilder::new() .with_title("kubi") .with_maximized(true) .with_min_inner_size(PhysicalSize::new(640, 480)) - .with_fullscreen({ - //this has no effect on android, so skip this pointless stuff - #[cfg(target_os = "android")] { - None + .build(event_loop) + .expect("Window creation failed"); + + //Enable fullscreen (on supported platforms; if enabled in settings) + #[cfg(not(target_os = "android"))] + window.set_fullscreen(settings.fullscreen.as_ref().and_then(|fullscreen| { + match fullscreen.mode { + FullscreenMode::Exclusive => { + Some(Fullscreen::Borderless(window.current_monitor())) } - #[cfg(not(target_os = "android"))] - if let Some(fs_settings) = &settings.fullscreen { - let monitor = event_loop.primary_monitor().or_else(|| { - event_loop.available_monitors().next() - }); - if let Some(monitor) = monitor { - log::info!("monitor: {}", monitor.name().unwrap_or_else(|| "generic".into())); - match fs_settings.mode { - FullscreenMode::Borderless => { - log::info!("starting in borderless fullscreen mode"); - Some(Fullscreen::Borderless(Some(monitor))) - }, - FullscreenMode::Exclusive => { - log::warn!("exclusive fullscreen mode is experimental"); - log::info!("starting in exclusive fullscreen mode"); - //TODO: grabbing the first video mode is probably not the best idea... - monitor.video_modes().next() - .map(|vmode| { - log::info!("video mode: {}", vmode.to_string()); - Some(Fullscreen::Exclusive(vmode)) - }) - .unwrap_or_else(|| { - log::warn!("no valid video modes found, falling back to windowed mode instead"); - None - }) - } - } - } else { - log::warn!("no monitors found, falling back to windowed mode"); - None - } + FullscreenMode::Borderless => { + window.current_monitor().and_then(|monitor| { + monitor.video_modes().next().map(|video_mode| { + Fullscreen::Exclusive(video_mode) + }) + }) + } + } + })); + + //Create wgpu stuff + let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { + backends: wgpu::Backends::all(), + dx12_shader_compiler: if cfg!(all(windows, feature = "dx12-dxc")) { + wgpu::Dx12Compiler::Dxc { dxil_path: None, dxc_path: None } + } else { + wgpu::Dx12Compiler::Fxc + } + }); + + let surface = unsafe { + instance.create_surface(&window) + }.expect("Failed to create a Surface"); + + let adapter = instance.request_adapter( + &wgpu::RequestAdapterOptions { + power_preference: wgpu::PowerPreference::HighPerformance, + compatible_surface: Some(&surface), + force_fallback_adapter: false, + }, + ).await.expect("Failed to create wgpu adapter"); + + let (device, queue) = adapter.request_device( + &wgpu::DeviceDescriptor { + features: wgpu::Features::empty(), + limits: if cfg!(target_arch = "wasm32") { + wgpu::Limits::downlevel_webgl2_defaults() + } else if cfg!(target_arch = "android") { + wgpu::Limits::downlevel_defaults() } else { - log::info!("starting in windowed mode"); - None - } - }); - - let cb = ContextBuilder::new() - .with_srgb(false) - .with_depth_buffer(24) - .with_multisampling(settings.msaa.unwrap_or_default()) - .with_vsync(settings.vsync) - .with_gl_profile(GlProfile::Core) - .with_gl(GlRequest::Latest); - - let display = Display::new(wb, cb, event_loop) - .expect("Failed to create a glium Display"); - - log::info!("Vendor: {}", display.get_opengl_vendor_string()); - log::info!("Renderer: {}", display.get_opengl_renderer_string()); - log::info!("OpenGL: {}", display.get_opengl_version_string()); - log::info!("Supports GLSL: {:?}", display.get_supported_glsl_version()); - log::info!("Framebuffer dimensions: {:?}", display.get_framebuffer_dimensions()); - if display.is_context_loss_possible() { log::warn!("OpenGL context loss possible") } - if display.is_robust() { log::warn!("OpenGL implementation is not robust") } - if display.is_debug() { log::info!("OpenGL context is in debug mode") } + wgpu::Limits::default() + }, + label: None, + }, + None, + ).await.unwrap(); - assert!(display.is_glsl_version_supported(&Version(Api::GlEs, 3, 0)), "GLSL ES 3.0 is not supported"); + log::info!("Adapter: {:?}", adapter.get_info()); + + Self { window, instance, surface, adapter, device, queue, size: PhysicalSize::default() } + } + + /// do not call from async functions + pub fn init_blocking(event_loop: &EventLoop<()>, settings: &GameSettings) -> Self { + Self::init(event_loop, settings).block_on() + } + + /// Start a new frame + pub fn render() -> RenderTarget { - Self { display } } } @@ -112,27 +120,10 @@ 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.); -} - -//not sure if this belongs here - -pub fn init_window_size( - storages: AllStoragesView, -) { - let size = storages.borrow::>().unwrap().iter().next().unwrap().0; - storages.add_unique(WindowSize(size)) -} - -pub fn update_window_size( - mut win_size: UniqueViewMut, - resize: View, -) { - if let Some(resize) = resize.iter().next() { - win_size.0 = resize.0; - } + } +#[deprecated] pub fn if_resized ( resize: View, ) -> bool { diff --git a/kubi/src/rendering/entities.rs b/kubi/src/rendering/entities.rs index 0135edf..7bd3534 100644 --- a/kubi/src/rendering/entities.rs +++ b/kubi/src/rendering/entities.rs @@ -1,5 +1,4 @@ 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, @@ -42,17 +41,17 @@ pub fn render_entities( 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(); + // 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 811d978..b89b090 100644 --- a/kubi/src/rendering/primitives.rs +++ b/kubi/src/rendering/primitives.rs @@ -1,5 +1,4 @@ use shipyard::{Workload, IntoWorkload}; -use glium::implement_vertex; pub mod cube; pub mod rect; @@ -7,17 +6,17 @@ pub mod rect; use cube::init_cube_primitive; use rect::init_rect_primitive; +#[repr(C)] #[derive(Clone, Copy, Default)] pub struct PositionOnlyVertex { pub position: [f32; 3], } -implement_vertex!(PositionOnlyVertex, position); +#[repr(C)] #[derive(Clone, Copy, Default)] pub struct PositionOnlyVertex2d { pub position: [f32; 2], } -implement_vertex!(PositionOnlyVertex2d, position); pub fn init_primitives() -> Workload { ( diff --git a/kubi/src/rendering/primitives/rect.rs b/kubi/src/rendering/primitives/rect.rs index 0215d14..1bf8966 100644 --- a/kubi/src/rendering/primitives/rect.rs +++ b/kubi/src/rendering/primitives/rect.rs @@ -1,5 +1,4 @@ use shipyard::{Unique, AllStoragesView, NonSendSync, UniqueView}; -use glium::{VertexBuffer, IndexBuffer, index::PrimitiveType}; use crate::rendering::Renderer; use super::PositionOnlyVertex2d; diff --git a/kubi/src/rendering/world.rs b/kubi/src/rendering/world.rs index d922dbe..0485408 100644 --- a/kubi/src/rendering/world.rs +++ b/kubi/src/rendering/world.rs @@ -1,22 +1,5 @@ use glam::{Vec3, Mat4, Quat, ivec3}; use shipyard::{NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, track}; -use glium::{ - implement_vertex, uniform, - Surface, DrawParameters, - uniforms::{ - Sampler, - SamplerBehavior, - MinifySamplerFilter, - MagnifySamplerFilter, - SamplerWrapFunction - }, - draw_parameters::{ - Depth, - DepthTest, - PolygonMode, - BackfaceCullingMode, - }, Blend -}; use crate::{ camera::Camera, player::MainPlayer, @@ -34,15 +17,14 @@ use crate::{ }; use super::{RenderTarget, primitives::cube::CubePrimitive}; -#[derive(Clone, Copy)] #[repr(C)] +#[derive(Clone, Copy)] pub struct ChunkVertex { pub position: [f32; 3], pub normal: [f32; 3], pub uv: [f32; 2], pub tex_index: u8, } -implement_vertex!(ChunkVertex, position, normal, uv, tex_index); pub fn draw_world( mut target: NonSendSync>, diff --git a/kubi/src/world/loading.rs b/kubi/src/world/loading.rs index aa854b7..502108e 100644 --- a/kubi/src/world/loading.rs +++ b/kubi/src/world/loading.rs @@ -1,5 +1,4 @@ use glam::{IVec3, ivec3}; -use glium::{VertexBuffer, IndexBuffer, index::PrimitiveType}; use kubi_shared::networking::messages::ClientToServerMessage; use shipyard::{View, UniqueView, UniqueViewMut, IntoIter, Workload, IntoWorkload, NonSendSync, track}; use uflow::SendMode;