From a3a1768ebf034c15ba7bb4f5faa5b166b97d52f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Tue, 7 Dec 2021 01:49:51 +0100 Subject: [PATCH 1/3] change default for image to be full white --- pipelined/bevy_render2/src/texture/image.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipelined/bevy_render2/src/texture/image.rs b/pipelined/bevy_render2/src/texture/image.rs index 30b7b84394435..22a2f51736a49 100644 --- a/pipelined/bevy_render2/src/texture/image.rs +++ b/pipelined/bevy_render2/src/texture/image.rs @@ -28,7 +28,7 @@ pub struct Image { impl Default for Image { fn default() -> Self { let format = wgpu::TextureFormat::bevy_default(); - let data = vec![1; format.pixel_size() as usize]; + let data = vec![255; format.pixel_size() as usize]; Image { data, texture_descriptor: wgpu::TextureDescriptor { From 06a076b24cf89aab2032c64ce221a267554ce899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Tue, 7 Dec 2021 01:50:48 +0100 Subject: [PATCH 2/3] add a default image with a const handle to the assets --- pipelined/bevy_render2/src/texture/image.rs | 3 +++ pipelined/bevy_render2/src/texture/mod.rs | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pipelined/bevy_render2/src/texture/image.rs b/pipelined/bevy_render2/src/texture/image.rs index 22a2f51736a49..aaa400971e08e 100644 --- a/pipelined/bevy_render2/src/texture/image.rs +++ b/pipelined/bevy_render2/src/texture/image.rs @@ -5,6 +5,7 @@ use crate::{ renderer::{RenderDevice, RenderQueue}, texture::BevyDefault, }; +use bevy_asset::HandleUntyped; use bevy_ecs::system::{lifetimeless::SRes, SystemParamItem}; use bevy_reflect::TypeUuid; use thiserror::Error; @@ -15,6 +16,8 @@ use wgpu::{ pub const TEXTURE_ASSET_INDEX: u64 = 0; pub const SAMPLER_ASSET_INDEX: u64 = 1; +pub const DEFAULT_IMAGE_HANDLE: HandleUntyped = + HandleUntyped::weak_from_u64(Image::TYPE_UUID, 13148262314052771789); #[derive(Debug, Clone, TypeUuid)] #[uuid = "6ea26da6-6cf8-4ea2-9986-1d7bf6c17d6f"] diff --git a/pipelined/bevy_render2/src/texture/mod.rs b/pipelined/bevy_render2/src/texture/mod.rs index 1b99642a5f642..82ca2f4128288 100644 --- a/pipelined/bevy_render2/src/texture/mod.rs +++ b/pipelined/bevy_render2/src/texture/mod.rs @@ -15,7 +15,7 @@ pub use texture_cache::*; use crate::{render_asset::RenderAssetPlugin, RenderApp, RenderStage}; use bevy_app::{App, Plugin}; -use bevy_asset::AddAsset; +use bevy_asset::{AddAsset, Assets}; // TODO: replace Texture names with Image names? /// Adds the [`Image`] as an asset and makes sure that they are extracted and prepared for the GPU. @@ -30,6 +30,10 @@ impl Plugin for ImagePlugin { app.add_plugin(RenderAssetPlugin::::default()) .add_asset::(); + app.world + .get_resource_mut::>() + .unwrap() + .set_untracked(DEFAULT_IMAGE_HANDLE, Image::default()); app.sub_app(RenderApp) .init_resource::() From e2b5e0c820a36f4face4967c3ffc190581928f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Tue, 7 Dec 2021 01:51:05 +0100 Subject: [PATCH 3/3] use default image handle in default for PipelinedSpriteBundle --- pipelined/bevy_sprite2/src/bundle.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pipelined/bevy_sprite2/src/bundle.rs b/pipelined/bevy_sprite2/src/bundle.rs index 27bb151c4af3b..67d84449780a7 100644 --- a/pipelined/bevy_sprite2/src/bundle.rs +++ b/pipelined/bevy_sprite2/src/bundle.rs @@ -5,12 +5,12 @@ use crate::{ use bevy_asset::Handle; use bevy_ecs::bundle::Bundle; use bevy_render2::{ - texture::Image, + texture::{Image, DEFAULT_IMAGE_HANDLE}, view::{ComputedVisibility, Visibility}, }; use bevy_transform::components::{GlobalTransform, Transform}; -#[derive(Bundle, Clone, Default)] +#[derive(Bundle, Clone)] pub struct PipelinedSpriteBundle { pub sprite: Sprite, pub transform: Transform, @@ -22,6 +22,18 @@ pub struct PipelinedSpriteBundle { pub computed_visibility: ComputedVisibility, } +impl Default for PipelinedSpriteBundle { + fn default() -> Self { + Self { + sprite: Default::default(), + transform: Default::default(), + global_transform: Default::default(), + texture: DEFAULT_IMAGE_HANDLE.typed(), + visibility: Default::default(), + computed_visibility: Default::default(), + } + } +} /// A Bundle of components for drawing a single sprite from a sprite sheet (also referred /// to as a `TextureAtlas`) #[derive(Bundle, Clone, Default)]