diff options
Diffstat (limited to 'src/jogl/classes/com/sun')
30 files changed, 297 insertions, 356 deletions
diff --git a/src/jogl/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java b/src/jogl/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java index 5549da170..fb1b8d6f4 100644 --- a/src/jogl/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java +++ b/src/jogl/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java @@ -53,18 +53,11 @@ import java.lang.reflect.*; they may be instantiated by the GLJPanel implementation. */ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory implements DynamicLookupHelper { - /** - * Make sure the right NativeWindowFactory is registered - */ - static { - initializeNativeWindowFactory(); - } - /** Creates a (typically software-accelerated) offscreen GLDrawable used to implement the fallback rendering path of the GLJPanel. */ - public abstract GLDrawableImpl createOffscreenDrawable(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + public abstract GLDrawableImpl createOffscreenDrawable(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, int width, int height); @@ -261,36 +254,4 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory implements gammaShutdownHookRegistered = false; // Leave the original gamma ramp data alone } - - private static void initializeNativeWindowFactory() { - String osName = System.getProperty("os.name"); - String osNameLowerCase = osName.toLowerCase(); - String factoryClassName = null; - - // We break compile-time dependencies on the AWT here to - // make it easier to run this code on mobile devices - - NativeWindowFactory factory = null; - - if (!osNameLowerCase.startsWith("wind") && - !osNameLowerCase.startsWith("mac os x")) { - // Assume X11 platform -- should probably test for these explicitly - try { - // try X11 AWT GLX .. - Constructor factoryConstructor = NWReflection.getConstructor("com.sun.opengl.impl.x11.glx.awt.X11AWTGLXNativeWindowFactory", new Class[] {}); - factory = (NativeWindowFactory) factoryConstructor.newInstance(null); - } catch (Exception e) {} - if(null==factory) { - try { - // try X11 GLX .. - Constructor factoryConstructor = NWReflection.getConstructor("com.sun.opengl.impl.x11.glx.X11GLXNativeWindowFactory", new Class[] {}); - factory = (NativeWindowFactory) factoryConstructor.newInstance(null); - } catch (Exception e) {} - } - /** - if(null==factory) { - // must be EGL then .. - } */ - } - } } diff --git a/src/jogl/classes/com/sun/opengl/impl/GLDrawableImpl.java b/src/jogl/classes/com/sun/opengl/impl/GLDrawableImpl.java index ce1dc6fdf..9df572af1 100644 --- a/src/jogl/classes/com/sun/opengl/impl/GLDrawableImpl.java +++ b/src/jogl/classes/com/sun/opengl/impl/GLDrawableImpl.java @@ -43,16 +43,16 @@ import javax.media.nativewindow.*; import javax.media.opengl.*; public abstract class GLDrawableImpl implements GLDrawable { - private NWCapabilities requestedCapabilities; + private GLCapabilities requestedCapabilities; protected GLDrawableImpl(GLDrawableFactory factory, NativeWindow comp, - NWCapabilities requestedCapabilities, + GLCapabilities requestedCapabilities, boolean realized) { this.factory = factory; this.component = comp; this.requestedCapabilities = - (requestedCapabilities == null) ? null : (NWCapabilities) requestedCapabilities.clone(); + (requestedCapabilities == null) ? null : (GLCapabilities) requestedCapabilities.clone(); this.realized = realized; } @@ -73,20 +73,20 @@ public abstract class GLDrawableImpl implements GLDrawable { return GLContextImpl.toHexString(hex); } - protected NWCapabilities getRequestedNWCapabilities() { + protected GLCapabilities getRequestedGLCapabilities() { return requestedCapabilities; } - public NWCapabilities getChosenNWCapabilities() { + public GLCapabilities getChosenGLCapabilities() { if (chosenCapabilities == null) return null; // Must return a new copy to avoid mutation by end user - return (NWCapabilities) chosenCapabilities.clone(); + return (GLCapabilities) chosenCapabilities.clone(); } - protected void setChosenNWCapabilities(NWCapabilities caps) { - chosenCapabilities = (caps==null) ? null : (NWCapabilities) caps.clone(); + protected void setChosenGLCapabilities(GLCapabilities caps) { + chosenCapabilities = (caps==null) ? null : (GLCapabilities) caps.clone(); } public NativeWindow getNativeWindow() { @@ -100,7 +100,7 @@ public abstract class GLDrawableImpl implements GLDrawable { public void setRealized(boolean realized) { this.realized = realized; if(!realized) { - setChosenNWCapabilities(null); + setChosenGLCapabilities(null); component.invalidate(); } } @@ -141,7 +141,7 @@ public abstract class GLDrawableImpl implements GLDrawable { protected GLDrawableFactory factory; protected NativeWindow component; - private NWCapabilities chosenCapabilities; + private GLCapabilities chosenCapabilities; // Indicates whether the component (if an onscreen context) has been // realized. Plausibly, before the component is realized the JAWT diff --git a/src/jogl/classes/com/sun/opengl/impl/GLPbufferImpl.java b/src/jogl/classes/com/sun/opengl/impl/GLPbufferImpl.java index c6cf74e19..b28dd1b53 100644 --- a/src/jogl/classes/com/sun/opengl/impl/GLPbufferImpl.java +++ b/src/jogl/classes/com/sun/opengl/impl/GLPbufferImpl.java @@ -157,11 +157,11 @@ public class GLPbufferImpl implements GLPbuffer { context.releasePbufferFromTexture(); } - public NWCapabilities getChosenNWCapabilities() { + public GLCapabilities getChosenGLCapabilities() { if (pbufferDrawable == null) return null; - return pbufferDrawable.getChosenNWCapabilities(); + return pbufferDrawable.getChosenGLCapabilities(); } private boolean surfaceLocked = false; diff --git a/src/jogl/classes/com/sun/opengl/impl/egl/EGLConfig.java b/src/jogl/classes/com/sun/opengl/impl/egl/EGLConfig.java index f9ad6e318..0f60dd6b4 100644 --- a/src/jogl/classes/com/sun/opengl/impl/egl/EGLConfig.java +++ b/src/jogl/classes/com/sun/opengl/impl/egl/EGLConfig.java @@ -41,7 +41,7 @@ import javax.media.opengl.*; import com.sun.opengl.impl.*; import com.sun.gluegen.runtime.NativeLibrary; -public class EGLConfig { +public class EGLConfig implements AbstractGraphicsConfiguration { public _EGLConfig getNativeConfig() { return _config; @@ -51,7 +51,7 @@ public class EGLConfig { return configID; } - public NWCapabilities getCapabilities() { + public GLCapabilities getCapabilities() { return capabilities; } @@ -83,11 +83,11 @@ public class EGLConfig { if (numConfigs[0] == 0) { throw new GLException("No valid graphics configuration selected from eglChooseConfig"); } - capabilities = new NWCapabilities(); + capabilities = new GLCapabilities(); setup(display, configID, configs[0]); } - public EGLConfig(long display, NWCapabilities caps) { + public EGLConfig(long display, GLCapabilities caps) { int[] attrs = glCapabilities2AttribList(caps); _EGLConfig[] configs = new _EGLConfig[1]; int[] numConfigs = new int[1]; @@ -100,7 +100,7 @@ public class EGLConfig { if (numConfigs[0] == 0) { throw new GLException("No valid graphics configuration selected from eglChooseConfig"); } - capabilities = (NWCapabilities)caps.clone(); + capabilities = (GLCapabilities)caps.clone(); setup(display, -1, configs[0]); } @@ -137,7 +137,7 @@ public class EGLConfig { } } - public static int[] glCapabilities2AttribList(NWCapabilities caps) { + public static int[] glCapabilities2AttribList(GLCapabilities caps) { int[] attrs = new int[] { EGL.EGL_RENDERABLE_TYPE, -1, // FIXME: does this need to be configurable? @@ -167,6 +167,6 @@ public class EGLConfig { } private _EGLConfig _config; private int configID; - private NWCapabilities capabilities; + private GLCapabilities capabilities; } diff --git a/src/jogl/classes/com/sun/opengl/impl/egl/EGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/egl/EGLDrawable.java index 733891009..105ccc6d9 100755 --- a/src/jogl/classes/com/sun/opengl/impl/egl/EGLDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/egl/EGLDrawable.java @@ -42,7 +42,7 @@ import javax.media.nativewindow.*; import javax.media.opengl.*; public class EGLDrawable extends GLDrawableImpl { - private NWCapabilitiesChooser chooser; + private GLCapabilitiesChooser chooser; private long display; private EGLConfig config; private long surface; @@ -50,8 +50,8 @@ public class EGLDrawable extends GLDrawableImpl { public EGLDrawable(EGLDrawableFactory factory, NativeWindow component, - NWCapabilities requestedCapabilities, - NWCapabilitiesChooser chooser) throws GLException { + GLCapabilities requestedCapabilities, + GLCapabilitiesChooser chooser) throws GLException { super(factory, component, requestedCapabilities, false); this.chooser = chooser; surface=EGL.EGL_NO_SURFACE; @@ -92,7 +92,7 @@ public class EGLDrawable extends GLDrawableImpl { public void setRealized(boolean realized) { if (realized) { - if (NWReflection.instanceOf(component, "com.sun.javafx.newt.kd.KDWindow")) { + if (NWReflection.instanceOf(component, "com.sun.javafx.newt.opengl.kd.KDWindow")) { // KDWindows holds already determined EGL values display = component.getDisplayHandle(); if (display==0) { @@ -101,11 +101,10 @@ public class EGLDrawable extends GLDrawableImpl { if (display == EGL.EGL_NO_DISPLAY) { throw new GLException("KDWindow has EGL_NO_DISPLAY"); } - Long setConfigID = new Long(component.getVisualID()); - if ( 0 <= setConfigID.longValue() && setConfigID.longValue() <= Integer.MAX_VALUE ) { - config = new EGLConfig(display, setConfigID.intValue()); - } else { - throw new GLException("KDWindow has invalid visualID/configID"); + EGLConfig config = (EGLConfig) component.getGraphicsConfiguration(); + int configID = 0; + if (config != null) { + configID = config.getNativeConfigID(); } } else { display = EGL.eglGetDisplay((0!=component.getDisplayHandle())?component.getDisplayHandle():EGL.EGL_DEFAULT_DISPLAY); @@ -115,9 +114,9 @@ public class EGLDrawable extends GLDrawableImpl { if (!EGL.eglInitialize(display, null, null)) { throw new GLException("eglInitialize failed"); } - config = new EGLConfig(display, getRequestedNWCapabilities()); + config = new EGLConfig(display, getRequestedGLCapabilities()); } - setChosenNWCapabilities(config.getCapabilities()); + setChosenGLCapabilities(config.getCapabilities()); } else if (surface != EGL.EGL_NO_SURFACE) { // Destroy the window surface if (!EGL.eglDestroySurface(display, surface)) { diff --git a/src/jogl/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java b/src/jogl/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java index 332a0a815..b73cfbd3e 100755 --- a/src/jogl/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java +++ b/src/jogl/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java @@ -117,23 +117,23 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { } } - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + public AbstractGraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, AbstractGraphicsDevice device) { return null; } public GLDrawable createGLDrawable(NativeWindow target, - NWCapabilities capabilities, - NWCapabilitiesChooser chooser) { + GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { target = NativeWindowFactory.getNativeWindow(target); return new EGLDrawable(this, target, capabilities, chooser); } - public GLDrawableImpl createOffscreenDrawable(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + public GLDrawableImpl createOffscreenDrawable(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, int width, int height) { throw new GLException("Not yet implemented"); @@ -143,8 +143,8 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { // Not supported on OpenGL ES return false; } - public GLPbuffer createGLPbuffer(final NWCapabilities capabilities, - final NWCapabilitiesChooser chooser, + public GLPbuffer createGLPbuffer(final GLCapabilities capabilities, + final GLCapabilitiesChooser chooser, final int initialWidth, final int initialHeight, final GLContext shareWith) { diff --git a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLContext.java index 4e4c2e329..62bacdda1 100644 --- a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLContext.java +++ b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLContext.java @@ -111,7 +111,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl } } int[] viewNotReady = new int[1]; - NWCapabilities capabilities = drawable.getRequestedNWCapabilities(); + GLCapabilities capabilities = drawable.getRequestedGLCapabilities(); int[] iattribs = new int[128]; int[] ivalues = new int[128]; int idx = 0; @@ -140,7 +140,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl long pixelFormat = CGL.createPixelFormat(iattribs, 0, idx, ivalues, 0); if (pixelFormat == 0) { - throw new GLException("Unable to allocate pixel format with requested NWCapabilities"); + throw new GLException("Unable to allocate pixel format with requested GLCapabilities"); } try { // Try to allocate a context with this @@ -168,10 +168,10 @@ public abstract class MacOSXCGLContext extends GLContextImpl // context and not the drawable. However it's a reasonable // approximation to just store the chosen pixel format up in the // drawable since the public API doesn't provide for a different - // NWCapabilities per context. - if (drawable.getChosenNWCapabilities() == null) { + // GLCapabilities per context. + if (drawable.getChosenGLCapabilities() == null) { // Figure out what attributes we really got - NWCapabilities caps = new NWCapabilities(); + GLCapabilities caps = new GLCapabilities(); CGL.queryPixelFormat(pixelFormat, iattribs, 0, idx, ivalues, 0); for (int i = 0; i < idx; i++) { int attr = iattribs[i]; @@ -235,7 +235,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl } } - drawable.setChosenNWCapabilities(caps); + drawable.setChosenGLCapabilities(caps); } diff --git a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLDrawable.java index 67358878e..7dc94b74d 100644 --- a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLDrawable.java @@ -46,7 +46,7 @@ import com.sun.opengl.impl.*; public abstract class MacOSXCGLDrawable extends GLDrawableImpl { protected static final boolean DEBUG = Debug.debug("MacOSXCGLDrawable"); - protected NWCapabilitiesChooser chooser; + protected GLCapabilitiesChooser chooser; // The Java2D/OpenGL pipeline on OS X uses low-level CGLContextObjs // to represent the contexts for e.g. the Java2D back buffer. When @@ -82,18 +82,18 @@ public abstract class MacOSXCGLDrawable extends GLDrawableImpl { public static final int CGL_MODE = 2; public MacOSXCGLDrawable(GLDrawableFactory factory, NativeWindow comp, boolean realized, - NWCapabilities requestedCapabilities, NWCapabilitiesChooser chooser) { + GLCapabilities requestedCapabilities, GLCapabilitiesChooser chooser) { super(factory, comp, requestedCapabilities, realized); this.chooser = chooser; } // These are public to allow access from a couple of context implementations - public void setChosenNWCapabilities(NWCapabilities caps) { - super.setChosenNWCapabilities(caps); + public void setChosenGLCapabilities(GLCapabilities caps) { + super.setChosenGLCapabilities(caps); } - public NWCapabilities getRequestedNWCapabilities() { - return super.getRequestedNWCapabilities(); + public GLCapabilities getRequestedGLCapabilities() { + return super.getRequestedGLCapabilities(); } protected static String getThreadName() { diff --git a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java index 318b6b123..2868a0899 100644 --- a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java +++ b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java @@ -51,30 +51,24 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { super(); } - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, - AbstractGraphicsDevice device) { - return null; - } - public GLDrawable createGLDrawable(NativeWindow target, - NWCapabilities capabilities, - NWCapabilitiesChooser chooser) { + GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { if (target == null) { throw new IllegalArgumentException("Null target"); } target = NativeWindowFactory.getNativeWindow(target); if (capabilities == null) { - capabilities = new NWCapabilities(); + capabilities = new GLCapabilities(); } if (chooser == null) { - chooser = new DefaultNWCapabilitiesChooser(); + chooser = new DefaultGLCapabilitiesChooser(); } return new MacOSXOnscreenCGLDrawable(this, target, capabilities, chooser); } - public GLDrawableImpl createOffscreenDrawable(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + public GLDrawableImpl createOffscreenDrawable(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, int width, int height) { return new MacOSXOffscreenCGLDrawable(this, capabilities, width, height); @@ -84,8 +78,8 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { return true; } - public GLPbuffer createGLPbuffer(final NWCapabilities capabilities, - final NWCapabilitiesChooser chooser, + public GLPbuffer createGLPbuffer(final GLCapabilities capabilities, + final GLCapabilitiesChooser chooser, final int initialWidth, final int initialHeight, final GLContext shareWith) { diff --git a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXOffscreenCGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXOffscreenCGLDrawable.java index 42eab51a1..ee469b71f 100644 --- a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXOffscreenCGLDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXOffscreenCGLDrawable.java @@ -46,7 +46,7 @@ import com.sun.opengl.impl.*; public class MacOSXOffscreenCGLDrawable extends MacOSXPbufferCGLDrawable { public MacOSXOffscreenCGLDrawable(GLDrawableFactory factory, - NWCapabilities capabilities, + GLCapabilities capabilities, int width, int height) { super(factory, capabilities, width, height); diff --git a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXOnscreenCGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXOnscreenCGLDrawable.java index 42e3957c2..12fc7c3ad 100644 --- a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXOnscreenCGLDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXOnscreenCGLDrawable.java @@ -52,8 +52,8 @@ public class MacOSXOnscreenCGLDrawable extends MacOSXCGLDrawable { new ArrayList(); protected MacOSXOnscreenCGLDrawable(GLDrawableFactory factory, NativeWindow component, - NWCapabilities capabilities, - NWCapabilitiesChooser chooser) { + GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { super(factory, component, false, capabilities, chooser); } diff --git a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java index 7141778ae..f8241af0d 100644 --- a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java +++ b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java @@ -81,7 +81,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { // Initialize render-to-texture support if requested GL gl = getGL(); - boolean rect = gl.isGL2() && drawable.getRequestedNWCapabilities().getPbufferRenderToTextureRectangle(); + boolean rect = gl.isGL2() && drawable.getRequestedGLCapabilities().getPbufferRenderToTextureRectangle(); if (rect) { if (!gl.isExtensionAvailable("GL_EXT_texture_rectangle")) { System.err.println("MacOSXPbufferCGLContext: WARNING: GL_EXT_texture_rectangle extension not " + @@ -136,7 +136,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { } protected boolean create() { - NWCapabilities capabilities = drawable.getRequestedNWCapabilities(); + GLCapabilities capabilities = drawable.getRequestedGLCapabilities(); if (capabilities.getPbufferFloatingPointBuffers() && !isTigerOrLater) { throw new GLException("Floating-point pbuffers supported only on OS X 10.4 or later"); @@ -211,7 +211,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { // NSOpenGLContext-based implementation class NSOpenGLImpl implements Impl { public long create() { - NWCapabilities capabilities = drawable.getRequestedNWCapabilities(); + GLCapabilities capabilities = drawable.getRequestedGLCapabilities(); if (capabilities.getPbufferFloatingPointBuffers() && !isTigerOrLater) { throw new GLException("Floating-point pbuffers supported only on OS X 10.4 or later"); @@ -266,7 +266,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext { int[] attrs = new int[256]; int i = 0; attrs[i++] = CGL.kCGLPFAPBuffer; - NWCapabilities capabilities = drawable.getRequestedNWCapabilities(); + GLCapabilities capabilities = drawable.getRequestedGLCapabilities(); if (capabilities.getPbufferFloatingPointBuffers()) attrs[i++] = CGL.kCGLPFAColorFloat; if (capabilities.getDoubleBuffered()) diff --git a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java index 6be7392b0..d8dea7595 100644 --- a/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java @@ -57,7 +57,7 @@ public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable { // semantic is that contains an NSView protected long pBuffer; - public MacOSXPbufferCGLDrawable(GLDrawableFactory factory, NWCapabilities capabilities, int width, int height) { + public MacOSXPbufferCGLDrawable(GLDrawableFactory factory, GLCapabilities capabilities, int width, int height) { super(factory, new NullWindow(), true, capabilities, null); NullWindow nw = (NullWindow) getNativeWindow(); nw.setSize(width, height); @@ -90,7 +90,7 @@ public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable { private void createPbuffer() { NullWindow nw = (NullWindow) getNativeWindow(); int renderTarget; - NWCapabilities capabilities = getRequestedNWCapabilities(); + GLCapabilities capabilities = getRequestedGLCapabilities(); if (GLProfile.isGL2() && capabilities.getPbufferRenderToTextureRectangle()) { renderTarget = GL2.GL_TEXTURE_RECTANGLE; } else { diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java index 619d28720..9bdc42087 100644 --- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsDummyWGLDrawable.java @@ -48,7 +48,7 @@ public class WindowsDummyWGLDrawable extends WindowsWGLDrawable { private long hwnd, hdc; public WindowsDummyWGLDrawable(GLDrawableFactory factory) { - super(factory, new NullWindow(), true, new NWCapabilities(), null); + super(factory, new NullWindow(), true, new GLCapabilities(), null); // All entries to CreateDummyWindow must synchronize on one object // to avoid accidentally registering the dummy window class twice synchronized (WindowsDummyWGLDrawable.class) { @@ -58,7 +58,7 @@ public class WindowsDummyWGLDrawable extends WindowsWGLDrawable { NullWindow nw = (NullWindow) getNativeWindow(); nw.setSurfaceHandle(hdc); // Choose a (hopefully hardware-accelerated) OpenGL pixel format for this device context - NWCapabilities caps = new NWCapabilities(); + GLCapabilities caps = new GLCapabilities(); caps.setDepthBits(16); PIXELFORMATDESCRIPTOR pfd = glCapabilities2PFD(caps, true); int pixelFormat = WGL.ChoosePixelFormat(hdc, pfd); diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java index 9de51e04c..78b06307a 100755 --- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsExternalWGLDrawable.java @@ -47,7 +47,7 @@ import com.sun.nativewindow.impl.NullWindow; public class WindowsExternalWGLDrawable extends WindowsWGLDrawable { public WindowsExternalWGLDrawable(GLDrawableFactory factory, NativeWindow component) { - super(factory, component, true, new NWCapabilities(), null); + super(factory, component, true, new GLCapabilities(), null); } public static WindowsExternalWGLDrawable create(GLDrawableFactory factory) { diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java index 979362780..efea5842f 100644 --- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java @@ -49,8 +49,8 @@ public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable { private long hbitmap; public WindowsOffscreenWGLDrawable(GLDrawableFactory factory, - NWCapabilities requestedCapabilities, - NWCapabilitiesChooser chooser, + GLCapabilities requestedCapabilities, + GLCapabilitiesChooser chooser, int width, int height) { super(factory, new NullWindow(), true, requestedCapabilities, chooser); @@ -64,7 +64,7 @@ public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable { private void create() { NullWindow nw = (NullWindow) getNativeWindow(); - NWCapabilities capabilities = getRequestedNWCapabilities(); + GLCapabilities capabilities = getRequestedGLCapabilities(); int width = getWidth(); int height = getHeight(); BITMAPINFO info = BITMAPINFO.create(); @@ -122,7 +122,7 @@ public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable { origbitmap = 0; hbitmap = 0; nw.setSurfaceHandle(0); - setChosenNWCapabilities(null); + setChosenGLCapabilities(null); } } } diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOnscreenWGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOnscreenWGLDrawable.java index ef9bf49c1..368462d6b 100644 --- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOnscreenWGLDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsOnscreenWGLDrawable.java @@ -54,8 +54,8 @@ public class WindowsOnscreenWGLDrawable extends WindowsWGLDrawable { private long profilingSwapBuffersTime; protected WindowsOnscreenWGLDrawable(GLDrawableFactory factory, NativeWindow component, - NWCapabilities capabilities, - NWCapabilitiesChooser chooser) { + GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { super(factory, component, false, capabilities, chooser); } diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLContext.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLContext.java index 87921f7e0..19c0d9d9c 100644 --- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLContext.java +++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLContext.java @@ -63,7 +63,7 @@ public class WindowsPbufferWGLContext extends WindowsWGLContext { public void bindPbufferToTexture() { if (!rtt) { throw new GLException("Shouldn't try to bind a pbuffer to a texture if render-to-texture hasn't been " + - "specified in its NWCapabilities"); + "specified in its GLCapabilities"); } GL gl = getGL(); WGLExt wglExt = getWGLExt(); @@ -81,7 +81,7 @@ public class WindowsPbufferWGLContext extends WindowsWGLContext { public void releasePbufferFromTexture() { if (!rtt) { throw new GLException("Shouldn't try to bind a pbuffer to a texture if render-to-texture hasn't been " + - "specified in its NWCapabilities"); + "specified in its GLCapabilities"); } if (rtt && hasRTT) { WGLExt wglExt = getWGLExt(); @@ -97,7 +97,7 @@ public class WindowsPbufferWGLContext extends WindowsWGLContext { System.err.println("WindowsPbufferWGLContext: super.makeCurrentImpl() = " + res); } if (res == CONTEXT_CURRENT_NEW) { - NWCapabilities capabilities = drawable.getRequestedNWCapabilities(); + GLCapabilities capabilities = drawable.getRequestedGLCapabilities(); // Initialize render-to-texture support if requested GL gl = getGL(); diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java index c829cca63..f0c0503e1 100644 --- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsPbufferWGLDrawable.java @@ -53,7 +53,7 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { private int floatMode; public WindowsPbufferWGLDrawable(GLDrawableFactory factory, - NWCapabilities requestedCapabilities, + GLCapabilities requestedCapabilities, int width, int height, WindowsWGLDrawable dummyDrawable, @@ -96,7 +96,7 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { throw new GLException("Error destroying pbuffer: error code " + WGL.GetLastError()); } buffer = 0; - setChosenNWCapabilities(null); + setChosenGLCapabilities(null); } } @@ -126,8 +126,8 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { } // This is public to allow access from PbufferContext - public NWCapabilities getRequestedNWCapabilities() { - return super.getRequestedNWCapabilities(); + public GLCapabilities getRequestedGLCapabilities() { + return super.getRequestedGLCapabilities(); } private void createPbuffer(long parentHdc, WGLExt wglExt) { @@ -137,7 +137,7 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { int niattribs = 0; int width, height; - NWCapabilities capabilities = getRequestedNWCapabilities(); + GLCapabilities capabilities = getRequestedGLCapabilities(); if (DEBUG) { System.out.println("Pbuffer parentHdc = " + toHexString(parentHdc)); @@ -309,7 +309,7 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { int[] ivalues = new int[niattribs]; // FIXME: usually prefer to throw exceptions, but failure here is not critical if (wglExt.wglGetPixelFormatAttribiv(parentHdc, pformats[whichFormat], 0, niattribs, iattributes, 0, ivalues, 0)) { - setChosenNWCapabilities(iattributes2NWCapabilities(iattributes, niattribs, ivalues, false)); + setChosenGLCapabilities(iattributes2GLCapabilities(iattributes, niattribs, ivalues, false)); } } diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawable.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawable.java index 534b0adf0..1885de1db 100644 --- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawable.java @@ -46,7 +46,7 @@ import com.sun.opengl.impl.*; public abstract class WindowsWGLDrawable extends GLDrawableImpl { protected static final boolean DEBUG = Debug.debug("WindowsWGLDrawable"); - protected NWCapabilitiesChooser chooser; + protected GLCapabilitiesChooser chooser; protected boolean pixelFormatChosen; // Workaround for problems on Intel 82855 cards @@ -57,8 +57,8 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl { protected static final int MAX_ATTRIBS = 256; public WindowsWGLDrawable(GLDrawableFactory factory, NativeWindow comp, boolean realized, - NWCapabilities requestedCapabilities, - NWCapabilitiesChooser chooser) { + GLCapabilities requestedCapabilities, + GLCapabilitiesChooser chooser) { super(factory, comp, requestedCapabilities, realized); this.chooser = chooser; } @@ -90,7 +90,7 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl { } return NativeWindow.LOCK_SURFACE_NOT_READY; } else { - // Probably a user error in the NWCapabilitiesChooser or similar. + // Probably a user error in the GLCapabilitiesChooser or similar. // Don't propagate non-GLExceptions out because calling code // expects to catch only that exception type throw new GLException(e); @@ -104,8 +104,8 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl { protected void choosePixelFormat(boolean onscreen) { PIXELFORMATDESCRIPTOR pfd = null; int pixelFormat = 0; - NWCapabilities chosenCaps = null; - NWCapabilities capabilities = getRequestedNWCapabilities(); + GLCapabilities chosenCaps = null; + GLCapabilities capabilities = getRequestedGLCapabilities(); long hdc = getNativeWindow().getSurfaceHandle(); if (onscreen) { if ((pixelFormat = WGL.GetPixelFormat(hdc)) != 0) { @@ -121,15 +121,15 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl { throw new GLException("Unable to describe pixel format " + pixelFormat + " of window set by Java2D/OpenGL pipeline"); } - setChosenNWCapabilities(pfd2NWCapabilities(pfd)); + setChosenGLCapabilities(pfd2GLCapabilities(pfd)); pixelFormatChosen = true; return; } - NWCapabilities[] availableCaps = null; + GLCapabilities[] availableCaps = null; int numFormats = 0; pfd = newPixelFormatDescriptor(); - // Produce a recommended pixel format selection for the NWCapabilitiesChooser. + // Produce a recommended pixel format selection for the GLCapabilitiesChooser. // Use wglChoosePixelFormatARB if user requested multisampling and if we have it available WindowsWGLDrawable dummyDrawable = null; GLContextImpl dummyContext = null; @@ -187,17 +187,17 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl { if (recommendedPixelFormat < 0) { System.err.print(getThreadName() + ": wglChoosePixelFormatARB didn't recommend a pixel format"); if (capabilities.getSampleBuffers()) { - System.err.print(" for multisampled NWCapabilities"); + System.err.print(" for multisampled GLCapabilities"); } System.err.println(); } } - // Produce a list of NWCapabilities to give to the - // NWCapabilitiesChooser. + // Produce a list of GLCapabilities to give to the + // GLCapabilitiesChooser. // Use wglGetPixelFormatAttribivARB instead of // DescribePixelFormat to get higher-precision information - // about the pixel format (should make the NWCapabilities + // about the pixel format (should make the GLCapabilities // more precise as well...i.e., remove the // "HardwareAccelerated" bit, which is basically // meaningless, and put in whether it can render to a @@ -213,7 +213,7 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl { // Should we be filtering out the pixel formats which aren't // applicable, as we are doing here? - // We don't have enough information in the NWCapabilities to + // We don't have enough information in the GLCapabilities to // represent those that aren't... iattributes[niattribs++] = WGLExt.WGL_DRAW_TO_WINDOW; iattributes[niattribs++] = WGLExt.WGL_ACCELERATION; @@ -236,12 +236,12 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl { iattributes[niattribs++] = WGLExt.WGL_SAMPLES; } - availableCaps = new NWCapabilities[numFormats]; + availableCaps = new GLCapabilities[numFormats]; for (int i = 0; i < numFormats; i++) { if (!dummyWGLExt.wglGetPixelFormatAttribiv(hdc, i+1, 0, niattribs, iattributes, 0, iresults, 0)) { throw new GLException("Error getting pixel format attributes for pixel format " + (i + 1) + " of device context"); } - availableCaps[i] = iattributes2NWCapabilities(iattributes, niattribs, iresults, true); + availableCaps[i] = iattributes2GLCapabilities(iattributes, niattribs, iresults, true); } gotAvailableCaps = true; } else { @@ -279,27 +279,31 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl { numFormats = WGL.DescribePixelFormat(hdc, 1, 0, null); if (numFormats == 0) { throw new GLException("Unable to enumerate pixel formats of window " + - toHexString(hdc) + " for NWCapabilitiesChooser"); + toHexString(hdc) + " for GLCapabilitiesChooser"); } - availableCaps = new NWCapabilities[numFormats]; + availableCaps = new GLCapabilities[numFormats]; for (int i = 0; i < numFormats; i++) { if (WGL.DescribePixelFormat(hdc, 1 + i, pfd.size(), pfd) == 0) { throw new GLException("Error describing pixel format " + (1 + i) + " of device context"); } - availableCaps[i] = pfd2NWCapabilities(pfd); + availableCaps[i] = pfd2GLCapabilities(pfd); } } // NOTE: officially, should make a copy of all of these - // NWCapabilities to avoid mutation by the end user during the + // GLCapabilities to avoid mutation by the end user during the // chooseCapabilities call, but for the time being, assume they // won't be changed // Supply information to chooser - pixelFormat = chooser.chooseCapabilities(capabilities, availableCaps, recommendedPixelFormat); + try { + pixelFormat = chooser.chooseCapabilities(capabilities, availableCaps, recommendedPixelFormat); + } catch (NativeWindowException e) { + throw new GLException(e); + } if ((pixelFormat < 0) || (pixelFormat >= numFormats)) { throw new GLException("Invalid result " + pixelFormat + - " from NWCapabilitiesChooser (should be between 0 and " + + " from GLCapabilitiesChooser (should be between 0 and " + (numFormats - 1) + ")"); } if (DEBUG) { @@ -327,19 +331,19 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl { } throw new GLException("Unable to set pixel format " + pixelFormat + " for device context " + toHexString(hdc) + ": error code " + lastError); } - // Reuse the previously-constructed NWCapabilities because it + // Reuse the previously-constructed GLCapabilities because it // turns out that using DescribePixelFormat on some pixel formats // (which, for example, support full-scene antialiasing) for some // reason return that they are not OpenGL-capable if (chosenCaps != null) { - setChosenNWCapabilities(chosenCaps); + setChosenGLCapabilities(chosenCaps); } else { - setChosenNWCapabilities(pfd2NWCapabilities(pfd)); + setChosenGLCapabilities(pfd2GLCapabilities(pfd)); } pixelFormatChosen = true; } - protected static PIXELFORMATDESCRIPTOR glCapabilities2PFD(NWCapabilities caps, boolean onscreen) { + protected static PIXELFORMATDESCRIPTOR glCapabilities2PFD(GLCapabilities caps, boolean onscreen) { int colorDepth = (caps.getRedBits() + caps.getGreenBits() + caps.getBlueBits()); @@ -388,11 +392,11 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl { return pfd; } - protected static NWCapabilities pfd2NWCapabilities(PIXELFORMATDESCRIPTOR pfd) { + protected static GLCapabilities pfd2GLCapabilities(PIXELFORMATDESCRIPTOR pfd) { if ((pfd.dwFlags() & WGL.PFD_SUPPORT_OPENGL) == 0) { return null; } - NWCapabilities res = new NWCapabilities(); + GLCapabilities res = new GLCapabilities(); res.setRedBits (pfd.cRedBits()); res.setGreenBits (pfd.cGreenBits()); res.setBlueBits (pfd.cBlueBits()); @@ -410,7 +414,7 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl { return res; } - protected static boolean glCapabilities2iattributes(NWCapabilities capabilities, + protected static boolean glCapabilities2iattributes(GLCapabilities capabilities, int[] iattributes, WGLExt wglExt, boolean pbuffer, @@ -532,7 +536,7 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl { } else { if (!rtt) { // Currently we don't support non-truecolor visuals in the - // NWCapabilities, so we don't offer the option of making + // GLCapabilities, so we don't offer the option of making // color-index pbuffers. iattributes[niattribs++] = WGLExt.WGL_PIXEL_TYPE; iattributes[niattribs++] = WGLExt.WGL_TYPE_RGBA; @@ -565,11 +569,11 @@ public abstract class WindowsWGLDrawable extends GLDrawableImpl { return true; } - protected static NWCapabilities iattributes2NWCapabilities(int[] iattribs, + protected static GLCapabilities iattributes2GLCapabilities(int[] iattribs, int niattribs, int[] iresults, boolean requireRenderToWindow) { - NWCapabilities res = new NWCapabilities(); + GLCapabilities res = new GLCapabilities(); for (int i = 0; i < niattribs; i++) { int attr = iattribs[i]; switch (attr) { diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java index d5dd930ed..10d7c5a22 100644 --- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java @@ -58,30 +58,24 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { super(); } - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, - AbstractGraphicsDevice device) { - return null; - } - public GLDrawable createGLDrawable(NativeWindow target, - NWCapabilities capabilities, - NWCapabilitiesChooser chooser) { + GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { if (target == null) { throw new IllegalArgumentException("Null target"); } target = NativeWindowFactory.getNativeWindow(target); if (capabilities == null) { - capabilities = new NWCapabilities(); + capabilities = new GLCapabilities(); } if (chooser == null) { - chooser = new DefaultNWCapabilitiesChooser(); + chooser = new DefaultGLCapabilitiesChooser(); } return new WindowsOnscreenWGLDrawable(this, target, capabilities, chooser); } - public GLDrawableImpl createOffscreenDrawable(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + public GLDrawableImpl createOffscreenDrawable(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, int width, int height) { return new WindowsOffscreenWGLDrawable(this, capabilities, chooser, width, height); @@ -122,8 +116,8 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { return canCreateGLPbuffer; } - public GLPbuffer createGLPbuffer(final NWCapabilities capabilities, - final NWCapabilitiesChooser chooser, + public GLPbuffer createGLPbuffer(final GLCapabilities capabilities, + final GLCapabilitiesChooser chooser, final int initialWidth, final int initialHeight, final GLContext shareWith) { diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawable.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawable.java index 2f1f777c9..0b916213c 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawable.java @@ -47,11 +47,11 @@ import com.sun.nativewindow.impl.x11.*; public abstract class X11GLXDrawable extends GLDrawableImpl { protected static final boolean DEBUG = Debug.debug("X11GLXDrawable"); - protected NWCapabilitiesChooser chooser; + protected GLCapabilitiesChooser chooser; protected X11GLXDrawable(GLDrawableFactory factory, NativeWindow comp, boolean realized, - NWCapabilities requestedCapabilities, - NWCapabilitiesChooser chooser) { + GLCapabilities requestedCapabilities, + GLCapabilitiesChooser chooser) { super(factory, comp, requestedCapabilities, realized); this.chooser = chooser; } @@ -62,7 +62,7 @@ public abstract class X11GLXDrawable extends GLDrawableImpl { protected XVisualInfo chooseVisual(boolean onscreen) { long display = getNativeWindow().getDisplayHandle(); - long visualID = getNativeWindow().getVisualID(); + long visualID = ((X11GLXDrawableFactory) getFactory()).getVisualID(getNativeWindow().getGraphicsConfiguration()); if (display == 0) { throw new GLException("null display"); } @@ -105,24 +105,29 @@ public abstract class X11GLXDrawable extends GLDrawableImpl { XVisualInfo template = XVisualInfo.create(); template.screen(screen); XVisualInfo[] infos = null; - NWCapabilities[] caps = null; + GLCapabilities[] caps = null; getFactoryImpl().lockToolkit(); try { infos = X11Lib.XGetVisualInfo(display, X11Lib.VisualScreenMask, template, count, 0); if (infos == null) { throw new GLException("Error while enumerating available XVisualInfos"); } - caps = new NWCapabilities[infos.length]; + caps = new GLCapabilities[infos.length]; for (int i = 0; i < infos.length; i++) { - caps[i] = ((X11GLXDrawableFactory)getFactory()).xvi2NWCapabilities(display, infos[i]); + caps[i] = ((X11GLXDrawableFactory)getFactory()).xvi2GLCapabilities(display, infos[i]); } } finally { getFactoryImpl().unlockToolkit(); } - NWCapabilities capabilities = getRequestedNWCapabilities(); - int chosen = chooser.chooseCapabilities(capabilities, caps, -1); + GLCapabilities capabilities = getRequestedGLCapabilities(); + int chosen; + try { + chosen = chooser.chooseCapabilities(capabilities, caps, -1); + } catch (NativeWindowException e) { + throw new GLException(e); + } if (chosen < 0 || chosen >= caps.length) { - throw new GLException("NWCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); + throw new GLException("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); } if (DEBUG) { System.err.println("Chosen visual (" + chosen + "):"); @@ -130,7 +135,7 @@ public abstract class X11GLXDrawable extends GLDrawableImpl { } vis = infos[chosen]; if (vis == null) { - throw new GLException("NWCapabilitiesChooser chose an invalid visual"); + throw new GLException("GLCapabilitiesChooser chose an invalid visual"); } // FIXME: the storage for the infos array is leaked (should // clean it up somehow when we're done with the visual we're diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawableFactory.java index a0c3a7758..3ca1396d2 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXDrawableFactory.java @@ -40,18 +40,21 @@ import java.nio.*; import java.security.*; import java.util.*; import javax.media.nativewindow.*; +import javax.media.nativewindow.x11.*; import javax.media.opengl.*; import com.sun.gluegen.runtime.*; import com.sun.gluegen.runtime.opengl.*; import com.sun.opengl.impl.*; import com.sun.opengl.impl.x11.glx.*; import com.sun.nativewindow.impl.NullWindow; +import com.sun.nativewindow.impl.NWReflection; import com.sun.nativewindow.impl.x11.*; +import com.sun.nativewindow.impl.jawt.x11.*; public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { protected static final boolean DEBUG = Debug.debug("X11GLXDrawableFactory"); - // Map for rediscovering the NWCapabilities associated with a + // Map for rediscovering the GLCapabilities associated with a // particular screen and visualID after the fact protected static Map visualToGLCapsMap = Collections.synchronizedMap(new HashMap()); // The screens for which we've already initialized it @@ -90,19 +93,27 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { // Must initialize GLX support eagerly in case a pbuffer is the // first thing instantiated GLProcAddressHelper.resetProcAddressTable(GLX.getGLXProcAddressTable(), this); + // Register our GraphicsConfigurationFactory implementations + // The act of constructing them causes them to be registered + new X11GLXGraphicsConfigurationFactory(); + try { + NWReflection.createInstance("com.sun.opengl.impl.x11.glx.awt.X11AWTGLXGraphicsConfigurationFactory", + new Object[] {}); + } catch (Exception e) { + } } private static final int MAX_ATTRIBS = 128; - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + public AbstractGraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, AbstractGraphicsDevice absDevice) { return null; } public GLDrawable createGLDrawable(NativeWindow target, - NWCapabilities capabilities, - NWCapabilitiesChooser chooser) { + GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { if (target == null) { throw new IllegalArgumentException("Null target"); } @@ -110,9 +121,9 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return new X11OnscreenGLXDrawable(this, target); } - public void initializeVisualToNWCapabilitiesMap(int screen, + public void initializeVisualToGLCapabilitiesMap(int screen, XVisualInfo[] infos, - NWCapabilities[] caps) { + GLCapabilities[] caps) { Integer key = new Integer(screen); if (!initializedScreenSet.contains(key)) { for (int i = 0; i < infos.length; i++) { @@ -125,13 +136,32 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } } - public NWCapabilities lookupCapabilitiesByScreenAndVisualID(int screenIndex, - long visualID) { - return (NWCapabilities) visualToGLCapsMap.get(new ScreenAndVisualIDKey(screenIndex, visualID)); + public GLCapabilities lookupCapabilitiesByScreenAndConfig(int screenIndex, + AbstractGraphicsConfiguration config) { + return (GLCapabilities) visualToGLCapsMap.get(new ScreenAndVisualIDKey(screenIndex, getVisualID(config))); + } + + public long getVisualID(AbstractGraphicsConfiguration config) { + if (config == null) { + return 0; + } + // FIXME: this is hopefully the last remaining place in this + // implementation that is over-specialized; third-party toolkits + // would need to use the X11GraphicsConfiguration in order to + // interoperate with this code + if (config instanceof X11GraphicsConfiguration) { + return ((X11GraphicsConfiguration) config).getVisualID(); + } + try { + // The AWT-specific code and casts have been moved to the X11SunJDKReflection helper class + return X11SunJDKReflection.graphicsConfigurationGetVisualID(config); + } catch (Throwable t) { + return 0; + } } - public GLDrawableImpl createOffscreenDrawable(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + public GLDrawableImpl createOffscreenDrawable(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, int width, int height) { return new X11OffscreenGLXDrawable(this, capabilities, chooser, width, height); @@ -181,8 +211,8 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return canCreateGLPbuffer; } - public GLPbuffer createGLPbuffer(final NWCapabilities capabilities, - final NWCapabilitiesChooser chooser, + public GLPbuffer createGLPbuffer(final GLCapabilities capabilities, + final GLCapabilitiesChooser chooser, final int initialWidth, final int initialHeight, final GLContext shareWith) { @@ -230,7 +260,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return res; } - public NWCapabilities xvi2NWCapabilities(long display, XVisualInfo info) { + public GLCapabilities xvi2GLCapabilities(long display, XVisualInfo info) { int[] tmp = new int[1]; int val = glXGetConfig(display, info, GLX.GLX_USE_GL, tmp, 0); if (val == 0) { @@ -242,12 +272,12 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { // Visual does not support RGBA return null; } - NWCapabilities res = new NWCapabilities(); + GLCapabilities res = new GLCapabilities(); res.setDoubleBuffered(glXGetConfig(display, info, GLX.GLX_DOUBLEBUFFER, tmp, 0) != 0); res.setStereo (glXGetConfig(display, info, GLX.GLX_STEREO, tmp, 0) != 0); // Note: use of hardware acceleration is determined by // glXCreateContext, not by the XVisualInfo. Optimistically claim - // that all NWCapabilities have the capability to be hardware + // that all GLCapabilities have the capability to be hardware // accelerated. res.setHardwareAccelerated(true); res.setDepthBits (glXGetConfig(display, info, GLX.GLX_DEPTH_SIZE, tmp, 0)); @@ -267,7 +297,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return res; } - public static int[] glCapabilities2AttribList(NWCapabilities caps, + public static int[] glCapabilities2AttribList(GLCapabilities caps, boolean isMultisampleAvailable, boolean pbuffer, long display, @@ -357,11 +387,11 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return res; } - public static NWCapabilities attribList2NWCapabilities(int[] iattribs, + public static GLCapabilities attribList2GLCapabilities(int[] iattribs, int niattribs, int[] ivalues, boolean pbuffer) { - NWCapabilities caps = new NWCapabilities(); + GLCapabilities caps = new GLCapabilities(); for (int i = 0; i < niattribs; i++) { int attr = iattribs[i]; diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXNativeWindowFactory.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java index 3944f4180..8120dca52 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXNativeWindowFactory.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java @@ -43,44 +43,58 @@ import javax.media.opengl.*; import com.sun.opengl.impl.*; import com.sun.opengl.impl.x11.glx.*; -/** Subclass of NativeWindowFactory used when non-AWT tookits are used - on X11 platforms. Toolkits will likely need to subclass this one - to add synchronization in certain places and change the accepted - and returned types of the GraphicsDevice and GraphicsConfiguration - abstractions. */ - -public class X11GLXNativeWindowFactory extends NativeWindowFactoryImpl { - - public X11GLXNativeWindowFactory() { - NativeWindowFactory.registerFactory(javax.media.nativewindow.NativeWindow.class, this); +/** Subclass of GraphicsConfigurationFactory used when non-AWT tookits + are used on X11 platforms. Toolkits will likely need to delegate + to this one to change the accepted and returned types of the + GraphicsDevice and GraphicsConfiguration abstractions. */ + +public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFactory { + // Keep this under the same debug flag as the drawable factory for convenience + protected static final boolean DEBUG = Debug.debug("X11GLXDrawableFactory"); + + public X11GLXGraphicsConfigurationFactory() { + GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.x11.X11GraphicsDevice.class, + this); } - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + public AbstractGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities, + CapabilitiesChooser chooser, AbstractGraphicsDevice absDevice) { if (absDevice != null && !(absDevice instanceof X11GraphicsDevice)) { throw new IllegalArgumentException("This NativeWindowFactory accepts only X11GraphicsDevice objects"); } + if (capabilities != null && + !(capabilities instanceof GLCapabilities)) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilities objects"); + } + + if (chooser != null && + !(chooser instanceof GLCapabilitiesChooser)) { + throw new IllegalArgumentException("This NativeWindowFactory accepts only GLCapabilitiesChooser objects"); + } + int screen = 0; if (absDevice != null) { screen = ((X11GraphicsDevice) absDevice).getScreen(); } - long visualID = chooseGraphicsConfigurationImpl(capabilities, chooser, screen); + long visualID = chooseGraphicsConfigurationImpl((GLCapabilities) capabilities, + (GLCapabilitiesChooser) chooser, + screen); return new X11GraphicsConfiguration(visualID); } /** Returns the visual ID of the chosen GraphicsConfiguration. */ - protected long chooseGraphicsConfigurationImpl(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + protected long chooseGraphicsConfigurationImpl(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, int screen) { if (capabilities == null) { - capabilities = new NWCapabilities(); + capabilities = new GLCapabilities(); } if (chooser == null) { - chooser = new DefaultNWCapabilitiesChooser(); + chooser = new DefaultGLCapabilitiesChooser(); } if (X11Util.isXineramaEnabled()) { @@ -93,9 +107,9 @@ public class X11GLXNativeWindowFactory extends NativeWindowFactoryImpl { int[] attribs = X11GLXDrawableFactory.glCapabilities2AttribList(capabilities, GLXUtil.isMultisampleAvailable(), false, 0, 0); XVisualInfo[] infos = null; - NWCapabilities[] caps = null; + GLCapabilities[] caps = null; int recommendedIndex = -1; - getDefaultFactory().getToolkitLock().lock(); + NativeWindowFactory.getDefaultFactory().getToolkitLock().lock(); try { long display = X11Util.getDisplayConnection(); XVisualInfo recommendedVis = GLX.glXChooseVisual(display, screen, attribs, 0); @@ -114,66 +128,33 @@ public class X11GLXNativeWindowFactory extends NativeWindowFactoryImpl { if (infos == null) { throw new GLException("Error while enumerating available XVisualInfos"); } - caps = new NWCapabilities[infos.length]; + caps = new GLCapabilities[infos.length]; for (int i = 0; i < infos.length; i++) { - caps[i] = ((X11GLXDrawableFactory) GLDrawableFactory.getFactory()).xvi2NWCapabilities(display, infos[i]); + caps[i] = ((X11GLXDrawableFactory) GLDrawableFactory.getFactory()).xvi2GLCapabilities(display, infos[i]); // Attempt to find the visual chosen by glXChooseVisual if (recommendedVis != null && recommendedVis.visualid() == infos[i].visualid()) { recommendedIndex = i; } } } finally { - getDefaultFactory().getToolkitLock().unlock(); + NativeWindowFactory.getDefaultFactory().getToolkitLock().unlock(); } // Store these away for later ((X11GLXDrawableFactory) GLDrawableFactory.getFactory()). - initializeVisualToNWCapabilitiesMap(screen, infos, caps); - int chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); + initializeVisualToGLCapabilitiesMap(screen, infos, caps); + int chosen; + try { + chosen = chooser.chooseCapabilities(capabilities, caps, recommendedIndex); + } catch (NativeWindowException e) { + throw new GLException(e); + } if (chosen < 0 || chosen >= caps.length) { - throw new GLException("NWCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); + throw new GLException("GLCapabilitiesChooser specified invalid index (expected 0.." + (caps.length - 1) + ")"); } XVisualInfo vis = infos[chosen]; if (vis == null) { - throw new GLException("NWCapabilitiesChooser chose an invalid visual"); + throw new GLException("GLCapabilitiesChooser chose an invalid visual"); } return vis.visualid(); } - - // On X11 platforms we need to do some locking; this basic - // implementation should suffice for some simple window toolkits - private ToolkitLock toolkitLock = new ToolkitLock() { - private Thread owner; - private int recursionCount; - - public synchronized void lock() { - Thread cur = Thread.currentThread(); - if (owner == cur) { - ++recursionCount; - return; - } - while (owner != null) { - try { - wait(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - owner = cur; - } - - public synchronized void unlock() { - if (owner != Thread.currentThread()) { - throw new RuntimeException("Not owner"); - } - if (recursionCount > 0) { - --recursionCount; - return; - } - owner = null; - } - }; - - public ToolkitLock getToolkitLock() { - return toolkitLock; - } } diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java index 46712bced..63dcca80e 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java @@ -50,8 +50,8 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { private boolean isDoubleBuffered; protected X11OffscreenGLXDrawable(GLDrawableFactory factory, - NWCapabilities requestedCapabilities, - NWCapabilitiesChooser chooser, + GLCapabilities requestedCapabilities, + GLCapabilitiesChooser chooser, int width, int height) { super(factory, new NullWindow(), true, requestedCapabilities, chooser); @@ -92,7 +92,7 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { ", GLXPixmap " + toHexString(drawable) + ", display " + toHexString(dpy)); } - setChosenNWCapabilities(((X11GLXDrawableFactory)getFactory()).xvi2NWCapabilities(dpy, vis)); + setChosenGLCapabilities(((X11GLXDrawableFactory)getFactory()).xvi2GLCapabilities(dpy, vis)); } finally { getFactoryImpl().unlockToolkit(); } @@ -131,7 +131,7 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { drawable = 0; pixmap = 0; display = 0; - setChosenNWCapabilities(null); + setChosenGLCapabilities(null); } finally { getFactoryImpl().unlockToolkit(); } diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXContext.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXContext.java index 9da86205d..b4370e142 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXContext.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXContext.java @@ -61,11 +61,11 @@ public class X11OnscreenGLXContext extends X11GLXContext { protected int makeCurrentImpl() throws GLException { int lockRes = drawable.lockSurface(); - if (drawable.getChosenNWCapabilities() == null) { + if (drawable.getChosenGLCapabilities() == null) { X11GLXDrawableFactory factory = (X11GLXDrawableFactory) drawable.getFactory(); NativeWindow window = drawable.getNativeWindow(); - drawable.setChosenNWCapabilities(factory.lookupCapabilitiesByScreenAndVisualID(window.getScreenIndex(), - window.getVisualID())); + drawable.setChosenGLCapabilities(factory.lookupCapabilitiesByScreenAndConfig(window.getScreenIndex(), + window.getGraphicsConfiguration())); } boolean exceptionOccurred = false; try { diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXDrawable.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXDrawable.java index 5c1a5071c..4a22940b6 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11OnscreenGLXDrawable.java @@ -79,16 +79,16 @@ public class X11OnscreenGLXDrawable extends X11GLXDrawable { } // This is public to allow access from the DrawableFactory - protected void setChosenNWCapabilities(NWCapabilities caps) { - super.setChosenNWCapabilities(caps); + protected void setChosenGLCapabilities(GLCapabilities caps) { + super.setChosenGLCapabilities(caps); } public void setRealized(boolean realized) { if (realized) { X11GLXDrawableFactory factory = (X11GLXDrawableFactory) getFactory(); NativeWindow window = getNativeWindow(); - setChosenNWCapabilities(factory.lookupCapabilitiesByScreenAndVisualID(window.getScreenIndex(), - window.getVisualID())); + setChosenGLCapabilities(factory.lookupCapabilitiesByScreenAndConfig(window.getScreenIndex(), + window.getGraphicsConfiguration())); } super.setRealized(realized); } diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11PbufferGLXDrawable.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11PbufferGLXDrawable.java index 99aebb4ed..91be786dd 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11PbufferGLXDrawable.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/X11PbufferGLXDrawable.java @@ -56,7 +56,7 @@ public class X11PbufferGLXDrawable extends X11GLXDrawable { protected static final int MAX_ATTRIBS = 256; protected X11PbufferGLXDrawable(GLDrawableFactory factory, - NWCapabilities requestedCapabilities, + GLCapabilities requestedCapabilities, int width, int height) { super(factory, new NullWindow(), true, requestedCapabilities, null); if (width <= 0 || height <= 0) { @@ -106,7 +106,7 @@ public class X11PbufferGLXDrawable extends X11GLXDrawable { int screen = X11Lib.DefaultScreen(display); nw.setScreenIndex(screen); - NWCapabilities capabilities = getRequestedNWCapabilities(); + GLCapabilities capabilities = getRequestedGLCapabilities(); if (capabilities.getPbufferRenderToTexture()) { throw new GLException("Render-to-texture pbuffers not supported yet on X11"); @@ -174,7 +174,7 @@ public class X11PbufferGLXDrawable extends X11GLXDrawable { int samplesAttrib = GLXUtil.isMultisampleAvailable() ? GLX.GLX_SAMPLES: GLX.GLX_RED_SIZE; int floatNV = capabilities.getPbufferFloatingPointBuffers() ? GLXExt.GLX_FLOAT_COMPONENTS_NV : GLX.GLX_RED_SIZE; - // Query the fbconfig to determine its NWCapabilities + // Query the fbconfig to determine its GLCapabilities int[] iattribs = { GLX.GLX_DOUBLEBUFFER, GLX.GLX_STEREO, @@ -195,7 +195,7 @@ public class X11PbufferGLXDrawable extends X11GLXDrawable { int[] ivalues = new int[iattribs.length]; queryFBConfig(display, fbConfig, iattribs, iattribs.length, ivalues); - setChosenNWCapabilities(X11GLXDrawableFactory.attribList2NWCapabilities(iattribs, iattribs.length, ivalues, true)); + setChosenGLCapabilities(X11GLXDrawableFactory.attribList2GLCapabilities(iattribs, iattribs.length, ivalues, true)); // Determine the actual width and height we were able to create. int[] tmp = new int[1]; diff --git a/src/jogl/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXNativeWindowFactory.java b/src/jogl/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java index 4029d90bd..0d75056c4 100644 --- a/src/jogl/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXNativeWindowFactory.java +++ b/src/jogl/classes/com/sun/opengl/impl/x11/glx/awt/X11AWTGLXGraphicsConfigurationFactory.java @@ -36,8 +36,10 @@ import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import javax.media.nativewindow.*; -import javax.media.nativewindow.awt.AWTGraphicsDevice; +import javax.media.nativewindow.x11.X11GraphicsConfiguration; +import javax.media.nativewindow.x11.X11GraphicsDevice; import javax.media.nativewindow.awt.AWTGraphicsConfiguration; +import javax.media.nativewindow.awt.AWTGraphicsDevice; import javax.media.opengl.*; import javax.media.opengl.awt.*; @@ -47,26 +49,19 @@ import com.sun.nativewindow.impl.jawt.x11.*; import com.sun.opengl.impl.x11.*; import com.sun.opengl.impl.x11.glx.*; -public class X11AWTGLXNativeWindowFactory extends X11GLXNativeWindowFactory { - - public X11AWTGLXNativeWindowFactory() { - Class componentClass = null; - try { - componentClass = Class.forName("java.awt.Component"); - } catch (Exception e) { - throw new GLException(e); - } - - NativeWindowFactory.registerFactory(componentClass, this); +public class X11AWTGLXGraphicsConfigurationFactory extends GraphicsConfigurationFactory { + public X11AWTGLXGraphicsConfigurationFactory() { + GraphicsConfigurationFactory.registerFactory(javax.media.nativewindow.awt.AWTGraphicsDevice.class, + this); } - public AbstractGraphicsConfiguration chooseGraphicsConfiguration(NWCapabilities capabilities, - NWCapabilitiesChooser chooser, + public AbstractGraphicsConfiguration chooseGraphicsConfiguration(Capabilities capabilities, + CapabilitiesChooser chooser, AbstractGraphicsDevice absDevice) { GraphicsDevice device = null; if (absDevice != null && !(absDevice instanceof AWTGraphicsDevice)) { - throw new IllegalArgumentException("This NativeWindowFactory accepts only AWTGraphicsDevice objects"); + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only AWTGraphicsDevice objects"); } if ((absDevice == null) || @@ -76,21 +71,40 @@ public class X11AWTGLXNativeWindowFactory extends X11GLXNativeWindowFactory { device = ((AWTGraphicsDevice) absDevice).getGraphicsDevice(); } - long visualID = chooseGraphicsConfigurationImpl(capabilities, chooser, - X11SunJDKReflection.graphicsDeviceGetScreen(device)); + if (capabilities != null && + !(capabilities instanceof GLCapabilities)) { + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only GLCapabilities objects"); + } - // Now figure out which GraphicsConfiguration corresponds to this - // visual by matching the visual ID - GraphicsConfiguration[] configs = device.getConfigurations(); - for (int i = 0; i < configs.length; i++) { - GraphicsConfiguration config = configs[i]; - if (config != null) { - if (X11SunJDKReflection.graphicsConfigurationGetVisualID(config) == visualID) { - return new AWTGraphicsConfiguration(config); + if (chooser != null && + !(chooser instanceof GLCapabilitiesChooser)) { + throw new IllegalArgumentException("This GraphicsConfigurationFactory accepts only GLCapabilitiesChooser objects"); + } + + // Fabricate an X11GraphicsDevice and delegate to the GraphicsConfigurationFactory for those + // + // Note that we could derive from X11GLXGraphicsConfigurationFactory, but that would + // limit the ability of third parties to plug in new visual selection algorithms + X11GraphicsDevice x11Device = new X11GraphicsDevice(X11SunJDKReflection.graphicsDeviceGetScreen(device)); + X11GraphicsConfiguration x11Config = (X11GraphicsConfiguration) + GraphicsConfigurationFactory.getFactory(x11Device).chooseGraphicsConfiguration(capabilities, + chooser, + x11Device); + if (x11Config != null) { + long visualID = x11Config.getVisualID(); + // Now figure out which GraphicsConfiguration corresponds to this + // visual by matching the visual ID + GraphicsConfiguration[] configs = device.getConfigurations(); + for (int i = 0; i < configs.length; i++) { + GraphicsConfiguration config = configs[i]; + if (config != null) { + if (X11SunJDKReflection.graphicsConfigurationGetVisualID(config) == visualID) { + return new AWTGraphicsConfiguration(config); + } } } } - + // Either we weren't able to reflectively introspect on the // X11GraphicsConfig or something went wrong in the steps above; // we're going to return null without signaling an error condition @@ -98,44 +112,4 @@ public class X11AWTGLXNativeWindowFactory extends X11GLXNativeWindowFactory { // and possibly report more of an error in the latter case) return null; } - - // When running the AWT on X11 platforms, we use the AWT native - // interface (JAWT) to lock and unlock the toolkit - private ToolkitLock toolkitLock = new ToolkitLock() { - private Thread owner; - private int recursionCount; - - public synchronized void lock() { - Thread cur = Thread.currentThread(); - if (owner == cur) { - ++recursionCount; - return; - } - while (owner != null) { - try { - wait(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - owner = cur; - JAWTUtil.lockToolkit(); - } - - public synchronized void unlock() { - if (owner != Thread.currentThread()) { - throw new RuntimeException("Not owner"); - } - if (recursionCount > 0) { - --recursionCount; - return; - } - owner = null; - JAWTUtil.unlockToolkit(); - } - }; - - public ToolkitLock getToolkitLock() { - return toolkitLock; - } } diff --git a/src/jogl/classes/com/sun/opengl/util/awt/TextRenderer.java b/src/jogl/classes/com/sun/opengl/util/awt/TextRenderer.java index 58f021e90..d40339264 100755 --- a/src/jogl/classes/com/sun/opengl/util/awt/TextRenderer.java +++ b/src/jogl/classes/com/sun/opengl/util/awt/TextRenderer.java @@ -66,7 +66,6 @@ import java.text.*; import java.util.*; -import javax.media.nativewindow.*; import javax.media.opengl.*; import javax.media.opengl.glu.*; import javax.media.opengl.glu.gl2.*; @@ -902,7 +901,7 @@ public class TextRenderer { private void debug() { dbgFrame = new Frame("TextRenderer Debug Output"); - GLCanvas dbgCanvas = new GLCanvas(new NWCapabilities(), null, + GLCanvas dbgCanvas = new GLCanvas(new GLCapabilities(), null, GLContext.getCurrent(), null); dbgCanvas.addGLEventListener(new DebugListener(dbgFrame)); dbgFrame.add(dbgCanvas); |