# Full Screen application performance

**URL:** <https://discourse.processing.org/t/full-screen-application-performance/21760>\
**Category:** Coding Questions\
**Created:** [June 11, 2020, 3:58am UTC](https://discourse.processing.org/t/full-screen-application-performance/21760 "2020-06-11T03:58:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgood7123](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mgood7123](https://discourse.processing.org/u/mgood7123)\
**Post date:** [June 11, 2020, 3:58am UTC](https://discourse.processing.org/t/full-screen-application-performance/21760/1 "2020-06-11T03:58:27Z")

</div>

what would some techiques be for optiming full screen application performance? in particular with a lot of image(PGraphicsObjectInstance) calls

with a 400x400 size and 4 Window objects being rendered i can achieve 60FPS average even when moving a window

however with fullscreen, with zero rendered i get 50 to 60 FPS, with 1 i get 51 FPS, with 4 i get 38 FPS, and this drops to 4 FPS when i move a window

for example

having a single Window

which is 1 graphics object (Window), rendered onto a parent graphics object (WindowObject), rendered onto a parent graphics object (Compositor) and finally rendered onto the surface (PApplet)

via `image(graphics) -> graphics.image(graphics, ...)`

drops my FPS from 60 to 51

and with 4 Windows it drops to 30 FPS

`Compositor.<call>() -> WindowObject[<number>].<call>() -> Window.<call>();`

eg `Compositor.draw() -> { WindowObject[0].draw() -> Window.draw() };`

for example, a typical draw() call looks like this

1. \*.draw

```auto
void draw() {
  compositor.draw();
}

```

1. Compositor.draw

```auto
class Compositor {
  void draw() {
    graphics.beginDraw();
    graphics.background(0);
    for (WindowObject window: windows) {
      window.draw();
      drawGraphics(window);
    }
    graphics.endDraw();
    drawGraphics();
  }

  void drawGraphics() {
    if (displayFPS) {
      graphics.beginDraw();
      int oldColor = graphics.fillColor;
      graphics.fill(255);
      graphics.textSize(16);
      graphics.text("FPS: " + frameRate, 10, 20);
      graphics.fill(oldColor);
      graphics.endDraw();
    }
    image(graphics, 0, 0);
  }

  void drawGraphics(WindowObject window) {
    graphics.image(
      window.graphics,
      window.x,
      window.y,
      window.previewWidth,
      window.previewHeight
    );
  }
}

```

1. WindowObject.draw

```auto
class WindowObject {
  void draw() {
    correctMouseLocation();
    window.draw();
    drawWindow();
  }
  void drawGraphics() {
    if (displayFPS) {
      window.graphics.beginDraw();
      int oldColor = window.graphics.fillColor;
      window.graphics.fill(255);
      window.graphics.textSize(16);
      window.graphics.text("FPS: " + frameRate, 10, 20);
      window.graphics.fill(oldColor);
      window.graphics.endDraw();
    }
    graphics.beginDraw();
    graphics.image(
      window.graphics,
      window.x,
      window.y,
      window.width,
      window.height
    );
    graphics.endDraw();
  }
  
  void drawWindow() {
    clearScreen();
    if (focus) {
      if (clickedOnBorder && locked) drawBordersLocked();
      else drawBordersHighlighted();
    } else {
      drawBorders();
    }
    drawGraphics();
  }
}

```

1. Window.draw

```auto
class Window {
  public PGraphics graphics = null;
  
  int height;
  int width;
  int x, y;
  int mouseX, mouseY;
  Window() {} // implicit super constructor required
  void onBeforeResize() {}
  String onRequestType() { return P3D; }
  void onAfterResize() {}
  void setup() {
    graphics.beginDraw();
    graphics.background(0);
    graphics.endDraw();
  }
  void draw() {
    graphics.beginDraw();
    graphics.background(0);
    graphics.endDraw();
  }
  void mousePressed() {}
  void mouseDragged() {}
  void mouseReleased() {}
  void mouseMoved() {}
}

```

1. {\* extends Window}.draw

```auto
class Applications_Cube extends Window {
  
  @Override
  void draw() {
    graphics.beginDraw();
    graphics.lights();
    graphics.background(0);
    graphics.noStroke();
    graphics.translate(width/2, height/2);
    graphics.rotateX(frameCount/100.0);
    graphics.rotateY(frameCount/200.0);
    graphics.box(40);
    graphics.endDraw();
  }
}

```

FILES/CODE:

```auto
Compositor compositor;

void settings() {
  fullScreen(P3D);
  //size(400, 400, P3D);
}

void addApplications() {
  compositor.add(new Applications_DraggableExample(), 200, 200);
  compositor.setLocation(0, 0);
  compositor.add(new Applications_Cube(), 200, 200);
  compositor.setLocation(0, 200);
  compositor.add(new Applications_XCursor_Decoder_Example(), 200, 200);
  compositor.setLocation(200, 0);
  compositor.add(new Applications_Cube(), 200, 200);
  compositor.setLocation(200, 200);
}

void setup() {
  compositor = new Compositor(width, height);
  compositor.displayFPS = true;
  compositor.displayWindowFPS = true;
  compositor.debug = false;
  addApplications();
  compositor.setup();
}

void draw() {
  compositor.draw(); //<>// //<>//
}

void mousePressed() {
  compositor.mousePressed();
}

void mouseDragged() {
  compositor.mouseDragged();
}

void mouseReleased() {
  compositor.mouseReleased();
}

void mouseMoved() {
  compositor.mouseMoved();
}

```

> <https://github.com/mgood7123/Processing3Compositor/blob/master/Compositor.pde>

> <https://github.com/mgood7123/Processing3Compositor/blob/master/WindowObject.pde>

---

<div class="post-metadata">

**Author:** ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)\
**Post date:** [June 11, 2020, 8:17am UTC](https://discourse.processing.org/t/full-screen-application-performance/21760/2 "2020-06-11T08:17:52Z")

</div>

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f6d20530bde43748723539fb977240fea746e20d.png)

Runs alright for me (1920x1080). Is your PC just terrible?

I once did a similar thing (running multiple sketches within one sketch) and got hammered by the _resize()_ function, since each sketch would first draw into a buffer the size of the Processing window and then be resized to the size of it’s internal window. If you’re not resizing (rather, your buffer is the size of the window), then it’s hard to think of any possible performance improvements.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/65248b9db59b22e7b536609beeda2998f690cfa2.png)

---

<div class="post-metadata">

**Author:** ![mgood7123](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mgood7123](https://discourse.processing.org/u/mgood7123)\
**Post date:** [June 11, 2020, 8:28am UTC](https://discourse.processing.org/t/full-screen-application-performance/21760/4 "2020-06-11T08:28:37Z")

</div>

`I once did a similar thing (running multiple sketches within one sketch) and got hammered by the resize() function, since each sketch would first draw into a buffer the size of the Processing window and then be resized to the size of it’s internal window.`

damn, mine just draws directly into a PGraphics and recreates it with the specified window dimensions upon resize, with a preview scaling displayed during the resize operation, saves alot of cpu as opposed to just drawing the full texture then downscaling it

```auto
  void mouseReleased() {
    if (clickedOnResizeBorder) {
      if (mouseDragType != MOUSE_CLICKED_NOTHING) {
        if (
          clickedResizeType == MOUSE_CLICKED_RESIZE_LEFT ||
          clickedResizeType == MOUSE_CLICKED_RESIZE_RIGHT
        ) {
          windowResize(previewWidth, height);
        } else if (
          clickedResizeType == MOUSE_CLICKED_RESIZE_TOP ||
          clickedResizeType == MOUSE_CLICKED_RESIZE_BOTTOM
        ) {
          windowResize(width, previewHeight);
        } else if (
          clickedResizeType == MOUSE_CLICKED_RESIZE_TOP_LEFT ||
          clickedResizeType == MOUSE_CLICKED_RESIZE_TOP_RIGHT ||
          clickedResizeType == MOUSE_CLICKED_RESIZE_BOTTOM_LEFT ||
          clickedResizeType == MOUSE_CLICKED_RESIZE_BOTTOM_RIGHT
        ) {
          windowResize(previewWidth, previewHeight);
        }
        resizeWindow();
        graphics = createGraphics(width, height, P3D);
      }
      clickedOnResizeBorder = false;
      resizing = false;
      resizingLeft = false;
      resizingTop = false;
      resizingRight = false;
      resizingBottom = false;
      resizingTopLeft = false;
      resizingTopRight = false;
      resizingBottomLeft = false;
      resizingBottomRight = false;
      clickedResizeType = MOUSE_CLICKED_NOTHING;
    } else if (clickedOnBorder) {
      ct.loadCursor("cursors/aerodrop/4498f0e0c1937ffe01fd06f973665830");
      clickedOnBorder = false;
      locked = false;
    } else if (clickedOnApp) {
      clickedOnApp = false;
      correctMouseLocation();
      window.mouseReleased();
    }
    drawWindow();
  }

```

---

<div class="post-metadata">

**Author:** ![mgood7123](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mgood7123](https://discourse.processing.org/u/mgood7123)\
**Post date:** [June 11, 2020, 8:37am UTC](https://discourse.processing.org/t/full-screen-application-performance/21760/5 "2020-06-11T08:37:46Z")

</div>

im using a Macbook Pro mid-2012 (MacBookPro92)

0 windows, 60 FPS

 ![Screenshot_20200611_184451](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/94a9bd08d4c5c01d56c3ed1575e1c9e15bc0dce3.png)

1 window - 52 FPS

 ![Screenshot_20200611_184429](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8b0e981b03f4cd977bfc81a81b87dcf60d7250c8.png)

2 windows - 40 FPS

 ![Screenshot_20200611_184349](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e6e37c59d96a1909f1ba3f7d319494593657e371.png)

3 windows - 33 FPS

 ![Screenshot_20200611_184317](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/4ca13cc446fddf7d6121a5a066476134ddf77a89.png)

4 windows - 28 FPS

 ![Screenshot_20200611_184057](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/6cee8ca4da751efbe928d05141707c8ce59f0b7f.png)

16 windows - 11 fps

 ![Screenshot_20200611_190231](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/c/cadd373bc0b5733fd14fc6de125959e581241896.png)

---

<div class="post-metadata">

**Author:** ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)\
**Post date:** [June 11, 2020, 10:52am UTC](https://discourse.processing.org/t/full-screen-application-performance/21760/6 "2020-06-11T10:52:29Z")

</div>

> im using a Macbook Pro mid-2012 (MacBookPro92)  
> No wonder…🤣
> 
> ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0d34c5545243568da1a257fa27571a1c1423ff1f.png)

---

<div class="post-metadata">

**Author:** ![mgood7123](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mgood7123](https://discourse.processing.org/u/mgood7123)\
**Post date:** [June 11, 2020, 11:06am UTC](https://discourse.processing.org/t/full-screen-application-performance/21760/7 "2020-06-11T11:06:08Z")

</div>

whats so bad about that?

---

<div class="post-metadata">

**Author:** ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)\
**Post date:** [June 11, 2020, 11:39am UTC](https://discourse.processing.org/t/full-screen-application-performance/21760/8 "2020-06-11T11:39:19Z")

</div>

> [@micycle](#):
>
> MacBookPro92

It’s an 8-year-old laptop processor. Of course it sucks.

---

<div class="post-metadata">

**Author:** ![mgood7123](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@mgood7123](https://discourse.processing.org/u/mgood7123)\
**Post date:** [June 11, 2020, 11:42am UTC](https://discourse.processing.org/t/full-screen-application-performance/21760/9 "2020-06-11T11:42:03Z")

</div>

oof, how can i optimize for low-end/mid-end (can play gta 5 at 11 fps in fullscreen lol) GPU/CPU’s lmao (intel i5 CPU)

---

<div class="post-metadata">

**Author:** ![Brastin](https://avatars.discourse-cdn.com/v4/letter/b/c5a1d2/32.png) [@Brastin](https://discourse.processing.org/u/Brastin)\
**Post date:** [September 6, 2020, 10:28pm UTC](https://discourse.processing.org/t/full-screen-application-performance/21760/10 "2020-09-06T22:28:32Z")

</div>

Hey, this is probably a little late but I’m also trying to do the exact same thing right now. I’ve been making a windowed environment and something that’s been killing me for ages is that I can’t figure out how to mask out the window contents but still have a sketch that can run in real time. So far I’ve been using PGraphics objects like you, but using some altered drawing functions that take into account how much the PGraphics object is being scaled so I don’t have to call resize() as much.
