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 18 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
44 changes: 17 additions & 27 deletions crates/bevy_render/src/draw.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::pipeline::VERTEX_FALLBACK_LAYOUT_NAME;
use crate::{
pipeline::{
PipelineCompiler, PipelineDescriptor, PipelineLayout, PipelineSpecialization,
VertexBufferDescriptors,
},
pipeline::{PipelineCompiler, PipelineDescriptor, PipelineLayout, PipelineSpecialization},
renderer::{
BindGroup, BindGroupId, BufferId, BufferUsage, RenderResource, RenderResourceBinding,
RenderResourceBindings, RenderResourceContext, SharedBuffers,
Expand Down Expand Up @@ -128,7 +126,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 +137,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 +158,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 +166,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 +195,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 +212,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 +252,6 @@ impl<'a> DrawContext<'a> {
&mut self.pipelines,
&mut self.shaders,
pipeline_handle,
&self.vertex_buffer_descriptors,
specialization,
)
};
Expand Down Expand Up @@ -350,18 +337,21 @@ impl<'a> DrawContext<'a> {
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)
{
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;
// 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() {
if let Some(index_buffer) = bindings.index_buffer {
draw.set_index_buffer(index_buffer, 0);
}
if let Some(main_vertex_buffer) = bindings.vertex_attribute_buffer {
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);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions crates/bevy_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub mod prelude {
};
}

use crate::pipeline::PipelineSpecialization;
use crate::prelude::*;
use base::{MainPass, Msaa};
use bevy_app::prelude::*;
Expand All @@ -37,8 +38,7 @@ use camera::{
ActiveCameras, Camera, OrthographicProjection, PerspectiveProjection, VisibleEntities,
};
use pipeline::{
DynamicBinding, PipelineCompiler, PipelineDescriptor, PipelineSpecialization,
PrimitiveTopology, ShaderSpecialization, VertexBufferDescriptors,
DynamicBinding, PipelineCompiler, PipelineDescriptor, 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