GithubHelp home page GithubHelp logo

Comments (6)

davepagurek avatar davepagurek commented on June 14, 2024 1

I believe changing the pixel density will also have similar effects, so I'm updating the title of the issue to include that too.

from p5.js.

aferriss avatar aferriss commented on June 14, 2024

Good catch! @wong-justin do you want to take a look at this?

from p5.js.

wong-justin avatar wong-justin commented on June 14, 2024

Yes I'll have a look. Thanks @davepagurek for catching it

from p5.js.

davepagurek avatar davepagurek commented on June 14, 2024

Currently, we create a new filter shader graphic if one does not yet exist here, matching the main canvas's size and density:

if (!this.filterGraphicsLayer) {
// the real _pInst is buried when this is a secondary p5.Graphics
const pInst =
this._pInst instanceof p5.Graphics ? this._pInst._pInst : this._pInst;
// create secondary layer
this.filterGraphicsLayer =
new p5.Graphics(
this.width,
this.height,
constants.WEBGL,
pInst
);
// geometries/borders on this layer should always be invisible
this.filterGraphicsLayer.noStroke();
}

However, once it has been made, we never check if it needs to be resized. I think to fix this, we can add an else branch to that if, and inside it, check if the width/height and pixel density still match, and if not, call this.filterGraphicsLayer.resizeCanvas(this.width, this.height) and this.filterGraphicsLayer.pixelDensity(this.pixelDensity()).

from p5.js.

Gaurav-1306 avatar Gaurav-1306 commented on June 14, 2024

@davepagurek

if (!this.filterGraphicsLayer) { 
   // the real _pInst is buried when this is a secondary p5.Graphics 
   const pInst = this._pInst instanceof p5.Graphics ? this._pInst._pInst : this._pInst; 
  
   // create secondary layer 
   this.filterGraphicsLayer = new p5.Graphics( 
       this.width, 
       this.height, 
       constants.WEBGL, 
       pInst 
   ); 
   // geometries/borders on this layer should always be invisible 
   this.filterGraphicsLayer.noStroke(); 
} else {
   // Check if dimensions or pixel density need to be resized
   if (
       this.filterGraphicsLayer.width !== this.width ||
       this.filterGraphicsLayer.height !== this.height ||
       this.filterGraphicsLayer.pixelDensity() !== this.pixelDensity()
   ) {
       // Resize the graphics layer
       this.filterGraphicsLayer.resizeCanvas(this.width, this.height);
       this.filterGraphicsLayer.pixelDensity(this.pixelDensity());
   }
}

do you think this looks good. I think we can have the else and if merged into one and using else if. what do you think?

from p5.js.

davepagurek avatar davepagurek commented on June 14, 2024

Thanks, @Gaurav-1306, that looks good!

I think we can have the else and if merged into one and using else if.

Agreed, that works!

from p5.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.