2023-12-16 22:28:41 +11:00
|
|
|
use array_concat::concat_arrays;
|
|
|
|
use librashader_runtime::quad::QuadType;
|
|
|
|
use wgpu::util::{BufferInitDescriptor, DeviceExt};
|
2024-01-18 14:35:52 +11:00
|
|
|
use wgpu::{Buffer, BufferAddress, BufferDescriptor, Device, Maintain, Queue, RenderPass};
|
2023-12-16 22:28:41 +11:00
|
|
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
const VBO_OFFSCREEN: [f32; 16] = [
|
|
|
|
// Offscreen
|
|
|
|
-1.0f32, -1.0, 0.0, 0.0,
|
|
|
|
-1.0, 1.0, 0.0, 1.0,
|
|
|
|
1.0, -1.0, 1.0, 0.0,
|
|
|
|
1.0, 1.0, 1.0, 1.0,
|
|
|
|
];
|
|
|
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
const VBO_DEFAULT_FINAL: [f32; 16] = [
|
|
|
|
// Final
|
|
|
|
0.0f32, 0.0, 0.0, 0.0,
|
|
|
|
0.0, 1.0, 0.0, 1.0,
|
|
|
|
1.0, 0.0, 1.0, 0.0,
|
|
|
|
1.0, 1.0, 1.0, 1.0,
|
|
|
|
];
|
|
|
|
|
2024-01-18 14:35:52 +11:00
|
|
|
const VBO_DATA: [f32; 32] = concat_arrays!(VBO_OFFSCREEN, VBO_DEFAULT_FINAL);
|
|
|
|
|
2023-12-16 22:28:41 +11:00
|
|
|
pub struct DrawQuad {
|
|
|
|
buffer: Buffer,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DrawQuad {
|
2024-02-06 16:29:45 +11:00
|
|
|
pub fn new(device: &Device) -> DrawQuad {
|
2023-12-16 22:28:41 +11:00
|
|
|
let buffer = device.create_buffer_init(&BufferInitDescriptor {
|
|
|
|
label: Some("librashader vbo"),
|
2024-01-18 14:35:52 +11:00
|
|
|
contents: bytemuck::cast_slice(&VBO_DATA),
|
2023-12-16 22:28:41 +11:00
|
|
|
usage: wgpu::BufferUsages::VERTEX,
|
|
|
|
});
|
|
|
|
|
|
|
|
DrawQuad { buffer }
|
|
|
|
}
|
|
|
|
|
2024-02-06 16:29:45 +11:00
|
|
|
pub fn draw_quad<'a, 'b: 'a>(&'b self, cmd: &mut RenderPass<'a>, vbo: QuadType) {
|
2023-12-16 22:28:41 +11:00
|
|
|
cmd.set_vertex_buffer(0, self.buffer.slice(0..));
|
|
|
|
|
|
|
|
let offset = match vbo {
|
2024-02-06 16:29:45 +11:00
|
|
|
QuadType::Offscreen => 0..4,
|
|
|
|
QuadType::Final => 4..8,
|
2023-12-16 22:28:41 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
cmd.draw(offset, 0..1)
|
|
|
|
}
|
|
|
|
}
|