@@ -14,12 +14,13 @@ use wasm_bindgen::prelude::*;
14
14
15
15
16
16
struct State {
17
- surface : wgpu:: Surface ,
18
- device : wgpu:: Device ,
19
- queue : wgpu:: Queue ,
20
- config : wgpu:: SurfaceConfiguration ,
21
- size : winit:: dpi:: PhysicalSize < u32 > ,
22
- window : Window ,
17
+ surface : wgpu:: Surface ,
18
+ device : wgpu:: Device ,
19
+ queue : wgpu:: Queue ,
20
+ config : wgpu:: SurfaceConfiguration ,
21
+ size : winit:: dpi:: PhysicalSize < u32 > ,
22
+ window : Window ,
23
+ render_pipeline : wgpu:: RenderPipeline ,
23
24
}
24
25
25
26
// ============================================================
@@ -89,13 +90,90 @@ impl State {
89
90
90
91
surface. configure ( & device, & config) ;
91
92
93
+ let shader = device. create_shader_module (
94
+ wgpu:: include_wgsl!( "shader.wgsl" ) ,
95
+ ) ;
96
+
97
+ let render_pipeline_layout = device. create_pipeline_layout (
98
+ & wgpu:: PipelineLayoutDescriptor {
99
+ label : Some ( "Render pipeline layout" ) ,
100
+ bind_group_layouts : & [ ] ,
101
+ push_constant_ranges : & [ ] ,
102
+ } ,
103
+ ) ;
104
+
105
+ let render_pipeline = device. create_render_pipeline (
106
+ & wgpu:: RenderPipelineDescriptor {
107
+ label : Some ( "Render pipeline" ) ,
108
+ layout : Some ( & render_pipeline_layout) ,
109
+
110
+ vertex : wgpu:: VertexState {
111
+ module : & shader,
112
+ entry_point : "vs_main" ,
113
+
114
+ // This tells `wgpu` what type of vertices to pass to the
115
+ // vertex shader. Since we're specifying the vertices in the vertex
116
+ // shader itself, empty is OK
117
+ buffers : & [ ] ,
118
+ } ,
119
+
120
+ // Stores color data to the `surface`
121
+ fragment : Some ( wgpu:: FragmentState {
122
+ module : & shader,
123
+ entry_point : "fs_main" ,
124
+
125
+ // Tells `wgpu` what color outputs it should set up. Currently,
126
+ // we only need one for the surface.
127
+ targets : & [ Some ( wgpu:: ColorTargetState {
128
+
129
+ // Uses the `surface` format so copying to it is easy
130
+ format : config. format ,
131
+
132
+ // Tells the blending to replace old pixel data with new data
133
+ blend : Some ( wgpu:: BlendState :: REPLACE ) ,
134
+
135
+ // Tells `wgpu` to write to all colors: red, blue, green, alpha
136
+ write_mask : wgpu:: ColorWrites :: ALL ,
137
+ } ) ] ,
138
+ } ) ,
139
+
140
+ primitive : wgpu:: PrimitiveState {
141
+
142
+ // Makes every three vertices correspond to one triangle
143
+ topology : wgpu:: PrimitiveTopology :: TriangleList ,
144
+ strip_index_format : None ,
145
+
146
+ // Defines the forward direction
147
+ front_face : wgpu:: FrontFace :: Ccw ,
148
+
149
+ // Culls triangles which are not facing forward
150
+ cull_mode : Some ( wgpu:: Face :: Back ) ,
151
+
152
+ unclipped_depth : false ,
153
+ polygon_mode : wgpu:: PolygonMode :: Fill ,
154
+ conservative : false ,
155
+ } ,
156
+
157
+ depth_stencil : None ,
158
+
159
+ multisample : wgpu:: MultisampleState {
160
+ count : 1 ,
161
+ mask : !0 ,
162
+ alpha_to_coverage_enabled : false ,
163
+ } ,
164
+
165
+ multiview : None ,
166
+ } ,
167
+ ) ;
168
+
92
169
Self {
93
170
window,
94
171
surface,
95
172
device,
96
173
queue,
97
174
config,
98
175
size,
176
+ render_pipeline,
99
177
}
100
178
}
101
179
0 commit comments