mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 09:48:44 +00:00
smaller critical section, but didn't fix lag
This commit is contained in:
1 parent
3ce5d4d871
commit
58c72b24c3
2 files changed
+23
-17
No files matched your search
+18
-15
@@ -19,6 +19,7 @@ use std::sync::{Arc, PoisonError, RwLockReadGuard};
|
||||
use std::sync::RwLock;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use glium::{Display, glutin, Surface};
|
||||
use glium::glutin::event::{Event, StartCause};
|
||||
@@ -52,7 +53,7 @@ pub mod k4a_sys_wrapper;
|
||||
pub mod sensors;
|
||||
|
||||
pub fn main() {
|
||||
let frame : Arc<RwLock<Option<DynamicImage>>> = Arc::new(RwLock::new(None));
|
||||
let frame : Arc<Mutex<Option<DynamicImage>>> = Arc::new(Mutex::new(None));
|
||||
let frame2 = frame.clone();
|
||||
|
||||
thread::spawn(move || {
|
||||
@@ -167,25 +168,27 @@ pub fn main() {
|
||||
let mut target = display.draw();
|
||||
target.clear_color(0.0, 0.0, 1.0, 1.0);
|
||||
|
||||
let mut texture_frame : Option<Texture2d> = None;
|
||||
let mut dynamic_image : Option<DynamicImage> = None;
|
||||
|
||||
match frame.read() {
|
||||
Ok(lock) => {
|
||||
let frame_image = lock.as_ref();
|
||||
|
||||
match lock.as_ref() {
|
||||
Some(dynamic_image) => {
|
||||
let frame_image = dynamic_image.to_rgba();
|
||||
let frame_dimensions = frame_image.dimensions();
|
||||
let frame_image = glium::texture::RawImage2d::from_raw_rgba_reversed(&frame_image.into_raw(), frame_dimensions);
|
||||
texture_frame = Some(glium::texture::Texture2d::new(&display, frame_image).unwrap());
|
||||
},
|
||||
None => {},
|
||||
}
|
||||
match frame.lock() {
|
||||
Ok(mut lock) => {
|
||||
dynamic_image = lock.take();
|
||||
},
|
||||
Err(_) => {},
|
||||
}
|
||||
|
||||
let mut texture_frame : Option<Texture2d> = None;
|
||||
|
||||
match dynamic_image {
|
||||
Some(image) => {
|
||||
let frame_image = image.to_rgba();
|
||||
let frame_dimensions = frame_image.dimensions();
|
||||
let frame_image = glium::texture::RawImage2d::from_raw_rgba_reversed(&frame_image.into_raw(), frame_dimensions);
|
||||
texture_frame = Some(glium::texture::Texture2d::new(&display, frame_image).unwrap());
|
||||
},
|
||||
None => {},
|
||||
}
|
||||
|
||||
let texture_to_use: &Texture2d = texture_frame.as_ref().unwrap_or(&textureB);
|
||||
|
||||
let uniforms = uniform! {
|
||||
|
||||
+5
-2
@@ -5,6 +5,7 @@ use std::os::raw::c_char;
|
||||
use std::ptr;
|
||||
use std::slice;
|
||||
use std::sync::{Arc, PoisonError, RwLockWriteGuard};
|
||||
use std::sync::Mutex;
|
||||
use std::sync::RwLock;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
@@ -33,7 +34,7 @@ use k4a_sys_wrapper::Device;
|
||||
use k4a_sys_wrapper::device_get_installed_count;
|
||||
use k4a_sys_wrapper::Image;
|
||||
|
||||
pub fn capture_thread(frame: Arc<RwLock<Option<DynamicImage>>>) {
|
||||
pub fn capture_thread(frame: Arc<Mutex<Option<DynamicImage>>>) {
|
||||
let installed_devices = device_get_installed_count();
|
||||
println!("Installed devices: {}", installed_devices);
|
||||
|
||||
@@ -60,14 +61,16 @@ pub fn capture_thread(frame: Arc<RwLock<Option<DynamicImage>>>) {
|
||||
continue; // We didn't grab a frame.
|
||||
},
|
||||
}
|
||||
println!("Got frame!");
|
||||
|
||||
let image = captured_image.unwrap();
|
||||
|
||||
let image_image = depth_to_image(&image)
|
||||
.expect("depth_to_image should work");
|
||||
|
||||
match frame.write() {
|
||||
match frame.lock() {
|
||||
Ok(mut lock) => {
|
||||
println!("Wrote to mutex!");
|
||||
*lock = Some(image_image)
|
||||
},
|
||||
Err(_) => {
|
||||
|
||||
Reference in new issue
Block a user