diff options
Diffstat (limited to 'src/jogl')
16 files changed, 158 insertions, 107 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/FBObject.java b/src/jogl/classes/com/jogamp/opengl/FBObject.java index 40b45ead2..26c8ff77f 100644 --- a/src/jogl/classes/com/jogamp/opengl/FBObject.java +++ b/src/jogl/classes/com/jogamp/opengl/FBObject.java @@ -2283,7 +2283,8 @@ public class FBObject { /** Returns the framebuffer name to render to. */ public final int getWriteFramebuffer() { return fbName; } /** Returns the framebuffer name to read from. Depending on multisampling, this may be a different framebuffer. */ - public final int getReadFramebuffer() { return ( samples > 0 ) ? samplingSink.getReadFramebuffer() : fbName; } + public final int getReadFramebuffer() { return ( samples > 0 ) ? samplingSink.getReadFramebuffer() : fbName; } + public final int getDefaultReadBuffer() { return GL.GL_COLOR_ATTACHMENT0; } /** Return the number of color/texture attachments */ public final int getColorAttachmentCount() { return colorAttachmentCount; } /** Return the stencil {@link RenderAttachment} attachment, if exist. Maybe share the same {@link Attachment#getName()} as {@link #getDepthAttachment()}, if packed depth-stencil is being used. */ 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 { * </p> */ 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. + * <p> + * 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. + * </p> + */ + 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. + * <p> + * 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. + * </p> + */ + 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. + <p> + Default impl. is <code>true</code>. + </p> + */ + 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 <i>GL_ARB_debug_output</i> or <i>GL_AMD_debug_output</i>. 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}. + * <p> + * If {@link GLCapabilities#getDoubleBuffered() double buffering} is not chosen, this is a NOP. + * </p> + * <p> + * Must be called before {@link #isInitialized() initialization}, otherwise an exception is thrown. + * </p> + * @return the new number of buffers (FBO) used, maybe different than the requested <code>bufferCount</code> (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(); } } diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java index 65b523394..24fc466b1 100644 --- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java @@ -1513,15 +1513,46 @@ public abstract class GLContextImpl extends GLContext { throw new GLException("Not supported on non-pbuffer contexts"); } - /** 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. */ - public abstract boolean offscreenImageNeedsVerticalFlip(); + @Override + public boolean isGLOrientationFlippedVertical() { + return true; + } - /** Only called for offscreen contexts; needed by glReadPixels */ - public abstract int getOffscreenContextPixelDataType(); + @Override + public int getDefaultPixelDataType() { + if(!pixelDataTypeEvaluated) { + synchronized(this) { + if(!pixelDataTypeEvaluated) { + evalPixelDataType(); + pixelDataTypeEvaluated = true; + } + } + } + return pixelDataType; + } + private volatile boolean pixelDataTypeEvaluated = false; + int /* pixelDataInternalFormat, */ pixelDataFormat, pixelDataType; + + private final void evalPixelDataType() { + /* if(isGL2GL3() && 3 == components) { + pixelDataInternalFormat=GL.GL_RGB; + pixelDataFormat=GL.GL_RGB; + pixelDataType = GL.GL_UNSIGNED_BYTE; + } else */ if(isGLES2Compatible() || isExtensionAvailable(GLExtensions.OES_read_format)) { + final int[] glImplColorReadVals = new int[] { 0, 0 }; + gl.glGetIntegerv(GL.GL_IMPLEMENTATION_COLOR_READ_FORMAT, glImplColorReadVals, 0); + gl.glGetIntegerv(GL.GL_IMPLEMENTATION_COLOR_READ_TYPE, glImplColorReadVals, 1); + // pixelDataInternalFormat = (4 == components) ? GL.GL_RGBA : GL.GL_RGB; + pixelDataFormat = glImplColorReadVals[0]; + pixelDataType = glImplColorReadVals[1]; + } else { + // RGBA read is safe for all GL profiles + // pixelDataInternalFormat = (4 == components) ? GL.GL_RGBA : GL.GL_RGB; + pixelDataFormat=GL.GL_RGBA; + pixelDataType = GL.GL_UNSIGNED_BYTE; + } + } //---------------------------------------------------------------------- // Helpers for buffer object optimizations @@ -1599,8 +1630,10 @@ public abstract class GLContextImpl extends GLContext { @Override public final int getDefaultDrawFramebuffer() { return drawable.getDefaultDrawFramebuffer(); } @Override - public final int getDefaultReadFramebuffer() { return drawable.getDefaultReadFramebuffer(); } - + public final int getDefaultReadFramebuffer() { return drawable.getDefaultReadFramebuffer(); } + @Override + public final int getDefaultReadBuffer() { return drawable.getDefaultReadBuffer(gl); } + //--------------------------------------------------------------------------- // GL_ARB_debug_output, GL_AMD_debug_output helpers // diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableImpl.java b/src/jogl/classes/jogamp/opengl/GLDrawableImpl.java index df7f742aa..ccf0a8f0d 100644 --- a/src/jogl/classes/jogamp/opengl/GLDrawableImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLDrawableImpl.java @@ -244,7 +244,16 @@ public abstract class GLDrawableImpl implements GLDrawable { /** Callback for special implementations, allowing GLContext to fetch a custom default render framebuffer. Defaults to zero.*/ protected int getDefaultDrawFramebuffer() { return 0; } /** Callback for special implementations, allowing GLContext to fetch a custom default read framebuffer. Defaults to zero. */ - protected int getDefaultReadFramebuffer() { return 0; } + protected int getDefaultReadFramebuffer() { return 0; } + /** Callback for special implementations, allowing GLContext to fetch a custom default read buffer of current framebuffer. */ + protected int getDefaultReadBuffer(GL gl) { + if(gl.isGLES() || getChosenGLCapabilities().getDoubleBuffered()) { + // Note-1: Neither ES1 nor ES2 supports selecting the read buffer via glReadBuffer + // Note-2: ES3 only supports GL_BACK, GL_NONE or GL_COLOR_ATTACHMENT0+i + return GL.GL_BACK; + } + return GL.GL_FRONT ; + } @Override public final synchronized boolean isRealized() { diff --git a/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java b/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java index 7a468a41e..b72f79868 100644 --- a/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java @@ -302,6 +302,9 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable { protected final int getDefaultReadFramebuffer() { return initialized ? fbos[fboIFront].getReadFramebuffer() : 0; } @Override + protected final int getDefaultReadBuffer(GL gl) { return initialized ? fbos[fboIFront].getDefaultReadBuffer() : GL.GL_COLOR_ATTACHMENT0 ; } + + @Override protected final void setRealizedImpl() { final MutableGraphicsConfiguration msConfig = (MutableGraphicsConfiguration) surface.getGraphicsConfiguration(); if(realized) { @@ -435,6 +438,17 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable { } } + @Override + public final int setNumBuffers(int bufferCount) throws GLException { + // FIXME: Implement + return bufferCount; + } + + @Override + public final int getNumBuffers() { + return bufferCount; + } + /** // TODO: Add or remove TEXTURE (only) DoubleBufferMode support @Override public final DoubleBufferMode getDoubleBufferMode() { diff --git a/src/jogl/classes/jogamp/opengl/GLOffscreenAutoDrawableImpl.java b/src/jogl/classes/jogamp/opengl/GLOffscreenAutoDrawableImpl.java index 7701f209f..59a00170d 100644 --- a/src/jogl/classes/jogamp/opengl/GLOffscreenAutoDrawableImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLOffscreenAutoDrawableImpl.java @@ -95,6 +95,16 @@ public class GLOffscreenAutoDrawableImpl extends GLAutoDrawableDelegate implemen windowRepaintOp(); } + @Override + public final int setNumBuffers(int bufferCount) throws GLException { + return ((GLFBODrawableImpl)drawable).setNumBuffers(bufferCount); + } + + @Override + public final int getNumBuffers() { + return ((GLFBODrawableImpl)drawable).getNumBuffers(); + } + /** // TODO: Add or remove TEXTURE (only) DoubleBufferMode support @Override public DoubleBufferMode getDoubleBufferMode() { diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java index 84aeaa94a..deb3813b1 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java @@ -344,14 +344,4 @@ public abstract class EGLContext extends GLContextImpl { public ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { throw new GLException("Should not call this"); } - - @Override - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - - @Override - public int getOffscreenContextPixelDataType() { - throw new GLException("Should not call this"); - } } diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java index cde9841b8..63ed2ab7d 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java @@ -420,20 +420,6 @@ public abstract class MacOSXCGLContext extends GLContextImpl return super.isExtensionAvailable(glExtensionName); } - @Override - public int getOffscreenContextPixelDataType() { - throw new GLException("Should not call this"); - } - - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - @Override - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - // Support for "mode switching" as described in MacOSXCGLDrawable public void setOpenGLMode(GLBackendType mode) { if (mode == openGLMode) { diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOffscreenCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOffscreenCGLContext.java index 7b13ce22e..f2e636796 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOffscreenCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOffscreenCGLContext.java @@ -49,18 +49,8 @@ public class MacOSXOffscreenCGLContext extends MacOSXPbufferCGLContext } @Override - public int getOffscreenContextPixelDataType() { - GL gl = getGL(); + public int getDefaultPixelDataType() { + final GL gl = getGL(); return gl.isGL2GL3()?GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV:GL.GL_UNSIGNED_SHORT_5_5_5_1; } - - @Override - public int getOffscreenContextReadBuffer() { - return GL.GL_FRONT; - } - - @Override - public boolean offscreenImageNeedsVerticalFlip() { - return true; - } } diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsBitmapWGLContext.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsBitmapWGLContext.java index 51341a098..c8aac7f7b 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsBitmapWGLContext.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsBitmapWGLContext.java @@ -49,18 +49,12 @@ public class WindowsBitmapWGLContext extends WindowsWGLContext { } @Override - public int getOffscreenContextPixelDataType() { + public int getDefaultPixelDataType() { return GL.GL_UNSIGNED_BYTE; } @Override - public int getOffscreenContextReadBuffer() { - // On Windows these contexts are always single-buffered - return GL.GL_FRONT; - } - - @Override - public boolean offscreenImageNeedsVerticalFlip() { + public boolean isGLOrientationFlippedVertical() { // We can take care of this in the DIB creation (see below) return false; } diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java index 57f16522c..92d75e3fd 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java @@ -538,20 +538,6 @@ public class WindowsWGLContext extends GLContextImpl { } @Override - public int getOffscreenContextPixelDataType() { - throw new GLException("Should not call this"); - } - - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - @Override - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - - @Override public void bindPbufferToTexture() { throw new GLException("Should not call this"); } diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java index 76e0bc15c..bf1045132 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java @@ -619,20 +619,6 @@ public abstract class X11GLXContext extends GLContextImpl { } @Override - public int getOffscreenContextPixelDataType() { - throw new GLException("Should not call this"); - } - - public int getOffscreenContextReadBuffer() { - throw new GLException("Should not call this"); - } - - @Override - public boolean offscreenImageNeedsVerticalFlip() { - throw new GLException("Should not call this"); - } - - @Override public void bindPbufferToTexture() { throw new GLException("Should not call this"); } diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11PixmapGLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11PixmapGLXContext.java index 96d0f18dc..1cfb7e427 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11PixmapGLXContext.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11PixmapGLXContext.java @@ -50,24 +50,9 @@ public class X11PixmapGLXContext extends X11GLXContext { } @Override - public int getOffscreenContextPixelDataType() { + public int getDefaultPixelDataType() { GL gl = getGL(); return gl.isGL2GL3()?GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV:GL.GL_UNSIGNED_SHORT_5_5_5_1; } - @Override - public int getOffscreenContextReadBuffer() { - GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable)drawable.getNativeSurface().getGraphicsConfiguration().getChosenCapabilities(); - if (caps.getDoubleBuffered()) { - return GL.GL_BACK; - } - return GL.GL_FRONT; - } - - @Override - public boolean offscreenImageNeedsVerticalFlip() { - // There doesn't seem to be a way to do this in the construction - // of the Pixmap or GLXPixmap - return true; - } } |