Skip to content

Comments

fix(core): apply drawing buffer resize immediately for WebGL#2504

Draft
nokonoko1203 wants to merge 1 commit intovisgl:masterfrom
nokonoko1203:fix/canvas-resize-webgl
Draft

fix(core): apply drawing buffer resize immediately for WebGL#2504
nokonoko1203 wants to merge 1 commit intovisgl:masterfrom
nokonoko1203:fix/canvas-resize-webgl

Conversation

@nokonoko1203
Copy link

Background

Commit 939287e ("Fix flicker when resizing CanvasContext") deferred the actual canvas resize from setDrawingBufferSize() to getCurrentFramebuffer() to avoid flicker caused by clearing the drawing buffer on resize.

However, on WebGL this deferred resize never fires. When beginRenderPass({framebuffer: null}) is called, the two backends behave differently.

WebGPU (webgpu-render-pass.ts) — calls getCurrentFramebuffer():

const framebuffer = (props.framebuffer as WebGPUFramebuffer) || device.getCanvasContext().getCurrentFramebuffer();

WebGL (webgl-render-pass.ts) — only calls getDrawingBufferSize():

const [width, height] = device.getDefaultCanvasContext().getDrawingBufferSize();
viewport = [0, 0, width, height];

As a result, on WebGL canvas.width/canvas.height are never updated from their initial values, while drawingBufferWidth/drawingBufferHeight are correctly set by ResizeObserver. The viewport is set to the intended size but the actual drawing buffer remains at the initial canvas size, causing a resolution mismatch.

Change List

  • Call _resizeDrawingBufferIfNeeded() immediately after setting _needsDrawingBufferResize = true in setDrawingBufferSize()
  • The deferred path in getCurrentFramebuffer() becomes a harmless no-op (flag is already cleared)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant