Recording FPS in webGL

后端 未结 5 557
甜味超标
甜味超标 2020-12-18 12:54

I am trying to compare performance for 3d applications on mobile devices. I have a 3d solar system set up in webGL and im trying to record or at least display the FPS. So

5条回答
  •  盖世英雄少女心
    2020-12-18 13:34

    Using a rotating array can do better. with dom element:

    the following script do the trick:

    var fpsLastTick = new Date().getTime();
    var fpsTri = [15, 15, 15]; // aims for 60fps
    
    function animate() {
      // your rendering logic blahh blahh.....
    
    
      // update fps at last
      var now = new Date().getTime();
      var frameTime = (now - fpsLastTick);
      fpsTri.shift(); // drop one
      fpsTri.push(frameTime); // append one
      fpsLastTick = now;
      fps = Math.floor(3000 / (fpsTri[0] + fpsTri[1] + fpsTri[2])); // mean of 3
      var fpsElement = document.getElementById('fps')
      if (fpsElement) {
        fpsElement.innerHTML = fps;
      }
    }

提交回复
热议问题