Check which renderer is active?

Was checking out the source code on GitHub and found many mentions to ‘this.renderer’ for internal use to see which renderer is in use (P2D, P3D) – just wondering if we’re able to access this variable? Was interested to alternate some code in a library based on P3D being in use or not.

Tried:

this.renderer
PApplet.renderer

Both report that it’s not visible…

1 Like
// https://Discourse.Processing.org/t/check-which-renderer-is-active/6452/2
// GoToLoop (2018/Dec/09)

void setup() {
  size(800, 600, P2D); // JAVA2D, FX2D, P2D, P3D
  final String render = discoverRenderer(this);
  println(render);
  exit();
}

static final String discoverRenderer(final PApplet p) {
  final Object window = p.getSurface().getNative();
  final PGraphics pg  = p.getGraphics();

  if (window instanceof javafx.scene.canvas.Canvas) return FX2D;
  else if (pg.isGL()) return pg.is3D()? P3D : P2D;
  return JAVA2D;
}
5 Likes