diff options
author | Sven Gothel <[email protected]> | 2023-07-15 14:35:02 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-07-15 14:35:02 +0200 |
commit | be9c3e42e618148584689a1ccf30c8c3f4e6227a (patch) | |
tree | 6daa57deb2ba89640c44da0a75bcada528c04570 | |
parent | ddbffc38f001e3297d560ab1f6b3e7575771bdc5 (diff) |
Add {GL, GLContext}.getDefaultDrawBuffer() to complement getDefaultReadBuffer()
7 files changed, 103 insertions, 28 deletions
diff --git a/make/config/jogl/gl-impl-CustomJavaCode-common.java b/make/config/jogl/gl-impl-CustomJavaCode-common.java index b764191e2..b1500adcf 100644 --- a/make/config/jogl/gl-impl-CustomJavaCode-common.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-common.java @@ -124,6 +124,11 @@ } @Override + public final int getDefaultDrawBuffer() { + return _context.getDefaultDrawBuffer(); + } + + @Override public final int getDefaultReadBuffer() { return _context.getDefaultReadBuffer(); } diff --git a/src/jogl/classes/com/jogamp/opengl/FBObject.java b/src/jogl/classes/com/jogamp/opengl/FBObject.java index a559445c7..8f62c9952 100644 --- a/src/jogl/classes/com/jogamp/opengl/FBObject.java +++ b/src/jogl/classes/com/jogamp/opengl/FBObject.java @@ -2772,7 +2772,11 @@ public class FBObject { public final int getReadFramebuffer() { return 0 < samples ? ( null != samplingSink ? samplingSink.getReadFramebuffer() : 0 ) : fbName; } + + public final int getDefaultDrawBuffer() { return GL.GL_COLOR_ATTACHMENT0; } + public final int getDefaultReadBuffer() { return GL.GL_COLOR_ATTACHMENT0; } + /** Return the number of attached {@link Colorbuffer}s */ public final int getColorbufferCount() { return colorbufferCount; } /** Return the number of attached {@link TextureAttachment}s */ diff --git a/src/jogl/classes/com/jogamp/opengl/GLBase.java b/src/jogl/classes/com/jogamp/opengl/GLBase.java index 0cbcbe40f..a2f22a4d4 100644 --- a/src/jogl/classes/com/jogamp/opengl/GLBase.java +++ b/src/jogl/classes/com/jogamp/opengl/GLBase.java @@ -648,31 +648,55 @@ 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) glReadPixels} 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> - * <p> - * Note-1: Neither ES1 nor ES2 supports selecting the read buffer via glReadBuffer - * and {@link GL#GL_BACK} is the default. - * </p> - * <p> - * Note-2: ES3 only supports {@link GL#GL_BACK}, {@link GL#GL_NONE} or {@link GL#GL_COLOR_ATTACHMENT0}+i - * </p> - * <p> - * Note-3: See {@link com.jogamp.opengl.util.GLDrawableUtil#swapBuffersBeforeRead(GLCapabilitiesImmutable) swapBuffersBeforeRead} - * for read-pixels and swap-buffers implications. - * </p> - * <p> - * Calls {@link GLContext#getDefaultReadBuffer()}. - * </p> - */ - public int getDefaultReadBuffer(); + /** + * Returns the default color buffer within the current bound + * {@link #getDefaultReadFramebuffer()}, i.e. GL_READ_FRAMEBUFFER, + * which will be used as the target (output) for (fragment shader) draw commands, + * settable via {@link GL2ES2#glDrawBuffers(int, int[], int)} or {@link GL2#glDrawBuffer(int)}. + * <p> + * For offscreen framebuffer objects this is {@link GL#GL_COLOR_ATTACHMENT0}, + * otherwise this is {@link GL#GL_FRONT} for non-ES profile and single buffer configurations + * and {@link GL#GL_BACK} for double buffer configurations or ES profiles. + * </p> + * <p> + * Note-1: Neither ES1 nor ES2 supports selecting the draw buffer at all + * and {@link GL#GL_BACK} is the default. + * </p> + * <p> + * Note-2: ES3 only supports {@link GL#GL_BACK}, {@link GL#GL_NONE} or {@link GL#GL_COLOR_ATTACHMENT0}+i + * via {@link GL2ES2#glDrawBuffers(int, int[], int)}. + * </p> + * <p> + * Method is only thread-safe while context is {@link #makeCurrent() made current}. + * </p> + */ + public int getDefaultDrawBuffer(); + + /** + * 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) glReadPixels} etc. + * <p> + * For offscreen framebuffer objects this is {@link GL#GL_COLOR_ATTACHMENT0}, + * otherwise this is {@link GL#GL_FRONT} for non-ES profile and single buffer configurations + * and {@link GL#GL_BACK} for double buffer configurations or ES profiles. + * </p> + * <p> + * Note-1: Neither ES1 nor ES2 supports selecting the read buffer via glReadBuffer + * and {@link GL#GL_BACK} is the default. + * </p> + * <p> + * Note-2: ES3 only supports {@link GL#GL_BACK}, {@link GL#GL_NONE} or {@link GL#GL_COLOR_ATTACHMENT0}+i + * </p> + * <p> + * Note-3: See {@link com.jogamp.opengl.util.GLDrawableUtil#swapBuffersBeforeRead(GLCapabilitiesImmutable) swapBuffersBeforeRead} + * for read-pixels and swap-buffers implications. + * </p> + * <p> + * Method is only thread-safe while context is {@link #makeCurrent() made current}. + * </p> + */ + public int getDefaultReadBuffer(); } diff --git a/src/jogl/classes/com/jogamp/opengl/GLContext.java b/src/jogl/classes/com/jogamp/opengl/GLContext.java index 4455633a1..470635a98 100644 --- a/src/jogl/classes/com/jogamp/opengl/GLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/GLContext.java @@ -1367,12 +1367,36 @@ public abstract class GLContext { /** * Returns the default color buffer within the current bound * {@link #getDefaultReadFramebuffer()}, i.e. GL_READ_FRAMEBUFFER, + * which will be used as the target (output) for (fragment shader) draw commands, + * settable via {@link GL2ES2#glDrawBuffers(int, int[], int)} or {@link GL2#glDrawBuffer(int)}. + * <p> + * For offscreen framebuffer objects this is {@link GL#GL_COLOR_ATTACHMENT0}, + * otherwise this is {@link GL#GL_FRONT} for non-ES profile and single buffer configurations + * and {@link GL#GL_BACK} for double buffer configurations or ES profiles. + * </p> + * <p> + * Note-1: Neither ES1 nor ES2 supports selecting the draw buffer at all + * and {@link GL#GL_BACK} is the default. + * </p> + * <p> + * Note-2: ES3 only supports {@link GL#GL_BACK}, {@link GL#GL_NONE} or {@link GL#GL_COLOR_ATTACHMENT0}+i + * via {@link GL2ES2#glDrawBuffers(int, int[], int)}. + * </p> + * <p> + * Method is only thread-safe while context is {@link #makeCurrent() made current}. + * </p> + */ + public abstract int getDefaultDrawBuffer(); + + /** + * 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) glReadPixels} 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. + * otherwise this is {@link GL#GL_FRONT} for non-ES profile and single buffer configurations + * and {@link GL#GL_BACK} for double buffer configurations or ES profiles. * </p> * <p> * Note-1: Neither ES1 nor ES2 supports selecting the read buffer via glReadBuffer diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java index 88b746df6..8154dec31 100644 --- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java @@ -2938,6 +2938,8 @@ public abstract class GLContextImpl extends GLContext { @Override public final int getDefaultReadFramebuffer() { return drawable.getDefaultReadFramebuffer(); } @Override + public final int getDefaultDrawBuffer() { return drawable.getDefaultDrawBuffer(gl); } + @Override public final int getDefaultReadBuffer() { return drawable.getDefaultReadBuffer(gl, drawableRead != drawable); } //--------------------------------------------------------------------------- diff --git a/src/jogl/classes/jogamp/opengl/GLDrawableImpl.java b/src/jogl/classes/jogamp/opengl/GLDrawableImpl.java index 98a0a0948..4e0f5eaca 100644 --- a/src/jogl/classes/jogamp/opengl/GLDrawableImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLDrawableImpl.java @@ -257,6 +257,17 @@ public abstract class GLDrawableImpl implements GLDrawable { 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; } + + /** Callback for special implementations, allowing GLContext to fetch a custom default draw buffer of current framebuffer. */ + protected int getDefaultDrawBuffer(final GL gl) { + if( gl.isGLES() || getChosenGLCapabilities().getDoubleBuffered() ) { + // Note-1: Neither ES1 nor ES2 supports selecting the read buffer via glDrawBuffer + // Note-2: ES3 only supports GL_BACK, GL_NONE or GL_COLOR_ATTACHMENT0+i + return GL.GL_BACK; + } + return GL.GL_FRONT; + } + /** Callback for special implementations, allowing GLContext to fetch a custom default read buffer of current framebuffer. */ protected int getDefaultReadBuffer(final GL gl, final boolean hasDedicatedDrawableRead) { if( gl.isGLES() || hasDedicatedDrawableRead || getChosenGLCapabilities().getDoubleBuffered() ) { diff --git a/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java b/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java index 8ec3c0dd9..2bc682324 100644 --- a/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java @@ -411,6 +411,11 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable { protected final int getDefaultReadFramebuffer() { return initialized ? fbos[fboIFront].getReadFramebuffer() : 0; } @Override + protected final int getDefaultDrawBuffer(final GL gl) { + return initialized ? fbos[fboIBack].getDefaultDrawBuffer() : GL.GL_COLOR_ATTACHMENT0 ; + } + + @Override protected final int getDefaultReadBuffer(final GL gl, final boolean hasDedicatedDrawableRead) { return initialized ? fbos[fboIFront].getDefaultReadBuffer() : GL.GL_COLOR_ATTACHMENT0 ; } |