commit efc280afa5b11dc06d1abfad620e004a7c19aa36
Author: Leszek Koltunski <leszek@koltunski.pl>
Date:   Fri Apr 6 23:45:54 2018 +0100

    New 'PostprocessTree' app (unfinished)

diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index 2bac027..849c8c2 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -46,6 +46,7 @@
         <activity android:name=".blur.BlurActivity"/>
         <activity android:name=".multiblur.MultiblurActivity"/>
         <activity android:name=".triblur.TriblurActivity"/>
+        <activity android:name=".postprocesstree.PostprocessTreeActivity"/>
         <activity android:name=".stencil.StencilActivity"/>
         <activity android:name=".glow.GlowActivity"/>
         <activity android:name=".movingglow.MovingGlowActivity"/>
diff --git a/src/main/java/org/distorted/examples/TableOfContents.java b/src/main/java/org/distorted/examples/TableOfContents.java
index 8306875..e7741eb 100644
--- a/src/main/java/org/distorted/examples/TableOfContents.java
+++ b/src/main/java/org/distorted/examples/TableOfContents.java
@@ -64,6 +64,7 @@ import org.distorted.examples.mirror.MirrorActivity;
 import org.distorted.examples.blur.BlurActivity;
 import org.distorted.examples.multiblur.MultiblurActivity;
 import org.distorted.examples.triblur.TriblurActivity;
+import org.distorted.examples.postprocesstree.PostprocessTreeActivity;
 import org.distorted.examples.stencil.StencilActivity;
 import org.distorted.examples.glow.GlowActivity;
 import org.distorted.examples.movingglow.MovingGlowActivity;
@@ -359,6 +360,15 @@ public class TableOfContents extends ListActivity
       activityMapping.put(i++, TriblurActivity.class);
    }
 
+   {
+      final Map<String, Object> item = new HashMap<>();
+      item.put(ITEM_IMAGE, R.drawable.icon_example_postprocesstree);
+      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_postprocesstree));
+      item.put(ITEM_SUBTITLE, getText(R.string.example_postprocesstree_subtitle));
+      data.add(item);
+      activityMapping.put(i++, PostprocessTreeActivity.class);
+   }
+
    {
       final Map<String, Object> item = new HashMap<>();
       item.put(ITEM_IMAGE, R.drawable.icon_example_stencil);
diff --git a/src/main/java/org/distorted/examples/blur/BlurActivity.java b/src/main/java/org/distorted/examples/blur/BlurActivity.java
index 3a94a06..b1b389b 100644
--- a/src/main/java/org/distorted/examples/blur/BlurActivity.java
+++ b/src/main/java/org/distorted/examples/blur/BlurActivity.java
@@ -77,8 +77,8 @@ public class BlurActivity extends Activity  implements OnSeekBarChangeListener
       Distorted.onDestroy();  
       super.onDestroy();
       }
-   
-///////////////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
     
     public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) 
       {
@@ -92,11 +92,11 @@ public class BlurActivity extends Activity  implements OnSeekBarChangeListener
         }
       }
 
-///////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////////////////////////
 
     public void onStartTrackingTouch(SeekBar bar) { }
-    
-///////////////////////////////////////////////////////////////////
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
 
     public void onStopTrackingTouch(SeekBar bar)  { }
      
diff --git a/src/main/java/org/distorted/examples/postprocesstree/PostprocessTreeActivity.java b/src/main/java/org/distorted/examples/postprocesstree/PostprocessTreeActivity.java
new file mode 100644
index 0000000..8c73811
--- /dev/null
+++ b/src/main/java/org/distorted/examples/postprocesstree/PostprocessTreeActivity.java
@@ -0,0 +1,102 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 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.examples.postprocesstree;
+
+import android.app.Activity;
+import android.opengl.GLSurfaceView;
+import android.os.Bundle;
+import android.widget.SeekBar;
+import android.widget.TextView;
+
+import org.distorted.examples.R;
+import org.distorted.library.main.Distorted;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class PostprocessTreeActivity extends Activity implements SeekBar.OnSeekBarChangeListener
+{
+    private TextView mText;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    @Override
+    protected void onCreate(Bundle savedState)
+      {
+      super.onCreate(savedState);
+      setContentView(R.layout.postprocesstreelayout);
+      mText = (TextView)findViewById(R.id.postprocesstreeText);
+      SeekBar bar = (SeekBar)findViewById(R.id.postprocesstreeSeek);
+      bar.setOnSeekBarChangeListener(this);
+      bar.setProgress(50);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    @Override
+    protected void onPause()
+      {
+      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.postprocesstreeSurfaceView);
+      view.onPause();
+      Distorted.onPause();
+      super.onPause();
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    @Override
+    protected void onResume()
+      {
+      super.onResume();
+      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.postprocesstreeSurfaceView);
+      view.onResume();
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    @Override
+    protected void onDestroy()
+      {
+      Distorted.onDestroy();
+      super.onDestroy();
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
+      {
+      PostprocessTreeSurfaceView view = (PostprocessTreeSurfaceView) this.findViewById(R.id.postprocesstreeSurfaceView);
+
+      switch (bar.getId())
+        {
+        case R.id.blurSeek: int level = view.getRenderer().setBlur(progress);
+                            mText.setText(getString(R.string.blur_placeholder,level));
+                            break;
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void onStartTrackingTouch(SeekBar bar) { }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public void onStopTrackingTouch(SeekBar bar)  { }
+
+}
diff --git a/src/main/java/org/distorted/examples/postprocesstree/PostprocessTreeRenderer.java b/src/main/java/org/distorted/examples/postprocesstree/PostprocessTreeRenderer.java
new file mode 100644
index 0000000..f15af07
--- /dev/null
+++ b/src/main/java/org/distorted/examples/postprocesstree/PostprocessTreeRenderer.java
@@ -0,0 +1,215 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 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.examples.postprocesstree;
+
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.opengl.GLSurfaceView;
+
+import org.distorted.examples.R;
+import org.distorted.library.effect.FragmentEffectChroma;
+import org.distorted.library.effect.MatrixEffectMove;
+import org.distorted.library.effect.MatrixEffectRotate;
+import org.distorted.library.effect.MatrixEffectScale;
+import org.distorted.library.effect.PostprocessEffectBlur;
+import org.distorted.library.main.Distorted;
+import org.distorted.library.main.DistortedEffects;
+import org.distorted.library.main.DistortedNode;
+import org.distorted.library.main.DistortedScreen;
+import org.distorted.library.main.DistortedTexture;
+import org.distorted.library.main.MeshFlat;
+import org.distorted.library.type.Dynamic1D;
+import org.distorted.library.type.Static1D;
+import org.distorted.library.type.Static3D;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class PostprocessTreeRenderer implements GLSurfaceView.Renderer
+{
+   private static final int LEAF_SIZE = 100;
+   private static final int NUM_LEAVES  = 8;
+   
+   private GLSurfaceView mView;
+   private DistortedTexture mLeaf;
+   private DistortedScreen mScreen;
+   private int mScreenW, mScreenH;
+   private Static3D mMove, mInnerScale, mOuterScale;
+   private Static1D mRadiusSta;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+   PostprocessTreeRenderer(GLSurfaceView v)
+      {     
+      mView = v;
+
+      mScreenW = 9*LEAF_SIZE;
+      mScreenH = 9*LEAF_SIZE;
+
+      mRadiusSta = new Static1D(5);
+      Dynamic1D radiusDyn = new Dynamic1D();
+      radiusDyn.add(mRadiusSta);
+
+      mLeaf = new DistortedTexture(LEAF_SIZE,LEAF_SIZE);
+
+      MeshFlat mesh = new MeshFlat(1,1);
+      mMove = new Static3D(0,0,0);
+
+      mInnerScale= new Static3D(1,1,1);
+      mOuterScale= new Static3D(1,1,1);
+
+      DistortedEffects rootEffects  = new DistortedEffects();
+      DistortedEffects innerEffects = new DistortedEffects();
+      DistortedEffects[] innerLeafEffects= new DistortedEffects[NUM_LEAVES];
+      DistortedEffects[] outerLeafEffects= new DistortedEffects[NUM_LEAVES];
+
+      DistortedNode root = new DistortedNode(new DistortedTexture(mScreenW,mScreenH), rootEffects, mesh);
+
+      DistortedNode[] innerLeafNodes = new DistortedNode[NUM_LEAVES];
+      DistortedNode[] outerLeafNodes = new DistortedNode[NUM_LEAVES];
+
+      rootEffects.apply(new MatrixEffectMove(mMove));
+      rootEffects.apply(new MatrixEffectScale(mOuterScale));
+
+      Dynamic1D rot = new Dynamic1D(5000,0.0f);
+      rot.setMode(Dynamic1D.MODE_JUMP);
+      rot.add(new Static1D(  0));
+      rot.add(new Static1D(360));
+
+      Static3D center = new Static3D(3*LEAF_SIZE/2, 3*LEAF_SIZE/2, 0);
+      Static3D axis   = new Static3D(0,0,1);
+      Static3D innerMoveVector = new Static3D(0,  LEAF_SIZE,0);
+      Static3D outerMoveVector = new Static3D(0,3*LEAF_SIZE,0);
+
+      for(int j=0; j<NUM_LEAVES; j++)
+        {
+        outerLeafEffects[j] = new DistortedEffects();
+        outerLeafEffects[j].apply( new MatrixEffectRotate(new Static1D(j*(360/NUM_LEAVES)), axis, center) );
+        outerLeafEffects[j].apply(new MatrixEffectMove(outerMoveVector));
+        outerLeafNodes[j] = new DistortedNode( mLeaf, outerLeafEffects[j], mesh);
+
+        root.attach(outerLeafNodes[j]);
+        }
+
+      innerEffects.apply( new MatrixEffectMove(new Static3D( mScreenW/2, mScreenH/2, 0)) );
+      innerEffects.apply( new MatrixEffectRotate(rot, axis, center) );
+      rootEffects.apply(new MatrixEffectScale(mInnerScale));
+      innerEffects.apply( new FragmentEffectChroma(new Static1D(0.5f), new Static3D(1,0,0) ) );
+
+      DistortedNode innerNode = new DistortedNode( new DistortedTexture(3*LEAF_SIZE,3*LEAF_SIZE), innerEffects, mesh);
+      root.attach(innerNode);
+
+      for(int j=0; j<NUM_LEAVES; j++)
+        {
+        innerLeafEffects[j] = new DistortedEffects();
+        innerLeafEffects[j].apply( new MatrixEffectRotate(new Static1D(j*(360/NUM_LEAVES)), axis, center) );
+        innerLeafEffects[j].apply(new MatrixEffectMove(innerMoveVector));
+        innerLeafNodes[j] = new DistortedNode( mLeaf, innerLeafEffects[j], mesh);
+
+        innerNode.attach(innerLeafNodes[j]);
+        }
+
+      mScreen = new DistortedScreen();
+      mScreen.attach(root);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+   int setBlur(int blur)
+     {
+     int radius = blur/2;
+     mRadiusSta.set(radius);
+     return radius;
+     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+   
+   public void onDrawFrame(GL10 glUnused)
+     {
+     mScreen.render(System.currentTimeMillis());
+     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+   public void onSurfaceChanged(GL10 glUnused, int width, int height)
+     {
+     float iFactor, oFactor;
+
+     if( (float)mScreenH/mScreenW > (float)height/width )
+       {
+       int w = (height*mScreenW)/mScreenH;
+       oFactor = (float)height/mScreenH;
+       iFactor = 0.3f*oFactor;
+       mMove.set((width-w)/2 ,0, 0);
+       }
+     else
+       {
+       int h = (width*mScreenH)/mScreenW;
+       oFactor = (float)width/mScreenW;
+       iFactor = 0.3f*oFactor;
+       mMove.set(0,(height-h)/2,0);
+       }
+
+     mOuterScale.set(oFactor,oFactor,oFactor);
+     mInnerScale.set(iFactor,iFactor,iFactor);
+
+     mScreen.resize(width, height);
+     }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
+     {
+     InputStream is = mView.getContext().getResources().openRawResource(R.raw.leaf);
+     Bitmap leaf;
+      
+     try
+       {
+       leaf = BitmapFactory.decodeStream(is);
+       }
+     finally
+       {
+       try
+         {
+         is.close();
+         }
+       catch(IOException e) { }
+       }
+      
+     mLeaf.setTexture(leaf);
+
+     FragmentEffectChroma.enable();
+     PostprocessEffectBlur.enable();
+
+     try
+       {
+       Distorted.onCreate(mView.getContext());
+       }
+     catch(Exception ex)
+       {
+       android.util.Log.e("PostprocessTree", ex.getMessage() );
+       }
+     }
+}
diff --git a/src/main/java/org/distorted/examples/postprocesstree/PostprocessTreeSurfaceView.java b/src/main/java/org/distorted/examples/postprocesstree/PostprocessTreeSurfaceView.java
new file mode 100644
index 0000000..21a776d
--- /dev/null
+++ b/src/main/java/org/distorted/examples/postprocesstree/PostprocessTreeSurfaceView.java
@@ -0,0 +1,57 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// Copyright 2016 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.examples.postprocesstree;
+
+import android.app.ActivityManager;
+import android.content.Context;
+import android.content.pm.ConfigurationInfo;
+import android.opengl.GLSurfaceView;
+import android.util.AttributeSet;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class PostprocessTreeSurfaceView extends GLSurfaceView
+{
+    private PostprocessTreeRenderer mRenderer;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+   
+    public PostprocessTreeSurfaceView(Context context, AttributeSet attrs)
+      {
+      super(context,attrs);
+
+      if(!isInEditMode())
+        {
+        mRenderer = new PostprocessTreeRenderer(this);
+        final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+        final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
+        setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
+        setRenderer(mRenderer);
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    PostprocessTreeRenderer getRenderer()
+      {
+      return mRenderer;
+      }
+}
+
diff --git a/src/main/res/layout/postprocesstreelayout.xml b/src/main/res/layout/postprocesstreelayout.xml
new file mode 100644
index 0000000..55a3440
--- /dev/null
+++ b/src/main/res/layout/postprocesstreelayout.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:orientation="vertical" >
+
+    <org.distorted.examples.postprocesstree.PostprocessTreeSurfaceView
+        android:id="@+id/postprocesstreeSurfaceView"
+        android:layout_width="fill_parent"
+        android:layout_height="0dp"
+        android:layout_weight="1" />
+
+    <LinearLayout
+        android:id="@+id/linearLayout1"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:gravity="center|fill_horizontal"
+        android:orientation="horizontal" >
+
+        <TextView
+                android:id="@+id/postprocesstreeText"
+                android:layout_width="150dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="0.5"
+                android:gravity="center_vertical|center"
+                android:text="@string/blur"
+                android:textAppearance="?android:attr/textAppearanceMedium" />
+
+        <SeekBar
+                android:id="@+id/postprocesstreeSeek"
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                android:paddingLeft="15dp"
+                android:paddingRight="10dp" />
+
+    </LinearLayout>
+
+</LinearLayout>
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index b503ba8..b48db72 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -157,6 +157,8 @@
     <string name="example_multiblur_subtitle">Blur multiple objects which obstruct each other.</string>
     <string name="example_triblur">Triblur</string>
     <string name="example_triblur_subtitle">Three different, blurred, obstructing objects.</string>
+    <string name="example_postprocesstree">Postprocess Tree</string>
+    <string name="example_postprocesstree_subtitle">Three layers of postprocessed surfaces.</string>
     <string name="example_stencil">Stencil Buffer</string>
     <string name="example_stencil_subtitle">Implement the classic stencil example from https://open.gl/depthstencils</string>
     <string name="example_glow">Glowing Leaf</string>
