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 all 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
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ to view all changes since the `0.2.1` release.
## Unreleased

### Added

- [Mesh overhaul with custom vertex attributes][616] for `Mesh`
- Any vertex attribute can now be added over `mesh.attributes.insert()`. For example: `mesh.attributes.insert(Cow::Borrowed(Mesh::ATTRIBUTE_POSITION), points.into())`.
- For missing attributes (requested by shader, but not defined by mesh), Bevy will provide a zero-filled fallback buffer.
- [Touch Input][696]
- [Do not depend on spirv on wasm32 target][689]
- [Another fast compile flag for macOS][552]
- [Mesh overhaul with custom vertex attributes][599]
- [Introduce Mouse capture API][679]
- [`bevy_input::touch`: implement touch input][696]
- [D-pad support on MacOS][653]
Expand Down Expand Up @@ -56,6 +62,12 @@ to view all changes since the `0.2.1` release.
`Color::rgb` and `Color::rgba` will be converted to linear sRGB under-the-hood.
- This allows drop-in use of colors from most applications.
- New methods `Color::rgb_linear` and `Color::rgba_linear` will accept colors already in linear sRGB (the old behavior)
- Individual color-components must now be accessed through setters and getters: `.r`, `.g`, `.b`, `.a`, `.set_r`, `.set_g`, `.set_b`, `.set_a`, and the corresponding methods with the `*_linear` suffix.
- Breaking Change: [Mesh overhaul with custom vertex attributes][616] for `Mesh`
- Removed `VertexAttribute`, `Vertex`, `AsVertexBufferDescriptor`.

- Despawning an entity multiple times causes a debug-level log message to be emitted instead of a panic [649] [651]
- Breaking Change: Migrated to rodio 0.12, this means:
- Individual color-components must now be accessed through setters and getters:
`.r`, `.g`, `.b`, `.a`, `.set_r`, `.set_g`, `.set_b`, `.set_a`, and the corresponding methods with the `*_linear` suffix.
- Despawning an entity multiple times causes a debug-level log message to be emitted instead of a panic: [#649][649], [#651][651]
Expand All @@ -65,6 +77,9 @@ to view all changes since the `0.2.1` release.

### Fixed

[599]: https://github.com/bevyengine/bevy/pull/599
[696]: https://github.com/bevyengine/bevy/pull/696
[689]: https://github.com/bevyengine/bevy/pull/689
- [Properly update bind group ids when setting dynamic bindings][560]
- [Properly exit the app on AppExit event][610]
- [Fix FloatOrd hash being different for different NaN values][618]
Expand Down
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 @@ -45,12 +44,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
19 changes: 11 additions & 8 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy_ecs::{bevy_utils::BoxedFuture, World, WorldBuilderSource};
use bevy_math::Mat4;
use bevy_pbr::prelude::{PbrComponents, StandardMaterial};
use bevy_render::{
mesh::{Indices, Mesh, VertexAttribute},
mesh::{Indices, Mesh, VertexAttributeValues},
pipeline::PrimitiveTopology,
prelude::{Color, Texture},
texture::{AddressMode, FilterMode, SamplerDescriptor, TextureFormat},
Expand All @@ -20,7 +20,7 @@ use gltf::{
Primitive,
};
use image::{GenericImageView, ImageFormat};
use std::path::Path;
use std::{borrow::Cow, path::Path};
use thiserror::Error;

/// An error that occurs when loading a GLTF file
Expand Down Expand Up @@ -88,23 +88,26 @@ async fn load_gltf<'a, 'b>(

if let Some(vertex_attribute) = reader
.read_positions()
.map(|v| VertexAttribute::position(v.collect()))
.map(|v| VertexAttributeValues::Float3(v.collect()))
{
mesh.attributes.push(vertex_attribute);
mesh.attributes
.insert(Cow::Borrowed(Mesh::ATTRIBUTE_POSITION), vertex_attribute);
}

if let Some(vertex_attribute) = reader
.read_normals()
.map(|v| VertexAttribute::normal(v.collect()))
.map(|v| VertexAttributeValues::Float3(v.collect()))
{
mesh.attributes.push(vertex_attribute);
mesh.attributes
.insert(Cow::Borrowed(Mesh::ATTRIBUTE_NORMAL), vertex_attribute);
}

if let Some(vertex_attribute) = reader
.read_tex_coords(0)
.map(|v| VertexAttribute::uv(v.into_f32().collect()))
.map(|v| VertexAttributeValues::Float2(v.into_f32().collect()))
{
mesh.attributes.push(vertex_attribute);
mesh.attributes
.insert(Cow::Borrowed(Mesh::ATTRIBUTE_UV_0), vertex_attribute);
}

if let Some(indices) = reader.read_indices() {
Expand Down
38 changes: 16 additions & 22 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,
VERTEX_FALLBACK_LAYOUT_NAME,
},
renderer::{
BindGroup, BindGroupId, BufferId, BufferUsage, RenderResource, RenderResourceBinding,
Expand Down Expand Up @@ -131,7 +131,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 @@ -143,7 +142,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.clone(),
}
Expand All @@ -166,7 +164,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 @@ -175,7 +172,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 @@ -205,9 +201,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,7 +214,6 @@ impl<'a> FetchResource<'a> for FetchDrawContext {
access.add_write(TypeId::of::<Assets<Shader>>());
access.add_write(TypeId::of::<PipelineCompiler>());
access.add_read(TypeId::of::<Box<dyn RenderResourceContext>>());
access.add_read(TypeId::of::<VertexBufferDescriptors>());
access.add_read(TypeId::of::<SharedBuffers>());
access
}
Expand Down Expand Up @@ -262,7 +254,6 @@ impl<'a> DrawContext<'a> {
&mut self.pipelines,
&mut self.shaders,
pipeline_handle,
&self.vertex_buffer_descriptors,
specialization,
)
};
Expand Down Expand Up @@ -358,18 +349,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
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, IndexFormat, PipelineCompiler, PipelineDescriptor, PipelineSpecialization,
PrimitiveTopology, ShaderSpecialization, VertexBufferDescriptors,
PrimitiveTopology, ShaderSpecialization,
};
use render_graph::{
base::{self, BaseRenderGraphBuilder, BaseRenderGraphConfig},
Expand Down Expand Up @@ -119,7 +119,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