mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
default assets
This commit is contained in:
parent
f2b2065fbe
commit
89d72ae044
4 changed files with 43 additions and 5 deletions
|
@ -11,6 +11,7 @@ use std::{any::TypeId, collections::HashMap, marker::PhantomData};
|
|||
|
||||
// TODO: move these types to their own files
|
||||
pub type HandleId = usize;
|
||||
pub const DEFAULT_HANDLE_ID: HandleId = 0;
|
||||
|
||||
pub struct Handle<T> {
|
||||
pub id: HandleId,
|
||||
|
@ -58,11 +59,10 @@ impl<T> Debug for Handle<T> {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: somehow handle this gracefully in asset managers. or alternatively remove Default
|
||||
impl<T> Default for Handle<T> {
|
||||
fn default() -> Self {
|
||||
Handle {
|
||||
id: std::usize::MAX,
|
||||
id: DEFAULT_HANDLE_ID,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ impl<T> AssetStorage<T> {
|
|||
AssetStorage {
|
||||
assets: HashMap::new(),
|
||||
names: HashMap::new(),
|
||||
current_index: 0,
|
||||
current_index: 1,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,6 +139,11 @@ impl<T> AssetStorage<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn add_default(&mut self, asset: T) -> Handle<T> {
|
||||
self.assets.insert(DEFAULT_HANDLE_ID, asset);
|
||||
Handle::default()
|
||||
}
|
||||
|
||||
pub fn set_name(&mut self, name: &str, handle: Handle<T>) {
|
||||
self.names.insert(name.to_string(), handle);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ pub trait ForwardPipelineBuilder {
|
|||
|
||||
impl<'a, 'b, 'c> ForwardPipelineBuilder for RenderGraphBuilder<'a, 'b, 'c> {
|
||||
fn add_forward_pipeline(&mut self) -> &mut Self {
|
||||
self.add_pipeline(resource_name::pipeline::FORWARD, |builder| {
|
||||
self.add_default_pipeline(resource_name::pipeline::FORWARD, |builder| {
|
||||
builder
|
||||
.with_vertex_shader(Shader::from_glsl(
|
||||
ShaderStage::Vertex,
|
||||
|
|
|
@ -40,6 +40,20 @@ impl<'a, 'b, 'c> RenderGraphBuilder<'a, 'b, 'c> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn add_default_pipeline(&mut self, name: &str, build: impl Fn(&mut PipelineBuilder)) -> &mut Self {
|
||||
if let Some(ref pass) = self.current_pass {
|
||||
let mut builder = PipelineBuilder::new(name, &mut self.shaders);
|
||||
build(&mut builder);
|
||||
let pipeline = builder.finish();
|
||||
let pipeline_descriptor_handle = self.pipelines.add_default(pipeline);
|
||||
self.pipelines.set_name(name, pipeline_descriptor_handle);
|
||||
self.render_graph
|
||||
.add_pipeline(&pass, pipeline_descriptor_handle);
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_pipeline_to_pass(
|
||||
&mut self,
|
||||
pass: &str,
|
||||
|
@ -59,6 +73,25 @@ impl<'a, 'b, 'c> RenderGraphBuilder<'a, 'b, 'c> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn add_default_pipeline_to_pass(
|
||||
&mut self,
|
||||
pass: &str,
|
||||
name: &str,
|
||||
build: impl Fn(&mut PipelineBuilder),
|
||||
) -> &mut Self {
|
||||
{
|
||||
let mut builder = PipelineBuilder::new(name, &mut self.shaders);
|
||||
build(&mut builder);
|
||||
let pipeline = builder.finish();
|
||||
let pipeline_descriptor_handle = self.pipelines.add_default(pipeline);
|
||||
self.pipelines.set_name(name, pipeline_descriptor_handle);
|
||||
self.render_graph
|
||||
.add_pipeline(pass, pipeline_descriptor_handle);
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub fn add_resource_provider<T>(&mut self, resource_provider: T) -> &mut Self
|
||||
where
|
||||
T: ResourceProvider + Send + Sync + 'static,
|
||||
|
|
|
@ -24,7 +24,7 @@ impl Default for Renderable {
|
|||
Renderable {
|
||||
is_visible: true,
|
||||
pipelines: vec![
|
||||
Handle::new(0), // TODO: this could be better
|
||||
Handle::default(),
|
||||
],
|
||||
render_resource_assignments: RenderResourceAssignments::default(),
|
||||
is_instanced: false,
|
||||
|
|
Loading…
Reference in a new issue