Skip to content

Commit

Permalink
glium: Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dcz-self committed Oct 9, 2024
1 parent 62db5f3 commit d1a48c9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 49 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ v4l-sys = { path = "v4l-sys", version = "0.3.0", optional = true }
v4l2-sys = { path = "v4l2-sys", version = "0.3.0", package="v4l2-sys-mit", optional = true }

[dev-dependencies]
glium = "0.34"
glium = "0.35"
jpeg-decoder = "0.3.0"
winit = "0.29"
winit = "0.30"

[features]
default = ["v4l2"]
Expand Down
116 changes: 69 additions & 47 deletions examples/glium.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ use v4l::video::capture::Parameters;
use v4l::video::Capture;
use v4l::{Format, FourCC};

use winit::application::ApplicationHandler;
use winit::event::WindowEvent;
use winit::event_loop::ActiveEventLoop;
use winit::window::WindowId;

#[derive(Debug, Clone, Copy)]
enum UserEvent {
WakeUp,
Expand Down Expand Up @@ -157,58 +162,75 @@ fn main() -> io::Result<()> {
}
});

event_loop
.run(move |event, elwt| {
let t0 = Instant::now();
let data = rx.recv().unwrap();
let t1 = Instant::now();

let image = glium::texture::RawImage2d::from_raw_rgb_reversed(
&data,
(format.width, format.height),
);
let opengl_texture = glium::texture::Texture2d::new(&display, image).unwrap();

// building the uniforms
let uniforms = uniform! {
matrix: [
[1.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 1.0f32]
],
tex: &opengl_texture
};
struct LoopHandler<F> {
user_event: F,
}

// drawing a frame

let mut target = display.draw();
target.clear_color(0.0, 0.0, 0.0, 0.0);
target
.draw(
&vertex_buffer,
&index_buffer,
&program,
&uniforms,
&Default::default(),
)
.unwrap();
target.finish().unwrap();
impl<F: Fn(UserEvent)> ApplicationHandler<UserEvent> for LoopHandler<F> {
fn resumed(&mut self, _event_loop: &ActiveEventLoop) {}

fn window_event(
&mut self,
event_loop: &ActiveEventLoop,
_window_id: WindowId,
event: WindowEvent,
) {
// polling and handling the events received by the window
if let winit::event::Event::WindowEvent {
event: winit::event::WindowEvent::CloseRequested,
..
} = event
{
elwt.exit();
if let winit::event::WindowEvent::CloseRequested = event {
event_loop.exit();
}
}

print!(
"\rms: {}\t (buffer) + {}\t (UI)",
t1.duration_since(t0).as_millis(),
t1.elapsed().as_millis(),
);
fn user_event(&mut self, _event_loop: &ActiveEventLoop, event: UserEvent) {
(self.user_event)(event)
}
}

event_loop
.run_app(&mut LoopHandler {
user_event: move |_event| {
let t0 = Instant::now();
let data = rx.recv().unwrap();
let t1 = Instant::now();

let image = glium::texture::RawImage2d::from_raw_rgb_reversed(
&data,
(format.width, format.height),
);
let opengl_texture = glium::texture::Texture2d::new(&display, image).unwrap();

// building the uniforms
let uniforms = uniform! {
matrix: [
[1.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 1.0f32]
],
tex: &opengl_texture
};

// drawing a frame

let mut target = display.draw();
target.clear_color(0.0, 0.0, 0.0, 0.0);
target
.draw(
&vertex_buffer,
&index_buffer,
&program,
&uniforms,
&Default::default(),
)
.unwrap();
target.finish().unwrap();

print!(
"\rms: {}\t (buffer) + {}\t (UI)",
t1.duration_since(t0).as_millis(),
t1.elapsed().as_millis(),
);
},
})
.map_err(io::Error::other)
}

0 comments on commit d1a48c9

Please sign in to comment.