Skip to content

Commit 124f803

Browse files
authored
Remove unnecessary cast in DynamicTextureAtlasBuilder (#16937)
# Summary - I started experimenting if `TextureAtlas` and friends can be moved to `bevy_image`. See [Discord](https://discord.com/channels/691052431525675048/692572690833473578/1320176054911897642) thread. - While doing that, and moving `DynamicTextureAtlasBuilder` to `bevy_image`, it revealed that `DynamicTextureAtlasBuilder` depends on `bevy_render::GpuImage`, but we can't have `bevy_image` depend on `bevy_render`. - The reason for the dependency is an assertion introduced in [this PR](https://github.com/bevyengine/bevy/pull/12827/files?show-viewed-files=true&file-filters%5B%5D=#diff-d9afd2170466f4aae340b244bdaa2a80aef58e979268c003878ca6c95860eb37R59). - [It doesn't seem like there was a specific reason for that change](https://discord.com/channels/691052431525675048/743663924229963868/1320506862067650580), so should be safe to change it. - So instead of the cast, just look up `asset_usage` directly on the concrete `Image` type. - Also update the message which referred to a non-existent variable `atlas_texture_handle` (it was renamed during a subsequent refactor PR). # Testing - Checked on Discord if there was any known reason this had to stay like this. - CI builds it.
1 parent 48fe2a6 commit 124f803

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

crates/bevy_sprite/src/dynamic_texture_atlas_builder.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
use crate::TextureAtlasLayout;
22
use bevy_image::{Image, TextureFormatPixelInfo};
33
use bevy_math::{URect, UVec2};
4-
use bevy_render::{
5-
render_asset::{RenderAsset, RenderAssetUsages},
6-
texture::GpuImage,
7-
};
4+
use bevy_render::render_asset::RenderAssetUsages;
85
use guillotiere::{size2, Allocation, AtlasAllocator};
96

107
/// Helper utility to update [`TextureAtlasLayout`] on the fly.
@@ -53,9 +50,8 @@ impl DynamicTextureAtlasBuilder {
5350
));
5451
if let Some(allocation) = allocation {
5552
assert!(
56-
<GpuImage as RenderAsset>::asset_usage(atlas_texture)
57-
.contains(RenderAssetUsages::MAIN_WORLD),
58-
"The asset at atlas_texture_handle must have the RenderAssetUsages::MAIN_WORLD usage flag set"
53+
atlas_texture.asset_usage.contains(RenderAssetUsages::MAIN_WORLD),
54+
"The atlas_texture image must have the RenderAssetUsages::MAIN_WORLD usage flag set"
5955
);
6056

6157
self.place_texture(atlas_texture, allocation, texture);

0 commit comments

Comments
 (0)