Skip to content

Commit ad4bb64

Browse files
committed
use handleid in renderer
1 parent 5afda8d commit ad4bb64

File tree

13 files changed

+29
-31
lines changed

13 files changed

+29
-31
lines changed

crates/bevy_pbr/src/material.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl<M: SpecializedMaterial, const I: usize> EntityRenderCommand for SetMaterial
259259
pass: &mut TrackedRenderPass<'w>,
260260
) -> RenderCommandResult {
261261
let material_handle = query.get(item).unwrap();
262-
let material = materials.into_inner().get(material_handle).unwrap();
262+
let material = materials.into_inner().get(&material_handle.id).unwrap();
263263
pass.set_bind_group(
264264
I,
265265
M::bind_group(material),
@@ -313,9 +313,9 @@ pub fn queue_material_meshes<M: SpecializedMaterial>(
313313
if let Ok((material_handle, mesh_handle, mesh_uniform)) =
314314
material_meshes.get(*visible_entity)
315315
{
316-
if let Some(material) = render_materials.get(material_handle) {
316+
if let Some(material) = render_materials.get(&material_handle.id) {
317317
let mut mesh_key = mesh_key;
318-
if let Some(mesh) = render_meshes.get(mesh_handle) {
318+
if let Some(mesh) = render_meshes.get(&mesh_handle.id) {
319319
if mesh.has_tangents {
320320
mesh_key |= MeshPipelineKey::VERTEX_TANGENTS;
321321
}

crates/bevy_pbr/src/render/light.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ pub fn queue_shadows(
11221122
for entity in visible_entities.iter().copied() {
11231123
let mut key = ShadowPipelineKey::empty();
11241124
if let Ok(mesh_handle) = casting_meshes.get(entity) {
1125-
if let Some(mesh) = render_meshes.get(mesh_handle) {
1125+
if let Some(mesh) = render_meshes.get(&mesh_handle.id) {
11261126
if mesh.has_tangents {
11271127
key |= ShadowPipelineKey::VERTEX_TANGENTS;
11281128
}

crates/bevy_pbr/src/render/mesh.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ impl MeshPipeline {
349349
handle_option: &Option<Handle<Image>>,
350350
) -> Option<(&'a TextureView, &'a Sampler)> {
351351
if let Some(handle) = handle_option {
352-
let gpu_image = gpu_images.get(handle)?;
352+
let gpu_image = gpu_images.get(&handle.id)?;
353353
Some((&gpu_image.texture_view, &gpu_image.sampler))
354354
} else {
355355
Some((
@@ -717,7 +717,7 @@ impl EntityRenderCommand for DrawMesh {
717717
pass: &mut TrackedRenderPass<'w>,
718718
) -> RenderCommandResult {
719719
let mesh_handle = mesh_query.get(item).unwrap();
720-
if let Some(gpu_mesh) = meshes.into_inner().get(mesh_handle) {
720+
if let Some(gpu_mesh) = meshes.into_inner().get(&mesh_handle.id) {
721721
pass.set_vertex_buffer(0, gpu_mesh.vertex_buffer.slice(..));
722722
match &gpu_mesh.buffer_info {
723723
GpuBufferInfo::Indexed {

crates/bevy_pbr/src/wireframe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn queue_wireframes(
119119

120120
let add_render_phase =
121121
|(entity, mesh_handle, mesh_uniform): (Entity, &Handle<Mesh>, &MeshUniform)| {
122-
if let Some(mesh) = render_meshes.get(mesh_handle) {
122+
if let Some(mesh) = render_meshes.get(&mesh_handle.id) {
123123
let key =
124124
key | MeshPipelineKey::from_primitive_topology(mesh.primitive_topology);
125125
transparent_phase.add(Opaque3d {

crates/bevy_render/src/render_asset.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{RenderApp, RenderStage};
22
use bevy_app::{App, Plugin};
3-
use bevy_asset::{Asset, AssetEvent, Assets, Handle};
3+
use bevy_asset::{Asset, AssetEvent, Assets, HandleId};
44
use bevy_ecs::{
55
prelude::*,
66
system::{lifetimeless::*, RunSystem, SystemParam, SystemParamItem},
@@ -68,8 +68,8 @@ impl<A: RenderAsset> Plugin for RenderAssetPlugin<A> {
6868

6969
/// Temporarily stores the extracted and removed assets of the current frame.
7070
pub struct ExtractedAssets<A: RenderAsset> {
71-
extracted: Vec<(Handle<A>, A::ExtractedAsset)>,
72-
removed: Vec<Handle<A>>,
71+
extracted: Vec<(HandleId, A::ExtractedAsset)>,
72+
removed: Vec<HandleId>,
7373
}
7474

7575
impl<A: RenderAsset> Default for ExtractedAssets<A> {
@@ -83,7 +83,7 @@ impl<A: RenderAsset> Default for ExtractedAssets<A> {
8383

8484
/// Stores all GPU representations ([`RenderAsset::PreparedAssets`](RenderAsset::PreparedAsset))
8585
/// of [`RenderAssets`](RenderAsset) as long as they exist.
86-
pub type RenderAssets<A> = HashMap<Handle<A>, <A as RenderAsset>::PreparedAsset>;
86+
pub type RenderAssets<A> = HashMap<HandleId, <A as RenderAsset>::PreparedAsset>;
8787

8888
/// This system extracts all crated or modified assets of the corresponding [`RenderAsset`] type
8989
/// into the "render world".
@@ -97,26 +97,26 @@ fn extract_render_asset<A: RenderAsset>(
9797
for event in events.iter() {
9898
match event {
9999
AssetEvent::Created { handle } => {
100-
changed_assets.insert(handle);
100+
changed_assets.insert(handle.id);
101101
}
102102
AssetEvent::Modified { handle } => {
103-
changed_assets.insert(handle);
103+
changed_assets.insert(handle.id);
104104
}
105105
AssetEvent::Removed { handle } => {
106-
changed_assets.remove(handle);
107-
removed.push(handle.clone_weak());
106+
changed_assets.remove(&handle.id);
107+
removed.push(handle.id);
108108
}
109109
}
110110
}
111111

112112
let mut extracted_assets = Vec::new();
113113
for handle in changed_assets.drain() {
114114
if let Some(asset) = assets.get(handle) {
115-
extracted_assets.push((handle.clone_weak(), asset.extract_asset()));
115+
extracted_assets.push((handle, asset.extract_asset()));
116116
}
117117
}
118118

119-
commands.insert_resource(ExtractedAssets {
119+
commands.insert_resource(ExtractedAssets::<A> {
120120
extracted: extracted_assets,
121121
removed,
122122
});
@@ -133,7 +133,7 @@ pub type RenderAssetParams<R> = (
133133
// TODO: consider storing inside system?
134134
/// All assets that should be prepared next frame.
135135
pub struct PrepareNextFrameAssets<A: RenderAsset> {
136-
assets: Vec<(Handle<A>, A::ExtractedAsset)>,
136+
assets: Vec<(HandleId, A::ExtractedAsset)>,
137137
}
138138

139139
impl<A: RenderAsset> Default for PrepareNextFrameAssets<A> {

crates/bevy_sprite/src/mesh2d/material.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl<M: SpecializedMaterial2d, const I: usize> EntityRenderCommand
245245
pass: &mut TrackedRenderPass<'w>,
246246
) -> RenderCommandResult {
247247
let material2d_handle = query.get(item).unwrap();
248-
let material2d = materials.into_inner().get(material2d_handle).unwrap();
248+
let material2d = materials.into_inner().get(&material2d_handle.id).unwrap();
249249
pass.set_bind_group(
250250
I,
251251
M::bind_group(material2d),
@@ -282,9 +282,9 @@ pub fn queue_material2d_meshes<M: SpecializedMaterial2d>(
282282
if let Ok((material2d_handle, mesh2d_handle, mesh2d_uniform)) =
283283
material2d_meshes.get(*visible_entity)
284284
{
285-
if let Some(material2d) = render_materials.get(material2d_handle) {
285+
if let Some(material2d) = render_materials.get(&material2d_handle.id) {
286286
let mut mesh2d_key = mesh_key;
287-
if let Some(mesh) = render_meshes.get(&mesh2d_handle.0) {
287+
if let Some(mesh) = render_meshes.get(&mesh2d_handle.0.id) {
288288
if mesh.has_tangents {
289289
mesh2d_key |= Mesh2dPipelineKey::VERTEX_TANGENTS;
290290
}

crates/bevy_sprite/src/mesh2d/mesh.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl Mesh2dPipeline {
214214
handle_option: &Option<Handle<Image>>,
215215
) -> Option<(&'a TextureView, &'a Sampler)> {
216216
if let Some(handle) = handle_option {
217-
let gpu_image = gpu_images.get(handle)?;
217+
let gpu_image = gpu_images.get(&handle.id)?;
218218
Some((&gpu_image.texture_view, &gpu_image.sampler))
219219
} else {
220220
Some((
@@ -489,7 +489,7 @@ impl EntityRenderCommand for DrawMesh2d {
489489
pass: &mut TrackedRenderPass<'w>,
490490
) -> RenderCommandResult {
491491
let mesh_handle = &mesh2d_query.get(item).unwrap().0;
492-
if let Some(gpu_mesh) = meshes.into_inner().get(mesh_handle) {
492+
if let Some(gpu_mesh) = meshes.into_inner().get(&mesh_handle.id) {
493493
pass.set_vertex_buffer(0, gpu_mesh.vertex_buffer.slice(..));
494494
match &gpu_mesh.buffer_info {
495495
GpuBufferInfo::Indexed {

crates/bevy_sprite/src/render/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,7 @@ pub fn queue_sprites(
433433
};
434434
if new_batch != current_batch {
435435
// Set-up a new possible batch
436-
if let Some(gpu_image) =
437-
gpu_images.get(&Handle::weak(new_batch.image_handle_id))
438-
{
436+
if let Some(gpu_image) = gpu_images.get(&new_batch.image_handle_id) {
439437
current_batch = new_batch;
440438
current_image_size = Vec2::new(gpu_image.size.width, gpu_image.size.height);
441439
current_batch_entity = commands.spawn_bundle((current_batch,)).id();

crates/bevy_ui/src/render/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ pub fn queue_uinodes(
448448
.values
449449
.entry(batch.image.clone_weak())
450450
.or_insert_with(|| {
451-
let gpu_image = gpu_images.get(&batch.image).unwrap();
451+
let gpu_image = gpu_images.get(&batch.image.id).unwrap();
452452
render_device.create_bind_group(&BindGroupDescriptor {
453453
entries: &[
454454
BindGroupEntry {

examples/2d/mesh2d_manual.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ pub fn queue_colored_mesh2d(
333333
if let Ok((mesh2d_handle, mesh2d_uniform)) = colored_mesh2d.get(*visible_entity) {
334334
// Get our specialized pipeline
335335
let mut mesh2d_key = mesh_key;
336-
if let Some(mesh) = render_meshes.get(&mesh2d_handle.0) {
336+
if let Some(mesh) = render_meshes.get(&mesh2d_handle.0.id) {
337337
mesh2d_key |=
338338
Mesh2dPipelineKey::from_primitive_topology(mesh.primitive_topology);
339339
}

examples/shader/compute_shader_game_of_life.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn queue_bind_group(
8787
game_of_life_image: Res<GameOfLifeImage>,
8888
render_device: Res<RenderDevice>,
8989
) {
90-
let view = &gpu_images[&game_of_life_image.0];
90+
let view = &gpu_images[&game_of_life_image.0.id];
9191
let bind_group = render_device.create_bind_group(&BindGroupDescriptor {
9292
label: None,
9393
layout: &pipeline.texture_bind_group_layout,

examples/shader/shader_defs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ fn queue_custom(
147147
let view_matrix = view.transform.compute_matrix();
148148
let view_row_2 = view_matrix.row(2);
149149
for (entity, mesh_handle, mesh_uniform, is_red) in material_meshes.iter() {
150-
if let Some(mesh) = render_meshes.get(mesh_handle) {
150+
if let Some(mesh) = render_meshes.get(&mesh_handle.id) {
151151
let key = key | MeshPipelineKey::from_primitive_topology(mesh.primitive_topology);
152152
let pipeline =
153153
pipelines.specialize(&mut pipeline_cache, &custom_pipeline, (*is_red, key));

examples/shader/shader_instancing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl EntityRenderCommand for DrawMeshInstanced {
231231
let mesh_handle = mesh_query.get(item).unwrap();
232232
let instance_buffer = instance_buffer_query.get(item).unwrap();
233233

234-
let gpu_mesh = match meshes.into_inner().get(mesh_handle) {
234+
let gpu_mesh = match meshes.into_inner().get(&mesh_handle.id) {
235235
Some(gpu_mesh) => gpu_mesh,
236236
None => return RenderCommandResult::Failure,
237237
};

0 commit comments

Comments
 (0)