aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl/ios/eagl
diff options
context:
space:
mode:
authorSven Gothel <sgothel@jausoft.com>2019-06-24 14:57:55 +0200
committerSven Gothel <sgothel@jausoft.com>2019-06-24 14:57:55 +0200
commit203f795cd3332d6d61c210c8b7901de069d9166a (patch)
treee35b5ff354eadbf917162fa83469e420a55b8b9f /src/jogl/classes/jogamp/opengl/ios/eagl
parentbba73bc096250a3c7fc036d84b1ea054d1b70b06 (diff)
iOS: Clean up promotion of EAGLLayer use down to FBObject
Initial commit bba73bc096250a3c7fc036d84b1ea054d1b70b06 hacked its path using a context global EGLLayer instance attachement. The hack was good for the first demo, however, it forbid using other FBObjects etc on the way. Properly specifying FBObject.Attachment.StorageDefinition, allowing the user to inject code for selected FBO attachements to define their storage. This might be useful for different platforms as well - however, it is OS agnostic and instance specific now. In this sense, GLFBODrawableImpl, hosting FBObject, has a more specific instance of FBObject.Attachment.StorageDefinition for color-renderbuffer. It is passed along newly created color renderbuffer. GLDrawableFactoryImpl.createGLDrawable uses a derived interface, OnscreenFBOColorbufferStorageDefinition which is defined in IOSEAGLDrawableFactory and return by its getter. GLDrawableFactoryImpl.createGLDrawable is therefor platform agnostic again. Bottom line is, as more platforms will be added, these semi-public interfaces have to adapt to suit them all .. All this due to iOS architecture for 'onscreen rendering' using a FBO which shares its color renderbuffer storage with the EAGLLayer, associated with the UIView. A bit weird maybe in first sight, but efficient for creating cheap hardware design ;-) Only criticism here is that Apple didn't bother using EGL and an extension.
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/ios/eagl')
-rw-r--r--src/jogl/classes/jogamp/opengl/ios/eagl/IOSEAGLContext.java98
-rw-r--r--src/jogl/classes/jogamp/opengl/ios/eagl/IOSEAGLDrawableFactory.java37
2 files changed, 64 insertions, 71 deletions
diff --git a/src/jogl/classes/jogamp/opengl/ios/eagl/IOSEAGLContext.java b/src/jogl/classes/jogamp/opengl/ios/eagl/IOSEAGLContext.java
index 57c20d465..e3b7a64a7 100644
--- a/src/jogl/classes/jogamp/opengl/ios/eagl/IOSEAGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/ios/eagl/IOSEAGLContext.java
@@ -34,19 +34,18 @@ import com.jogamp.nativewindow.AbstractGraphicsConfiguration;
import com.jogamp.nativewindow.AbstractGraphicsDevice;
import com.jogamp.nativewindow.MutableGraphicsConfiguration;
import com.jogamp.nativewindow.OffscreenLayerSurface;
-import com.jogamp.opengl.FBObject;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GLCapabilitiesImmutable;
import com.jogamp.opengl.GLContext;
import com.jogamp.opengl.GLException;
-import com.jogamp.opengl.GLFBODrawable;
import com.jogamp.opengl.GLProfile;
-import jogamp.nativewindow.ios.IOSUtil;
import jogamp.opengl.GLContextImpl;
+import jogamp.opengl.GLDrawableFactoryImpl;
import jogamp.opengl.GLDrawableImpl;
import jogamp.opengl.GLDynamicLookupHelper;
import jogamp.opengl.GLFBODrawableImpl;
+import jogamp.opengl.GLDrawableFactoryImpl.OnscreenFBOColorbufferStorageDefinition;
import jogamp.opengl.GLFBODrawableImpl.SwapBufferContext;
import jogamp.opengl.DummyGLExtProcAddressTable;
import jogamp.opengl.ios.eagl.IOSEAGLDrawable.GLBackendType;
@@ -100,8 +99,6 @@ public class IOSEAGLContext extends GLContextImpl
// CGL extension functions.
private DummyGLExtProcAddressTable cglExtProcAddressTable;
- private int lastWidth, lastHeight;
-
protected IOSEAGLContext(final GLDrawableImpl drawable,
final GLContext shareWith) {
super(drawable, shareWith);
@@ -194,11 +191,6 @@ public class IOSEAGLContext extends GLContextImpl
@Override
protected void makeCurrentImpl() throws GLException {
- /** FIXME: won't work w/ special drawables (like FBO) - check for CGL mode regressions!
- *
- if (getOpenGLMode() != ((IOSEAGLDrawable)drawable).getOpenGLMode()) {
- setOpenGLMode(((IOSEAGLDrawable)drawable).getOpenGLMode());
- } */
if ( !impl.makeCurrent(contextHandle) ) {
throw new GLException("Error making Context current: "+this);
}
@@ -221,50 +213,48 @@ public class IOSEAGLContext extends GLContextImpl
@Override
protected void drawableUpdatedNotify() throws GLException {
- if( drawable.getChosenGLCapabilities().isOnscreen() ) {
- final int w = drawable.getSurfaceWidth();
- final int h = drawable.getSurfaceHeight();
- // final boolean sizeChanged = w != lastWidth || h != lastHeight;
- if(drawable instanceof GLFBODrawable) {
- final GLFBODrawable fbod = (GLFBODrawable) drawable;
- final FBObject.Colorbuffer col = fbod.getColorbuffer(GL.GL_FRONT); // FIXME GL_BACK swap ..
- final int renderbuffer = col.getName();
- EAGL.eaglPresentRenderbuffer(contextHandle, renderbuffer);
- }
- // TODO: Check for resize ...
- lastWidth = w;
- lastHeight = h;
- }
+ // NOTE to resize: GLFBODrawableImpl.resetSize(GL) called from many
+ // high level instances in the GLDrawable* space,
+ // e.g. GLAutoDrawableBase's defaultWindowResizedOp(..)
}
@Override
protected void associateDrawable(final boolean bound) {
// context stuff depends on drawable stuff
- if(bound) {
+ final GLFBODrawableImpl fboDrawable;
+ final boolean taggedOnscreenFBOEAGLLayer;
+ {
final GLDrawableImpl drawable = getDrawableImpl();
- if( drawable instanceof GLFBODrawableImpl ) {
- final GLFBODrawableImpl fboDrawable = (GLFBODrawableImpl) drawable;
+ final GLDrawableFactoryImpl factory = drawable.getFactoryImpl();
+ final IOSEAGLDrawableFactory iosFactory = (factory instanceof IOSEAGLDrawableFactory) ? (IOSEAGLDrawableFactory) factory : null;
+ final OnscreenFBOColorbufferStorageDefinition onscreenFBOColorbufStorageDef = (null != iosFactory) ? iosFactory.getOnscreenFBOColorbufStorageDef() : null;
+
+ fboDrawable = (drawable instanceof GLFBODrawableImpl) ? (GLFBODrawableImpl)drawable : null;
+ taggedOnscreenFBOEAGLLayer = (null != fboDrawable && null != onscreenFBOColorbufStorageDef) ?
+ fboDrawable.hasColorRenderbufferStorageDef(onscreenFBOColorbufStorageDef) : false;
+ }
+ if( DEBUG ) {
+ System.err.println(getThreadName() + ": IOSEAGLContext.associateDrawable(bound "+bound+"): taggedOnscreenFBOEAGLLayer "+taggedOnscreenFBOEAGLLayer+
+ ", hasFBODrawable "+(null != fboDrawable)+", drawable: "+getDrawableImpl().getClass().getName());
+ }
+ if(bound) {
+ if( taggedOnscreenFBOEAGLLayer ) {
+ // Done in GLDrawableFactory.createGDrawable(..) for onscreen drawables:
+ // fboDrawable.setColorRenderbufferStorageDef(iosFactory.getOnscreenFBOColorbufStorageDef());
fboDrawable.setSwapBufferContext(new SwapBufferContext() {
@Override
public void swapBuffers(final boolean doubleBuffered) {
EAGL.eaglPresentRenderbuffer(contextHandle, GL.GL_RENDERBUFFER);
} } );
}
- // FIXME: Need better way to inject the IOS EAGL Layer into FBObject
- // FIXME: May want to implement optional injection of a BufferStorage SPI?
- // FBObject.ColorAttachment.initialize(GL): EAGL.eaglBindDrawableStorageToRenderbuffer(contextHandle, GL.GL_RENDERBUFFER, eaglLayer);
- final long eaglLayer = IOSUtil.GetCAEAGLLayer(drawable.getNativeSurface().getSurfaceHandle());
- System.err.println("EAGL: Ctx attach EAGLLayer 0x"+Long.toHexString(eaglLayer));
- attachObject("IOS_EAGL_LAYER", new Long(eaglLayer));
-
super.associateDrawable(true); // 1) init drawable stuff (FBO init, ..)
impl.associateDrawable(true); // 2) init context stuff
} else {
impl.associateDrawable(false); // 1) free context stuff
super.associateDrawable(false); // 2) free drawable stuff
-
- EAGL.eaglBindDrawableStorageToRenderbuffer(contextHandle, GL.GL_RENDERBUFFER, 0);
- detachObject("IOS_EAGL_LAYER");
+ if( taggedOnscreenFBOEAGLLayer ) {
+ EAGL.eaglBindDrawableStorageToRenderbuffer(contextHandle, GL.GL_RENDERBUFFER, 0);
+ }
}
}
@@ -361,40 +351,6 @@ public class IOSEAGLContext extends GLContextImpl
@Override
public boolean isUsingCAEAGLLayer() { return null != backingLayerHost; }
- /** Only returns a valid UIView. If !UIView, return null and mark isFBO or isSurfaceless. */
- private long getUIViewHandle(final boolean[] isFBO, final boolean[] isSurfaceless) {
- final long uiViewHandle;
- if(drawable instanceof GLFBODrawableImpl) {
- uiViewHandle = 0;
- isFBO[0] = true;
- isSurfaceless[0] = false;
- if(DEBUG) {
- System.err.println("UI viewHandle.1: GLFBODrawableImpl drawable: isFBO "+isFBO[0]+", isSurfaceless "+isSurfaceless[0]+", "+drawable.getClass().getName()+",\n\t"+drawable);
- }
- } else {
- final long drawableHandle = drawable.getHandle();
- final boolean isUIView = IOSUtil.isUIView(drawableHandle);
- final boolean isUIWindow = IOSUtil.isUIWindow(drawableHandle);
- isFBO[0] = false;
- isSurfaceless[0] = false;
-
- if( isUIView ) {
- uiViewHandle = drawableHandle;
- } else if( isUIWindow ) {
- uiViewHandle = IOSUtil.GetUIView(drawableHandle, true /* only EAGL */);
- } else if( isSurfaceless() ) {
- isSurfaceless[0] = true;
- uiViewHandle = 0;
- } else {
- throw new GLException("Drawable's handle neither NSView, NSWindow nor PBuffer: drawableHandle "+toHexString(drawableHandle)+", isNSView "+isUIView+", isNSWindow "+isUIWindow+", isFBO "+isFBO[0]+", "+drawable.getClass().getName()+",\n\t"+drawable);
- }
- if(DEBUG) {
- System.err.println("NS viewHandle.2: drawableHandle "+toHexString(drawableHandle)+" -> nsViewHandle "+toHexString(uiViewHandle)+": isNSView "+isUIView+", isNSWindow "+isUIWindow+", isFBO "+isFBO[0]+", isSurfaceless "+isSurfaceless[0]+", "+drawable.getClass().getName()+",\n\t"+drawable);
- }
- }
- return uiViewHandle;
- }
-
@Override
public long create(final long share, final int ctp, final int major, final int minor) {
long ctx = 0;
diff --git a/src/jogl/classes/jogamp/opengl/ios/eagl/IOSEAGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/ios/eagl/IOSEAGLDrawableFactory.java
index 3c3f1edb8..71904d1a6 100644
--- a/src/jogl/classes/jogamp/opengl/ios/eagl/IOSEAGLDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/ios/eagl/IOSEAGLDrawableFactory.java
@@ -41,6 +41,7 @@ import com.jogamp.nativewindow.NativeSurface;
import com.jogamp.nativewindow.ProxySurface;
import com.jogamp.nativewindow.UpstreamSurfaceHook;
import com.jogamp.nativewindow.ios.IOSGraphicsDevice;
+import com.jogamp.opengl.FBObject;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLCapabilitiesChooser;
@@ -52,6 +53,7 @@ import com.jogamp.opengl.GLProfile;
import jogamp.nativewindow.WrappedSurface;
import jogamp.nativewindow.ios.IOSDummyUpstreamSurfaceHook;
+import jogamp.nativewindow.ios.IOSUtil;
import jogamp.opengl.GLContextImpl;
import jogamp.opengl.GLDrawableFactoryImpl;
import jogamp.opengl.GLDrawableImpl;
@@ -62,6 +64,8 @@ import jogamp.opengl.SharedResourceRunner;
import com.jogamp.nativewindow.GenericUpstreamSurfacelessHook;
import com.jogamp.opengl.GLExtensions;
import com.jogamp.opengl.GLRendererQuirks;
+import com.jogamp.opengl.FBObject.Attachment;
+import com.jogamp.opengl.FBObject.Attachment.StorageDefinition;
public class IOSEAGLDrawableFactory extends GLDrawableFactoryImpl {
private static final boolean DEBUG_SHAREDCTX = DEBUG || GLContext.DEBUG;
@@ -343,6 +347,39 @@ public class IOSEAGLDrawableFactory extends GLDrawableFactoryImpl {
}
@Override
+ protected final OnscreenFBOColorbufferStorageDefinition getOnscreenFBOColorbufStorageDef() { return onscreenGLDrawableFBOColorRenderbufferStorageDef; }
+ private final OnscreenFBOColorbufferStorageDefinition onscreenGLDrawableFBOColorRenderbufferStorageDef = new OnscreenFBOColorbufferStorageDefinition() {
+ @Override
+ public final void setStorage(final GL gl, final Attachment a) {
+ final int samples = ((FBObject.RenderAttachment) a).getSamples();
+ if( samples > 0 ) {
+ gl.glRenderbufferStorageMultisample(GL.GL_RENDERBUFFER, samples, a.format, a.getWidth(), a.getHeight());
+ } else {
+ // gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, a.format, a.getWidth(), a.getHeight());
+ final long eaglLayer = IOSUtil.GetCAEAGLLayer(gl.getContext().getGLDrawable().getNativeSurface().getSurfaceHandle());
+ EAGL.eaglBindDrawableStorageToRenderbuffer(gl.getContext().getHandle(), GL.GL_RENDERBUFFER, eaglLayer);
+ if( DEBUG ) {
+ System.err.println("EAGL.eaglBindDrawableStorageToRenderbuffer: ctx 0x"+Long.toHexString(gl.getContext().getHandle()) +
+ ", eaglLayer 0x"+Long.toHexString(eaglLayer));
+ }
+ }
+ }
+ @Override
+ public final boolean isDoubleBufferSupported() {
+ return false;
+ }
+ @Override
+ public final int getTextureUnit() {
+ return -1; // force using a color renderbuffer
+ } };
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * This IOS <i>onscreen drawable</i> implementation actually is only a dummy implementation
+ * </p>
+ */
+ @Override
protected GLDrawableImpl createOnscreenDrawableImpl(final NativeSurface target) {
if (target == null) {
throw new IllegalArgumentException("Null target");