summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com')
-rw-r--r--src/jogl/classes/com/jogamp/gluegen/opengl/BuildComposablePipeline.java2
-rw-r--r--src/jogl/classes/com/jogamp/gluegen/opengl/BuildStaticGLInfo.java4
-rwxr-xr-xsrc/jogl/classes/com/jogamp/gluegen/opengl/GLConfiguration.java10
-rw-r--r--src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java18
-rw-r--r--src/jogl/classes/com/jogamp/gluegen/runtime/opengl/GLNameResolver.java (renamed from src/jogl/classes/com/jogamp/gluegen/runtime/opengl/GLExtensionNames.java)3
-rw-r--r--src/jogl/classes/com/jogamp/gluegen/runtime/opengl/GLProcAddressResolver.java4
-rw-r--r--src/jogl/classes/com/jogamp/opengl/FBObject.java1943
-rw-r--r--src/jogl/classes/com/jogamp/opengl/GLExtensions.java81
-rw-r--r--src/jogl/classes/com/jogamp/opengl/JoglVersion.java18
-rw-r--r--src/jogl/classes/com/jogamp/opengl/OffscreenAutoDrawable.java98
-rw-r--r--src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java381
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/FBObject.java483
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLBuffers.java179
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java12
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java25
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/awt/Screenshot.java3
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java3
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java25
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java8
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java1
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/texture/spi/NetPbmTextureWriter.java6
21 files changed, 2580 insertions, 727 deletions
diff --git a/src/jogl/classes/com/jogamp/gluegen/opengl/BuildComposablePipeline.java b/src/jogl/classes/com/jogamp/gluegen/opengl/BuildComposablePipeline.java
index 1d9cf3668..5334d45cf 100644
--- a/src/jogl/classes/com/jogamp/gluegen/opengl/BuildComposablePipeline.java
+++ b/src/jogl/classes/com/jogamp/gluegen/opengl/BuildComposablePipeline.java
@@ -410,7 +410,7 @@ public class BuildComposablePipeline {
output.flush();
output.close();
- System.out.println("wrote to file: " + file); // JAU
+ System.out.println("wrote to file: " + file);
}
/** Get the name of the object through which API calls should be routed. */
diff --git a/src/jogl/classes/com/jogamp/gluegen/opengl/BuildStaticGLInfo.java b/src/jogl/classes/com/jogamp/gluegen/opengl/BuildStaticGLInfo.java
index 87a734e1f..482d35cae 100644
--- a/src/jogl/classes/com/jogamp/gluegen/opengl/BuildStaticGLInfo.java
+++ b/src/jogl/classes/com/jogamp/gluegen/opengl/BuildStaticGLInfo.java
@@ -293,9 +293,9 @@ public class BuildStaticGLInfo {
output.println(" public static String getFunctionAssociation(String glFunctionName)");
output.println(" {");
output.println(" String mappedName = null;");
- output.println(" int funcNamePermNum = com.jogamp.gluegen.runtime.opengl.GLExtensionNames.getFuncNamePermutationNumber(glFunctionName);");
+ output.println(" int funcNamePermNum = com.jogamp.gluegen.runtime.opengl.GLNameResolver.getFuncNamePermutationNumber(glFunctionName);");
output.println(" for(int i = 0; null==mappedName && i < funcNamePermNum; i++) {");
- output.println(" String tmp = com.jogamp.gluegen.runtime.opengl.GLExtensionNames.getFuncNamePermutation(glFunctionName, i);");
+ output.println(" String tmp = com.jogamp.gluegen.runtime.opengl.GLNameResolver.getFuncNamePermutation(glFunctionName, i);");
output.println(" try {");
output.println(" mappedName = (String)funcToAssocMap.get(tmp);");
output.println(" } catch (Exception e) { }");
diff --git a/src/jogl/classes/com/jogamp/gluegen/opengl/GLConfiguration.java b/src/jogl/classes/com/jogamp/gluegen/opengl/GLConfiguration.java
index c1a4facd2..ba025e18c 100755
--- a/src/jogl/classes/com/jogamp/gluegen/opengl/GLConfiguration.java
+++ b/src/jogl/classes/com/jogamp/gluegen/opengl/GLConfiguration.java
@@ -43,7 +43,7 @@ import com.jogamp.gluegen.GlueEmitterControls;
import com.jogamp.gluegen.GlueGen;
import com.jogamp.gluegen.MethodBinding;
import com.jogamp.gluegen.procaddress.ProcAddressConfiguration;
-import com.jogamp.gluegen.runtime.opengl.GLExtensionNames;
+import com.jogamp.gluegen.runtime.opengl.GLNameResolver;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
@@ -224,11 +224,11 @@ public class GLConfiguration extends ProcAddressConfiguration {
}
}
}
- boolean isGLEnum = GLExtensionNames.isGLEnumeration(symbol);
- boolean isGLFunc = GLExtensionNames.isGLFunction(symbol);
+ boolean isGLEnum = GLNameResolver.isGLEnumeration(symbol);
+ boolean isGLFunc = GLNameResolver.isGLFunction(symbol);
if (isGLFunc || isGLEnum) {
- if (GLExtensionNames.isExtensionVEN(symbol, isGLFunc)) {
- String extSuffix = GLExtensionNames.getExtensionSuffix(symbol, isGLFunc);
+ if (GLNameResolver.isExtensionVEN(symbol, isGLFunc)) {
+ String extSuffix = GLNameResolver.getExtensionSuffix(symbol, isGLFunc);
if (getDropUniqVendorExtensions(extSuffix)) {
if (DEBUG_IGNORES) {
System.err.println("Ignore UniqVendorEXT: " + symbol + ", vendor " + extSuffix);
diff --git a/src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java b/src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java
index f4658ad7b..809c6783d 100644
--- a/src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java
+++ b/src/jogl/classes/com/jogamp/gluegen/opengl/GLEmitter.java
@@ -51,7 +51,7 @@ import com.jogamp.gluegen.SymbolFilter;
import com.jogamp.gluegen.cgram.types.FunctionSymbol;
import com.jogamp.gluegen.procaddress.ProcAddressEmitter;
import com.jogamp.gluegen.procaddress.ProcAddressJavaMethodBindingEmitter;
-import com.jogamp.gluegen.runtime.opengl.GLExtensionNames;
+import com.jogamp.gluegen.runtime.opengl.GLNameResolver;
import java.io.IOException;
import java.io.PrintWriter;
@@ -110,13 +110,13 @@ public class GLEmitter extends ProcAddressEmitter {
if (declarations != null) {
for (Iterator<String> iterator = declarations.iterator(); iterator.hasNext();) {
String decl = iterator.next();
- boolean isGLFunction = GLExtensionNames.isGLFunction(decl);
+ boolean isGLFunction = GLNameResolver.isGLFunction(decl);
boolean isGLEnumeration = false;
if (!isGLFunction) {
- isGLEnumeration = GLExtensionNames.isGLEnumeration(decl);
+ isGLEnumeration = GLNameResolver.isGLEnumeration(decl);
}
if (isGLFunction || isGLEnumeration) {
- String renamed = GLExtensionNames.normalize(decl, isGLFunction);
+ String renamed = GLNameResolver.normalize(decl, isGLFunction);
if (!renamed.equals(decl)) {
config.addJavaSymbolRename(decl, renamed);
}
@@ -181,7 +181,7 @@ public class GLEmitter extends ProcAddressEmitter {
String cause = null;
for (String decl : declarations) {
boolean isFunc = !decl.startsWith("GL_");
- if (!GLExtensionNames.isExtension(decl, isFunc)) {
+ if (!GLNameResolver.isExtension(decl, isFunc)) {
isExtension = false;
break;
}
@@ -199,7 +199,7 @@ public class GLEmitter extends ProcAddressEmitter {
}
}
cause = decl;
- String unifiedName = GLExtensionNames.normalize(decl, isFunc);
+ String unifiedName = GLNameResolver.normalize(decl, isFunc);
// NOTE that we look up the unified name in the
// BuildStaticGLInfo's notion of the APIs -- since
// we might not be emitting glue code for the
@@ -472,12 +472,12 @@ public class GLEmitter extends ProcAddressEmitter {
w.println(" * it was statically linked.");
w.println(" */");
w.println(" public long getAddressFor(String functionNameUsr) {");
- w.println(" String functionNameBase = "+GLExtensionNames.class.getName()+".normalizeVEN(com.jogamp.gluegen.runtime.opengl.GLExtensionNames.normalizeARB(functionNameUsr, true), true);");
+ w.println(" String functionNameBase = "+GLNameResolver.class.getName()+".normalizeVEN(com.jogamp.gluegen.runtime.opengl.GLNameResolver.normalizeARB(functionNameUsr, true), true);");
w.println(" String addressFieldNameBase = PROCADDRESS_VAR_PREFIX + functionNameBase;");
w.println(" java.lang.reflect.Field addressField = null;");
- w.println(" int funcNamePermNum = "+GLExtensionNames.class.getName()+".getFuncNamePermutationNumber(functionNameBase);");
+ w.println(" int funcNamePermNum = "+GLNameResolver.class.getName()+".getFuncNamePermutationNumber(functionNameBase);");
w.println(" for(int i = 0; null==addressField && i < funcNamePermNum; i++) {");
- w.println(" String addressFieldName = "+GLExtensionNames.class.getName()+".getFuncNamePermutation(addressFieldNameBase, i);");
+ w.println(" String addressFieldName = "+GLNameResolver.class.getName()+".getFuncNamePermutation(addressFieldNameBase, i);");
w.println(" try {");
w.println(" addressField = getClass().getField(addressFieldName);");
w.println(" } catch (Exception e) { }");
diff --git a/src/jogl/classes/com/jogamp/gluegen/runtime/opengl/GLExtensionNames.java b/src/jogl/classes/com/jogamp/gluegen/runtime/opengl/GLNameResolver.java
index 426333034..92554776a 100644
--- a/src/jogl/classes/com/jogamp/gluegen/runtime/opengl/GLExtensionNames.java
+++ b/src/jogl/classes/com/jogamp/gluegen/runtime/opengl/GLNameResolver.java
@@ -37,7 +37,8 @@
*/
package com.jogamp.gluegen.runtime.opengl;
-public class GLExtensionNames {
+/** Runtime utility identify and resolve extension names, which may be subsumed to core. */
+public class GLNameResolver {
//GL_XYZ : GL_XYZ, GL_XYZ_GL2, GL_XYZ_ARB, GL_XYZ_OES, GL_XYZ_OML
//GL_XYZ : GL_XYZ, GL_GL2_XYZ, GL_ARB_XYZ, GL_OES_XYZ, GL_OML_XYZ
//
diff --git a/src/jogl/classes/com/jogamp/gluegen/runtime/opengl/GLProcAddressResolver.java b/src/jogl/classes/com/jogamp/gluegen/runtime/opengl/GLProcAddressResolver.java
index fe9efebc7..9775de491 100644
--- a/src/jogl/classes/com/jogamp/gluegen/runtime/opengl/GLProcAddressResolver.java
+++ b/src/jogl/classes/com/jogamp/gluegen/runtime/opengl/GLProcAddressResolver.java
@@ -45,10 +45,10 @@ public class GLProcAddressResolver implements FunctionAddressResolver {
public long resolve(String name, DynamicLookupHelper lookup) {
long newProcAddress = 0;
- int permutations = GLExtensionNames.getFuncNamePermutationNumber(name);
+ int permutations = GLNameResolver.getFuncNamePermutationNumber(name);
for (int i = 0; 0 == newProcAddress && i < permutations; i++) {
- String funcName = GLExtensionNames.getFuncNamePermutation(name, i);
+ String funcName = GLNameResolver.getFuncNamePermutation(name, i);
try {
newProcAddress = lookup.dynamicLookupFunction(funcName);
} catch (Exception e) {
diff --git a/src/jogl/classes/com/jogamp/opengl/FBObject.java b/src/jogl/classes/com/jogamp/opengl/FBObject.java
new file mode 100644
index 000000000..644d87b1a
--- /dev/null
+++ b/src/jogl/classes/com/jogamp/opengl/FBObject.java
@@ -0,0 +1,1943 @@
+/**
+ * Copyright 2012 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2GL3;
+import javax.media.opengl.GL3;
+import javax.media.opengl.GLBase;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLException;
+import javax.media.opengl.GLProfile;
+
+import jogamp.opengl.Debug;
+
+import com.jogamp.opengl.FBObject.Attachment.Type;
+
+/**
+ * Core utility class simplifying usage of framebuffer objects (FBO)
+ * with all {@link GLProfile}s.
+ * <p>
+ * Supports on-the-fly reconfiguration of dimension and multisample buffers via {@link #reset(GL, int, int, int)}
+ * while preserving the {@link Attachment} references.
+ * </p>
+ * <p>
+ * Integrates default read/write framebuffers via {@link GLContext#getDefaultReadFramebuffer()} and {@link GLContext#getDefaultReadFramebuffer()},
+ * which is being hooked at {@link GL#glBindFramebuffer(int, int)} when the default (<code>zero</code>) framebuffer is selected.
+ * </p>
+ *
+ * <p>FIXME: Implement support for {@link Type#DEPTH_TEXTURE}, {@link Type#STENCIL_TEXTURE} .</p>
+ */
+public class FBObject {
+ protected static final boolean DEBUG = Debug.debug("FBObject");
+
+ /**
+ * Returns <code>true</code> if basic FBO support is available, otherwise <code>false</code>.
+ * <p>
+ * Basic FBO is supported if the context is either GL-ES >= 2.0, GL >= core 3.0 or implements the extensions
+ * <code>ARB_ES2_compatibility</code>, <code>ARB_framebuffer_object</code>, <code>EXT_framebuffer_object</code> or <code>OES_framebuffer_object</code>.
+ * </p>
+ * <p>
+ * Basic FBO support may only include one color attachment and no multisampling,
+ * as well as limited internal formats for renderbuffer.
+ * </p>
+ * @see GLContext#hasFBO()
+ */
+ public static final boolean supportsBasicFBO(GL gl) {
+ return gl.getContext().hasFBO();
+ }
+
+ /**
+ * Returns <code>true</code> if full FBO support is available, otherwise <code>false</code>.
+ * <p>
+ * Full FBO is supported if the context is either GL >= core 3.0 or implements the extensions
+ * <code>ARB_framebuffer_object</code>, or all of
+ * <code>EXT_framebuffer_object</code>, <code>EXT_framebuffer_multisample</code>,
+ * <code>EXT_framebuffer_blit</code>, <code>GL_EXT_packed_depth_stencil</code>.
+ * </p>
+ * <p>
+ * Full FBO support includes multiple color attachments and multisampling.
+ * </p>
+ */
+ public static final boolean supportsFullFBO(GL gl) {
+ return gl.isGL3() || // GL >= 3.0
+
+ gl.isExtensionAvailable(GLExtensions.ARB_framebuffer_object) || // ARB_framebuffer_object
+
+ ( gl.isExtensionAvailable(GLExtensions.EXT_framebuffer_object) && // All EXT_framebuffer_object*
+ gl.isExtensionAvailable(GLExtensions.EXT_framebuffer_multisample) &&
+ gl.isExtensionAvailable(GLExtensions.EXT_framebuffer_blit) &&
+ gl.isExtensionAvailable(GLExtensions.EXT_packed_depth_stencil) ) ;
+ }
+
+ public static final int getMaxSamples(GL gl) {
+ if( supportsFullFBO(gl) ) {
+ int[] val = new int[] { 0 } ;
+ gl.glGetIntegerv(GL2GL3.GL_MAX_SAMPLES, val, 0);
+ return val[0];
+ } else {
+ return 0;
+ }
+ }
+
+ /** Common super class of all attachments */
+ public static abstract class Attachment {
+ public enum Type {
+ NONE, DEPTH, STENCIL, DEPTH_STENCIL, COLOR, COLOR_TEXTURE, DEPTH_TEXTURE, STENCIL_TEXTURE;
+
+ /**
+ * Returns {@link #COLOR}, {@link #DEPTH}, {@link #STENCIL} or {@link #DEPTH_STENCIL}
+ * @throws IllegalArgumentException if <code>format</code> cannot be handled.
+ */
+ public static Type determine(int format) throws IllegalArgumentException {
+ switch(format) {
+ case GL.GL_RGBA4:
+ case GL.GL_RGB5_A1:
+ case GL.GL_RGB565:
+ case GL.GL_RGB8:
+ case GL.GL_RGBA8:
+ return Type.COLOR;
+ case GL.GL_DEPTH_COMPONENT16:
+ case GL.GL_DEPTH_COMPONENT24:
+ case GL.GL_DEPTH_COMPONENT32:
+ return Type.DEPTH;
+ case GL.GL_STENCIL_INDEX1:
+ case GL.GL_STENCIL_INDEX4:
+ case GL.GL_STENCIL_INDEX8:
+ return Type.STENCIL;
+ case GL.GL_DEPTH24_STENCIL8:
+ return Type.DEPTH_STENCIL;
+ default:
+ throw new IllegalArgumentException("format invalid: 0x"+Integer.toHexString(format));
+ }
+ }
+ };
+
+ /** immutable type [{@link #COLOR}, {@link #DEPTH}, {@link #STENCIL}, {@link #COLOR_TEXTURE}, {@link #DEPTH_TEXTURE}, {@link #STENCIL_TEXTURE} ] */
+ public final Type type;
+
+ /** immutable the internal format */
+ public final int format;
+
+ private int width, height;
+
+ private int name;
+
+ /** <code>true</code> if resource is initialized by {@link #initialize(GL)}, hence {@link #free(GL)} is allowed to free the GL resources. */
+ protected boolean resourceOwner;
+
+ private int initCounter;
+
+ protected Attachment(Type type, int iFormat, int width, int height, int name) {
+ this.type = type;
+ this.format = iFormat;
+ this.width = width;
+ this.height = height;
+ this.name = name;
+ this.resourceOwner = false;
+ this.initCounter = 0;
+ }
+
+ /** width of attachment */
+ public final int getWidth() { return width; }
+ /** height of attachment */
+ public final int getHeight() { return height; }
+ /* pp */ final void setSize(int w, int h) { width = w; height = h; }
+
+ /** buffer name [1..max], maybe a texture or renderbuffer name, depending on type. */
+ public final int getName() { return name; }
+ /* pp */ final void setName(int n) { name = n; }
+
+ public final int getInitCounter() { return initCounter; }
+
+ /**
+ * Initializes the attachment buffer and set it's parameter, if uninitialized, i.e. name is <code>zero</code>.
+ * <p>Implementation employs an initialization counter, hence it can be paired recursively with {@link #free(GL)}.</p>
+ * @throws GLException if buffer generation or setup fails. The just created buffer name will be deleted in this case.
+ */
+ public void initialize(GL gl) throws GLException {
+ initCounter++;
+ /*
+ super.initialize(gl);
+ if(1 == getInitCounter() && 0 == getName() ) {
+ do init ..
+ freeResources = true; // if all OK
+ }
+ */
+ }
+
+ /**
+ * Releases the attachment buffer if initialized, i.e. name is <code>zero</code>.
+ * <p>Implementation employs an initialization counter, hence it can be paired recursively with {@link #initialize(GL)}.</p>
+ * @throws GLException if buffer release fails.
+ */
+ public void free(GL gl) throws GLException {
+ /*
+ if(1 == getInitCounter() && freeResources && .. ) {
+ do free ..
+ }
+ super.free(gl);
+ */
+ initCounter--;
+ if(0 == initCounter) {
+ resourceOwner = false;
+ name = 0;
+ }
+ if(DEBUG) {
+ System.err.println("Attachment.free: "+this);
+ }
+ }
+
+ /**
+ * <p>
+ * Comparison by {@link #type}, {@link #format}, {@link #width}, {@link #height} and {@link #name}.
+ * </p>
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object o) {
+ if( this == o ) return true;
+ if( ! ( o instanceof Attachment ) ) return false;
+ final Attachment a = (Attachment)o;
+ return type == a.type &&
+ format == a.format ||
+ width == a.width ||
+ height== a.height ||
+ name == a.name ;
+ }
+
+ /**
+ * <p>
+ * Hashed by {@link #type}, {@link #format}, {@link #width}, {@link #height} and {@link #name}.
+ * </p>
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ // 31 * x == (x << 5) - x
+ int hash = 31 + type.ordinal();
+ hash = ((hash << 5) - hash) + format;
+ hash = ((hash << 5) - hash) + width;
+ hash = ((hash << 5) - hash) + height;
+ hash = ((hash << 5) - hash) + name;
+ return hash;
+ }
+
+ int objectHashCode() { return super.hashCode(); }
+
+ public String toString() {
+ return getClass().getSimpleName()+"[type "+type+", format 0x"+Integer.toHexString(format)+", "+width+"x"+height+
+ ", name 0x"+Integer.toHexString(name)+", obj 0x"+Integer.toHexString(objectHashCode())+
+ ", resOwner "+resourceOwner+", initCount "+initCounter+"]";
+ }
+
+ public static Type getType(int attachmentPoint, int maxColorAttachments) {
+ if( GL.GL_COLOR_ATTACHMENT0 <= attachmentPoint && attachmentPoint < GL.GL_COLOR_ATTACHMENT0+maxColorAttachments ) {
+ return Type.COLOR;
+ }
+ switch(attachmentPoint) {
+ case GL.GL_DEPTH_ATTACHMENT:
+ return Type.DEPTH;
+ case GL.GL_STENCIL_ATTACHMENT:
+ return Type.STENCIL;
+ default:
+ throw new IllegalArgumentException("Invalid attachment point 0x"+Integer.toHexString(attachmentPoint));
+ }
+ }
+ }
+
+ /** Other renderbuffer attachment which maybe a colorbuffer, depth or stencil. */
+ public static class RenderAttachment extends Attachment {
+ private int samples;
+
+ /**
+ * @param type allowed types are {@link Type#DEPTH}, {@link Type#STENCIL} or {@link Type#COLOR}
+ * @param iFormat
+ * @param samples
+ * @param width
+ * @param height
+ * @param name
+ */
+ public RenderAttachment(Type type, int iFormat, int samples, int width, int height, int name) {
+ super(validateType(type), iFormat, width, height, name);
+ this.samples = samples;
+ }
+
+ /** number of samples, or zero for no multisampling */
+ public final int getSamples() { return samples; }
+ /* pp */ final void setSamples(int s) { samples = s; }
+
+ private static Type validateType(Type type) {
+ switch(type) {
+ case DEPTH:
+ case STENCIL:
+ case COLOR:
+ return type;
+ default:
+ throw new IllegalArgumentException("Invalid type: "+type);
+ }
+ }
+
+ /**
+ * <p>
+ * Comparison by {@link #type}, {@link #format}, {@link #samples}, {@link #width}, {@link #height} and {@link #name}.
+ * </p>
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean equals(Object o) {
+ if( this == o ) return true;
+ if( ! ( o instanceof RenderAttachment ) ) return false;
+ return super.equals(o) &&
+ samples == ((RenderAttachment)o).samples;
+ }
+
+ /**
+ * <p>
+ * Hashed by {@link #type}, {@link #format}, {@link #samples}, {@link #width}, {@link #height} and {@link #name}.
+ * </p>
+ * {@inheritDoc}
+ */
+ @Override
+ public int hashCode() {
+ // 31 * x == (x << 5) - x
+ int hash = super.hashCode();
+ hash = ((hash << 5) - hash) + samples;
+ return hash;
+ }
+
+ @Override
+ public void initialize(GL gl) throws GLException {
+ super.initialize(gl);
+ if( 1 == getInitCounter() && 0 == getName() ) {
+ final int[] name = new int[] { -1 };
+ gl.glGenRenderbuffers(1, name, 0);
+ if( 0 == name[0] ) {
+ throw new GLException("null renderbuffer, "+this);
+ }
+ setName(name[0]);
+
+ gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, getName());
+ if( samples > 0 ) {
+ ((GL2GL3)gl).glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, samples, format, getWidth(), getHeight());
+ } else {
+ gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, format, getWidth(), getHeight());
+ }
+ int glerr = gl.glGetError();
+ if(GL.GL_NO_ERROR != glerr) {
+ gl.glDeleteRenderbuffers(1, name, 0);
+ setName(0);
+ throw new GLException("GL Error 0x"+Integer.toHexString(glerr)+" while creating "+this);
+ }
+ resourceOwner = true;
+ if(DEBUG) {
+ System.err.println("Attachment.init: "+this);
+ }
+ }
+ }
+
+ @Override
+ public void free(GL gl) {
+ if(1 == getInitCounter() && resourceOwner && 0 != getName() ) {
+ final int[] name = new int[] { getName() };
+ gl.glDeleteRenderbuffers(1, name, 0);
+ }
+ super.free(gl);
+ }
+
+ public String toString() {
+ return getClass().getSimpleName()+"[type "+type+", format 0x"+Integer.toHexString(format)+", samples "+samples+", "+getWidth()+"x"+getHeight()+
+ ", name 0x"+Integer.toHexString(getName())+", obj 0x"+Integer.toHexString(objectHashCode())+
+ ", resOwner "+resourceOwner+", initCount "+getInitCounter()+"]";
+ }
+ }
+
+ /**
+ * Marker interface, denotes a color buffer attachment.
+ * <p>Always an instance of {@link Attachment}.</p>
+ * <p>Either an instance of {@link ColorAttachment} or {@link TextureAttachment}.</b>
+ */
+ public static interface Colorbuffer {
+ }
+
+ /** Color render buffer attachment */
+ public static class ColorAttachment extends RenderAttachment implements Colorbuffer {
+ public ColorAttachment(int iFormat, int samples, int width, int height, int name) {
+ super(Type.COLOR, iFormat, samples, width, height, name);
+ }
+ }
+
+ /** Texture attachment */
+ public static class TextureAttachment extends Attachment implements Colorbuffer {
+ /** details of the texture setup */
+ public final int dataFormat, dataType, magFilter, minFilter, wrapS, wrapT;
+
+ /**
+ * @param type allowed types are [ {@link Type#COLOR_TEXTURE}, {@link Type#DEPTH_TEXTURE}, {@link Type#STENCIL_TEXTURE} ]
+ * @param iFormat
+ * @param width
+ * @param height
+ * @param dataFormat
+ * @param dataType
+ * @param magFilter
+ * @param minFilter
+ * @param wrapS
+ * @param wrapT
+ * @param name
+ */
+ public TextureAttachment(Type type, int iFormat, int width, int height, int dataFormat, int dataType,
+ int magFilter, int minFilter, int wrapS, int wrapT, int name) {
+ super(validateType(type), iFormat, width, height, name);
+ this.dataFormat = dataFormat;
+ this.dataType = dataType;
+ this.magFilter = magFilter;
+ this.minFilter = minFilter;
+ this.wrapS = wrapS;
+ this.wrapT = wrapT;
+ }
+
+ private static Type validateType(Type type) {
+ switch(type) {
+ case COLOR_TEXTURE:
+ case DEPTH_TEXTURE:
+ case STENCIL_TEXTURE:
+ return type;
+ default:
+ throw new IllegalArgumentException("Invalid type: "+type);
+ }
+ }
+
+ /**
+ * Initializes the texture and set it's parameter, if uninitialized, i.e. name is <code>zero</code>.
+ * @throws GLException if texture generation and setup fails. The just created texture name will be deleted in this case.
+ */
+ @Override
+ public void initialize(GL gl) throws GLException {
+ super.initialize(gl);
+ if( 1 == getInitCounter() && 0 == getName() ) {
+ final int[] name = new int[] { -1 };
+ gl.glGenTextures(1, name, 0);
+ if(0 == name[0]) {
+ throw new GLException("null texture, "+this);
+ }
+ setName(name[0]);
+
+ gl.glBindTexture(GL.GL_TEXTURE_2D, name[0]);
+ gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, format, getWidth(), getHeight(), 0, dataFormat, dataType, null);
+ if( 0 < magFilter ) {
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, magFilter);
+ }
+ if( 0 < minFilter ) {
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, minFilter);
+ }
+ if( 0 < wrapS ) {
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, wrapS);
+ }
+ if( 0 < wrapT ) {
+ gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, wrapT);
+ }
+ int glerr = gl.glGetError();
+ if(GL.GL_NO_ERROR != glerr) {
+ gl.glDeleteTextures(1, name, 0);
+ setName(0);
+ throw new GLException("GL Error 0x"+Integer.toHexString(glerr)+" while creating "+this);
+ }
+ resourceOwner = true;
+ }
+ if(DEBUG) {
+ System.err.println("Attachment.init: "+this);
+ }
+ }
+
+ @Override
+ public void free(GL gl) {
+ if(1 == getInitCounter() && resourceOwner && 0 != getName() ) {
+ final int[] name = new int[] { getName() };
+ gl.glDeleteTextures(1, name, 0);
+ }
+ super.free(gl);
+ }
+ }
+
+ private boolean initialized;
+ private boolean basicFBOSupport;
+ private boolean fullFBOSupport;
+ private boolean rgba8Avail;
+ private boolean depth24Avail;
+ private boolean depth32Avail;
+ private boolean stencil01Avail;
+ private boolean stencil04Avail;
+ private boolean stencil08Avail;
+ private boolean stencil16Avail;
+ private boolean packedDepthStencilAvail;
+ private int maxColorAttachments, maxSamples, maxTextureSize, maxRenderbufferSize;
+
+ private int width, height, samples;
+ private int vStatus;
+ private int fbName;
+ private boolean bound;
+
+ private int colorAttachmentCount;
+ private Colorbuffer[] colorAttachmentPoints; // colorbuffer attachment points
+ private RenderAttachment depth, stencil; // depth and stencil maybe equal in case of packed-depth-stencil
+
+ private final FBObject samplesSink; // MSAA sink
+ private TextureAttachment samplesSinkTexture;
+ private boolean samplesSinkDirty;
+
+ //
+ // ColorAttachment helper ..
+ //
+
+ private final void validateColorAttachmentPointRange(int point) {
+ if(maxColorAttachments != colorAttachmentPoints.length) {
+ throw new InternalError("maxColorAttachments "+maxColorAttachments+", array.lenght "+colorAttachmentPoints);
+ }
+ if(0 > point || point >= maxColorAttachments) {
+ throw new IllegalArgumentException("attachment point out of range: "+point+", should be within [0.."+(maxColorAttachments-1)+"]");
+ }
+ }
+
+ private final void validateAddColorAttachment(int point, Colorbuffer ca) {
+ validateColorAttachmentPointRange(point);
+ if( null != colorAttachmentPoints[point] ) {
+ throw new IllegalArgumentException("Cannot attach "+ca+", attachment point already in use by "+colorAttachmentPoints[point]);
+ }
+ }
+
+ private final void addColorAttachment(int point, Colorbuffer ca) {
+ validateColorAttachmentPointRange(point);
+ final Colorbuffer c = colorAttachmentPoints[point];
+ if( null != c && c != ca ) {
+ throw new IllegalArgumentException("Add failed: requested to add "+ca+" at "+point+", but slot is holding "+c+"; "+this);
+ }
+ colorAttachmentPoints[point] = ca;
+ colorAttachmentCount++;
+ }
+
+ private final void removeColorAttachment(int point, Colorbuffer ca) {
+ validateColorAttachmentPointRange(point);
+ final Colorbuffer c = colorAttachmentPoints[point];
+ if( null != c && c != ca ) {
+ throw new IllegalArgumentException("Remove failed: requested to removed "+ca+" at "+point+", but slot is holding "+c+"; "+this);
+ }
+ colorAttachmentPoints[point] = null;
+ colorAttachmentCount--;
+ }
+
+ /**
+ * Return the {@link Colorbuffer} attachment at <code>attachmentPoint</code> if it is attached to this FBO, otherwise null.
+ *
+ * @see #attachColorbuffer(GL, boolean)
+ * @see #attachColorbuffer(GL, boolean)
+ * @see #attachTexture2D(GL, int, boolean, int, int, int, int)
+ * @see #attachTexture2D(GL, int, int, int, int, int, int, int, int)
+ */
+ public final Colorbuffer getColorbuffer(int attachmentPoint) {
+ validateColorAttachmentPointRange(attachmentPoint);
+ return colorAttachmentPoints[attachmentPoint];
+ }
+
+ /**
+ * Finds the passed {@link Colorbuffer} within the valid range of attachment points
+ * using <i>reference</i> comparison only.
+ * <p>
+ * Note: Slow. Implementation uses a logN array search to save resources, i.e. not using a HashMap.
+ * </p>
+ * @param ca the {@link Colorbuffer} to look for.
+ * @return -1 if the {@link Colorbuffer} could not be found, otherwise [0..{@link #getMaxColorAttachments()}-1]
+ */
+ public final int getColorbufferAttachmentPoint(Colorbuffer ca) {
+ for(int i=0; i<colorAttachmentPoints.length; i++) {
+ if( colorAttachmentPoints[i] == ca ) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * Returns the passed {@link Colorbuffer} if it is attached to this FBO, otherwise null.
+ * Implementation compares the <i>reference</i> only.
+ *
+ * <p>
+ * Note: Slow. Uses {@link #getColorbufferAttachmentPoint(Colorbuffer)} to determine it's attachment point
+ * to be used for {@link #getColorbuffer(int)}
+ * </p>
+ *
+ * @see #attachColorbuffer(GL, boolean)
+ * @see #attachColorbuffer(GL, boolean)
+ * @see #attachTexture2D(GL, int, boolean, int, int, int, int)
+ * @see #attachTexture2D(GL, int, int, int, int, int, int, int, int)
+ */
+ public final Colorbuffer getColorbuffer(Colorbuffer ca) {
+ final int p = getColorbufferAttachmentPoint(ca);
+ return p>=0 ? getColorbuffer(p) : null;
+ }
+
+ /**
+ * Creates an uninitialized FBObject instance.
+ * <p>
+ * Call {@link #init(GL, int, int, int)} .. etc to use it.
+ * </p>
+ */
+ public FBObject() {
+ this(false);
+ }
+ /* pp */ FBObject(boolean isSampleSink) {
+ this.initialized = false;
+
+ // TBD @ init
+ this.basicFBOSupport = false;
+ this.fullFBOSupport = false;
+ this.rgba8Avail = false;
+ this.depth24Avail = false;
+ this.depth32Avail = false;
+ this.stencil01Avail = false;
+ this.stencil04Avail = false;
+ this.stencil08Avail = false;
+ this.stencil16Avail = false;
+ this.packedDepthStencilAvail = false;
+ this.maxColorAttachments=-1;
+ this.maxSamples=-1;
+ this.maxTextureSize = 0;
+ this.maxRenderbufferSize = 0;
+
+ this.width = 0;
+ this.height = 0;
+ this.samples = 0;
+ this.vStatus = -1;
+ this.fbName = 0;
+ this.bound = false;
+
+ this.colorAttachmentPoints = null; // at init ..
+ this.colorAttachmentCount = 0;
+ this.depth = null;
+ this.stencil = null;
+
+ this.samplesSink = isSampleSink ? null : new FBObject(true);
+ this.samplesSinkTexture = null;
+ this.samplesSinkDirty = true;
+ }
+
+ private void init(GL gl, int width, int height, int samples) throws GLException {
+ if(initialized) {
+ throw new GLException("FBO already initialized");
+ }
+ fullFBOSupport = supportsFullFBO(gl);
+
+ if( !fullFBOSupport && !supportsBasicFBO(gl) ) {
+ throw new GLException("FBO not supported w/ context: "+gl.getContext()+", "+this);
+ }
+
+ basicFBOSupport = true;
+
+ rgba8Avail = gl.isGL2GL3() || gl.isExtensionAvailable(GLExtensions.OES_rgb8_rgba8);
+ depth24Avail = fullFBOSupport || gl.isExtensionAvailable(GLExtensions.OES_depth24);
+ depth32Avail = fullFBOSupport || gl.isExtensionAvailable(GLExtensions.OES_depth32);
+ stencil01Avail = fullFBOSupport || gl.isExtensionAvailable(GLExtensions.OES_stencil1);
+ stencil04Avail = fullFBOSupport || gl.isExtensionAvailable(GLExtensions.OES_stencil4);
+ stencil08Avail = fullFBOSupport || gl.isExtensionAvailable(GLExtensions.OES_stencil8);
+ stencil16Avail = fullFBOSupport;
+
+ packedDepthStencilAvail = fullFBOSupport || gl.isExtensionAvailable(GLExtensions.OES_packed_depth_stencil);
+
+ final boolean NV_fbo_color_attachments = gl.isExtensionAvailable(GLExtensions.NV_fbo_color_attachments);
+
+ int val[] = new int[1];
+
+ int glerr = gl.glGetError();
+ if(DEBUG && GL.GL_NO_ERROR != glerr) {
+ System.err.println("FBObject.init-preexisting.0 GL Error 0x"+Integer.toHexString(glerr));
+ }
+
+ int realMaxColorAttachments = 1;
+ maxColorAttachments = 1;
+ if( null != samplesSink && fullFBOSupport || NV_fbo_color_attachments ) {
+ try {
+ gl.glGetIntegerv(GL2GL3.GL_MAX_COLOR_ATTACHMENTS, val, 0);
+ glerr = gl.glGetError();
+ if(GL.GL_NO_ERROR == glerr) {
+ realMaxColorAttachments = 1 <= val[0] ? val[0] : 1; // cap minimum to 1
+ } else if(DEBUG) {
+ System.err.println("FBObject.init-GL_MAX_COLOR_ATTACHMENTS query GL Error 0x"+Integer.toHexString(glerr));
+ }
+ } catch (GLException gle) {}
+ }
+ maxColorAttachments = realMaxColorAttachments <= 8 ? realMaxColorAttachments : 8; // cap to limit array size
+
+ colorAttachmentPoints = new Colorbuffer[maxColorAttachments];
+ colorAttachmentCount = 0;
+
+ maxSamples = 0;
+ if(fullFBOSupport) {
+ gl.glGetIntegerv(GL2GL3.GL_MAX_SAMPLES, val, 0);
+ glerr = gl.glGetError();
+ if(GL.GL_NO_ERROR == glerr) {
+ maxSamples = val[0];
+ } else if(DEBUG) {
+ System.err.println("FBObject.init-GL_MAX_SAMPLES query GL Error 0x"+Integer.toHexString(glerr));
+ }
+ }
+ gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, val, 0);
+ maxTextureSize = val[0];
+ gl.glGetIntegerv(GL.GL_MAX_RENDERBUFFER_SIZE, val, 0);
+ this.maxRenderbufferSize = val[0];
+
+ glerr = gl.glGetError();
+ if(DEBUG && GL.GL_NO_ERROR != glerr) {
+ System.err.println("FBObject.init-preexisting.1 GL Error 0x"+Integer.toHexString(glerr));
+ }
+
+ this.width = width;
+ this.height = height;
+ this.samples = samples <= maxSamples ? samples : maxSamples;
+
+ if(DEBUG) {
+ System.err.println("FBObject "+width+"x"+height+", "+samples+" -> "+samples+" samples");
+ System.err.println("basicFBOSupport: "+basicFBOSupport);
+ System.err.println("fullFBOSupport: "+fullFBOSupport);
+ System.err.println("maxColorAttachments: "+maxColorAttachments+"/"+realMaxColorAttachments);
+ System.err.println("maxSamples: "+maxSamples);
+ System.err.println("maxTextureSize: "+maxTextureSize);
+ System.err.println("maxRenderbufferSize: "+maxRenderbufferSize);
+ System.err.println("rgba8: "+rgba8Avail);
+ System.err.println("depth24: "+depth24Avail);
+ System.err.println("depth32: "+depth32Avail);
+ System.err.println("stencil01: "+stencil01Avail);
+ System.err.println("stencil04: "+stencil04Avail);
+ System.err.println("stencil08: "+stencil08Avail);
+ System.err.println("stencil16: "+stencil16Avail);
+ System.err.println("packedDepthStencil: "+packedDepthStencilAvail);
+ System.err.println("NV_fbo_color_attachments: "+NV_fbo_color_attachments);
+ System.err.println(gl.getContext().getGLVersion());
+ System.err.println(JoglVersion.getGLStrings(gl, null).toString());
+ System.err.println(gl.getContext());
+ }
+
+ checkNoError(null, gl.glGetError(), "FBObject Init.pre"); // throws GLException if error
+
+ if(width > 2 + maxTextureSize || height> 2 + maxTextureSize ||
+ width > maxRenderbufferSize || height> maxRenderbufferSize ) {
+ throw new GLException("size "+width+"x"+height+" exceeds on of the maxima [texture "+maxTextureSize+", renderbuffer "+maxRenderbufferSize+"]");
+ }
+
+ if(null != samplesSink) {
+ // init sampling sink
+ samplesSink.reset(gl, width, height);
+ resetMSAATexture2DSink(gl);
+ }
+
+ // generate fbo ..
+ gl.glGenFramebuffers(1, val, 0);
+ fbName = val[0];
+ if(0 == fbName) {
+ throw new GLException("null framebuffer");
+ }
+
+ // bind fbo ..
+ gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, fbName);
+ checkNoError(gl, gl.glGetError(), "FBObject Init.bindFB"); // throws GLException if error
+ if(!gl.glIsFramebuffer(fbName)) {
+ checkNoError(gl, GL.GL_INVALID_VALUE, "FBObject Init.isFB"); // throws GLException
+ }
+ bound = true;
+ initialized = true;
+
+ updateStatus(gl);
+ if(DEBUG) {
+ System.err.println("FBObject.init(): "+this);
+ }
+ }
+
+ /**
+ * Initializes or resets this FBO's instance.
+ * <p>
+ * In case the new parameters are compatible with the current ones
+ * no action will be performed. Otherwise all attachments will be recreated
+ * to match the new given parameters.
+ * </p>
+ * <p>
+ * Currently incompatibility and hence recreation is given if
+ * the size or sample count doesn't match for subsequent calls.
+ * </p>
+ *
+ * <p>Leaves the FBO bound state untouched</p>
+ *
+ * @param gl the current GL context
+ * @param newWidth
+ * @param newHeight
+ * @throws GLException in case of an error
+ */
+ public final void reset(GL gl, int newWidth, int newHeight) {
+ reset(gl, newWidth, newHeight, 0);
+ }
+
+ /**
+ * Initializes or resets this FBO's instance.
+ * <p>
+ * In case the new parameters are compatible with the current ones
+ * no action will be performed. Otherwise all attachments will be recreated
+ * to match the new given parameters.
+ * </p>
+ * <p>
+ * Currently incompatibility and hence recreation is given if
+ * the size or sample count doesn't match for subsequent calls.
+ * </p>
+ *
+ * <p>Leaves the FBO bound state untouched</p>
+ *
+ * @param gl the current GL context
+ * @param newWidth
+ * @param newHeight
+ * @param newSamples if > 0, MSAA will be used, otherwise no multisampling. Will be capped to {@link #getMaxSamples()}.
+ * @throws GLException in case of an error
+ */
+ public final void reset(GL gl, int newWidth, int newHeight, int newSamples) {
+ if(!initialized) {
+ init(gl, newWidth, newHeight, newSamples);
+ return;
+ }
+ newSamples = newSamples <= maxSamples ? newSamples : maxSamples; // clamp
+
+ if( newWidth != width || newHeight != height || newSamples != samples ) {
+ if(DEBUG) {
+ System.err.println("FBObject.reset - START - "+this);
+ }
+
+ final boolean wasBound = isBound();
+
+ width = newWidth;
+ height = newHeight;
+ samples = newSamples;
+ detachAllImpl(gl, true , true);
+ resetMSAATexture2DSink(gl);
+
+ if(wasBound) {
+ bind(gl);
+ } else {
+ unbind(gl);
+ }
+
+ if(DEBUG) {
+ System.err.println("FBObject.reset - END - "+this);
+ }
+ }
+ }
+
+ /**
+ * Note that the status may reflect an incomplete state during transition of attachments.
+ * @return The FB status. {@link GL.GL_FRAMEBUFFER_COMPLETE} if ok, otherwise return GL FBO error state or -1
+ * @see #validateStatus()
+ */
+ public final int getStatus() {
+ return vStatus;
+ }
+
+ /** return the {@link #getStatus()} as a string. */
+ public final String getStatusString() {
+ return getStatusString(vStatus);
+ }
+
+ public static final String getStatusString(int fbStatus) {
+ switch(fbStatus) {
+ case -1:
+ return "NOT A FBO";
+
+ case GL.GL_FRAMEBUFFER_COMPLETE:
+ return "OK";
+
+ case GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
+ return("GL FBO: incomplete, incomplete attachment\n");
+ case GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
+ return("GL FBO: incomplete, missing attachment");
+ case GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
+ return("GL FBO: incomplete, attached images must have same dimensions");
+ case GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS:
+ return("GL FBO: incomplete, attached images must have same format");
+ case GL2GL3.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
+ return("GL FBO: incomplete, missing draw buffer");
+ case GL2GL3.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
+ return("GL FBO: incomplete, missing read buffer");
+ case GL2GL3.GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
+ return("GL FBO: incomplete, missing multisample buffer");
+ case GL3.GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:
+ return("GL FBO: incomplete, layer targets");
+
+ case GL.GL_FRAMEBUFFER_UNSUPPORTED:
+ return("GL FBO: Unsupported framebuffer format");
+ case GL2GL3.GL_FRAMEBUFFER_UNDEFINED:
+ return("GL FBO: framebuffer undefined");
+
+ case 0:
+ return("GL FBO: incomplete, implementation fault");
+ default:
+ return("GL FBO: incomplete, implementation ERROR 0x"+Integer.toHexString(fbStatus));
+ }
+ }
+
+ /**
+ * The status may even be valid if incomplete during transition of attachments.
+ * @see #getStatus()
+ */
+ public final boolean isStatusValid() {
+ switch(vStatus) {
+ case GL.GL_FRAMEBUFFER_COMPLETE:
+ return true;
+
+ case GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
+ case GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
+ case GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
+ case GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS:
+ case GL2GL3.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
+ case GL2GL3.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
+ case GL2GL3.GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
+ case GL3.GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS:
+ if(0 == colorAttachmentCount || null == depth) {
+ // we are in transition
+ return true;
+ }
+
+ case GL.GL_FRAMEBUFFER_UNSUPPORTED:
+ case GL2GL3.GL_FRAMEBUFFER_UNDEFINED:
+
+ case 0:
+ default:
+ System.out.println("Framebuffer " + fbName + " is incomplete: status = 0x" + Integer.toHexString(vStatus) +
+ " : " + getStatusString(vStatus));
+ return false;
+ }
+ }
+
+ private final boolean checkNoError(GL gl, int err, String exceptionMessage) throws GLException {
+ if(GL.GL_NO_ERROR != err) {
+ if(null != gl) {
+ destroy(gl);
+ }
+ if(null != exceptionMessage) {
+ throw new GLException(exceptionMessage+" GL Error 0x"+Integer.toHexString(err));
+ }
+ return false;
+ }
+ return true;
+ }
+
+ private final void checkInitialized() throws GLException {
+ if(!initialized) {
+ throw new GLException("FBO not initialized, call init(GL) first.");
+ }
+ }
+
+ /**
+ * Attaches a Texture2D Color Buffer to this FBO's instance at the given attachment point,
+ * selecting the texture data type and format automatically.
+ *
+ * <p>Using default min/mag filter {@link GL#GL_NEAREST} and default wrapS/wrapT {@link GL#GL_CLAMP_TO_EDGE}.</p>
+ *
+ * <p>Leaves the FBO bound.</p>
+ *
+ * @param gl the current GL context
+ * @param attachmentPoint the color attachment point ranging from [0..{@link #getMaxColorAttachments()}-1]
+ * @param alpha set to <code>true</code> if you request alpha channel, otherwise <code>false</code>;
+ * @return TextureAttachment instance describing the new attached texture colorbuffer if bound and configured successfully, otherwise GLException is thrown
+ * @throws GLException in case the texture colorbuffer couldn't be allocated or MSAA has been chosen
+ */
+ public final TextureAttachment attachTexture2D(GL gl, int attachmentPoint, boolean alpha) throws GLException {
+ return attachTexture2D(gl, attachmentPoint, alpha, GL.GL_NEAREST, GL.GL_NEAREST, GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE);
+ }
+
+ /**
+ * Attaches a Texture2D Color Buffer to this FBO's instance at the given attachment point,
+ * selecting the texture data type and format automatically.
+ *
+ * <p>Leaves the FBO bound.</p>
+ *
+ * @param gl the current GL context
+ * @param attachmentPoint the color attachment point ranging from [0..{@link #getMaxColorAttachments()}-1]
+ * @param alpha set to <code>true</code> if you request alpha channel, otherwise <code>false</code>;
+ * @param magFilter if > 0 value for {@link GL#GL_TEXTURE_MAG_FILTER}
+ * @param minFilter if > 0 value for {@link GL#GL_TEXTURE_MIN_FILTER}
+ * @param wrapS if > 0 value for {@link GL#GL_TEXTURE_WRAP_S}
+ * @param wrapT if > 0 value for {@link GL#GL_TEXTURE_WRAP_T}
+ * @return TextureAttachment instance describing the new attached texture colorbuffer if bound and configured successfully, otherwise GLException is thrown
+ * @throws GLException in case the texture colorbuffer couldn't be allocated or MSAA has been chosen
+ */
+ public final TextureAttachment attachTexture2D(GL gl, int attachmentPoint, boolean alpha, int magFilter, int minFilter, int wrapS, int wrapT) throws GLException {
+ final int textureInternalFormat, textureDataFormat, textureDataType;
+ if(gl.isGLES()) {
+ textureInternalFormat = alpha ? GL.GL_RGBA : GL.GL_RGB;
+ textureDataFormat = alpha ? GL.GL_RGBA : GL.GL_RGB;
+ textureDataType = GL.GL_UNSIGNED_BYTE;
+ } else {
+ textureInternalFormat = alpha ? GL.GL_RGBA8 : GL.GL_RGB8;
+ textureDataFormat = alpha ? GL.GL_BGRA : GL.GL_RGB;
+ textureDataType = alpha ? GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV : GL.GL_UNSIGNED_BYTE;
+ }
+ return attachTexture2D(gl, attachmentPoint, textureInternalFormat, textureDataFormat, textureDataType, magFilter, minFilter, wrapS, wrapT);
+ }
+
+ /**
+ * Attaches a Texture2D Color Buffer to this FBO's instance at the given attachment point.
+ *
+ * <p>Leaves the FBO bound.</p>
+ *
+ * @param gl the current GL context
+ * @param attachmentPoint the color attachment point ranging from [0..{@link #getMaxColorAttachments()}-1]
+ * @param internalFormat internalFormat parameter to {@link GL#glTexImage2D(int, int, int, int, int, int, int, int, long)}
+ * @param dataFormat format parameter to {@link GL#glTexImage2D(int, int, int, int, int, int, int, int, long)}
+ * @param dataType type parameter to {@link GL#glTexImage2D(int, int, int, int, int, int, int, int, long)}
+ * @param magFilter if > 0 value for {@link GL#GL_TEXTURE_MAG_FILTER}
+ * @param minFilter if > 0 value for {@link GL#GL_TEXTURE_MIN_FILTER}
+ * @param wrapS if > 0 value for {@link GL#GL_TEXTURE_WRAP_S}
+ * @param wrapT if > 0 value for {@link GL#GL_TEXTURE_WRAP_T}
+ * @return TextureAttachment instance describing the new attached texture colorbuffer if bound and configured successfully, otherwise GLException is thrown
+ * @throws GLException in case the texture colorbuffer couldn't be allocated or MSAA has been chosen
+ */
+ public final TextureAttachment attachTexture2D(GL gl, int attachmentPoint,
+ int internalFormat, int dataFormat, int dataType,
+ int magFilter, int minFilter, int wrapS, int wrapT) throws GLException {
+ return attachTexture2D(gl, attachmentPoint,
+ new TextureAttachment(Type.COLOR_TEXTURE, internalFormat, width, height, dataFormat, dataType,
+ magFilter, minFilter, wrapS, wrapT, 0 /* name */));
+ }
+
+ /**
+ * Attaches a Texture2D Color Buffer to this FBO's instance at the given attachment point.
+ *
+ * <p>
+ * In case the passed TextureAttachment <code>texA</code> is uninitialized, i.e. it's texture name is <code>zero</code>,
+ * a new texture name is generated and setup w/ the texture parameter.<br/>
+ * Otherwise, i.e. texture name is not <code>zero</code>, the passed TextureAttachment <code>texA</code> is
+ * considered complete and assumed matching this FBO requirement. A GL error may occur is the latter is untrue.
+ * </p>
+ *
+ * <p>Leaves the FBO bound.</p>
+ *
+ * @param gl the current GL context
+ * @param attachmentPoint the color attachment point ranging from [0..{@link #getMaxColorAttachments()}-1]
+ * @param texA the to be attached {@link TextureAttachment}. Maybe complete or uninitialized, see above.
+ * @return the passed TextureAttachment <code>texA</code> instance describing the new attached texture colorbuffer if bound and configured successfully, otherwise GLException is thrown
+ * @throws GLException in case the texture colorbuffer couldn't be allocated or MSAA has been chosen
+ */
+ public final TextureAttachment attachTexture2D(GL gl, int attachmentPoint, TextureAttachment texA) throws GLException {
+ validateAddColorAttachment(attachmentPoint, texA);
+
+ if(samples>0) {
+ removeColorAttachment(attachmentPoint, texA);
+ throw new GLException("Texture2D not supported w/ MSAA. If you have enabled MSAA with exisiting texture attachments, you may want to detach them via detachAllTexturebuffer(gl).");
+ }
+
+ texA.initialize(gl);
+ addColorAttachment(attachmentPoint, texA);
+
+ bind(gl);
+
+ // Set up the color buffer for use as a renderable texture:
+ gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER,
+ GL.GL_COLOR_ATTACHMENT0 + attachmentPoint,
+ GL.GL_TEXTURE_2D, texA.getName(), 0);
+ updateStatus(gl);
+
+ if(!isStatusValid()) {
+ detachColorbuffer(gl, attachmentPoint);
+ throw new GLException("attachTexture2D "+texA+" at "+attachmentPoint+" failed "+getStatusString()+", "+this);
+ }
+ if(DEBUG) {
+ System.err.println("FBObject.attachTexture2D: "+this);
+ }
+ return texA;
+ }
+
+ /**
+ * Attaches a Color Buffer to this FBO's instance at the given attachment point,
+ * selecting the format automatically.
+ *
+ * <p>Leaves the FBO bound.</p>
+ *
+ * @param gl the current GL context
+ * @param attachmentPoint the color attachment point ranging from [0..{@link #getMaxColorAttachments()}-1]
+ * @param alpha set to <code>true</code> if you request alpha channel, otherwise <code>false</code>;
+ * @return ColorAttachment instance describing the new attached colorbuffer if bound and configured successfully, otherwise GLException is thrown
+ * @throws GLException in case the colorbuffer couldn't be allocated
+ */
+ public final ColorAttachment attachColorbuffer(GL gl, int attachmentPoint, boolean alpha) throws GLException {
+ final int internalFormat;
+ if( rgba8Avail ) {
+ internalFormat = alpha ? GL.GL_RGBA8 : GL.GL_RGB8 ;
+ } else {
+ internalFormat = alpha ? GL.GL_RGBA4 : GL.GL_RGB565;
+ }
+ return attachColorbuffer(gl, attachmentPoint, internalFormat);
+ }
+
+ /**
+ * Attaches a Color Buffer to this FBO's instance at the given attachment point.
+ *
+ * <p>Leaves the FBO bound.</p>
+ *
+ * @param gl the current GL context
+ * @param attachmentPoint the color attachment point ranging from [0..{@link #getMaxColorAttachments()}-1]
+ * @param internalFormat usually {@link GL#GL_RGBA4}, {@link GL#GL_RGB5_A1}, {@link GL#GL_RGB565}, {@link GL#GL_RGB8} or {@link GL#GL_RGBA8}
+ * @return ColorAttachment instance describing the new attached colorbuffer if bound and configured successfully, otherwise GLException is thrown
+ * @throws GLException in case the colorbuffer couldn't be allocated
+ * @throws IllegalArgumentException if <code>internalFormat</code> doesn't reflect a colorbuffer
+ */
+ public final ColorAttachment attachColorbuffer(GL gl, int attachmentPoint, int internalFormat) throws GLException, IllegalArgumentException {
+ final Attachment.Type atype = Attachment.Type.determine(internalFormat);
+ if( Attachment.Type.COLOR != atype ) {
+ throw new IllegalArgumentException("colorformat invalid: 0x"+Integer.toHexString(internalFormat)+", "+this);
+ }
+
+ return attachColorbuffer(gl, attachmentPoint, new ColorAttachment(internalFormat, samples, width, height, 0));
+ }
+
+ /**
+ * Attaches a Color Buffer to this FBO's instance at the given attachment point.
+ *
+ * <p>Leaves the FBO bound.</p>
+ *
+ * @param gl
+ * @param attachmentPoint the color attachment point ranging from [0..{@link #getMaxColorAttachments()}-1]
+ * @param colA the template for the new {@link ColorAttachment}
+ * @return ColorAttachment instance describing the new attached colorbuffer if bound and configured successfully, otherwise GLException is thrown
+ * @throws GLException in case the colorbuffer couldn't be allocated
+ */
+ public final ColorAttachment attachColorbuffer(GL gl, int attachmentPoint, ColorAttachment colA) throws GLException {
+ validateAddColorAttachment(attachmentPoint, colA);
+
+ colA.initialize(gl);
+ addColorAttachment(attachmentPoint, colA);
+
+ bind(gl);
+
+ // Attach the color buffer
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
+ GL.GL_COLOR_ATTACHMENT0 + attachmentPoint,
+ GL.GL_RENDERBUFFER, colA.getName());
+
+ updateStatus(gl);
+ if(!isStatusValid()) {
+ detachColorbuffer(gl, attachmentPoint);
+ throw new GLException("attachColorbuffer "+colA+" at "+attachmentPoint+" failed "+getStatusString()+", "+this);
+ }
+ if(DEBUG) {
+ System.err.println("FBObject.attachColorbuffer: "+this);
+ }
+ return colA;
+ }
+
+
+ /**
+ * Attaches one depth, stencil or packed-depth-stencil buffer to this FBO's instance,
+ * selecting the internalFormat automatically.
+ * <p>
+ * Stencil and depth buffer can be attached only once.
+ * </p>
+ * <p>
+ * In case the desired type or bit-number is not supported, the next available one is chosen.
+ * </p>
+ * <p>
+ * Use {@link #getDepthAttachment()} and/or {@link #getStencilAttachment()} to retrieve details
+ * about the attached buffer. The details cannot be returned, since it's possible 2 buffers
+ * are being created, depth and stencil.
+ * </p>
+ *
+ * <p>Leaves the FBO bound.</p>
+ *
+ * @param gl
+ * @param atype either {@link Type#DEPTH}, {@link Type#STENCIL} or {@link Type#DEPTH_STENCIL}
+ * @param reqBits desired bits for depth or -1 for default (24 bits)
+ * @throws GLException in case the renderbuffer couldn't be allocated or one is already attached.
+ * @throws IllegalArgumentException
+ * @see #getDepthAttachment()
+ * @see #getStencilAttachment()
+ */
+ public final void attachRenderbuffer(GL gl, Attachment.Type atype, int reqBits) throws GLException, IllegalArgumentException {
+ if( 0 > reqBits ) {
+ reqBits = 24;
+ }
+ final int internalFormat;
+ int internalStencilFormat = -1;
+
+ switch ( atype ) {
+ case DEPTH:
+ if( 32 <= reqBits && depth32Avail ) {
+ internalFormat = GL.GL_DEPTH_COMPONENT32;
+ } else if( 24 <= reqBits && depth24Avail ) {
+ internalFormat = GL.GL_DEPTH_COMPONENT24;
+ } else {
+ internalFormat = GL.GL_DEPTH_COMPONENT16;
+ }
+ break;
+
+ case STENCIL:
+ if( 16 <= reqBits && stencil16Avail ) {
+ internalFormat = GL2GL3.GL_STENCIL_INDEX16;
+ } else if( 8 <= reqBits && stencil08Avail ) {
+ internalFormat = GL.GL_STENCIL_INDEX8;
+ } else if( 4 <= reqBits && stencil04Avail ) {
+ internalFormat = GL.GL_STENCIL_INDEX4;
+ } else if( 1 <= reqBits && stencil01Avail ) {
+ internalFormat = GL.GL_STENCIL_INDEX1;
+ } else {
+ throw new GLException("stencil buffer n/a");
+ }
+ break;
+
+ case DEPTH_STENCIL:
+ if( packedDepthStencilAvail ) {
+ internalFormat = GL.GL_DEPTH24_STENCIL8;
+ } else {
+ if( 24 <= reqBits && depth24Avail ) {
+ internalFormat = GL.GL_DEPTH_COMPONENT24;
+ } else {
+ internalFormat = GL.GL_DEPTH_COMPONENT16;
+ }
+ if( stencil08Avail ) {
+ internalStencilFormat = GL.GL_STENCIL_INDEX8;
+ } else if( stencil04Avail ) {
+ internalStencilFormat = GL.GL_STENCIL_INDEX4;
+ } else if( stencil01Avail ) {
+ internalStencilFormat = GL.GL_STENCIL_INDEX1;
+ } else {
+ throw new GLException("stencil buffer n/a");
+ }
+ }
+ break;
+ default:
+ throw new IllegalArgumentException("only depth/stencil types allowed, was "+atype+", "+this);
+ }
+
+ attachRenderbufferImpl(gl, atype, internalFormat);
+
+ if(0<=internalStencilFormat) {
+ attachRenderbufferImpl(gl, Attachment.Type.STENCIL, internalStencilFormat);
+ }
+ }
+
+ /**
+ * Attaches one depth, stencil or packed-depth-stencil buffer to this FBO's instance,
+ * depending on the <code>internalFormat</code>.
+ * <p>
+ * Stencil and depth buffer can be attached only once.
+ * </p>
+ * <p>
+ * Use {@link #getDepthAttachment()} and/or {@link #getStencilAttachment()} to retrieve details
+ * about the attached buffer. The details cannot be returned, since it's possible 2 buffers
+ * are being created, depth and stencil.
+ * </p>
+ *
+ * <p>Leaves the FBO bound.</p>
+ *
+ * @param gl the current GL context
+ * @param internalFormat {@link GL#GL_DEPTH_COMPONENT16}, {@link GL#GL_DEPTH_COMPONENT24}, {@link GL#GL_DEPTH_COMPONENT32},
+ * {@link GL#GL_STENCIL_INDEX1}, {@link GL#GL_STENCIL_INDEX4}, {@link GL#GL_STENCIL_INDEX8}
+ * or {@link GL#GL_DEPTH24_STENCIL8}
+ * @throws GLException in case the renderbuffer couldn't be allocated or one is already attached.
+ * @throws IllegalArgumentException
+ * @see #getDepthAttachment()
+ * @see #getStencilAttachment()
+ */
+ public final void attachRenderbuffer(GL gl, int internalFormat) throws GLException, IllegalArgumentException {
+ final Attachment.Type atype = Attachment.Type.determine(internalFormat);
+ if( Attachment.Type.DEPTH != atype && Attachment.Type.STENCIL != atype && Attachment.Type.DEPTH_STENCIL != atype ) {
+ throw new IllegalArgumentException("renderformat invalid: 0x"+Integer.toHexString(internalFormat)+", "+this);
+ }
+ attachRenderbufferImpl(gl, atype, internalFormat);
+ }
+
+ protected final void attachRenderbufferImpl(GL gl, Attachment.Type atype, int internalFormat) throws GLException {
+ if( null != depth && ( Attachment.Type.DEPTH == atype || Attachment.Type.DEPTH_STENCIL == atype ) ) {
+ throw new GLException("FBO depth buffer already attached (rb "+depth+"), type is "+atype+", 0x"+Integer.toHexString(internalFormat)+", "+this);
+ }
+ if( null != stencil && ( Attachment.Type.STENCIL== atype || Attachment.Type.DEPTH_STENCIL == atype ) ) {
+ throw new GLException("FBO stencil buffer already attached (rb "+stencil+"), type is "+atype+", 0x"+Integer.toHexString(internalFormat)+", "+this);
+ }
+ attachRenderbufferImpl2(gl, atype, internalFormat);
+ }
+
+ private final void attachRenderbufferImpl2(GL gl, Attachment.Type atype, int internalFormat) throws GLException {
+ if( Attachment.Type.DEPTH == atype ) {
+ if(null == depth) {
+ depth = new RenderAttachment(Type.DEPTH, internalFormat, samples, width, height, 0);
+ } else {
+ depth.setSize(width, height);
+ depth.setSamples(samples);
+ }
+ depth.initialize(gl);
+ } else if( Attachment.Type.STENCIL == atype ) {
+ if(null == stencil) {
+ stencil = new RenderAttachment(Type.STENCIL, internalFormat, samples, width, height, 0);
+ } else {
+ stencil.setSize(width, height);
+ stencil.setSamples(samples);
+ }
+ stencil.initialize(gl);
+ } else if( Attachment.Type.DEPTH_STENCIL == atype ) {
+ if(null == depth) {
+ depth = new RenderAttachment(Type.DEPTH, internalFormat, samples, width, height, 0);
+ } else {
+ depth.setSize(width, height);
+ depth.setSamples(samples);
+ }
+ depth.initialize(gl);
+ if(null == stencil) {
+ stencil = new RenderAttachment(Type.STENCIL, internalFormat, samples, width, height, depth.getName());
+ } else {
+ stencil.setName(depth.getName());
+ stencil.setSize(width, height);
+ stencil.setSamples(samples);
+ }
+ stencil.initialize(gl);
+ }
+
+ bind(gl);
+
+ // Attach the buffer
+ if( Attachment.Type.DEPTH == atype ) {
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, GL.GL_RENDERBUFFER, depth.getName());
+ } else if( Attachment.Type.STENCIL == atype ) {
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_STENCIL_ATTACHMENT, GL.GL_RENDERBUFFER, stencil.getName());
+ } else if( Attachment.Type.DEPTH_STENCIL == atype ) {
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, GL.GL_RENDERBUFFER, depth.getName());
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_STENCIL_ATTACHMENT, GL.GL_RENDERBUFFER, stencil.getName());
+ }
+
+ updateStatus(gl);
+ if( !isStatusValid() ) {
+ detachRenderbuffer(gl, atype);
+ throw new GLException("renderbuffer attachment failed: "+this.getStatusString());
+ }
+
+ if(DEBUG) {
+ System.err.println("FBObject.attachRenderbuffer: "+this);
+ }
+ }
+
+ /**
+ * <p>Leaves the FBO bound!</p>
+ * @param gl
+ * @param ca
+ * @throws IllegalArgumentException
+ */
+ public final void detachColorbuffer(GL gl, int attachmentPoint) throws IllegalArgumentException {
+ if(null == detachColorbufferImpl(gl, attachmentPoint, false)) {
+ throw new IllegalArgumentException("ColorAttachment at "+attachmentPoint+", not attached, "+this);
+ }
+ if(DEBUG) {
+ System.err.println("FBObject.detachAll: "+this);
+ }
+ }
+
+ private final Colorbuffer detachColorbufferImpl(GL gl, int attachmentPoint, boolean recreate) {
+ final Colorbuffer colbuf = colorAttachmentPoints[attachmentPoint]; // shortcut, don't validate here
+
+ if(null == colbuf) {
+ return null;
+ }
+
+ bind(gl);
+
+ if(colbuf instanceof TextureAttachment) {
+ final TextureAttachment texA = (TextureAttachment) colbuf;
+ if( 0 != texA.getName() ) {
+ gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER,
+ GL.GL_COLOR_ATTACHMENT0 + attachmentPoint,
+ GL.GL_TEXTURE_2D, 0, 0);
+ gl.glBindTexture(GL.GL_TEXTURE_2D, 0);
+ }
+ texA.free(gl);
+ removeColorAttachment(attachmentPoint, texA);
+ if(recreate) {
+ texA.setSize(width, height);
+ attachTexture2D(gl, attachmentPoint, texA);
+ }
+ } else if(colbuf instanceof ColorAttachment) {
+ final ColorAttachment colA = (ColorAttachment) colbuf;
+ if( 0 != colA.getName() ) {
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
+ GL.GL_COLOR_ATTACHMENT0+attachmentPoint,
+ GL.GL_RENDERBUFFER, 0);
+ }
+ colA.free(gl);
+ removeColorAttachment(attachmentPoint, colbuf);
+ if(recreate) {
+ colA.setSize(width, height);
+ colA.setSamples(samples);
+ attachColorbuffer(gl, attachmentPoint, colA);
+ }
+ }
+ return colbuf;
+ }
+
+ /**
+ *
+ * @param gl
+ * @param reqAType {@link Type#DEPTH}, {@link Type#DEPTH} or {@link Type#DEPTH_STENCIL}
+ */
+ public final void detachRenderbuffer(GL gl, Attachment.Type atype) throws IllegalArgumentException {
+ detachRenderbufferImpl(gl, atype, false);
+ }
+
+ public final boolean isDepthStencilPackedFormat() {
+ final boolean res = null != depth && null != stencil &&
+ depth.format == stencil.format ;
+ if(res && depth.getName() != stencil.getName() ) {
+ throw new InternalError("depth/stencil packed format not sharing: depth "+depth+", stencil "+stencil);
+ }
+ return res;
+ }
+
+ private final void detachRenderbufferImpl(GL gl, Attachment.Type atype, boolean recreate) throws IllegalArgumentException {
+ switch ( atype ) {
+ case DEPTH:
+ case STENCIL:
+ case DEPTH_STENCIL:
+ break;
+ default:
+ throw new IllegalArgumentException("only depth/stencil types allowed, was "+atype+", "+this);
+ }
+ if( null == depth && null == stencil ) {
+ return ; // nop
+ }
+ // reduction of possible combinations, create unique atype command(s)
+ final ArrayList<Attachment.Type> actions = new ArrayList<Attachment.Type>(2);
+ if( isDepthStencilPackedFormat() ) {
+ // packed
+ actions.add(Attachment.Type.DEPTH_STENCIL);
+ } else {
+ // individual
+ switch ( atype ) {
+ case DEPTH:
+ if( null != depth ) { actions.add(Attachment.Type.DEPTH); }
+ break;
+ case STENCIL:
+ if( null != stencil ) { actions.add(Attachment.Type.STENCIL); }
+ break;
+ case DEPTH_STENCIL:
+ if( null != depth ) { actions.add(Attachment.Type.DEPTH); }
+ if( null != stencil ) { actions.add(Attachment.Type.STENCIL); }
+ break;
+ default: // handled
+ }
+ }
+
+ bind(gl);
+
+ for(int i = 0; i < actions.size(); i++) {
+ final int format;
+
+ Attachment.Type action = actions.get(i);
+ switch ( action ) {
+ case DEPTH:
+ format = depth.format;
+ if( 0 != depth.getName() ) {
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, GL.GL_RENDERBUFFER, 0);
+ }
+ depth.free(gl);
+ if(!recreate) {
+ depth = null;
+ }
+ break;
+ case STENCIL:
+ format = stencil.format;
+ if(0 != stencil.getName()) {
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_STENCIL_ATTACHMENT, GL.GL_RENDERBUFFER, 0);
+ }
+ stencil.free(gl);
+ if(!recreate) {
+ stencil = null;
+ }
+ break;
+ case DEPTH_STENCIL:
+ format = depth.format;
+ if(0 != depth.getName()) {
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, GL.GL_RENDERBUFFER, 0);
+ gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER, GL.GL_STENCIL_ATTACHMENT, GL.GL_RENDERBUFFER, 0);
+ }
+ depth.free(gl);
+ stencil.free(gl);
+ if(!recreate) {
+ depth = null;
+ stencil = null;
+ }
+ break;
+ default:
+ throw new InternalError("XXX");
+ }
+ if(recreate) {
+ attachRenderbufferImpl2(gl, action, format);
+ }
+ }
+ }
+
+ /**
+ * Detaches all {@link ColorAttachment}s, {@link TextureAttachment}s and {@link RenderAttachment}s.
+ * <p>Leaves the FBO bound!</p>
+ * <p>
+ * An attached sampling sink texture will be detached as well, see {@link #getSamplingSink()}.
+ * </p>
+ * @param gl the current GL context
+ */
+ public final void detachAll(GL gl) {
+ if(null != samplesSink) {
+ samplesSink.detachAll(gl);
+ }
+ detachAllImpl(gl, true/* detachNonColorbuffer */, false /* recreate */);
+ }
+
+ /**
+ * Detaches all {@link ColorAttachment}s and {@link TextureAttachment}s.
+ * <p>Leaves the FBO bound!</p>
+ * <p>
+ * An attached sampling sink texture will be detached as well, see {@link #getSamplingSink()}.
+ * </p>
+ * @param gl the current GL context
+ */
+ public final void detachAllColorbuffer(GL gl) {
+ if(null != samplesSink) {
+ samplesSink.detachAllColorbuffer(gl);
+ }
+ detachAllImpl(gl, false/* detachNonColorbuffer */, false /* recreate */);
+ }
+
+ /**
+ * Detaches all {@link TextureAttachment}s
+ * <p>Leaves the FBO bound!</p>
+ * <p>
+ * An attached sampling sink texture will be detached as well, see {@link #getSamplingSink()}.
+ * </p>
+ * @param gl the current GL context
+ */
+ public final void detachAllTexturebuffer(GL gl) {
+ if(null != samplesSink) {
+ samplesSink.detachAllTexturebuffer(gl);
+ }
+ for(int i=0; i<maxColorAttachments; i++) {
+ if(colorAttachmentPoints[i] instanceof TextureAttachment) {
+ detachColorbufferImpl(gl, i, false);
+ }
+ }
+ }
+
+ public final void detachAllRenderbuffer(GL gl) {
+ if(null != samplesSink) {
+ samplesSink.detachAllRenderbuffer(gl);
+ }
+ detachRenderbufferImpl(gl, Attachment.Type.DEPTH_STENCIL, false);
+ }
+
+ private final void detachAllImpl(GL gl, boolean detachNonColorbuffer, boolean recreate) {
+ for(int i=0; i<maxColorAttachments; i++) {
+ detachColorbufferImpl(gl, i, recreate);
+ }
+ if( !recreate && colorAttachmentCount>0 ) {
+ throw new InternalError("Non zero ColorAttachments "+this);
+ }
+
+ if(detachNonColorbuffer) {
+ detachRenderbufferImpl(gl, Attachment.Type.DEPTH_STENCIL, recreate);
+ }
+
+ if(DEBUG) {
+ System.err.println("FBObject.detachAll: [resetNonColorbuffer "+detachNonColorbuffer+", recreate "+recreate+"]: "+this);
+ }
+ }
+
+ /**
+ * @param gl the current GL context
+ */
+ public final void destroy(GL gl) {
+ if(null != samplesSink) {
+ samplesSink.destroy(gl);
+ }
+
+ detachAllImpl(gl, true /* detachNonColorbuffer */, false /* recreate */);
+
+ // cache FB names, preset exposed to zero,
+ // braking ties w/ GL/GLContext link to getReadFramebuffer()/getWriteFramebuffer()
+ final int fb_cache = fbName;
+ fbName = 0;
+
+ int name[] = new int[1];
+ if(0!=fb_cache) {
+ name[0] = fb_cache;
+ gl.glDeleteFramebuffers(1, name, 0);
+ }
+ initialized = false;
+ bound = false;
+ if(DEBUG) {
+ System.err.println("FBObject.destroy: "+this);
+ }
+ }
+
+ private final boolean sampleSinkSizeMismatch() {
+ return samplesSink.getWidth() != width || samplesSink.getHeight() != height ;
+ }
+ private final boolean sampleSinkTexMismatch() {
+ return null == samplesSinkTexture || 0 == samplesSinkTexture.getName() ;
+ }
+ private final boolean sampleSinkDepthStencilMismatch() {
+ final boolean depthMismatch = ( null != depth && null == samplesSink.depth ) ||
+ ( null != depth && null != samplesSink.depth &&
+ depth.format != samplesSink.depth.format );
+
+ final boolean stencilMismatch = ( null != stencil && null == samplesSink.stencil ) ||
+ ( null != stencil && null != samplesSink.stencil &&
+ stencil.format != samplesSink.stencil.format );
+
+ return depthMismatch || stencilMismatch;
+ }
+
+ private final void resetMSAATexture2DSink(GL gl) throws GLException {
+ if(0 == samples) {
+ // MSAA off
+ if(null != samplesSink) {
+ samplesSink.detachAll(gl);
+ }
+ return;
+ }
+
+ boolean sampleSinkSizeMismatch = sampleSinkSizeMismatch();
+ boolean sampleSinkTexMismatch = sampleSinkTexMismatch();
+ boolean sampleSinkDepthStencilMismatch = sampleSinkDepthStencilMismatch();
+
+ /** if(DEBUG) {
+ System.err.println("FBObject.resetMSAATexture2DSink.0: \n\tTHIS "+this+",\n\tSINK "+samplesSink+
+ "\n\t size "+sampleSinkSizeMismatch +", tex "+sampleSinkTexMismatch +", depthStencil "+sampleSinkDepthStencilMismatch);
+ } */
+
+ if(!sampleSinkSizeMismatch && !sampleSinkTexMismatch && !sampleSinkDepthStencilMismatch) {
+ // all properties match ..
+ return;
+ }
+
+ unbind(gl);
+
+ if(DEBUG) {
+ System.err.println("FBObject.resetMSAATexture2DSink: BEGIN\n\tTHIS "+this+",\n\tSINK "+samplesSink+
+ "\n\t size "+sampleSinkSizeMismatch +", tex "+sampleSinkTexMismatch +", depthStencil "+sampleSinkDepthStencilMismatch);
+ }
+
+ if( sampleSinkDepthStencilMismatch ) {
+ samplesSink.detachAllRenderbuffer(gl);
+ }
+
+ if( sampleSinkSizeMismatch ) {
+ samplesSink.reset(gl, width, height);
+ }
+
+ if(null == samplesSinkTexture) {
+ samplesSinkTexture = samplesSink.attachTexture2D(gl, 0, true);
+ } else if( 0 == samplesSinkTexture.getName() ) {
+ samplesSinkTexture.setSize(width, height);
+ samplesSink.attachTexture2D(gl, 0, samplesSinkTexture);
+ }
+
+ if( sampleSinkDepthStencilMismatch ) {
+ samplesSink.attachRenderbuffer(gl, depth.format);
+ if( null != stencil && !isDepthStencilPackedFormat() ) {
+ samplesSink.attachRenderbuffer(gl, stencil.format);
+ }
+ }
+
+ sampleSinkSizeMismatch = sampleSinkSizeMismatch();
+ sampleSinkTexMismatch = sampleSinkTexMismatch();
+ sampleSinkDepthStencilMismatch = sampleSinkDepthStencilMismatch();
+ if(sampleSinkSizeMismatch || sampleSinkTexMismatch || sampleSinkDepthStencilMismatch) {
+ throw new InternalError("Samples sink mismatch after reset: \n\tTHIS "+this+",\n\t SINK "+samplesSink+
+ "\n\t size "+sampleSinkSizeMismatch +", tex "+sampleSinkTexMismatch +", depthStencil "+sampleSinkDepthStencilMismatch);
+ }
+
+ if(DEBUG) {
+ System.err.println("FBObject.resetMSAATexture2DSink: END\n\tTHIS "+this+",\n\tSINK "+samplesSink+
+ "\n\t size "+sampleSinkSizeMismatch +", tex "+sampleSinkTexMismatch +", depthStencil "+sampleSinkDepthStencilMismatch);
+ }
+ }
+
+ /**
+ * Bind this FBO, i.e. bind write framebuffer to {@link #getWriteFramebuffer()}.
+ *
+ * <p>If multisampling is used, it sets the read framebuffer to the sampling sink {@link #getWriteFramebuffer()},
+ * if full FBO is supported.</p>
+ *
+ * <p>
+ * In case you have attached more than one color buffer,
+ * you may want to setup {@link GL2GL3#glDrawBuffers(int, int[], int)}.
+ * </p>
+ * @param gl the current GL context
+ * @throws GLException
+ */
+ public final void bind(GL gl) throws GLException {
+ if(!bound || fbName != gl.getBoundFramebuffer(GL.GL_FRAMEBUFFER)) {
+ checkInitialized();
+ if(samples > 0 && fullFBOSupport) {
+ // draw to multisampling - read from samplesSink
+ gl.glBindFramebuffer(GL2GL3.GL_DRAW_FRAMEBUFFER, getWriteFramebuffer());
+ gl.glBindFramebuffer(GL2GL3.GL_READ_FRAMEBUFFER, getReadFramebuffer());
+ } else {
+ // one for all
+ gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, getWriteFramebuffer());
+ }
+
+ checkNoError(null, gl.glGetError(), "FBObject post-bind"); // throws GLException if error
+ bound = true;
+ samplesSinkDirty = true;
+ }
+ }
+
+ /**
+ * Unbind this FBO, i.e. bind read and write framebuffer to default, see {@link GLBase#getDefaultDrawFramebuffer()}.
+ *
+ * <p>If full FBO is supported, sets the read and write framebuffer individually to default, hence not disturbing
+ * an optional operating MSAA FBO, see {@link GLBase#getDefaultReadFramebuffer()} and {@link GLBase#getDefaultDrawFramebuffer()}</p>
+ *
+ * @param gl the current GL context
+ * @throws GLException
+ */
+ public final void unbind(GL gl) throws GLException {
+ if(bound) {
+ if(fullFBOSupport) {
+ // default read/draw buffers, may utilize GLContext/GLDrawable override of
+ // GLContext.getDefaultDrawFramebuffer() and GLContext.getDefaultReadFramebuffer()
+ gl.glBindFramebuffer(GL2GL3.GL_DRAW_FRAMEBUFFER, 0);
+ gl.glBindFramebuffer(GL2GL3.GL_READ_FRAMEBUFFER, 0);
+ } else {
+ gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0); // default draw buffer
+ }
+ checkNoError(null, gl.glGetError(), "FBObject post-unbind"); // throws GLException if error
+ bound = false;
+ }
+ }
+
+ /**
+ * Returns <code>true</code> if framebuffer object is bound via {@link #bind(GL)}, otherwise <code>false</code>.
+ * <p>
+ * Method verifies the bound state via {@link GL#getBoundFramebuffer(int)}.
+ * </p>
+ * @param gl the current GL context
+ */
+ public final boolean isBound(GL gl) {
+ bound = bound && fbName != gl.getBoundFramebuffer(GL.GL_FRAMEBUFFER) ;
+ return bound;
+ }
+
+ /** Returns <code>true</code> if framebuffer object is bound via {@link #bind(GL)}, otherwise <code>false</code>. */
+ public final boolean isBound() { return bound; }
+
+ /**
+ * Samples the multisampling colorbuffer (msaa-buffer) to it's sink {@link #getSamplingSink()}.
+ *
+ * <p>The operation is skipped, if no multisampling is used or
+ * the msaa-buffer has not been flagged dirty by a previous call of {@link #bind(GL)},
+ * see {@link #isSamplingBufferDirty()} </p>
+ *
+ * <p>If full FBO is supported, sets the read and write framebuffer individually to default after sampling, hence not disturbing
+ * an optional operating MSAA FBO, see {@link GLBase#getDefaultReadFramebuffer()} and {@link GLBase#getDefaultDrawFramebuffer()}</p>
+ *
+ * <p>In case you intend to employ {@link GL#glReadPixels(int, int, int, int, int, int, java.nio.Buffer) glReadPixels(..)}
+ * you may want to call {@link GL#glBindFramebuffer(int, int) glBindFramebuffer}({@link GL2GL3#GL_READ_FRAMEBUFFER}, {@link #getReadFramebuffer()});
+ * </p>
+ *
+ * <p>Leaves the FBO unbound.</p>
+ *
+ * @param gl the current GL context
+ * @param ta {@link TextureAttachment} to use, prev. attached w/ {@link #attachTexture2D(GL, int, boolean, int, int, int, int) attachTexture2D(..)}
+ * @throws IllegalArgumentException
+ */
+ public final void syncSamplingBuffer(GL gl) {
+ unbind(gl);
+ if(samples>0 && samplesSinkDirty) {
+ samplesSinkDirty = false;
+ resetMSAATexture2DSink(gl);
+ gl.glBindFramebuffer(GL2GL3.GL_READ_FRAMEBUFFER, fbName);
+ gl.glBindFramebuffer(GL2GL3.GL_DRAW_FRAMEBUFFER, samplesSink.getWriteFramebuffer());
+ ((GL2GL3)gl).glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, // since MSAA is supported, ugly cast is OK
+ GL.GL_COLOR_BUFFER_BIT, GL.GL_NEAREST);
+ if(fullFBOSupport) {
+ // default read/draw buffers, may utilize GLContext/GLDrawable override of
+ // GLContext.getDefaultDrawFramebuffer() and GLContext.getDefaultReadFramebuffer()
+ gl.glBindFramebuffer(GL2GL3.GL_DRAW_FRAMEBUFFER, 0);
+ gl.glBindFramebuffer(GL2GL3.GL_READ_FRAMEBUFFER, 0);
+ } else {
+ gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0); // default draw buffer
+ }
+ }
+ }
+
+ /**
+ * Bind the given texture colorbuffer.
+ *
+ * <p>If multisampling is being used, {@link #syncSamplingBuffer(GL)} is being called.</p>
+ *
+ * <p>Leaves the FBO unbound!</p>
+ *
+ * @param gl the current GL context
+ * @param ta {@link TextureAttachment} to use, prev. attached w/ {@link #attachTexture2D(GL, int, boolean, int, int, int, int) attachTexture2D(..)}
+ * @throws IllegalArgumentException
+ */
+ public final void use(GL gl, TextureAttachment ta) throws IllegalArgumentException {
+ if(null == ta) { throw new IllegalArgumentException("null TextureAttachment"); }
+ if(samples > 0 && samplesSinkTexture == ta) {
+ syncSamplingBuffer(gl);
+ } else {
+ unbind(gl);
+ }
+ gl.glBindTexture(GL.GL_TEXTURE_2D, ta.getName()); // use it ..
+ }
+
+ /**
+ * Unbind texture, ie bind 'non' texture 0
+ *
+ * <p>Leaves the FBO unbound.</p>
+ */
+ public final void unuse(GL gl) {
+ unbind(gl);
+ gl.glBindTexture(GL.GL_TEXTURE_2D, 0); // don't use it
+ }
+
+ /**
+ * Returns <code>true</code> if <i>basic</i> or <i>full</i> FBO is supported, otherwise <code>false</code>.
+ * @param full <code>true</code> for <i>full</i> FBO supported query, otherwise <code>false</code> for <i>basic</i> FBO support query.
+ * @see #supportsFullFBO(GL)
+ * @see #supportsBasicFBO(GL)
+ * @throws GLException if {@link #init(GL)} hasn't been called.
+ */
+ public final boolean supportsFBO(boolean full) throws GLException { checkInitialized(); return full ? fullFBOSupport : basicFBOSupport; }
+
+ /**
+ * Returns <code>true</code> if renderbuffer accepts internal format {@link GL#GL_RGB8} and {@link GL#GL_RGBA8}, otherwise <code>false</code>.
+ * @throws GLException if {@link #init(GL)} hasn't been called.
+ */
+ public final boolean supportsRGBA8() throws GLException { checkInitialized(); return rgba8Avail; }
+
+ /**
+ * Returns <code>true</code> if {@link GL#GL_DEPTH_COMPONENT16}, {@link GL#GL_DEPTH_COMPONENT24} or {@link GL#GL_DEPTH_COMPONENT32} is supported, otherwise <code>false</code>.
+ * @param bits 16, 24 or 32 bits
+ * @throws GLException if {@link #init(GL)} hasn't been called.
+ */
+ public final boolean supportsDepth(int bits) throws GLException {
+ checkInitialized();
+ switch(bits) {
+ case 16: return basicFBOSupport;
+ case 24: return depth24Avail;
+ case 32: return depth32Avail;
+ default: return false;
+ }
+ }
+
+ /**
+ * Returns <code>true</code> if {@link GL#GL_STENCIL_INDEX1}, {@link GL#GL_STENCIL_INDEX4}, {@link GL#GL_STENCIL_INDEX8} or {@link GL2GL3#GL_STENCIL_INDEX16} is supported, otherwise <code>false</code>.
+ * @param bits 1, 4, 8 or 16 bits
+ * @throws GLException if {@link #init(GL)} hasn't been called.
+ */
+ public final boolean supportsStencil(int bits) throws GLException {
+ checkInitialized();
+ switch(bits) {
+ case 1: return stencil01Avail;
+ case 4: return stencil04Avail;
+ case 8: return stencil08Avail;
+ case 16: return stencil16Avail;
+ default: return false;
+ }
+ }
+
+ /**
+ * Returns <code>true</code> if {@link GL#GL_DEPTH24_STENCIL8} is supported, otherwise <code>false</code>.
+ * @throws GLException if {@link #init(GL)} hasn't been called.
+ */
+ public final boolean supportsPackedDepthStencil() throws GLException { checkInitialized(); return packedDepthStencilAvail; }
+
+ /**
+ * Returns the maximum number of colorbuffer attachments.
+ * @throws GLException if {@link #init(GL)} hasn't been called.
+ */
+ public final int getMaxColorAttachments() throws GLException { checkInitialized(); return maxColorAttachments; }
+
+ /**
+ * Returns the maximum number of samples for multisampling. Maybe zero if multisampling is not supported.
+ * @throws GLException if {@link #init(GL)} hasn't been called.
+ */
+ public final int getMaxSamples() throws GLException { checkInitialized(); return maxSamples; }
+
+ /**
+ * Returns <code>true</code> if this instance has been initialized with {@link #reset(GL, int, int)}
+ * or {@link #reset(GL, int, int, int)}, otherwise <code>false</code>
+ */
+ public final boolean isInitialized() { return initialized; }
+ /** Returns the width */
+ public final int getWidth() { return width; }
+ /** Returns the height */
+ public final int getHeight() { return height; }
+ /** Returns the number of samples for multisampling (MSAA). zero if no multisampling is used. */
+ public final int getNumSamples() { return samples; }
+ /** 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 ) ? samplesSink.getReadFramebuffer() : fbName; }
+ /** 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. */
+ public final RenderAttachment getStencilAttachment() { return stencil; }
+ /** Return the depth {@link RenderAttachment} attachment. Maybe share the same {@link Attachment#getName()} as {@link #getStencilAttachment()}, if packed depth-stencil is being used. */
+ public final RenderAttachment getDepthAttachment() { return depth; }
+
+ /** Return the complete multisampling {@link FBObject} sink, if using multisampling. */
+ public final FBObject getSamplingSinkFBO() { return samplesSink; }
+
+ /** Return the multisampling {@link TextureAttachment} sink, if using multisampling. */
+ public final TextureAttachment getSamplingSink() { return samplesSinkTexture; }
+ /**
+ * Returns <code>true</code> if the multisampling colorbuffer (msaa-buffer)
+ * has been flagged dirty by a previous call of {@link #bind(GL)},
+ * otherwise <code>false</code>.
+ */
+ public final boolean isSamplingBufferDirty() { return samplesSinkDirty; }
+
+ int objectHashCode() { return super.hashCode(); }
+
+ public final String toString() {
+ final String caps = null != colorAttachmentPoints ? Arrays.asList(colorAttachmentPoints).toString() : null ;
+ return "FBO[name r/w "+fbName+"/"+getReadFramebuffer()+", init "+initialized+", bound "+bound+", size "+width+"x"+height+", samples "+samples+"/"+maxSamples+
+ ", depth "+depth+", stencil "+stencil+", color attachments: "+colorAttachmentCount+"/"+maxColorAttachments+
+ ": "+caps+", msaa-sink "+samplesSinkTexture+", isSamplesSink "+(null == samplesSink)+
+ ", obj 0x"+Integer.toHexString(objectHashCode())+"]";
+ }
+
+ private final void updateStatus(GL gl) {
+ if( 0 == fbName ) {
+ vStatus = -1;
+ } else {
+ vStatus = gl.glCheckFramebufferStatus(GL.GL_FRAMEBUFFER);
+ }
+ }
+}
diff --git a/src/jogl/classes/com/jogamp/opengl/GLExtensions.java b/src/jogl/classes/com/jogamp/opengl/GLExtensions.java
new file mode 100644
index 000000000..f7e25fa01
--- /dev/null
+++ b/src/jogl/classes/com/jogamp/opengl/GLExtensions.java
@@ -0,0 +1,81 @@
+/**
+ * Copyright 2012 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+package com.jogamp.opengl;
+
+/**
+ * Class holding OpenGL extension strings, commonly used by JOGL's implementation.
+ */
+public class GLExtensions {
+ public static final String VERSION_1_2 = "GL_VERSION_1_2";
+ public static final String VERSION_1_4 = "GL_VERSION_1_4";
+ public static final String VERSION_1_5 = "GL_VERSION_1_5";
+ public static final String VERSION_2_0 = "GL_VERSION_2_0";
+
+ public static final String ARB_debug_output = "GL_ARB_debug_output";
+ public static final String AMD_debug_output = "GL_AMD_debug_output";
+
+ public static final String ARB_framebuffer_object = "GL_ARB_framebuffer_object";
+ public static final String OES_framebuffer_object = "GL_OES_framebuffer_object";
+ public static final String EXT_framebuffer_object = "GL_EXT_framebuffer_object";
+ public static final String EXT_framebuffer_blit = "GL_EXT_framebuffer_blit";
+ public static final String EXT_framebuffer_multisample = "GL_EXT_framebuffer_multisample";
+ public static final String EXT_packed_depth_stencil = "GL_EXT_packed_depth_stencil";
+ public static final String OES_depth24 = "GL_OES_depth24";
+ public static final String OES_depth32 = "GL_OES_depth32";
+ public static final String OES_packed_depth_stencil = "GL_OES_packed_depth_stencil";
+ public static final String NV_fbo_color_attachments = "GL_NV_fbo_color_attachments";
+
+ public static final String ARB_ES2_compatibility = "GL_ARB_ES2_compatibility";
+
+ public static final String EXT_abgr = "GL_EXT_abgr";
+ public static final String OES_rgb8_rgba8 = "GL_OES_rgb8_rgba8";
+ public static final String OES_stencil1 = "GL_OES_stencil1";
+ public static final String OES_stencil4 = "GL_OES_stencil4";
+ public static final String OES_stencil8 = "GL_OES_stencil8";
+ public static final String APPLE_float_pixels = "GL_APPLE_float_pixels";
+
+ public static final String ARB_texture_non_power_of_two = "GL_ARB_texture_non_power_of_two";
+ public static final String ARB_texture_rectangle = "GL_ARB_texture_rectangle";
+ public static final String EXT_texture_rectangle = "GL_EXT_texture_rectangle";
+ public static final String NV_texture_rectangle = "GL_NV_texture_rectangle";
+ public static final String EXT_texture_format_BGRA8888 = "GL_EXT_texture_format_BGRA8888";
+ public static final String IMG_texture_format_BGRA8888 = "GL_IMG_texture_format_BGRA8888";
+ public static final String EXT_texture_compression_s3tc = "GL_EXT_texture_compression_s3tc";
+ public static final String NV_texture_compression_vtc = "GL_NV_texture_compression_vtc";
+ public static final String SGIS_generate_mipmap = "GL_SGIS_generate_mipmap";
+ public static final String OES_read_format = "GL_OES_read_format";
+
+ public static final String OES_EGL_image_external = "GL_OES_EGL_image_external";
+
+ //
+ // Aliased GLX/WGL/.. extensions
+ //
+
+ public static final String ARB_pixel_format = "GL_ARB_pixel_format";
+ public static final String ARB_pbuffer = "GL_ARB_pbuffer";
+}
diff --git a/src/jogl/classes/com/jogamp/opengl/JoglVersion.java b/src/jogl/classes/com/jogamp/opengl/JoglVersion.java
index 75785fd86..cdb4b82bb 100644
--- a/src/jogl/classes/com/jogamp/opengl/JoglVersion.java
+++ b/src/jogl/classes/com/jogamp/opengl/JoglVersion.java
@@ -93,11 +93,13 @@ public class JoglVersion extends JogampVersion {
return sb;
}
- public static StringBuilder getDefaultOpenGLInfo(StringBuilder sb, boolean withCapabilitiesInfo) {
+ public static StringBuilder getDefaultOpenGLInfo(AbstractGraphicsDevice device, StringBuilder sb, boolean withCapabilitiesInfo) {
if(null==sb) {
sb = new StringBuilder();
}
- final AbstractGraphicsDevice device = GLProfile.getDefaultDevice();
+ if(null == device) {
+ device = GLProfile.getDefaultDevice();
+ }
sb.append("Default Profiles on device ").append(device).append(Platform.getNewline());
if(null!=device) {
GLProfile.glAvailabilityToString(device, sb, "\t", 1);
@@ -120,13 +122,21 @@ public class JoglVersion extends JogampVersion {
if(null==sb) {
sb = new StringBuilder();
}
- GLContext ctx = gl.getContext();
-
+
sb.append(VersionUtil.SEPERATOR).append(Platform.getNewline());
sb.append(device.getClass().getSimpleName()).append("[type ")
.append(device.getType()).append(", connection ").append(device.getConnection()).append("]: ").append(Platform.getNewline());
GLProfile.glAvailabilityToString(device, sb, "\t", 1);
sb.append(Platform.getNewline());
+
+ return getGLStrings(gl, sb);
+ }
+
+ public static StringBuilder getGLStrings(GL gl, StringBuilder sb) {
+ if(null==sb) {
+ sb = new StringBuilder();
+ }
+ final GLContext ctx = gl.getContext();
sb.append("Swap Interval ").append(gl.getSwapInterval());
sb.append(Platform.getNewline());
sb.append("GL Profile ").append(gl.getGLProfile());
diff --git a/src/jogl/classes/com/jogamp/opengl/OffscreenAutoDrawable.java b/src/jogl/classes/com/jogamp/opengl/OffscreenAutoDrawable.java
new file mode 100644
index 000000000..8450ffdb0
--- /dev/null
+++ b/src/jogl/classes/com/jogamp/opengl/OffscreenAutoDrawable.java
@@ -0,0 +1,98 @@
+/**
+ * Copyright 2012 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl;
+
+import javax.media.nativewindow.AbstractGraphicsDevice;
+import javax.media.opengl.GLAutoDrawableDelegate;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLDrawable;
+import javax.media.opengl.GLException;
+
+import jogamp.opengl.GLFBODrawableImpl;
+
+/**
+ * Platform-independent class exposing FBO offscreen functionality to
+ * applications.
+ * <p>
+ * This class distinguishes itself from {@link GLAutoDrawableDelegate}
+ * with it's {@link #setSize(int, int)} functionality.
+ * </p>
+ */
+public class OffscreenAutoDrawable extends GLAutoDrawableDelegate {
+
+ /**
+ * @param drawable a valid {@link GLDrawable}, may not be realized yet.
+ * @param context a valid {@link GLContext}, may not be made current (created) yet.
+ * @param ownDevice pass <code>true</code> if {@link AbstractGraphicsDevice#close()} shall be issued,
+ * otherwise pass <code>false</code>. Closing the device is required in case
+ * the drawable is created w/ it's own new instance, e.g. offscreen drawables,
+ * and no further lifecycle handling is applied.
+ */
+ public OffscreenAutoDrawable(GLDrawable drawable, GLContext context, boolean ownDevice) {
+ super(drawable, context, null, ownDevice);
+ }
+
+ /**
+ * Attempts to resize this offscreen auto drawable, if supported
+ * by the underlying {@link GLDrawable).
+ * @param newWidth
+ * @param newHeight
+ * @return <code>true</code> if resize was executed, otherwise <code>false</code>.
+ * @throws GLException in case of an error during the resize operation
+ */
+ public boolean setSize(int newWidth, int newHeight) throws GLException {
+ boolean done = false;
+ if(drawable instanceof GLFBODrawableImpl) {
+ context.makeCurrent();
+ try {
+ ((GLFBODrawableImpl)drawable).setSize(context.getGL(), newWidth, newHeight);
+ done = true;
+ } finally {
+ context.release();
+ }
+ }
+ if(done) {
+ this.defaultWindowResizedOp();
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * If the underlying {@link GLDrawable} is an FBO implementation
+ * and contains an {#link FBObject}, the same is returned.
+ * Otherwise returns <code>null</code>.
+ */
+ public FBObject getFBObject() {
+ if(drawable instanceof GLFBODrawableImpl) {
+ return ((GLFBODrawableImpl)drawable).getFBObject();
+ }
+ return null;
+ }
+}
diff --git a/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java b/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java
index 5ee58b78d..8d237162c 100644
--- a/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java
+++ b/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java
@@ -45,6 +45,7 @@ import javax.media.opengl.GLProfile;
import javax.media.opengl.GLRunnable;
import javax.media.opengl.Threading;
+import jogamp.opengl.Debug;
import jogamp.opengl.GLContextImpl;
import jogamp.opengl.GLDrawableHelper;
@@ -63,27 +64,19 @@ import org.eclipse.swt.widgets.Shell;
import com.jogamp.common.GlueGenVersion;
import com.jogamp.common.os.Platform;
import com.jogamp.common.util.VersionUtil;
+import com.jogamp.common.util.locks.LockFactory;
+import com.jogamp.common.util.locks.RecursiveLock;
import com.jogamp.nativewindow.swt.SWTAccessor;
import com.jogamp.opengl.JoglVersion;
/**
* Native SWT Canvas implementing GLAutoDrawable
- * <p>
- * FIXME: If this instance runs in multithreading mode, see {@link Threading#isSingleThreaded()} (impossible),
- * proper recursive locking is required for drawable/context @ destroy and display.
- * Recreation etc could pull those instances while animating!
- * Simply locking before using drawable/context offthread
- * would allow a deadlock situation!
- * </p>
- * <p>
- * NOTE: [MT-0] Methods utilizing [volatile] drawable/context are not synchronized.
- In case any of the methods are called outside of a locked state
- extra care should be added. Maybe we shall expose locking facilities to the user.
- However, since the user shall stick to the GLEventListener model while utilizing
- GLAutoDrawable implementations, she is safe due to the implicit locked state.
- * </p>
+ *
+ * <p>Note: To employ custom GLCapabilities, NewtCanvasSWT shall be used instead.</p>
+ *
*/
public class GLCanvas extends Canvas implements GLAutoDrawable {
+ private static final boolean DEBUG = Debug.debug("GLCanvas");
/*
* Flag for whether the SWT thread should be used for OpenGL calls when in single-threaded mode. This is controlled
@@ -97,22 +90,25 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
//private static final boolean useSWTThread = ThreadingImpl.getMode() != ThreadingImpl.WORKER;
/* GL Stuff */
+ private final RecursiveLock lock = LockFactory.createRecursiveLock();
private final GLDrawableHelper helper = new GLDrawableHelper();
- private volatile GLDrawable drawable; // volatile avoids locking all accessors. FIXME still need to sync destroy/display
+
+ private final GLContext shareWith;
+ private final GLCapabilitiesImmutable capsRequested;
+ private final GLCapabilitiesChooser capsChooser;
+
+ private volatile GLDrawable drawable; // volatile: avoid locking for read-only access
private GLContext context;
/* Native window surface */
private AbstractGraphicsDevice device;
- private final long nativeWindowHandle;
- private final ProxySurface proxySurface;
/* Construction parameters stored for GLAutoDrawable accessor methods */
private int additionalCtxCreationFlags = 0;
- private final GLCapabilitiesImmutable glCapsRequested;
/* Flag indicating whether an unprocessed reshape is pending. */
- private volatile boolean sendReshape;
+ private volatile boolean sendReshape; // volatile: maybe written by WindowManager thread w/o locking
/*
* Invokes init(...) on all GLEventListeners. Assumes context is current when run.
@@ -141,10 +137,16 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
};
/* Action to make specified context current prior to running displayAction */
- private final Runnable makeCurrentAndDisplayAction = new Runnable() {
+ private final Runnable makeCurrentAndDisplayOnEDTAction = new Runnable() {
@Override
public void run() {
- helper.invokeGL(drawable, context, displayAction, initAction);
+ final RecursiveLock _lock = lock;
+ _lock.lock();
+ try {
+ helper.invokeGL(drawable, context, displayAction, initAction);
+ } finally {
+ _lock.unlock();
+ }
}
};
@@ -157,10 +159,16 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
};
/* Swaps buffers, making the GLContext current first */
- private final Runnable makeCurrentAndSwapBuffersAction = new Runnable() {
+ private final Runnable makeCurrentAndSwapBuffersOnEDTAction = new Runnable() {
@Override
public void run() {
- helper.invokeGL(drawable, context, swapBuffersAction, initAction);
+ final RecursiveLock _lock = lock;
+ _lock.lock();
+ try {
+ helper.invokeGL(drawable, context, swapBuffersAction, initAction);
+ } finally {
+ _lock.unlock();
+ }
}
};
@@ -181,16 +189,33 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
private final Runnable disposeOnEDTGLAction = new Runnable() {
@Override
public void run() {
- helper.disposeGL(GLCanvas.this, drawable, context, postDisposeGLAction);
- }
- };
-
- private final Runnable disposeGraphicsDeviceAction = new Runnable() {
- @Override
- public void run() {
- if (null != device) {
- device.close();
- device = null;
+ final RecursiveLock _lock = lock;
+ _lock.lock();
+ try {
+ if (null != drawable && null != context) {
+ boolean animatorPaused = false;
+ final GLAnimatorControl animator = getAnimator();
+ if (null != animator) {
+ animatorPaused = animator.pause();
+ }
+
+ if(context.isCreated()) {
+ helper.disposeGL(GLCanvas.this, drawable, context, postDisposeGLAction);
+ }
+
+ if (animatorPaused) {
+ animator.resume();
+ }
+ }
+ // SWT is owner of the device handle, not us.
+ // Hence close() operation is a NOP.
+ if (null != device) {
+ device.close();
+ device = null;
+ }
+ SWTAccessor.setRealized(GLCanvas.this, false); // unrealize ..
+ } finally {
+ _lock.unlock();
}
}
};
@@ -200,6 +225,37 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
*/
private volatile Rectangle clientArea;
+ /**
+ * Creates an instance using {@link #GLCanvas(Composite, int, GLCapabilitiesImmutable, GLCapabilitiesChooser, GLContext)}
+ * on the SWT thread.
+ *
+ * @param parent
+ * Required (non-null) parent Composite.
+ * @param style
+ * Optional SWT style bit-field. The {@link SWT#NO_BACKGROUND} bit is set before passing this up to the
+ * Canvas constructor, so OpenGL handles the background.
+ * @param caps
+ * Optional GLCapabilities. If not provided, the default capabilities for the default GLProfile for the
+ * graphics device determined by the parent Composite are used. Note that the GLCapabilities that are
+ * actually used may differ based on the capabilities of the graphics device.
+ * @param chooser
+ * Optional GLCapabilitiesChooser to customize the selection of the used GLCapabilities based on the
+ * requested GLCapabilities, and the available capabilities of the graphics device.
+ * @param shareWith
+ * Optional GLContext to share state (textures, vbos, shaders, etc.) with.
+ * @return a new instance
+ */
+ public static GLCanvas create(final Composite parent, final int style, final GLCapabilitiesImmutable caps,
+ final GLCapabilitiesChooser chooser, final GLContext shareWith) {
+ final GLCanvas[] res = new GLCanvas[] { null };
+ parent.getDisplay().syncExec(new Runnable() {
+ public void run() {
+ res[0] = new GLCanvas( parent, style, caps, chooser, shareWith );
+ }
+ });
+ return res[0];
+ }
+
/**
* Creates a new SWT GLCanvas.
*
@@ -229,35 +285,29 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
clientArea = GLCanvas.this.getClientArea();
- /* Get the nativewindow-Graphics Device associated with this control (which is determined by the parent Composite) */
+ /* Get the nativewindow-Graphics Device associated with this control (which is determined by the parent Composite).
+ * Note: SWT is owner of the native handle, hence no closing operation will be a NOP. */
device = SWTAccessor.getDevice(this);
- /* Native handle for the control, used to associate with GLContext */
- nativeWindowHandle = SWTAccessor.getWindowHandle(this);
/* Select default GLCapabilities if none was provided, otherwise clone provided caps to ensure safety */
if(null == caps) {
caps = new GLCapabilities(GLProfile.getDefault(device));
}
- glCapsRequested = caps;
-
- final GLDrawableFactory glFactory = GLDrawableFactory.getFactory(caps.getGLProfile());
-
- /* Create a NativeWindow proxy for the SWT canvas */
- proxySurface = glFactory.createProxySurface(device, nativeWindowHandle, caps, chooser);
-
- /* Associate a GL surface with the proxy */
- drawable = glFactory.createGLDrawable(proxySurface);
- drawable.setRealized(true);
-
- context = drawable.createContext(shareWith);
-
+ this.capsRequested = caps;
+ this.capsChooser = chooser;
+ this.shareWith = shareWith;
+
+ // post create .. when ready
+ drawable = null;
+ context = null;
+
/* Register SWT listeners (e.g. PaintListener) to render/resize GL surface. */
/* TODO: verify that these do not need to be manually de-registered when destroying the SWT component */
addPaintListener(new PaintListener() {
@Override
public void paintControl(final PaintEvent arg0) {
- if (!helper.isExternalAnimatorAnimating()) {
- display();
+ if ( !helper.isExternalAnimatorAnimating() ) {
+ display(); // checks: null != drawable
}
}
});
@@ -265,12 +315,112 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
addControlListener(new ControlAdapter() {
@Override
public void controlResized(final ControlEvent arg0) {
- clientArea = GLCanvas.this.getClientArea();
- /* Mark for OpenGL reshape next time the control is painted */
- sendReshape = true;
+ updateSizeCheck();
}
});
}
+ private final ProxySurface.UpstreamSurfaceHook swtCanvasUpStreamHook = new ProxySurface.UpstreamSurfaceHook() {
+ @Override
+ public final void create(ProxySurface s) { /* nop */ }
+
+ @Override
+ public final void destroy(ProxySurface s) { /* nop */ }
+
+ @Override
+ public final int getWidth(ProxySurface s) {
+ return clientArea.width;
+ }
+
+ @Override
+ public final int getHeight(ProxySurface s) {
+ return clientArea.height;
+ }
+
+ @Override
+ public String toString() {
+ return "SWTCanvasUpstreamSurfaceHook[upstream: "+GLCanvas.this.toString()+", "+clientArea.width+"x"+clientArea.height+"]";
+ }
+ };
+
+ protected final void updateSizeCheck() {
+ final Rectangle oClientArea = clientArea;
+ final Rectangle nClientArea = GLCanvas.this.getClientArea();
+ if ( nClientArea != null &&
+ ( nClientArea.width != oClientArea.width || nClientArea.height != oClientArea.height )
+ ) {
+ clientArea = nClientArea; // write back new value
+ sendReshape = true; // Mark for OpenGL reshape next time the control is painted
+ }
+ }
+
+ @Override
+ public void display() {
+ if( null != drawable || validateDrawableAndContext() ) {
+ runInGLThread(makeCurrentAndDisplayOnEDTAction);
+ }
+ }
+
+
+ /** assumes drawable == null ! */
+ protected final boolean validateDrawableAndContext() {
+ if( GLCanvas.this.isDisposed() ) {
+ return false;
+ }
+ final Rectangle nClientArea = clientArea;
+ if(0 == nClientArea.width * nClientArea.height) {
+ return false;
+ }
+
+ final RecursiveLock _lock = lock;
+ _lock.lock();
+ try {
+ final GLDrawableFactory glFactory = GLDrawableFactory.getFactory(capsRequested.getGLProfile());
+
+ /* Native handle for the control, used to associate with GLContext */
+ final long nativeWindowHandle = SWTAccessor.getWindowHandle(this);
+
+ /* Create a NativeWindow proxy for the SWT canvas */
+ ProxySurface proxySurface = null;
+ try {
+ proxySurface = glFactory.createProxySurface(device, 0 /* screenIdx */, nativeWindowHandle,
+ capsRequested, capsChooser, swtCanvasUpStreamHook);
+ } catch (GLException gle) {
+ // not ready yet ..
+ if(DEBUG) { System.err.println(gle.getMessage()); }
+ }
+
+ if(null != proxySurface) {
+ /* Associate a GL surface with the proxy */
+ drawable = glFactory.createGLDrawable(proxySurface);
+ drawable.setRealized(true);
+
+ context = drawable.createContext(shareWith);
+ }
+ } finally {
+ _lock.unlock();
+ }
+ final boolean res = null != drawable;
+ if(DEBUG && res) {
+ System.err.println("SWT GLCanvas realized! "+this+", "+drawable);
+ Thread.dumpStack();
+ }
+ return res;
+ }
+
+ @Override
+ public final Object getUpstreamWidget() {
+ return this;
+ }
+
+ @Override
+ public int getWidth() {
+ return clientArea.width;
+ }
+
+ @Override
+ public int getHeight() {
+ return clientArea.height;
+ }
@Override
public void addGLEventListener(final GLEventListener arg0) {
@@ -296,11 +446,6 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
}
@Override
- public void display() {
- runInGLThread(makeCurrentAndDisplayAction);
- }
-
- @Override
public GLAnimatorControl getAnimator() {
return helper.getAnimator();
}
@@ -312,7 +457,7 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
@Override
public GLContext getContext() {
- return context;
+ return null != drawable ? context : null;
}
@Override
@@ -322,7 +467,8 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
@Override
public GL getGL() {
- return (null == context) ? null : context.getGL();
+ final GLContext _context = context;
+ return (null == _context) ? null : _context.getGL();
}
@Override
@@ -352,27 +498,35 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
@Override
public GLContext setContext(GLContext newCtx) {
- final GLContext oldCtx = context;
- final boolean newCtxCurrent = helper.switchContext(drawable, oldCtx, newCtx, additionalCtxCreationFlags);
- context=(GLContextImpl)newCtx;
- if(newCtxCurrent) {
- context.makeCurrent();
+ final RecursiveLock _lock = lock;
+ _lock.lock();
+ try {
+ final GLContext oldCtx = context;
+ final boolean newCtxCurrent = helper.switchContext(drawable, oldCtx, newCtx, additionalCtxCreationFlags);
+ context=(GLContextImpl)newCtx;
+ if(newCtxCurrent) {
+ context.makeCurrent();
+ }
+ return oldCtx;
+ } finally {
+ _lock.unlock();
}
- return oldCtx;
}
@Override
public void setContextCreationFlags(final int arg0) {
additionalCtxCreationFlags = arg0;
- if(null != context) {
- context.setContextCreationFlags(additionalCtxCreationFlags);
+ final GLContext _context = context;
+ if(null != _context) {
+ _context.setContextCreationFlags(additionalCtxCreationFlags);
}
}
@Override
public GL setGL(final GL arg0) {
- if (null != context) {
- context.setGL(arg0);
+ final GLContext _context = context;
+ if (null != _context) {
+ _context.setGL(arg0);
return arg0;
}
return null;
@@ -380,17 +534,24 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
@Override
public GLContext createContext(final GLContext shareWith) {
- if(drawable != null) {
- final GLContext _ctx = drawable.createContext(shareWith);
- _ctx.setContextCreationFlags(additionalCtxCreationFlags);
- return _ctx;
+ final RecursiveLock _lock = lock;
+ _lock.lock();
+ try {
+ if(drawable != null) {
+ final GLContext _ctx = drawable.createContext(shareWith);
+ _ctx.setContextCreationFlags(additionalCtxCreationFlags);
+ return _ctx;
+ }
+ return null;
+ } finally {
+ _lock.unlock();
}
- return null;
}
@Override
public GLCapabilitiesImmutable getChosenGLCapabilities() {
- return (GLCapabilitiesImmutable)proxySurface.getGraphicsConfiguration().getChosenCapabilities();
+ final GLDrawable _drawable = drawable;
+ return null != _drawable ? (GLCapabilitiesImmutable)_drawable.getChosenGLCapabilities() : null;
}
/**
@@ -399,46 +560,37 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
* @return Non-null GLCapabilities.
*/
public GLCapabilitiesImmutable getRequestedGLCapabilities() {
- return (GLCapabilitiesImmutable)proxySurface.getGraphicsConfiguration().getRequestedCapabilities();
+ final GLDrawable _drawable = drawable;
+ return null != _drawable ? (GLCapabilitiesImmutable)_drawable.getNativeSurface().getGraphicsConfiguration().getRequestedCapabilities() : null;
}
@Override
public GLDrawableFactory getFactory() {
- return (drawable != null) ? drawable.getFactory() : null;
+ final GLDrawable _drawable = drawable;
+ return (_drawable != null) ? _drawable.getFactory() : null;
}
@Override
public GLProfile getGLProfile() {
- return glCapsRequested.getGLProfile();
+ return capsRequested.getGLProfile();
}
@Override
public long getHandle() {
- return (drawable != null) ? drawable.getHandle() : 0;
- }
-
- @Override
- public int getHeight() {
- final Rectangle clientArea = this.clientArea;
- if (clientArea == null) return 0;
- return clientArea.height;
+ final GLDrawable _drawable = drawable;
+ return (_drawable != null) ? _drawable.getHandle() : 0;
}
@Override
public NativeSurface getNativeSurface() {
- return (drawable != null) ? drawable.getNativeSurface() : null;
- }
-
- @Override
- public int getWidth() {
- final Rectangle clientArea = this.clientArea;
- if (clientArea == null) return 0;
- return clientArea.width;
+ final GLDrawable _drawable = drawable;
+ return (_drawable != null) ? _drawable.getNativeSurface() : null;
}
@Override
public boolean isRealized() {
- return (drawable != null) ? drawable.isRealized() : false;
+ final GLDrawable _drawable = drawable;
+ return (_drawable != null) ? _drawable.isRealized() : false;
}
@Override
@@ -448,41 +600,18 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
@Override
public void swapBuffers() throws GLException {
- runInGLThread(makeCurrentAndSwapBuffersAction);
+ runInGLThread(makeCurrentAndSwapBuffersOnEDTAction);
}
- // FIXME: API of update() method ?
@Override
public void update() {
- // FIXME: display();
+ // don't paint background etc .. nop avoids flickering
}
@Override
public void dispose() {
- if (null != drawable && null != context) { // drawable is volatile!
- boolean animatorPaused = false;
- final GLAnimatorControl animator = getAnimator();
- if (null != animator) {
- // can't remove us from animator for recreational addNotify()
- animatorPaused = animator.pause();
- }
-
- if(context.isCreated()) {
- runInGLThread(disposeOnEDTGLAction);
- }
-
- if (animatorPaused) {
- animator.resume();
- }
- }
- final Display display = getDisplay();
-
- if (display.getThread() == Thread.currentThread()) {
- disposeGraphicsDeviceAction.run();
- } else {
- display.syncExec(disposeGraphicsDeviceAction);
- }
- super.dispose();
+ runInGLThread(disposeOnEDTGLAction);
+ super.dispose();
}
/**
@@ -501,7 +630,7 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
* @see Platform#AWT_AVAILABLE
* @see Platform#getOSType()
*/
- private void runInGLThread(final Runnable action) {
+ private static void runInGLThread(final Runnable action) {
if(Platform.OSType.MACOS == Platform.OS_TYPE) {
SWTAccessor.invoke(true, action);
} else {
@@ -515,7 +644,7 @@ public class GLCanvas extends Canvas implements GLAutoDrawable {
// System.err.println(NativeWindowVersion.getInstance());
System.err.println(JoglVersion.getInstance());
- System.err.println(JoglVersion.getDefaultOpenGLInfo(null, true).toString());
+ System.err.println(JoglVersion.getDefaultOpenGLInfo(null, null, true).toString());
final GLCapabilitiesImmutable caps = new GLCapabilities( GLProfile.getDefault(GLProfile.getDefaultDevice()) );
final Display display = new Display();
diff --git a/src/jogl/classes/com/jogamp/opengl/util/FBObject.java b/src/jogl/classes/com/jogamp/opengl/util/FBObject.java
deleted file mode 100644
index 3e049a334..000000000
--- a/src/jogl/classes/com/jogamp/opengl/util/FBObject.java
+++ /dev/null
@@ -1,483 +0,0 @@
-/*
- * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
- * Copyright (c) 2011 JogAmp Community. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * - Redistribution of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistribution in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * Neither the name of Sun Microsystems, Inc. or the names of
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
- * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
- * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
- * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
- * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
- * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
- * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
- * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
- */
-
-package com.jogamp.opengl.util;
-
-import javax.media.opengl.*;
-
-public class FBObject {
- static final int MAX_FBO_TEXTURES = 32; // just for our impl .. not the real 'max' FBO color attachments
- private int[] fbo_tex_names;
- private int[] fbo_tex_units;
- private int fbo_tex_num;
- private int colorattachment_num;
-
- private boolean initialized;
- private int width, height;
- private int fb, depth_rb, stencil_rb, vStatus;
- private boolean bound;
-
- public FBObject(int width, int height) {
- this.fbo_tex_names = new int[MAX_FBO_TEXTURES];
- this.fbo_tex_units = new int[MAX_FBO_TEXTURES];
- this.fbo_tex_num = 0;
- this.colorattachment_num = 0;
- this.initialized = false;
- this.width = width;
- this.height = height;
- this.fb = 0;
- this.depth_rb = 0;
- this.stencil_rb = 0;
- this.bound = false;
- }
-
- /**
- * @return true if the FB status is valid, otherwise false
- * @see #getStatus()
- */
- public boolean isStatusValid() {
- switch(vStatus) {
- case GL.GL_FRAMEBUFFER_COMPLETE:
- return true;
- case GL.GL_FRAMEBUFFER_UNSUPPORTED:
- case GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
- case GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
- case GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
- case GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS:
- //case GL2.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
- //case GL2.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
- //case GL2.GL_FRAMEBUFFER_INCOMPLETE_DUPLICATE_ATTACHMENT:
- case 0:
- default:
- System.out.println("Framebuffer " + fb + " is incomplete: status = 0x" + Integer.toHexString(vStatus) +
- " : " + getStatusString(vStatus));
- return false;
- }
- }
-
- /**
- * @return The FB status. {@link GL.GL_FRAMEBUFFER_COMPLETE} if ok, otherwise return GL FBO error state or -1
- * @see #validateStatus()
- */
- public int getStatus() {
- return vStatus;
- }
-
- public String getStatusString() {
- return getStatusString(vStatus);
- }
-
- public static final String getStatusString(int fbStatus) {
- switch(fbStatus) {
- case -1:
- return "NOT A FBO";
- case GL.GL_FRAMEBUFFER_COMPLETE:
- return "OK";
- case GL.GL_FRAMEBUFFER_UNSUPPORTED:
- return("GL FBO: Unsupported framebuffer format");
- case GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
- return("GL FBO: incomplete, incomplete attachment\n");
- case GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
- return("GL FBO: incomplete, missing attachment");
- case GL.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
- return("GL FBO: incomplete, attached images must have same dimensions");
- case GL.GL_FRAMEBUFFER_INCOMPLETE_FORMATS:
- return("GL FBO: incomplete, attached images must have same format");
- case GL2.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
- return("GL FBO: incomplete, missing draw buffer");
- case GL2.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
- return("GL FBO: incomplete, missing read buffer");
- case GL2.GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
- return("GL FBO: incomplete, missing multisample buffer");
- case 0:
- return("GL FBO: incomplete, implementation fault");
- default:
- return("GL FBO: incomplete, implementation ERROR");
- }
- }
-
- private boolean checkNoError(GL gl, int err, String exceptionMessage) {
- if(GL.GL_NO_ERROR != err) {
- if(null != gl) {
- destroy(gl);
- }
- if(null != exceptionMessage) {
- throw new GLException(exceptionMessage+" GL Error 0x"+Integer.toHexString(err));
- }
- return false;
- }
- return true;
- }
-
- private final void checkInitialized() {
- if(!initialized) {
- throw new GLException("FBO not initialized, call init(GL) first.");
- }
- }
-
- private final void checkBound(GL gl, boolean shallBeBound) {
- checkInitialized();
- if(bound != shallBeBound) {
- final String s0 = shallBeBound ? "not" : "already" ;
- throw new GLException("FBO "+s0+" bound "+toString());
- }
- checkNoError(null, gl.glGetError(), "FBObject pre"); // throws GLException if error
- }
-
- /**
- * Initializes this FBO's instance with it's texture.
- *
- * <p>Leaves the FBO bound!</p>
- *
- * @param gl the current GL context
- * @throws GLException in case of an error
- */
- public void init(GL gl) throws GLException {
- if(initialized) {
- throw new GLException("FBO already initialized");
- }
- checkNoError(null, gl.glGetError(), "FBObject Init.pre"); // throws GLException if error
-
- // generate fbo ..
- int name[] = new int[1];
-
- gl.glGenFramebuffers(1, name, 0);
- fb = name[0];
- if(fb==0) {
- throw new GLException("null generated framebuffer");
- }
-
- // bind fbo ..
- gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, fb);
- checkNoError(gl, gl.glGetError(), "FBObject Init.bindFB"); // throws GLException if error
- if(!gl.glIsFramebuffer(fb)) {
- checkNoError(gl, GL.GL_INVALID_VALUE, "FBObject Init.isFB"); // throws GLException
- }
- bound = true;
- initialized = true;
-
- updateStatus(gl);
- }
-
- /**
- * Attaches a[nother] Texture2D Color Buffer to this FBO's instance,
- * selecting the texture data type and format automatically.
- * <p>This may be done as many times as many color attachments are supported,
- * see {@link GL2GL3#GL_MAX_COLOR_ATTACHMENTS}.</p>
- *
- * <p>Assumes a bound FBO</p>
- * <p>Leaves the FBO bound!</p>
- *
- * @param gl the current GL context
- * @param texUnit the desired texture unit ranging from [0..{@link GL2#GL_MAX_TEXTURE_UNITS}-1], or -1 if no unit shall be activate at {@link #use(GL, int)}
- * @param magFilter if > 0 value for {@link GL#GL_TEXTURE_MAG_FILTER}
- * @param minFilter if > 0 value for {@link GL#GL_TEXTURE_MIN_FILTER}
- * @param wrapS if > 0 value for {@link GL#GL_TEXTURE_WRAP_S}
- * @param wrapT if > 0 value for {@link GL#GL_TEXTURE_WRAP_T}
- * @return idx of the new attached texture, otherwise -1
- * @throws GLException in case of an error
- */
- public int attachTexture2D(GL gl, int texUnit, int magFilter, int minFilter, int wrapS, int wrapT) throws GLException {
- final int textureInternalFormat, textureDataFormat, textureDataType;
- if(gl.isGLES()) {
- textureInternalFormat=GL.GL_RGBA;
- textureDataFormat=GL.GL_RGBA;
- textureDataType=GL.GL_UNSIGNED_BYTE;
- } else {
- textureInternalFormat=GL.GL_RGBA8;
- textureDataFormat=GL.GL_BGRA;
- textureDataType=GL2GL3.GL_UNSIGNED_INT_8_8_8_8_REV;
- }
- return attachTexture2D(gl, texUnit, textureInternalFormat, textureDataFormat, textureDataType, magFilter, minFilter, wrapS, wrapT);
- }
-
- /**
- * Attaches a[nother] Texture2D Color Buffer to this FBO's instance,
- * selecting the texture data type and format automatically.
- * <p>This may be done as many times as many color attachments are supported,
- * see {@link GL2GL3#GL_MAX_COLOR_ATTACHMENTS}.</p>
- *
- * <p>Assumes a bound FBO</p>
- * <p>Leaves the FBO bound!</p>
- *
- * @param gl the current GL context
- * @param texUnit the desired texture unit ranging from [0..{@link GL2#GL_MAX_TEXTURE_UNITS}-1], or -1 if no unit shall be activate at {@link #use(GL, int)}
- * @param textureInternalFormat internalFormat parameter to {@link GL#glTexImage2D(int, int, int, int, int, int, int, int, long)}
- * @param textureDataFormat format parameter to {@link GL#glTexImage2D(int, int, int, int, int, int, int, int, long)}
- * @param textureDataType type parameter to {@link GL#glTexImage2D(int, int, int, int, int, int, int, int, long)}
- * @param magFilter if > 0 value for {@link GL#GL_TEXTURE_MAG_FILTER}
- * @param minFilter if > 0 value for {@link GL#GL_TEXTURE_MIN_FILTER}
- * @param wrapS if > 0 value for {@link GL#GL_TEXTURE_WRAP_S}
- * @param wrapT if > 0 value for {@link GL#GL_TEXTURE_WRAP_T}
- * @return index of the texture colorbuffer if bound and configured successfully, otherwise -1
- * @throws GLException in case the texture colorbuffer couldn't be allocated
- */
- public int attachTexture2D(GL gl, int texUnit,
- int textureInternalFormat, int textureDataFormat, int textureDataType,
- int magFilter, int minFilter, int wrapS, int wrapT) throws GLException {
- checkBound(gl, true);
- final int fbo_tex_idx = fbo_tex_num;
- gl.glGenTextures(1, fbo_tex_names, fbo_tex_num);
- if(fbo_tex_names[fbo_tex_idx]==0) {
- throw new GLException("null generated texture");
- }
- fbo_tex_units[fbo_tex_idx] = texUnit;
- fbo_tex_num++;
- if(0<=texUnit) {
- gl.glActiveTexture(GL.GL_TEXTURE0 + texUnit);
- }
- gl.glBindTexture(GL.GL_TEXTURE_2D, fbo_tex_names[fbo_tex_idx]);
- checkNoError(gl, gl.glGetError(), "FBObject Init.bindTex"); // throws GLException if error
- gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, textureInternalFormat, width, height, 0,
- textureDataFormat, textureDataType, null);
- int glerr = gl.glGetError();
- if(GL.GL_NO_ERROR != glerr) {
- int[] sz = new int[1];
- gl.glGetIntegerv(GL.GL_MAX_TEXTURE_SIZE, sz, 0);
- // throws GLException if error
- checkNoError(gl, glerr, "FBObject Init.texImage2D: "+
- " int-fmt 0x"+Integer.toHexString(textureInternalFormat)+
- ", "+width+"x"+height+
- ", data-fmt 0x"+Integer.toHexString(textureDataFormat)+
- ", data-type 0x"+Integer.toHexString(textureDataType)+
- ", max tex-sz "+sz[0]);
- }
- if( 0 < magFilter ) {
- gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, magFilter);
- }
- if( 0 < minFilter ) {
- gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, minFilter);
- }
- if( 0 < wrapS ) {
- gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, wrapS);
- }
- if( 0 < wrapT ) {
- gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, wrapT);
- }
-
- // Set up the color buffer for use as a renderable texture:
- gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER,
- GL.GL_COLOR_ATTACHMENT0 + colorattachment_num++,
- GL.GL_TEXTURE_2D, fbo_tex_names[fbo_tex_idx], 0);
-
- updateStatus(gl);
- return isStatusValid() ? fbo_tex_idx : -1;
- }
-
- /**
- * Attaches one Depth Buffer to this FBO's instance.
- * <p>This may be done only one time.</p>
- *
- * <p>Assumes a bound FBO</p>
- * <p>Leaves the FBO bound!</p>
- * @param gl the current GL context
- * @param depthComponentType {@link GL#GL_DEPTH_COMPONENT16}, {@link GL#GL_DEPTH_COMPONENT24} or {@link GL#GL_DEPTH_COMPONENT32}
- * @return true if the depth renderbuffer could be bound and configured, otherwise false
- * @throws GLException in case the depth renderbuffer couldn't be allocated or one is already attached.
- */
- public boolean attachDepthBuffer(GL gl, int depthComponentType) throws GLException {
- checkBound(gl, true);
- if(depth_rb != 0) {
- throw new GLException("FBO depth buffer already attached (rb "+depth_rb+")");
- }
- int name[] = new int[1];
- gl.glGenRenderbuffers(1, name, 0);
- depth_rb = name[0];
- if(depth_rb==0) {
- throw new GLException("null generated renderbuffer");
- }
- // Initialize the depth buffer:
- gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, depth_rb);
- if(!gl.glIsRenderbuffer(depth_rb)) {
- System.err.println("not a depthbuffer: "+ depth_rb);
- name[0] = depth_rb;
- gl.glDeleteRenderbuffers(1, name, 0);
- depth_rb=0;
- return false;
- }
-
- gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, depthComponentType, width, height);
- // Set up the depth buffer attachment:
- gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
- GL.GL_DEPTH_ATTACHMENT,
- GL.GL_RENDERBUFFER, depth_rb);
- updateStatus(gl);
- return isStatusValid();
- }
-
- /**
- * Attaches one Stencil Buffer to this FBO's instance.
- * <p>This may be done only one time.</p>
- *
- * <p>Assumes a bound FBO</p>
- * <p>Leaves the FBO bound!</p>
- * @param gl the current GL context
- * @param stencilComponentType {@link GL#GL_STENCIL_INDEX1}, {@link GL#GL_STENCIL_INDEX4} or {@link GL#GL_STENCIL_INDEX8}
- * @return true if the stencil renderbuffer could be bound and configured, otherwise false
- * @throws GLException in case the stencil renderbuffer couldn't be allocated or one is already attached.
- */
- public boolean attachStencilBuffer(GL gl, int stencilComponentType) throws GLException {
- checkBound(gl, true);
- if(stencil_rb != 0) {
- throw new GLException("FBO stencil buffer already attached (rb "+stencil_rb+")");
- }
- int name[] = new int[1];
- gl.glGenRenderbuffers(1, name, 0);
- stencil_rb = name[0];
- if(stencil_rb==0) {
- throw new GLException("null generated stencilbuffer");
- }
- // Initialize the stencil buffer:
- gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, stencil_rb);
- if(!gl.glIsRenderbuffer(stencil_rb)) {
- System.err.println("not a stencilbuffer: "+ stencil_rb);
- name[0] = stencil_rb;
- gl.glDeleteRenderbuffers(1, name, 0);
- stencil_rb=0;
- return false;
- }
- gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, stencilComponentType, width, height);
- gl.glFramebufferRenderbuffer(GL.GL_FRAMEBUFFER,
- GL.GL_STENCIL_ATTACHMENT,
- GL.GL_RENDERBUFFER, stencil_rb);
- updateStatus(gl);
- return isStatusValid();
- }
-
- /**
- * @param gl the current GL context
- */
- public void destroy(GL gl) {
- if(bound) {
- unbind(gl);
- }
-
- int name[] = new int[1];
-
- if(0!=stencil_rb) {
- name[0] = stencil_rb;
- gl.glDeleteRenderbuffers(1, name, 0);
- stencil_rb = 0;
- }
- if(0!=depth_rb) {
- name[0] = depth_rb;
- gl.glDeleteRenderbuffers(1, name, 0);
- depth_rb=0;
- }
- if(null!=fbo_tex_names && fbo_tex_num>0) {
- gl.glDeleteTextures(1, fbo_tex_names, fbo_tex_num);
- fbo_tex_names = new int[MAX_FBO_TEXTURES];
- fbo_tex_units = new int[MAX_FBO_TEXTURES];
- fbo_tex_num = 0;
- }
- colorattachment_num = 0;
- if(0!=fb) {
- name[0] = fb;
- gl.glDeleteFramebuffers(1, name, 0);
- fb = 0;
- }
- initialized = false;
- }
-
- /**
- * Bind this FBO
- * <p>In case you have attached more than one color buffer,
- * you may want to setup {@link GL2GL3#glDrawBuffers(int, int[], int)}.</p>
- * @param gl the current GL context
- */
- public void bind(GL gl) {
- checkBound(gl, false);
- gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, fb);
- bound = true;
- }
-
- /**
- * Unbind FBO, ie bind 'non' FBO 0
- * @param gl the current GL context
- */
- public void unbind(GL gl) {
- checkBound(gl, true);
- gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0);
- bound = false;
- }
-
- /**
- * Bind the texture with given index.
- *
- * <p>If a valid texture unit was named via {@link #attachTexture2D(GL, int, int, int, int, int) attachTexture2D(..)},
- * the unit is activated via {@link GL#glActiveTexture(int) glActiveTexture(GL.GL_TEXTURE0 + unit)}.</p>
- * @param gl the current GL context
- * @param texIdx index of the texture to use, prev. attached w/ {@link #attachTexture2D(GL, int, int, int, int, int) attachTexture2D(..)}
- */
- public void use(GL gl, int texIdx) {
- checkBound(gl, false);
- if(texIdx >= fbo_tex_num) {
- throw new GLException("Invalid texId, only "+fbo_tex_num+" textures are attached");
- }
- if(0<=fbo_tex_units[texIdx]) {
- gl.glActiveTexture(GL.GL_TEXTURE0 + fbo_tex_units[texIdx]);
- }
- gl.glBindTexture(GL.GL_TEXTURE_2D, fbo_tex_names[texIdx]); // use it ..
- }
-
- /** Unbind texture, ie bind 'non' texture 0 */
- public void unuse(GL gl) {
- checkBound(gl, false);
- gl.glBindTexture(GL.GL_TEXTURE_2D, 0); // don't use it
- }
-
- public final boolean isBound() { return bound; }
- public final int getWidth() { return width; }
- public final int getHeight() { return height; }
- public final int getFBName() { return fb; }
- public final int getTextureNumber() { return fbo_tex_num; }
- public final int getTextureName(int idx) { return fbo_tex_names[idx]; }
-
- /** @return the named texture unit ranging from [0..{@link GL2#GL_MAX_TEXTURE_UNITS}-1], or -1 if no unit was desired. */
- public final int getTextureUnit(int idx) { return fbo_tex_units[idx]; }
- public final int getColorAttachmentNumber() { return colorattachment_num; }
- public final int getStencilBuffer() { return stencil_rb; }
- public final int getDepthBuffer() { return depth_rb; }
- public final String toString() {
- return "FBO[name "+fb+", size "+width+"x"+height+", color num "+colorattachment_num+", tex num "+fbo_tex_num+", depth "+depth_rb+", stencil "+stencil_rb+"]";
- }
-
- private void updateStatus(GL gl) {
- if(!gl.glIsFramebuffer(fb)) {
- vStatus = -1;
- } else {
- vStatus = gl.glCheckFramebufferStatus(GL.GL_FRAMEBUFFER);
- }
- }
-}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLBuffers.java b/src/jogl/classes/com/jogamp/opengl/util/GLBuffers.java
index 8401b9cd2..331d6fa4e 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLBuffers.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLBuffers.java
@@ -39,6 +39,7 @@
package com.jogamp.opengl.util;
import com.jogamp.common.nio.Buffers;
+
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
import javax.media.opengl.GL2ES2;
@@ -56,22 +57,32 @@ import java.nio.*;
public class GLBuffers extends Buffers {
/**
- * @param glType shall be one of
- * GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT,
- * GL_UNSIGNED_INT, GL_INT, GL_HALF_FLOAT, GL_FLOAT, GL_DOUBLE,
- * GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
- * GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV,
- * GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV,
- * GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
- * GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,
- * GL_UNSIGNED_INT_10_10_10_2, GL_UNSIGNED_INT_2_10_10_10_REV
- * GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
- * GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT_32_UNSIGNED_INT_24_8_REV,
- * GL_HILO16_NV, GL_SIGNED_HILO16_NV (27)
+ * @param glType shall be one of (29) <br/>
+ * GL_BYTE, GL_UNSIGNED_BYTE, <br/>
+ * GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, <br/>
+ * <br/>
+ * GL_SHORT, GL_UNSIGNED_SHORT, <br/>
+ * GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, <br/>
+ * GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, <br/>
+ * GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, <br/>
+ * GL.GL_HALF_FLOAT, GLES2.GL_HALF_FLOAT_OES: <br/>
+ * <br/>
+ * GL_FIXED, GL_INT <br/>
+ * GL_UNSIGNED_INT, GL_UNSIGNED_INT_8_8_8_8, <br/>
+ * GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2, <br/>
+ * GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, <br/>
+ * GL_UNSIGNED_INT_10F_11F_11F_REV, GL_UNSIGNED_INT_5_9_9_9_REV <br/>
+ * GL_HILO16_NV, GL_SIGNED_HILO16_NV <br/>
+ * <br/>
+ * GL2GL3.GL_FLOAT_32_UNSIGNED_INT_24_8_REV <br/>
+ * <br/>
+ * GL_FLOAT, GL_DOUBLE <br/>
+ *
* @return -1 if glType is unhandled, otherwise the actual value > 0
*/
public static final int sizeOfGLType(int glType) {
- switch (glType) { // 25
+ switch (glType) { // 29
+ // case GL2.GL_BITMAP:
case GL.GL_BYTE:
case GL.GL_UNSIGNED_BYTE:
case GL2GL3.GL_UNSIGNED_BYTE_3_3_2:
@@ -86,6 +97,8 @@ public class GLBuffers extends Buffers {
case GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4_REV:
case GL2GL3.GL_UNSIGNED_SHORT_5_5_5_1:
case GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV:
+ case GL.GL_HALF_FLOAT:
+ case GLES2.GL_HALF_FLOAT_OES:
return SIZEOF_SHORT;
case GL.GL_FIXED:
@@ -108,29 +121,38 @@ public class GLBuffers extends Buffers {
case GL.GL_FLOAT:
return SIZEOF_FLOAT;
- case GL2.GL_DOUBLE:
+ case GL2GL3.GL_DOUBLE:
return SIZEOF_DOUBLE;
}
return -1;
}
/**
- * @param glType shall be one of
- * GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT,
- * GL_UNSIGNED_INT, GL_INT, GL_HALF_FLOAT, GL_FLOAT, GL_DOUBLE,
- * GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
- * GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV,
- * GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV,
- * GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
- * GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,
- * GL_UNSIGNED_INT_10_10_10_2, GL_UNSIGNED_INT_2_10_10_10_REV
- * GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
- * GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT_32_UNSIGNED_INT_24_8_REV,
- * GL_HILO16_NV, GL_SIGNED_HILO16_NV (27)
+ * @param glType shall be one of (29) <br/>
+ * GL_BYTE, GL_UNSIGNED_BYTE, <br/>
+ * GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, <br/>
+ * <br/>
+ * GL_SHORT, GL_UNSIGNED_SHORT, <br/>
+ * GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, <br/>
+ * GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, <br/>
+ * GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, <br/>
+ * GL_HALF_FLOAT, GL_HALF_FLOAT_OES <br/>
+ * <br/>
+ * GL_FIXED, GL_INT <br/>
+ * GL_UNSIGNED_INT, GL_UNSIGNED_INT_8_8_8_8, <br/>
+ * GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2, <br/>
+ * GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, <br/>
+ * GL_UNSIGNED_INT_10F_11F_11F_REV, GL_UNSIGNED_INT_5_9_9_9_REV <br/>
+ * GL_HILO16_NV, GL_SIGNED_HILO16_NV <br/>
+ * <br/>
+ * GL_FLOAT_32_UNSIGNED_INT_24_8_REV <br/>
+ * <br/>
+ * GL_FLOAT, GL_DOUBLE <br/>
+ *
* @return null if glType is unhandled, otherwise the new Buffer object
*/
public static final Buffer newDirectGLBuffer(int glType, int numElements) {
- switch (glType) {
+ switch (glType) { // 29
case GL.GL_BYTE:
case GL.GL_UNSIGNED_BYTE:
case GL2GL3.GL_UNSIGNED_BYTE_3_3_2:
@@ -145,6 +167,8 @@ public class GLBuffers extends Buffers {
case GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4_REV:
case GL2GL3.GL_UNSIGNED_SHORT_5_5_5_1:
case GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV:
+ case GL.GL_HALF_FLOAT:
+ case GLES2.GL_HALF_FLOAT_OES:
return newDirectShortBuffer(numElements);
case GL.GL_FIXED:
@@ -174,18 +198,26 @@ public class GLBuffers extends Buffers {
}
/**
- * @param glType shall be one of
- * GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT,
- * GL_UNSIGNED_INT, GL_INT, GL_HALF_FLOAT, GL_FLOAT, GL_DOUBLE,
- * GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
- * GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV,
- * GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV,
- * GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
- * GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,
- * GL_UNSIGNED_INT_10_10_10_2, GL_UNSIGNED_INT_2_10_10_10_REV
- * GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
- * GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT_32_UNSIGNED_INT_24_8_REV,
- * GL_HILO16_NV, GL_SIGNED_HILO16_NV (27)
+ * @param glType shall be one of (29) <br/>
+ * GL_BYTE, GL_UNSIGNED_BYTE, <br/>
+ * GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, <br/>
+ * <br/>
+ * GL_SHORT, GL_UNSIGNED_SHORT, <br/>
+ * GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, <br/>
+ * GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, <br/>
+ * GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, <br/>
+ * GL_HALF_FLOAT, GL_HALF_FLOAT_OES <br/>
+ * <br/>
+ * GL_FIXED, GL_INT <br/>
+ * GL_UNSIGNED_INT, GL_UNSIGNED_INT_8_8_8_8, <br/>
+ * GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2, <br/>
+ * GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, <br/>
+ * GL_UNSIGNED_INT_10F_11F_11F_REV, GL_UNSIGNED_INT_5_9_9_9_REV <br/>
+ * GL_HILO16_NV, GL_SIGNED_HILO16_NV <br/>
+ * <br/>
+ * GL_FLOAT_32_UNSIGNED_INT_24_8_REV <br/>
+ * <br/>
+ * GL_FLOAT, GL_DOUBLE <br/>
* @return null if glType is unhandled or parent is null or bufLen is 0, otherwise the new Buffer object
*/
public static final Buffer sliceGLBuffer(ByteBuffer parent, int bytePos, int byteLen, int glType) {
@@ -195,7 +227,7 @@ public class GLBuffers extends Buffers {
parent.position(bytePos);
parent.limit(bytePos + byteLen);
- switch (glType) {
+ switch (glType) { // 29
case GL.GL_BYTE:
case GL.GL_UNSIGNED_BYTE:
case GL2GL3.GL_UNSIGNED_BYTE_3_3_2:
@@ -210,6 +242,8 @@ public class GLBuffers extends Buffers {
case GL2GL3.GL_UNSIGNED_SHORT_4_4_4_4_REV:
case GL2GL3.GL_UNSIGNED_SHORT_5_5_5_1:
case GL2GL3.GL_UNSIGNED_SHORT_1_5_5_5_REV:
+ case GL.GL_HALF_FLOAT:
+ case GLES2.GL_HALF_FLOAT_OES:
return parent.asShortBuffer();
case GL.GL_FIXED:
@@ -362,28 +396,46 @@ public class GLBuffers extends Buffers {
*
* @param tmp a pass through integer array of size >= 1 used to store temp data (performance)
*
- * @param format must be one of
- * GL_COLOR_INDEX, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL,
- * GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_LUMINANCE,
- * GL_RG, GL_LUMINANCE_ALPHA,
- * GL_RGB, GL_BGR, GL_RGBA, GL_BGRA, GL_ABGR_EXT,
- * GL_RED_INTEGER, GL_GREEN_INTEGER, GL_BLUE_INTEGER,
- * GL_RG_INTEGER, GL_RGB_INTEGER, GL_BGR_INTEGER,
- * GL_RGBA_INTEGER, GL_BGRA_INTEGER, GL_HILO_NV, GL_SIGNED_HILO_NV (26)
+ * @param format must be one of (26) <br/>
+ * GL_COLOR_INDEX GL_STENCIL_INDEX <br/>
+ * GL_DEPTH_COMPONENT GL_DEPTH_STENCIL <br/>
+ * GL_RED GL_RED_INTEGER <br/>
+ * GL_GREEN GL_GREEN_INTEGER <br/>
+ * GL_BLUE GL_BLUE_INTEGER <br/>
+ * GL_ALPHA GL_LUMINANCE (12) <br/>
+ * <br/>
+ * GL_LUMINANCE_ALPHA GL_RG <br/>
+ * GL_RG_INTEGER GL_HILO_NV <br/>
+ * GL_SIGNED_HILO_NV (5) <br/>
+ * <br/>
+ * GL_RGB GL_RGB_INTEGER <br/>
+ * GL_BGR GL_BGR_INTEGER (4)<br/>
+ * <br/>
+ * GL_RGBA GL_RGBA_INTEGER <br/>
+ * GL_BGRA GL_BGRA_INTEGER <br/>
+ * GL_ABGR_EXT (5)<br/>
*
- * @param type must be one of
- * GL_BITMAP,
- * GL_UNSIGNED_BYTE, GL_BYTE, GL_UNSIGNED_SHORT, GL_SHORT,
- * GL_UNSIGNED_INT, GL_INT, GL_HALF_FLOAT, GL_FLOAT, GL_DOUBLE,
- * GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV,
- * GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV,
- * GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV,
- * GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV,
- * GL_UNSIGNED_INT_8_8_8_8, GL_UNSIGNED_INT_8_8_8_8_REV,
- * GL_UNSIGNED_INT_10_10_10_2, GL_UNSIGNED_INT_2_10_10_10_REV
- * GL_UNSIGNED_INT_24_8, GL_UNSIGNED_INT_10F_11F_11F_REV,
- * GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT_32_UNSIGNED_INT_24_8_REV,
- * GL_HILO16_NV, GL_SIGNED_HILO16_NV (28)
+ * @param type must be one of (30) <br/>
+ * GL_BITMAP, <br/>
+ * GL_BYTE, GL_UNSIGNED_BYTE, <br/>
+ * GL_UNSIGNED_BYTE_3_3_2, GL_UNSIGNED_BYTE_2_3_3_REV, <br/>
+ * <br/>
+ * GL_SHORT, GL_UNSIGNED_SHORT, <br/>
+ * GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5_REV, <br/>
+ * GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_4_4_4_4_REV, <br/>
+ * GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_1_5_5_5_REV, <br/>
+ * GL_HALF_FLOAT, GL_HALF_FLOAT_OES <br/>
+ * <br/>
+ * GL_FIXED, GL_INT <br/>
+ * GL_UNSIGNED_INT, GL_UNSIGNED_INT_8_8_8_8, <br/>
+ * GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2, <br/>
+ * GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT_24_8, <br/>
+ * GL_UNSIGNED_INT_10F_11F_11F_REV, GL_UNSIGNED_INT_5_9_9_9_REV <br/>
+ * GL_HILO16_NV, GL_SIGNED_HILO16_NV <br/>
+ * <br/>
+ * GL_FLOAT_32_UNSIGNED_INT_24_8_REV <br/>
+ * <br/>
+ * GL_FLOAT, GL_DOUBLE <br/>
*
* @param width in pixels
* @param height in pixels
@@ -402,7 +454,7 @@ public class GLBuffers extends Buffers {
if (height < 0) return 0;
if (depth < 0) return 0;
- switch (format) /* 24 */ {
+ switch (format) /* 26 */ {
case GL2.GL_COLOR_INDEX:
case GL2GL3.GL_STENCIL_INDEX:
case GL2GL3.GL_DEPTH_COMPONENT:
@@ -445,7 +497,7 @@ public class GLBuffers extends Buffers {
throw new GLException("format 0x"+Integer.toHexString(format)+" not supported [yet], pls notify the maintainer in case this is our bug.");
}
- switch (type) /* 26 */ {
+ switch (type) /* 30 */ {
case GL2.GL_BITMAP:
if (GL2.GL_COLOR_INDEX == format || GL2GL3.GL_STENCIL_INDEX == format) {
return (depth * (height * ((width+7)/8)));
@@ -460,6 +512,7 @@ public class GLBuffers extends Buffers {
case GLES2.GL_HALF_FLOAT_OES:
esize = 2;
break;
+ case GL.GL_FIXED:
case GL2ES2.GL_INT:
case GL.GL_UNSIGNED_INT:
case GL.GL_FLOAT:
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java b/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java
index 368cbc0a2..b0fae8a6d 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLReadBufferUtil.java
@@ -35,6 +35,7 @@ import java.io.IOException;
import java.nio.*;
import javax.media.opengl.*;
+import com.jogamp.opengl.GLExtensions;
import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureData;
import com.jogamp.opengl.util.texture.TextureIO;
@@ -67,6 +68,10 @@ public class GLReadBufferUtil {
return null!=readTextureData && null!=readPixelBuffer ;
}
+ public boolean hasAlpha() { return 4 == components ? true : false ; }
+
+ public GLPixelStorageModes getGLPixelStorageModes() { return psm; }
+
/**
* @return the raw pixel ByteBuffer, filled by {@link #readPixels(GLAutoDrawable, boolean)}
*/
@@ -104,13 +109,14 @@ public class GLReadBufferUtil {
/**
* Read the drawable's pixels to TextureData and Texture, if requested at construction
*
- * @param gl the current GL object
+ * @param gl the current GL context object. It's read drawable is being used as the pixel source.
* @param drawable the drawable to read from
* @param flip weather to flip the data vertically or not
*
* @see #GLReadBufferUtil(boolean, boolean)
*/
- public boolean readPixels(GL gl, GLDrawable drawable, boolean flip) {
+ public boolean readPixels(GL gl, boolean flip) {
+ final GLDrawable drawable = gl.getContext().getGLReadDrawable();
final int textureInternalFormat, textureDataFormat, textureDataType;
final int[] glImplColorReadVals = new int[] { 0, 0 };
@@ -118,7 +124,7 @@ public class GLReadBufferUtil {
textureInternalFormat=GL.GL_RGB;
textureDataFormat=GL.GL_RGB;
textureDataType = GL.GL_UNSIGNED_BYTE;
- } else if(gl.isGLES2Compatible() || gl.isExtensionAvailable("GL_OES_read_format")) {
+ } else if(gl.isGLES2Compatible() || gl.isExtensionAvailable(GLExtensions.OES_read_format)) {
gl.glGetIntegerv(GL.GL_IMPLEMENTATION_COLOR_READ_FORMAT, glImplColorReadVals, 0);
gl.glGetIntegerv(GL.GL_IMPLEMENTATION_COLOR_READ_TYPE, glImplColorReadVals, 1);
textureInternalFormat = (4 == components) ? GL.GL_RGBA : GL.GL_RGB;
diff --git a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
index 3b817afcf..cf0373044 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/ImmModeSink.java
@@ -1,15 +1,20 @@
package com.jogamp.opengl.util;
-import com.jogamp.common.util.*;
-import com.jogamp.opengl.util.glsl.ShaderState;
+import java.nio.Buffer;
+import java.nio.ByteBuffer;
+import java.nio.ShortBuffer;
+import java.util.ArrayList;
+import java.util.Iterator;
-import javax.media.opengl.*;
-import javax.media.opengl.fixedfunc.*;
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2ES1;
+import javax.media.opengl.GL2ES2;
+import javax.media.opengl.GLException;
+import javax.media.opengl.fixedfunc.GLPointerFunc;
-import java.nio.*;
-import java.util.Iterator;
-import java.util.ArrayList;
+import com.jogamp.common.util.ReflectionUtil;
+import com.jogamp.opengl.util.glsl.ShaderState;
public class ImmModeSink {
@@ -337,10 +342,8 @@ public class ImmModeSink {
enableBuffer(gl, true);
if (buffer!=null) {
- GL2ES1 glf = gl.getGL2ES1();
-
if(null==indices) {
- glf.glDrawArrays(mode, 0, count);
+ gl.glDrawArrays(mode, 0, count);
} else {
Class<?> clazz = indices.getClass();
int type=-1;
@@ -352,7 +355,7 @@ public class ImmModeSink {
if(0>type) {
throw new GLException("Given Buffer Class not supported: "+clazz+", should be ubyte or ushort:\n\t"+this);
}
- glf.glDrawElements(mode, indices.remaining(), type, indices);
+ gl.glDrawElements(mode, indices.remaining(), type, indices);
// GL2: gl.glDrawRangeElements(mode, 0, indices.remaining()-1, indices.remaining(), type, indices);
}
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/awt/Screenshot.java b/src/jogl/classes/com/jogamp/opengl/util/awt/Screenshot.java
index fa66673fd..0022d5c2d 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/awt/Screenshot.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/awt/Screenshot.java
@@ -48,6 +48,7 @@ import javax.media.opengl.GLException;
import javax.media.opengl.glu.gl2.GLUgl2;
import com.jogamp.common.util.IOUtil;
+import com.jogamp.opengl.GLExtensions;
import com.jogamp.opengl.util.GLPixelStorageModes;
import com.jogamp.opengl.util.TGAWriter;
@@ -392,7 +393,7 @@ public class Screenshot {
private static void checkExtABGR() {
GL2 gl = GLUgl2.getCurrentGL2();
- if (!gl.isExtensionAvailable("GL_EXT_abgr")) {
+ if (!gl.isExtensionAvailable(GLExtensions.EXT_abgr)) {
throw new IllegalArgumentException("Saving alpha channel requires GL_EXT_abgr");
}
}
diff --git a/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java
index 622ee1b79..1735fcddd 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/awt/TextRenderer.java
@@ -41,6 +41,7 @@ package com.jogamp.opengl.util.awt;
import com.jogamp.common.nio.Buffers;
+import com.jogamp.opengl.GLExtensions;
import com.jogamp.opengl.util.*;
import com.jogamp.opengl.util.packrect.*;
import com.jogamp.opengl.util.texture.*;
@@ -1976,7 +1977,7 @@ public class TextRenderer {
private final boolean is15Available(GL gl) {
if (!checkFor_isExtensionAvailable_GL_VERSION_1_5) {
- isExtensionAvailable_GL_VERSION_1_5 = gl.isExtensionAvailable("GL_VERSION_1_5");
+ isExtensionAvailable_GL_VERSION_1_5 = gl.isExtensionAvailable(GLExtensions.VERSION_1_5);
checkFor_isExtensionAvailable_GL_VERSION_1_5 = true;
}
return isExtensionAvailable_GL_VERSION_1_5;
diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java b/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java
index 49d4add5f..e7bf87a36 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java
@@ -44,6 +44,7 @@ import javax.media.nativewindow.NativeWindowFactory;
import jogamp.opengl.*;
+import com.jogamp.opengl.GLExtensions;
import com.jogamp.opengl.util.texture.spi.*;
/**
@@ -262,8 +263,8 @@ public class Texture {
*
* See the <a href="#perftips">performance tips</a> above for hints
* on how to maximize performance when using many Texture objects.
- * @param gl TODO
- *
+ *
+ * @param gl the current GL context
* @throws GLException if no OpenGL context was current or if any
* OpenGL-related errors occurred
*/
@@ -448,12 +449,12 @@ public class Texture {
// See whether we have automatic mipmap generation support
boolean haveAutoMipmapGeneration =
- (gl.isExtensionAvailable("GL_VERSION_1_4") ||
- gl.isExtensionAvailable("GL_SGIS_generate_mipmap"));
+ (gl.isExtensionAvailable(GLExtensions.VERSION_1_4) ||
+ gl.isExtensionAvailable(GLExtensions.SGIS_generate_mipmap));
// Indicate to the TextureData what functionality is available
- data.setHaveEXTABGR(gl.isExtensionAvailable("GL_EXT_abgr"));
- data.setHaveGL12(gl.isExtensionAvailable("GL_VERSION_1_2"));
+ data.setHaveEXTABGR(gl.isExtensionAvailable(GLExtensions.EXT_abgr));
+ data.setHaveGL12(gl.isExtensionAvailable(GLExtensions.VERSION_1_2));
// Indicates whether both width and height are power of two
boolean isPOT = isPowerOfTwo(imgWidth) && isPowerOfTwo(imgHeight);
@@ -646,7 +647,7 @@ public class Texture {
int minFilter = (data.getMipmap() ? GL.GL_LINEAR_MIPMAP_LINEAR : GL.GL_LINEAR);
int magFilter = GL.GL_LINEAR;
- int wrapMode = (gl.isExtensionAvailable("GL_VERSION_1_2") || !gl.isGL2()) ? GL.GL_CLAMP_TO_EDGE : GL2.GL_CLAMP;
+ int wrapMode = (gl.isExtensionAvailable(GLExtensions.VERSION_1_2) || !gl.isGL2()) ? GL.GL_CLAMP_TO_EDGE : GL2.GL_CLAMP;
// REMIND: figure out what to do for GL_TEXTURE_RECTANGLE_ARB
if (texTarget != GL2.GL_TEXTURE_RECTANGLE_ARB) {
@@ -925,8 +926,8 @@ public class Texture {
private void updateSubImageImpl(GL gl, TextureData data, int newTarget, int mipmapLevel,
int dstx, int dsty,
int srcx, int srcy, int width, int height) throws GLException {
- data.setHaveEXTABGR(gl.isExtensionAvailable("GL_EXT_abgr"));
- data.setHaveGL12(gl.isExtensionAvailable("GL_VERSION_1_2"));
+ data.setHaveEXTABGR(gl.isExtensionAvailable(GLExtensions.EXT_abgr));
+ data.setHaveGL12(gl.isExtensionAvailable(GLExtensions.VERSION_1_2));
Buffer buffer = data.getBuffer();
if (buffer == null && data.getMipmapData() == null) {
@@ -1044,8 +1045,8 @@ public class Texture {
case GL.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
case GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
- if (!gl.isExtensionAvailable("GL_EXT_texture_compression_s3tc") &&
- !gl.isExtensionAvailable("GL_NV_texture_compression_vtc")) {
+ if (!gl.isExtensionAvailable(GLExtensions.EXT_texture_compression_s3tc) &&
+ !gl.isExtensionAvailable(GLExtensions.NV_texture_compression_vtc)) {
throw new GLException("DXTn compressed textures not supported by this graphics card");
}
break;
@@ -1081,7 +1082,7 @@ public class Texture {
private static boolean haveTexRect(GL gl) {
return (!disableTexRect &&
TextureIO.isTexRectEnabled() &&
- gl.isExtensionAvailable("GL_ARB_texture_rectangle"));
+ gl.isExtensionAvailable(GLExtensions.ARB_texture_rectangle));
}
private static boolean preferTexRect(GL gl) {
diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java
index ca97cdc4b..b878c6002 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java
@@ -155,6 +155,14 @@ public class TextureIO {
file. */
public static final String TIFF = "tiff";
+ /** Constant which can be used as a file suffix to indicate a PAM
+ file, NetPbm magic 7 - binary RGB and RGBA. Write support only. */
+ public static final String PAM = "pam";
+
+ /** Constant which can be used as a file suffix to indicate a PAM
+ file, NetPbm magic 6 - binary RGB. Write support only. */
+ public static final String PPM = "ppm";
+
private static final boolean DEBUG = Debug.debug("TextureIO");
// For manually disabling the use of the texture rectangle
diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java
index 5ee2104a3..6b41c0bc8 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java
@@ -102,7 +102,6 @@ import javax.media.opengl.GL;
*/
public interface TextureSequence {
public static final String GL_OES_EGL_image_external_Required_Prelude = "#extension GL_OES_EGL_image_external : enable\n";
- public static final String GL_OES_EGL_image_external = "GL_OES_EGL_image_external";
public static final String samplerExternalOES = "samplerExternalOES";
public static final String sampler2D = "sampler2D";
diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/NetPbmTextureWriter.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/NetPbmTextureWriter.java
index c2b131b97..cd42a1157 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/NetPbmTextureWriter.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/NetPbmTextureWriter.java
@@ -77,8 +77,10 @@ public class NetPbmTextureWriter implements TextureWriter {
public int getMagic() { return magic; }
- public static final String PPM = "ppm";
- public static final String PAM = "pam";
+ /** @see TextureIO#PPM */
+ public static final String PPM = TextureIO.PPM;
+ /** @see TextureIO#PAM */
+ public static final String PAM = TextureIO.PAM;
public String getSuffix() { return (magic==6)?PPM:PAM; }