1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
//! Provides ability to change shader source files and have them reload on the fly. Also provides //! macros to simply include the shader code at compile time when running in release mode. //! //! # Examples //! ```rust,no_run //! #[macro_use] extern crate gfx; //! #[macro_use] extern crate gfx_shader_watch; //! # extern crate gfx_window_glutin; //! # extern crate glutin; //! //! # use gfx::traits::FactoryExt; //! # use gfx::Device; //! # use gfx::format::{Rgba8, Depth}; //! use gfx_shader_watch::*; //! use gfx::Primitive; //! use gfx::state::Rasterizer; //! //! # gfx_defines!{ //! # vertex Vertex { //! # pos: [f32; 2] = "pos", //! # } //! # pipeline mypipeline { //! # vbuf: gfx::VertexBuffer<Vertex> = (), //! # out: gfx::RenderTarget<Rgba8> = "Target0", //! # } //! # } //! # const TRIANGLE: [Vertex; 3] = [ //! # Vertex { pos: [ -0.5, -0.5 ] }, //! # Vertex { pos: [ 0.5, -0.5 ] }, //! # Vertex { pos: [ 0.0, 0.5 ] } //! # ]; //! pub fn main() { //! // {code to setup window / gfx factory etc } //! # let mut events_loop = glutin::EventsLoop::new(); //! # let window_builder = glutin::WindowBuilder::new() //! # .with_title("Triangle".to_string()) //! # .with_dimensions((1024, 768).into()); //! # let context = glutin::ContextBuilder::new() //! # .with_vsync(true); //! # let (window, mut device, mut factory, main_color, _main_depth) = //! # gfx_window_glutin::init::<Rgba8, Depth>(window_builder, context, &events_loop).unwrap(); //! # let mut encoder: gfx::Encoder<_, _> = factory.create_command_buffer().into(); //! # let (vertex_buffer, slice) = factory.create_vertex_buffer_with_slice(&TRIANGLE, ()); //! # let data = mypipeline::Data { //! # vbuf: vertex_buffer, //! # out: main_color //! # }; //! //! // Container has SimplePsoCell or WatcherPsoCell type, depending on compile mode //! // if you need to refer to the type, use the `debug_watcher_pso_cell_type!` macro //! let mut pso_cell = debug_watcher_pso_cell!( //! pipe = mypipeline, //! vertex_shader = "shader/vert.glsl", //! fragment_shader = "shader/frag.glsl", //! factory = factory, //! primitive = Primitive::TriangleList, //! rasterizer = Rasterizer::new_fill()).expect("psocell"); //! //! let mut running = true; //! while running { //! // ... //! # events_loop.poll_events(|event| { //! # if let glutin::Event::WindowEvent{ event, .. } = event { //! # match event { //! # glutin::WindowEvent::KeyboardInput { //! # input: glutin::KeyboardInput { //! # virtual_keycode: Some(glutin::VirtualKeyCode::Escape), //! # .. }, //! # .. //! # } | //! # glutin::WindowEvent::CloseRequested => running = false, //! # _ => {}, //! # } //! # } //! # }); //! # encoder.clear(&data.out, [0.1, 0.2, 0.3, 1.0]); //! encoder.draw(&slice, pso_cell.pso(), &data); //! // ... //! # encoder.flush(&mut device); //! # window.swap_buffers().unwrap(); //! # device.cleanup(); //! } //! } //! ``` mod psocell; pub use crate::psocell::*;