Do not queue sprites/meshes if there are no views (#13)

* bevy_sprite2/_pbr2: Do not queue sprites/meshes if there are no views
This commit is contained in:
Robert Swain 2021-07-02 01:23:11 +02:00 committed by Carter Anderson
parent a9937190cd
commit 858065ef8d
4 changed files with 34 additions and 2 deletions

View File

@ -488,6 +488,10 @@ pub fn queue_meshes(
) {
let mesh_meta = mesh_meta.into_inner();
if view_meta.uniforms.len() == 0 {
return;
}
light_meta.shadow_view_bind_group.get_or_insert_with(|| {
render_device.create_bind_group(&BindGroupDescriptor {
entries: &[BindGroupEntry {

View File

@ -44,6 +44,11 @@ impl<T: AsStd140> UniformVec<T> {
})
}
#[inline]
pub fn len(&self) -> usize {
self.values.len()
}
#[inline]
pub fn capacity(&self) -> usize {
self.capacity
@ -145,6 +150,11 @@ impl<T: AsStd140> DynamicUniformVec<T> {
self.uniform_vec.binding()
}
#[inline]
pub fn len(&self) -> usize {
self.uniform_vec.len()
}
#[inline]
pub fn capacity(&self) -> usize {
self.uniform_vec.capacity()

View File

@ -36,7 +36,10 @@ impl RenderDevice {
/// Creates a shader module from either SPIR-V or WGSL source code.
#[inline]
pub fn create_shader_module<'a>(&self, desc: impl Into<wgpu::ShaderModuleDescriptor<'a>>) -> wgpu::ShaderModule {
pub fn create_shader_module<'a>(
&self,
desc: impl Into<wgpu::ShaderModuleDescriptor<'a>>,
) -> wgpu::ShaderModule {
self.device.create_shader_module(&desc.into())
}

View File

@ -2,7 +2,18 @@ use crate::Sprite;
use bevy_asset::{Assets, Handle};
use bevy_ecs::{prelude::*, system::SystemState};
use bevy_math::{Mat4, Vec2, Vec3, Vec4Swizzles};
use bevy_render2::{core_pipeline::Transparent2dPhase, mesh::{shape::Quad, Indices, Mesh, VertexAttributeValues}, render_asset::RenderAssets, render_graph::{Node, NodeRunError, RenderGraphContext}, render_phase::{Draw, DrawFunctions, Drawable, RenderPhase, TrackedRenderPass}, render_resource::*, renderer::{RenderContext, RenderDevice}, shader::Shader, texture::{BevyDefault, Image}, view::{ViewMeta, ViewUniform, ViewUniformOffset}};
use bevy_render2::{
core_pipeline::Transparent2dPhase,
mesh::{shape::Quad, Indices, Mesh, VertexAttributeValues},
render_asset::RenderAssets,
render_graph::{Node, NodeRunError, RenderGraphContext},
render_phase::{Draw, DrawFunctions, Drawable, RenderPhase, TrackedRenderPass},
render_resource::*,
renderer::{RenderContext, RenderDevice},
shader::Shader,
texture::{BevyDefault, Image},
view::{ViewMeta, ViewUniform, ViewUniformOffset},
};
use bevy_transform::components::GlobalTransform;
use bevy_utils::slab::{FrameSlabMap, FrameSlabMapKey};
use bytemuck::{Pod, Zeroable};
@ -276,6 +287,10 @@ pub fn queue_sprites(
gpu_images: Res<RenderAssets<Image>>,
mut views: Query<&mut RenderPhase<Transparent2dPhase>>,
) {
if view_meta.uniforms.len() == 0 {
return;
}
// TODO: define this without needing to check every frame
sprite_meta.view_bind_group.get_or_insert_with(|| {
render_device.create_bind_group(&BindGroupDescriptor {