This repository has been archived by the owner on May 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wgpu_hello_world.rs
69 lines (52 loc) · 1.66 KB
/
wgpu_hello_world.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use std::collections::HashMap;
use renderer::{RenderPass, Renderer, Shader, ShaderStage, Window, WindowHandler, WindowMode, WindowSettings};
use resources::Resources;
extern crate noire;
extern crate futures;
extern crate wgpu;
// NOTE for now shaders are hard coded here
const VERTEX_SHADER: &str = r#"
#version 450
out gl_PerVertex {
vec4 gl_Position;
};
void main() {
vec2 position = vec2(gl_VertexIndex, (gl_VertexIndex & 1) * 2) - 1;
gl_Position = vec4(position, 0.0, 1.0);
}
"#;
const FRAGMENT_SHADER: &str = r#"
#version 450
layout(location = 0) out vec4 outColor;
void main() {
outColor = vec4(1.0, 1.0, 1.0, 1.0);
}
"#;
pub struct Example {
shaders: HashMap<ShaderStage, Shader>,
}
impl WindowHandler for Example {
fn load(_window: &Window, _resources: &Resources, renderer: &mut Renderer) -> Self where Self: Sized {
let vertex_shader = renderer.create_shader(&VERTEX_SHADER, ShaderStage::Vertex);
let fragment_shader = renderer.create_shader(&FRAGMENT_SHADER, ShaderStage::Fragment);
let mut shaders = HashMap::new();
shaders.insert(ShaderStage::Vertex, vertex_shader);
shaders.insert(ShaderStage::Fragment, fragment_shader);
Example {
shaders,
}
}
fn update(&mut self, _resources: &Resources) {
}
fn render(&mut self, window: &mut Window, renderer: &mut Renderer) {
let mut pass_descriptor = window.into();
renderer.begin_pass(&mut pass_descriptor, &mut |_render_pass| {
});
}
}
fn main() {
let settings = WindowSettings::default()
.with_title("Test")
.with_mode(WindowMode::Windowed);
Example::run(settings);
}