use serde::{Deserialize, Serialize};
use wgpu_core::command::{RenderPass, RenderPassError};
use wgpu_core::global::Global;
use crate::wgc::id;
use crate::wgt;
#[derive(Debug, Deserialize, Serialize)]
pub enum RenderCommand {
SetPipeline(id::RenderPipelineId),
SetBindGroup {
index: u32,
bind_group_id: id::BindGroupId,
offsets: Vec<u32>,
},
SetViewport {
x: f32,
y: f32,
width: f32,
height: f32,
min_depth: f32,
max_depth: f32,
},
SetScissorRect {
x: u32,
y: u32,
width: u32,
height: u32,
},
SetBlendConstant(wgt::Color),
SetStencilReference(u32),
SetIndexBuffer {
buffer_id: id::BufferId,
index_format: wgt::IndexFormat,
offset: u64,
size: Option<wgt::BufferSize>,
},
SetVertexBuffer {
slot: u32,
buffer_id: id::BufferId,
offset: u64,
size: Option<wgt::BufferSize>,
},
Draw {
vertex_count: u32,
instance_count: u32,
first_vertex: u32,
first_instance: u32,
},
DrawIndexed {
index_count: u32,
instance_count: u32,
first_index: u32,
base_vertex: i32,
first_instance: u32,
},
DrawIndirect {
buffer_id: id::BufferId,
offset: u64,
},
DrawIndexedIndirect {
buffer_id: id::BufferId,
offset: u64,
},
ExecuteBundles(Vec<id::RenderBundleId>),
}
pub fn apply_render_command(
global: &Global,
pass: &mut RenderPass,
command: RenderCommand,
) -> Result<(), RenderPassError> {
match command {
RenderCommand::SetPipeline(pipeline_id) => {
global.render_pass_set_pipeline(pass, pipeline_id)
},
RenderCommand::SetBindGroup {
index,
bind_group_id,
offsets,
} => global.render_pass_set_bind_group(pass, index, Some(bind_group_id), &offsets),
RenderCommand::SetViewport {
x,
y,
width,
height,
min_depth,
max_depth,
} => global.render_pass_set_viewport(pass, x, y, width, height, min_depth, max_depth),
RenderCommand::SetScissorRect {
x,
y,
width,
height,
} => global.render_pass_set_scissor_rect(pass, x, y, width, height),
RenderCommand::SetBlendConstant(color) => {
global.render_pass_set_blend_constant(pass, color)
},
RenderCommand::SetStencilReference(reference) => {
global.render_pass_set_stencil_reference(pass, reference)
},
RenderCommand::SetIndexBuffer {
buffer_id,
index_format,
offset,
size,
} => global.render_pass_set_index_buffer(pass, buffer_id, index_format, offset, size),
RenderCommand::SetVertexBuffer {
slot,
buffer_id,
offset,
size,
} => global.render_pass_set_vertex_buffer(pass, slot, buffer_id, offset, size),
RenderCommand::Draw {
vertex_count,
instance_count,
first_vertex,
first_instance,
} => global.render_pass_draw(
pass,
vertex_count,
instance_count,
first_vertex,
first_instance,
),
RenderCommand::DrawIndexed {
index_count,
instance_count,
first_index,
base_vertex,
first_instance,
} => global.render_pass_draw_indexed(
pass,
index_count,
instance_count,
first_index,
base_vertex,
first_instance,
),
RenderCommand::DrawIndirect { buffer_id, offset } => {
global.render_pass_draw_indirect(pass, buffer_id, offset)
},
RenderCommand::DrawIndexedIndirect { buffer_id, offset } => {
global.render_pass_draw_indexed_indirect(pass, buffer_id, offset)
},
RenderCommand::ExecuteBundles(bundles) => {
global.render_pass_execute_bundles(pass, &bundles)
},
}
}