-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathhlsl.rs
49 lines (43 loc) · 1.8 KB
/
hlsl.rs
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
use {
screen_13::prelude::*,
screen_13_hot::prelude::*,
screen_13_window::{Window, WindowError},
std::path::PathBuf,
};
/// This program draws a noise signal to the swapchain - make changes to fill_image.hlsl or the
/// noise.hlsl file it includes to see those changes update while the program is still running.
///
/// Run with RUST_LOG=info to get notification of shader compilations.
fn main() -> Result<(), WindowError> {
pretty_env_logger::init();
let window = Window::new()?;
// Create a graphic pipeline - the same as normal except for "Hot" prefixes and we provide the
// shader source code path instead of the shader source code bytes
let cargo_manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let fill_image_path = cargo_manifest_dir.join("examples/res/fill_image.hlsl");
let mut pipeline = HotGraphicPipeline::create(
&window.device,
GraphicPipelineInfo::default(),
[
HotShader::new_vertex(&fill_image_path).entry_name("vertex_main".to_string()),
HotShader::new_fragment(&fill_image_path).entry_name("fragment_main".to_string()),
],
)?;
let mut frame_index: u32 = 0;
window.run(|frame| {
frame
.render_graph
.begin_pass("make some noise")
.bind_pipeline(pipeline.hot())
.clear_color(0, frame.swapchain_image)
.store_color(0, frame.swapchain_image)
.record_subpass(move |subpass, _| {
subpass
.push_constants_offset(0, &frame_index.to_ne_bytes())
.push_constants_offset(4, &frame.width.to_ne_bytes())
.push_constants_offset(8, &frame.height.to_ne_bytes())
.draw(3, 1, 0, 0);
});
frame_index += 1;
})
}