diff options
author | Kenneth Russel <[email protected]> | 2009-03-19 00:32:21 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2009-03-19 00:32:21 +0000 |
commit | c4cd0db6b9865c97245921d2824bcc4c1541e615 (patch) | |
tree | 6f9df4a383767992fa9ec36d820630bfabedf75a /src/jogl/classes/javax/media | |
parent | 23d13ee00ebdf7052299fc65af6f50e43d673e67 (diff) |
Movement of Capabilities class and chooseCapabilities functionality
into NativeWindowFactory introduced an undesirable dependence between
the windowing toolkit, which can be replaced via NativeWindowFactory,
and the library which implements the selection algorithm, for example
OpenGL. This would prevent, for example, an easy SWT port of JOGL.
To fix this, refactored chooseCapabilities into new
GraphicsConfigurationFactory, the default implementation of which is
currently a no-op on X11 platforms, and which is provided by JOGL in a
toolkit-agnostic manner via GLX. Refactored OpenGL portions of
Capabilities class back into GLCapabilities. Reintroduced
GLCapabilitiesChooser interface for compatibility and to avoid having
to import javax.media.nativewindow classes in most user code.
Fixed problem in GLProfile where failures to load native libraries
were being squelched. Reorganized build to have all outputs under
build/ directory.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1884 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/jogl/classes/javax/media')
8 files changed, 671 insertions, 59 deletions
diff --git a/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java b/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java new file mode 100644 index 000000000..782d041a5 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2003-2009 Sun Microsystems, Inc. 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. + * + * 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. + */ + +package javax.media.opengl; + +import javax.media.nativewindow.Capabilities; +import javax.media.nativewindow.NativeWindowException; + +/** <P> The default implementation of the {@link + GLCapabilitiesChooser} interface, which provides consistent visual + selection behavior across platforms. The precise algorithm is + deliberately left loosely specified. Some properties are: </P> + + <UL> + + <LI> As long as there is at least one available non-null + GLCapabilities which matches the "stereo" option, will return a + valid index. + + <LI> Attempts to match as closely as possible the given + GLCapabilities, but will select one with fewer capabilities (i.e., + lower color depth) if necessary. + + <LI> Prefers hardware-accelerated visuals to + non-hardware-accelerated. + + <LI> If there is no exact match, prefers a more-capable visual to + a less-capable one. + + <LI> If there is more than one exact match, chooses an arbitrary + one. + + <LI> May select the opposite of a double- or single-buffered + visual (based on the user's request) in dire situations. + + <LI> Color depth (including alpha) mismatches are weighted higher + than depth buffer mismatches, which are in turn weighted higher + than accumulation buffer (including alpha) and stencil buffer + depth mismatches. + + <LI> If a valid windowSystemRecommendedChoice parameter is + supplied, chooses that instead of using the cross-platform code. + + </UL> +*/ + +public class DefaultGLCapabilitiesChooser implements GLCapabilitiesChooser { + private static final boolean DEBUG = false; // FIXME: Debug.debug("DefaultGLCapabilitiesChooser"); + + public int chooseCapabilities(Capabilities desired, + Capabilities[] available, + int windowSystemRecommendedChoice) { + GLCapabilities _desired = (GLCapabilities) desired; + GLCapabilities[] _available = (GLCapabilities[]) available; + + if (DEBUG) { + System.err.println("Desired: " + _desired); + for (int i = 0; i < _available.length; i++) { + System.err.println("Available " + i + ": " + _available[i]); + } + System.err.println("Window system's recommended choice: " + windowSystemRecommendedChoice); + } + + if (windowSystemRecommendedChoice >= 0 && + windowSystemRecommendedChoice < _available.length && + _available[windowSystemRecommendedChoice] != null) { + if (DEBUG) { + System.err.println("Choosing window system's recommended choice of " + windowSystemRecommendedChoice); + System.err.println(_available[windowSystemRecommendedChoice]); + } + return windowSystemRecommendedChoice; + } + + // Create score array + int[] scores = new int[_available.length]; + int NO_SCORE = -9999999; + int DOUBLE_BUFFER_MISMATCH_PENALTY = 1000; + int STENCIL_MISMATCH_PENALTY = 500; + // Pseudo attempt to keep equal rank penalties scale-equivalent + // (e.g., stencil mismatch is 3 * accum because there are 3 accum + // components) + int COLOR_MISMATCH_PENALTY_SCALE = 36; + int DEPTH_MISMATCH_PENALTY_SCALE = 6; + int ACCUM_MISMATCH_PENALTY_SCALE = 1; + int STENCIL_MISMATCH_PENALTY_SCALE = 3; + for (int i = 0; i < scores.length; i++) { + scores[i] = NO_SCORE; + } + // Compute score for each + for (int i = 0; i < scores.length; i++) { + GLCapabilities cur = _available[i]; + if (cur == null) { + continue; + } + if (_desired.getStereo() != cur.getStereo()) { + continue; + } + int score = 0; + // Compute difference in color depth + // (Note that this decides the direction of all other penalties) + score += (COLOR_MISMATCH_PENALTY_SCALE * + ((cur.getRedBits() + cur.getGreenBits() + cur.getBlueBits() + cur.getAlphaBits()) - + (_desired.getRedBits() + _desired.getGreenBits() + _desired.getBlueBits() + _desired.getAlphaBits()))); + // Compute difference in depth buffer depth + score += (DEPTH_MISMATCH_PENALTY_SCALE * sign(score) * + Math.abs(cur.getDepthBits() - _desired.getDepthBits())); + // Compute difference in accumulation buffer depth + score += (ACCUM_MISMATCH_PENALTY_SCALE * sign(score) * + Math.abs((cur.getAccumRedBits() + cur.getAccumGreenBits() + cur.getAccumBlueBits() + cur.getAccumAlphaBits()) - + (_desired.getAccumRedBits() + _desired.getAccumGreenBits() + _desired.getAccumBlueBits() + _desired.getAccumAlphaBits()))); + // Compute difference in stencil bits + score += STENCIL_MISMATCH_PENALTY_SCALE * sign(score) * (cur.getStencilBits() - _desired.getStencilBits()); + if (cur.getDoubleBuffered() != _desired.getDoubleBuffered()) { + score += sign(score) * DOUBLE_BUFFER_MISMATCH_PENALTY; + } + if ((_desired.getStencilBits() > 0) && (cur.getStencilBits() == 0)) { + score += sign(score) * STENCIL_MISMATCH_PENALTY; + } + scores[i] = score; + } + // Now prefer hardware-accelerated visuals by pushing scores of + // non-hardware-accelerated visuals out + boolean gotHW = false; + int maxAbsoluteHWScore = 0; + for (int i = 0; i < scores.length; i++) { + int score = scores[i]; + if (score == NO_SCORE) { + continue; + } + GLCapabilities cur = _available[i]; + if (cur.getHardwareAccelerated()) { + int absScore = Math.abs(score); + if (!gotHW || + (absScore > maxAbsoluteHWScore)) { + gotHW = true; + maxAbsoluteHWScore = absScore; + } + } + } + if (gotHW) { + for (int i = 0; i < scores.length; i++) { + int score = scores[i]; + if (score == NO_SCORE) { + continue; + } + GLCapabilities cur = _available[i]; + if (!cur.getHardwareAccelerated()) { + if (score <= 0) { + score -= maxAbsoluteHWScore; + } else if (score > 0) { + score += maxAbsoluteHWScore; + } + scores[i] = score; + } + } + } + + if (DEBUG) { + System.err.print("Scores: ["); + for (int i = 0; i < _available.length; i++) { + if (i > 0) { + System.err.print(","); + } + System.err.print(" " + scores[i]); + } + System.err.println(" ]"); + } + + // Ready to select. Choose score closest to 0. + int scoreClosestToZero = NO_SCORE; + int chosenIndex = -1; + for (int i = 0; i < scores.length; i++) { + int score = scores[i]; + if (score == NO_SCORE) { + continue; + } + // Don't substitute a positive score for a smaller negative score + if ((scoreClosestToZero == NO_SCORE) || + (Math.abs(score) < Math.abs(scoreClosestToZero) && + ((sign(scoreClosestToZero) < 0) || (sign(score) > 0)))) { + scoreClosestToZero = score; + chosenIndex = i; + } + } + if (chosenIndex < 0) { + throw new NativeWindowException("Unable to select one of the provided GLCapabilities"); + } + if (DEBUG) { + System.err.println("Chosen index: " + chosenIndex); + System.err.println("Chosen capabilities:"); + System.err.println(_available[chosenIndex]); + } + + return chosenIndex; + } + + private static int sign(int score) { + if (score < 0) { + return -1; + } + return 1; + } +} diff --git a/src/jogl/classes/javax/media/opengl/GLCapabilities.java b/src/jogl/classes/javax/media/opengl/GLCapabilities.java new file mode 100644 index 000000000..35b04d5f6 --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLCapabilities.java @@ -0,0 +1,310 @@ +/* + * Copyright (c) 2003-2009 Sun Microsystems, Inc. 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. + * + * 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. + */ + +package javax.media.opengl; + +import javax.media.nativewindow.Capabilities; + +/** Specifies a set of OpenGL capabilities that a rendering context + must support, such as color depth and whether stereo is enabled. + It currently contains the minimal number of routines which allow + configuration on all supported window systems. */ + +public class GLCapabilities extends Capabilities implements Cloneable { + private boolean doubleBuffered = true; + private boolean stereo = false; + private boolean hardwareAccelerated = true; + private int depthBits = 24; + private int stencilBits = 0; + private int accumRedBits = 0; + private int accumGreenBits = 0; + private int accumBlueBits = 0; + private int accumAlphaBits = 0; + // Shift bits from PIXELFORMATDESCRIPTOR not present because they + // are unlikely to be supported on Windows anyway + + // Support for full-scene antialiasing (FSAA) + private boolean sampleBuffers = false; + private int numSamples = 2; + + // Support for transparent windows containing OpenGL content + // (currently only has an effect on Mac OS X) + private boolean backgroundOpaque = true; + + // Bits for pbuffer creation + private boolean pbufferFloatingPointBuffers; + private boolean pbufferRenderToTexture; + private boolean pbufferRenderToTextureRectangle; + + /** Creates a GLCapabilities object. All attributes are in a default + state. + */ + public GLCapabilities() {} + + public Object clone() { + try { + return super.clone(); + } catch (RuntimeException e) { + throw new GLException(e); + } + } + + /** Indicates whether double-buffering is enabled. */ + public boolean getDoubleBuffered() { + return doubleBuffered; + } + + /** Enables or disables double buffering. */ + public void setDoubleBuffered(boolean onOrOff) { + doubleBuffered = onOrOff; + } + + /** Indicates whether stereo is enabled. */ + public boolean getStereo() { + return stereo; + } + + /** Enables or disables stereo viewing. */ + public void setStereo(boolean onOrOff) { + stereo = onOrOff; + } + + /** Indicates whether hardware acceleration is enabled. */ + public boolean getHardwareAccelerated() { + return hardwareAccelerated; + } + + /** Enables or disables hardware acceleration. */ + public void setHardwareAccelerated(boolean onOrOff) { + hardwareAccelerated = onOrOff; + } + + /** Returns the number of bits requested for the depth buffer. */ + public int getDepthBits() { + return depthBits; + } + + /** Sets the number of bits requested for the depth buffer. */ + public void setDepthBits(int depthBits) { + this.depthBits = depthBits; + } + + /** Returns the number of bits requested for the stencil buffer. */ + public int getStencilBits() { + return stencilBits; + } + + /** Sets the number of bits requested for the stencil buffer. */ + public void setStencilBits(int stencilBits) { + this.stencilBits = stencilBits; + } + + /** Returns the number of bits requested for the accumulation + buffer's red component. On some systems only the accumulation + buffer depth, which is the sum of the red, green, and blue bits, + is considered. */ + public int getAccumRedBits() { + return accumRedBits; + } + + /** Sets the number of bits requested for the accumulation buffer's + red component. On some systems only the accumulation buffer + depth, which is the sum of the red, green, and blue bits, is + considered. */ + public void setAccumRedBits(int accumRedBits) { + this.accumRedBits = accumRedBits; + } + + /** Returns the number of bits requested for the accumulation + buffer's green component. On some systems only the accumulation + buffer depth, which is the sum of the red, green, and blue bits, + is considered. */ + public int getAccumGreenBits() { + return accumGreenBits; + } + + /** Sets the number of bits requested for the accumulation buffer's + green component. On some systems only the accumulation buffer + depth, which is the sum of the red, green, and blue bits, is + considered. */ + public void setAccumGreenBits(int accumGreenBits) { + this.accumGreenBits = accumGreenBits; + } + + /** Returns the number of bits requested for the accumulation + buffer's blue component. On some systems only the accumulation + buffer depth, which is the sum of the red, green, and blue bits, + is considered. */ + public int getAccumBlueBits() { + return accumBlueBits; + } + + /** Sets the number of bits requested for the accumulation buffer's + blue component. On some systems only the accumulation buffer + depth, which is the sum of the red, green, and blue bits, is + considered. */ + public void setAccumBlueBits(int accumBlueBits) { + this.accumBlueBits = accumBlueBits; + } + + /** Returns the number of bits requested for the accumulation + buffer's alpha component. On some systems only the accumulation + buffer depth, which is the sum of the red, green, and blue bits, + is considered. */ + public int getAccumAlphaBits() { + return accumAlphaBits; + } + + /** Sets number of bits requested for accumulation buffer's alpha + component. On some systems only the accumulation buffer depth, + which is the sum of the red, green, and blue bits, is + considered. */ + public void setAccumAlphaBits(int accumAlphaBits) { + this.accumAlphaBits = accumAlphaBits; + } + + /** Indicates whether sample buffers for full-scene antialiasing + (FSAA) should be allocated for this drawable. Defaults to + false. */ + public void setSampleBuffers(boolean onOrOff) { + sampleBuffers = onOrOff; + } + + /** Returns whether sample buffers for full-scene antialiasing + (FSAA) should be allocated for this drawable. Defaults to + false. */ + public boolean getSampleBuffers() { + return sampleBuffers; + } + + /** If sample buffers are enabled, indicates the number of buffers + to be allocated. Defaults to 2. */ + public void setNumSamples(int numSamples) { + this.numSamples = numSamples; + } + + /** Returns the number of sample buffers to be allocated if sample + buffers are enabled. Defaults to 2. */ + 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 onOrOff) { + pbufferFloatingPointBuffers = onOrOff; + } + + /** For pbuffers only, returns whether floating-point buffers should + be used if available. Defaults to false. */ + 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 onOrOff) { + pbufferRenderToTexture = onOrOff; + } + + /** For pbuffers only, returns whether the render-to-texture + extension should be used if available. Defaults to false. */ + 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 onOrOff) { + pbufferRenderToTextureRectangle = onOrOff; + } + + /** For pbuffers only, returns whether the render-to-texture + extension should be used. Defaults to false. */ + public boolean getPbufferRenderToTextureRectangle() { + return pbufferRenderToTextureRectangle; + } + + /** For on-screen OpenGL contexts on some platforms, sets whether + the background of the context should be considered opaque. On + supported platforms, setting this to false, in conjunction with + other changes at the window toolkit level, can allow + hardware-accelerated OpenGL content inside of windows of + arbitrary shape. To achieve this effect it is necessary to use + an OpenGL clear color with an alpha less than 1.0. The default + value for this flag is <code>true</code>; setting it to false + may incur a certain performance penalty, so it is not + recommended to arbitrarily set it to false. */ + public void setBackgroundOpaque(boolean opaque) { + backgroundOpaque = opaque; + } + + /** Indicates whether the background of this OpenGL context should + be considered opaque. Defaults to true. + + @see #setBackgroundOpaque + */ + public boolean isBackgroundOpaque() { + return backgroundOpaque; + } + + /** Returns a textual representation of this GLCapabilities + object. */ + public String toString() { + return ("GLCapabilities [" + + "DoubleBuffered: " + doubleBuffered + + ", Stereo: " + stereo + + ", HardwareAccelerated: " + hardwareAccelerated + + ", DepthBits: " + depthBits + + ", StencilBits: " + stencilBits + + ", Red: " + getRedBits() + + ", Green: " + getGreenBits() + + ", Blue: " + getBlueBits() + + ", Alpha: " + getAlphaBits() + + ", Red Accum: " + accumRedBits + + ", Green Accum: " + accumGreenBits + + ", Blue Accum: " + accumBlueBits + + ", Alpha Accum: " + accumAlphaBits + + ", Multisample: " + sampleBuffers + + (sampleBuffers ? ", Num samples: " + numSamples : "") + + ", Opaque: " + backgroundOpaque + + " ]"); + } +} diff --git a/src/jogl/classes/javax/media/opengl/GLCapabilitiesChooser.java b/src/jogl/classes/javax/media/opengl/GLCapabilitiesChooser.java new file mode 100644 index 000000000..38cda8cdf --- /dev/null +++ b/src/jogl/classes/javax/media/opengl/GLCapabilitiesChooser.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2003-2009 Sun Microsystems, Inc. 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. + * + * 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. + */ + +package javax.media.opengl; + +import javax.media.nativewindow.CapabilitiesChooser; + +/** Provides a mechanism by which applications can customize the + window type selection for a given {@link GLCapabilities}. + Developers can implement this interface and pass an instance into + the appropriate method of {@link GLDrawableFactory}; the chooser + will be called during the OpenGL context creation process. Note + that this is only a marker interface; its signature is the same as + {@link CapabilitiesChooser}, but the array of {@link Capabilities} + objects passed to {@link #chooseCapabilities chooseCapabilities} + will actually be an array of {@link GLCapabilities}. */ + +public interface GLCapabilitiesChooser extends CapabilitiesChooser { +} diff --git a/src/jogl/classes/javax/media/opengl/GLDrawable.java b/src/jogl/classes/javax/media/opengl/GLDrawable.java index 26fdc8753..746c8e728 100644 --- a/src/jogl/classes/javax/media/opengl/GLDrawable.java +++ b/src/jogl/classes/javax/media/opengl/GLDrawable.java @@ -143,7 +143,7 @@ public interface GLDrawable { automatically and should not be called by the end user. */ public void swapBuffers() throws GLException; - /** Fetches the {@link NWCapabilities} corresponding to the chosen + /** Fetches the {@link GLCapabilities} corresponding to the chosen OpenGL capabilities (pixel format / visual) for this drawable. Some drawables, in particular on-screen drawables, may be created lazily; null is returned if the drawable is not @@ -153,7 +153,7 @@ public interface GLDrawable { value in this case. Returns a copy of the passed object. */ - public NWCapabilities getChosenNWCapabilities(); + public GLCapabilities getChosenGLCapabilities(); public NativeWindow getNativeWindow(); diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java index 21e5ddcbb..66585eb56 100644 --- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java +++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java @@ -49,21 +49,21 @@ import com.sun.nativewindow.impl.NWReflection; /** <P> Provides a virtual machine- and operating system-independent mechanism for creating {@link GLDrawable}s. </P> - <P> The {@link javax.media.opengl.NWCapabilities} objects passed + <P> The {@link javax.media.opengl.GLCapabilities} objects passed in to the various factory methods are used as a hint for the properties of the returned drawable. The default capabilities selection algorithm (equivalent to passing in a null {@link - NWCapabilitiesChooser}) is described in {@link - DefaultNWCapabilitiesChooser}. Sophisticated applications needing + GLCapabilitiesChooser}) is described in {@link + DefaultGLCapabilitiesChooser}. Sophisticated applications needing to change the selection algorithm may pass in their own {@link - NWCapabilitiesChooser} which can select from the available pixel - formats. The NWCapabilitiesChooser mechanism may not be supported + GLCapabilitiesChooser} which can select from the available pixel + formats. The GLCapabilitiesChooser mechanism may not be supported by all implementations or on all platforms, in which case any - passed NWCapabilitiesChooser will be ignored. </P> + passed GLCapabilitiesChooser will be ignored. </P> <P> Because of the multithreaded nature of the Java platform's Abstract Window Toolkit, it is typically not possible to immediately - reject a given {@link NWCapabilities} as being unsupportable by + reject a given {@link GLCapabilities} as being unsupportable by either returning <code>null</code> from the creation routines or raising a {@link GLException}. The semantics of the rejection process are (unfortunately) left unspecified for now. The current @@ -156,19 +156,19 @@ public abstract class GLDrawableFactory { * Returns a GLDrawable that wraps a platform-specific window system * object, such as an AWT or LCDUI Canvas. On platforms which * support it, selects a pixel format compatible with the supplied - * NWCapabilities, or if the passed NWCapabilities object is null, + * GLCapabilities, or if the passed GLCapabilities object is null, * uses a default set of capabilities. On these platforms, uses - * either the supplied NWCapabilitiesChooser object, or if the - * passed NWCapabilitiesChooser object is null, uses a - * DefaultNWCapabilitiesChooser instance. + * either the supplied GLCapabilitiesChooser object, or if the + * passed GLCapabilitiesChooser object is null, uses a + * DefaultGLCapabilitiesChooser instance. * * @throws IllegalArgumentException if the passed target is null * @throws GLException if any window system-specific errors caused * the creation of the GLDrawable to fail. */ public abstract GLDrawable createGLDrawable(NativeWindow target, - NWCapabilities capabilities, - NWCapabilitiesChooser chooser) + GLCapabilities capabilities, + GLCapabilitiesChooser chooser) throws IllegalArgumentException, GLException; //---------------------------------------------------------------------- @@ -189,8 +189,8 @@ public abstract class GLDrawableFactory { * @throws GLException if any window system-specific errors caused * the creation of the GLPbuffer to fail. */ - public abstract GLPbuffer createGLPbuffer(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + public abstract GLPbuffer createGLPbuffer(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, int initialWidth, int initialHeight, GLContext shareWith) diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index 5180a4e2d..54bf63dda 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -58,7 +58,7 @@ public class GLProfile { /** The JVM/process wide chosen GL profile **/ private static String profile = null; - private static final void tryLibrary() + private static final Throwable tryLibrary() { try { Class clazz = Class.forName(getGLImplBaseClassName()+"Impl"); @@ -79,11 +79,13 @@ public class GLProfile { } } System.out.println("Successfully loaded profile " + profile); + return null; } catch (Throwable e) { if (Debug.debug("GLProfile")) { e.printStackTrace(); } profile=null; + return e; } } @@ -92,9 +94,9 @@ public class GLProfile { { if(null==GLProfile.profile) { GLProfile.profile = profile; - tryLibrary(); - if (profile == null) { - throw new GLException("Profile " + profile + " not available"); + Throwable t = tryLibrary(); + if (GLProfile.profile == null) { + throw new GLException("Profile " + profile + " not available", t); } } else { if(!GLProfile.profile.equals(profile)) { @@ -106,9 +108,14 @@ public class GLProfile { public static synchronized final void setProfile(String[] profiles) throws GLException { + Throwable t = null; for(int i=0; profile==null && i<profiles.length; i++) { profile = profiles[i]; - tryLibrary(); + if (t == null) { + t = tryLibrary(); + } else { + tryLibrary(); + } } if(null==profile) { StringBuffer msg = new StringBuffer(); @@ -119,7 +126,7 @@ public class GLProfile { msg.append(profiles[i]); } msg.append("]"); - throw new GLException("Profiles "+msg.toString()+" not available"); + throw new GLException("Profiles "+msg.toString()+" not available", t); } } diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java index 8ef797c97..232299594 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -84,8 +84,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { private boolean sendReshape = false; private GraphicsConfiguration chosen; - private NWCapabilities glCaps; - private NWCapabilitiesChooser glCapChooser; + private GLCapabilities glCaps; + private GLCapabilitiesChooser glCapChooser; static { // Default to the GL2 profile, which is the default on the desktop @@ -104,15 +104,15 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { /** Creates a new GLCanvas component with the requested set of OpenGL capabilities, using the default OpenGL capabilities selection mechanism, on the default screen device. */ - public GLCanvas(NWCapabilities capabilities) { + public GLCanvas(GLCapabilities capabilities) { this(capabilities, null, null, null); } - /** Creates a new GLCanvas component. The passed NWCapabilities + /** Creates a new GLCanvas component. The passed GLCapabilities specifies the OpenGL capabilities for the component; if null, a - default set of capabilities is used. The NWCapabilitiesChooser + default set of capabilities is used. The GLCapabilitiesChooser specifies the algorithm for selecting one of the available - NWCapabilities for the component; a DefaultGLCapabilitesChooser + GLCapabilities for the component; a DefaultGLCapabilitesChooser is used if null is passed for this argument. The passed GLContext specifies an OpenGL context with which to share textures, display lists and other OpenGL state, and may be null @@ -123,8 +123,8 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { which to create the GLCanvas; the GLDrawableFactory uses the default screen device of the local GraphicsEnvironment if null is passed for this argument. */ - public GLCanvas(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + public GLCanvas(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, GLContext shareWith, GraphicsDevice device) { // The platform-specific GLDrawableFactory will only provide a @@ -466,11 +466,11 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { maybeDoSingleThreadedWorkaround(swapBuffersOnEventDispatchThreadAction, swapBuffersAction); } - public NWCapabilities getChosenNWCapabilities() { + public GLCapabilities getChosenGLCapabilities() { if (drawable == null) return null; - return drawable.getChosenNWCapabilities(); + return drawable.getChosenGLCapabilities(); } public NativeWindow getNativeWindow() { @@ -609,18 +609,19 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable { } } - private static GraphicsConfiguration chooseGraphicsConfiguration(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + private static GraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, GraphicsDevice device) { // Make GLCanvas behave better in NetBeans GUI builder if (Beans.isDesignTime()) { return null; } + AWTGraphicsDevice awtDevice = new AWTGraphicsDevice(device); AWTGraphicsConfiguration config = (AWTGraphicsConfiguration) - NativeWindowFactory.getFactory(Component.class).chooseGraphicsConfiguration(capabilities, - chooser, - new AWTGraphicsDevice(device)); + GraphicsConfigurationFactory.getFactory(awtDevice).chooseGraphicsConfiguration(capabilities, + chooser, + awtDevice); if (config == null) { return null; } diff --git a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java index 9ea7d59dd..86668373d 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLJPanel.java @@ -64,7 +64,7 @@ import com.sun.opengl.impl.awt.*; Z-ordering or LayoutManager problems. <P> The GLJPanel can be made transparent by creating it with a - NWCapabilities object with alpha bits specified and calling {@link + GLCapabilities object with alpha bits specified and calling {@link #setOpaque}(false). Pixels with resulting OpenGL alpha values less than 1.0 will be overlaid on any underlying Swing rendering. <P> @@ -91,8 +91,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { private volatile boolean isInitialized; // Data used for either pbuffers or pixmap-based offscreen surfaces - private NWCapabilities offscreenCaps; - private NWCapabilitiesChooser chooser; + private GLCapabilities offscreenCaps; + private GLCapabilitiesChooser chooser; private GLContext shareWith; // Width of the actual GLJPanel private int panelWidth = 0; @@ -159,33 +159,33 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { /** Creates a new GLJPanel component with the requested set of OpenGL capabilities, using the default OpenGL capabilities selection mechanism. */ - public GLJPanel(NWCapabilities capabilities) { + public GLJPanel(GLCapabilities capabilities) { this(capabilities, null, null); } - /** Creates a new GLJPanel component. The passed NWCapabilities + /** Creates a new GLJPanel component. The passed GLCapabilities specifies the OpenGL capabilities for the component; if null, a - default set of capabilities is used. The NWCapabilitiesChooser + default set of capabilities is used. The GLCapabilitiesChooser specifies the algorithm for selecting one of the available - NWCapabilities for the component; a DefaultGLCapabilitesChooser + GLCapabilities for the component; a DefaultGLCapabilitesChooser is used if null is passed for this argument. The passed GLContext specifies an OpenGL context with which to share textures, display lists and other OpenGL state, and may be null if sharing is not desired. See the note in the overview documentation on <a href="../../../overview-summary.html#SHARING">context sharing</a>. */ - public GLJPanel(NWCapabilities capabilities, NWCapabilitiesChooser chooser, GLContext shareWith) { + public GLJPanel(GLCapabilities capabilities, GLCapabilitiesChooser chooser, GLContext shareWith) { super(); // Works around problems on many vendors' cards; we don't need a // back buffer for the offscreen surface anyway if (capabilities != null) { - offscreenCaps = (NWCapabilities) capabilities.clone(); + offscreenCaps = (GLCapabilities) capabilities.clone(); } else { - offscreenCaps = new NWCapabilities(); + offscreenCaps = new GLCapabilities(); } offscreenCaps.setDoubleBuffered(false); - this.chooser = ((chooser != null) ? chooser : new DefaultNWCapabilitiesChooser()); + this.chooser = ((chooser != null) ? chooser : new DefaultGLCapabilitiesChooser()); this.shareWith = shareWith; } @@ -404,8 +404,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { return oglPipelineEnabled; } - public NWCapabilities getChosenNWCapabilities() { - return backend.getChosenNWCapabilities(); + public GLCapabilities getChosenGLCapabilities() { + return backend.getChosenGLCapabilities(); } public NativeWindow getNativeWindow() { @@ -620,8 +620,8 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { // Called to get the current backend's GLDrawable public GLDrawable getDrawable(); - // Called to fetch the "real" chosen NWCapabilities for the backend - public NWCapabilities getChosenNWCapabilities(); + // Called to fetch the "real" chosen GLCapabilities for the backend + public GLCapabilities getChosenGLCapabilities(); // Called to handle a reshape event. When this is called, the // OpenGL context associated with the backend is not current, to @@ -861,11 +861,11 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { return offscreenDrawable; } - public NWCapabilities getChosenNWCapabilities() { + public GLCapabilities getChosenGLCapabilities() { if (offscreenDrawable == null) { return null; } - return offscreenDrawable.getChosenNWCapabilities(); + return offscreenDrawable.getChosenGLCapabilities(); } public void handleReshape() { @@ -952,11 +952,11 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { return pbuffer; } - public NWCapabilities getChosenNWCapabilities() { + public GLCapabilities getChosenGLCapabilities() { if (pbuffer == null) { return null; } - return pbuffer.getChosenNWCapabilities(); + return pbuffer.getChosenGLCapabilities(); } public void handleReshape() { @@ -1123,9 +1123,9 @@ public class GLJPanel extends JPanel implements AWTGLAutoDrawable { return joglDrawable; } - public NWCapabilities getChosenNWCapabilities() { + public GLCapabilities getChosenGLCapabilities() { // FIXME: should do better than this; is it possible to using only platform-independent code? - return new NWCapabilities(); + return new GLCapabilities(); } public void handleReshape() { |