Skip to content

Commit

Permalink
Added ability to share textures across windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Dec 26, 2023
1 parent cda8f82 commit fec4ce6
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 94 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `UnwindSafe` has been removed from the bounds of `WindowBehavior::Context`,
and various types may or may no longer implmement `UnwindSafe`. The underlying
requirement for this has been removed from `appit`.
- `Texture::lazy_from_data` and `Texture::lazy_from_image` have been refactored
into a new type: `LazyTexture::from_data`/`LazyTexture::from_image`.
`LazyTexture` is able to be shared across different windows/wgpu rendering
contexts by loading a copy of its data once per context it is used within. The
previous lazy texture support created textures that weren't able to be shared
between windows.
- `include_texture!` now returns a `LazyTexture` instead of a `Texture`.

## Added

Expand Down
4 changes: 2 additions & 2 deletions examples/lazy-texture.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use appit::winit::error::EventLoopError;
use kludgine::figures::{Lp2D, Point};
use kludgine::Texture;
use kludgine::LazyTexture;

fn main() -> Result<(), EventLoopError> {
let texture = Texture::lazy_from_image(
let texture = LazyTexture::from_image(
image::open("./examples/assets/k.png").unwrap(),
wgpu::FilterMode::Linear,
);
Expand Down
6 changes: 3 additions & 3 deletions src/atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ impl TextureCollection {
.device()
.create_command_encoder(&wgpu::CommandEncoderDescriptor::default());
commands.copy_texture_to_texture(
this.texture.wgpu(graphics).as_image_copy(),
new_texture.wgpu(graphics).as_image_copy(),
this.texture.data.wgpu.as_image_copy(),
new_texture.data.wgpu.as_image_copy(),
this.texture.size.into(),
);
graphics.queue().submit([commands.finish()]);
Expand All @@ -145,7 +145,7 @@ impl TextureCollection {

graphics.queue().write_texture(
wgpu::ImageCopyTexture {
texture: this.texture.wgpu(graphics),
texture: &this.texture.data.wgpu,
mip_level: 0,
origin: region.origin.into(),
aspect: wgpu::TextureAspect::All,
Expand Down
Loading

0 comments on commit fec4ce6

Please sign in to comment.