I am having a problem with rendering 2d sprites to a GL canvas. When my browser is on a lower resolution monitor it renders at a higher FPS than if it's rendering in a higher resolution monitor.
Mac Retina Display: 2880x1800 = ~20 FPS
External Monitor: 1920x1080 = ~60 FPS
WebGL is rendering at a faster FPS on my 1080 resolution monitor than it is on the Mac retina display.
What is the best practice to force WebGL to render at a lower resolution? I have tried looking for sources to help answer this but can't find anything online.
I've tried lowering the resolution as follows:
var ratio = 1
var width = $(window).width();
var height = $(window).height();
if (window.screen.height * window.devicePixelRatio > 1080) {
ratio = 1080/(window.screen.height * window.devicePixelRatio);
}
width = width*ratio;
height = height*ratio;
gl.canvas.width = width;
gl.canvas.height = height;
And then setting my viewport like this:
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
Update to code
var width = $(window).width();
var height = $(window).height();
if (window.screen.height * window.devicePixelRatio > 1080) {
glTools.ratio = 1080/(window.screen.height * window.devicePixelRatio);
} else {
glTools.ratio = 1;
}
width = Math.round(width*glTools.ratio);
height = Math.round(height*glTools.ratio);
glTools.gl.canvas.width = width;
glTools.gl.canvas.height = height;
glTools.gl.viewport(0, 0, width, height);
Performance Update Although the answer to this question is correct. I just wanted to point another culprit to my FPS in my video game. Having timers in my code and performing non-hardware accelerated css animations in my game managed to block the thread and therefore cause the render to be scheduled for later. You can see that the game renders at 60FPS at Obsidio