aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/javax/media/opengl/GLCapabilities.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/javax/media/opengl/GLCapabilities.java')
-rw-r--r--src/jogl/classes/javax/media/opengl/GLCapabilities.java317
1 files changed, 186 insertions, 131 deletions
diff --git a/src/jogl/classes/javax/media/opengl/GLCapabilities.java b/src/jogl/classes/javax/media/opengl/GLCapabilities.java
index 8b832b310..b825d6388 100644
--- a/src/jogl/classes/javax/media/opengl/GLCapabilities.java
+++ b/src/jogl/classes/javax/media/opengl/GLCapabilities.java
@@ -1,22 +1,22 @@
/*
* Copyright (c) 2003-2009 Sun Microsystems, Inc. All Rights Reserved.
* Copyright (c) 2010 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
@@ -29,11 +29,11 @@
* 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.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
- *
+ *
* Sun gratefully acknowledges that this software was originally authored
* and developed by Kenneth Bradley Russell and Christopher John Kline.
*/
@@ -41,6 +41,7 @@
package javax.media.opengl;
import javax.media.nativewindow.Capabilities;
+import javax.media.nativewindow.CapabilitiesImmutable;
/** Specifies a set of OpenGL capabilities.<br>
At creation time of a {@link GLDrawable} using {@link GLDrawableFactory},
@@ -49,13 +50,15 @@ import javax.media.nativewindow.Capabilities;
must support, such as the OpenGL profile, color depth and whether stereo is enabled.<br>
The actual capabilites of created {@link GLDrawable}s are then reflected by their own
- GLCapabilites instance, which can be queried with {@link GLDrawable#getGLCapabilities()}.<br>
+ GLCapabilites instance, which can be queried with {@link GLDrawable#getChosenGLCapabilities()}.
+ <br>
It currently contains the minimal number of routines which allow
configuration on all supported window systems. */
public class GLCapabilities extends Capabilities implements Cloneable, GLCapabilitiesImmutable {
- private GLProfile glProfile = null;
- private boolean pbuffer = false;
+ private GLProfile glProfile = null;
+ private boolean isPBuffer = false;
+ private boolean isFBO = false;
private boolean doubleBuffered = true;
private boolean stereo = false;
private boolean hardwareAccelerated = true;
@@ -73,11 +76,6 @@ public class GLCapabilities extends Capabilities implements Cloneable, GLCapabil
private boolean sampleBuffers = false;
private int numSamples = 2;
- // Bits for pbuffer creation
- private boolean pbufferFloatingPointBuffers;
- private boolean pbufferRenderToTexture;
- private boolean pbufferRenderToTextureRectangle;
-
/** Creates a GLCapabilities object. All attributes are in a default state.
* @param glp GLProfile, or null for the default GLProfile
* @throws GLException if no profile is given and no default profile is available for the default device.
@@ -86,10 +84,12 @@ public class GLCapabilities extends Capabilities implements Cloneable, GLCapabil
glProfile = (null!=glp)?glp:GLProfile.getDefault(GLProfile.getDefaultDevice());
}
+ @Override
public Object cloneMutable() {
return clone();
}
+ @Override
public Object clone() {
try {
return super.clone();
@@ -98,27 +98,53 @@ public class GLCapabilities extends Capabilities implements Cloneable, GLCapabil
}
}
+ /**
+ * Copies all {@link GLCapabilities} and {@link Capabilities} values
+ * from <code>source</code> into this instance.
+ * @return this instance
+ */
+ public GLCapabilities copyFrom(GLCapabilitiesImmutable source) {
+ super.copyFrom(source);
+ glProfile = source.getGLProfile();
+ isPBuffer = source.isPBuffer();
+ isFBO = source.isFBO();
+ doubleBuffered = source.getDoubleBuffered();
+ stereo = source.getStereo();
+ hardwareAccelerated = source.getHardwareAccelerated();
+ depthBits = source.getDepthBits();
+ stencilBits = source.getStencilBits();
+ accumRedBits = source.getAccumRedBits();
+ accumGreenBits = source.getAccumGreenBits();
+ accumBlueBits = source.getAccumBlueBits();
+ accumAlphaBits = source.getAccumAlphaBits();
+ sampleBuffers = source.getSampleBuffers();
+ numSamples = source.getNumSamples();
+ sampleExtension = source.getSampleExtension();
+ return this;
+ }
+
+ @Override
public int hashCode() {
// 31 * x == (x << 5) - x
- int hash = 31 + this.glProfile.hashCode() ;
- hash = ((hash << 5) - hash) + ( this.pbuffer ? 1 : 0 );
- hash = ((hash << 5) - hash) + ( this.stereo ? 1 : 0 );
+ int hash = super.hashCode();
+ hash = ((hash << 5) - hash) + this.glProfile.hashCode() ;
hash = ((hash << 5) - hash) + ( this.hardwareAccelerated ? 1 : 0 );
+ hash = ((hash << 5) - hash) + ( this.stereo ? 1 : 0 );
+ hash = ((hash << 5) - hash) + ( this.isFBO ? 1 : 0 );
+ hash = ((hash << 5) - hash) + ( this.isPBuffer ? 1 : 0 );
+ hash = ((hash << 5) - hash) + ( this.sampleBuffers ? 1 : 0 );
+ hash = ((hash << 5) - hash) + this.getNumSamples();
+ hash = ((hash << 5) - hash) + this.sampleExtension.hashCode();
hash = ((hash << 5) - hash) + this.depthBits;
hash = ((hash << 5) - hash) + this.stencilBits;
hash = ((hash << 5) - hash) + this.accumRedBits;
hash = ((hash << 5) - hash) + this.accumGreenBits;
hash = ((hash << 5) - hash) + this.accumBlueBits;
hash = ((hash << 5) - hash) + this.accumAlphaBits;
- hash = ((hash << 5) - hash) + ( this.sampleBuffers ? 1 : 0 );
- hash = ((hash << 5) - hash) + this.numSamples;
- hash = ((hash << 5) - hash) + this.sampleExtension.hashCode();
- hash = ((hash << 5) - hash) + ( this.pbufferFloatingPointBuffers ? 1 : 0 );
- hash = ((hash << 5) - hash) + ( this.pbufferRenderToTexture ? 1 : 0 );
- hash = ((hash << 5) - hash) + ( this.pbufferRenderToTextureRectangle ? 1 : 0 );
return hash;
}
+ @Override
public boolean equals(Object obj) {
if(this == obj) { return true; }
if(!(obj instanceof GLCapabilitiesImmutable)) {
@@ -127,7 +153,9 @@ public class GLCapabilities extends Capabilities implements Cloneable, GLCapabil
GLCapabilitiesImmutable other = (GLCapabilitiesImmutable)obj;
boolean res = super.equals(obj) &&
other.getGLProfile()==glProfile &&
- other.isPBuffer()==pbuffer &&
+ other.isPBuffer()==isPBuffer &&
+ other.isFBO()==isFBO &&
+ other.getDoubleBuffered() == doubleBuffered &&
other.getStereo()==stereo &&
other.getHardwareAccelerated()==hardwareAccelerated &&
other.getDepthBits()==depthBits &&
@@ -136,52 +164,54 @@ public class GLCapabilities extends Capabilities implements Cloneable, GLCapabil
other.getAccumGreenBits()==accumGreenBits &&
other.getAccumBlueBits()==accumBlueBits &&
other.getAccumAlphaBits()==accumAlphaBits &&
- other.getSampleBuffers()==sampleBuffers &&
- other.getPbufferFloatingPointBuffers()==pbufferFloatingPointBuffers &&
- other.getPbufferRenderToTexture()==pbufferRenderToTexture &&
- other.getPbufferRenderToTextureRectangle()==pbufferRenderToTextureRectangle;
- if(sampleBuffers) {
- res = res &&
- other.getNumSamples()==numSamples &&
+ other.getSampleBuffers()==sampleBuffers;
+ if(res && sampleBuffers) {
+ res = other.getNumSamples()==getNumSamples() &&
other.getSampleExtension().equals(sampleExtension) ;
}
return res;
}
/** comparing hw/sw, stereo, multisample, stencil, RGBA and depth only */
- public int compareTo(Object o) {
- if ( ! ( o instanceof GLCapabilities ) ) {
+ @Override
+ public int compareTo(final CapabilitiesImmutable o) {
+ if ( ! ( o instanceof GLCapabilitiesImmutable ) ) {
Class<?> c = (null != o) ? o.getClass() : null ;
- throw new ClassCastException("Not a GLCapabilities object: " + c);
+ throw new ClassCastException("Not a GLCapabilitiesImmutable object, but " + c);
}
+ final GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) o;
- final GLCapabilities caps = (GLCapabilities) o;
+ if(hardwareAccelerated && !caps.getHardwareAccelerated()) {
+ return 1;
+ } else if(!hardwareAccelerated && caps.getHardwareAccelerated()) {
+ return -1;
+ }
- if(hardwareAccelerated && !caps.hardwareAccelerated) {
+ if(stereo && !caps.getStereo()) {
return 1;
- } else if(!hardwareAccelerated && caps.hardwareAccelerated) {
+ } else if(!stereo && caps.getStereo()) {
return -1;
}
- if(stereo && !caps.stereo) {
+ if(doubleBuffered && !caps.getDoubleBuffered()) {
return 1;
- } else if(!stereo && caps.stereo) {
+ } else if(!doubleBuffered && caps.getDoubleBuffered()) {
return -1;
}
- final int ms = sampleBuffers ? numSamples : 0;
- final int xms = caps.sampleBuffers ? caps.numSamples : 0;
+ final int ms = getNumSamples();
+ final int xms = caps.getNumSamples() ;
if(ms > xms) {
return 1;
} else if( ms < xms ) {
return -1;
}
- // ignore the sample extension
+ // ignore the sample extension
- if(stencilBits > caps.stencilBits) {
+ if(stencilBits > caps.getStencilBits()) {
return 1;
- } else if(stencilBits < caps.stencilBits) {
+ } else if(stencilBits < caps.getStencilBits()) {
return -1;
}
@@ -190,16 +220,17 @@ public class GLCapabilities extends Capabilities implements Cloneable, GLCapabil
return sc;
}
- if(depthBits > caps.depthBits) {
+ if(depthBits > caps.getDepthBits()) {
return 1;
- } else if(depthBits < caps.depthBits) {
+ } else if(depthBits < caps.getDepthBits()) {
return -1;
}
return 0; // they are equal: hw/sw, stereo, multisample, stencil, RGBA and depth
}
- public GLProfile getGLProfile() {
+ @Override
+ public final GLProfile getGLProfile() {
return glProfile;
}
@@ -208,35 +239,56 @@ public class GLCapabilities extends Capabilities implements Cloneable, GLCapabil
glProfile=profile;
}
- public boolean isPBuffer() {
- return pbuffer;
+ @Override
+ public final boolean isPBuffer() {
+ return isPBuffer;
}
- /**
- * Enables or disables pbuffer usage.<br>
- * If enabled this method also invokes {@link #setOnscreen(int) setOnscreen(false)}<br>
+ /**
+ * Requesting offscreen pbuffer mode.
+ * <p>
+ * If enabled this method also invokes {@link #setOnscreen(boolean) setOnscreen(false)}.
+ * </p>
+ * <p>
* Defaults to false.
+ * </p>
+ * <p>
+ * Requesting offscreen pbuffer mode disables the offscreen auto selection.
+ * </p>
*/
public void setPBuffer(boolean enable) {
if(enable) {
setOnscreen(false);
}
- pbuffer = enable;
+ isPBuffer = enable;
+ }
+
+ @Override
+ public final boolean isFBO() {
+ return isFBO;
}
/**
- * Sets whether the drawable surface supports onscreen.<br>
- * If enabled this method also invokes {@link #setPBuffer(int) setPBuffer(false)}<br>
- * Defaults to true.
- */
- public void setOnscreen(boolean onscreen) {
- if(onscreen) {
- setPBuffer(false);
+ * Requesting offscreen FBO mode.
+ * <p>
+ * If enabled this method also invokes {@link #setOnscreen(boolean) setOnscreen(false)}.
+ * </p>
+ * <p>
+ * Defaults to false.
+ * </p>
+ * <p>
+ * Requesting offscreen FBO mode disables the offscreen auto selection.
+ * </p>
+ */
+ public void setFBO(boolean enable) {
+ if(enable) {
+ setOnscreen(false);
}
- super.setOnscreen(onscreen);
+ isFBO = enable;
}
- public boolean getDoubleBuffered() {
+ @Override
+ public final boolean getDoubleBuffered() {
return doubleBuffered;
}
@@ -245,25 +297,28 @@ public class GLCapabilities extends Capabilities implements Cloneable, GLCapabil
doubleBuffered = enable;
}
- public boolean getStereo() {
+ @Override
+ public final boolean getStereo() {
return stereo;
}
-
+
/** Enables or disables stereo viewing. */
public void setStereo(boolean enable) {
stereo = enable;
}
- public boolean getHardwareAccelerated() {
+ @Override
+ public final boolean getHardwareAccelerated() {
return hardwareAccelerated;
}
-
+
/** Enables or disables hardware acceleration. */
public void setHardwareAccelerated(boolean enable) {
hardwareAccelerated = enable;
}
- public int getDepthBits() {
+ @Override
+ public final int getDepthBits() {
return depthBits;
}
@@ -271,8 +326,9 @@ public class GLCapabilities extends Capabilities implements Cloneable, GLCapabil
public void setDepthBits(int depthBits) {
this.depthBits = depthBits;
}
-
- public int getStencilBits() {
+
+ @Override
+ public final int getStencilBits() {
return stencilBits;
}
@@ -280,8 +336,9 @@ public class GLCapabilities extends Capabilities implements Cloneable, GLCapabil
public void setStencilBits(int stencilBits) {
this.stencilBits = stencilBits;
}
-
- public int getAccumRedBits() {
+
+ @Override
+ public final int getAccumRedBits() {
return accumRedBits;
}
@@ -293,7 +350,8 @@ public class GLCapabilities extends Capabilities implements Cloneable, GLCapabil
this.accumRedBits = accumRedBits;
}
- public int getAccumGreenBits() {
+ @Override
+ public final int getAccumGreenBits() {
return accumGreenBits;
}
@@ -305,7 +363,8 @@ public class GLCapabilities extends Capabilities implements Cloneable, GLCapabil
this.accumGreenBits = accumGreenBits;
}
- public int getAccumBlueBits() {
+ @Override
+ public final int getAccumBlueBits() {
return accumBlueBits;
}
@@ -317,7 +376,8 @@ public class GLCapabilities extends Capabilities implements Cloneable, GLCapabil
this.accumBlueBits = accumBlueBits;
}
- public int getAccumAlphaBits() {
+ @Override
+ public final int getAccumAlphaBits() {
return accumAlphaBits;
}
@@ -333,14 +393,15 @@ public class GLCapabilities extends Capabilities implements Cloneable, GLCapabil
* Sets the desired extension for full-scene antialiasing
* (FSAA), default is {@link #DEFAULT_SAMPLE_EXTENSION}.
*/
- public void setSampleExtension(String se) {
- sampleExtension = se;
+ public void setSampleExtension(String se) {
+ sampleExtension = se;
}
-
- public String getSampleExtension() {
- return sampleExtension;
+
+ @Override
+ public final String getSampleExtension() {
+ return sampleExtension;
}
-
+
/**
* Defaults to false.<br>
* Indicates whether sample buffers for full-scene antialiasing
@@ -353,65 +414,40 @@ public class GLCapabilities extends Capabilities implements Cloneable, GLCapabil
sampleBuffers = enable;
if(sampleBuffers && getAlphaBits()==0) {
setAlphaBits(1);
- }
+ }
}
- public boolean getSampleBuffers() {
+ @Override
+ public final boolean getSampleBuffers() {
return sampleBuffers;
}
- /** If sample buffers are enabled, indicates the number of buffers
- to be allocated. Defaults to 2. */
+ /**
+ * If sample buffers are enabled, indicates the number of buffers
+ * to be allocated. Defaults to 2.
+ * @see #getNumSamples()
+ */
public void setNumSamples(int numSamples) {
this.numSamples = numSamples;
}
- public int getNumSamples() {
- return numSamples;
- }
-
- /** For pbuffers only, indicates whether floating-point buffers
- should be used if available. Defaults to false. */
- public void setPbufferFloatingPointBuffers(boolean enable) {
- pbufferFloatingPointBuffers = enable;
- }
-
- public boolean getPbufferFloatingPointBuffers() {
- return pbufferFloatingPointBuffers;
- }
-
- /** For pbuffers only, indicates whether the render-to-texture
- extension should be used if available. Defaults to false. */
- public void setPbufferRenderToTexture(boolean enable) {
- pbufferRenderToTexture = enable;
- }
-
- public boolean getPbufferRenderToTexture() {
- return pbufferRenderToTexture;
- }
-
- /** For pbuffers only, indicates whether the
- render-to-texture-rectangle extension should be used if
- available. Defaults to false. */
- public void setPbufferRenderToTextureRectangle(boolean enable) {
- pbufferRenderToTextureRectangle = enable;
- }
-
- public boolean getPbufferRenderToTextureRectangle() {
- return pbufferRenderToTextureRectangle;
+ @Override
+ public final int getNumSamples() {
+ return sampleBuffers ? numSamples : 0;
}
+ @Override
public StringBuilder toString(StringBuilder sink) {
if(null == sink) {
sink = new StringBuilder();
}
- int samples = sampleBuffers ? numSamples : 0 ;
+ final int samples = sampleBuffers ? numSamples : 0 ;
- super.toString(sink);
+ super.toString(sink, false);
- sink.append(", accum-rgba ").append(accumRedBits).append("/").append(accumGreenBits).append("/").append(accumBlueBits).append("/").append(accumAlphaBits);
- sink.append(", dp/st/ms: ").append(depthBits).append("/").append(stencilBits).append("/").append(samples);
+ sink.append(", accum-rgba ").append(accumRedBits).append(ESEP).append(accumGreenBits).append(ESEP).append(accumBlueBits).append(ESEP).append(accumAlphaBits);
+ sink.append(", dp/st/ms ").append(depthBits).append(ESEP).append(stencilBits).append(ESEP).append(samples);
if(samples>0) {
sink.append(", sample-ext ").append(sampleExtension);
}
@@ -431,22 +467,41 @@ public class GLCapabilities extends Capabilities implements Cloneable, GLCapabil
sink.append(", sw, ");
}
sink.append(glProfile);
- if(!isOnscreen()) {
- if(pbuffer) {
- sink.append(", pbuffer [r2t ").append(pbufferRenderToTexture?1:0)
- .append(", r2tr ").append(pbufferRenderToTextureRectangle?1:0)
- .append(", float ").append(pbufferFloatingPointBuffers?1:0)
- .append("]");
+ if(isOnscreen()) {
+ sink.append(", on-scr[");
+ } else {
+ sink.append(", offscr[");
+ }
+ boolean ns=false;
+ if(isFBO()) {
+ sink.append("fbo");
+ ns = true;
+ }
+ if(isPBuffer()) {
+ if(ns) { sink.append(CSEP); }
+ sink.append("pbuffer");
+ ns = true;
+ }
+ if(isBitmap()) {
+ if(ns) { sink.append(CSEP); }
+ sink.append("bitmap");
+ ns = true;
+ }
+ if(!ns) { // !FBO !PBuffer !Bitmap
+ if(isOnscreen()) {
+ sink.append("."); // no additional off-screen modes besides on-screen
} else {
- sink.append(", pixmap");
+ sink.append("auto-cfg"); // auto-config off-screen mode
}
}
-
+ sink.append("]");
+
return sink;
}
/** Returns a textual representation of this GLCapabilities
- object. */
+ object. */
+ @Override
public String toString() {
StringBuilder msg = new StringBuilder();
msg.append("GLCaps[");