Skip to content

Commit

Permalink
[Fix] reset internal cached state for face culling when the device is…
Browse files Browse the repository at this point in the history
… restored (#6155)

Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
  • Loading branch information
mvaligursky and Martin Valigursky committed Mar 13, 2024
1 parent 48141cc commit 50f1756
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/platform/graphics/webgl/webgl-graphics-device.js
Expand Up @@ -337,15 +337,13 @@ class WebglGraphicsDevice extends GraphicsDevice {

this._contextLostHandler = (event) => {
event.preventDefault();
this.contextLost = true;
this.loseContext();
Debug.log('pc.GraphicsDevice: WebGL context lost.');
this.fire('devicelost');
};

this._contextRestoredHandler = () => {
Debug.log('pc.GraphicsDevice: WebGL context restored.');
this.contextLost = false;
this.restoreContext();
this.fire('devicerestored');
};
Expand Down Expand Up @@ -1229,6 +1227,8 @@ class WebglGraphicsDevice extends GraphicsDevice {
gl.blendColor(0, 0, 0, 0);

gl.enable(gl.CULL_FACE);

this.cullFace = gl.BACK;
gl.cullFace(gl.BACK);

// default depth state
Expand Down Expand Up @@ -1321,6 +1321,8 @@ class WebglGraphicsDevice extends GraphicsDevice {
*/
loseContext() {

this.contextLost = true;

// force the backbuffer to be recreated on restore
this.backBufferSize.set(-1, -1);

Expand Down Expand Up @@ -1355,6 +1357,9 @@ class WebglGraphicsDevice extends GraphicsDevice {
* @ignore
*/
restoreContext() {

this.contextLost = false;

this.initializeExtensions();
this.initializeCapabilities();
this.initializeRenderState();
Expand Down

0 comments on commit 50f1756

Please sign in to comment.