use crate::wgpu::{
buffer::Buffer, buffers::BindGroup, material::RenderPipeline, render_pass::IndexFormat,
texture_format::TextureFormat,
};
pub struct RenderBundleEncoderDescriptor<'a> {
pub label: Option<&'a str>,
pub color_formats: Vec<Option<TextureFormat>>,
pub depth_stencil_format: Option<TextureFormat>,
pub depth_read_only: bool,
pub stencil_read_only: bool,
pub sample_count: u32,
}
impl<'a> Default for RenderBundleEncoderDescriptor<'a> {
fn default() -> Self {
Self {
label: None,
color_formats: Vec::new(),
depth_stencil_format: None,
depth_read_only: false,
stencil_read_only: false,
sample_count: 1,
}
}
}
pub struct RenderBundleEncoder<'a> {
raw: wgpu::RenderBundleEncoder<'a>,
}
impl<'a> RenderBundleEncoder<'a> {
pub(crate) fn new(raw: wgpu::RenderBundleEncoder<'a>) -> Self {
Self { raw }
}
pub fn set_pipeline(&mut self, pipeline: &'a RenderPipeline) {
self.raw.set_pipeline(pipeline.raw());
}
pub fn set_bind_group(&mut self, index: u32, bind_group: &'a BindGroup, offsets: &[u32]) {
self.raw.set_bind_group(index, Some(bind_group.raw()), offsets);
}
pub fn set_vertex_buffer(&mut self, slot: u32, buffer: &'a Buffer) {
self.raw.set_vertex_buffer(slot, buffer.raw().slice(..));
}
pub fn set_index_buffer(&mut self, buffer: &'a Buffer, format: IndexFormat) {
self.raw.set_index_buffer(buffer.raw().slice(..), format.into());
}
pub fn draw(&mut self, vertices: std::ops::Range<u32>, instances: std::ops::Range<u32>) {
self.raw.draw(vertices, instances);
}
pub fn draw_indexed(
&mut self,
indices: std::ops::Range<u32>,
base_vertex: i32,
instances: std::ops::Range<u32>,
) {
self.raw.draw_indexed(indices, base_vertex, instances);
}
pub fn finish(self, label: Option<&str>) -> RenderBundle {
RenderBundle(self.raw.finish(&wgpu::RenderBundleDescriptor { label }))
}
}
pub struct RenderBundle(wgpu::RenderBundle);
impl RenderBundle {
pub(crate) fn raw(&self) -> &wgpu::RenderBundle {
&self.0
}
}