-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy path10_fixed_functions.rs.diff
77 lines (71 loc) · 2.82 KB
/
10_fixed_functions.rs.diff
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
--- a/08_graphics_pipeline.rs
+++ b/10_fixed_functions.rs
@@ -30,6 +30,11 @@ use vulkano::swapchain::{
use vulkano::format::Format;
use vulkano::image::{ImageUsage, swapchain::SwapchainImage};
use vulkano::sync::SharingMode;
+use vulkano::pipeline::{
+ GraphicsPipeline,
+ vertex::BufferlessDefinition,
+ viewport::Viewport,
+};
const WIDTH: u32 = 800;
const HEIGHT: u32 = 600;
@@ -96,7 +101,7 @@ impl HelloTriangleApplication {
let (swap_chain, swap_chain_images) = Self::create_swap_chain(&instance, &surface, physical_device_index,
&device, &graphics_queue, &present_queue);
- Self::create_graphics_pipeline(&device);
+ Self::create_graphics_pipeline(&device, swap_chain.dimensions());
Self {
instance,
@@ -290,8 +295,52 @@ impl HelloTriangleApplication {
(swap_chain, images)
}
- fn create_graphics_pipeline(_device: &Arc<Device>) {
+ fn create_graphics_pipeline(
+ device: &Arc<Device>,
+ swap_chain_extent: [u32; 2],
+ ) {
+ mod vertex_shader {
+ vulkano_shaders::shader! {
+ ty: "vertex",
+ path: "src/bin/09_shader_base.vert"
+ }
+ }
+
+ mod fragment_shader {
+ vulkano_shaders::shader! {
+ ty: "fragment",
+ path: "src/bin/09_shader_base.frag"
+ }
+ }
+
+ let vert_shader_module = vertex_shader::Shader::load(device.clone())
+ .expect("failed to create vertex shader module!");
+ let frag_shader_module = fragment_shader::Shader::load(device.clone())
+ .expect("failed to create fragment shader module!");
+
+ let dimensions = [swap_chain_extent[0] as f32, swap_chain_extent[1] as f32];
+ let viewport = Viewport {
+ origin: [0.0, 0.0],
+ dimensions,
+ depth_range: 0.0 .. 1.0,
+ };
+ let _pipeline_builder = Arc::new(GraphicsPipeline::start()
+ .vertex_input(BufferlessDefinition {})
+ .vertex_shader(vert_shader_module.main_entry_point(), ())
+ .triangle_list()
+ .primitive_restart(false)
+ .viewports(vec![viewport]) // NOTE: also sets scissor to cover whole viewport
+ .fragment_shader(frag_shader_module.main_entry_point(), ())
+ .depth_clamp(false)
+ // NOTE: there's an outcommented .rasterizer_discard() in Vulkano...
+ .polygon_mode_fill() // = default
+ .line_width(1.0) // = default
+ .cull_mode_back()
+ .front_face_clockwise()
+ // NOTE: no depth_bias here, but on pipeline::raster::Rasterization
+ .blend_pass_through() // = default
+ );
}
fn find_queue_families(surface: &Arc<Surface<Window>>, device: &PhysicalDevice) -> QueueFamilyIndices {