我使用glium作为我的 opengl 绑定,但不可能获得可靠的 60 FPS。
一个最小的测试用例是
#[macro_use]
extern crate glium;
extern crate clock_ticks;
use glium::Surface;
use glium::glutin;
fn main() {
use glium::DisplayBuild;
let display = glutin::WindowBuilder::new()
.build_glium()
.unwrap();
let frames = 60 * 5;
let trials = 3;
for _ in 0.. trials {
let start_ns = clock_ticks::precise_time_ns();
for _ in 0..frames {
display.draw().finish().unwrap();
}
let duration_ns = clock_ticks::precise_time_ns() - start_ns;
let duration_s = (duration_ns as f64) / 1_000_000_000f64;
let fps = (frames as f64) / duration_s;
let dropped = (duration_s - (frames as f64 * (1f64/60f64))) / (1f64/60f64);
println!("{} frames in {:.6} seconds = {:.3} fps (estimated {:.1} frames dropped)", frames, duration_s, fps, dropped);
}
}
我期望 60 FPS,但在我运行它时经常显示 59 FPS(在 OSX 中)。该项目在 github 上可用,以便于编译和运行。
有什么办法可以调整 glium 使其不会掉帧?OSX 会覆盖该vsync
设置,因此无法不等待每帧之间的垂直同步。