Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webgl): Prevent auto resizing when using external gl context (9.0-release) #2296

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is autoResize possibly overridden by the user in device props?

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
Loading