Skip to content

Commit

Permalink
Impl RenderAssets for GizmoBuffers instead of GizmoDrawData
Browse files Browse the repository at this point in the history
Addresses Bevy [12827](bevyengine/bevy#12827)
  • Loading branch information
zhaop committed Jun 24, 2024
1 parent e6fc4ce commit 4c7fbeb
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions crates/transform-gizmo-bevy/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Plugin for TransformGizmoRenderPlugin {
load_internal_asset!(app, GIZMO_SHADER_HANDLE, "gizmo.wgsl", Shader::from_wgsl);

app.init_resource::<DrawDataHandles>()
.add_plugins(RenderAssetPlugin::<GizmoDrawData>::default());
.add_plugins(RenderAssetPlugin::<GizmoBuffers>::default());

let Some(render_app) = app.get_sub_app_mut(RenderApp) else {
return;
Expand All @@ -57,7 +57,7 @@ impl Plugin for TransformGizmoRenderPlugin {
Render,
queue_transform_gizmos
.in_set(RenderSet::Queue)
.after(prepare_assets::<GizmoDrawData>),
.after(prepare_assets::<GizmoBuffers>),
);
}

Expand Down Expand Up @@ -100,33 +100,33 @@ pub(crate) struct GizmoBuffers {
index_count: u32,
}

impl RenderAsset for GizmoDrawData {
type PreparedAsset = GizmoBuffers;
impl RenderAsset for GizmoBuffers {
type SourceAsset = GizmoDrawData;
type Param = SRes<RenderDevice>;

fn asset_usage(&self) -> RenderAssetUsages {
fn asset_usage(_source_asset: &Self::SourceAsset) -> RenderAssetUsages {
RenderAssetUsages::all()
}

fn prepare_asset(
self,
source_asset: Self::SourceAsset,
render_device: &mut SystemParamItem<Self::Param>,
) -> Result<Self::PreparedAsset, PrepareAssetError<Self>> {
let position_buffer_data = cast_slice(&self.0.vertices);
) -> Result<Self, PrepareAssetError<Self::SourceAsset>> {
let position_buffer_data = cast_slice(&source_asset.0.vertices);
let position_buffer = render_device.create_buffer_with_data(&BufferInitDescriptor {
usage: BufferUsages::VERTEX,
label: Some("TransformGizmo Position Buffer"),
contents: position_buffer_data,
});

let index_buffer_data = cast_slice(&self.0.indices);
let index_buffer_data = cast_slice(&source_asset.0.indices);
let index_buffer = render_device.create_buffer_with_data(&BufferInitDescriptor {
usage: BufferUsages::INDEX,
label: Some("TransformGizmo Index Buffer"),
contents: index_buffer_data,
});

let color_buffer_data = cast_slice(&self.0.colors);
let color_buffer_data = cast_slice(&source_asset.0.colors);
let color_buffer = render_device.create_buffer_with_data(&BufferInitDescriptor {
usage: BufferUsages::VERTEX,
label: Some("TransformGizmo Color Buffer"),
Expand All @@ -137,7 +137,7 @@ impl RenderAsset for GizmoDrawData {
index_buffer,
position_buffer,
color_buffer,
index_count: self.0.indices.len() as u32,
index_count: source_asset.0.indices.len() as u32,
})
}
}
Expand All @@ -147,7 +147,7 @@ struct DrawTransformGizmo;
impl<P: PhaseItem> RenderCommand<P> for DrawTransformGizmo {
type ViewQuery = ();
type ItemQuery = Read<Handle<GizmoDrawData>>;
type Param = SRes<RenderAssets<GizmoDrawData>>;
type Param = SRes<RenderAssets<GizmoBuffers>>;

#[inline]
fn render<'w>(
Expand Down Expand Up @@ -288,7 +288,7 @@ fn queue_transform_gizmos(
pipeline_cache: Res<PipelineCache>,
msaa: Res<Msaa>,
transform_gizmos: Query<(Entity, &Handle<GizmoDrawData>)>,
transform_gizmo_assets: Res<RenderAssets<GizmoDrawData>>,
transform_gizmo_assets: Res<RenderAssets<GizmoBuffers>>,
mut views: Query<(
&ExtractedView,
&mut RenderPhase<Transparent3d>,
Expand Down

0 comments on commit 4c7fbeb

Please sign in to comment.