parent
7aac4223d0
commit
fcf9d525e1
@ -1,8 +1,5 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
pipeline::{
|
pipeline::{PipelineCompiler, PipelineDescriptor, PipelineLayout, PipelineSpecialization},
|
||||||
PipelineCompiler, PipelineDescriptor, PipelineLayout, PipelineSpecialization,
|
|
||||||
VERTEX_FALLBACK_LAYOUT_NAME,
|
|
||||||
},
|
|
||||||
renderer::{
|
renderer::{
|
||||||
BindGroup, BindGroupId, BufferId, BufferUsage, RenderResource, RenderResourceBinding,
|
BindGroup, BindGroupId, BufferId, BufferUsage, RenderResource, RenderResourceBinding,
|
||||||
RenderResourceBindings, RenderResourceContext, SharedBuffers,
|
RenderResourceBindings, RenderResourceContext, SharedBuffers,
|
||||||
@ -255,22 +252,6 @@ impl<'a> DrawContext<'a> {
|
|||||||
draw: &mut Draw,
|
draw: &mut Draw,
|
||||||
render_resource_bindings: &[&RenderResourceBindings],
|
render_resource_bindings: &[&RenderResourceBindings],
|
||||||
) -> Result<(), DrawError> {
|
) -> Result<(), DrawError> {
|
||||||
let pipeline = self
|
|
||||||
.current_pipeline
|
|
||||||
.as_ref()
|
|
||||||
.ok_or(DrawError::NoPipelineSet)?;
|
|
||||||
let pipeline_descriptor = self
|
|
||||||
.pipelines
|
|
||||||
.get(pipeline)
|
|
||||||
.ok_or(DrawError::NonExistentPipeline)?;
|
|
||||||
let layout = pipeline_descriptor
|
|
||||||
.get_layout()
|
|
||||||
.ok_or(DrawError::PipelineHasNoLayout)?;
|
|
||||||
// figure out if the fallback buffer is needed
|
|
||||||
let need_fallback_buffer = layout
|
|
||||||
.vertex_buffer_descriptors
|
|
||||||
.iter()
|
|
||||||
.any(|x| x.name == VERTEX_FALLBACK_LAYOUT_NAME);
|
|
||||||
for bindings in render_resource_bindings.iter() {
|
for bindings in render_resource_bindings.iter() {
|
||||||
if let Some(index_buffer) = bindings.index_buffer {
|
if let Some(index_buffer) = bindings.index_buffer {
|
||||||
draw.set_index_buffer(index_buffer, 0);
|
draw.set_index_buffer(index_buffer, 0);
|
||||||
@ -278,11 +259,6 @@ impl<'a> DrawContext<'a> {
|
|||||||
if let Some(main_vertex_buffer) = bindings.vertex_attribute_buffer {
|
if let Some(main_vertex_buffer) = bindings.vertex_attribute_buffer {
|
||||||
draw.set_vertex_buffer(0, main_vertex_buffer, 0);
|
draw.set_vertex_buffer(0, main_vertex_buffer, 0);
|
||||||
}
|
}
|
||||||
if need_fallback_buffer {
|
|
||||||
if let Some(fallback_vertex_buffer) = bindings.vertex_fallback_buffer {
|
|
||||||
draw.set_vertex_buffer(1, fallback_vertex_buffer, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@ use bevy_utils::HashMap;
|
|||||||
|
|
||||||
pub const INDEX_BUFFER_ASSET_INDEX: u64 = 0;
|
pub const INDEX_BUFFER_ASSET_INDEX: u64 = 0;
|
||||||
pub const VERTEX_ATTRIBUTE_BUFFER_ID: u64 = 10;
|
pub const VERTEX_ATTRIBUTE_BUFFER_ID: u64 = 10;
|
||||||
pub const VERTEX_FALLBACK_BUFFER_ID: u64 = 20;
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum VertexAttributeValues {
|
pub enum VertexAttributeValues {
|
||||||
Float(Vec<f32>),
|
Float(Vec<f32>),
|
||||||
@ -526,7 +526,6 @@ fn remove_current_mesh_resources(
|
|||||||
handle: &Handle<Mesh>,
|
handle: &Handle<Mesh>,
|
||||||
) {
|
) {
|
||||||
remove_resource_save(render_resource_context, handle, VERTEX_ATTRIBUTE_BUFFER_ID);
|
remove_resource_save(render_resource_context, handle, VERTEX_ATTRIBUTE_BUFFER_ID);
|
||||||
remove_resource_save(render_resource_context, handle, VERTEX_FALLBACK_BUFFER_ID);
|
|
||||||
remove_resource_save(render_resource_context, handle, INDEX_BUFFER_ASSET_INDEX);
|
remove_resource_save(render_resource_context, handle, INDEX_BUFFER_ASSET_INDEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,20 +592,6 @@ pub fn mesh_resource_provider_system(
|
|||||||
)),
|
)),
|
||||||
VERTEX_ATTRIBUTE_BUFFER_ID,
|
VERTEX_ATTRIBUTE_BUFFER_ID,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Fallback buffer
|
|
||||||
// TODO: can be done with a 1 byte buffer + zero stride?
|
|
||||||
render_resource_context.set_asset_resource(
|
|
||||||
changed_mesh_handle,
|
|
||||||
RenderResourceId::Buffer(render_resource_context.create_buffer_with_data(
|
|
||||||
BufferInfo {
|
|
||||||
buffer_usage: BufferUsage::VERTEX,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
&vec![0; mesh.count_vertices() * VertexFormat::Float4.get_size() as usize],
|
|
||||||
)),
|
|
||||||
VERTEX_FALLBACK_BUFFER_ID,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -640,13 +625,6 @@ pub fn mesh_resource_provider_system(
|
|||||||
render_pipelines.bindings.vertex_attribute_buffer =
|
render_pipelines.bindings.vertex_attribute_buffer =
|
||||||
Some(vertex_attribute_buffer_resource);
|
Some(vertex_attribute_buffer_resource);
|
||||||
}
|
}
|
||||||
if let Some(RenderResourceId::Buffer(vertex_attribute_fallback_resource)) =
|
|
||||||
render_resource_context.get_asset_resource(handle, VERTEX_FALLBACK_BUFFER_ID)
|
|
||||||
{
|
|
||||||
// set index buffer into binding
|
|
||||||
render_pipelines.bindings.vertex_fallback_buffer =
|
|
||||||
Some(vertex_attribute_fallback_resource);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
use super::{state_descriptors::PrimitiveTopology, IndexFormat, PipelineDescriptor};
|
use super::{state_descriptors::PrimitiveTopology, IndexFormat, PipelineDescriptor};
|
||||||
use crate::{
|
use crate::{
|
||||||
pipeline::{
|
pipeline::{BindType, InputStepMode, VertexBufferDescriptor},
|
||||||
BindType, InputStepMode, VertexAttributeDescriptor, VertexBufferDescriptor, VertexFormat,
|
|
||||||
VERTEX_FALLBACK_LAYOUT_NAME,
|
|
||||||
},
|
|
||||||
renderer::RenderResourceContext,
|
renderer::RenderResourceContext,
|
||||||
shader::{Shader, ShaderSource},
|
shader::{Shader, ShaderSource},
|
||||||
};
|
};
|
||||||
@ -12,7 +9,6 @@ use bevy_property::{Properties, Property};
|
|||||||
use bevy_utils::{HashMap, HashSet};
|
use bevy_utils::{HashMap, HashSet};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
#[derive(Clone, Eq, PartialEq, Debug, Properties)]
|
#[derive(Clone, Eq, PartialEq, Debug, Properties)]
|
||||||
pub struct PipelineSpecialization {
|
pub struct PipelineSpecialization {
|
||||||
@ -206,11 +202,6 @@ impl PipelineCompiler {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut fallback_vertex_buffer_descriptor = VertexBufferDescriptor {
|
|
||||||
name: Cow::Borrowed(VERTEX_FALLBACK_LAYOUT_NAME),
|
|
||||||
stride: VertexFormat::Float4.get_size(), //TODO: use smallest possible format
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
for shader_vertex_attribute in pipeline_layout.vertex_buffer_descriptors.iter() {
|
for shader_vertex_attribute in pipeline_layout.vertex_buffer_descriptors.iter() {
|
||||||
let shader_vertex_attribute = shader_vertex_attribute
|
let shader_vertex_attribute = shader_vertex_attribute
|
||||||
.attributes
|
.attributes
|
||||||
@ -229,23 +220,18 @@ impl PipelineCompiler {
|
|||||||
.attributes
|
.attributes
|
||||||
.push(compiled_vertex_attribute);
|
.push(compiled_vertex_attribute);
|
||||||
} else {
|
} else {
|
||||||
fallback_vertex_buffer_descriptor
|
panic!(
|
||||||
.attributes
|
"Attribute {} is required by shader, but not supplied by mesh. Either remove the attribute from the shader or supply the attribute ({}) to the mesh. ",
|
||||||
.push(VertexAttributeDescriptor {
|
shader_vertex_attribute.name,
|
||||||
name: Default::default(),
|
shader_vertex_attribute.name,
|
||||||
offset: 0,
|
);
|
||||||
format: shader_vertex_attribute.format, //TODO: use smallest possible format
|
|
||||||
shader_location: shader_vertex_attribute.shader_location,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: add other buffers (like instancing) here
|
//TODO: add other buffers (like instancing) here
|
||||||
let mut vertex_buffer_descriptors = Vec::<VertexBufferDescriptor>::default();
|
let mut vertex_buffer_descriptors = Vec::<VertexBufferDescriptor>::default();
|
||||||
vertex_buffer_descriptors.push(compiled_vertex_buffer_descriptor);
|
vertex_buffer_descriptors.push(compiled_vertex_buffer_descriptor);
|
||||||
if !fallback_vertex_buffer_descriptor.attributes.is_empty() {
|
|
||||||
vertex_buffer_descriptors.push(fallback_vertex_buffer_descriptor);
|
|
||||||
}
|
|
||||||
pipeline_layout.vertex_buffer_descriptors = vertex_buffer_descriptors;
|
pipeline_layout.vertex_buffer_descriptors = vertex_buffer_descriptors;
|
||||||
specialized_descriptor.sample_count = pipeline_specialization.sample_count;
|
specialized_descriptor.sample_count = pipeline_specialization.sample_count;
|
||||||
specialized_descriptor.primitive_topology = pipeline_specialization.primitive_topology;
|
specialized_descriptor.primitive_topology = pipeline_specialization.primitive_topology;
|
||||||
|
|||||||
@ -14,7 +14,6 @@ pub struct VertexBufferDescriptor {
|
|||||||
pub attributes: Vec<VertexAttributeDescriptor>,
|
pub attributes: Vec<VertexAttributeDescriptor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const VERTEX_FALLBACK_LAYOUT_NAME: &str = "Fallback";
|
|
||||||
impl VertexBufferDescriptor {
|
impl VertexBufferDescriptor {
|
||||||
pub fn new_from_attribute(
|
pub fn new_from_attribute(
|
||||||
attribute: VertexAttributeDescriptor,
|
attribute: VertexAttributeDescriptor,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user