diff options
author | Sven Gothel <[email protected]> | 2010-12-03 21:32:16 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2010-12-03 21:32:16 +0100 |
commit | 4b9ad2508ff31a03d3bc4482d812a6cbc0c5c33b (patch) | |
tree | 28212ee090a08c3fae1943a26e6ac4633ecc5090 /src/jogl/classes/com | |
parent | de9211df2c1654db889bb5d5c43297ed7d6499ba (diff) |
Cleanup GLDrawableFactory API and platform Implementations
- Finish API change using the AbstractGraphicsDevice, which denotes the target device
for the desired NativeSurface / GLDrawable.
The AbstractGraphicsDevice argument may be null to reflect the platform's default device.
Clarified API documentation.
This move is necessary to make the API coherent.
- createOffscreenDrawable(..) may create a Pbuffer drawable if caps and supported.
This unifies the functionality with createGLDrawable(..).
Further more, a Pbuffer drawable is an offscreen as well.
- added createOffscreenSurface(..) following the same behavior as createOffscreenDrawable(..),
this is a convenient native offscreen surface factory entry.
- removed createGLPbufferDrawable(..), use createOffscreenDrawable(..),
since it is redundant!
Implementation Details:
- EGLDrawableFactory holds a shared native EGLGraphicsDevice,
being used by the offscreen EGL drawable (no more multiple creation).
Diffstat (limited to 'src/jogl/classes/com')
13 files changed, 287 insertions, 214 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java index ef5f67081..01e0b8298 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/GLDrawableFactoryImpl.java @@ -55,7 +55,33 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { protected GLDrawableFactoryImpl() { super(); } - + + /** + * Returns the shared device mapped to the <code>device</code> {@link AbstractGraphicsDevice#getConnection()}, + * either a preexisting or newly created, or <code>null</code> if creation failed or not supported.<br> + * Creation of the shared context is tried only once. + * + * @param device which {@link javax.media.nativewindow.AbstractGraphicsDevice#getConnection() connection} denotes the shared device to be used, may be <code>null</code> for the platform's default device. + */ + protected final AbstractGraphicsDevice getOrCreateSharedDevice(AbstractGraphicsDevice device) { + if(null==device) { + device = getDefaultDevice(); + if(null==device) { + throw new InternalError("no default device"); + } + if (GLProfile.DEBUG) { + System.err.println("Info: GLDrawableFactoryImpl.getOrCreateSharedContext: using default device : "+device); + } + } else if( !getIsDeviceCompatible(device) ) { + if (GLProfile.DEBUG) { + System.err.println("Info: GLDrawableFactoryImpl.getOrCreateSharedContext: device not compatible : "+device); + } + return null; + } + return getOrCreateSharedDeviceImpl(device); + } + protected abstract AbstractGraphicsDevice getOrCreateSharedDeviceImpl(AbstractGraphicsDevice device); + /** * Returns the GLDynamicLookupHelper * @param profile if EGL/ES, profile <code>1</code> refers to ES1 and <code>2</code> to ES2, @@ -85,18 +111,10 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { if( ! ( target instanceof SurfaceChangeable ) ) { throw new IllegalArgumentException("Passed NativeSurface must implement SurfaceChangeable for offscreen: "+target); } - if(caps.isPBuffer() && canCreateGLPbuffer(adevice)) { - if(DEBUG) { - System.err.println("GLDrawableFactoryImpl.createGLDrawable -> PbufferDrawable: "+target); - } - result = createGLPbufferDrawable(target); - } - if(null==result) { - if(DEBUG) { - System.err.println("GLDrawableFactoryImpl.createGLDrawable -> OffScreenDrawable: "+target); - } - result = createOffscreenDrawableImpl(target); + if(DEBUG) { + System.err.println("GLDrawableFactoryImpl.createGLDrawable -> OffScreenDrawable (PBuffer: "+caps.isPBuffer()+"): "+target); } + result = createOffscreenDrawableImpl(target); } } finally { adevice.unlock(); @@ -121,20 +139,12 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { public abstract boolean canCreateGLPbuffer(AbstractGraphicsDevice device); - /** Target must implement SurfaceChangeable */ - protected abstract GLDrawableImpl createGLPbufferDrawableImpl(NativeSurface target); - - private GLDrawableImpl createGLPbufferDrawable(NativeSurface target) { - if (!canCreateGLPbuffer(target.getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice())) { - throw new GLException("Pbuffer support not available with current graphics card"); - } - return createGLPbufferDrawableImpl(target); - } - - public GLDrawable createGLPbufferDrawable(GLCapabilitiesImmutable capsRequested, - GLCapabilitiesChooser chooser, - int width, - int height) { + public GLPbuffer createGLPbuffer(AbstractGraphicsDevice deviceReq, + GLCapabilitiesImmutable capsRequested, + GLCapabilitiesChooser chooser, + int width, + int height, + GLContext shareWith) { if(height<=0 || height<=0) { throw new GLException("Width and height of pbuffer must be positive (were (" + width + ", " + height + "))"); @@ -142,6 +152,15 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { GLCapabilitiesImmutable capsChosen; + AbstractGraphicsDevice device = getOrCreateSharedDevice(deviceReq); + if(null == device) { + throw new GLException("No shared device for requested: "+deviceReq); + } + + if (!canCreateGLPbuffer(device)) { + throw new GLException("Pbuffer support not available with device: "+device); + } + if( capsRequested.getDoubleBuffered() || capsRequested.isOnscreen() || !capsRequested.isPBuffer()) { // fix caps .. GLCapabilities caps2 = (GLCapabilities) capsRequested.cloneMutable(); @@ -152,21 +171,19 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { } else { capsChosen = capsRequested; } - NativeWindowFactory.getDefaultToolkitLock().lock(); + + GLDrawableImpl drawable = null; + device.lock(); try { - return createGLPbufferDrawable( createOffscreenSurfaceImpl(capsChosen, capsRequested, chooser, height, height) ); + drawable = (GLDrawableImpl) createGLDrawable( createOffscreenSurfaceImpl(device, capsChosen, capsRequested, chooser, height, height) ); } finally { - NativeWindowFactory.getDefaultToolkitLock().unlock(); + device.unlock(); } - } - public GLPbuffer createGLPbuffer(GLCapabilitiesImmutable capabilities, - GLCapabilitiesChooser chooser, - int width, - int height, - GLContext shareWith) { - return new GLPbufferImpl( (GLDrawableImpl) createGLPbufferDrawable(capabilities, chooser, height, height), - shareWith); + if(null==drawable) { + throw new GLException("Could not create Pbuffer drawable for: "+device+", "+capsChosen+", "+width+"x"+height); + } + return new GLPbufferImpl( drawable, shareWith); } @@ -177,7 +194,8 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { protected abstract GLDrawableImpl createOffscreenDrawableImpl(NativeSurface target) ; - public GLDrawable createOffscreenDrawable(GLCapabilitiesImmutable capsRequested, + public GLDrawable createOffscreenDrawable(AbstractGraphicsDevice deviceReq, + GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) { @@ -185,6 +203,10 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { throw new GLException("Width and height of pbuffer must be positive (were (" + width + ", " + height + "))"); } + AbstractGraphicsDevice device = getOrCreateSharedDevice(deviceReq); + if(null == device) { + throw new GLException("No shared device for requested: "+deviceReq); + } GLCapabilitiesImmutable capsChosen; if( capsRequested.getDoubleBuffered() || capsRequested.isOnscreen() || capsRequested.isPBuffer()) { @@ -192,16 +214,49 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { GLCapabilities caps2 = (GLCapabilities) capsRequested.cloneMutable(); caps2.setDoubleBuffered(false); // FIXME DBLBUFOFFSCRN caps2.setOnscreen(false); - caps2.setPBuffer(false); + if(caps2.isPBuffer() && !canCreateGLPbuffer(device)) { + caps2.setPBuffer(false); + } capsChosen = caps2; } else { capsChosen = capsRequested; } - NativeWindowFactory.getDefaultToolkitLock().lock(); + device.lock(); try { - return createOffscreenDrawableImpl( createOffscreenSurfaceImpl(capsChosen, capsRequested, chooser, width, height) ); + return createGLDrawable( createOffscreenSurfaceImpl(device, capsChosen, capsRequested, chooser, width, height) ); } finally { - NativeWindowFactory.getDefaultToolkitLock().unlock(); + device.unlock(); + } + } + + public NativeSurface createOffscreenSurface(AbstractGraphicsDevice deviceReq, + GLCapabilitiesImmutable capsRequested, + GLCapabilitiesChooser chooser, + int width, int height) { + GLCapabilitiesImmutable capsChosen; + + AbstractGraphicsDevice device = getOrCreateSharedDevice(deviceReq); + if(null == device) { + throw new GLException("No shared device for requested: "+deviceReq); + } + + if( capsRequested.getDoubleBuffered() || capsRequested.isOnscreen() || capsRequested.isPBuffer()) { + // fix caps .. + GLCapabilities caps2 = (GLCapabilities) capsRequested.cloneMutable(); + caps2.setDoubleBuffered(false); // FIXME DBLBUFOFFSCRN + caps2.setOnscreen(false); + if(caps2.isPBuffer() && !canCreateGLPbuffer(device)) { + caps2.setPBuffer(false); + } + capsChosen = caps2; + } else { + capsChosen = capsRequested; + } + device.lock(); + try { + return createOffscreenSurfaceImpl(device, capsChosen, capsRequested, chooser, width, height); + } finally { + device.unlock(); } } @@ -209,7 +264,8 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { * creates an offscreen NativeSurface, which must implement SurfaceChangeable as well, * so the windowing system related implementation is able to set the surface handle. */ - protected abstract NativeSurface createOffscreenSurfaceImpl(GLCapabilitiesImmutable capabilities, GLCapabilitiesImmutable capsRequested, + protected abstract NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device, + GLCapabilitiesImmutable capabilities, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawable.java index 88685faf7..4120b0167 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawable.java @@ -166,7 +166,7 @@ public abstract class EGLDrawable extends GLDrawableImpl { if (!EGL.eglInitialize(eglDisplay, null, null)) { throw new GLException("eglInitialize failed"+", error 0x"+Integer.toHexString(EGL.eglGetError())); } - EGLGraphicsDevice e = new EGLGraphicsDevice(eglDisplay, AbstractGraphicsDevice.DEFAULT_UNIT); + EGLGraphicsDevice e = new EGLGraphicsDevice(eglDisplay, AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT); DefaultGraphicsScreen s = new DefaultGraphicsScreen(e, aConfig.getScreen().getIndex()); // yes, use the already choosen/requested Capabilities (x11,win32,..) GLCapabilitiesImmutable capsChosen = (GLCapabilitiesImmutable) aConfig.getChosenCapabilities(); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java index 737aa5519..f451cb9bc 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLDrawableFactory.java @@ -95,17 +95,20 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { public EGLDrawableFactory() { super(); - defaultDevice = new EGLGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT); + defaultDevice = new EGLGraphicsDevice(AbstractGraphicsDevice.DEFAULT_CONNECTION, AbstractGraphicsDevice.DEFAULT_UNIT); } static class SharedResource { - private EGLDrawable drawable; - private EGLContext context; - - SharedResource(EGLDrawable draw, EGLContext ctx) { - drawable = draw; - context = ctx; + private EGLGraphicsDevice device; + //private EGLDrawable drawable; + //private EGLContext context; + + SharedResource(EGLGraphicsDevice dev /*, EGLDrawable draw, EGLContext ctx */) { + device = dev; + // drawable = draw; + // context = ctx; } + EGLGraphicsDevice getDevice() { return device; } } HashMap/*<connection, SharedResource>*/ sharedMap = new HashMap(); EGLGraphicsDevice defaultDevice; @@ -121,8 +124,45 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { return false; } + private SharedResource getOrCreateShared(AbstractGraphicsDevice device) { + String connection = device.getConnection(); + SharedResource sr; + synchronized(sharedMap) { + sr = (SharedResource) sharedMap.get(connection); + } + if(null==sr) { + long eglDisplay = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY); + if (eglDisplay == EGL.EGL_NO_DISPLAY) { + throw new GLException("Failed to created EGL default display: error 0x"+Integer.toHexString(EGL.eglGetError())); + } else if(DEBUG) { + System.err.println("eglDisplay(EGL_DEFAULT_DISPLAY): 0x"+Long.toHexString(eglDisplay)); + } + if (!EGL.eglInitialize(eglDisplay, null, null)) { + throw new GLException("eglInitialize failed"+", error 0x"+Integer.toHexString(EGL.eglGetError())); + } + EGLGraphicsDevice sharedDevice = new EGLGraphicsDevice(eglDisplay, connection, device.getUnitID()); + sr = new SharedResource(sharedDevice); + synchronized(sharedMap) { + sharedMap.put(connection, sr); + } + if (DEBUG) { + System.err.println("!!! SharedDevice: "+sharedDevice); + } + } + return sr; + } + + protected final GLContext getOrCreateSharedContextImpl(AbstractGraphicsDevice device) { - // FIXME: not implemented .. needs a dummy EGL surface + // FIXME: not implemented .. needs a dummy EGL surface - NEEDED ? + return null; + } + + protected AbstractGraphicsDevice getOrCreateSharedDeviceImpl(AbstractGraphicsDevice device) { + SharedResource sr = getOrCreateShared(device); + if(null!=sr) { + return sr.getDevice(); + } return null; } @@ -152,19 +192,24 @@ public class EGLDrawableFactory extends GLDrawableFactoryImpl { } protected GLDrawableImpl createOffscreenDrawableImpl(NativeSurface target) { - throw new GLException("Not yet implemented"); + if (target == null) { + throw new IllegalArgumentException("Null target"); + } + AbstractGraphicsConfiguration config = target.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + if(!caps.isPBuffer()) { + throw new GLException("Not yet implemented"); + } + // PBuffer GLDrawable Creation + return new EGLPbufferDrawable(this, target); } public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { return true; } - protected GLDrawableImpl createGLPbufferDrawableImpl(NativeSurface target) { - return new EGLPbufferDrawable(this, target); - } - - protected NativeSurface createOffscreenSurfaceImpl(GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) { - ProxySurface ns = new ProxySurface(EGLGraphicsConfigurationFactory.createOffscreenGraphicsConfiguration(capsChosen, capsRequested, chooser)); + protected NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device, GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) { + ProxySurface ns = new ProxySurface(EGLGraphicsConfigurationFactory.createOffscreenGraphicsConfiguration(device, capsChosen, capsRequested, chooser)); ns.setSize(width, height); return ns; } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfigurationFactory.java index a9c8652b0..fc2416cb9 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLGraphicsConfigurationFactory.java @@ -291,7 +291,7 @@ public class EGLGraphicsConfigurationFactory extends GraphicsConfigurationFactor } } - static EGLGraphicsConfiguration createOffscreenGraphicsConfiguration(GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsReq, GLCapabilitiesChooser chooser) { + static EGLGraphicsConfiguration createOffscreenGraphicsConfiguration(AbstractGraphicsDevice device, GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsReq, GLCapabilitiesChooser chooser) { if(capsChosen.isOnscreen()) { throw new GLException("Error: Onscreen set: "+capsChosen); } @@ -303,21 +303,10 @@ public class EGLGraphicsConfigurationFactory extends GraphicsConfigurationFactor capsChosen = caps2; } - long eglDisplay = EGL.eglGetDisplay(EGL.EGL_DEFAULT_DISPLAY); - if (eglDisplay == EGL.EGL_NO_DISPLAY) { - throw new GLException("Failed to created EGL default display: error 0x"+Integer.toHexString(EGL.eglGetError())); - } else if(DEBUG) { - System.err.println("eglDisplay(EGL_DEFAULT_DISPLAY): 0x"+Long.toHexString(eglDisplay)); - } - if (!EGL.eglInitialize(eglDisplay, null, null)) { - throw new GLException("eglInitialize failed"+", error 0x"+Integer.toHexString(EGL.eglGetError())); - } - EGLGraphicsDevice e = new EGLGraphicsDevice(eglDisplay, AbstractGraphicsDevice.DEFAULT_UNIT); - DefaultGraphicsScreen s = new DefaultGraphicsScreen(e, 0); - EGLGraphicsConfiguration eglConfig = chooseGraphicsConfigurationStatic(capsChosen, capsReq, chooser, s); + DefaultGraphicsScreen screen = new DefaultGraphicsScreen(device, 0); + EGLGraphicsConfiguration eglConfig = chooseGraphicsConfigurationStatic(capsChosen, capsReq, chooser, screen); if (null == eglConfig) { - EGL.eglTerminate(eglDisplay); - throw new GLException("Couldn't create EGLGraphicsConfiguration from "+s); + throw new GLException("Couldn't create EGLGraphicsConfiguration from "+screen); } else if(DEBUG) { System.err.println("Chosen eglConfig: "+eglConfig); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java index 71b99c2d5..1895c8e67 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java @@ -117,6 +117,10 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { return null; } + protected AbstractGraphicsDevice getOrCreateSharedDeviceImpl(AbstractGraphicsDevice device) { + return device; // nothing to do, no native open device + } + protected final void shutdownInstance() {} protected GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) { @@ -127,15 +131,14 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { } protected GLDrawableImpl createOffscreenDrawableImpl(NativeSurface target) { - return new MacOSXOffscreenCGLDrawable(this, target); - } - - public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { - return true; - } + AbstractGraphicsConfiguration config = target.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + if(!caps.isPBuffer()) { + return new MacOSXOffscreenCGLDrawable(this, target); + } - protected GLDrawableImpl createGLPbufferDrawableImpl(final NativeSurface target) { - /** + // PBuffer GLDrawable Creation + /** * FIXME: Think about this .. * should not be necessary ? .. final List returnList = new ArrayList(); @@ -151,7 +154,11 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { return new MacOSXPbufferCGLDrawable(this, target); } - protected NativeSurface createOffscreenSurfaceImpl(GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) { + public boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { + return true; + } + + protected NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device,GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) { AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_MACOSX); ProxySurface ns = new ProxySurface(MacOSXCGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic(capsChosen, capsRequested, chooser, screen, true)); ns.setSize(width, height); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsOffscreenWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsBitmapWGLContext.java index 25d93b50e..7b769d971 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsOffscreenWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsBitmapWGLContext.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -40,10 +41,9 @@ package com.jogamp.opengl.impl.windows.wgl; import javax.media.opengl.*; -import com.jogamp.opengl.impl.*; -public class WindowsOffscreenWGLContext extends WindowsWGLContext { - public WindowsOffscreenWGLContext(WindowsOffscreenWGLDrawable drawable, +public class WindowsBitmapWGLContext extends WindowsWGLContext { + public WindowsBitmapWGLContext(WindowsBitmapWGLDrawable drawable, GLContext shareWith) { super(drawable, shareWith); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsBitmapWGLDrawable.java index 3452d3b55..0d360b339 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsOffscreenWGLDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsBitmapWGLDrawable.java @@ -51,11 +51,11 @@ import com.jogamp.nativewindow.impl.windows.BITMAPINFOHEADER; import com.jogamp.nativewindow.impl.windows.GDI; import javax.media.opengl.GLCapabilitiesImmutable; -public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable { +public class WindowsBitmapWGLDrawable extends WindowsWGLDrawable { private long origbitmap; private long hbitmap; - protected WindowsOffscreenWGLDrawable(GLDrawableFactory factory, NativeSurface target) { + protected WindowsBitmapWGLDrawable(GLDrawableFactory factory, NativeSurface target) { super(factory, target, true); create(); } @@ -69,7 +69,7 @@ public class WindowsOffscreenWGLDrawable extends WindowsWGLDrawable { } public GLContext createContext(GLContext shareWith) { - return new WindowsOffscreenWGLContext(this, shareWith); + return new WindowsBitmapWGLContext(this, shareWith); } private void create() { diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java index 53badb25e..e85308371 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java @@ -111,10 +111,15 @@ public class WindowsWGLContext extends GLContextImpl { WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory)drawable.getFactoryImpl(); AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); AbstractGraphicsDevice device = config.getScreen().getDevice(); - WindowsWGLDrawableFactory.SharedResource sr = factory.getOrCreateShared(device); - if(null != sr) { - wglMakeContextCurrentAvailable = factory.isReadDrawableAvailable(device); - wglMakeContextCurrentInitialized=true; + switch( factory.isReadDrawableAvailable(device) ) { + case 1: + wglMakeContextCurrentAvailable = true; + wglMakeContextCurrentInitialized=true; + break; + case 0: + wglMakeContextCurrentAvailable = false; + wglMakeContextCurrentInitialized=true; + break; } } return wglMakeContextCurrentAvailable; diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java index 99e78b184..903e1af81 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLDrawableFactory.java @@ -69,6 +69,7 @@ import com.jogamp.opengl.impl.DesktopGLDynamicLookupHelper; import com.jogamp.opengl.impl.GLDrawableFactoryImpl; import com.jogamp.opengl.impl.GLDrawableImpl; import com.jogamp.opengl.impl.GLDynamicLookupHelper; +import javax.media.nativewindow.AbstractGraphicsConfiguration; import javax.media.opengl.GLCapabilitiesImmutable; public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { @@ -110,17 +111,21 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { } static class SharedResource { + private WindowsGraphicsDevice device; private WindowsDummyWGLDrawable drawable; private WindowsWGLContext context; private boolean canCreateGLPbuffer; private boolean readDrawableAvailable; - SharedResource(WindowsDummyWGLDrawable draw, WindowsWGLContext ctx, boolean readBufferAvail, boolean canPbuffer) { + SharedResource(WindowsGraphicsDevice dev, WindowsDummyWGLDrawable draw, WindowsWGLContext ctx, + boolean readBufferAvail, boolean canPbuffer) { + device = dev; drawable = draw; context = ctx; canCreateGLPbuffer = canPbuffer; readDrawableAvailable = readBufferAvail; } + WindowsGraphicsDevice getDevice() { return device; } WindowsWGLContext getContext() { return context; } boolean canCreateGLPbuffer() { return canCreateGLPbuffer; } boolean isReadDrawableAvailable() { return readDrawableAvailable; } @@ -156,7 +161,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { final static String WGL_ARB_make_current_read = "WGL_ARB_make_current_read"; final static String wglMakeContextCurrent = "wglMakeContextCurrent"; - protected final SharedResource getOrCreateShared(AbstractGraphicsDevice device) { + private SharedResource getOrCreateShared(AbstractGraphicsDevice device) { String connection = device.getConnection(); SharedResource sr; synchronized(sharedMap) { @@ -166,16 +171,19 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { addDeviceTried(connection); NativeWindowFactory.getDefaultToolkitLock().lock(); // OK try { - WindowsDummyWGLDrawable sharedDrawable = WindowsDummyWGLDrawable.create(this, null); + WindowsGraphicsDevice sharedDevice = new WindowsGraphicsDevice(connection, AbstractGraphicsDevice.DEFAULT_UNIT); + GLProfile glp = GLProfile.getDefault(/*sharedDevice*/); // can't fetch device profile, which shared resource we create here + AbstractGraphicsScreen absScreen = new DefaultGraphicsScreen(sharedDevice, 0); + WindowsDummyWGLDrawable sharedDrawable = WindowsDummyWGLDrawable.create(this, glp, absScreen); WindowsWGLContext ctx = (WindowsWGLContext) sharedDrawable.createContext(null); ctx.makeCurrent(); boolean canCreateGLPbuffer = ctx.getGL().isExtensionAvailable(GL_ARB_pbuffer); boolean readDrawableAvailable = ctx.isExtensionAvailable(WGL_ARB_make_current_read) && ctx.isFunctionAvailable(wglMakeContextCurrent); ctx.release(); - sr = new SharedResource(sharedDrawable, ctx, readDrawableAvailable, canCreateGLPbuffer); + sr = new SharedResource(sharedDevice, sharedDrawable, ctx, readDrawableAvailable, canCreateGLPbuffer); synchronized(sharedMap) { - sharedMap.put(device.getConnection(), sr); + sharedMap.put(connection, sr); } if (DEBUG) { System.err.println("!!! SharedContext: "+ctx+", pbuffer supported "+canCreateGLPbuffer+ @@ -199,6 +207,14 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { return null; } + protected AbstractGraphicsDevice getOrCreateSharedDeviceImpl(AbstractGraphicsDevice device) { + SharedResource sr = getOrCreateShared(device); + if(null!=sr) { + return sr.getDevice(); + } + return null; + } + protected final void shutdownInstance() { if (DEBUG) { Exception e = new Exception("Debug"); @@ -238,38 +254,22 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { return new WindowsOnscreenWGLDrawable(this, target); } - protected final GLDrawableImpl createOffscreenDrawableImpl(NativeSurface target) { + protected final GLDrawableImpl createOffscreenDrawableImpl(final NativeSurface target) { if (target == null) { throw new IllegalArgumentException("Null target"); } - return new WindowsOffscreenWGLDrawable(this, target); - } - - public final boolean isReadDrawableAvailable(AbstractGraphicsDevice device) { - SharedResource sr = getOrCreateShared((null!=device)?device:defaultDevice); - if(null!=sr) { - return sr.isReadDrawableAvailable(); - } - return false; - } - - public final boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { - SharedResource sr = getOrCreateShared((null!=device)?device:defaultDevice); - if(null!=sr) { - return sr.canCreateGLPbuffer(); + AbstractGraphicsConfiguration config = target.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + if(!caps.isPBuffer()) { + return new WindowsBitmapWGLDrawable(this, target); } - return false; - } - protected final GLDrawableImpl createGLPbufferDrawableImpl(final NativeSurface target) { - if (target == null) { - throw new IllegalArgumentException("Null target"); - } - final AbstractGraphicsDevice device = target.getGraphicsConfiguration().getNativeGraphicsConfiguration().getScreen().getDevice(); + // PBuffer GLDrawable Creation + final AbstractGraphicsDevice device = config.getScreen().getDevice(); final SharedResource sr = getOrCreateShared(device); if(null==sr) { - return null; + throw new IllegalArgumentException("No shared resource for "+device); } final List returnList = new ArrayList(); Runnable r = new Runnable() { @@ -298,7 +298,27 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { return (GLDrawableImpl) returnList.get(0); } - protected final NativeSurface createOffscreenSurfaceImpl(GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) { + /** + * @return 1 if read drawable extension is available, 0 if not + * and -1 if undefined yet, ie no shared device exist at this point. + */ + public final int isReadDrawableAvailable(AbstractGraphicsDevice device) { + SharedResource sr = getOrCreateShared((null!=device)?device:defaultDevice); + if(null!=sr) { + return sr.isReadDrawableAvailable() ? 1 : 0 ; + } + return -1; // undefined + } + + public final boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { + SharedResource sr = getOrCreateShared((null!=device)?device:defaultDevice); + if(null!=sr) { + return sr.canCreateGLPbuffer(); + } + return false; + } + + protected final NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device,GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, int width, int height) { AbstractGraphicsScreen screen = DefaultGraphicsScreen.createDefault(NativeWindowFactory.TYPE_WINDOWS); ProxySurface ns = new ProxySurface(WindowsWGLGraphicsConfigurationFactory.chooseGraphicsConfigurationStatic( capsChosen, capsRequested, chooser, screen) ); diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java index c8b656e9f..3abbcee57 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXDrawableFactory.java @@ -207,7 +207,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { private final SharedResource createSharedResource(String connection) { X11GraphicsDevice sharedDevice = new X11GraphicsDevice(X11Util.createDisplay(connection), AbstractGraphicsDevice.DEFAULT_UNIT); sharedDevice.setCloseDisplay(true); - X11Util.lockDefaultToolkit(sharedDevice.getHandle()); // OK + sharedDevice.lock(); try { String glXVendorName = GLXUtil.getVendorName(sharedDevice.getHandle()); X11GraphicsScreen sharedScreen = new X11GraphicsScreen(sharedDevice, 0); @@ -245,7 +245,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } return new SharedResource(sharedDevice, sharedScreen, sharedDrawable, sharedContext, glXVersion, glXVendorName); } finally { - X11Util.unlockDefaultToolkit(sharedDevice.getHandle()); // OK + sharedDevice.unlock(); } } @@ -343,23 +343,18 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } } - protected final SharedResource getOrCreateShared(AbstractGraphicsDevice device) { + private SharedResource getOrCreateShared(AbstractGraphicsDevice device) { String connection = device.getConnection(); - boolean deviceTried = getDeviceTried(connection); SharedResource sr; synchronized(sharedMap) { sr = (SharedResource) sharedMap.get(connection); } - if (DEBUG) { - System.err.println("getOrCreateShared() "+connection+": has shared "+(null!=sr)+", already tried "+deviceTried); - } - - if(null==sr && !deviceTried) { + if(null==sr && !getDeviceTried(connection)) { + addDeviceTried(connection); if (DEBUG) { System.err.println("getOrCreateShared() "+connection+": trying"); } - addDeviceTried(connection); sharedResourcesRunner.initializeAndWait(connection); synchronized(sharedMap) { sr = (SharedResource) sharedMap.get(connection); @@ -380,6 +375,14 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return null; } + protected AbstractGraphicsDevice getOrCreateSharedDeviceImpl(AbstractGraphicsDevice device) { + SharedResource sr = getOrCreateShared(device); + if(null!=sr) { + return sr.getDevice(); + } + return null; + } + protected final long getOrCreateSharedDpy(AbstractGraphicsDevice device) { SharedResource sr = getOrCreateShared(device); if(null!=sr) { @@ -439,35 +442,17 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { if (target == null) { throw new IllegalArgumentException("Null target"); } - return new X11OffscreenGLXDrawable(this, target); - } - - public final boolean glXVersionGreaterEqualOneThree(AbstractGraphicsDevice device) { - VersionNumber glXVersion = getGLXVersion(device); - return ( null != glXVersion ) ? glXVersion.compareTo(versionOneThree) >= 0 : false ; - } - - public final boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { - if(null == device) { - SharedResource sr = getOrCreateShared(defaultDevice); - if(null!=sr) { - device = sr.getDevice(); - } - } - return glXVersionGreaterEqualOneThree(device); - } - - protected final GLDrawableImpl createGLPbufferDrawableImpl(final NativeSurface target) { - if (target == null) { - throw new IllegalArgumentException("Null target"); + AbstractGraphicsConfiguration config = target.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + if(!caps.isPBuffer()) { + return new X11PixmapGLXDrawable(this, target); } + // PBuffer GLDrawable Creation GLDrawableImpl pbufferDrawable; - - AbstractGraphicsConfiguration config = target.getGraphicsConfiguration().getNativeGraphicsConfiguration(); AbstractGraphicsDevice device = config.getScreen().getDevice(); - /** + /** * Due to the ATI Bug https://bugzilla.mozilla.org/show_bug.cgi?id=486277, * we need to have a context current on the same Display to create a PBuffer. * The dummy context shall also use the same Display, @@ -489,11 +474,27 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { return pbufferDrawable; } + public final boolean glXVersionGreaterEqualOneThree(AbstractGraphicsDevice device) { + VersionNumber glXVersion = getGLXVersion(device); + return ( null != glXVersion ) ? glXVersion.compareTo(versionOneThree) >= 0 : false ; + } - protected final NativeSurface createOffscreenSurfaceImpl(GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, GLCapabilitiesChooser chooser, + public final boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { + if(null == device) { + SharedResource sr = getOrCreateShared(defaultDevice); + if(null!=sr) { + device = sr.getDevice(); + } + } + return glXVersionGreaterEqualOneThree(device); + } + + protected final NativeSurface createOffscreenSurfaceImpl(AbstractGraphicsDevice device, + GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsRequested, + GLCapabilitiesChooser chooser, int width, int height) { X11GraphicsScreen screen = null; - SharedResource sr = getOrCreateShared(defaultDevice); + SharedResource sr = getOrCreateShared(device); if(null!=sr) { screen = sr.getScreen(); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java index fcd2e4266..327ecd0be 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXGraphicsConfigurationFactory.java @@ -88,56 +88,6 @@ public class X11GLXGraphicsConfigurationFactory extends GraphicsConfigurationFac (GLCapabilitiesChooser)chooser, (X11GraphicsScreen)absScreen); } - /** - static X11GLXGraphicsConfiguration createDefaultGraphicsConfigurationFBConfig(AbstractGraphicsScreen absScreen, boolean onscreen, boolean usePBuffer) { - if (absScreen == null) { - throw new IllegalArgumentException("AbstractGraphicsScreen is null"); - } - if (!(absScreen instanceof X11GraphicsScreen)) { - throw new IllegalArgumentException("Only X11GraphicsScreen are allowed here"); - } - X11GraphicsScreen x11Screen = (X11GraphicsScreen)absScreen; - - GLProfile glProfile = GLProfile.getDefault(); - GLCapabilities availableCaps=null; - XVisualInfo xvis=null; - long fbcfg = 0; - int fbid = -1; - - // Utilizing FBConfig - // - GLCapabilities capsFB = null; - long display = x11Screen.getDevice().getHandle(); - - try { - int screen = x11Screen.getIndex(); - boolean isMultisampleAvailable = GLXUtil.isMultisampleAvailable(display); - - long visID = X11Util.DefaultVisualID(display, x11Screen.getIndex()); - xvis = X11GLXGraphicsConfiguration.XVisualID2XVisualInfo(display, visID); - availableCaps = X11GLXGraphicsConfiguration.XVisualInfo2GLCapabilities(glProfile, display, xvis, onscreen, usePBuffer, isMultisampleAvailable); - - int[] attribs = X11GLXGraphicsConfiguration.GLCapabilities2AttribList(availableCaps, true, isMultisampleAvailable, display, screen); - int[] count = { -1 }; - PointerBuffer fbcfgsL = GLX.glXChooseFBConfig(display, screen, attribs, 0, count, 0); - if (fbcfgsL == null || fbcfgsL.limit()<1) { - throw new Exception("Could not fetch FBConfig for "+availableCaps); - } - fbcfg = fbcfgsL.get(0); - capsFB = X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(glProfile, display, fbcfg, true, onscreen, usePBuffer, isMultisampleAvailable); - - fbid = X11GLXGraphicsConfiguration.glXFBConfig2FBConfigID(display, fbcfg); - - xvis = GLX.glXGetVisualFromFBConfig(display, fbcfg); - if (xvis==null) { - throw new GLException("Error: Choosen FBConfig has no visual"); - } - } catch (Throwable t) { - } - - return new X11GLXGraphicsConfiguration(x11Screen, (null!=capsFB)?capsFB:availableCaps, availableCaps, null, xvis, fbcfg, fbid); - } */ - static X11GLXGraphicsConfiguration chooseGraphicsConfigurationStatic(GLCapabilitiesImmutable capsChosen, GLCapabilitiesImmutable capsReq, GLCapabilitiesChooser chooser, diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PixmapGLXContext.java index 5ae641278..b7b4da75d 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXContext.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PixmapGLXContext.java @@ -42,9 +42,9 @@ package com.jogamp.opengl.impl.x11.glx; import javax.media.opengl.*; -public class X11OffscreenGLXContext extends X11GLXContext { +public class X11PixmapGLXContext extends X11GLXContext { - public X11OffscreenGLXContext(X11OffscreenGLXDrawable drawable, + public X11PixmapGLXContext(X11PixmapGLXDrawable drawable, GLContext shareWith) { super(drawable, shareWith); } diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PixmapGLXDrawable.java index f46bdbb75..0343ffb02 100644 --- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OffscreenGLXDrawable.java +++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11PixmapGLXDrawable.java @@ -44,10 +44,10 @@ import javax.media.nativewindow.*; import javax.media.opengl.*; import com.jogamp.nativewindow.impl.x11.*; -public class X11OffscreenGLXDrawable extends X11GLXDrawable { +public class X11PixmapGLXDrawable extends X11GLXDrawable { private long pixmap; - protected X11OffscreenGLXDrawable(GLDrawableFactory factory, NativeSurface target) { + protected X11PixmapGLXDrawable(GLDrawableFactory factory, NativeSurface target) { super(factory, target, true); create(); } @@ -61,7 +61,7 @@ public class X11OffscreenGLXDrawable extends X11GLXDrawable { } public GLContext createContext(GLContext shareWith) { - return new X11OffscreenGLXContext(this, shareWith); + return new X11PixmapGLXContext(this, shareWith); } private void create() { |