首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >避免glium中的丢帧

避免glium中的丢帧
EN

Stack Overflow用户
提问于 2015-09-28 02:46:22
回答 1查看 645关注 0票数 3

我使用glium作为我的opengl绑定,但它不可能获得一个可靠的60fps。

最小的测试用例是

代码语言:javascript
复制
#[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,但当我运行它(在OSX中)时,经常显示59 FPS。The project is available on github,便于编译和运行。

有没有办法调整glium,使它不会丢弃帧?OSX覆盖了vsync设置,所以不能不等待每一帧之间的vsync。

EN

回答 1

Stack Overflow用户

发布于 2015-09-28 10:31:50

是的,像@8bitree一样,我怀疑你的测量是错误的,而不是一个实际的问题。在我的系统上,Debian:

代码语言:javascript
复制
steve@warmachine:~/tmp/guess$ cargo run
     Running `target/debug/guess`
300 frames in 4.427656 seconds = 67.756 fps (estimated -34.3 frames dropped)
300 frames in 0.006892 seconds = 43529.834 fps (estimated -299.6 frames dropped)
300 frames in 0.006522 seconds = 45997.412 fps (estimated -299.6 frames dropped)
steve@warmachine:~/tmp/guess$ cargo run
     Running `target/debug/guess`
300 frames in 4.953447 seconds = 60.564 fps (estimated -2.8 frames dropped)
300 frames in 4.999410 seconds = 60.007 fps (estimated -0.0 frames dropped)
300 frames in 1.608712 seconds = 186.485 fps (estimated -203.5 frames dropped)

所以,是的,有些东西有点...很奇怪。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32811559

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档