brendanzab / gl-rs

An OpenGL function pointer loader for Rust
Apache License 2.0
680 stars 115 forks source link

gl::clear waits for vsync? #505

Closed RainbowCookie32 closed 4 years ago

RainbowCookie32 commented 4 years ago

Hi! First of all, I'm still pretty much a noob when it comes to OGL and graphics programming, but I'm slowly trying to improve :D

With that out of the way, I'm using gl on some areas of my code, and I noticed that clear() seems to take 16ms to run, which leads me to believe that it's waiting on VSync to do its job. Now, this wouldn't bother me usually, but it's bottlenecking my render loop so it's a problem. I have a second window that needs faster updating, and the 16ms wait is killing it.

I've been looking around, but I couldn't find anything related to this, is there any way to disable this wait? I couldn't really figure out a way to check/disable vsync, so that's why I came here now. My current workaround is to avoid updating that window if it's not on focus, but it's not really the nicest way to go about it imo.

Bzomak commented 4 years ago

Hi @RainbowCookie32! How are you creating your windows? Are you using glutin, winit, glfw-rs, sdl2, or something else?

RainbowCookie32 commented 4 years ago

Both windows are created with SDL2. The one I'm clearing with gl is used for imgui (followed the example from this crate https://github.com/michaelfairley/rust-imgui-sdl2), the other one I clear from the sdl canvas. Trying to clear this one using an sdl canvas didn't quite work out, ended up with flickering on it. The gl::Clear() approach is the one worked out the best, but with this issue.

Bzomak commented 4 years ago

Hmm. In the example you mentioned it has the line ::std::thread::sleep(::std::time::Duration::new(0, 1_000_000_000u32 / 60));

That looks to me as if it puts the thread to sleep for 16ms... If you have included this line you could try removing it?

If that is not a problem, and it is indeed a vsync issue, then you could try changing the SwapInterval with gl_set_swap_interval.

RainbowCookie32 commented 4 years ago

Yeah, I didn't include the sleep. gl_set_swap_interval(0) did fix the issue, now it's rendering as fast as possible. Never actually though about looking into SDL for a solution for some reason :sweat_smile:

Thank you.