Skip to content

Commit b11a544

Browse files
committed
more cleaning up
1 parent 3b7380c commit b11a544

File tree

2 files changed

+78
-53
lines changed

2 files changed

+78
-53
lines changed

core/src/processing/opengl/PJOGL.java

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java.nio.ByteBuffer;
1616
import java.nio.FloatBuffer;
1717
import java.nio.IntBuffer;
18-
import java.util.concurrent.CountDownLatch;
18+
//import java.util.concurrent.CountDownLatch;
1919

2020
import javax.media.opengl.GL;
2121
import javax.media.opengl.GL2;
@@ -27,10 +27,10 @@
2727
import javax.media.opengl.GLCapabilitiesImmutable;
2828
import javax.media.opengl.GLContext;
2929
import javax.media.opengl.GLDrawable;
30-
import javax.media.opengl.GLEventListener;
31-
import javax.media.opengl.GLFBODrawable;
30+
//import javax.media.opengl.GLEventListener;
31+
//import javax.media.opengl.GLFBODrawable;
3232
import javax.media.opengl.GLProfile;
33-
import javax.media.opengl.awt.GLCanvas;
33+
//import javax.media.opengl.awt.GLCanvas;
3434
import javax.media.opengl.fixedfunc.GLMatrixFunc;
3535
import javax.media.opengl.glu.GLU;
3636
import javax.media.opengl.glu.GLUtessellator;
@@ -39,9 +39,9 @@
3939
import processing.core.PApplet;
4040
import processing.core.PGraphics;
4141

42-
import com.jogamp.newt.awt.NewtCanvasAWT;
43-
import com.jogamp.newt.opengl.GLWindow;
44-
import com.jogamp.opengl.FBObject;
42+
//import com.jogamp.newt.awt.NewtCanvasAWT;
43+
//import com.jogamp.newt.opengl.GLWindow;
44+
//import com.jogamp.opengl.FBObject;
4545

4646

4747
public class PJOGL extends PGL {
@@ -123,8 +123,8 @@ public class PJOGL extends PGL {
123123
}
124124
*/
125125

126-
protected static boolean USE_FBOLAYER_BY_DEFAULT = false;
127-
protected static boolean USE_JOGL_FBOLAYER = false;
126+
// protected static boolean USE_FBOLAYER_BY_DEFAULT = false;
127+
// protected static boolean USE_JOGL_FBOLAYER = false;
128128

129129
// ........................................................
130130

@@ -147,25 +147,25 @@ public class PJOGL extends PGL {
147147
protected GL2 gl2x;
148148

149149
/** The AWT-OpenGL canvas */
150-
protected GLCanvas canvasAWT;
150+
// protected GLCanvas canvasAWT;
151151

152152
/** The NEWT window */
153-
protected GLWindow windowNEWT;
153+
// protected GLWindow windowNEWT;
154154

155155
/** The NEWT-OpenGL canvas */
156-
protected NewtCanvasAWT canvasNEWT;
156+
// protected NewtCanvasAWT canvasNEWT;
157157

158158
/** The listener that fires the frame rendering in Processing */
159-
protected PGLListener listener;
159+
// protected PGLListener listener;
160160

161161
/** This countdown latch is used to maintain the synchronization between
162162
* Processing's drawing thread and JOGL's rendering thread */
163-
protected CountDownLatch drawLatch = new CountDownLatch(0);
163+
// protected CountDownLatch drawLatch = new CountDownLatch(0);
164164

165165
/** Flag used to do request final display() call to make sure that the
166166
* buffers are properly swapped.
167167
*/
168-
protected boolean prevCanDraw = false;
168+
// protected boolean prevCanDraw = false;
169169

170170
/** Stores exceptions that ocurred during drawing */
171171
protected Exception drawException;
@@ -175,16 +175,16 @@ public class PJOGL extends PGL {
175175
// JOGL's FBO-layer
176176

177177
/** Back (== draw, current frame) buffer */
178-
protected FBObject backFBO;
178+
// protected FBObject backFBO;
179179
/** Sink buffer, used in the multisampled case */
180-
protected FBObject sinkFBO;
180+
// protected FBObject sinkFBO;
181181
/** Front (== read, previous frame) buffer */
182-
protected FBObject frontFBO;
183-
protected FBObject.TextureAttachment backTexAttach;
184-
protected FBObject.TextureAttachment frontTexAttach;
182+
// protected FBObject frontFBO;
183+
// protected FBObject.TextureAttachment backTexAttach;
184+
// protected FBObject.TextureAttachment frontTexAttach;
185185

186-
protected boolean changedFrontTex = false;
187-
protected boolean changedBackTex = false;
186+
// protected boolean changedFrontTex = false;
187+
// protected boolean changedBackTex = false;
188188

189189
// ........................................................
190190

@@ -805,7 +805,7 @@ protected boolean hasShaders() {
805805

806806
// JOGL event listeners
807807

808-
808+
/*
809809
protected void getBuffers(GLWindow glWindow) {
810810
if (false) {
811811
// if (capabilities.isFBO()) {
@@ -865,6 +865,7 @@ protected void getBuffers(GLWindow glWindow) {
865865
866866
}
867867
}
868+
*/
868869

869870
protected void init(GLAutoDrawable glDrawable) {
870871
capabilities = glDrawable.getChosenGLCapabilities();
@@ -874,18 +875,19 @@ protected void init(GLAutoDrawable glDrawable) {
874875
if (!hasShaders()) {
875876
throw new RuntimeException(MISSING_GLSL_ERROR);
876877
}
877-
if (USE_JOGL_FBOLAYER && capabilities.isFBO()) {
878-
int maxs = maxSamples();
879-
numSamples = PApplet.min(capabilities.getNumSamples(), maxs);
880-
}
878+
// if (USE_JOGL_FBOLAYER && capabilities.isFBO()) {
879+
// int maxs = maxSamples();
880+
// numSamples = PApplet.min(capabilities.getNumSamples(), maxs);
881+
// }
881882
}
882883

884+
/*
883885
protected class PGLListener implements GLEventListener {
884886
public PGLListener() {}
885887
886888
@Override
887889
public void display(GLAutoDrawable glDrawable) {
888-
/*
890+
889891
getGL(glDrawable);
890892
891893
if (USE_JOGL_FBOLAYER && capabilities.isFBO()) {
@@ -956,7 +958,6 @@ public void display(GLAutoDrawable glDrawable) {
956958
drawException = ex;
957959
}
958960
drawLatch.countDown();
959-
*/
960961
}
961962
962963
@Override
@@ -1005,6 +1006,7 @@ public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) {
10051006
// }
10061007
// }
10071008
}
1009+
*/
10081010

10091011
/*
10101012
protected void nativeMouseEvent(com.jogamp.newt.event.MouseEvent nativeEvent,

core/src/processing/opengl/PSurfaceNEWT.java

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import java.awt.Canvas;
44
import java.awt.Color;
5+
import java.awt.EventQueue;
56
import java.awt.Frame;
67
import java.awt.Rectangle;
8+
import java.lang.reflect.InvocationTargetException;
79
import java.util.ArrayList;
810

911
import javax.media.nativewindow.ScalableSurface;
@@ -145,6 +147,7 @@ public Frame initFrame(PApplet sketch, Color backgroundColor,
145147
caps.setBackgroundOpaque(true);
146148
caps.setOnscreen(true);
147149
pgl.capabilities = caps;
150+
System.err.println("0. create window");
148151
window = GLWindow.create(screen, caps);
149152

150153

@@ -194,8 +197,6 @@ public Frame initFrame(PApplet sketch, Color backgroundColor,
194197
}
195198
}
196199

197-
window.setVisible(true);
198-
199200
int[] reqSurfacePixelScale;
200201
if (graphics.is2X()) {
201202
// Retina
@@ -220,16 +221,32 @@ public Frame initFrame(PApplet sketch, Color backgroundColor,
220221
DrawListener drawlistener = new DrawListener();
221222
window.addGLEventListener(drawlistener);
222223

224+
System.err.println("0. create animator");
223225
animator = new FPSAnimator(window, 60);
224226

225-
226227
window.addWindowListener(new WindowAdapter() {
227228
@Override
228229
public void windowDestroyNotify(final WindowEvent e) {
229230
animator.stop();
230231
}
231232
});
232233

234+
// window.setVisible(true);
235+
try {
236+
EventQueue.invokeAndWait(new Runnable() {
237+
public void run() {
238+
window.setVisible(true);
239+
System.err.println("1. set visible");
240+
}});
241+
} catch (InvocationTargetException e1) {
242+
// TODO Auto-generated catch block
243+
e1.printStackTrace();
244+
} catch (InterruptedException e1) {
245+
// TODO Auto-generated catch block
246+
e1.printStackTrace();
247+
}
248+
249+
233250
frame = new DummyFrame();
234251
return frame;
235252
}
@@ -238,20 +255,15 @@ class DummyFrame extends Frame {
238255

239256
public DummyFrame() {
240257
super();
241-
// setVisible(false);
242258
}
243259

244260
@Override
245261
public void setResizable(boolean resizable) {
246-
super.setResizable(resizable);
247-
248-
// call NEWT function to make the window resizable
262+
// super.setResizable(resizable);
249263
}
250264

251265
@Override
252266
public void setVisible(boolean visible) {
253-
// don't call super.setVisible()
254-
// make the NEWT window visible/invisible
255267
window.setVisible(visible);
256268
}
257269

@@ -297,6 +309,7 @@ public void setupExternalMessages() {
297309

298310
public void startThread() {
299311
if (animator != null) {
312+
System.err.println("2. start animator");
300313
animator.start();
301314
}
302315
}
@@ -314,17 +327,27 @@ public void resumeThread() {
314327
}
315328

316329
public boolean stopThread() {
317-
return animator.stop();
330+
if (animator != null) {
331+
return animator.stop();
332+
} else {
333+
return false;
334+
}
318335
}
319336

320337
public boolean isStopped() {
321-
return !animator.isAnimating();
338+
if (animator != null) {
339+
return !animator.isAnimating();
340+
} else {
341+
return true;
342+
}
322343
}
323344

324345
public void setSize(int width, int height) {
325-
sketchWidth = sketch.width = width;
326-
sketchHeight = sketch.height = height;
327-
// System.err.println("resize to " + width + ", " + height);
346+
if (frame != null) {
347+
System.err.println("3. set size");
348+
sketchWidth = sketch.width = width;
349+
sketchHeight = sketch.height = height;
350+
}
328351
}
329352

330353
public void setFrameRate(float fps) {
@@ -338,18 +361,20 @@ public void requestFocus() {
338361

339362
public void blit() {
340363
// TODO Auto-generated method stub
341-
342364
}
343365

344-
345-
346-
347-
348366
class DrawListener implements GLEventListener {
349367
public void display(GLAutoDrawable drawable) {
350368
pgl.getGL(drawable);
351-
pgl.getBuffers(window);
352-
sketch.handleDraw();
369+
// pgl.getBuffers(window);
370+
371+
try {
372+
sketch.handleDraw();
373+
} catch (Exception ex) {
374+
// drawException = ex;
375+
}
376+
377+
353378
if (sketch.frameCount == 1) {
354379
requestFocus();
355380
}
@@ -367,9 +392,7 @@ public void init(GLAutoDrawable drawable) {
367392
}
368393
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
369394
pgl.getGL(drawable);
370-
if (animator != null && animator.isStarted()) {
371-
setSize(w, h);
372-
}
395+
setSize(w, h);
373396
}
374397
}
375398

0 commit comments

Comments
 (0)