aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml1
-rw-r--r--examples/render-quad/Cargo.toml1
-rw-r--r--examples/render-quad/src/main.rs21
-rw-r--r--stockton-passes/Cargo.toml22
-rw-r--r--stockton-passes/src/camera.rs (renamed from stockton-render/src/draw/camera.rs)4
-rw-r--r--stockton-passes/src/data/3d.frag (renamed from stockton-render/src/draw/data/stockton.frag)0
-rw-r--r--stockton-passes/src/data/3d.vert (renamed from stockton-render/src/draw/data/stockton.vert)0
-rw-r--r--stockton-passes/src/data/ui.frag (renamed from stockton-render/src/draw/ui/data/stockton.frag)0
-rw-r--r--stockton-passes/src/data/ui.vert (renamed from stockton-render/src/draw/ui/data/stockton.vert)0
-rw-r--r--stockton-passes/src/level.rs (renamed from stockton-render/src/draw/draw_passes/level.rs)106
-rw-r--r--stockton-passes/src/lib.rs9
-rw-r--r--stockton-passes/src/ui.rs (renamed from stockton-render/src/draw/draw_passes/ui.rs)148
-rw-r--r--stockton-passes/src/window.rs (renamed from stockton-render/src/window.rs)40
-rw-r--r--stockton-render/Cargo.toml2
-rw-r--r--stockton-render/src/buffers/dedicated_image.rs (renamed from stockton-render/src/draw/buffers/dedicated_image.rs)2
-rw-r--r--stockton-render/src/buffers/draw_buffers.rs (renamed from stockton-render/src/draw/buffers/draw_buffers.rs)0
-rw-r--r--stockton-render/src/buffers/mod.rs (renamed from stockton-render/src/draw/buffers/mod.rs)12
-rw-r--r--stockton-render/src/buffers/staged.rs (renamed from stockton-render/src/draw/buffers/staged.rs)0
-rw-r--r--stockton-render/src/builders/mod.rs7
-rw-r--r--stockton-render/src/builders/pipeline.rs (renamed from stockton-render/src/draw/builders/pipeline.rs)18
-rw-r--r--stockton-render/src/builders/renderpass.rs (renamed from stockton-render/src/draw/builders/renderpass.rs)0
-rw-r--r--stockton-render/src/builders/shader.rs (renamed from stockton-render/src/draw/builders/shader.rs)0
-rw-r--r--stockton-render/src/context.rs (renamed from stockton-render/src/draw/context.rs)75
-rw-r--r--stockton-render/src/culling.rs70
-rw-r--r--stockton-render/src/draw/builders/mod.rs3
-rw-r--r--stockton-render/src/draw/mod.rs17
-rw-r--r--stockton-render/src/draw/ui/mod.rs52
-rw-r--r--stockton-render/src/draw_passes/cons.rs (renamed from stockton-render/src/draw/draw_passes/cons.rs)44
-rw-r--r--stockton-render/src/draw_passes/mod.rs (renamed from stockton-render/src/draw/draw_passes/mod.rs)29
-rw-r--r--stockton-render/src/draw_passes/util.rs (renamed from stockton-render/src/draw/draw_passes/util.rs)0
-rw-r--r--stockton-render/src/lib.rs91
-rw-r--r--stockton-render/src/queue_negotiator.rs (renamed from stockton-render/src/draw/queue_negotiator.rs)0
-rw-r--r--stockton-render/src/systems.rs2
-rw-r--r--stockton-render/src/target.rs (renamed from stockton-render/src/draw/target.rs)13
-rw-r--r--stockton-render/src/texture/block.rs (renamed from stockton-render/src/draw/texture/block.rs)0
-rw-r--r--stockton-render/src/texture/image.rs (renamed from stockton-render/src/draw/texture/image.rs)0
-rw-r--r--stockton-render/src/texture/load.rs (renamed from stockton-render/src/draw/texture/load.rs)0
-rw-r--r--stockton-render/src/texture/loader.rs (renamed from stockton-render/src/draw/texture/loader.rs)2
-rw-r--r--stockton-render/src/texture/mod.rs (renamed from stockton-render/src/draw/texture/mod.rs)0
-rw-r--r--stockton-render/src/texture/repo.rs (renamed from stockton-render/src/draw/texture/repo.rs)4
-rw-r--r--stockton-render/src/texture/resolver.rs (renamed from stockton-render/src/draw/texture/resolver.rs)2
-rw-r--r--stockton-render/src/texture/staging_buffer.rs (renamed from stockton-render/src/draw/texture/staging_buffer.rs)0
-rw-r--r--stockton-render/src/utils.rs (renamed from stockton-render/src/draw/utils.rs)2
43 files changed, 386 insertions, 413 deletions
diff --git a/Cargo.toml b/Cargo.toml
index d365a31..162e989 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,6 +5,7 @@ members = [
"stockton-input-codegen",
"stockton-render",
"stockton-levels",
+ "stockton-passes",
"stockton-contrib",
"rendy-memory",
"rendy-descriptor",
diff --git a/examples/render-quad/Cargo.toml b/examples/render-quad/Cargo.toml
index d32aa6e..9988c66 100644
--- a/examples/render-quad/Cargo.toml
+++ b/examples/render-quad/Cargo.toml
@@ -11,6 +11,7 @@ stockton-input-codegen = { path = "../../stockton-input-codegen" }
stockton-types = { path = "../../stockton-types" }
stockton-levels = { path = "../../stockton-levels" }
stockton-contrib = { path = "../../stockton-contrib", features = ["delta_time", "flycam"] }
+stockton-passes = { path = "../../stockton-passes" }
winit = "^0.21"
log = "0.4.0"
simplelog = "^0.10"
diff --git a/examples/render-quad/src/main.rs b/examples/render-quad/src/main.rs
index 3dbb824..0cc8b83 100644
--- a/examples/render-quad/src/main.rs
+++ b/examples/render-quad/src/main.rs
@@ -9,14 +9,19 @@ extern crate legion;
use anyhow::{Context, Result};
use log::warn;
use std::collections::BTreeMap;
+use stockton_passes::camera::calc_vp_matrix_system;
+use stockton_passes::window::{process_window_events_system, UiState, WindowEvent, WindowFlow};
+use winit::event_loop::ControlFlow;
use std::path::Path;
use std::sync::{Arc, RwLock};
use stockton_levels::parts::data::{Geometry, Vertex};
use stockton_levels::types::Rgba;
-use stockton_render::draw::{
- texture::resolver::FsResolver, ConsDrawPass, LevelDrawPass, LevelDrawPassConfig, UiDrawPass,
+use stockton_passes::{
+ level::{LevelDrawPass, LevelDrawPassConfig},
+ ui::UiDrawPass,
};
+use stockton_render::{draw_passes::ConsDrawPass, texture::resolver::FsResolver};
use winit::{event::Event, event_loop::EventLoop, window::WindowBuilder};
use egui::{containers::CentralPanel, Frame};
@@ -26,8 +31,7 @@ use stockton_contrib::flycam::*;
use stockton_input::{Axis, InputManager, Mouse};
use stockton_render::error::full_error_display;
-use stockton_render::systems::*;
-use stockton_render::{Renderer, UiState, WindowEvent};
+use stockton_render::Renderer;
use stockton_types::components::{CameraSettings, CameraVPMatrix, Transform};
use stockton_types::{Session, Vector2, Vector3};
@@ -186,9 +190,9 @@ fn try_main<'a>() -> Result<()> {
));
// Create the renderer
- let (renderer, tx): (Renderer<Dp<'static>>, _) = Renderer::new(
+ let renderer = Renderer::<Dp<'static>>::new(
&window,
- &session,
+ &mut session,
(
LevelDrawPassConfig {
active_camera: player,
@@ -200,7 +204,10 @@ fn try_main<'a>() -> Result<()> {
(),
),
)?;
- let new_control_flow = renderer.update_control_flow.clone();
+
+ let new_control_flow = Arc::new(RwLock::new(ControlFlow::Poll));
+ let (window_flow, tx) = WindowFlow::new(new_control_flow.clone());
+ session.resources.insert(window_flow);
// Populate the initial UI state
{
diff --git a/stockton-passes/Cargo.toml b/stockton-passes/Cargo.toml
new file mode 100644
index 0000000..a37846c
--- /dev/null
+++ b/stockton-passes/Cargo.toml
@@ -0,0 +1,22 @@
+[package]
+name = "stockton-passes"
+version = "0.1.0"
+authors = ["tcmal <oscar.shrimpton.personal@gmail.com>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+stockton-render = { path = "../stockton-render" }
+stockton-types = { path = "../stockton-types" }
+stockton-levels = { path = "../stockton-levels" }
+stockton-input = { path = "../stockton-input" }
+anyhow = "1.0.40"
+egui = "^0.12"
+epaint = "^0.12"
+gfx-hal = "^0.8.0"
+shaderc = "^0.7"
+legion = { version = "^0.3" }
+log = "0.4.0"
+winit = "^0.21"
+nalgebra-glm = "^0.6"
diff --git a/stockton-render/src/draw/camera.rs b/stockton-passes/src/camera.rs
index 62784de..49cce59 100644
--- a/stockton-render/src/draw/camera.rs
+++ b/stockton-passes/src/camera.rs
@@ -7,9 +7,9 @@ use stockton_types::{
Vector3,
};
-use crate::Renderer;
+use stockton_render::Renderer;
-use super::DrawPass;
+use stockton_render::draw_passes::DrawPass;
fn euler_to_direction(euler: &Vector3) -> Vector3 {
let pitch = euler.x;
diff --git a/stockton-render/src/draw/data/stockton.frag b/stockton-passes/src/data/3d.frag
index 336d9fe..336d9fe 100644
--- a/stockton-render/src/draw/data/stockton.frag
+++ b/stockton-passes/src/data/3d.frag
diff --git a/stockton-render/src/draw/data/stockton.vert b/stockton-passes/src/data/3d.vert
index aaee1a5..aaee1a5 100644
--- a/stockton-render/src/draw/data/stockton.vert
+++ b/stockton-passes/src/data/3d.vert
diff --git a/stockton-render/src/draw/ui/data/stockton.frag b/stockton-passes/src/data/ui.frag
index c30c99e..c30c99e 100644
--- a/stockton-render/src/draw/ui/data/stockton.frag
+++ b/stockton-passes/src/data/ui.frag
diff --git a/stockton-render/src/draw/ui/data/stockton.vert b/stockton-passes/src/data/ui.vert
index 8912e96..8912e96 100644
--- a/stockton-render/src/draw/ui/data/stockton.vert
+++ b/stockton-passes/src/data/ui.vert
diff --git a/stockton-render/src/draw/draw_passes/level.rs b/stockton-passes/src/level.rs
index 682c775..cd3ce6a 100644
--- a/stockton-render/src/draw/draw_passes/level.rs
+++ b/stockton-passes/src/level.rs
@@ -1,27 +1,5 @@
//! Minimal code for drawing any level, based on traits from stockton-levels
-use super::{util::TargetSpecificResources, DrawPass, IntoDrawPass};
-use crate::{
- draw::{
- buffers::{
- draw_buffers::{DrawBuffers, INITIAL_INDEX_SIZE, INITIAL_VERT_SIZE},
- DedicatedLoadedImage, ModifiableBuffer,
- },
- builders::{
- pipeline::{
- CompletePipeline, PipelineSpecBuilder, VertexBufferSpec,
- VertexPrimitiveAssemblerSpec,
- },
- renderpass::RenderpassSpec,
- shader::ShaderDesc,
- },
- queue_negotiator::QueueNegotiator,
- target::SwapchainProperties,
- texture::{resolver::TextureResolver, TexLoadQueue, TextureLoadConfig, TextureRepo},
- },
- error::{EnvironmentError, LevelError, LockPoisoned},
- types::*,
-};
use hal::{
buffer::SubRange,
command::{ClearColor, ClearDepthStencil, ClearValue, RenderAttachmentInfo, SubpassContents},
@@ -42,6 +20,21 @@ use stockton_levels::{
features::MinRenderFeatures,
parts::{data::Geometry, IsFace},
};
+use stockton_render::{
+ buffers::{
+ DedicatedLoadedImage, DrawBuffers, ModifiableBuffer, INITIAL_INDEX_SIZE, INITIAL_VERT_SIZE,
+ },
+ builders::{
+ CompletePipeline, PipelineSpecBuilder, RenderpassSpec, ShaderDesc, VertexBufferSpec,
+ VertexPrimitiveAssemblerSpec,
+ },
+ context::RenderingContext,
+ draw_passes::{util::TargetSpecificResources, DrawPass, IntoDrawPass},
+ error::{EnvironmentError, LevelError, LockPoisoned},
+ queue_negotiator::QueueNegotiator,
+ texture::{resolver::TextureResolver, TexLoadQueue, TextureLoadConfig, TextureRepo},
+ types::*,
+};
use stockton_types::{
components::{CameraSettings, CameraVPMatrix, Transform},
*,
@@ -82,7 +75,7 @@ where
&mut self,
session: &Session,
img_view: &ImageViewT,
- cmd_buffer: &mut crate::types::CommandBufferT,
+ cmd_buffer: &mut CommandBufferT,
) -> anyhow::Result<()> {
// We might have loaded more textures
self.repo.process_responses();
@@ -245,9 +238,9 @@ where
Ok(())
}
- fn deactivate(self, device_lock: &mut Arc<RwLock<DeviceT>>) -> Result<()> {
+ fn deactivate(self, context: &mut RenderingContext) -> Result<()> {
unsafe {
- let mut device = device_lock.write().map_err(|_| LockPoisoned::Device)?;
+ let mut device = context.device().write().map_err(|_| LockPoisoned::Device)?;
self.pipeline.deactivate(&mut device);
self.draw_buffers.deactivate(&mut device);
for fb in self.framebuffers.dissolve() {
@@ -257,10 +250,18 @@ where
db.deactivate(&mut device);
}
}
- self.repo.deactivate(device_lock);
+ self.repo.deactivate(context.device());
Ok(())
}
+
+ fn handle_surface_change(
+ &mut self,
+ _session: &Session,
+ _context: &mut RenderingContext,
+ ) -> Result<()> {
+ todo!()
+ }
}
pub struct LevelDrawPassConfig<R> {
@@ -275,11 +276,8 @@ where
{
fn init(
self,
- _session: &Session,
- adapter: &Adapter,
- device_lock: Arc<RwLock<DeviceT>>,
- queue_negotiator: &mut QueueNegotiator,
- swapchain_properties: &SwapchainProperties,
+ _session: &mut Session,
+ context: &mut RenderingContext,
) -> Result<LevelDrawPass<'a, M>> {
let spec = PipelineSpecBuilder::default()
.rasterizer(Rasterizer {
@@ -323,19 +321,19 @@ where
}],
))
.shader_vertex(ShaderDesc {
- source: include_str!("../data/stockton.vert").to_string(),
+ source: include_str!("./data/3d.vert").to_string(),
entry: "main".to_string(),
kind: ShaderKind::Vertex,
})
.shader_fragment(ShaderDesc {
- source: include_str!("../data/stockton.frag").to_string(),
+ source: include_str!("./data/3d.frag").to_string(),
entry: "main".to_string(),
kind: ShaderKind::Fragment,
})
.push_constants(vec![(ShaderStageFlags::VERTEX, 0..64)])
.renderpass(RenderpassSpec {
colors: vec![Attachment {
- format: Some(swapchain_properties.format),
+ format: Some(context.target_chain().properties().format),
samples: 1,
ops: AttachmentOps::new(AttachmentLoadOp::Clear, AttachmentStoreOp::Store),
stencil_ops: AttachmentOps::new(
@@ -345,7 +343,7 @@ where
layouts: Layout::ColorAttachmentOptimal..Layout::ColorAttachmentOptimal,
}],
depth: Some(Attachment {
- format: Some(swapchain_properties.depth_format),
+ format: Some(context.target_chain().properties().depth_format),
samples: 1,
ops: AttachmentOps::new(AttachmentLoadOp::Clear, AttachmentStoreOp::DontCare),
stencil_ops: AttachmentOps::new(
@@ -362,16 +360,18 @@ where
.context("Error building pipeline")?;
let repo = TextureRepo::new(
- device_lock.clone(),
- queue_negotiator
+ context.device().clone(),
+ context
+ .queue_negotiator_mut()
.family::<TexLoadQueue>()
.ok_or(EnvironmentError::NoSuitableFamilies)
.context("Error finding texture queue")?,
- queue_negotiator
+ context
+ .queue_negotiator_mut()
.get_queue::<TexLoadQueue>()
.ok_or(EnvironmentError::NoQueues)
.context("Error finding texture queue")?,
- adapter,
+ context.adapter(),
TextureLoadConfig {
resolver: self.tex_resolver,
filter: Filter::Linear,
@@ -381,22 +381,22 @@ where
.context("Error creating texture repo")?;
let (draw_buffers, pipeline, framebuffers, depth_buffers) = {
- let mut device = device_lock.write().map_err(|_| LockPoisoned::Device)?;
- let draw_buffers =
- DrawBuffers::new(&mut device, adapter).context("Error creating draw buffers")?;
+ let mut device = context.device().write().map_err(|_| LockPoisoned::Device)?;
+ let draw_buffers = DrawBuffers::new(&mut device, context.adapter())
+ .context("Error creating draw buffers")?;
let pipeline = spec
.build(
&mut device,
- swapchain_properties.extent,
- swapchain_properties,
+ context.target_chain().properties().extent,
+ context.target_chain().properties(),
once(&*repo.get_ds_layout()?),
)
.context("Error building pipeline")?;
- let fat = swapchain_properties.framebuffer_attachment();
+ let fat = context.target_chain().properties().framebuffer_attachment();
let dat = FramebufferAttachment {
usage: Usage::DEPTH_STENCIL_ATTACHMENT,
- format: swapchain_properties.depth_format,
+ format: context.target_chain().properties().depth_format,
view_caps: ViewCapabilities::empty(),
};
let framebuffers = TargetSpecificResources::new(
@@ -404,17 +404,17 @@ where
Ok(device.create_framebuffer(
&pipeline.renderpass,
IntoIter::new([fat.clone(), dat.clone()]),
- swapchain_properties.extent,
+ context.target_chain().properties().extent,
)?)
},
- swapchain_properties.image_count as usize,
+ context.target_chain().properties().image_count as usize,
)?;
let depth_buffers = TargetSpecificResources::new(
|| {
DedicatedLoadedImage::new(
&mut device,
- adapter,
- swapchain_properties.depth_format,
+ context.adapter(),
+ context.target_chain().properties().depth_format,
Usage::DEPTH_STENCIL_ATTACHMENT,
SubresourceRange {
aspects: Aspects::DEPTH,
@@ -423,12 +423,12 @@ where
layer_start: 0,
layer_count: Some(1),
},
- swapchain_properties.extent.width as usize,
- swapchain_properties.extent.height as usize,
+ context.target_chain().properties().extent.width as usize,
+ context.target_chain().properties().extent.height as usize,
)
.context("Error creating depth buffer")
},
- swapchain_properties.image_count as usize,
+ context.target_chain().properties().image_count as usize,
)?;
(draw_buffers, pipeline, framebuffers, depth_buffers)
diff --git a/stockton-passes/src/lib.rs b/stockton-passes/src/lib.rs
new file mode 100644
index 0000000..e3e5bf8
--- /dev/null
+++ b/stockton-passes/src/lib.rs
@@ -0,0 +1,9 @@
+#[macro_use]
+extern crate legion;
+extern crate gfx_hal as hal;
+extern crate nalgebra_glm as na;
+
+pub mod camera;
+pub mod level;
+pub mod ui;
+pub mod window;
diff --git a/stockton-render/src/draw/draw_passes/ui.rs b/stockton-passes/src/ui.rs
index 5e6c68e..4b4e1c2 100644
--- a/stockton-render/src/draw/draw_passes/ui.rs
+++ b/stockton-passes/src/ui.rs
@@ -1,26 +1,5 @@
//! Minimal code for drawing any level, based on traits from stockton-levels
-use super::{util::TargetSpecificResources, DrawPass, IntoDrawPass};
-use crate::{
- draw::{
- buffers::{draw_buffers::DrawBuffers, ModifiableBuffer},
- builders::{
- pipeline::{
- CompletePipeline, PipelineSpecBuilder, VertexBufferSpec,
- VertexPrimitiveAssemblerSpec,
- },
- renderpass::RenderpassSpec,
- shader::ShaderDesc,
- },
- queue_negotiator::QueueNegotiator,
- target::SwapchainProperties,
- texture::{TexLoadQueue, TextureLoadConfig, TextureRepo},
- ui::UiTextures,
- },
- error::{EnvironmentError, LockPoisoned},
- types::*,
- UiState,
-};
use egui::{ClippedMesh, TextureId};
use hal::{
buffer::SubRange,
@@ -35,16 +14,33 @@ use hal::{
},
};
use shaderc::ShaderKind;
+use stockton_render::{
+ buffers::{DrawBuffers, ModifiableBuffer},
+ builders::{
+ CompletePipeline, PipelineSpecBuilder, RenderpassSpec, ShaderDesc, VertexBufferSpec,
+ VertexPrimitiveAssemblerSpec,
+ },
+ context::RenderingContext,
+ draw_passes::{util::TargetSpecificResources, DrawPass, IntoDrawPass},
+ error::{EnvironmentError, LockPoisoned},
+ queue_negotiator::QueueNegotiator,
+ texture::{TexLoadQueue, TextureLoadConfig, TextureRepo},
+ types::*,
+};
use stockton_types::{Session, Vector2};
use std::{
array::IntoIter,
convert::TryInto,
iter::{empty, once},
- sync::{Arc, RwLock},
};
use anyhow::{anyhow, Context, Result};
+use egui::{CtxRef, Texture};
+use std::sync::Arc;
+use stockton_render::texture::{resolver::TextureResolver, LoadableImage};
+
+use crate::window::UiState;
#[derive(Debug)]
pub struct UiPoint(pub Vector2, pub Vector2, pub [f32; 4]);
@@ -63,7 +59,7 @@ impl<'a> DrawPass for UiDrawPass<'a> {
&mut self,
session: &Session,
img_view: &ImageViewT,
- cmd_buffer: &mut crate::types::CommandBufferT,
+ cmd_buffer: &mut CommandBufferT,
) -> anyhow::Result<()> {
// We might have loaded more textures
self.repo.process_responses();
@@ -187,30 +183,31 @@ impl<'a> DrawPass for UiDrawPass<'a> {
Ok(())
}
- fn deactivate(self, device_lock: &mut Arc<RwLock<DeviceT>>) -> Result<()> {
+ fn deactivate(self, context: &mut RenderingContext) -> Result<()> {
unsafe {
- let mut device = device_lock.write().map_err(|_| LockPoisoned::Device)?;
+ let mut device = context.device().write().map_err(|_| LockPoisoned::Device)?;
self.pipeline.deactivate(&mut device);
self.draw_buffers.deactivate(&mut device);
for fb in self.framebuffers.dissolve() {
device.destroy_framebuffer(fb);
}
}
- self.repo.deactivate(device_lock);
+ self.repo.deactivate(context.device());
Ok(())
}
+
+ fn handle_surface_change(
+ &mut self,
+ _session: &Session,
+ _context: &mut RenderingContext,
+ ) -> Result<()> {
+ todo!()
+ }
}
impl<'a> IntoDrawPass<UiDrawPass<'a>> for () {
- fn init(
- self,
- session: &Session,
- adapter: &Adapter,
- device_lock: Arc<RwLock<DeviceT>>,
- queue_negotiator: &mut QueueNegotiator,
- swapchain_properties: &SwapchainProperties,
- ) -> Result<UiDrawPass<'a>> {
+ fn init(self, session: &mut Session, context: &mut RenderingContext) -> Result<UiDrawPass<'a>> {
let spec = PipelineSpecBuilder::default()
.rasterizer(Rasterizer {
polygon_mode: PolygonMode::Fill,
@@ -250,19 +247,19 @@ impl<'a> IntoDrawPass<UiDrawPass<'a>> for () {
}],
))
.shader_vertex(ShaderDesc {
- source: include_str!("../ui/data/stockton.vert").to_string(),
+ source: include_str!("./data/ui.vert").to_string(),
entry: "main".to_string(),
kind: ShaderKind::Vertex,
})
.shader_fragment(ShaderDesc {
- source: include_str!("../ui/data/stockton.frag").to_string(),
+ source: include_str!("./data/ui.frag").to_string(),
entry: "main".to_string(),
kind: ShaderKind::Fragment,
})
.push_constants(vec![(ShaderStageFlags::VERTEX, 0..8)])
.renderpass(RenderpassSpec {
colors: vec![Attachment {
- format: Some(swapchain_properties.format),
+ format: Some(context.target_chain().properties().format),
samples: 1,
ops: AttachmentOps::new(AttachmentLoadOp::Load, AttachmentStoreOp::Store),
stencil_ops: AttachmentOps::new(
@@ -282,16 +279,18 @@ impl<'a> IntoDrawPass<UiDrawPass<'a>> for () {
let ui: &mut UiState = &mut session.resources.get_mut::<UiState>().unwrap();
let repo = TextureRepo::new(
- device_lock.clone(),
- queue_negotiator
+ context.device().clone(),
+ context
+ .queue_negotiator_mut()
.family::<TexLoadQueue>()
.ok_or(EnvironmentError::NoSuitableFamilies)
.context("Error finding texture queue")?,
- queue_negotiator
+ context
+ .queue_negotiator_mut()
.get_queue::<TexLoadQueue>()
.ok_or(EnvironmentError::NoQueues)
.context("Error finding texture queue")?,
- adapter,
+ context.adapter(),
TextureLoadConfig {
resolver: UiTextures::new(ui.ctx().clone()),
filter: hal::image::Filter::Linear,
@@ -301,28 +300,28 @@ impl<'a> IntoDrawPass<UiDrawPass<'a>> for () {
.context("Error creating texture repo")?;
let (draw_buffers, pipeline, framebuffers) = {
- let mut device = device_lock.write().map_err(|_| LockPoisoned::Device)?;
- let draw_buffers =
- DrawBuffers::new(&mut device, adapter).context("Error creating draw buffers")?;
+ let mut device = context.device().write().map_err(|_| LockPoisoned::Device)?;
+ let draw_buffers = DrawBuffers::new(&mut device, context.adapter())
+ .context("Error creating draw buffers")?;
let pipeline = spec
.build(
&mut device,
- swapchain_properties.extent,
- swapchain_properties,
+ context.target_chain().properties().extent,
+ context.target_chain().properties(),
once(&*repo.get_ds_layout()?),
)
.context("Error building pipeline")?;
- let fat = swapchain_properties.framebuffer_attachment();
+ let fat = context.target_chain().properties().framebuffer_attachment();
let framebuffers = TargetSpecificResources::new(
|| unsafe {
Ok(device.create_framebuffer(
&pipeline.renderpass,
IntoIter::new([fat.clone()]),
- swapchain_properties.extent,
+ context.target_chain().properties().extent,
)?)
},
- swapchain_properties.image_count as usize,
+ context.target_chain().properties().image_count as usize,
)?;
(draw_buffers, pipeline, framebuffers)
};
@@ -346,3 +345,54 @@ impl<'a> IntoDrawPass<UiDrawPass<'a>> for () {
.ok_or(EnvironmentError::NoSuitableFamilies)?])
}
}
+
+pub struct UiTexture(Arc<Texture>);
+
+pub struct UiTextures {
+ ctx: CtxRef,
+}
+
+impl TextureResolver for UiTextures {
+ type Image = UiTexture;
+ fn resolve(&mut self, tex: u32) -> Option<Self::Image> {
+ if tex == 0 {
+ Some(UiTexture(self.ctx.texture()))
+ } else {
+ None
+ }
+ }
+}
+
+impl UiTextures {
+ pub fn new(ctx: CtxRef) -> Self {
+ UiTextures { ctx }
+ }
+}
+
+impl LoadableImage for UiTexture {
+ fn width(&self) -> u32 {
+ self.0.width as u32
+ }
+ fn height(&self) -> u32 {
+ self.0.height as u32
+ }
+ fn copy_row(&self, y: u32, ptr: *mut u8) {
+ let row_size = self.0.width as u32;
+ let pixels = &self.0.pixels[(y * row_size) as usize..((y + 1) * row_size) as usize];
+
+ for (i, x) in pixels.iter().enumerate() {
+ unsafe {
+ *ptr.offset(i as isize * 4) = 255;
+ *ptr.offset((i as isize * 4) + 1) = 255;
+ *ptr.offset((i as isize * 4) + 2) = 255;
+ *ptr.offset((i as isize * 4) + 3) = *x;
+ }
+ }
+ }
+
+ unsafe fn copy_into(&self, ptr: *mut u8, row_size: usize) {
+ for y in 0..self.height() {
+ self.copy_row(y, ptr.offset((row_size * y as usize).try_into().unwrap()));
+ }
+ }
+}
diff --git a/stockton-render/src/window.rs b/stockton-passes/src/window.rs
index 87f3182..c806fa0 100644
--- a/stockton-render/src/window.rs
+++ b/stockton-passes/src/window.rs
@@ -1,11 +1,16 @@
-use crate::{error::full_error_display, DrawPass, Renderer};
+use std::sync::mpsc::channel;
+use std::sync::mpsc::Receiver;
+use std::sync::mpsc::Sender;
+use std::sync::Arc;
+use std::sync::RwLock;
+
use egui::{Modifiers, Rect, Vec2};
use legion::systems::Runnable;
use log::debug;
+use stockton_render::{draw_passes::DrawPass, Renderer};
use egui::{CtxRef, Event, Output, Pos2, RawInput};
use epaint::ClippedShape;
-use log::error;
use stockton_input::{Action as KBAction, InputManager, Mouse};
use winit::event::{
@@ -90,9 +95,9 @@ impl UiState {
}
pub fn populate_initial_state<'a, T: DrawPass>(&mut self, renderer: &Renderer<T>) {
- let props = &renderer.context.target_chain.properties;
+ let props = &renderer.context().target_chain().properties();
self.set_dimensions(props.extent.width, props.extent.height);
- self.set_pixels_per_point(Some(renderer.context.pixels_per_point));
+ self.set_pixels_per_point(Some(renderer.context().pixels_per_point()));
debug!("{:?}", self.raw_input);
}
@@ -171,10 +176,28 @@ impl UiState {
}
}
+pub struct WindowFlow {
+ window_events: Receiver<WindowEvent>,
+ update_control_flow: Arc<RwLock<ControlFlow>>,
+}
+
+impl WindowFlow {
+ pub fn new(update_control_flow: Arc<RwLock<ControlFlow>>) -> (Self, Sender<WindowEvent>) {
+ let (tx, rx) = channel();
+ (
+ Self {
+ window_events: rx,
+ update_control_flow,
+ },
+ tx,
+ )
+ }
+}
+
#[system]
/// A system to process the window events sent to renderer by the winit event loop.
pub fn _process_window_events<T: 'static + InputManager, DP: 'static + DrawPass>(
- #[resource] renderer: &mut Renderer<DP>,
+ #[resource] window_channel: &mut WindowFlow,
#[resource] manager: &mut T,
#[resource] mouse: &mut Mouse,
#[resource] ui_state: &mut UiState,
@@ -183,16 +206,13 @@ pub fn _process_window_events<T: 'static + InputManager, DP: 'static + DrawPass>
let mut actions_buf_cursor = 0;
let mut mouse_delta = mouse.abs;
- while let Ok(event) = renderer.window_events.try_recv() {
+ while let Ok(event) = window_channel.window_events.try_recv() {
match event {
WindowEvent::SizeChanged(w, h) => {
- if let Err(err) = renderer.resize() {
- error!("{}", full_error_display(err));
- };
ui_state.set_dimensions(w, h);
}
WindowEvent::CloseRequested => {
- let mut flow = renderer.update_control_flow.write().unwrap();
+ let mut flow = window_channel.update_control_flow.write().unwrap();
// TODO: Let everything know this is our last frame
*flow = ControlFlow::Exit;
}
diff --git a/stockton-render/Cargo.toml b/stockton-render/Cargo.toml
index 7f93b3b..cb056b4 100644
--- a/stockton-render/Cargo.toml
+++ b/stockton-render/Cargo.toml
@@ -16,8 +16,6 @@ shaderc = "^0.7"
log = "0.4.0"
image = "0.23.11"
legion = { version = "^0.3" }
-egui = "^0.12"
-epaint = "^0.12"
rendy-memory = { path = "../rendy-memory" }
rendy-descriptor = { path = "../rendy-descriptor" }
anyhow = "1.0.40"
diff --git a/stockton-render/src/draw/buffers/dedicated_image.rs b/stockton-render/src/buffers/dedicated_image.rs
index 878d304..bf49a38 100644
--- a/stockton-render/src/draw/buffers/dedicated_image.rs
+++ b/stockton-render/src/buffers/dedicated_image.rs
@@ -1,6 +1,6 @@
//! A dedicated image. Used for depth buffers.
-use crate::draw::texture::PIXEL_SIZE;
+use crate::texture::PIXEL_SIZE;
use crate::types::*;
use std::mem::ManuallyDrop;
diff --git a/stockton-render/src/draw/buffers/draw_buffers.rs b/stockton-render/src/buffers/draw_buffers.rs
index 5baec92..5baec92 100644
--- a/stockton-render/src/draw/buffers/draw_buffers.rs
+++ b/stockton-render/src/buffers/draw_buffers.rs
diff --git a/stockton-render/src/draw/buffers/mod.rs b/stockton-render/src/buffers/mod.rs
index dc7df65..82ca62a 100644
--- a/stockton-render/src/draw/buffers/mod.rs
+++ b/stockton-render/src/buffers/mod.rs
@@ -11,13 +11,13 @@ use hal::{
MemoryTypeId,
};
-pub mod dedicated_image;
-pub mod draw_buffers;
-pub mod staged;
+mod dedicated_image;
+mod draw_buffers;
+mod staged;
-pub use dedicated_image::DedicatedLoadedImage;
-pub use draw_buffers::DrawBuffers;
-pub use staged::StagedBuffer;
+pub use dedicated_image::*;
+pub use draw_buffers::*;
+pub use staged::*;
/// Create a buffer of the given specifications, allocating more device memory.
// TODO: Use a different memory allocator?
diff --git a/stockton-render/src/draw/buffers/staged.rs b/stockton-render/src/buffers/staged.rs
index 71b5204..71b5204 100644
--- a/stockton-render/src/draw/buffers/staged.rs
+++ b/stockton-render/src/buffers/staged.rs
diff --git a/stockton-render/src/builders/mod.rs b/stockton-render/src/builders/mod.rs
new file mode 100644
index 0000000..97b47a0
--- /dev/null
+++ b/stockton-render/src/builders/mod.rs
@@ -0,0 +1,7 @@
+mod pipeline;
+mod renderpass;
+mod shader;
+
+pub use pipeline::*;
+pub use renderpass::*;
+pub use shader::*;
diff --git a/stockton-render/src/draw/builders/pipeline.rs b/stockton-render/src/builders/pipeline.rs
index 0c06774..25a4dc6 100644
--- a/stockton-render/src/draw/builders/pipeline.rs
+++ b/stockton-render/src/builders/pipeline.rs
@@ -1,5 +1,5 @@
use super::{renderpass::RenderpassSpec, shader::ShaderDesc};
-use crate::{draw::target::SwapchainProperties, error::EnvironmentError, types::*};
+use crate::{error::EnvironmentError, target::SwapchainProperties, types::*};
use std::{mem::ManuallyDrop, ops::Range};
@@ -241,23 +241,23 @@ impl PipelineSpec {
pub struct CompletePipeline {
/// Our main render pass
- pub(crate) renderpass: ManuallyDrop<RenderPassT>,
+ pub renderpass: ManuallyDrop<RenderPassT>,
/// The layout of our main graphics pipeline
- pub(crate) pipeline_layout: ManuallyDrop<PipelineLayoutT>,
+ pub pipeline_layout: ManuallyDrop<PipelineLayoutT>,
/// Our main graphics pipeline
- pub(crate) pipeline: ManuallyDrop<GraphicsPipelineT>,
+ pub pipeline: ManuallyDrop<GraphicsPipelineT>,
/// The vertex shader module
- pub(crate) vs_module: ManuallyDrop<ShaderModuleT>,
+ pub vs_module: ManuallyDrop<ShaderModuleT>,
/// The fragment shader module
- pub(crate) fs_module: Option<ShaderModuleT>,
- pub(crate) gm_module: Option<ShaderModuleT>,
- pub(crate) ts_module: Option<(ShaderModuleT, ShaderModuleT)>,
+ pub fs_module: Option<ShaderModuleT>,
+ pub gm_module: Option<ShaderModuleT>,
+ pub ts_module: Option<(ShaderModuleT, ShaderModuleT)>,
- pub(crate) render_area: Rect,
+ pub render_area: Rect,
}
impl CompletePipeline {
diff --git a/stockton-render/src/draw/builders/renderpass.rs b/stockton-render/src/builders/renderpass.rs
index 43f0eb2..43f0eb2 100644
--- a/stockton-render/src/draw/builders/renderpass.rs
+++ b/stockton-render/src/builders/renderpass.rs
diff --git a/stockton-render/src/draw/builders/shader.rs b/stockton-render/src/builders/shader.rs
index fde185d..fde185d 100644
--- a/stockton-render/src/draw/builders/shader.rs
+++ b/stockton-render/src/builders/shader.rs
diff --git a/stockton-render/src/draw/context.rs b/stockton-render/src/context.rs
index 65dcff6..3985c47 100644
--- a/stockton-render/src/draw/context.rs
+++ b/stockton-render/src/context.rs
@@ -28,7 +28,7 @@ use stockton_types::Session;
/// Contains all the hal related stuff.
/// In the end, this takes in a depth-sorted list of faces and a map file and renders them.
// TODO: Settings for clear colour, buffer sizes, etc
-pub struct RenderingContext<DP> {
+pub struct RenderingContext {
// Parents for most of these things
/// Vulkan Instance
instance: ManuallyDrop<back::Instance>,
@@ -40,28 +40,23 @@ pub struct RenderingContext<DP> {
adapter: Adapter,
/// Swapchain and stuff
- pub(crate) target_chain: ManuallyDrop<TargetChain>,
+ target_chain: ManuallyDrop<TargetChain>,
// Command pool and buffers
/// The command pool used for our buffers
cmd_pool: ManuallyDrop<CommandPoolT>,
+ queue_negotiator: QueueNegotiator,
+
/// The queue to use for drawing
queue: Arc<RwLock<QueueT>>,
- /// Deals with drawing logic, and holds any data required for drawing.
- draw_pass: ManuallyDrop<DP>,
-
- pub(crate) pixels_per_point: f32,
+ pixels_per_point: f32,
}
-impl<DP: DrawPass> RenderingContext<DP> {
+impl RenderingContext {
/// Create a new RenderingContext for the given window.
- pub fn new<IDP: IntoDrawPass<DP>>(
- window: &Window,
- session: &Session,
- idp: IDP,
- ) -> Result<Self> {
+ pub fn new<IDP: IntoDrawPass<DP>, DP: DrawPass>(window: &Window) -> Result<Self> {
// Create surface
let (instance, surface, mut adapters) = unsafe {
let instance =
@@ -125,17 +120,6 @@ impl<DP: DrawPass> RenderingContext<DP> {
let swapchain_properties = SwapchainProperties::find_best(&adapter, &surface)
.context("Error getting properties for swapchain")?;
- // Draw pass
- let dp = idp
- .init(
- session,
- &adapter,
- device_lock.clone(),
- &mut queue_negotiator,
- &swapchain_properties,
- )
- .context("Error initialising draw pass")?;
-
// Lock device
let mut device = device_lock
.write()
@@ -168,18 +152,20 @@ impl<DP: DrawPass> RenderingContext<DP> {
// Unlock device
drop(device);
+ let queue = queue_negotiator
+ .get_queue::<DrawQueue>()
+ .ok_or(EnvironmentError::NoQueues)
+ .context("Error getting draw queue")?;
+
Ok(RenderingContext {
instance: ManuallyDrop::new(instance),
device: device_lock,
adapter,
- queue: queue_negotiator
- .get_queue::<DrawQueue>()
- .ok_or(EnvironmentError::NoQueues)
- .context("Error getting draw queue")?,
+ queue_negotiator,
+ queue,
- draw_pass: ManuallyDrop::new(dp),
target_chain: ManuallyDrop::new(target_chain),
cmd_pool: ManuallyDrop::new(cmd_pool),
@@ -208,8 +194,6 @@ impl<DP: DrawPass> RenderingContext<DP> {
let properties = SwapchainProperties::find_best(&self.adapter, &surface)
.context("Error finding best swapchain properties")?;
- // TODO: Notify draw passes
-
self.target_chain = ManuallyDrop::new(
TargetChain::new(
&mut device,
@@ -224,7 +208,7 @@ impl<DP: DrawPass> RenderingContext<DP> {
}
/// Draw onto the next frame of the swapchain
- pub fn draw_next_frame(&mut self, session: &Session) -> Result<()> {
+ pub fn draw_next_frame<DP: DrawPass>(&mut self, session: &Session, dp: &mut DP) -> Result<()> {
let mut device = self
.device
.write()
@@ -238,14 +222,39 @@ impl<DP: DrawPass> RenderingContext<DP> {
// Level draw pass
self.target_chain
- .do_draw_with(&mut device, &mut queue, &mut *self.draw_pass, session)
+ .do_draw_with(&mut device, &mut queue, dp, session)
.context("Error preparing next target")?;
Ok(())
}
+
+ /// Get a reference to the rendering context's pixels per point.
+ pub fn pixels_per_point(&self) -> f32 {
+ self.pixels_per_point
+ }
+
+ /// Get a reference to the rendering context's device.
+ pub fn device(&self) -> &Arc<RwLock<DeviceT>> {
+ &self.device
+ }
+
+ /// Get a reference to the rendering context's target chain.
+ pub fn target_chain(&self) -> &TargetChain {
+ &self.target_chain
+ }
+
+ /// Get a reference to the rendering context's adapter.
+ pub fn adapter(&self) -> &Adapter {
+ &self.adapter
+ }
+
+ /// Get a mutable reference to the rendering context's queue negotiator.
+ pub fn queue_negotiator_mut(&mut self) -> &mut QueueNegotiator {
+ &mut self.queue_negotiator
+ }
}
-impl<DP> core::ops::Drop for RenderingContext<DP> {
+impl core::ops::Drop for RenderingContext {
fn drop(&mut self) {
{
self.device.write().unwrap().wait_idle().unwrap();
diff --git a/stockton-render/src/culling.rs b/stockton-render/src/culling.rs
deleted file mode 100644
index c10605f..0000000
--- a/stockton-render/src/culling.rs
+++ /dev/null
@@ -1,70 +0,0 @@
-//! Functions for figuring out what to render
-#![allow(dead_code)]
-
-use stockton_levels::prelude::*;
-use stockton_levels::parts::tree::{BspNode, BspNodeValue};
-use stockton_types::Vector3;
-
-/// Get the visible faces according to visdata and frustum culling
-// TODO: Write this. For now, just render all faces
-pub fn get_visible_faces<X: CoordSystem, T: MinBspFeatures<X>>(pos: Vector3, file: &T) -> Vec<u32> {
- let vis_cluster = get_cluster_id(pos, file);
-
- let mut visible = Vec::with_capacity(file.faces_len() as usize);
- if (vis_cluster & 0x80000000) != 0 {
- // Negative = Invalid camera position
- // For now just render everything
- for face_idx in 0..file.faces_len() {
- visible.push(face_idx);
- }
-
- return visible;
- }
-
- walk_bsp_tree(file.get_bsp_root(), vis_cluster, &mut visible, file);
-
- visible
-}
-
-pub fn walk_bsp_tree<X: CoordSystem, T: MinBspFeatures<X>>(
- node: &BspNode,
- vis_cluster: u32,
- visible_faces: &mut Vec<u32>,
- file: &T,
-) {
- if let BspNodeValue::Children(front, back) = &node.value {
- walk_bsp_tree(back, vis_cluster, visible_faces, file);
- walk_bsp_tree(front, vis_cluster, visible_faces, file);
- } else if let BspNodeValue::Leaf(leaf) = &node.value {
- if (leaf.cluster_id & 0x80000000) != 0 {
- // Negative means invalid leaf
- return;
- } else if file.cluster_visible_from(vis_cluster, leaf.cluster_id) {
- for face_idx in leaf.faces_idx.iter() {
- // TODO: Culling or something
- visible_faces.push(*face_idx);
- }
- }
- }
-}
-
-/// Get the viscluster pos lies in
-fn get_cluster_id<X: CoordSystem, T: MinBspFeatures<X>>(pos: Vector3, file: &T) -> u32 {
- let mut node = file.get_bsp_root();
- while let BspNodeValue::Children(front, back) = &node.value {
- let plane = file.get_plane(node.plane_idx);
- let dist = plane.normal.dot(&pos) - plane.dist;
-
- if dist >= 0.0 {
- node = front;
- } else {
- node = back;
- }
- }
-
- if let BspNodeValue::Leaf(leaf) = &node.value {
- leaf.cluster_id
- } else {
- panic!("should have had a leaf but didn't");
- }
-}
diff --git a/stockton-render/src/draw/builders/mod.rs b/stockton-render/src/draw/builders/mod.rs
deleted file mode 100644
index 002c09f..0000000
--- a/stockton-render/src/draw/builders/mod.rs
+++ /dev/null
@@ -1,3 +0,0 @@
-pub mod pipeline;
-pub mod renderpass;
-pub mod shader;
diff --git a/stockton-render/src/draw/mod.rs b/stockton-render/src/draw/mod.rs
deleted file mode 100644
index 4ba38cd..0000000
--- a/stockton-render/src/draw/mod.rs
+++ /dev/null
@@ -1,17 +0,0 @@
-//! Given 3D points and some camera information, renders to the screen.
-
-pub mod target;
-
-mod buffers;
-mod builders;
-pub mod camera;
-mod context;
-pub mod draw_passes;
-mod queue_negotiator;
-pub mod texture;
-mod ui;
-mod utils;
-
-pub use self::context::RenderingContext;
-
-pub use self::draw_passes::*;
diff --git a/stockton-render/src/draw/ui/mod.rs b/stockton-render/src/draw/ui/mod.rs
deleted file mode 100644
index 1b52753..0000000
--- a/stockton-render/src/draw/ui/mod.rs
+++ /dev/null
@@ -1,52 +0,0 @@
-use crate::draw::texture::{resolver::TextureResolver, LoadableImage};
-use egui::{CtxRef, Texture};
-use std::{convert::TryInto, sync::Arc};
-
-pub struct UiTextures {
- ctx: CtxRef,
-}
-
-impl TextureResolver for UiTextures {
- type Image = Arc<Texture>;
- fn resolve(&mut self, tex: u32) -> Option<Self::Image> {
- if tex == 0 {
- Some(self.ctx.texture())
- } else {
- None
- }
- }
-}
-
-impl UiTextures {
- pub fn new(ctx: CtxRef) -> Self {
- UiTextures { ctx }
- }
-}
-
-impl LoadableImage for Arc<Texture> {
- fn width(&self) -> u32 {
- self.width as u32
- }
- fn height(&self) -> u32 {
- self.height as u32
- }
- fn copy_row(&self, y: u32, ptr: *mut u8) {
- let row_size = self.width();
- let pixels = &self.pixels[(y * row_size) as usize..((y + 1) * row_size) as usize];
-
- for (i, x) in pixels.iter().enumerate() {
- unsafe {
- *ptr.offset(i as isize * 4) = 255;
- *ptr.offset((i as isize * 4) + 1) = 255;
- *ptr.offset((i as isize * 4) + 2) = 255;
- *ptr.offset((i as isize * 4) + 3) = *x;
- }
- }
- }
-
- unsafe fn copy_into(&self, ptr: *mut u8, row_size: usize) {
- for y in 0..self.height() {
- self.copy_row(y, ptr.offset((row_size * y as usize).try_into().unwrap()));
- }
- }
-}
diff --git a/stockton-render/src/draw/draw_passes/cons.rs b/stockton-render/src/draw_passes/cons.rs
index 3209806..ad94b1c 100644
--- a/stockton-render/src/draw/draw_passes/cons.rs
+++ b/stockton-render/src/draw_passes/cons.rs
@@ -1,10 +1,8 @@
//! Code for using multiple draw passes in place of just one
//! Note that this can be extended to an arbitrary amount of draw passes.
-use std::sync::{Arc, RwLock};
-
use super::{DrawPass, IntoDrawPass};
-use crate::types::*;
+use crate::{context::RenderingContext, queue_negotiator::QueueNegotiator, types::*};
use stockton_types::Session;
use anyhow::Result;
@@ -28,9 +26,18 @@ impl<A: DrawPass, B: DrawPass> DrawPass for ConsDrawPass<A, B> {
Ok(())
}
- fn deactivate(self, device: &mut Arc<RwLock<DeviceT>>) -> Result<()> {
- self.a.deactivate(device)?;
- self.b.deactivate(device)
+ fn deactivate(self, context: &mut RenderingContext) -> Result<()> {
+ self.a.deactivate(context)?;
+ self.b.deactivate(context)
+ }
+
+ fn handle_surface_change(
+ &mut self,
+ session: &Session,
+ context: &mut RenderingContext,
+ ) -> Result<()> {
+ self.a.handle_surface_change(session, context)?;
+ self.b.handle_surface_change(session, context)
}
}
@@ -39,33 +46,18 @@ impl<A: DrawPass, B: DrawPass, IA: IntoDrawPass<A>, IB: IntoDrawPass<B>>
{
fn init(
self,
- session: &Session,
- adapter: &Adapter,
- device: Arc<RwLock<DeviceT>>,
- queue_negotiator: &mut crate::draw::queue_negotiator::QueueNegotiator,
- swapchain_properties: &crate::draw::target::SwapchainProperties,
+ session: &mut Session,
+ context: &mut RenderingContext,
) -> Result<ConsDrawPass<A, B>> {
Ok(ConsDrawPass {
- a: self.0.init(
- session,
- adapter,
- device.clone(),
- queue_negotiator,
- swapchain_properties,
- )?,
- b: self.1.init(
- session,
- adapter,
- device,
- queue_negotiator,
- swapchain_properties,
- )?,
+ a: self.0.init(session, context)?,
+ b: self.1.init(session, context)?,
})
}
fn find_aux_queues<'a>(
adapter: &'a Adapter,
- queue_negotiator: &mut crate::draw::queue_negotiator::QueueNegotiator,
+ queue_negotiator: &mut QueueNegotiator,
) -> Result<Vec<(&'a QueueFamilyT, Vec<f32>)>> {
let mut v = IA::find_aux_queues(adapter, queue_negotiator)?;
v.extend(IB::find_aux_queues(adapter, queue_negotiator)?);
diff --git a/stockton-render/src/draw/draw_passes/mod.rs b/stockton-render/src/draw_passes/mod.rs
index 8d1d59b..a0dbba5 100644
--- a/stockton-render/src/draw/draw_passes/mod.rs
+++ b/stockton-render/src/draw_passes/mod.rs
@@ -1,20 +1,14 @@
//! Traits and common draw passes.
-use super::{queue_negotiator::QueueNegotiator, target::SwapchainProperties};
+use super::{queue_negotiator::QueueNegotiator, RenderingContext};
use crate::types::*;
use stockton_types::Session;
-use std::sync::{Arc, RwLock};
-
use anyhow::Result;
mod cons;
-mod level;
-mod ui;
pub mod util;
pub use cons::ConsDrawPass;
-pub use level::{LevelDrawPass, LevelDrawPassConfig};
-pub use ui::UiDrawPass;
/// One of several 'passes' that draw on each frame.
pub trait DrawPass {
@@ -27,20 +21,21 @@ pub trait DrawPass {
cmd_buffer: &mut CommandBufferT,
) -> Result<()>;
- fn deactivate(self, device: &mut Arc<RwLock<DeviceT>>) -> Result<()>;
+ /// Called just after the surface changes (probably a resize).
+ fn handle_surface_change(
+ &mut self,
+ session: &Session,
+ context: &mut RenderingContext,
+ ) -> Result<()>;
+
+ /// Deactivate any vulkan parts that need to be deactivated
+ fn deactivate(self, context: &mut RenderingContext) -> Result<()>;
}
/// A type that can be made into a specific draw pass type.
/// This allows extra data to be used in initialisation without the Renderer needing to worry about it.
-pub trait IntoDrawPass<O: DrawPass> {
- fn init(
- self,
- session: &Session,
- adapter: &Adapter,
- device: Arc<RwLock<DeviceT>>,
- queue_negotiator: &mut QueueNegotiator,
- swapchain_properties: &SwapchainProperties,
- ) -> Result<O>;
+pub trait IntoDrawPass<T: DrawPass> {
+ fn init(self, session: &mut Session, context: &mut RenderingContext) -> Result<T>;
/// This function should ask the queue negotatior to find families for any auxilary operations this draw pass needs to perform
/// For example, .find(&TexLoadQueue)
diff --git a/stockton-render/src/draw/draw_passes/util.rs b/stockton-render/src/draw_passes/util.rs
index 5a4eb1a..5a4eb1a 100644
--- a/stockton-render/src/draw/draw_passes/util.rs
+++ b/stockton-render/src/draw_passes/util.rs
diff --git a/stockton-render/src/lib.rs b/stockton-render/src/lib.rs
index 37acf27..03f6d53 100644
--- a/stockton-render/src/lib.rs
+++ b/stockton-render/src/lib.rs
@@ -6,86 +6,87 @@ extern crate nalgebra_glm as na;
#[macro_use]
extern crate derive_builder;
-#[macro_use]
-extern crate legion;
-
-pub mod draw;
+pub mod buffers;
+pub mod builders;
+pub mod context;
+pub mod draw_passes;
pub mod error;
-pub mod systems;
-mod types;
-pub mod window;
-
-use draw::{
- draw_passes::{DrawPass, IntoDrawPass},
- RenderingContext,
-};
+pub mod queue_negotiator;
+mod target;
+pub mod texture;
+pub mod types;
+pub mod utils;
-use std::sync::mpsc::{Receiver, Sender};
-use std::sync::Arc;
-use std::sync::RwLock;
-pub use window::{UiState, WindowEvent};
+use context::RenderingContext;
+use draw_passes::{DrawPass, IntoDrawPass};
-use anyhow::Result;
+use anyhow::{Context, Result};
use stockton_types::Session;
-use winit::event_loop::ControlFlow;
use winit::window::Window;
-use std::sync::mpsc::channel;
-
/// Renders a world to a window when you tell it to.
/// Also takes ownership of the window and channels window events to be processed outside winit's event loop.
pub struct Renderer<DP> {
/// All the vulkan stuff
- pub(crate) context: RenderingContext<DP>,
-
- /// For getting events from the winit event loop
- pub window_events: Receiver<WindowEvent>,
+ context: RenderingContext,
- /// For updating the control flow of the winit event loop
- pub update_control_flow: Arc<RwLock<ControlFlow>>,
+ /// The draw pass we're using
+ draw_pass: DP,
}
impl<DP: DrawPass> Renderer<DP> {
/// Create a new Renderer.
pub fn new<IDP: IntoDrawPass<DP>>(
window: &Window,
- session: &Session,
+ session: &mut Session,
idp: IDP,
- ) -> Result<(Self, Sender<WindowEvent>)> {
- let (tx, rx) = channel();
- let update_control_flow = Arc::new(RwLock::new(ControlFlow::Poll));
-
- Ok((
- Renderer {
- context: RenderingContext::new(window, session, idp)?,
- window_events: rx,
- update_control_flow,
- },
- tx,
- ))
+ ) -> Result<Self> {
+ let mut context = RenderingContext::new::<IDP, DP>(window)?;
+
+ // Draw pass
+ let draw_pass = idp
+ .init(session, &mut context)
+ .context("Error initialising draw pass")?;
+
+ Ok(Renderer { context, draw_pass })
}
/// Render a single frame of the given session.
pub fn render(&mut self, session: &Session) -> Result<()> {
// Try to draw
- if self.context.draw_next_frame(session).is_err() {
+ if self
+ .context
+ .draw_next_frame(session, &mut self.draw_pass)
+ .is_err()
+ {
// Probably the surface changed
- unsafe { self.context.handle_surface_change()? };
+ self.handle_surface_change(session)?;
// If it fails twice, then error
- self.context.draw_next_frame(session)?;
+ self.context.draw_next_frame(session, &mut self.draw_pass)?;
}
Ok(())
}
pub fn get_aspect_ratio(&self) -> f32 {
- let e = self.context.target_chain.properties.extent;
+ let e = self.context.target_chain().properties().extent;
e.width as f32 / e.height as f32
}
- fn resize(&mut self) -> Result<()> {
- unsafe { self.context.handle_surface_change() }
+ pub fn handle_surface_change(&mut self, session: &Session) -> Result<()> {
+ unsafe {
+ self.context.handle_surface_change()?;
+ self.draw_pass
+ .handle_surface_change(session, &mut self.context)?;
+ }
+
+ Ok(())
+ }
+
+ /// Get a reference to the renderer's context.
+ pub fn context(&self) -> &RenderingContext {
+ &self.context
}
}
diff --git a/stockton-render/src/draw/queue_negotiator.rs b/stockton-render/src/queue_negotiator.rs
index 65c7aa4..65c7aa4 100644
--- a/stockton-render/src/draw/queue_negotiator.rs
+++ b/stockton-render/src/queue_negotiator.rs
diff --git a/stockton-render/src/systems.rs b/stockton-render/src/systems.rs
deleted file mode 100644
index 5f86c29..0000000
--- a/stockton-render/src/systems.rs
+++ /dev/null
@@ -1,2 +0,0 @@
-pub use crate::draw::camera::calc_vp_matrix_system;
-pub use crate::window::process_window_events_system;
diff --git a/stockton-render/src/draw/target.rs b/stockton-render/src/target.rs
index 3861192..d0d2380 100644
--- a/stockton-render/src/draw/target.rs
+++ b/stockton-render/src/target.rs
@@ -122,15 +122,15 @@ impl SwapchainProperties {
pub struct TargetChain {
/// Surface we're targeting
- pub surface: ManuallyDrop<SurfaceT>,
- pub properties: SwapchainProperties,
+ surface: ManuallyDrop<SurfaceT>,
+ properties: SwapchainProperties,
/// Resources tied to each target frame in the swapchain
- pub targets: Box<[TargetResources]>,
+ targets: Box<[TargetResources]>,
/// Sync objects used in drawing
/// These are seperated from the targets because we don't necessarily always match up indexes
- pub sync_objects: Box<[SyncObjects]>,
+ sync_objects: Box<[SyncObjects]>,
/// The last set of sync objects used
last_syncs: usize,
@@ -327,6 +327,11 @@ impl TargetChain {
Ok(())
}
+
+ /// Get a reference to the target chain's properties.
+ pub fn properties(&self) -> &SwapchainProperties {
+ &self.properties
+ }
}
/// Resources for a single target frame, including sync objects
diff --git a/stockton-render/src/draw/texture/block.rs b/stockton-render/src/texture/block.rs
index 5ac3a94..5ac3a94 100644
--- a/stockton-render/src/draw/texture/block.rs
+++ b/stockton-render/src/texture/block.rs
diff --git a/stockton-render/src/draw/texture/image.rs b/stockton-render/src/texture/image.rs
index 0e272e9..0e272e9 100644
--- a/stockton-render/src/draw/texture/image.rs
+++ b/stockton-render/src/texture/image.rs
diff --git a/stockton-render/src/draw/texture/load.rs b/stockton-render/src/texture/load.rs
index 1f33ad5..1f33ad5 100644
--- a/stockton-render/src/draw/texture/load.rs
+++ b/stockton-render/src/texture/load.rs
diff --git a/stockton-render/src/draw/texture/loader.rs b/stockton-render/src/texture/loader.rs
index e6c19db..f9c643c 100644
--- a/stockton-render/src/draw/texture/loader.rs
+++ b/stockton-render/src/texture/loader.rs
@@ -7,7 +7,7 @@ use super::{
resolver::TextureResolver,
PIXEL_SIZE,
};
-use crate::{draw::utils::find_memory_type_id, error::LockPoisoned, types::*};
+use crate::{error::LockPoisoned, types::*, utils::find_memory_type_id};
use std::{
array::IntoIter,
diff --git a/stockton-render/src/draw/texture/mod.rs b/stockton-render/src/texture/mod.rs
index aef1b03..aef1b03 100644
--- a/stockton-render/src/draw/texture/mod.rs
+++ b/stockton-render/src/texture/mod.rs
diff --git a/stockton-render/src/draw/texture/repo.rs b/stockton-render/src/texture/repo.rs
index e427eef..e29625b 100644
--- a/stockton-render/src/draw/texture/repo.rs
+++ b/stockton-render/src/texture/repo.rs
@@ -4,8 +4,8 @@ use super::{
loader::{BlockRef, LoaderRequest, TextureLoader, TextureLoaderRemains, NUM_SIMULTANEOUS_CMDS},
resolver::TextureResolver,
};
-use crate::draw::queue_negotiator::QueueFamilySelector;
use crate::error::LockPoisoned;
+use crate::queue_negotiator::QueueFamilySelector;
use crate::types::*;
use std::{
@@ -153,7 +153,7 @@ impl TextureRepo {
}
}
- pub fn deactivate(mut self, device_lock: &mut Arc<RwLock<DeviceT>>) {
+ pub fn deactivate(mut self, device_lock: &Arc<RwLock<DeviceT>>) {
unsafe {
use std::ptr::read;
diff --git a/stockton-render/src/draw/texture/resolver.rs b/stockton-render/src/texture/resolver.rs
index 4b61c41..f66b724 100644
--- a/stockton-render/src/draw/texture/resolver.rs
+++ b/stockton-render/src/texture/resolver.rs
@@ -1,6 +1,6 @@
//! Resolves a texture in a BSP File to an image
-use crate::draw::texture::image::LoadableImage;
+use crate::texture::image::LoadableImage;
use stockton_levels::{parts::IsTexture, prelude::HasTextures};
use std::{
diff --git a/stockton-render/src/draw/texture/staging_buffer.rs b/stockton-render/src/texture/staging_buffer.rs
index 8d2ae17..8d2ae17 100644
--- a/stockton-render/src/draw/texture/staging_buffer.rs
+++ b/stockton-render/src/texture/staging_buffer.rs
diff --git a/stockton-render/src/draw/utils.rs b/stockton-render/src/utils.rs
index 2ab984b..152ba10 100644
--- a/stockton-render/src/draw/utils.rs
+++ b/stockton-render/src/utils.rs
@@ -1,5 +1,5 @@
use crate::types::*;
-use hal::{memory::Properties as MemProperties, prelude::*, MemoryTypeId};
+use hal::{memory::Properties as MemProperties, MemoryTypeId};
pub fn find_memory_type_id(
adapter: &Adapter,