From e85237a62662bfd8099163fbdf61edfb35299ce0 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Sat, 15 Nov 2014 23:04:32 -0700 Subject: [PATCH] cleaning up PGL --- core/src/processing/opengl/PGL.java | 59 +++++++++---------- .../processing/opengl/PGraphicsOpenGL.java | 24 ++++---- core/src/processing/opengl/PJOGL.java | 59 ++++++++++++------- core/src/processing/opengl/PSurfaceNEWT.java | 16 +++-- 4 files changed, 92 insertions(+), 66 deletions(-) diff --git a/core/src/processing/opengl/PGL.java b/core/src/processing/opengl/PGL.java index 4e87f1508..d897f6947 100644 --- a/core/src/processing/opengl/PGL.java +++ b/core/src/processing/opengl/PGL.java @@ -351,23 +351,20 @@ public abstract class PGL { } - /** - * Return the native canvas the OpenGL context associated to this PGL object - * is rendering to (if any). - */ - public abstract Object getCanvas(); - - protected abstract void setFps(float fps); - - - protected abstract void initSurface(int antialias); - - - protected abstract void reinitSurface(); - - - protected abstract void registerListeners(); +// public abstract Object getCanvas(); +// +// +// protected abstract void setFps(float fps); +// +// +// protected abstract void initSurface(int antialias); +// +// +// protected abstract void reinitSurface(); +// +// +// protected abstract void registerListeners(); protected void deleteSurface() { @@ -569,7 +566,7 @@ public abstract class PGL { // The result of this assignment is the following: if the user requested // at some point the use of the FBO layer, but subsequently didn't // request it again, then the rendering won't render to the FBO layer if - // not needed by the condif, since it is slower than simple onscreen + // not needed by the config, since it is slower than simple onscreen // rendering. fboLayerRequested = false; } @@ -602,18 +599,18 @@ public abstract class PGL { protected abstract void getGL(PGL pgl); - - - protected abstract boolean canDraw(); - - - protected abstract void requestFocus(); - - - protected abstract void requestDraw(); - - - protected abstract void swapBuffers(); +// +// +// protected abstract boolean canDraw(); +// +// +// protected abstract void requestFocus(); +// +// +// protected abstract void requestDraw(); +// +// +// protected abstract void swapBuffers(); protected boolean threadIsCurrent() { @@ -630,10 +627,10 @@ public abstract class PGL { private boolean needFBOLayer(boolean clear0) { // TODO: need to revise this, on windows we might not want to use FBO layer // even with anti-aliasing enabled... - boolean res = !clear0 || fboLayerRequested || 1 < numSamples; +// boolean res = !clear0 || fboLayerRequested || 1 < numSamples; // System.err.println(res + " " + clear0 + " " + fboLayerRequested + " " + numSamples); // return res; - return false; + return fboLayerRequested; } diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 3034fd6ef..7058fbffc 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -632,7 +632,7 @@ public class PGraphicsOpenGL extends PGraphics { // render only 1 frame, so no enough rendering // iterations have been conducted so far to properly // initialize all the buffers. - pgl.swapBuffers(); +// pgl.swapBuffers(); } finalizePolyBuffers(); @@ -1649,10 +1649,10 @@ public class PGraphicsOpenGL extends PGraphics { * OpenGL cannot draw until a proper native peer is available, so this * returns the value of PApplet.isDisplayable() (inherited from Component). */ - @Override - public boolean canDraw() { - return pgl.canDraw(); - } +// @Override +// public boolean canDraw() { +// return pgl.canDraw(); +// } // @Override @@ -1671,10 +1671,14 @@ public class PGraphicsOpenGL extends PGraphics { @Override public void beginDraw() { if (primarySurface) { - if (initialized) { - if (sized) pgl.reinitSurface(); - if (parent.canDraw()) pgl.requestDraw(); - } else { +// if (initialized) { +// if (sized) pgl.reinitSurface(); +// if (parent.canDraw()) pgl.requestDraw(); +// } else { + initPrimary(); +// } + + if (!initialized) { initPrimary(); } @@ -6351,7 +6355,7 @@ public class PGraphicsOpenGL extends PGraphics { protected void initPrimary() { - pgl.initSurface(quality); +// pgl.initSurface(quality); if (texture != null) { removeCache(this); texture = ptexture = null; diff --git a/core/src/processing/opengl/PJOGL.java b/core/src/processing/opengl/PJOGL.java index dd8c709e1..4be0872b3 100644 --- a/core/src/processing/opengl/PJOGL.java +++ b/core/src/processing/opengl/PJOGL.java @@ -221,6 +221,7 @@ public class PJOGL extends PGL { } + /* @Override public Canvas getCanvas() { return canvas; @@ -242,11 +243,12 @@ public class PJOGL extends PGL { setFps = true; } } +*/ - + /* @Override protected void initSurface(int antialias) { - /* + if (profile == null) { if (PROFILE == 2) { try { @@ -377,15 +379,16 @@ public class PJOGL extends PGL { pg.parent.defaultSize = false; registerListeners(); - */ + fboLayerCreated = false; fboLayerInUse = false; firstFrame = true; setFps = false; } + */ - +/* @Override protected void reinitSurface() { sinkFBO = backFBO = frontFBO = null; @@ -394,10 +397,10 @@ public class PJOGL extends PGL { firstFrame = true; pg.parent.defaultSize = false; } +*/ - - @Override - protected void registerListeners() { +// @Override +// protected void registerListeners() { // if (WINDOW_TOOLKIT == AWT) { // pg.parent.addListeners(canvasAWT); // @@ -422,11 +425,11 @@ public class PJOGL extends PGL { // if (canvas != null) { // canvas.setFocusTraversalKeysEnabled(false); // } - } +// } - @Override - protected void deleteSurface() { +// @Override +// protected void deleteSurface() { // super.deleteSurface(); // // if (canvasAWT != null) { @@ -435,9 +438,9 @@ public class PJOGL extends PGL { // } else if (canvasNEWT != null) { // windowNEWT.removeGLEventListener(listener); // } - } - +// } +/* @Override protected int getReadFramebuffer() { if (fboLayerInUse) { @@ -637,7 +640,7 @@ public class PJOGL extends PGL { } } } - +*/ @Override protected void getGL(PGL pgl) { @@ -675,6 +678,8 @@ public class PJOGL extends PGL { } + + /* @Override protected boolean canDraw() { return true; @@ -689,7 +694,7 @@ public class PJOGL extends PGL { @Override protected void requestDraw() { - /* + drawException = null; boolean canDraw = pg.parent.canDraw(); if (pg.initialized && (canDraw || prevCanDraw)) { @@ -718,18 +723,18 @@ public class PJOGL extends PGL { throw new RuntimeException(drawException); } } - */ } @Override protected void swapBuffers() { -// if (WINDOW_TOOLKIT == AWT) { -// canvasAWT.swapBuffers(); -// } else if (WINDOW_TOOLKIT == NEWT) { -// windowNEWT.swapBuffers(); -// } + if (WINDOW_TOOLKIT == AWT) { + canvasAWT.swapBuffers(); + } else if (WINDOW_TOOLKIT == NEWT) { + windowNEWT.swapBuffers(); + } } + */ @Override @@ -861,6 +866,20 @@ public class PJOGL extends PGL { } } + protected void init(GLAutoDrawable glDrawable) { + capabilities = glDrawable.getChosenGLCapabilities(); + if (!hasFBOs()) { + throw new RuntimeException(MISSING_FBO_ERROR); + } + if (!hasShaders()) { + throw new RuntimeException(MISSING_GLSL_ERROR); + } + if (USE_JOGL_FBOLAYER && capabilities.isFBO()) { + int maxs = maxSamples(); + numSamples = PApplet.min(capabilities.getNumSamples(), maxs); + } + } + protected class PGLListener implements GLEventListener { public PGLListener() {} diff --git a/core/src/processing/opengl/PSurfaceNEWT.java b/core/src/processing/opengl/PSurfaceNEWT.java index dda855d04..ca677ac0e 100644 --- a/core/src/processing/opengl/PSurfaceNEWT.java +++ b/core/src/processing/opengl/PSurfaceNEWT.java @@ -128,7 +128,7 @@ public class PSurfaceNEWT implements PSurface { caps.setStencilBits(PGL.REQUESTED_STENCIL_BITS); caps.setPBuffer(false); - caps.setFBO(true); + caps.setFBO(false); caps.setSampleBuffers(true); caps.setNumSamples(2); @@ -286,15 +286,21 @@ public class PSurfaceNEWT implements PSurface { } public void startThread() { - animator.start(); + if (animator != null) { + animator.start(); + } } public void pauseThread() { - animator.pause(); + if (animator != null) { + animator.pause(); + } } public void resumeThread() { - animator.resume(); + if (animator != null) { + animator.resume(); + } } public boolean stopThread() { @@ -351,7 +357,7 @@ public class PSurfaceNEWT implements PSurface { } public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) { pgl.getGL(drawable); - if (animator.isStarted()) { + if (animator != null && animator.isStarted()) { setSize(w, h); } }