diff --git a/src/gl_debug.rs b/src/gl_debug.rs new file mode 100644 index 0000000000..0bc007fbf0 --- /dev/null +++ b/src/gl_debug.rs @@ -0,0 +1,33 @@ +//! Add an OpenGL debugging callback. + +use gl::types::*; +use gl; +use std::ffi::CStr; +use std::os::raw::c_void; +use std::ptr::null; + +extern "system" fn glDebugOutput( + source: GLenum, + gltype: GLenum, + id: GLuint, + severity: GLenum, + length: GLsizei, + message: *const GLchar, + userParam: *mut c_void) +{ + let message = unsafe { CStr::from_ptr(message) }; + //println!(">>> [GL DEBUG] id: {:?} message: {:?} source: {:?} type: {:?} severity: {:?}", + // id, message, source, gltype, severity); + println!(">>> [GL DEBUG] id: {:?} message: {:?}", id, message); +} + +pub fn enable_opengl_debugging() { + unsafe { + // Set debugging. This can be expensive, so we should be able to trigger it with a flag. + gl::Enable(gl::DEBUG_OUTPUT); + gl::Enable(gl::DEBUG_OUTPUT_SYNCHRONOUS); + gl::DebugMessageCallback(Some(glDebugOutput), null()); + // Opt into everything. + gl::DebugMessageControl(gl::DONT_CARE, gl::DONT_CARE, gl::DONT_CARE, 0, null(), gl::TRUE); + } +} diff --git a/src/graphics_gl.rs b/src/graphics_gl.rs index aa405553e2..f1034bf961 100644 --- a/src/graphics_gl.rs +++ b/src/graphics_gl.rs @@ -26,6 +26,7 @@ use point_cloud::point_cloud_compute_shader::PointCloudComputeShader; use point_cloud::point_cloud_renderer_shader::PointCloudRendererShader; use point_cloud::point_cloud_visualiser::{PointCloudVisualizer, PointCloudVisualizerError}; use point_cloud::viewer_image::ViewerImage; +use gl_debug::enable_opengl_debugging; //use shader::Shader; @@ -110,20 +111,6 @@ static TEXTURE_CHECKERBOARD : [GLfloat; 12] = [ 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, ]; -extern "system" fn glDebugOutput( - source: GLenum, - gltype: GLenum, - id: GLuint, - severity: GLenum, - length: GLsizei, - message: *const GLchar, - userParam: *mut c_void) -{ - let message = unsafe { CStr::from_ptr(message) }; - println!(">>> [GL DEBUG] id: {:?} message: {:?} source: {:?} type: {:?} severity: {:?}", - id, message, source, gltype, severity); -} - pub fn run(capture_provider: Arc, calibration_data: k4a_sys::k4a_calibration_t) { let event_loop = EventLoop::new(); let window = WindowBuilder::new(); @@ -151,14 +138,7 @@ pub fn run(capture_provider: Arc, calibration_data: k4a_sys::k4 } */ - unsafe { - // Set debugging. This can be expensive, so we should be able to trigger it with a flag. - gl::Enable(gl::DEBUG_OUTPUT); - gl::Enable(gl::DEBUG_OUTPUT_SYNCHRONOUS); - gl::DebugMessageCallback(Some(glDebugOutput), null()); - // Opt into everything. - gl::DebugMessageControl(gl::DONT_CARE, gl::DONT_CARE, gl::DONT_CARE, 0, null(), gl::TRUE); - } + enable_opengl_debugging(); // Create GLSL shaders /*let vs = compile_shader(VERTEX_SHADER_SRC, gl::VERTEX_SHADER); diff --git a/src/graphics_imgui.rs b/src/graphics_imgui.rs index 1f8cf02460..f7a135b178 100644 --- a/src/graphics_imgui.rs +++ b/src/graphics_imgui.rs @@ -1,41 +1,41 @@ use imgui::*; -use support; -use std::sync::Arc; -use sensor_control::CaptureProvider; -use point_cloud::point_cloud_visualiser::PointCloudVisualizer; +use glium::Display; +use glutin::ContextBuilder; use glutin::event::{Event, WindowEvent}; use glutin::event_loop::{ControlFlow, EventLoop}; +use glium::backend::Facade; use glutin::window::WindowBuilder; -use glutin::ContextBuilder; +use point_cloud::point_cloud_visualiser::{PointCloudVisualizer, PointCloudVisualizerError}; +use point_cloud::viewer_image::ViewerImage; +use sensor_control::CaptureProvider; +use std::sync::Arc; +use support; +use gl_debug::enable_opengl_debugging; pub fn run(capture_provider: Arc, calibration_data: k4a_sys::k4a_calibration_t) { - /*let event_loop = EventLoop::new(); - let window = WindowBuilder::new(); - let gl_window = ContextBuilder::new() - .build_windowed(window, &event_loop) - .unwrap(); - // It is essential to make the context current before calling `gl::load_with`. - let gl_window = unsafe { gl_window.make_current() }.unwrap(); - - // Load the OpenGL function pointers - gl::load_with(|symbol| gl_window.get_proc_address(symbol));*/ - let system = support::init(file!()); - // Load the OpenGL function pointers - //gl::load_with(|symbol| gl_window.get_proc_address(symbol)); - - let mut visualizer = PointCloudVisualizer::new( + /*let mut visualizer = PointCloudVisualizer::new( true, calibration_data - ); + );*/ + + let context = system.display.get_context(); + + enable_opengl_debugging(); + + /*let mut texture = ViewerImage::create( + 800, + 800, + None, + None + ).expect("ViewerImage texture creation should work");*/ system.main_loop(move |_, ui| { - println!("main loop"); - Window::new(im_str!("Hello world")) - .size([300.0, 110.0], Condition::FirstUseEver) + //.size([300.0, 110.0], Condition::FirstUseEver) + .size([300.0, 110.0], Condition::Always) .build(ui, || { ui.text(im_str!("Hello world!")); ui.text(im_str!("こんにちは世界!")); @@ -47,5 +47,34 @@ pub fn run(capture_provider: Arc, calibration_data: k4a_sys::k4 mouse_pos[0], mouse_pos[1] )); }); + + + // TODO: This belongs in a worker thread with buffers on both producer and consumer. + if let Some(capture) = capture_provider.get_capture() { + //println!("\n\n------- event loop: got capture ------"); + //println!("capture: {:?}", capture.0); + unsafe { + // TODO: CLEARING FOR TEMPORARY DEBUGGING. + //gl::ClearColor(0.8, 0.0, 0.0, 1.0); + //gl::Clear(gl::COLOR_BUFFER_BIT); + } + + /*visualizer.update_texture(&texture, capture) + .map(|_| { + println!("UPDATED TEXTURE!"); + }) + .map_err(|err| { + match err { + PointCloudVisualizerError::MissingDepthImage => { println!("Missing depth image"); }, + PointCloudVisualizerError::MissingColorImage => { println!("Missing color image"); }, + _ => { + unreachable!("Error: {:?}", err); + } + } + });*/ + + //println!("swapping buffers"); + //gl_window.swap_buffers().unwrap(); + } }); } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index a291357190..992d65b6c1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,6 +65,7 @@ pub mod k4a_sys_wrapper; pub mod old_graphics_libraries; pub mod support; pub mod old_k4a_wrapper; +pub mod gl_debug; pub mod opengl_wrapper; pub mod point_cloud; pub mod sensor_control;