commit 8eccf334cbf598ecd7a90974ffffe58b1245ffec
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Mon Jun 5 17:29:44 2017 +0100

    Beginnings of support for Effect classes.

diff --git a/src/main/java/org/distorted/library/Distorted.java b/src/main/java/org/distorted/library/Distorted.java
index 1d4f392..07d345b 100644
--- a/src/main/java/org/distorted/library/Distorted.java
+++ b/src/main/java/org/distorted/library/Distorted.java
@@ -25,6 +25,9 @@ import android.content.pm.ConfigurationInfo;
 import android.content.res.Resources;
 import org.distorted.library.program.*;
 
+import org.distorted.library.effect.*;
+
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * A singleton class used to control various global settings.
@@ -80,7 +83,7 @@ public class Distorted
 
   private Distorted()
     {
-    
+
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -119,6 +122,19 @@ public class Distorted
     EffectQueuePostprocess.createProgram(resources);
     EffectMessageSender.startSending();
 
+    Effect.reset();
+
+    String[] classes = Effect.getClassesOfPackage(context,"org.distorted.library.effect");
+    int len = classes.length;
+
+    android.util.Log.e("Distorted", "Number of classes found: "+len);
+
+    for(int i=0; i<len; i++)
+      {
+      android.util.Log.e("Distorted", "Class found: "+classes[i]);
+      }
+
+
     mInitialized = true;
     }
 
diff --git a/src/main/java/org/distorted/library/EffectQueueMatrix.java b/src/main/java/org/distorted/library/EffectQueueMatrix.java
index db0c0aa..cc7a92f 100644
--- a/src/main/java/org/distorted/library/EffectQueueMatrix.java
+++ b/src/main/java/org/distorted/library/EffectQueueMatrix.java
@@ -47,8 +47,8 @@ class EffectQueueMatrix extends EffectQueue
   private static float[] mViewMatrix= new float[16];
 
   private static int mObjDH;      // This is a handle to half a Object dimensions
-  private static int mMVPMatrixH; // pass in the transformation matrix
-  private static int mMVMatrixH;  // pass in the modelview matrix.
+  private static int mMVPMatrixH; // the transformation matrix
+  private static int mMVMatrixH;  // the modelview matrix.
   
 ///////////////////////////////////////////////////////////////////////////////////////////////////
    
diff --git a/src/main/java/org/distorted/library/effect/Effect.java b/src/main/java/org/distorted/library/effect/Effect.java
new file mode 100644
index 0000000..c67d0a4
--- /dev/null
+++ b/src/main/java/org/distorted/library/effect/Effect.java
@@ -0,0 +1,178 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2017 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// Distorted is free software: you can redistribute it and/or modify                             //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Distorted is distributed in the hope that it will be useful,                                  //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.library.effect;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+import android.content.Context;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+import dalvik.system.DexFile;
+
+public abstract class Effect
+  {
+  long mID;
+
+  private static long mNextID = 0;
+  static final int NUM_TYPES;
+  static int[] mMax;
+  static Class[] mDescendants;
+
+  static
+    {
+    try
+      {
+      mDescendants = getClasses("org.distorted.library.effect");
+      }
+    catch(ClassNotFoundException cnfe)
+      {
+      android.util.Log.e("Effect", "ClassNotFoundException: "+cnfe.getMessage());
+      }
+    catch(IOException ioe)
+      {
+      android.util.Log.e("Effect", "IOException: "+ioe.getMessage());
+      }
+
+    NUM_TYPES = mDescendants.length;
+    mMax = new int[NUM_TYPES];
+
+    android.util.Log.e("Effect", "Found "+NUM_TYPES+" descendant classes");
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static String[] getClassesOfPackage(Context c, String packageName)
+    {
+    ArrayList<String> classes = new ArrayList<>();
+
+    try
+      {
+      String packageCodePath = c.getPackageCodePath();
+      DexFile df = new DexFile(packageCodePath);
+
+      for (Enumeration<String> iter = df.entries(); iter.hasMoreElements(); )
+        {
+        String className = iter.nextElement();
+        if (className.contains(packageName))
+          {
+          classes.add(className.substring(className.lastIndexOf(".") + 1, className.length()));
+          }
+
+        android.util.Log.e("Distorted", "searching: "+className);
+        }
+      }
+    catch (IOException e)
+      {
+      e.printStackTrace();
+      }
+
+    return classes.toArray(new String[classes.size()]);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private static Class[] getClasses(String packageName) throws ClassNotFoundException, IOException
+    {
+    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+    assert classLoader != null;
+    String path = packageName.replace('.', '/');
+    Enumeration<URL> resources = classLoader.getResources(path);
+
+    android.util.Log.e("Effect", "resources: "+resources.toString());
+
+    List<File> dirs = new ArrayList<>();
+
+    while (resources.hasMoreElements())
+      {
+      URL resource = resources.nextElement();
+      dirs.add(new File(resource.getFile()));
+      }
+
+    android.util.Log.e("Effect", "Num of dirs: "+dirs.size());
+
+    ArrayList<Class> classes = new ArrayList<>();
+
+    for (File directory : dirs)
+      {
+      android.util.Log.e("Effect", "Searching in "+directory.getName());
+
+      classes.addAll(findClasses(directory, packageName));
+      }
+
+    return classes.toArray(new Class[classes.size()]);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  private static List<Class> findClasses(File directory, String packageName) throws ClassNotFoundException
+    {
+    List<Class> classes = new ArrayList<>();
+
+    if (!directory.exists())
+      {
+      return classes;
+      }
+
+    File[] files = directory.listFiles();
+
+    for (File file : files)
+      {
+      if (file.isDirectory())
+        {
+        assert !file.getName().contains(".");
+        classes.addAll(findClasses(file, packageName + "." + file.getName()));
+        }
+      else if (file.getName().endsWith(".class"))
+        {
+        classes.add(Class.forName(packageName + '.' + file.getName().substring(0, file.getName().length() - 6)));
+        }
+      }
+
+    return classes;
+    }
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static void onDestroy()
+    {
+    mNextID = 0;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  public static void reset()
+    {
+    mNextID = 1;
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+  Effect()
+    {
+    mID = mNextID++;
+    }
+  }
diff --git a/src/main/java/org/distorted/library/effect/FragmentEffect.java b/src/main/java/org/distorted/library/effect/FragmentEffect.java
new file mode 100644
index 0000000..cf9f821
--- /dev/null
+++ b/src/main/java/org/distorted/library/effect/FragmentEffect.java
@@ -0,0 +1,27 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2017 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// Distorted is free software: you can redistribute it and/or modify                             //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Distorted is distributed in the hope that it will be useful,                                  //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.library.effect;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public abstract class FragmentEffect extends Effect
+  {
+  
+  }
\ No newline at end of file
diff --git a/src/main/java/org/distorted/library/effect/MatrixEffect.java b/src/main/java/org/distorted/library/effect/MatrixEffect.java
new file mode 100644
index 0000000..b366cc4
--- /dev/null
+++ b/src/main/java/org/distorted/library/effect/MatrixEffect.java
@@ -0,0 +1,29 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2017 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// Distorted is free software: you can redistribute it and/or modify                             //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Distorted is distributed in the hope that it will be useful,                                  //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.library.effect;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public abstract class MatrixEffect extends Effect
+  {
+  static int mMax;
+
+
+  }
diff --git a/src/main/java/org/distorted/library/effect/PostprocessEffect.java b/src/main/java/org/distorted/library/effect/PostprocessEffect.java
new file mode 100644
index 0000000..1ff1708
--- /dev/null
+++ b/src/main/java/org/distorted/library/effect/PostprocessEffect.java
@@ -0,0 +1,27 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2017 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// Distorted is free software: you can redistribute it and/or modify                             //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Distorted is distributed in the hope that it will be useful,                                  //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.library.effect;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public abstract class PostprocessEffect extends Effect
+  {
+  
+  }
\ No newline at end of file
diff --git a/src/main/java/org/distorted/library/effect/VertexEffect.java b/src/main/java/org/distorted/library/effect/VertexEffect.java
new file mode 100644
index 0000000..5e45a85
--- /dev/null
+++ b/src/main/java/org/distorted/library/effect/VertexEffect.java
@@ -0,0 +1,27 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2017 Leszek Koltunski                                                               //
+//                                                                                               //
+// This file is part of Distorted.                                                               //
+//                                                                                               //
+// Distorted is free software: you can redistribute it and/or modify                             //
+// it under the terms of the GNU General Public License as published by                          //
+// the Free Software Foundation, either version 2 of the License, or                             //
+// (at your option) any later version.                                                           //
+//                                                                                               //
+// Distorted is distributed in the hope that it will be useful,                                  //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
+// GNU General Public License for more details.                                                  //
+//                                                                                               //
+// You should have received a copy of the GNU General Public License                             //
+// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+package org.distorted.library.effect;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public abstract class VertexEffect extends Effect
+  {
+  
+  }
\ No newline at end of file
