Add basic render/compute pass system
This commit is contained in:
parent
ee5308ac23
commit
a0ed278d24
|
@ -8,6 +8,9 @@ use winit::{
|
|||
event_loop::{EventLoop, EventLoopWindowTarget},
|
||||
window::{Window, WindowBuilder},
|
||||
};
|
||||
pub trait Pass {
|
||||
fn execute(&self, encoder: &mut wgpu::CommandEncoder, view: &wgpu::TextureView);
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ContextError {
|
||||
|
@ -23,6 +26,8 @@ pub enum ContextError {
|
|||
EventLoop(#[from] EventLoopError),
|
||||
#[error("Window creation failed: {0}")]
|
||||
Os(#[from] OsError),
|
||||
#[error("Render failed: {0}")]
|
||||
Render(#[from] wgpu::SurfaceError),
|
||||
}
|
||||
|
||||
pub struct Context<'window> {
|
||||
|
@ -138,6 +143,28 @@ impl<'window> Context<'window> {
|
|||
|
||||
handled
|
||||
}
|
||||
|
||||
pub fn render(&self, passes: &[Box<dyn Pass>]) -> Result<(), ContextError> {
|
||||
let frame = self.surface.get_current_texture()?;
|
||||
let view = frame
|
||||
.texture
|
||||
.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
|
||||
let mut encoder = self
|
||||
.device
|
||||
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
||||
label: Some("Base Render Encoder"),
|
||||
});
|
||||
|
||||
for pass in passes.iter() {
|
||||
pass.execute(&mut encoder, &view);
|
||||
}
|
||||
|
||||
self.queue.submit(Some(encoder.finish()));
|
||||
frame.present();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ContextBuilder {
|
||||
|
|
|
@ -7,7 +7,7 @@ mod texture;
|
|||
pub use self::{
|
||||
bind_group::{BindGroupBuilder, BindGroupLayoutBuilder},
|
||||
buffer::{BufferExt, BulkBufferBuilder},
|
||||
context::{Context, ContextBuilder},
|
||||
context::{Context, ContextBuilder, Pass},
|
||||
pipeline::{ComputePipelineBuilder, RenderPipelineBuilder},
|
||||
texture::{Texture, TextureBuilder},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue