Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesh overhaul with custom vertex attributes #592 #599

Merged
merged 35 commits into from
Oct 31, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
35a9bf8
first draft
Sep 28, 2020
4c5d883
clean up + format
Oct 1, 2020
92bae44
Update mesh.rs
Oct 1, 2020
d47897c
Update mesh.rs
Oct 1, 2020
6253a95
clippy nightly
Oct 1, 2020
ccbc1bc
changed vertex buffer slots now taken from binding; shader naming con…
Oct 4, 2020
66640b7
simplified shader vertex attribute reflection, removed VertexBufferDe…
Oct 4, 2020
519b6b0
format
Oct 4, 2020
ae2e670
format nightly
Oct 4, 2020
049e5a9
Draw panics now when vertex buffer is missing; Name based hashmap for…
Oct 5, 2020
21bd324
added proper clean up for mesh resources (untested)
Oct 6, 2020
5a09a47
fixed bevy_text to work with new vertex system
Oct 6, 2020
f59bacd
using fnv hash for vertex attributes; refactor
Oct 7, 2020
80eafc8
restored old vertex naming convention
Oct 7, 2020
8d54839
reintroduced multiple attributes per buffer
Oct 9, 2020
ab37614
changed internal resource id to u64; using AHasher for vertex attribu…
Oct 9, 2020
9734db5
Reintroduced interleaved buffers, but flexible. :smile: Pipeline spec…
Oct 13, 2020
20d101b
made fallback buffer obtional. readded properties to rendering structs
Oct 14, 2020
8ff3bbb
HashMap for attributes for consisten order and uniqueness. Removed Ve…
Oct 16, 2020
5608eb2
fixed text. cleanup
Oct 19, 2020
0d61e81
Removed mesh.insert_attribute. removed VertexBufferDescriptor hack in…
Oct 21, 2020
39740c4
Merge remote-tracking branch 'upstream/master' into render_mesh_seper…
Oct 22, 2020
1417b2c
post merge fixes
Oct 22, 2020
8fb3874
fmt
Oct 22, 2020
01f79c7
Update CHANGELOG.md
Oct 22, 2020
63c4574
Merge branch 'master' into render_mesh_seperate_buffers
Oct 22, 2020
1b39ca9
Sort attributes before turning them into bytes. Removed indices from …
Oct 30, 2020
8ce53ee
Merge branch 'master' into render_mesh_seperate_buffers
Oct 30, 2020
789de51
Update sprite_sheet.vert
Oct 30, 2020
f759aa6
Update mesh.rs
Oct 30, 2020
b766c9a
fixed a bug related to more attributes defined by mesh than used by s…
Oct 31, 2020
223f5a2
format
Oct 31, 2020
5a4d6e2
Revert "format"
Oct 31, 2020
87fde6d
Update pipeline_compiler.rs
Oct 31, 2020
e665298
Update pipeline_compiler.rs
Oct 31, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 0 additions & 124 deletions crates/bevy_derive/src/as_vertex_buffer_descriptor.rs

This file was deleted.

7 changes: 0 additions & 7 deletions crates/bevy_derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
extern crate proc_macro;

mod app_plugin;
mod as_vertex_buffer_descriptor;
mod bytes;
mod modules;
mod render_resource;
Expand Down Expand Up @@ -44,12 +43,6 @@ pub fn derive_shader_defs(input: TokenStream) -> TokenStream {
shader_defs::derive_shader_defs(input)
}

/// Derives the AsVertexBufferDescriptor trait.
#[proc_macro_derive(AsVertexBufferDescriptor, attributes(vertex, as_crate))]
pub fn derive_as_vertex_buffer_descriptor(input: TokenStream) -> TokenStream {
as_vertex_buffer_descriptor::derive_as_vertex_buffer_descriptor(input)
}

/// Generates a dynamic plugin entry point function for the given `Plugin` type.
#[proc_macro_derive(DynamicPlugin)]
pub fn derive_dynamic_plugin(input: TokenStream) -> TokenStream {
Expand Down
16 changes: 8 additions & 8 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bevy_render::{
mesh::{Indices, Mesh, VertexAttribute},
mesh::{Indices, Mesh, VertexAttributeData},
pipeline::PrimitiveTopology,
};

Expand Down Expand Up @@ -74,27 +74,27 @@ fn load_node(buffer_data: &[Vec<u8>], node: &gltf::Node, depth: i32) -> Result<M
if let Some(primitive) = mesh.primitives().next() {
let reader = primitive.reader(|buffer| Some(&buffer_data[buffer.index()]));
let primitive_topology = get_primitive_topology(primitive.mode())?;
let mut mesh = Mesh::new(primitive_topology);
let mut mesh = Mesh::new_empty(primitive_topology);

if let Some(vertex_attribute) = reader
.read_positions()
.map(|v| VertexAttribute::position(v.collect()))
.map(|v| VertexAttributeData::position(v.collect()))
{
mesh.attributes.push(vertex_attribute);
mesh.insert_attribute(vertex_attribute);
}

if let Some(vertex_attribute) = reader
.read_normals()
.map(|v| VertexAttribute::normal(v.collect()))
.map(|v| VertexAttributeData::normal(v.collect()))
{
mesh.attributes.push(vertex_attribute);
mesh.insert_attribute(vertex_attribute);
}

if let Some(vertex_attribute) = reader
.read_tex_coords(0)
.map(|v| VertexAttribute::uv(v.into_f32().collect()))
.map(|v| VertexAttributeData::uv(v.into_f32().collect()))
{
mesh.attributes.push(vertex_attribute);
mesh.insert_attribute(vertex_attribute);
}

if let Some(indices) = reader.read_indices() {
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ anyhow = "1.0"
hex = "0.4.2"
hexasphere = "1.0.0"
parking_lot = "0.11.0"
fnv = "1.0.7"

[target.'cfg(not(target_os = "ios"))'.dependencies]
bevy-glsl-to-spirv = "0.1.7"
Expand Down
51 changes: 20 additions & 31 deletions crates/bevy_render/src/draw.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
pipeline::{
PipelineCompiler, PipelineDescriptor, PipelineLayout, PipelineSpecialization,
VertexBufferDescriptors,
VertexBufferDescriptor,
},
renderer::{
BindGroup, BindGroupId, BufferId, BufferUsage, RenderResource, RenderResourceBinding,
Expand Down Expand Up @@ -128,7 +128,6 @@ pub struct DrawContext<'a> {
pub shaders: ResMut<'a, Assets<Shader>>,
pub pipeline_compiler: ResMut<'a, PipelineCompiler>,
pub render_resource_context: Res<'a, Box<dyn RenderResourceContext>>,
pub vertex_buffer_descriptors: Res<'a, VertexBufferDescriptors>,
pub shared_buffers: Res<'a, SharedBuffers>,
pub current_pipeline: Option<Handle<PipelineDescriptor>>,
}
Expand All @@ -140,7 +139,6 @@ impl<'a> UnsafeClone for DrawContext<'a> {
shaders: self.shaders.unsafe_clone(),
pipeline_compiler: self.pipeline_compiler.unsafe_clone(),
render_resource_context: self.render_resource_context.unsafe_clone(),
vertex_buffer_descriptors: self.vertex_buffer_descriptors.unsafe_clone(),
shared_buffers: self.shared_buffers.unsafe_clone(),
current_pipeline: self.current_pipeline,
}
Expand All @@ -162,7 +160,6 @@ impl<'a> FetchResource<'a> for FetchDrawContext {
resources.borrow_mut::<Assets<Shader>>();
resources.borrow_mut::<PipelineCompiler>();
resources.borrow::<Box<dyn RenderResourceContext>>();
resources.borrow::<VertexBufferDescriptors>();
resources.borrow::<SharedBuffers>();
}

Expand All @@ -171,7 +168,6 @@ impl<'a> FetchResource<'a> for FetchDrawContext {
resources.release_mut::<Assets<Shader>>();
resources.release_mut::<PipelineCompiler>();
resources.release::<Box<dyn RenderResourceContext>>();
resources.release::<VertexBufferDescriptors>();
resources.release::<SharedBuffers>();
}

Expand Down Expand Up @@ -201,9 +197,6 @@ impl<'a> FetchResource<'a> for FetchDrawContext {
render_resource_context: Res::new(
resources.get_unsafe_ref::<Box<dyn RenderResourceContext>>(ResourceIndex::Global),
),
vertex_buffer_descriptors: Res::new(
resources.get_unsafe_ref::<VertexBufferDescriptors>(ResourceIndex::Global),
),
shared_buffers: Res::new(
resources.get_unsafe_ref::<SharedBuffers>(ResourceIndex::Global),
),
Expand All @@ -221,9 +214,6 @@ impl<'a> FetchResource<'a> for FetchDrawContext {
access
.immutable
.insert(TypeId::of::<Box<dyn RenderResourceContext>>());
access
.immutable
.insert(TypeId::of::<VertexBufferDescriptors>());
access.immutable.insert(TypeId::of::<SharedBuffers>());
access
}
Expand Down Expand Up @@ -264,7 +254,6 @@ impl<'a> DrawContext<'a> {
&mut self.pipelines,
&mut self.shaders,
pipeline_handle,
&self.vertex_buffer_descriptors,
specialization,
)
};
Expand Down Expand Up @@ -341,29 +330,29 @@ impl<'a> DrawContext<'a> {
&self,
draw: &mut Draw,
render_resource_bindings: &[&RenderResourceBindings],
vertex_buffer_descriptors: &[VertexBufferDescriptor],
) -> Result<(), DrawError> {
let pipeline = self.current_pipeline.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)?;
for (slot, vertex_buffer_descriptor) in layout.vertex_buffer_descriptors.iter().enumerate()
{
for bindings in render_resource_bindings.iter() {
if let Some((vertex_buffer, index_buffer)) =
bindings.get_vertex_buffer(&vertex_buffer_descriptor.name)
for bindings in render_resource_bindings.iter() {
for vertex_buffer_descriptor in vertex_buffer_descriptors {
if let Some(vertex_buffer) =
bindings.vertex_buffers.get(&vertex_buffer_descriptor.name)
{
draw.set_vertex_buffer(slot as u32, vertex_buffer, 0);
if let Some(index_buffer) = index_buffer {
draw.set_index_buffer(index_buffer, 0);
}

break;
draw.set_vertex_buffer(
vertex_buffer_descriptor.attribute.shader_location,
*vertex_buffer,
0,
);
} else {
panic!(
"Attribute {} is required by shader, but no vertex buffer was found.",
&vertex_buffer_descriptor.name
);
}
}

if let Some(index_buffer) = bindings.index_buffer {
draw.set_index_buffer(index_buffer, 0);
}
}
Ok(())
}
Expand Down
3 changes: 1 addition & 2 deletions crates/bevy_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use camera::{
};
use pipeline::{
DynamicBinding, PipelineCompiler, PipelineDescriptor, PipelineSpecialization,
PrimitiveTopology, ShaderSpecialization, VertexBufferDescriptors,
PrimitiveTopology, ShaderSpecialization,
};
use render_graph::{
base::{self, BaseRenderGraphBuilder, BaseRenderGraphConfig},
Expand Down Expand Up @@ -114,7 +114,6 @@ impl Plugin for RenderPlugin {
.init_resource::<RenderGraph>()
.init_resource::<PipelineCompiler>()
.init_resource::<RenderResourceBindings>()
.init_resource::<VertexBufferDescriptors>()
.init_resource::<TextureResourceSystemState>()
.init_resource::<AssetRenderResourceBindings>()
.init_resource::<ActiveCameras>()
Expand Down
Loading