commit 7691a39f3126e7743afac456ec30712d9e76a6d5
Author: leszek <leszek@koltunski.pl>
Date:   Tue Feb 14 22:36:35 2017 +0000

    - workaround for the issue with flashing in StarWars
    - return number of objects rendered from OutputSurface.render() and use this in Olympic
    - rework tree isomorphism so that it now works even if we don't render the whole tree (and also we don't have to reset() the Tree anymore!)
    - current a buf with tree isomorphism: Leaf Nodes have the same NodeData only if they agree in Surface AND Effects!

diff --git a/src/main/java/org/distorted/library/Distorted.java b/src/main/java/org/distorted/library/Distorted.java
index 53c4d94..6a3cb34 100644
--- a/src/main/java/org/distorted/library/Distorted.java
+++ b/src/main/java/org/distorted/library/Distorted.java
@@ -30,11 +30,6 @@ import org.distorted.library.program.*;
  */
 public class Distorted 
   {
-  /**
-   * When creating an instance of a DistortedTexture (or Tree) from another instance, do not clone anything.
-   * Used in the copy constructor.
-   */
-  public static final int CLONE_NOTHING = 0x0;
   /**
    * When creating an instance of a DistortedTexture from another instance, clone the Bitmap that's
    * backing up our DistortedTexture.
@@ -121,7 +116,6 @@ public class Distorted
     DistortedEffects.createProgram(resources);
     EffectQueuePostprocess.createProgram(resources);
 
-    DistortedNode.reset();
     EffectMessageSender.startSending();
 
     mInitialized = true;
diff --git a/src/main/java/org/distorted/library/DistortedNode.java b/src/main/java/org/distorted/library/DistortedNode.java
index 9b88072..7ddbb64 100644
--- a/src/main/java/org/distorted/library/DistortedNode.java
+++ b/src/main/java/org/distorted/library/DistortedNode.java
@@ -52,7 +52,7 @@ public class DistortedNode implements DistortedAttacheable
     {
     long ID;
     int numPointingNodes;
-    int numRendered;
+    int numRender;
     ArrayList<Long> key;
     DistortedFramebuffer mFBO;
 
@@ -61,7 +61,7 @@ public class DistortedNode implements DistortedAttacheable
       ID              = id;
       key             = k;
       numPointingNodes= 1;
-      numRendered     = 0;
+      numRender       =-1;
       mFBO            = null;
       }
     }
@@ -81,6 +81,12 @@ public class DistortedNode implements DistortedAttacheable
     ArrayList<Long> ret = new ArrayList<>();
      
     ret.add( mSurface.getID() );
+
+    if( mNumChildren[0]==0 )
+      {
+      ret.add(-mEffects.getID());
+      }
+
     DistortedNode node;
    
     for(int i=0; i<mNumChildren[0]; i++)
@@ -92,21 +98,6 @@ public class DistortedNode implements DistortedAttacheable
     return ret;
     }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////  
-// this will be called on startup and every time OpenGL context has been lost
-
-  static void reset()
-    {
-    NodeData tmp;   
-     
-    for(ArrayList<Long> key: mMapNodeID.keySet())
-      {
-      tmp = mMapNodeID.get(key);
-          
-      if( tmp.mFBO != null ) tmp.numRendered = 0;
-      }
-    }
-
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // Debug - print all the Node IDs
 
@@ -208,9 +199,11 @@ public class DistortedNode implements DistortedAttacheable
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
+// return the total number of render calls issued
 
-  void drawRecursive(long currTime, DistortedOutputSurface surface)
+  int drawRecursive(int render, long currTime, DistortedOutputSurface surface)
     {
+    int ret = 0;
     float halfX = mSurface.getWidth()/2.0f;
     float halfY = mSurface.getHeight()/2.0f;
 
@@ -220,28 +213,32 @@ public class DistortedNode implements DistortedAttacheable
       }
     else
       {
-      if( mData.numRendered==0 )
+      if( mData.numRender!=render )
         {
+        mData.numRender = render;
         mData.mFBO.setAsOutput();
 
         GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
         GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
 
         if( mSurface.setAsInput() )
-          DistortedEffects.drawNoEffectsPriv(halfX, halfY, mMesh, mData.mFBO );
+          {
+          ret++;
+          DistortedEffects.drawNoEffectsPriv(halfX, halfY, mMesh, mData.mFBO);
+          }
 
         for(int i=0; i<mNumChildren[0]; i++)
           {
-          mChildren.get(i).drawRecursive(currTime, mData.mFBO);
+          ret += mChildren.get(i).drawRecursive(render, currTime, mData.mFBO);
           }
         }
 
-      mData.numRendered++;
-      mData.numRendered %= mData.numPointingNodes;
       mData.mFBO.setAsInput();
       }
 
     mEffects.drawPriv(halfX, halfY, mMesh, surface, currTime);
+
+    return ret+1;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -265,6 +262,7 @@ public class DistortedNode implements DistortedAttacheable
    
     ArrayList<Long> list = new ArrayList<>();
     list.add(mSurface.getID());
+    list.add(-mEffects.getID());
 
     mData = mMapNodeID.get(list);
    
diff --git a/src/main/java/org/distorted/library/DistortedOutputSurface.java b/src/main/java/org/distorted/library/DistortedOutputSurface.java
index 960d04f..b8e92e9 100644
--- a/src/main/java/org/distorted/library/DistortedOutputSurface.java
+++ b/src/main/java/org/distorted/library/DistortedOutputSurface.java
@@ -27,6 +27,8 @@ import java.util.ArrayList;
 
 abstract class DistortedOutputSurface extends DistortedSurface implements DistortedAttacheable
 {
+  private static int mRender = 0;
+
   private ArrayList<DistortedNode> mChildren;
   private int mNumChildren;   // ==mChildren.length(), but we only create mChildren if the first one gets added
 
@@ -105,9 +107,12 @@ abstract class DistortedOutputSurface extends DistortedSurface implements Distor
  * Must be called from a thread holding OpenGL Context.
  *
  * @param time Current time, in milliseconds. This will be passed to all the Effects stored in the children Nodes.
+ * @return Number of objects rendered.
  */
-  public void render(long time)
+  public int render(long time)
     {
+    mRender++;
+
     // change tree topology (attach and detach children)
     // create and delete all underlying OpenGL resources
     // Watch out: FIRST change topology, only then deal
@@ -125,7 +130,7 @@ abstract class DistortedOutputSurface extends DistortedSurface implements Distor
         mChildren.get(i).debug(0);
         }
 
-      //DistortedNode.debugMap();
+      DistortedNode.debugMap();
       }
 
     toDo();
@@ -135,10 +140,14 @@ abstract class DistortedOutputSurface extends DistortedSurface implements Distor
       DistortedSurface.debugLists();
       }
 
+    int numRenders = 0;
+
     for(int i=0; i<mNumChildren; i++)
       {
-      mChildren.get(i).drawRecursive(time,this);
+      numRenders += mChildren.get(i).drawRecursive(mRender,time,this);
       }
+
+    return numRenders;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
