From e7064ece049705e013d80985eae698ce0ee3c4e3 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 15 Dec 2012 23:25:12 +0100 Subject: Cleanup GLContext special entries: getOffscreenContextPixelDataType(), getOffscreenContextReadBuffer(), .. ; Add GLFBODrawable API entries for multi buffering (no impl. yet); GLJPanel 1st simplification using offscreen drawable - Cleanup GLContext special entries: getOffscreenContextPixelDataType(), getOffscreenContextReadBuffer(), .. ; - add: getDefaultReadBuffer() (-> exposed via GLBase as well) - add: isGLOrientationFlippedVertical() - add: getDefaultPixelDataType() - removed impl: getOffscreenContextPixelDataType() - removed impl: getOffscreenContextReadBuffer() - removed impl: offscreenImageNeedsVerticalFlip() - Add GLFBODrawable API entries for multi buffering (no impl. yet); - TODO: Add implementation code in GLFBODrawableImpl - GLJPanel 1st simplification using FBO - Use above new GL/GLContext entries - Fix: getNativeSurface() and getHandle() - TODO: - Remove distinction of 'pbuffer' and 'software', - Use GLDrawableFactory.createOffscreenDrawable(..) - Use GL for FBO swapping --- src/jogl/classes/javax/media/opengl/GLBase.java | 15 ++++++++++++- src/jogl/classes/javax/media/opengl/GLContext.java | 26 ++++++++++++++++++++++ .../classes/javax/media/opengl/GLFBODrawable.java | 22 +++++++++++++++++- .../classes/javax/media/opengl/awt/GLJPanel.java | 20 ++++++++++++----- 4 files changed, 75 insertions(+), 8 deletions(-) (limited to 'src/jogl/classes/javax/media') diff --git a/src/jogl/classes/javax/media/opengl/GLBase.java b/src/jogl/classes/javax/media/opengl/GLBase.java index 9bcee819a..82bb06b9c 100644 --- a/src/jogl/classes/javax/media/opengl/GLBase.java +++ b/src/jogl/classes/javax/media/opengl/GLBase.java @@ -432,6 +432,19 @@ public interface GLBase { *

*/ public int getDefaultReadFramebuffer(); - + + /** + * Returns the default color buffer within the current bound + * {@link #getDefaultReadFramebuffer()}, i.e. GL_READ_FRAMEBUFFER​, + * which will be used as the source for pixel reading commands, + * like {@link GL#glReadPixels(int, int, int, int, int, int, java.nio.Buffer)} etc. + *

+ * For offscreen framebuffer objects this is {@link GL#GL_COLOR_ATTACHMENT0}, + * otherwise this is {@link GL#GL_FRONT} for single buffer configurations + * and {@link GL#GL_BACK} for double buffer configurations. + *

+ */ + public int getDefaultReadBuffer(); + } diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index de10a2815..235003c38 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -970,6 +970,32 @@ public abstract class GLContext { */ public abstract int getDefaultReadFramebuffer(); + /** + * Returns the default color buffer within the current bound + * {@link #getDefaultReadFramebuffer()}, i.e. GL_READ_FRAMEBUFFER​, + * which will be used as the source for pixel reading commands, + * like {@link GL#glReadPixels(int, int, int, int, int, int, java.nio.Buffer)} etc. + *

+ * For offscreen framebuffer objects this is {@link GL#GL_COLOR_ATTACHMENT0}, + * otherwise this is {@link GL#GL_FRONT} for single buffer configurations + * and {@link GL#GL_BACK} for double buffer configurations. + *

+ */ + public abstract int getDefaultReadBuffer(); + + /** On some platforms the mismatch between OpenGL's coordinate + system (origin at bottom left) and the window system's + coordinate system (origin at top left) necessitates a vertical + flip of pixels read from offscreen contexts. +

+ Default impl. is true. +

+ */ + public abstract boolean isGLOrientationFlippedVertical(); + + /** Get the default pixel data type, as required by e.g. {@link GL#glReadPixels(int, int, int, int, int, int, java.nio.Buffer)}. */ + public abstract int getDefaultPixelDataType(); + /** * @return The extension implementing the GLDebugOutput feature, * either GL_ARB_debug_output or GL_AMD_debug_output. diff --git a/src/jogl/classes/javax/media/opengl/GLFBODrawable.java b/src/jogl/classes/javax/media/opengl/GLFBODrawable.java index 079d9af5c..4d6c7c20e 100644 --- a/src/jogl/classes/javax/media/opengl/GLFBODrawable.java +++ b/src/jogl/classes/javax/media/opengl/GLFBODrawable.java @@ -101,7 +101,8 @@ public interface GLFBODrawable extends GLDrawable { void setTextureUnit(int unit); /** - * Set a new sample size + * Set the number of sample buffers if using MSAA + * * @param gl GL context object bound to this drawable, will be made current during operation. * A prev. current context will be make current after operation. * @param newSamples new sample size @@ -113,6 +114,25 @@ public interface GLFBODrawable extends GLDrawable { * @return the number of sample buffers if using MSAA, otherwise 0 */ int getNumSamples(); + + /** + * Sets the number of buffers (FBO) being used if using {@link GLCapabilities#getDoubleBuffered() double buffering}. + *

+ * If {@link GLCapabilities#getDoubleBuffered() double buffering} is not chosen, this is a NOP. + *

+ *

+ * Must be called before {@link #isInitialized() initialization}, otherwise an exception is thrown. + *

+ * @return the new number of buffers (FBO) used, maybe different than the requested bufferCount (see above) + * @throws GLException if already initialized, see {@link #isInitialized()}. + */ + int setNumBuffers(int bufferCount) throws GLException; + + /** + * @return the number of buffers (FBO) being used. 1 if not using {@link GLCapabilities#getDoubleBuffered() double buffering}, + * otherwise ≥ 2, depending on {@link #setNumBuffers(int)}. + */ + int getNumBuffers(); /** * @return the used {@link DoubleBufferMode} diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index dcfc1f0dd..a9d4989dc 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -618,12 +618,18 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing @Override public NativeSurface getNativeSurface() { - throw new GLException("FIXME"); + if(null != backend) { + return backend.getDrawable().getNativeSurface(); + } + return null; } @Override public long getHandle() { - throw new GLException("FIXME"); + if(null != backend) { + return backend.getDrawable().getNativeSurface().getSurfaceHandle(); + } + return 0; } @Override @@ -657,6 +663,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing if (oglPipelineEnabled) { backend = new J2DOGLBackend(); } else { + backend = new SoftwareBackend(); + /** if (!hardwareAccelerationDisabled && factory.canCreateGLPbuffer(null)) { backend = new PbufferBackend(); @@ -665,7 +673,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing throw new GLException("Fallback to software rendering disabled by user"); } backend = new SoftwareBackend(); - } + } */ } } @@ -996,7 +1004,7 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing gl.glPixelStorei(GL2.GL_PACK_ALIGNMENT, 1); // Actually read the pixels. - gl.glReadBuffer(GL2.GL_FRONT); + gl.glReadBuffer(gl.getDefaultReadBuffer()); if (readBackBytes != null) { gl.glReadPixels(0, 0, readBackWidthInPixels, readBackHeightInPixels, glFormat, glType, readBackBytes); } else if (readBackInts != null) { @@ -1173,12 +1181,12 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable, WindowClosing @Override protected int getGLPixelType() { - return offscreenContext.getOffscreenContextPixelDataType(); + return offscreenContext.getDefaultPixelDataType(); } @Override protected boolean flipVertically() { - return offscreenContext.offscreenImageNeedsVerticalFlip(); + return offscreenContext.isGLOrientationFlippedVertical(); } } -- cgit v1.2.3