[Solved] Performance of PGraphics

I have several questions about the PGraphics

  • If I use several (more than two) PGraphics would it make slow my program ?
  • If I call a PGraphics over an another PGraphics would it also make my program slow ? example TestLayer.image(MainLayer,0,0,width,height); where TestLayer and MainLayer both are PGraphics
  • When I use multiple PGraphics it makes the program slow so I had thought of using P3D render while creating & initializing PGraphics object in setup() but when I put P3D render nothing shows up other than white blank screen. (in case of Layered GUI)

Answers

  • edited November 2013 Answer ✓

    General answer:

    • PGraphics is a subclass of PImage. So performance wise they're similar.
    • Canvas background is a PGraphics object itself. And variable g keeps its reference.
    • You can have as many PGraphics you want/need. But in the end you gotta stamp all of them in the main canvas (or inside another PGraphics) using image() like any other PImage, layer by layer. That's where the real bottleneck lies I think!
  • edited November 2013

    Thanks GoToLoop

    And Sorry about the second question. Actually I was asking if I make nested PGraphics would it make my program slow.

    Nested PGraphics: TestLayer.image(MainLayer,0,0,width,height); where TestLayer and MainLayer both are PGraphics

    Here why I was asking the performance because frameRate dropped significantly to 70-80% when I use more than two nested PGraphics. I am afraid if I can overcome this problem.

  • Answer ✓

    Just got some useless lousy tips: ~:>

    • In my experiences w/ PGraphics, I've found out that beginDraw() is only necessary once for each 1 of it.
    • We only need endDraw() just before a PGraphics is gonna be used elsewhere. Mainly for image().
    • If we don't need the drawing capabilities of a PGraphics anymore, it's a good idea to convert it to a simple PImage w/ get() in another variable.
  • thanks GoToLoop :)

Sign In or Register to comment.