diff options
author | Sven Gothel <[email protected]> | 2013-04-26 05:38:24 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-04-26 05:38:24 +0200 |
commit | 36dc4f5ab6957a4078842c488afb51df2fdc0630 (patch) | |
tree | 5e5629f085f7d244faf1c1e5e15cfe935e87e1b4 /src/jogl/classes/jogamp/opengl/windows/wgl | |
parent | 75b3d37a3b15c071b49609921244bcb62d329fa9 (diff) |
Simplify GLDrawableFactory's SharedResource Query Methods; Move WindowsWGLDrawableFactory Quirks to GLRendererQuirks (NeedCurrCtx4ARBPixFmtQueries, NeedCurrCtx4ARBCreateContext); Bug 706: Confine NeedCurrCtx4ARBCreateContext to [Windows, ATI, driver < 12.102.3); Avoid possible NPE @ GLContext.getGLVendorVersionNumber()
- Simplify GLDrawableFactory's SharedResource Query Methods
- Moving common methods to GLDrawableFactory/GLDrawableFactoryImpl
while reusing common methods to SharedResourceRunner.Resource.
- All factories SharedResources impl. SharedResourceRunner.Resource.
- Move WindowsWGLDrawableFactory Quirks to GLRendererQuirks (NeedCurrCtx4ARBPixFmtQueries, NeedCurrCtx4ARBCreateContext)
- For better maintenance, move the mentioned quirks from the windows factory to our common place,
being detected within GLContextImpl after each context creation.
- Bug 706: Confine NeedCurrCtx4ARBCreateContext to [Windows, ATI, driver < 12.102.3)
- Before we added this quirk if [Windows, ATI],
however, we have hopes that the new drivers will suffice for all
as tested successful on my test machine (AMD Radeon HD 6300M Series, amd_catalyst_13.5_mobility_beta2).
- Avoid possible NPE @ GLContext.getGLVendorVersionNumber()
- GLContext.getGLVendorVersionNumber() never returns 'null' but a zero version instance instead!
- Add API doc.
- Use mixed case names in GLContextImpl.setRendererQuirks(..).
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/windows/wgl')
5 files changed, 38 insertions, 123 deletions
diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java index 2a0f2596e..217ca18e8 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsPbufferWGLDrawable.java @@ -113,7 +113,7 @@ public class WindowsPbufferWGLDrawable extends WindowsWGLDrawable { private void createPbuffer() { WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration) getNativeSurface().getGraphicsConfiguration(); - SharedResource sharedResource = ((WindowsWGLDrawableFactory)factory).getOrCreateSharedResource(config.getScreen().getDevice()); + SharedResource sharedResource = ((WindowsWGLDrawableFactory)factory).getOrCreateSharedResourceImpl(config.getScreen().getDevice()); NativeSurface sharedSurface = sharedResource.getDrawable().getNativeSurface(); if (NativeSurface.LOCK_SURFACE_NOT_READY >= sharedSurface.lockSurface()) { throw new NativeWindowException("Could not lock (sharedSurface): "+this); diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java index 92b12a7ff..94153d96d 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java @@ -56,6 +56,7 @@ import com.jogamp.common.nio.Buffers; import com.jogamp.gluegen.runtime.ProcAddressTable; import com.jogamp.gluegen.runtime.opengl.GLProcAddressResolver; import com.jogamp.opengl.GLExtensions; +import com.jogamp.opengl.GLRendererQuirks; import jogamp.nativewindow.windows.GDI; import jogamp.opengl.GLContextImpl; @@ -271,8 +272,7 @@ public class WindowsWGLContext extends GLContextImpl { final AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration(); final AbstractGraphicsDevice device = config.getScreen().getDevice(); final WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory)drawable.getFactoryImpl(); - final WindowsWGLDrawableFactory.SharedResource sharedResource = factory.getOrCreateSharedResource(device); - final WindowsWGLContext sharedContext = (WindowsWGLContext) ( null != sharedResource ? sharedResource.getContext() : null ); + final WindowsWGLContext sharedContext = (WindowsWGLContext) factory.getOrCreateSharedContext(device); final GLCapabilitiesImmutable glCaps = drawable.getChosenGLCapabilities(); isGLReadDrawableAvailable(); // trigger setup wglGLReadDrawableAvailable @@ -296,7 +296,7 @@ public class WindowsWGLContext extends GLContextImpl { // utilize the shared context's GLXExt in case it was using the ARB method and it already exists ; exclude BITMAP if( null != sharedContext && sharedContext.isCreatedWithARBMethod() && !glCaps.isBitmap() ) { - if ( sharedResource.needsCurrenContext4ARBCreateContextAttribs() ) { + if ( sharedContext.getRendererQuirks().exist( GLRendererQuirks.NeedCurrCtx4ARBCreateContext ) ) { if(GLContext.CONTEXT_NOT_CURRENT == sharedContext.makeCurrent()) { throw new GLException("Could not make Shared Context current: "+sharedContext); } diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java index 483e31611..5fb01d1a3 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java @@ -41,6 +41,7 @@ package jogamp.opengl.windows.wgl; import java.nio.Buffer; + import java.nio.ShortBuffer; import java.util.Collection; import java.util.HashMap; @@ -53,7 +54,6 @@ import javax.media.nativewindow.DefaultGraphicsScreen; import javax.media.nativewindow.NativeSurface; import javax.media.nativewindow.ProxySurface; import javax.media.nativewindow.UpstreamSurfaceHook; -import javax.media.opengl.GL; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLCapabilitiesChooser; import javax.media.opengl.GLCapabilitiesImmutable; @@ -76,11 +76,10 @@ import jogamp.opengl.GLGraphicsConfigurationUtil; import jogamp.opengl.SharedResourceRunner; import com.jogamp.common.nio.PointerBuffer; -import com.jogamp.common.os.Platform; import com.jogamp.common.util.ReflectionUtil; -import com.jogamp.common.util.VersionNumber; import com.jogamp.nativewindow.windows.WindowsGraphicsDevice; import com.jogamp.opengl.GLExtensions; +import com.jogamp.opengl.GLRendererQuirks; public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { private static DesktopGLDynamicLookupHelper windowsWGLDynamicLookupHelper = null; @@ -201,29 +200,18 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { } } - /** - * http://msdn.microsoft.com/en-us/library/ms724832%28v=vs.85%29.aspx - * Windows XP 5.1 - */ - static final VersionNumber winXPVersionNumber = new VersionNumber ( 5, 1, 0); - static class SharedResource implements SharedResourceRunner.Resource { private final boolean hasARBPixelFormat; private final boolean hasARBMultisample; private final boolean hasARBPBuffer; private final boolean hasARBReadDrawable; - private final String vendor; - private final boolean isVendorATI; - private final boolean isVendorNVIDIA; - private final boolean needsCurrenContext4ARBPFDQueries; - private final boolean needsCurrenContext4ARBCreateContextAttribs; private WindowsGraphicsDevice device; private AbstractGraphicsScreen screen; private GLDrawableImpl drawable; private GLContextImpl context; - + SharedResource(WindowsGraphicsDevice dev, AbstractGraphicsScreen scrn, GLDrawableImpl draw, GLContextImpl ctx, - boolean arbPixelFormat, boolean arbMultisample, boolean arbPBuffer, boolean arbReadDrawable, String glVendor) { + boolean arbPixelFormat, boolean arbMultisample, boolean arbPBuffer, boolean arbReadDrawable) { device = dev; screen = scrn; drawable = draw; @@ -232,34 +220,13 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { hasARBMultisample = arbMultisample; hasARBPBuffer = arbPBuffer; hasARBReadDrawable = arbReadDrawable; - vendor = glVendor; - if(null != vendor) { - isVendorNVIDIA = vendor.startsWith("NVIDIA") ; - isVendorATI = vendor.startsWith("ATI") ; - } else { - isVendorNVIDIA = false; - isVendorATI = false; - } - - if ( isVendorATI ) { - needsCurrenContext4ARBCreateContextAttribs = true; - final VersionNumber winVersion = Platform.getOSVersionNumber(); - final boolean isWinXPOrLess = winVersion.compareTo(winXPVersionNumber) <= 0; - needsCurrenContext4ARBPFDQueries = isWinXPOrLess; - if(DEBUG) { - System.err.println("ATI && isWinXPOrLess = "+winVersion+" <= "+winXPVersionNumber+" = "+isWinXPOrLess+" - "+Platform.getOSVersion()); - } - } else { - needsCurrenContext4ARBPFDQueries = false; - needsCurrenContext4ARBCreateContextAttribs = false; - } - if(DEBUG) { - System.err.println("needsCurrenContext4ARBCreateContextAttribs: "+needsCurrenContext4ARBCreateContextAttribs); - System.err.println("needsCurrenContext4ARBPFDQueries: "+needsCurrenContext4ARBPFDQueries); - } } @Override + public final boolean isValid() { + return null != context; + } + @Override final public AbstractGraphicsDevice getDevice() { return device; } @Override final public AbstractGraphicsScreen getScreen() { return screen; } @@ -267,35 +234,15 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { final public GLDrawableImpl getDrawable() { return drawable; } @Override final public GLContextImpl getContext() { return context; } + @Override + public GLRendererQuirks getRendererQuirks() { + return null != context ? context.getRendererQuirks() : null; + } final boolean hasARBPixelFormat() { return hasARBPixelFormat; } final boolean hasARBMultisample() { return hasARBMultisample; } final boolean hasARBPBuffer() { return hasARBPBuffer; } final boolean hasReadDrawable() { return hasARBReadDrawable; } - - final String vendor() { return vendor; } - final boolean isVendorATI() { return isVendorATI; } - final boolean isVendorNVIDIA() { return isVendorNVIDIA; } - - /** - * Solves bug #480 - * - * TODO: Validate if bug actually relates to the 'old' ATI Windows driver for old GPU's like X300 etc - * and not to the Windows version ! - * - * @return true if GL_VENDOR is ATI _and_ platform is Windows version XP or less! - */ - final boolean needsCurrentContext4ARBPFDQueries() { return needsCurrenContext4ARBPFDQueries; } - - /** - * Solves bug #706 and bug #520 - * - * TODO: Validate if quirk can be reduced to a certain range of GPUs and/or driver versions, - * where we would also need a method to query the latter (-> jogl/src/nativewindow/native/win32/DeviceDriverQuery.txt). - * - * @return true if GL_VENDOR is ATI - */ - final boolean needsCurrenContext4ARBCreateContextAttribs() { return needsCurrenContext4ARBCreateContextAttribs; } } class SharedResourceImplementation implements SharedResourceRunner.Implementation { @@ -351,7 +298,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { boolean hasARBMultisample; boolean hasARBPBuffer; boolean hasARBReadDrawableAvailable; - String vendor; sharedContext.makeCurrent(); try { hasARBPixelFormat = sharedContext.isExtensionAvailable(WGL_ARB_pixel_format); @@ -359,7 +305,6 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { hasARBPBuffer = sharedContext.isExtensionAvailable(GLExtensions.ARB_pbuffer); hasARBReadDrawableAvailable = sharedContext.isExtensionAvailable(WGL_ARB_make_current_read) && sharedContext.isFunctionAvailable(wglMakeContextCurrent); - vendor = sharedContext.getGL().glGetString(GL.GL_VENDOR); } finally { sharedContext.release(); } @@ -371,11 +316,10 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { System.err.println("multisample: " + hasARBMultisample); System.err.println("pbuffer: " + hasARBPBuffer); System.err.println("readDrawable: " + hasARBReadDrawableAvailable); - System.err.println("vendor: " + vendor); } return new SharedResource(sharedDevice, absScreen, sharedDrawable, sharedContext, hasARBPixelFormat, hasARBMultisample, - hasARBPBuffer, hasARBReadDrawableAvailable, vendor); + hasARBPBuffer, hasARBReadDrawableAvailable); } catch (Throwable t) { throw new GLException("WindowsWGLDrawableFactory - Could not initialize shared resources for "+connection, t); } finally { @@ -441,51 +385,18 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { } @Override - protected final boolean createSharedResource(AbstractGraphicsDevice device) { - try { - SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); - if(null!=sr) { - return null != sr.getContext(); - } - } catch (GLException gle) { - if(DEBUG) { - System.err.println("Catched Exception on thread "+getThreadName()); - gle.printStackTrace(); - } - } - return false; - } - - @Override - protected final GLContext getOrCreateSharedContextImpl(AbstractGraphicsDevice device) { - SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); - if(null!=sr) { - return sr.getContext(); - } - return null; - } - - @Override - protected AbstractGraphicsDevice getOrCreateSharedDeviceImpl(AbstractGraphicsDevice device) { - SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); - if(null!=sr) { - return sr.getDevice(); - } - return null; + protected final SharedResource getOrCreateSharedResourceImpl(AbstractGraphicsDevice device) { + return (SharedResource) sharedResourceRunner.getOrCreateShared(device); } - protected WindowsWGLDrawable getOrCreateSharedDrawable(AbstractGraphicsDevice device) { - SharedResourceRunner.Resource sr = sharedResourceRunner.getOrCreateShared(device); + protected final WindowsWGLDrawable getOrCreateSharedDrawable(AbstractGraphicsDevice device) { + SharedResourceRunner.Resource sr = getOrCreateSharedResourceImpl(device); if(null!=sr) { return (WindowsWGLDrawable) sr.getDrawable(); } return null; } - SharedResource getOrCreateSharedResource(AbstractGraphicsDevice device) { - return (SharedResource) sharedResourceRunner.getOrCreateShared(device); - } - @Override protected List<GLCapabilitiesImmutable> getAvailableCapabilitiesImpl(AbstractGraphicsDevice device) { return WindowsWGLGraphicsConfigurationFactory.getAvailableCapabilities(this, device); @@ -518,7 +429,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { * Similar to 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. */ - final SharedResource sr = (SharedResource) sharedResourceRunner.getOrCreateShared(device); + final SharedResource sr = getOrCreateSharedResourceImpl(device); if(null!=sr) { GLContext lastContext = GLContext.getCurrent(); if (lastContext != null) { @@ -544,7 +455,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { * and -1 if undefined yet, ie no shared device exist at this point. */ public final int isReadDrawableAvailable(AbstractGraphicsDevice device) { - SharedResource sr = (SharedResource) sharedResourceRunner.getOrCreateShared((null!=device)?device:defaultDevice); + SharedResource sr = getOrCreateSharedResourceImpl( ( null != device ) ? device : defaultDevice ); if(null!=sr) { return sr.hasReadDrawable() ? 1 : 0 ; } @@ -553,7 +464,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { @Override public final boolean canCreateGLPbuffer(AbstractGraphicsDevice device) { - SharedResource sr = (SharedResource) sharedResourceRunner.getOrCreateShared((null!=device)?device:defaultDevice); + SharedResource sr = getOrCreateSharedResourceImpl( ( null != device ) ? device : defaultDevice ); if(null!=sr) { return sr.hasARBPBuffer(); } diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java index 017f8c40b..42b92305a 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java @@ -56,7 +56,6 @@ import jogamp.nativewindow.windows.GDI; import jogamp.nativewindow.windows.GDIUtil; import jogamp.nativewindow.windows.MARGINS; import jogamp.nativewindow.windows.PIXELFORMATDESCRIPTOR; -import jogamp.opengl.GLContextImpl; import jogamp.opengl.GLGraphicsConfigurationUtil; public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguration implements Cloneable { @@ -100,7 +99,7 @@ public class WindowsWGLGraphicsConfiguration extends MutableGraphicsConfiguratio } WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory) _factory; AbstractGraphicsDevice device = screen.getDevice(); - WindowsWGLDrawableFactory.SharedResource sharedResource = factory.getOrCreateSharedResource(device); + WindowsWGLDrawableFactory.SharedResource sharedResource = factory.getOrCreateSharedResourceImpl(device); boolean hasARB = null != sharedResource && sharedResource.hasARBPixelFormat(); WGLGLCapabilities caps = null; diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java index 1e72e312b..3d093b972 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java @@ -51,6 +51,7 @@ import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; import com.jogamp.common.nio.Buffers; +import com.jogamp.opengl.GLRendererQuirks; import jogamp.nativewindow.windows.GDI; import jogamp.nativewindow.windows.PIXELFORMATDESCRIPTOR; @@ -114,21 +115,23 @@ public class WindowsWGLGraphicsConfigurationFactory extends GLGraphicsConfigurat } protected static List<GLCapabilitiesImmutable> getAvailableCapabilities(WindowsWGLDrawableFactory factory, AbstractGraphicsDevice device) { - final WindowsWGLDrawableFactory.SharedResource sharedResource = factory.getOrCreateSharedResource(device); + final WindowsWGLDrawableFactory.SharedResource sharedResource = factory.getOrCreateSharedResourceImpl(device); if(null == sharedResource) { throw new GLException("Shared resource for device n/a: "+device); } final GLDrawableImpl sharedDrawable = sharedResource.getDrawable(); - final GLContext sharedContext = sharedResource.getContext(); final GLProfile glp = GLProfile.getDefault(device); List<GLCapabilitiesImmutable> availableCaps = null; - if ( sharedResource.needsCurrentContext4ARBPFDQueries() ) { + final GLContext sharedContext; + if ( factory.hasRendererQuirk(device, GLRendererQuirks.NeedCurrCtx4ARBPixFmtQueries) ) { + sharedContext = sharedResource.getContext(); if(GLContext.CONTEXT_NOT_CURRENT == sharedContext.makeCurrent()) { throw new GLException("Could not make Shared Context current: "+device); } } else { + sharedContext = null; sharedDrawable.lockSurface(); } try { @@ -147,7 +150,7 @@ public class WindowsWGLGraphicsConfigurationFactory extends GLGraphicsConfigurat availableCaps.addAll(availableCapsGDI); } } finally { - if ( sharedResource.needsCurrentContext4ARBPFDQueries() ) { + if ( null != sharedContext ) { sharedContext.release(); } else { sharedDrawable.unlockSurface(); @@ -281,13 +284,15 @@ public class WindowsWGLGraphicsConfigurationFactory extends GLGraphicsConfigurat System.err.println("user chosen caps " + config.getChosenCapabilities()); } AbstractGraphicsDevice device = config.getScreen().getDevice(); - WindowsWGLDrawableFactory.SharedResource sharedResource = ((WindowsWGLDrawableFactory)factory).getOrCreateSharedResource(device); - GLContext sharedContext = null; - if (null != sharedResource && sharedResource.needsCurrentContext4ARBPFDQueries()) { + WindowsWGLDrawableFactory.SharedResource sharedResource = ((WindowsWGLDrawableFactory)factory).getOrCreateSharedResourceImpl(device); + final GLContext sharedContext; + if ( factory.hasRendererQuirk(device, GLRendererQuirks.NeedCurrCtx4ARBPixFmtQueries) ) { sharedContext = sharedResource.getContext(); if(GLContext.CONTEXT_NOT_CURRENT == sharedContext.makeCurrent()) { throw new GLException("Could not make Shared Context current: "+device); } + } else { + sharedContext = null; } try { final GLCapabilitiesImmutable capsChosen = (GLCapabilitiesImmutable) config.getChosenCapabilities(); @@ -308,7 +313,7 @@ public class WindowsWGLGraphicsConfigurationFactory extends GLGraphicsConfigurat private static boolean updateGraphicsConfigurationARB(WindowsWGLDrawableFactory factory, WindowsWGLGraphicsConfiguration config, CapabilitiesChooser chooser, long hdc, boolean extHDC, int[] pformats) { final AbstractGraphicsDevice device = config.getScreen().getDevice(); - final WindowsWGLDrawableFactory.SharedResource sharedResource = factory.getOrCreateSharedResource(device); + final WindowsWGLDrawableFactory.SharedResource sharedResource = factory.getOrCreateSharedResourceImpl(device); if (null == sharedResource) { if (DEBUG) { |