diff options
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | examples/render/13power.bsp | bin | 0 -> 4568172 bytes | |||
-rw-r--r-- | examples/render/Cargo.toml | 11 | ||||
-rw-r--r-- | examples/render/src/main.rs | 49 | ||||
-rw-r--r-- | stockton-render/Cargo.toml | 45 | ||||
-rw-r--r-- | stockton-render/src/lib.rs | 66 | ||||
-rw-r--r-- | stockton-types/Cargo.toml | 2 |
7 files changed, 175 insertions, 2 deletions
@@ -1,4 +1,6 @@ [workspace] members = [ - "stockton-types" + "stockton-types", + "stockton-render", + "examples/render" ] diff --git a/examples/render/13power.bsp b/examples/render/13power.bsp Binary files differnew file mode 100644 index 0000000..0885199 --- /dev/null +++ b/examples/render/13power.bsp diff --git a/examples/render/Cargo.toml b/examples/render/Cargo.toml new file mode 100644 index 0000000..8a523e3 --- /dev/null +++ b/examples/render/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "render" +version = "0.1.0" +authors = ["Oscar <oscar.shrimpton.personal@gmail.com>"] +edition = "2018" + +[dependencies] +stockton-render = { path = "../../stockton-render" } +stockton-types = { path = "../../stockton-types" } +stockton-bsp = "2.0.0" +winit = "0.19.1"
\ No newline at end of file diff --git a/examples/render/src/main.rs b/examples/render/src/main.rs new file mode 100644 index 0000000..efb0e41 --- /dev/null +++ b/examples/render/src/main.rs @@ -0,0 +1,49 @@ +// Copyright (C) Oscar Shrimpton 2019 + +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. + +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. + +// You should have received a copy of the GNU General Public License along +// with this program. If not, see <http://www.gnu.org/licenses/>. + +//! Renders ./example.bsp + +extern crate stockton_types; +extern crate stockton_bsp; +extern crate stockton_render; +extern crate winit; + +use stockton_bsp::BSPFile; +use stockton_render::Renderer; +use stockton_types::World; + +use winit::{EventsLoop, Window}; + +use std::sync::{Arc,RwLock}; + + +fn main() { + // Parse the BSP file. + let data = include_bytes!("../13power.bsp"); + let bsp = BSPFile::from_buffer(data).unwrap(); + + // Load it into a world. + // None of the entities are mapped for simplicity. + let world = Arc::new(RwLock::new(World::new(bsp, |_| { + None + }).unwrap())); + + // Create the window. + let events = EventsLoop::new(); + let window = Window::new(&events).unwrap(); + + // Create the renderer. + let renderer = Renderer::new(world, &window); +} diff --git a/stockton-render/Cargo.toml b/stockton-render/Cargo.toml new file mode 100644 index 0000000..4dd5547 --- /dev/null +++ b/stockton-render/Cargo.toml @@ -0,0 +1,45 @@ +[package] +name = "stockton-render" +version = "0.1.0" +authors = ["Oscar <oscar.shrimpton.personal@gmail.com>"] +edition = "2018" + +[dependencies] +stockton-types = { path = "../stockton-types" } +winit = "0.19.1" +gfx-hal = "0.2.0" + +[features] +default = ["empty"] +empty = ["gfx-backend-empty"] +metal = ["gfx-backend-metal"] +gl = ["gfx-backend-gl"] +dx11 = ["gfx-backend-dx11"] +dx12 = ["gfx-backend-dx12"] +vulkan = ["gfx-backend-vulkan"] +unstable = [] + +[dependencies.gfx-backend-empty] +version = "0.2" +optional = true + +[dependencies.gfx-backend-gl] +version = "0.2" +features = ["glutin"] +optional = true + +[dependencies.gfx-backend-vulkan] +version = "0.2" +optional = true + +[target.'cfg(any(target_os = "macos", all(target_os = "ios", target_arch = "aarch64")))'.dependencies.gfx-backend-metal] +version = "0.2" +optional = true + +[target.'cfg(windows)'.dependencies.gfx-backend-dx11] +version = "0.2" +optional = true + +[target.'cfg(windows)'.dependencies.gfx-backend-dx12] +version = "0.2" +optional = true diff --git a/stockton-render/src/lib.rs b/stockton-render/src/lib.rs new file mode 100644 index 0000000..d399a76 --- /dev/null +++ b/stockton-render/src/lib.rs @@ -0,0 +1,66 @@ +// Copyright (C) 2019 Oscar Shrimpton + +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. + +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. + +// You should have received a copy of the GNU General Public License along +// with this program. If not, see <http://www.gnu.org/licenses/>. + +//! Renders a world to a window. +//! +//! You'll need to pick a backend using features. You should only pick one. +//! On Linux & Windows, you should use vulkan. +//! On Mac, you should use `metal`. +//! If your targetting machines without Vulkan, OpenGL or dx11/dx12 is preferred. +//! `empty` is used for testing +#[cfg(feature = "dx11")] +extern crate gfx_backend_dx11 as back; + +#[cfg(feature = "dx12")] +extern crate gfx_backend_dx12 as back; + +#[cfg(feature = "gl")] +extern crate gfx_backend_gl as back; + +#[cfg(feature = "metal")] +extern crate gfx_backend_metal as back; + +#[cfg(feature = "vulkan")] +extern crate gfx_backend_vulkan as back; + +#[cfg(feature = "empty")] +extern crate gfx_backend_empty as back; + +extern crate gfx_hal as hal; +extern crate stockton_types; +extern crate winit; + +use stockton_types::World; + +use winit::Window; + +use back::Instance; + +use std::sync::{Arc, RwLock}; + +pub struct Renderer<'a> { + world: Arc<RwLock<World<'a>>>, + instance: Instance, + window: &'a Window, +} + +impl<'a> Renderer<'a> { + pub fn new(world: Arc<RwLock<World<'a>>>, window: &'a Window) -> Renderer<'a> { + let instance = Instance::create("stockton", 1); + Renderer { + world, window, instance + } + } +} diff --git a/stockton-types/Cargo.toml b/stockton-types/Cargo.toml index b97f983..fd5336c 100644 --- a/stockton-types/Cargo.toml +++ b/stockton-types/Cargo.toml @@ -6,5 +6,5 @@ edition = "2018" [dependencies] nalgebra = "0.18.0" -stockton-bsp = "1.0.0" +stockton-bsp = "2.0.0" downcast-rs = "1.0.4"
\ No newline at end of file |