mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-12-22 03:48:21 -06:00
do rpass in world.rs
This commit is contained in:
parent
baf037d4a5
commit
3f768a8318
|
@ -14,12 +14,20 @@ pub mod sumberge;
|
|||
|
||||
pub struct BufferPair {
|
||||
pub index: wgpu::Buffer,
|
||||
pub index_len: u32,
|
||||
pub vertex: wgpu::Buffer,
|
||||
pub vertex_len: u32,
|
||||
}
|
||||
|
||||
#[derive(Unique)]
|
||||
pub struct BackgroundColor(pub Vec3);
|
||||
|
||||
pub struct RenderCtx<'a> {
|
||||
pub renderer: &'a Renderer,
|
||||
pub encoder: &'a mut wgpu::CommandEncoder,
|
||||
pub surface_view: &'a wgpu::TextureView,
|
||||
}
|
||||
|
||||
pub fn render_master(storages: AllStoragesViewMut) {
|
||||
let renderer = storages.borrow::<UniqueView<Renderer>>().unwrap();
|
||||
|
||||
|
@ -29,11 +37,10 @@ pub fn render_master(storages: AllStoragesViewMut) {
|
|||
let surface_texture = renderer.surface().get_current_texture().unwrap();
|
||||
let surface_view = surface_texture.texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
|
||||
//Main in-game render pass
|
||||
if storages.run(is_ingame) {
|
||||
{
|
||||
let bg = storages.borrow::<UniqueView<BackgroundColor>>().unwrap().0;
|
||||
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
label: Some("main0_pass"),
|
||||
let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
label: Some("rpass_background"),
|
||||
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
|
||||
view: &surface_view,
|
||||
resolve_target: None,
|
||||
|
@ -50,10 +57,16 @@ pub fn render_master(storages: AllStoragesViewMut) {
|
|||
depth_stencil_attachment: None,
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
||||
let data = (&mut render_pass, &*renderer);
|
||||
let mut data = RenderCtx {
|
||||
renderer: &renderer,
|
||||
encoder: &mut encoder,
|
||||
surface_view: &surface_view,
|
||||
};
|
||||
|
||||
storages.run_with_data(world::draw_world, data);
|
||||
if storages.run(is_ingame) {
|
||||
storages.run_with_data(world::draw_world, &mut data);
|
||||
}
|
||||
|
||||
renderer.queue().submit(std::iter::once(encoder.finish()));
|
||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
|||
settings::GameSettings,
|
||||
world::{ChunkMeshStorage, ChunkStorage},
|
||||
};
|
||||
use super::Renderer;
|
||||
use super::{RenderCtx, Renderer};
|
||||
|
||||
#[derive(Clone, Copy, Pod, Zeroable)]
|
||||
#[repr(C, packed)]
|
||||
|
@ -41,7 +41,7 @@ pub fn init_trans_chunk_queue(storages: AllStoragesView) {
|
|||
}
|
||||
|
||||
pub fn draw_world(
|
||||
(render_pass, renderer): (&mut wgpu::RenderPass, &Renderer),
|
||||
ctx: &mut RenderCtx,
|
||||
textures: UniqueView<TexturePrefabs>,
|
||||
chunks: UniqueView<ChunkStorage>,
|
||||
meshes: NonSendSync<UniqueView<ChunkMeshStorage>>,
|
||||
|
@ -53,6 +53,19 @@ pub fn draw_world(
|
|||
let camera = camera.iter().next().expect("No cameras in the scene");
|
||||
let camera_matrix = camera.view_matrix * camera.perspective_matrix;
|
||||
|
||||
let mut render_pass = ctx.encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
label: Some("draw_world"),
|
||||
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
|
||||
view: ctx.surface_view,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Load,
|
||||
store: wgpu::StoreOp::Store,
|
||||
},
|
||||
})],
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
for (&position, chunk) in &chunks.chunks {
|
||||
if let Some(key) = chunk.mesh_index {
|
||||
let mesh = meshes.get(key).expect("Mesh index pointing to nothing");
|
||||
|
@ -73,9 +86,10 @@ pub fn draw_world(
|
|||
//Draw chunk mesh
|
||||
if mesh.main.index.size() > 0 {
|
||||
//TODO
|
||||
// render_pass.set_index_buffer(mesh.main.index.slice(..), wgpu::IndexFormat::Uint32);
|
||||
// render_pass.set_vertex_buffer(0, mesh.main.vertex.slice(..));
|
||||
// render_pass.set_bind_group(0, &textures.block_diffuse_bind_group, &[]);
|
||||
render_pass.set_index_buffer(mesh.main.index.slice(..), wgpu::IndexFormat::Uint32);
|
||||
render_pass.set_vertex_buffer(0, mesh.main.vertex.slice(..));
|
||||
render_pass.set_bind_group(0, &textures.block_diffuse_bind_group, &[]);
|
||||
render_pass.draw_indexed(0..mesh.main.index_len, 0, 0..1);
|
||||
}
|
||||
|
||||
//TODO trans chunks
|
||||
|
|
|
@ -355,12 +355,16 @@ fn process_completed_tasks(
|
|||
|
||||
let main_buffer_pair = BufferPair {
|
||||
vertex: vtx_buffer,
|
||||
vertex_len: vertices.len() as u32,
|
||||
index: idx_buffer,
|
||||
index_len: indices.len() as u32,
|
||||
};
|
||||
|
||||
let trans_buffer_pair = BufferPair {
|
||||
vertex: vtx_buffer_trans,
|
||||
vertex_len: vertices.len() as u32,
|
||||
index: idx_buffer_trans,
|
||||
index_len: indices.len() as u32,
|
||||
};
|
||||
|
||||
let mesh = ChunkMesh {
|
||||
|
|
Loading…
Reference in a new issue