From 019a6fe3c2f5efe550d41f7262b8010d3cfa0aa0 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Mon, 24 Jun 2019 22:05:47 +0200
Subject: iOS: EAGLLayer FBO w/ DEPTH buffer workaround 1

Notable bug as mentioned before:
The FBO used and sharing the COLORBUFFER RENDERBUFFER
memory resources with CAEAGLLayer to be displayed in the UIView
seemingly cannot handle GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT24
or GL_DEPTH_COMPONENT32 depth buffer - none at all (Device + Simulation).

This workaround re-binds the used color renderbuffer for EAGLLayer presentation
at the end of the FBO drawable instantiation.

FBO DEPTH buffer works now as demonstrated w/ GearsES2.

We have to issue one more test now, using a demo using an FBO itself.
---
 src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java | 10 ++++++++++
 1 file changed, 10 insertions(+)

(limited to 'src/jogl/classes/jogamp')

diff --git a/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java b/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java
index ea226b407..8ec3c0dd9 100644
--- a/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLFBODrawableImpl.java
@@ -113,6 +113,7 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
 
         final boolean useDepth   = depthBits > 0;
         final boolean useStencil = stencilBits > 0;
+        FBObject.ColorAttachment pCA = null;
 
         fbo.init(gl, width, height, samples);
         if(fbo.getNumSamples() != samples) {
@@ -122,6 +123,7 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
             final FBObject.ColorAttachment ca = fbo.createColorAttachment(useAlpha);
             if( null != colorRenderbufferStorageDef ) {
                 ca.setStorageDefinition(colorRenderbufferStorageDef);
+                pCA = ca;
             }
             fbo.attachColorbuffer(gl, 0, ca);
         } else {
@@ -166,6 +168,14 @@ public class GLFBODrawableImpl extends GLDrawableImpl implements GLFBODrawable {
         // Also remedy for Bug 1020, i.e. OSX/Nvidia's FBO needs to be cleared before blitting,
         // otherwise first MSAA frame lacks antialiasing.
         fbo.bind(gl);
+
+        if( null != pCA ) {
+            // FIXME: Apple iOS EAGLLayer doesn't show any content if the
+            // last bound RENDERBUFFER isn't the color renderbuffer,
+            // i.e. a subsequent bound DEPTH buffer has been attached.
+            gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, pCA.getName());
+        }
+
         if( setupViewportScissors ) {
             // Surfaceless: Set initial viewport/scissors
             gl.glViewport(0, 0, width, height);
-- 
cgit v1.2.3