Skip to content

Commit

Permalink
fix(pixelRatio): reset pixelRatio on resize
Browse files Browse the repository at this point in the history
  • Loading branch information
Codeboy-cn committed Jan 12, 2025
1 parent 2aa531f commit 1d8d23b
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/gfx/graphics/webGpu/Context3D.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export class Context3D extends CEventDispatcher {
*/
async init(canvasConfig?: CanvasConfig): Promise<boolean> {
this.canvasConfig = canvasConfig;

if (canvasConfig && canvasConfig.canvas) {
this.canvas = canvasConfig.canvas;
if (this.canvas === null) {
Expand Down Expand Up @@ -104,9 +103,6 @@ export class Context3D extends CEventDispatcher {
throw new Error('Your browser does not support WebGPU!');
}

this._pixelRatio = this.canvasConfig?.devicePixelRatio || window.devicePixelRatio || 1;
this._pixelRatio = Math.min(this._pixelRatio, 2.0);

// configure webgpu context
this.device.label = 'device';
this.presentationFormat = navigator.gpu.getPreferredCanvasFormat();
Expand All @@ -131,8 +127,10 @@ export class Context3D extends CEventDispatcher {
}

public updateSize() {
let w = Math.floor(this.canvas.clientWidth * this.pixelRatio);
let h = Math.floor(this.canvas.clientHeight * this.pixelRatio);
this._pixelRatio = this.canvasConfig?.devicePixelRatio || window.devicePixelRatio || 1;
this._pixelRatio = Math.min(this._pixelRatio, 2.0);
let w = Math.floor(this.canvas.clientWidth * this._pixelRatio);
let h = Math.floor(this.canvas.clientHeight * this._pixelRatio);
if (w != this.windowWidth || h != this.windowHeight) {
this.canvas.width = this.windowWidth = w;
this.canvas.height = this.windowHeight = h;
Expand Down

0 comments on commit 1d8d23b

Please sign in to comment.