diff options
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | examples/render-quad/Cargo.toml | 4 | ||||
-rw-r--r-- | examples/render-quad/src/main.rs | 53 | ||||
-rw-r--r-- | stockton-passes/Cargo.toml | 22 | ||||
-rw-r--r-- | stockton-passes/src/lib.rs | 9 | ||||
-rw-r--r-- | stockton-render/Cargo.toml | 33 | ||||
-rw-r--r-- | stockton-render/src/camera.rs (renamed from stockton-passes/src/camera.rs) | 4 | ||||
-rw-r--r-- | stockton-render/src/data/3d.frag (renamed from stockton-passes/src/data/3d.frag) | 0 | ||||
-rw-r--r-- | stockton-render/src/data/3d.vert (renamed from stockton-passes/src/data/3d.vert) | 0 | ||||
-rw-r--r-- | stockton-render/src/data/ui.frag (renamed from stockton-passes/src/data/ui.frag) | 0 | ||||
-rw-r--r-- | stockton-render/src/data/ui.vert (renamed from stockton-passes/src/data/ui.vert) | 0 | ||||
-rw-r--r-- | stockton-render/src/level.rs (renamed from stockton-passes/src/level.rs) | 34 | ||||
-rw-r--r-- | stockton-render/src/lib.rs | 95 | ||||
-rw-r--r-- | stockton-render/src/ui.rs (renamed from stockton-passes/src/ui.rs) | 40 | ||||
-rw-r--r-- | stockton-render/src/window.rs (renamed from stockton-passes/src/window.rs) | 27 | ||||
-rw-r--r-- | stockton-skeleton/Cargo.toml | 31 | ||||
-rw-r--r-- | stockton-skeleton/src/buffers/dedicated_image.rs (renamed from stockton-render/src/buffers/dedicated_image.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/buffers/draw_buffers.rs (renamed from stockton-render/src/buffers/draw_buffers.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/buffers/mod.rs (renamed from stockton-render/src/buffers/mod.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/buffers/staged.rs (renamed from stockton-render/src/buffers/staged.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/builders/mod.rs (renamed from stockton-render/src/builders/mod.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/builders/pipeline.rs (renamed from stockton-render/src/builders/pipeline.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/builders/renderpass.rs (renamed from stockton-render/src/builders/renderpass.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/builders/shader.rs (renamed from stockton-render/src/builders/shader.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/context.rs (renamed from stockton-render/src/context.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/draw_passes/cons.rs (renamed from stockton-render/src/draw_passes/cons.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/draw_passes/mod.rs (renamed from stockton-render/src/draw_passes/mod.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/draw_passes/util.rs (renamed from stockton-render/src/draw_passes/util.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/error.rs (renamed from stockton-render/src/error.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/lib.rs | 92 | ||||
-rw-r--r-- | stockton-skeleton/src/queue_negotiator.rs (renamed from stockton-render/src/queue_negotiator.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/target.rs (renamed from stockton-render/src/target.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/texture/block.rs (renamed from stockton-render/src/texture/block.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/texture/image.rs (renamed from stockton-render/src/texture/image.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/texture/load.rs (renamed from stockton-render/src/texture/load.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/texture/loader.rs (renamed from stockton-render/src/texture/loader.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/texture/mod.rs (renamed from stockton-render/src/texture/mod.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/texture/repo.rs (renamed from stockton-render/src/texture/repo.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/texture/resolver.rs (renamed from stockton-render/src/texture/resolver.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/texture/staging_buffer.rs (renamed from stockton-render/src/texture/staging_buffer.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/types.rs (renamed from stockton-render/src/types.rs) | 0 | ||||
-rw-r--r-- | stockton-skeleton/src/utils.rs (renamed from stockton-render/src/utils.rs) | 0 |
42 files changed, 224 insertions, 224 deletions
@@ -3,9 +3,9 @@ members = [ "stockton-types", "stockton-input", "stockton-input-codegen", - "stockton-render", + "stockton-skeleton", "stockton-levels", - "stockton-passes", + "stockton-render", "stockton-contrib", "rendy-memory", "rendy-descriptor", diff --git a/examples/render-quad/Cargo.toml b/examples/render-quad/Cargo.toml index 9988c66..0c4306d 100644 --- a/examples/render-quad/Cargo.toml +++ b/examples/render-quad/Cargo.toml @@ -5,13 +5,13 @@ authors = ["Oscar <oscar.shrimpton.personal@gmail.com>"] edition = "2018" [dependencies] -stockton-render = { path = "../../stockton-render", features = ["vulkan"] } +stockton-skeleton = { path = "../../stockton-skeleton", features = ["vulkan"] } stockton-input = { path = "../../stockton-input" } 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" } +stockton-render = { path = "../../stockton-render" } 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 6e192dc..618779e 100644 --- a/examples/render-quad/src/main.rs +++ b/examples/render-quad/src/main.rs @@ -6,35 +6,40 @@ extern crate stockton_input_codegen; #[macro_use] 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_passes::{ +use std::{ + collections::BTreeMap, + path::Path, + sync::{Arc, RwLock}, +}; + +use stockton_contrib::{delta_time::*, flycam::*}; +use stockton_input::{Axis, InputManager, Mouse}; +use stockton_levels::{ + parts::data::{Geometry, Vertex}, + types::Rgba, +}; +use stockton_render::{ + camera::calc_vp_matrix_system, level::{LevelDrawPass, LevelDrawPassConfig}, ui::UiDrawPass, + window::{process_window_events_system, UiState, WindowEvent, WindowFlow}, +}; +use stockton_skeleton::{ + draw_passes::ConsDrawPass, error::full_error_display, texture::resolver::FsResolver, Renderer, +}; +use stockton_types::{ + components::{CameraSettings, CameraVPMatrix, Transform}, + Session, Vector2, Vector3, }; -use stockton_render::{draw_passes::ConsDrawPass, texture::resolver::FsResolver}; -use winit::{event::Event, event_loop::EventLoop, window::WindowBuilder}; +use anyhow::{Context, Result}; use egui::{containers::CentralPanel, Frame}; -use stockton_contrib::delta_time::*; -use stockton_contrib::flycam::*; - -use stockton_input::{Axis, InputManager, Mouse}; - -use stockton_render::error::full_error_display; -use stockton_render::Renderer; - -use stockton_types::components::{CameraSettings, CameraVPMatrix, Transform}; -use stockton_types::{Session, Vector2, Vector3}; +use log::warn; +use winit::{ + event::Event, + event_loop::{ControlFlow, EventLoop}, + window::WindowBuilder, +}; mod level; use level::*; diff --git a/stockton-passes/Cargo.toml b/stockton-passes/Cargo.toml deleted file mode 100644 index a37846c..0000000 --- a/stockton-passes/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[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-passes/src/lib.rs b/stockton-passes/src/lib.rs deleted file mode 100644 index e3e5bf8..0000000 --- a/stockton-passes/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -#[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/Cargo.toml b/stockton-render/Cargo.toml index cb056b4..e6ac094 100644 --- a/stockton-render/Cargo.toml +++ b/stockton-render/Cargo.toml @@ -1,31 +1,22 @@ [package] name = "stockton-render" version = "0.1.0" -authors = ["Oscar <oscar.shrimpton.personal@gmail.com>"] +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-input = { path = "../stockton-input" } -stockton-levels = { path = "../stockton-levels" } +stockton-skeleton = { path = "../stockton-skeleton" } stockton-types = { path = "../stockton-types" } -winit = "^0.21" +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" -arrayvec = "0.4.10" -nalgebra-glm = "^0.6" shaderc = "^0.7" -log = "0.4.0" -image = "0.23.11" legion = { version = "^0.3" } -rendy-memory = { path = "../rendy-memory" } -rendy-descriptor = { path = "../rendy-descriptor" } -anyhow = "1.0.40" -thiserror = "1.0.25" -derive_builder = "0.10.2" - -[features] -default = ["vulkan"] -vulkan = ["gfx-backend-vulkan"] - -[dependencies.gfx-backend-vulkan] -version = "^0.8.0" -optional = true +log = "0.4.0" +winit = "^0.21" +nalgebra-glm = "^0.6" diff --git a/stockton-passes/src/camera.rs b/stockton-render/src/camera.rs index 49cce59..dcc9d93 100644 --- a/stockton-passes/src/camera.rs +++ b/stockton-render/src/camera.rs @@ -7,9 +7,7 @@ use stockton_types::{ Vector3, }; -use stockton_render::Renderer; - -use stockton_render::draw_passes::DrawPass; +use stockton_skeleton::{draw_passes::DrawPass, Renderer}; fn euler_to_direction(euler: &Vector3) -> Vector3 { let pitch = euler.x; diff --git a/stockton-passes/src/data/3d.frag b/stockton-render/src/data/3d.frag index 336d9fe..336d9fe 100644 --- a/stockton-passes/src/data/3d.frag +++ b/stockton-render/src/data/3d.frag diff --git a/stockton-passes/src/data/3d.vert b/stockton-render/src/data/3d.vert index aaee1a5..aaee1a5 100644 --- a/stockton-passes/src/data/3d.vert +++ b/stockton-render/src/data/3d.vert diff --git a/stockton-passes/src/data/ui.frag b/stockton-render/src/data/ui.frag index c30c99e..c30c99e 100644 --- a/stockton-passes/src/data/ui.frag +++ b/stockton-render/src/data/ui.frag diff --git a/stockton-passes/src/data/ui.vert b/stockton-render/src/data/ui.vert index 8912e96..8912e96 100644 --- a/stockton-passes/src/data/ui.vert +++ b/stockton-render/src/data/ui.vert diff --git a/stockton-passes/src/level.rs b/stockton-render/src/level.rs index cd3ce6a..6c74211 100644 --- a/stockton-passes/src/level.rs +++ b/stockton-render/src/level.rs @@ -1,26 +1,10 @@ //! Minimal code for drawing any level, based on traits from stockton-levels -use hal::{ - buffer::SubRange, - command::{ClearColor, ClearDepthStencil, ClearValue, RenderAttachmentInfo, SubpassContents}, - format::{Aspects, Format}, - image::{ - Filter, FramebufferAttachment, Layout, SubresourceRange, Usage, ViewCapabilities, WrapMode, - }, - pass::{Attachment, AttachmentLoadOp, AttachmentOps, AttachmentStoreOp}, - pso::{ - BlendDesc, BlendOp, BlendState, ColorBlendDesc, ColorMask, Comparison, DepthStencilDesc, - DepthTest, Face, Factor, FrontFace, InputAssemblerDesc, LogicOp, PolygonMode, Primitive, - Rasterizer, ShaderStageFlags, State, VertexInputRate, - }, -}; -use legion::{Entity, IntoQuery}; -use shaderc::ShaderKind; use stockton_levels::{ features::MinRenderFeatures, parts::{data::Geometry, IsFace}, }; -use stockton_render::{ +use stockton_skeleton::{ buffers::{ DedicatedLoadedImage, DrawBuffers, ModifiableBuffer, INITIAL_INDEX_SIZE, INITIAL_VERT_SIZE, }, @@ -49,6 +33,22 @@ use std::{ }; use anyhow::{Context, Result}; +use hal::{ + buffer::SubRange, + command::{ClearColor, ClearDepthStencil, ClearValue, RenderAttachmentInfo, SubpassContents}, + format::{Aspects, Format}, + image::{ + Filter, FramebufferAttachment, Layout, SubresourceRange, Usage, ViewCapabilities, WrapMode, + }, + pass::{Attachment, AttachmentLoadOp, AttachmentOps, AttachmentStoreOp}, + pso::{ + BlendDesc, BlendOp, BlendState, ColorBlendDesc, ColorMask, Comparison, DepthStencilDesc, + DepthTest, Face, Factor, FrontFace, InputAssemblerDesc, LogicOp, PolygonMode, Primitive, + Rasterizer, ShaderStageFlags, State, VertexInputRate, + }, +}; +use legion::{Entity, IntoQuery}; +use shaderc::ShaderKind; /// The Vertexes that go to the shader #[derive(Debug, Clone, Copy)] diff --git a/stockton-render/src/lib.rs b/stockton-render/src/lib.rs index 03f6d53..e3e5bf8 100644 --- a/stockton-render/src/lib.rs +++ b/stockton-render/src/lib.rs @@ -1,92 +1,9 @@ -#[cfg(feature = "vulkan")] -extern crate gfx_backend_vulkan as back; +#[macro_use] +extern crate legion; extern crate gfx_hal as hal; extern crate nalgebra_glm as na; -#[macro_use] -extern crate derive_builder; - -pub mod buffers; -pub mod builders; -pub mod context; -pub mod draw_passes; -pub mod error; -pub mod queue_negotiator; -mod target; -pub mod texture; -pub mod types; -pub mod utils; - -use context::RenderingContext; -use draw_passes::{DrawPass, IntoDrawPass}; - -use anyhow::{Context, Result}; - -use stockton_types::Session; -use winit::window::Window; - -/// 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 - context: RenderingContext, - - /// 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: &mut Session, - idp: IDP, - ) -> 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, &mut self.draw_pass) - .is_err() - { - // Probably the surface changed - self.handle_surface_change(session)?; - - // If it fails twice, then error - 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; - e.width as f32 / e.height as f32 - } - - 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 - } -} +pub mod camera; +pub mod level; +pub mod ui; +pub mod window; diff --git a/stockton-passes/src/ui.rs b/stockton-render/src/ui.rs index bc1ba69..d1689be 100644 --- a/stockton-passes/src/ui.rs +++ b/stockton-render/src/ui.rs @@ -1,20 +1,7 @@ //! Minimal code for drawing any level, based on traits from stockton-levels +use crate::window::UiState; -use egui::{ClippedMesh, TextureId}; -use hal::{ - buffer::SubRange, - command::{ClearColor, ClearValue, RenderAttachmentInfo, SubpassContents}, - format::Format, - image::Layout, - pass::{Attachment, AttachmentLoadOp, AttachmentOps, AttachmentStoreOp}, - pso::{ - BlendDesc, BlendOp, BlendState, ColorBlendDesc, ColorMask, DepthStencilDesc, Face, Factor, - FrontFace, InputAssemblerDesc, LogicOp, PolygonMode, Primitive, Rasterizer, Rect, - ShaderStageFlags, State, VertexInputRate, - }, -}; -use shaderc::ShaderKind; -use stockton_render::{ +use stockton_skeleton::{ buffers::{DrawBuffers, ModifiableBuffer}, builders::{ CompletePipeline, PipelineSpecBuilder, RenderpassSpec, ShaderDesc, VertexBufferSpec, @@ -24,7 +11,9 @@ use stockton_render::{ draw_passes::{util::TargetSpecificResources, DrawPass, IntoDrawPass}, error::{EnvironmentError, LockPoisoned}, queue_negotiator::QueueNegotiator, - texture::{TexLoadQueue, TextureLoadConfig, TextureRepo}, + texture::{ + resolver::TextureResolver, LoadableImage, TexLoadQueue, TextureLoadConfig, TextureRepo, + }, types::*, }; use stockton_types::{Session, Vector2}; @@ -33,14 +22,25 @@ use std::{ array::IntoIter, convert::TryInto, iter::{empty, once}, + sync::Arc, }; use anyhow::{anyhow, Context, Result}; +use egui::{ClippedMesh, TextureId}; use egui::{CtxRef, Texture}; -use std::sync::Arc; -use stockton_render::texture::{resolver::TextureResolver, LoadableImage}; - -use crate::window::UiState; +use hal::{ + buffer::SubRange, + command::{ClearColor, ClearValue, RenderAttachmentInfo, SubpassContents}, + format::Format, + image::Layout, + pass::{Attachment, AttachmentLoadOp, AttachmentOps, AttachmentStoreOp}, + pso::{ + BlendDesc, BlendOp, BlendState, ColorBlendDesc, ColorMask, DepthStencilDesc, Face, Factor, + FrontFace, InputAssemblerDesc, LogicOp, PolygonMode, Primitive, Rasterizer, Rect, + ShaderStageFlags, State, VertexInputRate, + }, +}; +use shaderc::ShaderKind; #[derive(Debug)] pub struct UiPoint(pub Vector2, pub Vector2, pub [f32; 4]); diff --git a/stockton-passes/src/window.rs b/stockton-render/src/window.rs index 46ba1a1..15dd5a6 100644 --- a/stockton-passes/src/window.rs +++ b/stockton-render/src/window.rs @@ -1,22 +1,19 @@ -use std::sync::mpsc::channel; -use std::sync::mpsc::Receiver; -use std::sync::mpsc::Sender; -use std::sync::Arc; -use std::sync::RwLock; +use stockton_input::{Action as KBAction, InputManager, Mouse}; +use stockton_skeleton::{draw_passes::DrawPass, Renderer}; -use egui::{Modifiers, Rect, Vec2}; -use legion::systems::Runnable; -use log::debug; -use stockton_render::{draw_passes::DrawPass, Renderer}; +use std::sync::{ + mpsc::{channel, Receiver, Sender}, + Arc, RwLock, +}; -use egui::{CtxRef, Event, Output, Pos2, RawInput}; +use egui::{CtxRef, Event, Modifiers, Output, Pos2, RawInput, Rect, Vec2}; use epaint::ClippedShape; -use stockton_input::{Action as KBAction, InputManager, Mouse}; - -use winit::event::{ - ElementState, Event as WinitEvent, MouseButton, WindowEvent as WinitWindowEvent, +use legion::systems::Runnable; +use log::debug; +use winit::{ + event::{ElementState, Event as WinitEvent, MouseButton, WindowEvent as WinitWindowEvent}, + event_loop::ControlFlow, }; -use winit::event_loop::ControlFlow; #[derive(Debug, Clone, Copy)] pub enum WindowEvent { diff --git a/stockton-skeleton/Cargo.toml b/stockton-skeleton/Cargo.toml new file mode 100644 index 0000000..8e3df4b --- /dev/null +++ b/stockton-skeleton/Cargo.toml @@ -0,0 +1,31 @@ +[package] +name = "stockton-skeleton" +version = "0.1.0" +authors = ["Oscar <oscar.shrimpton.personal@gmail.com>"] +edition = "2018" + +[dependencies] +stockton-input = { path = "../stockton-input" } +stockton-levels = { path = "../stockton-levels" } +stockton-types = { path = "../stockton-types" } +winit = "^0.21" +gfx-hal = "^0.8.0" +arrayvec = "0.4.10" +nalgebra-glm = "^0.6" +shaderc = "^0.7" +log = "0.4.0" +image = "0.23.11" +legion = { version = "^0.3" } +rendy-memory = { path = "../rendy-memory" } +rendy-descriptor = { path = "../rendy-descriptor" } +anyhow = "1.0.40" +thiserror = "1.0.25" +derive_builder = "0.10.2" + +[features] +default = ["vulkan"] +vulkan = ["gfx-backend-vulkan"] + +[dependencies.gfx-backend-vulkan] +version = "^0.8.0" +optional = true diff --git a/stockton-render/src/buffers/dedicated_image.rs b/stockton-skeleton/src/buffers/dedicated_image.rs index bf49a38..bf49a38 100644 --- a/stockton-render/src/buffers/dedicated_image.rs +++ b/stockton-skeleton/src/buffers/dedicated_image.rs diff --git a/stockton-render/src/buffers/draw_buffers.rs b/stockton-skeleton/src/buffers/draw_buffers.rs index 5baec92..5baec92 100644 --- a/stockton-render/src/buffers/draw_buffers.rs +++ b/stockton-skeleton/src/buffers/draw_buffers.rs diff --git a/stockton-render/src/buffers/mod.rs b/stockton-skeleton/src/buffers/mod.rs index 74c5aab..74c5aab 100644 --- a/stockton-render/src/buffers/mod.rs +++ b/stockton-skeleton/src/buffers/mod.rs diff --git a/stockton-render/src/buffers/staged.rs b/stockton-skeleton/src/buffers/staged.rs index 71b5204..71b5204 100644 --- a/stockton-render/src/buffers/staged.rs +++ b/stockton-skeleton/src/buffers/staged.rs diff --git a/stockton-render/src/builders/mod.rs b/stockton-skeleton/src/builders/mod.rs index 97b47a0..97b47a0 100644 --- a/stockton-render/src/builders/mod.rs +++ b/stockton-skeleton/src/builders/mod.rs diff --git a/stockton-render/src/builders/pipeline.rs b/stockton-skeleton/src/builders/pipeline.rs index f68d9d6..f68d9d6 100644 --- a/stockton-render/src/builders/pipeline.rs +++ b/stockton-skeleton/src/builders/pipeline.rs diff --git a/stockton-render/src/builders/renderpass.rs b/stockton-skeleton/src/builders/renderpass.rs index 43f0eb2..43f0eb2 100644 --- a/stockton-render/src/builders/renderpass.rs +++ b/stockton-skeleton/src/builders/renderpass.rs diff --git a/stockton-render/src/builders/shader.rs b/stockton-skeleton/src/builders/shader.rs index fde185d..fde185d 100644 --- a/stockton-render/src/builders/shader.rs +++ b/stockton-skeleton/src/builders/shader.rs diff --git a/stockton-render/src/context.rs b/stockton-skeleton/src/context.rs index 802b8ca..802b8ca 100644 --- a/stockton-render/src/context.rs +++ b/stockton-skeleton/src/context.rs diff --git a/stockton-render/src/draw_passes/cons.rs b/stockton-skeleton/src/draw_passes/cons.rs index ad94b1c..ad94b1c 100644 --- a/stockton-render/src/draw_passes/cons.rs +++ b/stockton-skeleton/src/draw_passes/cons.rs diff --git a/stockton-render/src/draw_passes/mod.rs b/stockton-skeleton/src/draw_passes/mod.rs index a0dbba5..a0dbba5 100644 --- a/stockton-render/src/draw_passes/mod.rs +++ b/stockton-skeleton/src/draw_passes/mod.rs diff --git a/stockton-render/src/draw_passes/util.rs b/stockton-skeleton/src/draw_passes/util.rs index 7e82209..7e82209 100644 --- a/stockton-render/src/draw_passes/util.rs +++ b/stockton-skeleton/src/draw_passes/util.rs diff --git a/stockton-render/src/error.rs b/stockton-skeleton/src/error.rs index 1f57892..1f57892 100644 --- a/stockton-render/src/error.rs +++ b/stockton-skeleton/src/error.rs diff --git a/stockton-skeleton/src/lib.rs b/stockton-skeleton/src/lib.rs new file mode 100644 index 0000000..03f6d53 --- /dev/null +++ b/stockton-skeleton/src/lib.rs @@ -0,0 +1,92 @@ +#[cfg(feature = "vulkan")] +extern crate gfx_backend_vulkan as back; +extern crate gfx_hal as hal; +extern crate nalgebra_glm as na; + +#[macro_use] +extern crate derive_builder; + +pub mod buffers; +pub mod builders; +pub mod context; +pub mod draw_passes; +pub mod error; +pub mod queue_negotiator; +mod target; +pub mod texture; +pub mod types; +pub mod utils; + +use context::RenderingContext; +use draw_passes::{DrawPass, IntoDrawPass}; + +use anyhow::{Context, Result}; + +use stockton_types::Session; +use winit::window::Window; + +/// 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 + context: RenderingContext, + + /// 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: &mut Session, + idp: IDP, + ) -> 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, &mut self.draw_pass) + .is_err() + { + // Probably the surface changed + self.handle_surface_change(session)?; + + // If it fails twice, then error + 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; + e.width as f32 / e.height as f32 + } + + 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/queue_negotiator.rs b/stockton-skeleton/src/queue_negotiator.rs index 879a935..879a935 100644 --- a/stockton-render/src/queue_negotiator.rs +++ b/stockton-skeleton/src/queue_negotiator.rs diff --git a/stockton-render/src/target.rs b/stockton-skeleton/src/target.rs index d0d2380..d0d2380 100644 --- a/stockton-render/src/target.rs +++ b/stockton-skeleton/src/target.rs diff --git a/stockton-render/src/texture/block.rs b/stockton-skeleton/src/texture/block.rs index 5ac3a94..5ac3a94 100644 --- a/stockton-render/src/texture/block.rs +++ b/stockton-skeleton/src/texture/block.rs diff --git a/stockton-render/src/texture/image.rs b/stockton-skeleton/src/texture/image.rs index f984b72..f984b72 100644 --- a/stockton-render/src/texture/image.rs +++ b/stockton-skeleton/src/texture/image.rs diff --git a/stockton-render/src/texture/load.rs b/stockton-skeleton/src/texture/load.rs index 1f33ad5..1f33ad5 100644 --- a/stockton-render/src/texture/load.rs +++ b/stockton-skeleton/src/texture/load.rs diff --git a/stockton-render/src/texture/loader.rs b/stockton-skeleton/src/texture/loader.rs index 5c85fd3..5c85fd3 100644 --- a/stockton-render/src/texture/loader.rs +++ b/stockton-skeleton/src/texture/loader.rs diff --git a/stockton-render/src/texture/mod.rs b/stockton-skeleton/src/texture/mod.rs index aef1b03..aef1b03 100644 --- a/stockton-render/src/texture/mod.rs +++ b/stockton-skeleton/src/texture/mod.rs diff --git a/stockton-render/src/texture/repo.rs b/stockton-skeleton/src/texture/repo.rs index 341d355..341d355 100644 --- a/stockton-render/src/texture/repo.rs +++ b/stockton-skeleton/src/texture/repo.rs diff --git a/stockton-render/src/texture/resolver.rs b/stockton-skeleton/src/texture/resolver.rs index f66b724..f66b724 100644 --- a/stockton-render/src/texture/resolver.rs +++ b/stockton-skeleton/src/texture/resolver.rs diff --git a/stockton-render/src/texture/staging_buffer.rs b/stockton-skeleton/src/texture/staging_buffer.rs index 8d2ae17..8d2ae17 100644 --- a/stockton-render/src/texture/staging_buffer.rs +++ b/stockton-skeleton/src/texture/staging_buffer.rs diff --git a/stockton-render/src/types.rs b/stockton-skeleton/src/types.rs index 03c6e37..03c6e37 100644 --- a/stockton-render/src/types.rs +++ b/stockton-skeleton/src/types.rs diff --git a/stockton-render/src/utils.rs b/stockton-skeleton/src/utils.rs index 152ba10..152ba10 100644 --- a/stockton-render/src/utils.rs +++ b/stockton-skeleton/src/utils.rs |