Merge pull request #2 from codeanticode/master

more architectural work
This commit is contained in:
Ben Fry
2014-11-16 08:26:04 -07:00
4 changed files with 137 additions and 81 deletions
+30 -31
View File
@@ -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,8 +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...
// return !clear0 || fboLayerRequested || 1 < numSamples;
return false;
// boolean res = !clear0 || fboLayerRequested || 1 < numSamples;
// System.err.println(res + " " + clear0 + " " + fboLayerRequested + " " + numSamples);
// return res;
return fboLayerRequested;
}
+14 -10
View File
@@ -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;
+46 -27
View File
@@ -190,7 +190,7 @@ public class PJOGL extends PGL {
// Retina support
int retf = 1;
int pixel_scale = 1;
// ........................................................
@@ -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
@@ -802,7 +807,9 @@ public class PJOGL extends PGL {
protected void getBuffers(GLWindow glWindow) {
if (USE_JOGL_FBOLAYER && capabilities.isFBO()) {
if (false) {
// if (capabilities.isFBO()) {
// if (USE_JOGL_FBOLAYER && capabilities.isFBO()) {
// The onscreen drawing surface is backed by an FBO layer.
GLFBODrawable fboDrawable = null;
fboDrawable = (GLFBODrawable)glWindow.getDelegatedDrawable();
@@ -859,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() {}
@@ -1376,9 +1397,7 @@ public class PJOGL extends PGL {
public FontOutline(char ch, Object font) {
char textArray[] = new char[] { ch };
// ???????????????
// Graphics2D graphics = (Graphics2D) pg.parent.getGraphics();
Graphics2D graphics = null;
Graphics2D graphics = (Graphics2D) pg.parent.frame.getGraphics();
FontRenderContext frc = graphics.getFontRenderContext();
GlyphVector gv = ((Font)font).createGlyphVector(frc, textArray);
Shape shp = gv.getOutline();
@@ -1856,7 +1875,7 @@ public class PJOGL extends PGL {
@Override
public void viewport(int x, int y, int w, int h) {
gl.glViewport(retf * x, retf * y, retf * w, retf * h);
gl.glViewport(pixel_scale * x, pixel_scale * y, pixel_scale * w, pixel_scale * h);
}
//////////////////////////////////////////////////////////////////////////////
@@ -2378,7 +2397,7 @@ public class PJOGL extends PGL {
@Override
public void scissor(int x, int y, int w, int h) {
gl.glScissor(retf * x, retf * y, retf * w, retf * h);
gl.glScissor(pixel_scale * x, pixel_scale * y, pixel_scale * w, pixel_scale * h);
}
@Override
+47 -13
View File
@@ -2,6 +2,7 @@ package processing.opengl;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Rectangle;
import java.util.ArrayList;
import javax.media.nativewindow.ScalableSurface;
@@ -38,6 +39,7 @@ public class PSurfaceNEWT implements PSurface {
GLWindow window;
Frame frame;
FPSAnimator animator;
Rectangle screenRect;
PApplet sketch;
PGraphics graphics;
@@ -66,8 +68,6 @@ public class PSurfaceNEWT implements PSurface {
display.addReference();
Screen screen = NewtFactory.createScreen(display, 0);
screen.addReference();
int screenWidth = screen.getWidth();
int screenHeight = screen.getHeight();
ArrayList<MonitorDevice> monitors = new ArrayList<MonitorDevice>();
for (int i = 0; i < screen.getMonitorDevices().size(); i++) {
@@ -127,6 +127,9 @@ public class PSurfaceNEWT implements PSurface {
caps.setDepthBits(PGL.REQUESTED_DEPTH_BITS);
caps.setStencilBits(PGL.REQUESTED_STENCIL_BITS);
caps.setPBuffer(false);
caps.setFBO(false);
caps.setSampleBuffers(true);
caps.setNumSamples(2);
caps.setBackgroundOpaque(true);
@@ -144,29 +147,55 @@ public class PSurfaceNEWT implements PSurface {
int sketchX = displayDevice.getViewportInWindowUnits().getX();
int sketchY = displayDevice.getViewportInWindowUnits().getY();
int screenWidth = screen.getWidth();
int screenHeight = screen.getHeight();
screenRect = spanDisplays ? new Rectangle(0, 0, screen.getWidth(), screen.getHeight()) :
new Rectangle(0, 0, displayDevice.getViewportInWindowUnits().getWidth(),
displayDevice.getViewportInWindowUnits().getHeight());
// Sketch has already requested to be the same as the screen's
// width and height, so let's roll with full screen mode.
if (screenRect.width == sketchWidth &&
screenRect.height == sketchHeight) {
fullScreen = true;
}
if (fullScreen || spanDisplays) {
sketchWidth = screenRect.width;
sketchHeight = screenRect.height;
}
// window..setBackground(new Color(backgroundColor, true));
window.setPosition(sketchX, sketchY);
window.setSize(sketchWidth, sketchHeight);
System.out.println("deviceIndex: " + deviceIndex);
System.out.println(displayDevice);
System.out.println("Screen res " + screenWidth + "x" + screenHeight);
// This example could be useful:
// com.jogamp.opengl.test.junit.newt.mm.TestScreenMode01cNEWT
if (fullScreen) {
if (spanDisplays) {
window.setFullscreen(monitors);
} else {
window.setFullscreen(true);
}
}
window.setVisible(true);
// Retina
// int[] reqSurfacePixelScale = new int[] { ScalableSurface.AUTOMAX_PIXELSCALE,
// ScalableSurface.AUTOMAX_PIXELSCALE };
// pgl.pixel_scale = 2;
// Non-retina
int[] reqSurfacePixelScale = new int[] { ScalableSurface.IDENTITY_PIXELSCALE,
ScalableSurface.IDENTITY_PIXELSCALE };
window.setSurfaceScale(reqSurfacePixelScale);
pgl.pixel_scale = 1;
@@ -257,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() {
@@ -283,12 +318,11 @@ public class PSurfaceNEWT implements PSurface {
}
public void setFrameRate(float fps) {
// TODO Auto-generated method stub
animator.setFPS((int)fps);
}
public void requestFocus() {
// TODO Auto-generated method stub
window.requestFocus();
}
@@ -323,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);
}
}