Skip to content

Commit

Permalink
[Fix] When the defautl framebuffer is updates, refresh info about its…
Browse files Browse the repository at this point in the history
… format (#5784)

Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
  • Loading branch information
2 people authored and marklundin committed Nov 3, 2023
1 parent 38ae388 commit 9b9f783
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/platform/graphics/webgl/webgl-graphics-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,7 @@ class WebglGraphicsDevice extends GraphicsDevice {
this._deviceType = this.isWebGL2 ? DEVICETYPE_WEBGL2 : DEVICETYPE_WEBGL1;

// pixel format of the framebuffer
const alphaBits = gl.getParameter(gl.ALPHA_BITS);
this.backBufferFormat = alphaBits ? PIXELFORMAT_RGBA8 : PIXELFORMAT_RGB8;
this.updateBackbufferFormat(null);

const isChrome = platform.browserName === 'chrome';
const isSafari = platform.browserName === 'safari';
Expand Down Expand Up @@ -787,10 +786,24 @@ class WebglGraphicsDevice extends GraphicsDevice {
this.backBuffer.impl.suppliedColorFramebuffer = frameBuffer;
}

// Update framebuffer format based on the current framebuffer, as this is use to create matching multi-sampled framebuffer
updateBackbufferFormat(framebuffer) {
const gl = this.gl;
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
const alphaBits = this.gl.getParameter(this.gl.ALPHA_BITS);
this.backBufferFormat = alphaBits ? PIXELFORMAT_RGBA8 : PIXELFORMAT_RGB8;
}

updateBackbuffer() {

const resolutionChanged = this.canvas.width !== this.backBufferSize.x || this.canvas.height !== this.backBufferSize.y;
if (this._defaultFramebufferChanged || resolutionChanged) {

// if the default framebuffer changes (entering or exiting XR for example)
if (this._defaultFramebufferChanged) {
this.updateBackbufferFormat(this._defaultFramebuffer);
}

this._defaultFramebufferChanged = false;
this.backBufferSize.set(this.canvas.width, this.canvas.height);

Expand Down

0 comments on commit 9b9f783

Please sign in to comment.