Hide Storage from Primitive for type-safety
This commit is contained in:
parent
6a1cd02b3a
commit
53a98bf7de
5 changed files with 129 additions and 45 deletions
|
|
@ -128,26 +128,25 @@ impl Primitive {
|
|||
}
|
||||
|
||||
impl shader::Primitive for Primitive {
|
||||
fn prepare(
|
||||
type Renderer = Pipeline;
|
||||
|
||||
fn initialize(
|
||||
&self,
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
format: wgpu::TextureFormat,
|
||||
storage: &mut shader::Storage,
|
||||
) -> Pipeline {
|
||||
Pipeline::new(device, queue, format)
|
||||
}
|
||||
|
||||
fn prepare(
|
||||
&self,
|
||||
pipeline: &mut Pipeline,
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
_bounds: &Rectangle,
|
||||
viewport: &Viewport,
|
||||
) {
|
||||
if !storage.has::<Pipeline>() {
|
||||
storage.store(Pipeline::new(
|
||||
device,
|
||||
queue,
|
||||
format,
|
||||
viewport.physical_size(),
|
||||
));
|
||||
}
|
||||
|
||||
let pipeline = storage.get_mut::<Pipeline>().unwrap();
|
||||
|
||||
// Upload data to GPU
|
||||
pipeline.update(
|
||||
device,
|
||||
|
|
@ -161,14 +160,11 @@ impl shader::Primitive for Primitive {
|
|||
|
||||
fn render(
|
||||
&self,
|
||||
pipeline: &Pipeline,
|
||||
encoder: &mut wgpu::CommandEncoder,
|
||||
storage: &shader::Storage,
|
||||
target: &wgpu::TextureView,
|
||||
clip_bounds: &Rectangle<u32>,
|
||||
) {
|
||||
// At this point our pipeline should always be initialized
|
||||
let pipeline = storage.get::<Pipeline>().unwrap();
|
||||
|
||||
// Render primitive
|
||||
pipeline.render(
|
||||
target,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue