I got this to work... not sure how safe it is though....
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.Executors;
- PGraphics buffer;
- boolean runthread = false;
- ExecutorService executor;
- PGraphicsOpenGL pgl;
- PGL pglx;
- void setup() {
- size(width, height, P3D);
- buffer = createGraphics(width, height, P3D);
- executor = Executors.newFixedThreadPool(1);
- pgl = (PGraphicsOpenGL) g;
- pglx = pgl.beginPGL();
- //pglx.context.setGLDebugSynchronous(true);
- }
- void draw() {
- //do stuff
- stroke(random(0,255),random(0,255),random(0,255));
- line(random(0,width),random(0,height),random(0,width),random(0,height));
- if (!runthread) {
- runthread = true;
- executor.submit(new RunLoadNodes());
- }
- }
- void loadbuffer() {
- println("ya");
- pglx.context.makeCurrent();
- buffer.beginDraw();
- //do stuff
- buffer.endDraw();
- pglx.context.release();
- }
- public class RunLoadNodes implements Runnable {
- public RunLoadNodes() {
- }
- public void run() {
- loadbuffer();
- }
- }