Skip to content

Commit

Permalink
fix(webgl): Prevent auto resizing when using external gl context (#2296)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress authored Dec 9, 2024
1 parent 7e55b4b commit 1be3014
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion modules/core/src/adapter/canvas-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ export abstract class CanvasContext {
// For headless gl we might have used custom width and height
// hence use cached clientWidth
const [drawingBufferWidth] = this.getDrawingBufferSize();
const {clientWidth} = this._canvasSizeInfo;
// _canvasSizeInfo may not be populated if `setDevicePixelRatio` is never called
const clientWidth = this._canvasSizeInfo.clientWidth || this.htmlCanvas?.clientWidth;
return clientWidth ? drawingBufferWidth / clientWidth : 1;
} catch {
return 1;
Expand Down
7 changes: 5 additions & 2 deletions modules/webgl/src/adapter/webgl-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex

// Create and instrument context
const canvas = props.gl?.canvas || props.canvas;
this.canvasContext = new WebGLCanvasContext(this, {...props, canvas});
const autoResize = !props.gl;
this.canvasContext = new WebGLCanvasContext(this, {...props, autoResize, canvas});

this.lost = new Promise<{reason: 'destroyed'; message: string}>(resolve => {
this._resolveContextLost = resolve;
Expand Down Expand Up @@ -241,7 +242,9 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
this.features.initializeFeatures();
}

this.canvasContext.resize();
if (autoResize) {
this.canvasContext.resize();
}

// Install context state tracking
// @ts-expect-error - hidden parameters
Expand Down

0 comments on commit 1be3014

Please sign in to comment.