diff --git a/crates/components/src/map_view.rs b/crates/components/src/map_view.rs index 86609a79..fa2294e2 100644 --- a/crates/components/src/map_view.rs +++ b/crates/components/src/map_view.rs @@ -98,14 +98,12 @@ impl MapView { update_state.filesystem, e, &atlas, - update_state.graphics.push_constants_supported(), ); let preview_sprite = luminol_graphics::Event::new( &update_state.graphics, update_state.filesystem, e, &atlas, - update_state.graphics.push_constants_supported(), ); let Ok(sprite) = sprite else { return Err(sprite.unwrap_err()); @@ -127,7 +125,6 @@ impl MapView { &map, tileset, &passages, - update_state.graphics.push_constants_supported(), )?; Ok(Self { diff --git a/crates/components/src/tilepicker.rs b/crates/components/src/tilepicker.rs index 7d8eaa19..f377e94f 100644 --- a/crates/components/src/tilepicker.rs +++ b/crates/components/src/tilepicker.rs @@ -138,15 +138,8 @@ impl Tilepicker { let viewport = luminol_graphics::viewport::Viewport::new( &update_state.graphics, - glam::Mat4::orthographic_rh( - 0.0, - 256., - atlas.tileset_height as f32 + 32., - 0.0, - -1.0, - 1.0, - ), - update_state.graphics.push_constants_supported(), + 256., + atlas.tileset_height as f32 + 32., ); let tiles = luminol_graphics::tiles::Tiles::new( @@ -154,7 +147,6 @@ impl Tilepicker { &viewport, atlas, &tilepicker_data, - update_state.graphics.push_constants_supported(), ); let mut passages = @@ -177,7 +169,6 @@ impl Tilepicker { &update_state.graphics, &viewport, &passages, - update_state.graphics.push_constants_supported(), ); Ok(Self { diff --git a/crates/graphics/src/collision/mod.rs b/crates/graphics/src/collision/mod.rs index efafd678..51149c12 100644 --- a/crates/graphics/src/collision/mod.rs +++ b/crates/graphics/src/collision/mod.rs @@ -32,7 +32,6 @@ mod vertex; pub struct Collision { pub instances: Instances, pub bind_group: wgpu::BindGroup, - pub use_push_constants: bool, } #[derive(Debug, Clone)] @@ -149,12 +148,11 @@ impl Collision { graphics_state: &crate::GraphicsState, viewport: &Viewport, passages: &luminol_data::Table2, - use_push_constants: bool, ) -> Self { let instances = Instances::new(&graphics_state.render_state, passages); let mut bind_group_builder = BindGroupBuilder::new(); - if use_push_constants { + if graphics_state.push_constants_supported() { bind_group_builder.append_buffer(viewport.as_buffer().unwrap()); } let bind_group = bind_group_builder.build( @@ -166,7 +164,6 @@ impl Collision { Self { instances, bind_group, - use_push_constants, } } @@ -193,7 +190,7 @@ impl Collision { render_pass.push_debug_group("tilemap collision renderer"); render_pass.set_pipeline(&graphics_state.pipelines.collision); - if self.use_push_constants { + if graphics_state.push_constants_supported() { render_pass.set_push_constants( wgpu::ShaderStages::VERTEX, 0, diff --git a/crates/graphics/src/event.rs b/crates/graphics/src/event.rs index 7f66c4be..fdec02d3 100644 --- a/crates/graphics/src/event.rs +++ b/crates/graphics/src/event.rs @@ -64,7 +64,6 @@ impl Event { filesystem: &impl luminol_filesystem::FileSystem, event: &luminol_data::rpg::Event, atlas: &crate::tiles::Atlas, - use_push_constants: bool, ) -> anyhow::Result> { let Some(page) = event.pages.first() else { anyhow::bail!("event does not have first page"); @@ -86,11 +85,7 @@ impl Event { // Why does this have to be + 1? let quad = atlas.calc_quad((id + 1) as i16); - let viewport = crate::viewport::Viewport::new( - graphics_state, - glam::Mat4::orthographic_rh(0.0, 32., 32., 0., -1., 1.), - use_push_constants, - ); + let viewport = Viewport::new(graphics_state, 32., 32.); (quad, viewport, egui::vec2(32., 32.)) } else { @@ -114,16 +109,12 @@ impl Event { ); let quad = crate::quad::Quad::new(pos, tex_coords, 0.0); - let viewport = crate::viewport::Viewport::new( - graphics_state, - glam::Mat4::orthographic_rh(0.0, cw, ch, 0., -1., 1.), - use_push_constants, - ); + let viewport = Viewport::new(graphics_state, cw, ch); (quad, viewport, egui::vec2(cw, ch)) }; - let sprite = crate::sprite::Sprite::new( + let sprite = Sprite::new( graphics_state, &viewport, quads, @@ -131,7 +122,6 @@ impl Event { page.graphic.blend_type, page.graphic.character_hue, page.graphic.opacity, - use_push_constants, ); Ok(Some(Self { diff --git a/crates/graphics/src/lib.rs b/crates/graphics/src/lib.rs index 639c9130..4a4f0f73 100644 --- a/crates/graphics/src/lib.rs +++ b/crates/graphics/src/lib.rs @@ -87,7 +87,7 @@ impl GraphicsState { let nearest_sampler = render_state .device .create_sampler(&wgpu::SamplerDescriptor { - label: Some("luminol tileset atlas sampler"), + label: Some("luminol nearest texture sampler"), mag_filter: wgpu::FilterMode::Nearest, min_filter: wgpu::FilterMode::Nearest, ..Default::default() diff --git a/crates/graphics/src/map.rs b/crates/graphics/src/map.rs index 1b9a6365..2cd67aed 100644 --- a/crates/graphics/src/map.rs +++ b/crates/graphics/src/map.rs @@ -123,7 +123,6 @@ impl Map { map: &luminol_data::rpg::Map, tileset: &luminol_data::rpg::Tileset, passages: &luminol_data::Table2, - use_push_constants: bool, ) -> anyhow::Result { let atlas = graphics_state .atlas_cache @@ -131,30 +130,12 @@ impl Map { let viewport = crate::viewport::Viewport::new( graphics_state, - glam::Mat4::orthographic_rh( - 0.0, - map.width as f32 * 32., - map.height as f32 * 32., - 0.0, - -1.0, - 1.0, - ), - use_push_constants, + map.width as f32 * 32., + map.height as f32 * 32., ); - let tiles = Tiles::new( - graphics_state, - &viewport, - atlas, - &map.data, - use_push_constants, - ); - let collision = crate::collision::Collision::new( - graphics_state, - &viewport, - passages, - use_push_constants, - ); + let tiles = Tiles::new(graphics_state, &viewport, atlas, &map.data); + let collision = Collision::new(graphics_state, &viewport, passages); let panorama = if let Some(ref panorama_name) = tileset.panorama_name { Some(Plane::new( @@ -171,7 +152,6 @@ impl Map { 255, map.width, map.height, - use_push_constants, )) } else { None @@ -191,7 +171,6 @@ impl Map { tileset.fog_opacity, map.width, map.height, - use_push_constants, )) } else { None diff --git a/crates/graphics/src/plane.rs b/crates/graphics/src/plane.rs index bcdec70d..7cc52355 100644 --- a/crates/graphics/src/plane.rs +++ b/crates/graphics/src/plane.rs @@ -36,7 +36,6 @@ impl Plane { opacity: i32, map_width: usize, map_height: usize, - use_push_constants: bool, ) -> Self { let zoom = zoom as f32 / 100.; let map_width = map_width as f32 * 32.; @@ -61,7 +60,6 @@ impl Plane { blend_mode, hue, opacity, - use_push_constants, ); Self { sprite } diff --git a/crates/graphics/src/sprite/graphic.rs b/crates/graphics/src/sprite/graphic.rs index a101d1ce..3542d3b2 100644 --- a/crates/graphics/src/sprite/graphic.rs +++ b/crates/graphics/src/sprite/graphic.rs @@ -34,12 +34,7 @@ struct Data { } impl Graphic { - pub fn new( - graphics_state: &crate::GraphicsState, - hue: i32, - opacity: i32, - use_push_constants: bool, - ) -> Self { + pub fn new(graphics_state: &crate::GraphicsState, hue: i32, opacity: i32) -> Self { let hue = (hue % 360) as f32 / 360.0; let opacity = opacity as f32 / 255.; let data = Data { @@ -49,7 +44,7 @@ impl Graphic { _padding: 0, }; - let uniform = (!use_push_constants).then(|| { + let uniform = (!graphics_state.push_constants_supported()).then(|| { graphics_state.render_state.device.create_buffer_init( &wgpu::util::BufferInitDescriptor { label: Some("tilemap sprite graphic buffer"), diff --git a/crates/graphics/src/sprite/mod.rs b/crates/graphics/src/sprite/mod.rs index 0b8b8fdd..3c84acec 100644 --- a/crates/graphics/src/sprite/mod.rs +++ b/crates/graphics/src/sprite/mod.rs @@ -32,7 +32,6 @@ pub struct Sprite { pub graphic: graphic::Graphic, pub vertices: vertices::Vertices, pub blend_mode: luminol_data::BlendMode, - pub use_push_constants: bool, pub bind_group: wgpu::BindGroup, } @@ -46,11 +45,10 @@ impl Sprite { blend_mode: luminol_data::BlendMode, hue: i32, opacity: i32, - use_push_constants: bool, ) -> Self { let vertices = vertices::Vertices::from_quads(&graphics_state.render_state, &[quad], texture.size()); - let graphic = graphic::Graphic::new(graphics_state, hue, opacity, use_push_constants); + let graphic = graphic::Graphic::new(graphics_state, hue, opacity); let mut bind_group_builder = BindGroupBuilder::new(); bind_group_builder @@ -72,7 +70,6 @@ impl Sprite { graphic, vertices, blend_mode, - use_push_constants, bind_group, } } @@ -99,7 +96,7 @@ impl Sprite { render_pass.set_pipeline(&graphics_state.pipelines.sprites[&self.blend_mode]); render_pass.set_bind_group(0, &self.bind_group, &[]); - if self.use_push_constants { + if graphics_state.push_constants_supported() { render_pass.set_push_constants(wgpu::ShaderStages::VERTEX, 0, &viewport.as_bytes()); render_pass.set_push_constants( wgpu::ShaderStages::FRAGMENT, diff --git a/crates/graphics/src/tiles/autotiles.rs b/crates/graphics/src/tiles/autotiles.rs index f2a124e1..dddd5c36 100644 --- a/crates/graphics/src/tiles/autotiles.rs +++ b/crates/graphics/src/tiles/autotiles.rs @@ -35,11 +35,7 @@ struct Data { } impl Autotiles { - pub fn new( - graphics_state: &crate::GraphicsState, - atlas: &super::Atlas, - use_push_constants: bool, - ) -> Self { + pub fn new(graphics_state: &crate::GraphicsState, atlas: &super::Atlas) -> Self { let autotiles = Data { autotile_frames: atlas.autotile_frames, autotile_region_width: atlas.autotile_width, @@ -48,7 +44,7 @@ impl Autotiles { _end_padding: 0, }; - let uniform = (!use_push_constants).then(|| { + let uniform = (!graphics_state.push_constants_supported()).then(|| { graphics_state.render_state.device.create_buffer_init( &wgpu::util::BufferInitDescriptor { label: Some("tilemap autotile buffer"), diff --git a/crates/graphics/src/tiles/mod.rs b/crates/graphics/src/tiles/mod.rs index 9301bf35..e300b2f1 100644 --- a/crates/graphics/src/tiles/mod.rs +++ b/crates/graphics/src/tiles/mod.rs @@ -39,7 +39,6 @@ pub struct Tiles { pub atlas: Atlas, pub instances: Instances, pub opacity: Opacity, - pub use_push_constants: bool, pub bind_group: wgpu::BindGroup, } @@ -50,15 +49,14 @@ impl Tiles { viewport: &Viewport, atlas: Atlas, tiles: &luminol_data::Table3, - use_push_constants: bool, ) -> Self { - let autotiles = Autotiles::new(graphics_state, &atlas, use_push_constants); + let autotiles = Autotiles::new(graphics_state, &atlas); let instances = Instances::new( &graphics_state.render_state, tiles, atlas.atlas_texture.size(), ); - let opacity = Opacity::new(graphics_state, use_push_constants); + let opacity = Opacity::new(graphics_state); let mut bind_group_builder = BindGroupBuilder::new(); bind_group_builder @@ -81,7 +79,6 @@ impl Tiles { atlas, instances, opacity, - use_push_constants, bind_group, } @@ -115,7 +112,7 @@ impl Tiles { render_pass.set_pipeline(&graphics_state.pipelines.tiles); render_pass.set_bind_group(0, &self.bind_group, &[]); - if self.use_push_constants { + if graphics_state.push_constants_supported() { render_pass.set_push_constants( wgpu::ShaderStages::VERTEX, 0, @@ -135,7 +132,7 @@ impl Tiles { if enabled { self.opacity .set_opacity(&graphics_state.render_state, layer, opacity); - if self.use_push_constants { + if graphics_state.push_constants_supported() { render_pass.set_push_constants( wgpu::ShaderStages::FRAGMENT, 64 + 48, diff --git a/crates/graphics/src/tiles/opacity.rs b/crates/graphics/src/tiles/opacity.rs index 5a6d011d..c638b55f 100644 --- a/crates/graphics/src/tiles/opacity.rs +++ b/crates/graphics/src/tiles/opacity.rs @@ -25,10 +25,10 @@ pub struct Opacity { } impl Opacity { - pub fn new(graphics_state: &crate::GraphicsState, use_push_constants: bool) -> Self { + pub fn new(graphics_state: &crate::GraphicsState) -> Self { let opacity = [1.; 4]; - let uniform = (!use_push_constants).then(|| { + let uniform = (!graphics_state.push_constants_supported()).then(|| { graphics_state.render_state.device.create_buffer_init( &wgpu::util::BufferInitDescriptor { label: Some("tilemap opacity buffer"), diff --git a/crates/graphics/src/viewport.rs b/crates/graphics/src/viewport.rs index 6b58bc28..466a466d 100644 --- a/crates/graphics/src/viewport.rs +++ b/crates/graphics/src/viewport.rs @@ -25,12 +25,15 @@ pub struct Viewport { } impl Viewport { - pub fn new( - graphics_state: &crate::GraphicsState, - proj: glam::Mat4, - use_push_constants: bool, - ) -> Self { - let uniform = (!use_push_constants).then(|| { + pub fn new(graphics_state: &crate::GraphicsState, width: f32, height: f32) -> Self { + Self::new_proj( + graphics_state, + glam::Mat4::orthographic_rh(0.0, width, height, 0.0, -1.0, 1.0), + ) + } + + pub fn new_proj(graphics_state: &crate::GraphicsState, proj: glam::Mat4) -> Self { + let uniform = (!graphics_state.push_constants_supported()).then(|| { graphics_state.render_state.device.create_buffer_init( &wgpu::util::BufferInitDescriptor { label: Some("tilemap viewport buffer"), @@ -46,6 +49,13 @@ impl Viewport { } } + pub fn set_width_height(&self, render_state: &egui_wgpu::RenderState, width: f32, height: f32) { + self.set_proj( + render_state, + glam::Mat4::orthographic_rh(0.0, width, height, 0.0, -1.0, 1.0), + ) + } + pub fn set_proj(&self, render_state: &egui_wgpu::RenderState, proj: glam::Mat4) { let data = self.data.load(); if data != proj {