commit 09d4f4b11a42a5a6d33a1e80446b083ec97b5a25
Author: Leszek Koltunski <leszek@distorted.org>
Date:   Wed Dec 14 22:33:05 2016 +0000

    Change of API in DistortedFramebuffer.

diff --git a/src/main/java/org/distorted/library/DistortedFramebuffer.java b/src/main/java/org/distorted/library/DistortedFramebuffer.java
index a2eb340..be6b5ca 100644
--- a/src/main/java/org/distorted/library/DistortedFramebuffer.java
+++ b/src/main/java/org/distorted/library/DistortedFramebuffer.java
@@ -59,41 +59,6 @@ public class DistortedFramebuffer
   float mDistance;
   float[] mProjectionMatrix;
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  private void createProjection()
-    {
-    if( mWidth>0 && mHeight>1 )
-      {
-      if( mFOV>0.0f )  // perspective projection
-        {
-        float left   = (-mX-mWidth /2.0f)/mHeight;
-        float right  = (-mX+mWidth /2.0f)/mHeight;
-        float bottom = (-mY-mHeight/2.0f)/mHeight;
-        float top    = (-mY+mHeight/2.0f)/mHeight;
-        float near   = (top-bottom) / (2.0f*(float)Math.tan(mFOV*Math.PI/360));
-        mDistance    = mHeight*near/(top-bottom);
-        float far    = 2*mDistance-near;
-        mDepth       = (int)((far-near)/2);
-
-        Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
-        }
-      else             // parallel projection
-        {
-        float left   = -mX-mWidth /2.0f;
-        float right  = -mX+mWidth /2.0f;
-        float bottom = -mY-mHeight/2.0f;
-        float top    = -mY+mHeight/2.0f;
-        float near   = (mWidth+mHeight)/2;
-        mDistance    = 2*near;
-        float far    = 3*near;
-        mDepth       = (int)near;
-
-        Matrix.orthoM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
-        }
-      }
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Must be called from a thread holding OpenGL Context
 
@@ -148,6 +113,26 @@ public class DistortedFramebuffer
     mMarked = false;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Must be called from a thread holding OpenGL Context
+
+  void setAsOutput()
+    {
+    if( texIds[0]==TEXTURE_NOT_CREATED_YET ) createFBO();
+
+    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Must be called from a thread holding OpenGL Context
+
+  void setAsInput()
+    {
+    if( texIds[0]==TEXTURE_NOT_CREATED_YET ) createFBO();
+
+    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIds[0]);
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   void reset()
@@ -156,6 +141,41 @@ public class DistortedFramebuffer
       texIds[0] = TEXTURE_NOT_CREATED_YET;
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private void createProjection()
+    {
+    if( mWidth>0 && mHeight>1 )
+      {
+      if( mFOV>0.0f )  // perspective projection
+        {
+        float left   = (-mX-mWidth /2.0f)/mHeight;
+        float right  = (-mX+mWidth /2.0f)/mHeight;
+        float bottom = (-mY-mHeight/2.0f)/mHeight;
+        float top    = (-mY+mHeight/2.0f)/mHeight;
+        float near   = (top-bottom) / (2.0f*(float)Math.tan(mFOV*Math.PI/360));
+        mDistance    = mHeight*near/(top-bottom);
+        float far    = 2*mDistance-near;
+        mDepth       = (int)((far-near)/2);
+
+        Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
+        }
+      else             // parallel projection
+        {
+        float left   = -mX-mWidth /2.0f;
+        float right  = -mX+mWidth /2.0f;
+        float bottom = -mY-mHeight/2.0f;
+        float top    = -mY+mHeight/2.0f;
+        float near   = (mWidth+mHeight)/2;
+        mDistance    = 2*near;
+        float far    = 3*near;
+        mDepth       = (int)near;
+
+        Matrix.orthoM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
+        }
+      }
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
   static synchronized void release()
@@ -293,28 +313,17 @@ public class DistortedFramebuffer
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
- *  Set this as the Framebuffer to write to.
- *  <p>
- *  Must be called from a thread holding OpenGL Context
- */
-  public void setAsOutput()
-    {
-    if( texIds[0]==TEXTURE_NOT_CREATED_YET ) createFBO();
-
-    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]);
-    }
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-/**
- *  Set this as the Framebuffer to read from.
- *  <p>
- *  Must be called from a thread holding OpenGL Context
+ * Return the ID of the Texture (COLOR attachment 0) that's backing this FBO.
+ * <p>
+ * Catch: this will only work if the library has had time to actually create the texture. Remember
+ * that the texture gets created only on first render, thus creating a Texture object and immediately
+ * calling this method will return an invalid (negative) result.
+ *
+ * @returns If there was not a single render between creation of the Object and calling this method on
+ *          it, return a negative value. Otherwise, return ID of COLOR attachment 0.
  */
-  public void setAsInput()
+  public int getTextureID()
     {
-    if( texIds[0]==TEXTURE_NOT_CREATED_YET ) createFBO();
-
-    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIds[0]);
+    return texIds[0];
     }
-
   }
