commit c365100166ba0cbdda96f069a3726d470e53ad15
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Fri Jun 9 16:01:13 2017 +0100

    Convert the first few Apps to the new Effect API.

diff --git a/src/main/java/org/distorted/library/effect/Effect.java b/src/main/java/org/distorted/library/effect/Effect.java
index 4a5c5cf..1f7db6d 100644
--- a/src/main/java/org/distorted/library/effect/Effect.java
+++ b/src/main/java/org/distorted/library/effect/Effect.java
@@ -24,7 +24,7 @@ package org.distorted.library.effect;
 public abstract class Effect
   {
   private final static int MAX_UNITY_DIM = 4;
-  private final static int NUM_EFFECTS = EffectName.size();
+  private final static int NUM_EFFECTS = EffectName.LENGTH;
 
   private final long mID;
   private final EffectType mType;
diff --git a/src/main/java/org/distorted/library/effect/EffectName.java b/src/main/java/org/distorted/library/effect/EffectName.java
index 9e9e323..16f69fa 100644
--- a/src/main/java/org/distorted/library/effect/EffectName.java
+++ b/src/main/java/org/distorted/library/effect/EffectName.java
@@ -63,20 +63,26 @@ public enum EffectName
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
+  public static final int LENGTH = values().length;
   private final EffectType type;
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-  EffectName(EffectType type)
+  private static final EffectName[] names;  // copy the values() to a local variable so that we
+                                            // don't have to keep recreating the array every time
+  static
     {
-    this.type = type;
+    int i=0;
+    names = new EffectName[LENGTH];
+
+    for(EffectName name: EffectName.values())
+      {
+      names[i++] = name;
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  static int size()
+  EffectName(EffectType type)
     {
-    return values().length;
+    this.type = type;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -91,5 +97,16 @@ public enum EffectName
     {
     return type;
     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ * Returns the i-th EffectName.
+ * <p>
+ * If you want to loop over all possible Effects, you need this.
+ */
+  public static EffectName getName(int ordinal)
+    {
+    return names[ordinal];
+    }
   }
 
diff --git a/src/main/java/org/distorted/library/main/DistortedEffects.java b/src/main/java/org/distorted/library/main/DistortedEffects.java
index d666dea..f915325 100644
--- a/src/main/java/org/distorted/library/main/DistortedEffects.java
+++ b/src/main/java/org/distorted/library/main/DistortedEffects.java
@@ -52,7 +52,16 @@ public class DistortedEffects
   /// MAIN PROGRAM ///
   private static DistortedProgram mMainProgram;
   private static int mMainTextureH;
-  private static ArrayList<EffectName> mEnabledEffects = new ArrayList<>();
+  private static boolean[] mEffectEnabled = new boolean[EffectName.LENGTH];
+
+  static
+    {
+    int len = EffectName.LENGTH;
+    for(int i=0; i<len; i++)
+      {
+      mEffectEnabled[i] = false;
+      }
+    }
 
   /// BLIT PROGRAM ///
   private static DistortedProgram mBlitProgram;
@@ -99,26 +108,28 @@ public class DistortedEffects
     String mainVertHeader= Distorted.GLSL_VERSION;
     String mainFragHeader= Distorted.GLSL_VERSION;
 
+    EffectName name;
+    EffectType type;
     boolean foundF = false;
     boolean foundV = false;
-    int effects = mEnabledEffects.size();
-    EffectName effect;
-    EffectType type;
 
-    for(int i=0; i<effects; i++)
+    for(int i=0; i<mEffectEnabled.length; i++)
       {
-      effect = mEnabledEffects.remove(0);
-      type   = effect.getType();
-
-      if( type == EffectType.VERTEX )
-        {
-        mainVertHeader += ("#define "+effect.name()+" "+effect.ordinal()+"\n");
-        foundV = true;
-        }
-      else if( type == EffectType.FRAGMENT )
+      if( mEffectEnabled[i] )
         {
-        mainFragHeader += ("#define "+effect.name()+" "+effect.ordinal()+"\n");
-        foundF = true;
+        name = EffectName.getName(i);
+        type = name.getType();
+
+        if( type == EffectType.VERTEX )
+          {
+          mainVertHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
+          foundV = true;
+          }
+        else if( type == EffectType.FRAGMENT )
+          {
+          mainFragHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
+          foundF = true;
+          }
         }
       }
 
@@ -342,6 +353,11 @@ public class DistortedEffects
   static void onDestroy()
     {
     mNextID = 0;
+
+    for(int i=0; i<EffectName.LENGTH; i++)
+      {
+      mEffectEnabled[i] = false;
+      }
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -501,7 +517,7 @@ public class DistortedEffects
  */
   public static void enableEffect(EffectName name)
     {
-    mEnabledEffects.add(name);
+    mEffectEnabled[name.ordinal()] = true;
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
