Created
February 23, 2017 01:44
-
-
Save ebkalderon/de4c46bdb105c0f9bd8feb1aeaddd811 to your computer and use it in GitHub Desktop.
Basic amethyst_renderer example with revamped API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! Launches an empty renderer window with a deferred pipeline and white color. | |
//! | |
//! Uses `rayon` and `num_cpus` internally to batch `gfx::Encoder`s efficiently | |
//! and maximize parallelism. Haven't uploaded changes to GitHub since Amethyst is | |
//! completely broken with these changes. This is due to `gfx_device` and other | |
//! rendering stuff being directly inside the engine, instead of a `RenderingSystem` | |
//! where it really belongs. Some restructuring is necessary to fix this design | |
//! oversight and get this new renderer to work. | |
extern crate amethyst_renderer as renderer; | |
extern crate winit; | |
use renderer::{RendererBuilder, Layer, Target}; | |
use renderer::pass::{BlitLayer, ClearTarget, DrawFlat, DeferredLighting}; | |
use winit::ElementState::Pressed; | |
use winit::VirtualKeyCode as Key; | |
use winit::{Event, WindowBuilder}; | |
fn main() { | |
let builder = WindowBuilder::new() | |
.with_title("Amethyst Renderer Demo") | |
.with_dimensions(1024, 768); | |
let (window, mut renderer) = RendererBuilder::new(builder) | |
.build() | |
.expect("Could not build renderer"); | |
// Create GPU resources here, not implemented. | |
let pipe = renderer.create_pipeline() | |
.with_target(Target::new("gbuffer") | |
.with_num_color_bufs(4) | |
.with_depth_buf(true)) | |
.with_layer(Layer::with_target("gbuffer") | |
.with_pass(ClearTarget::with_values([0.0; 4], 0.0)) | |
.with_pass(DrawFlat::with_camera("main_camera"))) | |
.with_layer(Layer::with_target("main") | |
.with_pass(BlitTarget::from_target_color_buf("gbuffer", 2)) | |
.with_pass(DeferredLighting::new("main_camera", "gbuffer", "scene"))) | |
.build() | |
.expect("Could not build pipeline"); | |
// Build initial scene, not implemented. | |
'main: loop { | |
for event in window.poll_events() { | |
match event { | |
Event::Closed => break 'main, | |
Event::KeyboardInput(Pressed, _, Some(Key::Escape)) => break 'main, | |
_ => (), | |
} | |
} | |
// Modify scene and create/destroy GPU resources as needed. | |
renderer.draw(&pipe); // Pass scene and delta time here, eventually. | |
window.swap_buffers().expect("Window error"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment