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

[Merged by Bors] - Default image used in PipelinedSpriteBundle to be able to render without loading a texture #3270

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion pipelined/bevy_render2/src/texture/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"]
Expand All @@ -28,7 +31,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 {
Expand Down
6 changes: 5 additions & 1 deletion pipelined/bevy_render2/src/texture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -30,6 +30,10 @@ impl Plugin for ImagePlugin {

app.add_plugin(RenderAssetPlugin::<Image>::default())
.add_asset::<Image>();
app.world
.get_resource_mut::<Assets<Image>>()
.unwrap()
.set_untracked(DEFAULT_IMAGE_HANDLE, Image::default());

app.sub_app(RenderApp)
.init_resource::<TextureCache>()
Expand Down
16 changes: 14 additions & 2 deletions pipelined/bevy_sprite2/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)]
Expand Down