extract opengl debugging

This commit is contained in:
Brandon Thomas committed 2020-04-20 02:35:00 -04:00
1 parent 2f56db8c06
commit 730bf8b3ce
4 files changed
+89 -46

No files matched your search

+33
View File
@@ -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);
}
}
+2 -22
View File
@@ -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<CaptureProvider>, 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<CaptureProvider>, 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);
+53 -24
View File
@@ -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<CaptureProvider>, 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<CaptureProvider>, 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();
}
});
}
+1
View File
@@ -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;