Skip to content

Commit 0d3c09b

Browse files
committed
Merge pull request #1 from codeanticode/master
updating opengl for the new renderer arch
2 parents 8928caf + a4e2465 commit 0d3c09b

File tree

4 files changed

+659
-64
lines changed

4 files changed

+659
-64
lines changed

core/src/processing/opengl/PGL.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,8 @@ protected void endGL() { }
630630
private boolean needFBOLayer(boolean clear0) {
631631
// TODO: need to revise this, on windows we might not want to use FBO layer
632632
// even with anti-aliasing enabled...
633-
return !clear0 || fboLayerRequested || 1 < numSamples;
633+
// return !clear0 || fboLayerRequested || 1 < numSamples;
634+
return false;
634635
}
635636

636637

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,10 @@ public void setPrimary(boolean primary) {
560560
//public void setAntiAlias(int samples) // PGraphics
561561

562562

563-
@Override
564-
public void setFrameRate(float frameRate) {
565-
pgl.setFps(frameRate);
566-
}
563+
// @Override
564+
// public void setFrameRate(float frameRate) {
565+
// pgl.setFps(frameRate);
566+
// }
567567

568568

569569
@Override
@@ -686,6 +686,12 @@ protected void setFlushMode(int mode) {
686686
}
687687

688688

689+
@Override
690+
public PSurface createSurface() { // ignore
691+
return new PSurfaceNEWT(this);
692+
}
693+
694+
689695
//////////////////////////////////////////////////////////////
690696

691697
// IMAGE METADATA FOR THIS RENDERER
@@ -1633,10 +1639,10 @@ protected void finalizePointBuffers() {
16331639
}
16341640

16351641

1636-
@Override
1637-
public void requestFocus() { // ignore
1638-
pgl.requestFocus();
1639-
}
1642+
// @Override
1643+
// public void requestFocus() {
1644+
// pgl.requestFocus();
1645+
// }
16401646

16411647

16421648
/**
@@ -1649,22 +1655,29 @@ public boolean canDraw() {
16491655
}
16501656

16511657

1658+
// @Override
1659+
// public void requestDraw() {
1660+
// if (primarySurface) {
1661+
// if (initialized) {
1662+
// if (sized) pgl.reinitSurface();
1663+
// if (parent.canDraw()) pgl.requestDraw();
1664+
// } else {
1665+
// initPrimary();
1666+
// }
1667+
// }
1668+
// }
1669+
1670+
16521671
@Override
1653-
public void requestDraw() {
1672+
public void beginDraw() {
16541673
if (primarySurface) {
16551674
if (initialized) {
16561675
if (sized) pgl.reinitSurface();
16571676
if (parent.canDraw()) pgl.requestDraw();
16581677
} else {
16591678
initPrimary();
16601679
}
1661-
}
1662-
}
1663-
16641680

1665-
@Override
1666-
public void beginDraw() {
1667-
if (primarySurface) {
16681681
setCurrentPG(this);
16691682
} else {
16701683
pgl.getGL(getPrimaryPGL());

core/src/processing/opengl/PJOGL.java

Lines changed: 122 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public class PJOGL extends PGL {
9898

9999
// OS-specific configuration
100100

101+
/*
101102
protected static int WINDOW_TOOLKIT;
102103
protected static int EVENTS_TOOLKIT;
103104
protected static boolean USE_JOGL_FBOLAYER;
@@ -131,6 +132,10 @@ public class PJOGL extends PGL {
131132
USE_JOGL_FBOLAYER = false;
132133
}
133134
}
135+
*/
136+
137+
protected static boolean USE_FBOLAYER_BY_DEFAULT = false;
138+
protected static boolean USE_JOGL_FBOLAYER = false;
134139

135140
// ........................................................
136141

@@ -252,6 +257,7 @@ protected void setFps(float fps) {
252257

253258
@Override
254259
protected void initSurface(int antialias) {
260+
/*
255261
if (profile == null) {
256262
if (PROFILE == 2) {
257263
try {
@@ -382,6 +388,7 @@ protected void initSurface(int antialias) {
382388
383389
pg.parent.defaultSize = false;
384390
registerListeners();
391+
*/
385392

386393
fboLayerCreated = false;
387394
fboLayerInUse = false;
@@ -402,43 +409,43 @@ protected void reinitSurface() {
402409

403410
@Override
404411
protected void registerListeners() {
405-
if (WINDOW_TOOLKIT == AWT) {
406-
pg.parent.addListeners(canvasAWT);
407-
408-
listener = new PGLListener();
409-
canvasAWT.addGLEventListener(listener);
410-
} else if (WINDOW_TOOLKIT == NEWT) {
411-
if (EVENTS_TOOLKIT == NEWT) {
412-
NEWTMouseListener mouseListener = new NEWTMouseListener();
413-
windowNEWT.addMouseListener(mouseListener);
414-
NEWTKeyListener keyListener = new NEWTKeyListener();
415-
windowNEWT.addKeyListener(keyListener);
416-
NEWTWindowListener winListener = new NEWTWindowListener();
417-
windowNEWT.addWindowListener(winListener);
418-
} else if (EVENTS_TOOLKIT == AWT) {
419-
pg.parent.addListeners(canvasNEWT);
420-
}
421-
422-
listener = new PGLListener();
423-
windowNEWT.addGLEventListener(listener);
424-
}
425-
426-
if (canvas != null) {
427-
canvas.setFocusTraversalKeysEnabled(false);
428-
}
412+
// if (WINDOW_TOOLKIT == AWT) {
413+
// pg.parent.addListeners(canvasAWT);
414+
//
415+
// listener = new PGLListener();
416+
// canvasAWT.addGLEventListener(listener);
417+
// } else if (WINDOW_TOOLKIT == NEWT) {
418+
// if (EVENTS_TOOLKIT == NEWT) {
419+
// NEWTMouseListener mouseListener = new NEWTMouseListener();
420+
// windowNEWT.addMouseListener(mouseListener);
421+
// NEWTKeyListener keyListener = new NEWTKeyListener();
422+
// windowNEWT.addKeyListener(keyListener);
423+
// NEWTWindowListener winListener = new NEWTWindowListener();
424+
// windowNEWT.addWindowListener(winListener);
425+
// } else if (EVENTS_TOOLKIT == AWT) {
426+
// pg.parent.addListeners(canvasNEWT);
427+
// }
428+
//
429+
// listener = new PGLListener();
430+
// windowNEWT.addGLEventListener(listener);
431+
// }
432+
//
433+
// if (canvas != null) {
434+
// canvas.setFocusTraversalKeysEnabled(false);
435+
// }
429436
}
430437

431438

432439
@Override
433440
protected void deleteSurface() {
434-
super.deleteSurface();
435-
436-
if (canvasAWT != null) {
437-
canvasAWT.removeGLEventListener(listener);
438-
pg.parent.removeListeners(canvasAWT);
439-
} else if (canvasNEWT != null) {
440-
windowNEWT.removeGLEventListener(listener);
441-
}
441+
// super.deleteSurface();
442+
//
443+
// if (canvasAWT != null) {
444+
// canvasAWT.removeGLEventListener(listener);
445+
// pg.parent.removeListeners(canvasAWT);
446+
// } else if (canvasNEWT != null) {
447+
// windowNEWT.removeGLEventListener(listener);
448+
// }
442449
}
443450

444451

@@ -681,7 +688,9 @@ protected void getGL(GLAutoDrawable glDrawable) {
681688

682689
@Override
683690
protected boolean canDraw() {
684-
return pg.initialized && pg.parent.isDisplayable();
691+
return true;
692+
// return pg.initialized;
693+
// && pg.parent.isDisplayable();
685694
}
686695

687696

@@ -691,6 +700,7 @@ protected void requestFocus() { }
691700

692701
@Override
693702
protected void requestDraw() {
703+
/*
694704
drawException = null;
695705
boolean canDraw = pg.parent.canDraw();
696706
if (pg.initialized && (canDraw || prevCanDraw)) {
@@ -719,16 +729,17 @@ protected void requestDraw() {
719729
throw new RuntimeException(drawException);
720730
}
721731
}
732+
*/
722733
}
723734

724735

725736
@Override
726737
protected void swapBuffers() {
727-
if (WINDOW_TOOLKIT == AWT) {
728-
canvasAWT.swapBuffers();
729-
} else if (WINDOW_TOOLKIT == NEWT) {
730-
windowNEWT.swapBuffers();
731-
}
738+
// if (WINDOW_TOOLKIT == AWT) {
739+
// canvasAWT.swapBuffers();
740+
// } else if (WINDOW_TOOLKIT == NEWT) {
741+
// windowNEWT.swapBuffers();
742+
// }
732743
}
733744

734745

@@ -801,11 +812,70 @@ protected boolean hasShaders() {
801812
// JOGL event listeners
802813

803814

815+
protected void getBuffers(GLWindow glWindow) {
816+
if (USE_JOGL_FBOLAYER && capabilities.isFBO()) {
817+
// The onscreen drawing surface is backed by an FBO layer.
818+
GLFBODrawable fboDrawable = null;
819+
fboDrawable = (GLFBODrawable)glWindow.getDelegatedDrawable();
820+
821+
if (fboDrawable != null) {
822+
backFBO = fboDrawable.getFBObject(GL.GL_BACK);
823+
if (1 < numSamples) {
824+
if (needSepFrontTex) {
825+
// When using multisampled FBO, the back buffer is the MSAA
826+
// surface so it cannot be read from. The sink buffer contains
827+
// the readable 2D texture.
828+
// In this case, we create an auxiliary "front" buffer that it is
829+
// swapped with the sink buffer at the beginning of each frame.
830+
// In this way, we always have a readable copy of the previous
831+
// frame in the front texture, while the back is synchronized
832+
// with the contents of the MSAA back buffer when requested.
833+
if (frontFBO == null) {
834+
// init
835+
frontFBO = new FBObject();
836+
frontFBO.reset(gl, pg.width, pg.height, numSamples);
837+
frontFBO.attachTexture2D(gl, 0, true);
838+
sinkFBO = backFBO.getSamplingSinkFBO();
839+
changedFrontTex = changedBackTex = true;
840+
} else {
841+
// swap
842+
FBObject temp = sinkFBO;
843+
sinkFBO = frontFBO;
844+
frontFBO = temp;
845+
backFBO.setSamplingSink(sinkFBO);
846+
changedFrontTex = changedBackTex = false;
847+
}
848+
backTexAttach = (FBObject.TextureAttachment) sinkFBO.
849+
getColorbuffer(0);
850+
frontTexAttach = (FBObject.TextureAttachment)frontFBO.
851+
getColorbuffer(0);
852+
} else {
853+
changedFrontTex = changedBackTex = sinkFBO == null;
854+
855+
// Default setting (to save resources): the front and back
856+
// textures are the same.
857+
sinkFBO = backFBO.getSamplingSinkFBO();
858+
backTexAttach = (FBObject.TextureAttachment) sinkFBO.
859+
getColorbuffer(0);
860+
frontTexAttach = backTexAttach;
861+
}
862+
} else {
863+
// w/out multisampling, rendering is done on the back buffer.
864+
frontFBO = fboDrawable.getFBObject(GL.GL_FRONT);
865+
backTexAttach = (FBObject.TextureAttachment) backFBO.getColorbuffer(0);
866+
frontTexAttach = (FBObject.TextureAttachment) frontFBO.getColorbuffer(0);
867+
}
868+
}
869+
870+
}
871+
}
872+
804873
protected class PGLListener implements GLEventListener {
805874
public PGLListener() {}
806875

807876
@Override
808877
public void display(GLAutoDrawable glDrawable) {
878+
/*
809879
getGL(glDrawable);
810880
811881
if (USE_JOGL_FBOLAYER && capabilities.isFBO()) {
@@ -876,6 +946,7 @@ public void display(GLAutoDrawable glDrawable) {
876946
drawException = ex;
877947
}
878948
drawLatch.countDown();
949+
*/
879950
}
880951

881952
@Override
@@ -925,6 +996,7 @@ public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) {
925996
// }
926997
}
927998

999+
/*
9281000
protected void nativeMouseEvent(com.jogamp.newt.event.MouseEvent nativeEvent,
9291001
int peAction) {
9301002
int modifiers = nativeEvent.getModifiers();
@@ -1080,7 +1152,7 @@ public void keyTyped(com.jogamp.newt.event.KeyEvent e) {
10801152
nativeKeyEvent(e, KeyEvent.TYPE);
10811153
}
10821154
}
1083-
1155+
*/
10841156

10851157
///////////////////////////////////////////////////////////
10861158

@@ -1119,25 +1191,25 @@ protected int getFontAscent(Font font) {
11191191
}
11201192

11211193

1122-
@Override
11231194
protected int getFontDescent(Object font) {
1124-
FontMetrics metrics = pg.parent.getFontMetrics((Font)font);
1125-
return metrics.getDescent();
1195+
// FontMetrics metrics = pg.parent.getFontMetrics((Font)font);
1196+
// return metrics.getDescent();
1197+
return 0;
11261198
}
11271199

11281200

1129-
@Override
11301201
protected int getTextWidth(Object font, char buffer[], int start, int stop) {
11311202
// maybe should use one of the newer/fancier functions for this?
1132-
int length = stop - start;
1133-
FontMetrics metrics = pg.parent.getFontMetrics((Font)font);
1134-
return metrics.charsWidth(buffer, start, length);
1203+
// int length = stop - start;
1204+
// FontMetrics metrics = pg.parent.getFontMetrics((Font)font);
1205+
// return metrics.charsWidth(buffer, start, length);
1206+
return 0;
11351207
}
11361208

11371209

1138-
@Override
11391210
protected Object getDerivedFont(Object font, float size) {
11401211
return ((Font)font).deriveFont(size);
1212+
11411213
}
11421214

11431215

@@ -1315,7 +1387,9 @@ protected class FontOutline implements PGL.FontOutline {
13151387

13161388
public FontOutline(char ch, Object font) {
13171389
char textArray[] = new char[] { ch };
1318-
Graphics2D graphics = (Graphics2D) pg.parent.getGraphics();
1390+
// ???????????????
1391+
// Graphics2D graphics = (Graphics2D) pg.parent.getGraphics();
1392+
Graphics2D graphics = null;
13191393
FontRenderContext frc = graphics.getFontRenderContext();
13201394
GlyphVector gv = ((Font)font).createGlyphVector(frc, textArray);
13211395
Shape shp = gv.getOutline();

0 commit comments

Comments
 (0)