简体   繁体   中英

How do I measure FPS in my WebGL page using FPSMeter?

I am trying to measure the FPS that I am getting from my WebGL webpage, using FPSMeter . I would like to measure the FPS from within canvas element, in which I am rendering a graphic. The body and canvas are declared as follows:

<body onload="webGLStart();">

<canvas id="canvas" style="border: none;" width="800" height="500" align="center"></canvas>

</body>

I declared a new instance of FPSMeter and webGLStart() is defined as follows:

function webGLStart() {
    var canvas = document.getElementById("canvas");
    initGL(canvas);

    meter.tickStart();

    initShaders();      
    initBuffers();

    document.onkeydown = handleKeyDown;
    document.onkeyup = handleKeyUp;

    tick();
    meter.tick();
}

I am seeing the FPS meter on my page however the FPS begins at around 7 and drops to 0 after a second or so.

Does anyone know why this might be happening and how to fix it?

Many thanks!

You need to move the benchmarking code into your function that does the drawing, like so:

function tick() {
    meter.tickStart();
    // draw the scene here
    meter.tick();
    // requestAnimationFrame(tick) ?
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM