Commits

Michael Ludwig committed 2a1c07c

Correct context-swapping bugs to properly support pbuffer texture surfaces.

  • Participants
  • Parent commits db28b6e

Comments (0)

Files changed (7)

ferox-renderer/ferox-renderer-impl/src/main/java/com/ferox/renderer/impl/AbstractFramework.java

                         // accumulate the exceptions but continue to destroy
                         // all of the surfaces
                         surfaceDestroyExceptions.add(e);
+                        // must remove this surface so the loop can terminate
+                        surfaces.remove(toDestroy);
                     }
                 }
             }

ferox-renderer/ferox-renderer-impl/src/main/java/com/ferox/renderer/impl/AbstractSurface.java

                                 }
                             }, true);
         } else {
+            System.out.println("Destroy already completed");
             // If we've already been destroyed, use a completed future so
             // it's seen as completed
             return new CompletedFuture<Void>(null);

ferox-renderer/ferox-renderer-impl/src/main/java/com/ferox/renderer/impl/ContextManager.java

      */
     private class ContextThread extends Thread {
         private AbstractSurface activeSurface; // active surface, might differ from contextProvider
-        private AbstractSurface contextProvider; // source of currentContext if it's not the shared context
-
         private OpenGLContext currentContext; // non-null when a context is current
 
         private final BlockingDeque<Sync<?>> tasks; // pending tasks
                 sharedContext.makeCurrent();
 
                 currentContext = sharedContext;
-                contextProvider = null;
             } // else there's a current context from somewhere, just go with it
 
             return currentContext;
                 // Now check to see if the underlying context needs to change
                 OpenGLContext newContext = surface.getContext();
                 if (newContext != null) {
-                    // New surface needs its own context, so release and unlock the current context
-                    releaseContext();
+                    if (newContext != currentContext) {
+                        // New surface needs its own context, so release and unlock the current context
+                        releaseContext();
 
-                    // Now make its context current
-                    newContext.makeCurrent();
-                    currentContext = newContext;
-                    contextProvider = surface;
+                        // Now make its context current
+                        newContext.makeCurrent();
+                        currentContext = newContext;
+                    }
                 } else {
                     // Make sure we have a context for this surface, since it doesn't have its own
                     ensureContext();
                 deactivateSurface();
             }
 
-            // then make sure we release its context
-            if (surface == contextProvider) {
-                releaseContext();
-            }
+            // then make sure we release the current context because many libs
+            // make the surface being destroyed current prior to destruction
+            // and release, but that makes our tracking get out of sync
+            releaseContext();
         }
 
         private void deactivateSurface() {
             if (currentContext != null) {
                 currentContext.release();
                 currentContext = null;
-                contextProvider = null;
             }
         }
 

ferox-renderer/ferox-renderer-impl/src/main/java/com/ferox/renderer/impl/LifeCycleManager.java

             // This iteration does not need to worry about changes to the thread-list
             // since the shutdown task is only started after the status is set to STOPPING
             // at which point no threads can be added to the managed group.
-            boolean loop = false;
+            boolean loop;
             do {
                 loop = false;
                 for (Thread managed : managedThreads) {

ferox-renderer/ferox-renderer-jogl/src/main/java/com/ferox/renderer/impl/jogl/JoglFboTextureSurface.java

 
             // Enable/disable the read/draw buffers to make the fbo "complete"
             gl.glReadBuffer(GL.GL_NONE);
-            if (colorImageIds != null) {
+            if (colorImageIds.length > 0) {
                 int[] drawBuffers = new int[colorImageIds.length];
                 for (int i = 0; i < drawBuffers.length; i++) {
                     drawBuffers[i] = GL.GL_COLOR_ATTACHMENT0 + i;

ferox-renderer/ferox-renderer-lwjgl/src/main/java/com/ferox/renderer/impl/lwjgl/LwjglFboTextureSurface.java

 
             // Enable/disable the read/draw buffers to make the fbo "complete"
             GL11.glReadBuffer(GL11.GL_NONE);
-            if (colorImageIds != null) {
+            if (colorImageIds.length > 0) {
                 IntBuffer drawBuffers = BufferUtil.newIntBuffer(colorImageIds.length);
                 for (int i = 0; i < colorImageIds.length; i++) {
                     if (useEXT) {

ferox-renderer/ferox-renderer-lwjgl/src/main/java/com/ferox/renderer/impl/lwjgl/LwjglPbufferTextureSurface.java

 import com.ferox.renderer.impl.OpenGLContext;
 import com.ferox.renderer.impl.RendererProvider;
 import com.ferox.renderer.impl.drivers.TextureHandle;
-import com.ferox.resource.BufferData.DataType;
 import com.ferox.resource.Texture;
 import com.ferox.resource.TextureFormat;
 
         }
 
         if (depth != null) {
-            if (depth.getDataType() == DataType.UNSIGNED_BYTE) {
-                pf = pf.withDepthBits(16);
-            } else if (depth.getDataType() == DataType.UNSIGNED_SHORT) {
-                pf = pf.withDepthBits(24);
-            } else {
-                pf = pf.withDepthBits(32);
-            }
+            //            if (depth.getDataType() == DataType.UNSIGNED_BYTE) {
+            //                pf = pf.withDepthBits(16);
+            //            } else if (depth.getDataType() == DataType.UNSIGNED_SHORT) {
+            //                pf = pf.withDepthBits(24);
+            //            } else {
+            //                pf = pf.withDepthBits(32);
+            //            }
+            // FIXME On my Mac, LWJGL seems unable to select appropriate depth
+            pf = pf.withDepthBits(24);
         } else {
             pf = pf.withDepthBits(24);
         }