Skip to content

Commit

Permalink
Support Arc<wgpu::TextureView> for adding custom textures to yakui-wgpu
Browse files Browse the repository at this point in the history
  • Loading branch information
LPGhatguy committed Oct 31, 2023
1 parent 2274a21 commit 6c939b9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 5 additions & 4 deletions crates/yakui-wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod texture;
use std::collections::HashMap;
use std::mem::size_of;
use std::ops::Range;
use std::sync::Arc;

use buffer::Buffer;
use bytemuck::{Pod, Zeroable};
Expand Down Expand Up @@ -128,12 +129,12 @@ impl YakuiWgpu {
/// any yakui widgets.
pub fn add_texture(
&mut self,
view: wgpu::TextureView,
view: impl Into<Arc<wgpu::TextureView>>,
min_filter: wgpu::FilterMode,
mag_filter: wgpu::FilterMode,
) -> TextureId {
let index = self.textures.insert(GpuTexture {
view,
view: view.into(),
min_filter,
mag_filter,
});
Expand All @@ -146,7 +147,7 @@ impl YakuiWgpu {
///
/// Will panic if `TextureId` was not created from a previous call to
/// `add_texture`.
pub fn update_texture(&mut self, id: TextureId, view: wgpu::TextureView) {
pub fn update_texture(&mut self, id: TextureId, view: impl Into<Arc<wgpu::TextureView>>) {
let index = match id {
TextureId::User(bits) => Index::from_bits(bits).expect("invalid user texture"),
_ => panic!("invalid user texture"),
Expand All @@ -156,7 +157,7 @@ impl YakuiWgpu {
.textures
.get_mut(index)
.expect("user texture does not exist");
existing.view = view;
existing.view = view.into();
}

#[must_use = "YakuiWgpu::paint returns a command buffer which MUST be submitted to wgpu."]
Expand Down
4 changes: 3 additions & 1 deletion crates/yakui-wgpu/src/texture.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;

use glam::UVec2;
use yakui_core::paint::{Texture, TextureFilter, TextureFormat};

Expand All @@ -11,7 +13,7 @@ pub(crate) struct GpuManagedTexture {
}

pub(crate) struct GpuTexture {
pub view: wgpu::TextureView,
pub view: Arc<wgpu::TextureView>,
pub min_filter: wgpu::FilterMode,
pub mag_filter: wgpu::FilterMode,
}
Expand Down

0 comments on commit 6c939b9

Please sign in to comment.