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
- *.draw
void draw() {
compositor.draw();
}
- Compositor.draw
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
);
}
}
- WindowObject.draw
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();
}
}
- Window.draw
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() {}
}
- {* extends Window}.draw
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:
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();
}