aboutsummaryrefslogtreecommitdiff
path: root/src/render_assets.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/render_assets.rs')
-rw-r--r--src/render_assets.rs35
1 files changed, 16 insertions, 19 deletions
diff --git a/src/render_assets.rs b/src/render_assets.rs
index e5277d7..48efdd0 100644
--- a/src/render_assets.rs
+++ b/src/render_assets.rs
@@ -2,14 +2,14 @@ use bevy::{
ecs::system::{lifetimeless::SRes, SystemParamItem},
prelude::*,
render::{
- render_asset::{PrepareAssetError, RenderAsset, RenderAssetUsages, RenderAssets},
+ render_asset::{PrepareAssetError, RenderAsset, RenderAssets},
render_resource::{Buffer, BufferDescriptor, BufferUsages, Extent3d, TextureFormat},
- renderer::RenderDevice,
+ renderer::RenderDevice, texture::GpuImage,
},
};
-/// Render-world version of FramebufferExtractSource
-pub struct GpuFramebufferExtractSource {
+/// Render-world version of HeadlessRenderSource
+pub struct GpuHeadlessRenderSource {
pub(crate) buffer: Buffer,
pub(crate) source_handle: Handle<Image>,
pub(crate) source_size: Extent3d,
@@ -18,26 +18,22 @@ pub struct GpuFramebufferExtractSource {
pub(crate) format: TextureFormat,
}
-/// Framebuffer extraction source. Contains a handle to the render texture which will be extracted
+/// Headless render source. Contains a handle to the render texture which will be copied
/// from.
#[derive(Asset, Reflect, Clone, Default)]
-pub struct FramebufferExtractSource(pub Handle<Image>);
+pub struct HeadlessRenderSource(pub Handle<Image>);
-impl RenderAsset for FramebufferExtractSource {
- type PreparedAsset = GpuFramebufferExtractSource;
- type Param = (SRes<RenderDevice>, SRes<RenderAssets<Image>>);
-
- fn asset_usage(&self) -> RenderAssetUsages {
- RenderAssetUsages::default()
- }
+impl RenderAsset for GpuHeadlessRenderSource {
+ type SourceAsset = HeadlessRenderSource;
+ type Param = (SRes<RenderDevice>, SRes<RenderAssets<GpuImage>>);
fn prepare_asset(
- self,
+ source_asset: Self::SourceAsset,
(device, images): &mut SystemParamItem<Self::Param>,
- ) -> Result<Self::PreparedAsset, PrepareAssetError<Self>> {
- let Some(gpu_image) = images.get(&self.0) else {
+ ) -> Result<Self, PrepareAssetError<Self::SourceAsset>> {
+ let Some(gpu_image) = images.get(source_asset.0.id()) else {
warn!("Failed to get GPU image");
- return Err(PrepareAssetError::RetryNextUpdate(self));
+ return Err(PrepareAssetError::RetryNextUpdate(source_asset));
};
let size = gpu_image.texture.size();
@@ -47,18 +43,19 @@ impl RenderAsset for FramebufferExtractSource {
let padded_bytes_per_row =
RenderDevice::align_copy_bytes_per_row(bytes_per_row as usize) as u32;
- Ok(GpuFramebufferExtractSource {
+ Ok(GpuHeadlessRenderSource {
buffer: device.create_buffer(&BufferDescriptor {
label: Some("framebuffer_extract_buffer"),
size: (size.height * padded_bytes_per_row) as u64,
usage: BufferUsages::COPY_DST | BufferUsages::MAP_READ,
mapped_at_creation: false,
}),
- source_handle: self.0.clone(),
+ source_handle: source_asset.0.clone(),
source_size: size,
bytes_per_row,
padded_bytes_per_row,
format,
})
}
+
}