Skip to content

Commit

Permalink
Enable wgpu
Browse files Browse the repository at this point in the history
  • Loading branch information
valadaptive committed Aug 30, 2024
1 parent 268a353 commit f4226f7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 26 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repository = "https://github.com/valadaptive/ntsc-rs/tree/main/crates/gui"
[dependencies]
ntscrs = { path = "../ntscrs" }
arboard = "3.4.0"
eframe = { version = "0.28.1", features=["persistence"] }
eframe = { version = "0.28.1", features=["persistence", "wgpu"] }
# The dirs maintainer has intentionally inserted an MPL dependency into this package.
# https://github.com/dirs-dev/dirs-sys-rs/issues/21
# May his shoe forever contain a small pebble in it for making me waste time on this garbage.
Expand Down
21 changes: 14 additions & 7 deletions crates/gui/src/app/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,10 @@ impl NtscApp {

let tex = ctx.load_texture(
"preview",
egui::ColorImage::from_rgb([0, 0], &[]),
egui::ColorImage::from_rgb([1, 1], &[0, 0, 0]),
egui::TextureOptions::LINEAR,
);
let tex_sink = SinkTexture(Some(tex.clone()));
let tex_sink = SinkTexture::new(tex.clone());
let egui_ctx = EguiCtx(Some(ctx.clone()));
let video_sink = gstreamer::ElementFactory::make("eguisink")
.property("texture", tex_sink)
Expand Down Expand Up @@ -1835,9 +1835,7 @@ impl NtscApp {
ui.with_layout(
egui::Layout::centered_and_justified(egui::Direction::LeftToRight),
|ui| {
let Some(PipelineInfo {
preview, egui_sink, ..
}) = &mut self.pipeline
let Some(PipelineInfo { egui_sink, .. }) = &mut self.pipeline
else {
ui.add(
egui::Label::new(
Expand All @@ -1848,10 +1846,19 @@ impl NtscApp {
return;
};

if preview.size().iter().any(|dim| *dim == 0) {
let texture = {
let egui_sink =
egui_sink.downcast_ref::<elements::EguiSink>().unwrap();
let egui_sink = EguiSink::from_obj(egui_sink);
egui_sink.get_texture()
};

let (Some(preview), true) =
(texture.handle, texture.rendered_at_least_once)
else {
ui.add(egui::Spinner::new());
return;
}
};

let texture_size = if self.video_scale.enabled {
let texture_actual_size = preview.size_vec2();
Expand Down
44 changes: 26 additions & 18 deletions crates/gui/src/gst_utils/egui_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ use super::process_gst_frame::process_gst_frame;

#[derive(Clone, glib::Boxed, Default)]
#[boxed_type(name = "SinkTexture")]
pub struct SinkTexture(pub Option<TextureHandle>);
pub struct SinkTexture {
pub handle: Option<TextureHandle>,
pub rendered_at_least_once: bool,
}

impl SinkTexture {
pub fn new(handle: TextureHandle) -> Self {
Self {
handle: Some(handle),
rendered_at_least_once: false,
}
}
}

#[derive(Debug, Clone, Copy, PartialEq, glib::Boxed, Default)]
#[boxed_type(name = "VideoPreviewSetting")]
Expand All @@ -27,21 +39,16 @@ pub enum EffectPreviewSetting {

impl Debug for SinkTexture {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut t = f.debug_tuple("SinkTexture");

match &self.0 {
Some(_) => {
t.field(&"TextureHandle");
}
None => {
t.field(&"None");
}
}

t.finish()
f.debug_struct("SinkTexture")
.field("rendered_at_least_once", &self.rendered_at_least_once)
.finish()
}
}

#[derive(Debug, Clone, glib::Boxed, Default)]
#[boxed_type(name = "EguiCtx")]
pub struct EguiCtx(pub Option<Context>);

#[derive(glib::Properties, Default)]
#[properties(wrapper_type = super::elements::EguiSink)]
pub struct EguiSink {
Expand All @@ -63,10 +70,6 @@ pub struct EguiSink {
>,
}

#[derive(Debug, Clone, glib::Boxed, Default)]
#[boxed_type(name = "EguiCtx")]
pub struct EguiCtx(pub Option<Context>);

impl EguiSink {
fn set_settings(&self, value: NtscFilterSettings) {
*self.settings.lock().unwrap() = value;
Expand Down Expand Up @@ -107,6 +110,10 @@ impl EguiSink {
Ok(image)
}

pub fn get_texture(&self) -> SinkTexture {
self.texture.lock().unwrap().clone()
}

pub fn update_texture(&self) -> Result<(), gstreamer::FlowError> {
let mut tex = self.texture.lock().unwrap();
let vframe = self.last_frame.lock().unwrap();
Expand Down Expand Up @@ -144,14 +151,15 @@ impl EguiSink {
}
}

tex.0.as_mut().ok_or(gstreamer::FlowError::Error)?.set(
tex.handle.as_mut().ok_or(gstreamer::FlowError::Error)?.set(
image,
TextureOptions {
magnification: TextureFilter::Nearest,
minification: TextureFilter::Linear,
..Default::default()
},
);
tex.rendered_at_least_once = true;
if let Some(ctx) = &self.ctx.lock().unwrap().0 {
ctx.request_repaint();
}
Expand Down

0 comments on commit f4226f7

Please sign in to comment.