-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rt(wgpu): add structure to wgpu backend
- Loading branch information
Showing
19 changed files
with
566 additions
and
282 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use array_concat::concat_arrays; | ||
use librashader_runtime::quad::QuadType; | ||
use wgpu::util::{BufferInitDescriptor, DeviceExt}; | ||
use wgpu::{Buffer, BufferDescriptor, Device, RenderPass}; | ||
|
||
#[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, | ||
]; | ||
|
||
static VBO_DATA: &[f32; 32] = &concat_arrays!(VBO_OFFSCREEN, VBO_DEFAULT_FINAL); | ||
pub struct DrawQuad { | ||
buffer: Buffer, | ||
} | ||
|
||
impl DrawQuad { | ||
pub fn new(device: &Device) -> DrawQuad { | ||
let buffer = device.create_buffer_init(&BufferInitDescriptor { | ||
label: Some("librashader vbo"), | ||
contents: bytemuck::cast_slice(VBO_DATA), | ||
usage: wgpu::BufferUsages::VERTEX, | ||
}); | ||
|
||
DrawQuad { buffer } | ||
} | ||
|
||
pub fn bind_vbo_for_frame<'a, 'b: 'a>(&'b self, cmd: &mut RenderPass<'a>) { | ||
cmd.set_vertex_buffer(0, self.buffer.slice(0..)); | ||
} | ||
|
||
pub fn draw_quad<'a, 'b: 'a>(&'b self, cmd: &mut RenderPass<'a>, vbo: QuadType) { | ||
let offset = match vbo { | ||
QuadType::Offscreen => 0..3, | ||
QuadType::Final => 1..4, | ||
}; | ||
|
||
cmd.draw(offset, 0..1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.