simple_wgpu/
draw_call.rs

1use std::ops::Range;
2
3use crate::{bind_group::BindGroup, buffer::BufferSlice, render_pipeline::RenderPipeline};
4
5/// The set of rendering state that is convenient to vary on a per-draw basis
6#[derive(Debug, Clone, Hash, PartialEq, Eq)]
7pub struct RasteriserState {
8    pub front_face: wgpu::FrontFace,
9    pub cull_mode: Option<wgpu::Face>,
10    pub depth_write: bool,
11    pub depth_compare: wgpu::CompareFunction,
12    pub polygon_mode: wgpu::PolygonMode,
13}
14
15impl Default for RasteriserState {
16    fn default() -> Self {
17        Self {
18            front_face: wgpu::FrontFace::Ccw,
19            cull_mode: None,
20            depth_write: true,
21            depth_compare: wgpu::CompareFunction::LessEqual,
22            polygon_mode: wgpu::PolygonMode::Fill,
23        }
24    }
25}
26
27/// All of the data needed to issue a single draw call
28#[derive(Debug)]
29pub struct DrawCall {
30    pub bind_groups: Vec<BindGroup>,
31    pub bind_group_offsets: Vec<Vec<u32>>,
32    pub pipeline: RenderPipeline,
33    /// The vertex buffers, if any
34    ///
35    /// The provided buffers will be bound in order to vertex buffer slots 0..N
36    pub vertices: Vec<BufferSlice>,
37    /// The index buffer, if any
38    ///
39    /// If `indices` is `None`, the mesh data will be treated as unindexed
40    pub indices: Option<BufferSlice>,
41    /// The range of vertices to draw
42    pub element_range: Range<usize>,
43    /// The range of instances to draw
44    ///
45    /// You can pass `0..1` to disable instancing
46    pub instance_range: Range<usize>,
47    /// Additional state that is convenient to vary on a per-draw basis
48    pub rasteriser_state: RasteriserState,
49}