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
|
use std::{fmt::Display};
use std::error::Error;
use wgpu::RenderPass;
use crate::solar_system::Kilometers;
use crate::tacmap::camera::Camera;
use crate::timeman::{DAY, SYSTEM_TICK_INTERVAL};
use crate::{solar_system::{SolarSystem, SystemId}, timeman::Second, vertex::{self, Vertex}, wgpuctx::{WgpuCtx, pipeline::RenderPipelineBuilder}};
#[derive(Debug, Clone)]
pub struct NeedsRebuildError;
impl Display for NeedsRebuildError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "RenderState needs to be rebuilt before updating!")
}
}
impl Error for NeedsRebuildError {}
pub struct GridRenderer
{
pipeline: wgpu::RenderPipeline,
}
impl GridRenderer
{
pub fn new(wgpuctx: &WgpuCtx)
-> Self
{
let shader = wgpuctx.create_shader(
wgpu::include_wgsl!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/shaders/tacmap/grid.wgsl")
));
let render_pipeline = RenderPipelineBuilder::new(&shader)
.add_bindgroup(&Camera::bindgroup_layout(wgpuctx))
.cull_mode(None)
.build(Some("Tactical map grid pipeline"), wgpuctx);
Self {
pipeline: render_pipeline
}
}
pub fn render(
&self,
pass: &mut RenderPass,
camera: &Camera
)
{
pass.set_pipeline(&self.pipeline);
pass.set_bind_group(0, camera.bindgroup(), &[]);
pass.draw(0..6, 0..1);
}
} //impl GridRenderer
|