From 203f795cd3332d6d61c210c8b7901de069d9166a Mon Sep 17 00:00:00 2001
From: Sven Gothel
+ * Implementations are allowed to specialize {@link FBObject.Attachment.StorageDefinition}
+ * for the special use-case of:
+ *
+ *
+ *
+ * If a valid unit is returned, i.e. >= 0, a color texturebuffer is used, otherwise a color renderbuffer. + *
+ */ + public int getTextureUnit(); + } + + protected OnscreenFBOColorbufferStorageDefinition getOnscreenFBOColorbufStorageDef() { return null; } + //--------------------------------------------------------------------------- // Dispatching GLDrawable construction in respect to the NativeSurface Capabilities // @@ -273,29 +300,41 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { throw new IllegalArgumentException("Null target"); } final MutableGraphicsConfiguration config = (MutableGraphicsConfiguration) target.getGraphicsConfiguration(); + final GLCapabilitiesImmutable reqCaps = (GLCapabilitiesImmutable) config.getRequestedCapabilities(); final GLCapabilitiesImmutable chosenCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); final AbstractGraphicsDevice adevice = config.getScreen().getDevice(); final boolean isFBOAvailable = GLContext.isFBOAvailable(adevice, chosenCaps.getGLProfile()); GLDrawable result = null; adevice.lock(); try { + final OnscreenFBOColorbufferStorageDefinition onscreenFBOColorbufStorageDef = getOnscreenFBOColorbufStorageDef(); final boolean forceOnscreenFBOLayer; - final boolean useFBORendertarget; - if( chosenCaps.isOnscreen() && Platform.OSType.IOS == PlatformPropsImpl.OS_TYPE ) // FIXME: avoid hardcoding? - { + final int fboTextureUnit; + if( reqCaps.isOnscreen() && null != onscreenFBOColorbufStorageDef) { forceOnscreenFBOLayer = true; - useFBORendertarget = true; + fboTextureUnit = onscreenFBOColorbufStorageDef.getTextureUnit(); } else { forceOnscreenFBOLayer = false; - useFBORendertarget = false; + fboTextureUnit = 0; // assume texture unit 0 (default) is used at all } final OffscreenLayerSurface ols = NativeWindowFactory.getOffscreenLayerSurface(target, true); if(null != ols || forceOnscreenFBOLayer ) { - final GLCapabilitiesImmutable chosenCapsMod = GLGraphicsConfigurationUtil.fixOffscreenGLCapabilities(chosenCaps, this, adevice); - - // layered surface -> Offscreen/[FBO|PBuffer] - if( !chosenCapsMod.isFBO() && !chosenCapsMod.isPBuffer() ) { - throw new GLException("Neither FBO nor Pbuffer is available for "+chosenCapsMod+", "+target); + final GLCapabilitiesImmutable chosenCapsMod0 = GLGraphicsConfigurationUtil.fixOffscreenGLCapabilities(chosenCaps, this, adevice); + final GLCapabilitiesImmutable chosenCapsMod; + if( forceOnscreenFBOLayer && !onscreenFBOColorbufStorageDef.isDoubleBufferSupported() ) { + chosenCapsMod = GLGraphicsConfigurationUtil.fixDoubleBufferedGLCapabilities(chosenCapsMod0, false); + } else { + chosenCapsMod = chosenCapsMod0; + } + if( forceOnscreenFBOLayer ) { + if( !chosenCapsMod.isFBO() ) { + throw new GLException("FBO is not available for "+chosenCapsMod+", "+target); + } + } else { + // layered surface -> Offscreen/[FBO|PBuffer] + if( !chosenCapsMod.isFBO() && !chosenCapsMod.isPBuffer() ) { + throw new GLException("Neither FBO nor Pbuffer is available for "+chosenCapsMod+", "+target); + } } config.setChosenCapabilities(chosenCapsMod); if( null != ols ) { @@ -303,10 +342,11 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { } if(DEBUG) { System.err.println("GLDrawableFactoryImpl.createGLDrawable -> OnscreenDrawable -> Offscreen-Layer"); + System.err.println("requestedCaps: "+reqCaps); System.err.println("chosenCaps: "+chosenCaps); System.err.println("chosenCapsMod: "+chosenCapsMod); System.err.println("OffscreenLayerSurface: **** "+ols); - System.err.println("forceOnscreenFBOLayer: **** "+forceOnscreenFBOLayer+", useFBORendertarget "+useFBORendertarget); + System.err.println("forceOnscreenFBOLayer: **** "+forceOnscreenFBOLayer+", fboTextureUnit "+fboTextureUnit); System.err.println("Target: **** "+target); ExceptionUtils.dumpStack(System.err); } @@ -314,7 +354,11 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { throw new IllegalArgumentException("Passed NativeSurface must implement SurfaceChangeable for offscreen layered surface: "+target); } if( chosenCapsMod.isFBO() ) { - result = createFBODrawableImpl(target, chosenCapsMod, useFBORendertarget?-1:0); + final GLFBODrawableImpl fboDrawable = (GLFBODrawableImpl) createFBODrawableImpl(target, chosenCapsMod, fboTextureUnit); + if( forceOnscreenFBOLayer ) { + fboDrawable.setColorRenderbufferStorageDef(onscreenFBOColorbufStorageDef); + } + result = fboDrawable; } else { result = createOffscreenDrawableImpl(target); } @@ -523,7 +567,13 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory { } } - /** Creates a platform independent unrealized FBO offscreen GLDrawable */ + /** + * Creates a platform independent unrealized FBO offscreen GLDrawable + * @param dummySurface used for dummy-drawable and as surface for {@link GLFBODrawable} + * @param fboCaps + * @param textureUnit if valid, i.e. >= 0, signals using a color texturebuffer {@link GLFBODrawable#FBOMODE_USE_TEXTURE}, otherwise a color renderbuffer is used. + * @return + */ protected final GLFBODrawable createFBODrawableImpl(final NativeSurface dummySurface, final GLCapabilitiesImmutable fboCaps, final int textureUnit) { final GLDrawableImpl dummyDrawable = createOnscreenDrawableImpl(dummySurface); return new GLFBODrawableImpl(this, dummyDrawable, dummySurface, fboCaps, textureUnit); -- cgit v1.2.3