mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 06:30:19 +00:00
render: add AssetRenderResourceBindings
This commit is contained in:
parent
f799d3ac93
commit
8a704a3e28
3 changed files with 29 additions and 19 deletions
|
@ -38,9 +38,9 @@ use bevy_type_registry::RegisterType;
|
|||
use draw::{clear_draw_system, draw_system, Draw};
|
||||
use legion::prelude::IntoSystem;
|
||||
use mesh::mesh_resource_provider_system;
|
||||
use pipeline::{RenderPipelines, compile_pipelines_system};
|
||||
use pipeline::{compile_pipelines_system, RenderPipelines};
|
||||
use render_graph::{system::render_graph_schedule_executor_system, RenderGraph};
|
||||
use render_resource::bind_groups_system;
|
||||
use render_resource::{bind_groups_system, AssetRenderResourceBindings};
|
||||
use std::ops::Range;
|
||||
use texture::{PngTextureLoader, TextureResourceSystemState};
|
||||
|
||||
|
@ -92,6 +92,7 @@ impl AppPlugin for RenderPlugin {
|
|||
.init_resource::<RenderResourceBindings>()
|
||||
.init_resource::<VertexBufferDescriptors>()
|
||||
.init_resource::<TextureResourceSystemState>()
|
||||
.init_resource::<AssetRenderResourceBindings>()
|
||||
.add_system_to_stage(bevy_app::stage::PRE_UPDATE, clear_draw_system.system())
|
||||
.init_system_to_stage(
|
||||
bevy_app::stage::POST_UPDATE,
|
||||
|
@ -115,10 +116,7 @@ impl AppPlugin for RenderPlugin {
|
|||
stage::RENDER_GRAPH_SYSTEMS,
|
||||
compile_pipelines_system.system(),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
stage::RENDER_GRAPH_SYSTEMS,
|
||||
bind_groups_system.system(),
|
||||
)
|
||||
.add_system_to_stage(stage::RENDER_GRAPH_SYSTEMS, bind_groups_system.system())
|
||||
.add_system_to_stage(stage::DRAW, draw_system::<RenderPipelines>.system());
|
||||
|
||||
if let Some(ref config) = self.base_render_graph_config {
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::{
|
|||
|
||||
use bevy_asset::{Assets, Handle};
|
||||
use legion::prelude::*;
|
||||
use render_resource::{BufferId, RenderResourceType};
|
||||
use render_resource::{AssetRenderResourceBindings, BufferId, RenderResourceType};
|
||||
use std::{collections::HashMap, marker::PhantomData};
|
||||
|
||||
pub const BIND_BUFFER_ALIGNMENT: usize = 256;
|
||||
|
@ -497,12 +497,11 @@ where
|
|||
let mut command_queue = self.command_queue.clone();
|
||||
let mut uniform_buffer_arrays = UniformBufferArrays::<T>::default();
|
||||
// let mut asset_event_reader = EventReader::<AssetEvent<T>>::default();
|
||||
let mut asset_render_resource_bindings =
|
||||
HashMap::<Handle<T>, RenderResourceBindings>::default();
|
||||
let dynamic_uniforms = self.dynamic_uniforms;
|
||||
(move |world: &mut SubWorld,
|
||||
assets: Res<Assets<T>>,
|
||||
// asset_events: Res<Events<AssetEvent<T>>>,
|
||||
mut asset_render_resource_bindings: ResMut<AssetRenderResourceBindings>,
|
||||
render_resource_context: Res<Box<dyn RenderResourceContext>>,
|
||||
query: &mut Query<(Read<Handle<T>>, Read<Draw>, Write<RenderPipelines>)>| {
|
||||
let render_resource_context = &**render_resource_context;
|
||||
|
@ -540,9 +539,8 @@ where
|
|||
|
||||
for asset_handle in modified_assets.iter() {
|
||||
let asset = assets.get(&asset_handle).expect(EXPECT_ASSET_MESSAGE);
|
||||
let mut render_resource_bindings = asset_render_resource_bindings
|
||||
.entry(*asset_handle)
|
||||
.or_insert_with(|| RenderResourceBindings::default());
|
||||
let mut render_resource_bindings =
|
||||
asset_render_resource_bindings.get_or_insert_mut(*asset_handle);
|
||||
setup_uniform_texture_resources::<T>(
|
||||
&asset,
|
||||
render_resource_context,
|
||||
|
@ -554,9 +552,8 @@ where
|
|||
let mut staging_buffer: [u8; 0] = [];
|
||||
for asset_handle in modified_assets.iter() {
|
||||
let asset = assets.get(&asset_handle).expect(EXPECT_ASSET_MESSAGE);
|
||||
let mut render_resource_bindings = asset_render_resource_bindings
|
||||
.entry(*asset_handle)
|
||||
.or_insert_with(|| RenderResourceBindings::default());
|
||||
let mut render_resource_bindings =
|
||||
asset_render_resource_bindings.get_or_insert_mut(*asset_handle);
|
||||
// TODO: only setup buffer if we haven't seen this handle before
|
||||
uniform_buffer_arrays.setup_uniform_buffer_resources(
|
||||
&asset,
|
||||
|
@ -576,9 +573,8 @@ where
|
|||
&mut |mut staging_buffer, _render_resource_context| {
|
||||
for asset_handle in modified_assets.iter() {
|
||||
let asset = assets.get(&asset_handle).expect(EXPECT_ASSET_MESSAGE);
|
||||
let mut render_resource_bindings = asset_render_resource_bindings
|
||||
.entry(*asset_handle)
|
||||
.or_insert_with(|| RenderResourceBindings::default());
|
||||
let mut render_resource_bindings =
|
||||
asset_render_resource_bindings.get_or_insert_mut(*asset_handle);
|
||||
// TODO: only setup buffer if we haven't seen this handle before
|
||||
uniform_buffer_arrays.setup_uniform_buffer_resources(
|
||||
&asset,
|
||||
|
@ -597,7 +593,7 @@ where
|
|||
}
|
||||
|
||||
for (asset_handle, _draw, mut render_pipelines) in query.iter_mut(world) {
|
||||
if let Some(asset_bindings) = asset_render_resource_bindings.get(&asset_handle) {
|
||||
if let Some(asset_bindings) = asset_render_resource_bindings.get(*asset_handle) {
|
||||
render_pipelines.bindings.extend(asset_bindings);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use std::{
|
|||
ops::Range,
|
||||
};
|
||||
use uuid::Uuid;
|
||||
use bevy_asset::{HandleUntyped, Handle};
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Debug)]
|
||||
pub enum RenderResourceBinding {
|
||||
|
@ -186,6 +187,21 @@ impl RenderResourceBindings {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct AssetRenderResourceBindings {
|
||||
pub bindings: HashMap<HandleUntyped, RenderResourceBindings>,
|
||||
}
|
||||
|
||||
impl AssetRenderResourceBindings {
|
||||
pub fn get<T>(&self, handle: Handle<T>) -> Option<&RenderResourceBindings> {
|
||||
self.bindings.get(&HandleUntyped::from(handle))
|
||||
}
|
||||
|
||||
pub fn get_or_insert_mut<T>(&mut self, handle: Handle<T>) -> &mut RenderResourceBindings {
|
||||
self.bindings.entry(HandleUntyped::from(handle)).or_insert_with(|| RenderResourceBindings::default())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Hash, Eq, PartialEq, Debug, Copy, Clone)]
|
||||
pub struct RenderResourceBindingsId(Uuid);
|
||||
|
||||
|
|
Loading…
Reference in a new issue