Skip to content

Commit

Permalink
Move resize from APP to DRAW
Browse files Browse the repository at this point in the history
Because resizing blanks the canvas, it's better to do it immediately before we
instruct Pixi render to it.

The old code did resize in APP, which meant that after resizing,
the canvas would flash "black" until the next animation frame.
  • Loading branch information
bhousel committed Jul 31, 2024
1 parent 21cefa9 commit 7f4b982
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions modules/pixi/PixiRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,24 +493,6 @@ export class PixiRenderer extends EventEmitter {
const mapTransform = mapViewport.transform;
const pixiTransform = pixiViewport.transform;

// Resize Pixi canvas if needed
const pixiDims = pixiViewport.dimensions;
const canvasDims = [this.pixi.screen.width, this.pixi.screen.height];
if (!vecEqual(pixiDims, canvasDims)) {
const [w, h] = pixiDims;

// Resize supersurface and overlay to cover the screen dimensions.
const ssnode = this.supersurface.node();
ssnode.style.width = `${w}px`;
ssnode.style.height = `${h}px`;
const onode = this.overlay.node();
onode.style.width = `${w}px`;
onode.style.height = `${h}px`;

// Resize pixi canvas
this.pixi.renderer.resize(w, h);
}

// Determine "offset"
// We try to avoid reprojecting the pixi geometries unless zoom has changed, or map has translated very far.
// If the user is just panning, we can leave the geometries alone and add an offset translation to the origin.
Expand Down Expand Up @@ -556,10 +538,27 @@ export class PixiRenderer extends EventEmitter {

/**
* _draw
* The "Pixi" part of the drawing
* The "Pixi" part of the drawing.
* Where it converts Pixi geometries into WebGL instructions.
*/
_draw() {
// Resize Pixi canvas if needed..
// It will clear the canvas, so do this immediately before we render.
const pixiDims = this.pixiViewport.dimensions;
const canvasDims = [this.pixi.screen.width, this.pixi.screen.height];
if (!vecEqual(pixiDims, canvasDims)) {
const [w, h] = pixiDims;
// Resize supersurface and overlay to cover the screen dimensions.
const ssnode = this.supersurface.node();
ssnode.style.width = `${w}px`;
ssnode.style.height = `${h}px`;
const onode = this.overlay.node();
onode.style.width = `${w}px`;
onode.style.height = `${h}px`;
// Resize pixi canvas
this.pixi.renderer.resize(w, h);
}

// Let's go!
this.pixi.render();

Expand All @@ -580,7 +579,10 @@ export class PixiRenderer extends EventEmitter {
}


/* renders some debug shapes */
/**
* _renderDebug
* Render some debug shapes (usually commented out)
*/
_renderDebug() {
const context = this.context;
const mapViewport = context.viewport;
Expand Down

0 comments on commit 7f4b982

Please sign in to comment.