phaserjs / phaser-ce

Phaser CE is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
http://phaser.io
MIT License
1.34k stars 491 forks source link

Add powerPreference hint to PIXI WebGLRenderer context options #652

Closed rarecoil closed 4 years ago

rarecoil commented 4 years ago

This PR

As the changelog doesn't seem to have an "unreleased" section, I didn't add to this. This is my first pull request to this project, so I suspect it may need some massaging / discussion; I was going to file an issue but decided it is probably best to try to make an effort to fix the problem instead of complain.

Describe the changes below:

This adds support for powerPreference hinting to the PIXI WebGLRenderer's context options, per the spec at https://www.khronos.org/registry/webgl/specs/latest/1.0/. In situations where a high-performance GPU is available (e.g. laptops with discrete GPUs) this offers the ability to hint to the browser that you would like to use one GPU or the other. Note that this may cause greater power consumption.

Per the WebGL spec, "Applications that request high-performance should test and maintain robust context loss handling, as User Agents are very likely to decide to lose background high-performance contexts." Phaser appears to handle context loss, but I am admittedly new to this codebase and believe that the community should probably test this.

Phaser 3.x has this setting in game config (/src/core/Config.js), and WebGLRenderer.js L581 instantiates the context in a similar fashion to this pull request. This is an attempt to backport the functionality to Phaser CE.