commit baa47ae9cff61bc68a41358ff80263460468e140
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Tue May 2 15:12:10 2017 +0100

    Transform Feedback Example.

diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index b0afc56..1ce435b 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -45,5 +45,6 @@
         <activity android:name=".mirror.MirrorActivity"/>
         <activity android:name=".blur.BlurActivity"/>
         <activity android:name=".multiblur.MultiblurActivity"/>
+        <activity android:name=".feedback.FeedbackActivity"/>
     </application>
 </manifest>
diff --git a/src/main/java/org/distorted/examples/TableOfContents.java b/src/main/java/org/distorted/examples/TableOfContents.java
index 9012fd8..589c6f4 100644
--- a/src/main/java/org/distorted/examples/TableOfContents.java
+++ b/src/main/java/org/distorted/examples/TableOfContents.java
@@ -63,6 +63,7 @@ import org.distorted.examples.wind.WindActivity;
 import org.distorted.examples.mirror.MirrorActivity;
 import org.distorted.examples.blur.BlurActivity;
 import org.distorted.examples.multiblur.MultiblurActivity;
+import org.distorted.examples.feedback.FeedbackActivity;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
@@ -346,6 +347,15 @@ public class TableOfContents extends ListActivity
       activityMapping.put(i++, MultiblurActivity.class);
    }
 
+   {
+      final Map<String, Object> item = new HashMap<>();
+      item.put(ITEM_IMAGE, R.drawable.icon_example_feedback);
+      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_feedback));
+      item.put(ITEM_SUBTITLE, getText(R.string.example_feedback_subtitle));
+      data.add(item);
+      activityMapping.put(i++, FeedbackActivity.class);
+   }
+
    final SimpleAdapter dataAdapter = new SimpleAdapter(this, data, R.layout.toc_item, new String[] {ITEM_IMAGE, ITEM_TITLE, ITEM_SUBTITLE}, new int[] {R.id.Image, R.id.Title, R.id.SubTitle});
    setListAdapter(dataAdapter);  
       
diff --git a/src/main/java/org/distorted/examples/feedback/FeedbackActivity.java b/src/main/java/org/distorted/examples/feedback/FeedbackActivity.java
new file mode 100644
index 0000000..23003b8
--- /dev/null
+++ b/src/main/java/org/distorted/examples/feedback/FeedbackActivity.java
@@ -0,0 +1,69 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// 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.feedback;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+import org.distorted.library.Distorted;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+public class FeedbackActivity extends Activity
+{
+    private FeedbackSurfaceView mView;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    @Override
+    protected void onCreate(Bundle icicle)
+      {
+      super.onCreate(icicle);
+      mView = new FeedbackSurfaceView(this);
+      setContentView(mView);
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override
+    protected void onPause() 
+      {
+      mView.onPause();
+      super.onPause();
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override
+    protected void onResume() 
+      {
+      super.onResume();
+      mView.onResume();
+      }
+    
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    @Override
+    protected void onDestroy() 
+      {
+      super.onDestroy();
+      }
+    
+}
diff --git a/src/main/java/org/distorted/examples/feedback/FeedbackRenderer.java b/src/main/java/org/distorted/examples/feedback/FeedbackRenderer.java
new file mode 100644
index 0000000..f72ecef
--- /dev/null
+++ b/src/main/java/org/distorted/examples/feedback/FeedbackRenderer.java
@@ -0,0 +1,60 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// 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.feedback;
+
+import android.opengl.GLSurfaceView;
+
+import javax.microedition.khronos.egl.EGLConfig;
+import javax.microedition.khronos.opengles.GL10;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class FeedbackRenderer implements GLSurfaceView.Renderer
+{
+
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    FeedbackRenderer(GLSurfaceView v)
+      {
+
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+   
+    public void onDrawFrame(GL10 glUnused) 
+      {
+      TransformFeedback tf = new TransformFeedback();
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
+      { 
+
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+    
+    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
+      {
+
+      }
+}
diff --git a/src/main/java/org/distorted/examples/feedback/FeedbackSurfaceView.java b/src/main/java/org/distorted/examples/feedback/FeedbackSurfaceView.java
new file mode 100644
index 0000000..ee059c4
--- /dev/null
+++ b/src/main/java/org/distorted/examples/feedback/FeedbackSurfaceView.java
@@ -0,0 +1,42 @@
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// 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.feedback;
+
+import android.app.ActivityManager;
+import android.content.Context;
+import android.content.pm.ConfigurationInfo;
+import android.opengl.GLSurfaceView;
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+class FeedbackSurfaceView extends GLSurfaceView
+{
+///////////////////////////////////////////////////////////////////////////////////////////////////
+   
+    public FeedbackSurfaceView(Context context)
+      {
+      super(context);
+      final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+      final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
+      setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
+      setRenderer(new FeedbackRenderer(this));
+      }
+}
+
diff --git a/src/main/java/org/distorted/examples/feedback/TransformFeedback.java b/src/main/java/org/distorted/examples/feedback/TransformFeedback.java
new file mode 100644
index 0000000..23f36e8
--- /dev/null
+++ b/src/main/java/org/distorted/examples/feedback/TransformFeedback.java
@@ -0,0 +1,198 @@
+package org.distorted.examples.feedback;
+
+import android.opengl.EGL14;
+import android.opengl.GLES30;
+import android.util.Log;
+
+import java.nio.Buffer;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+
+/**
+ * Created by izzy on 6/24/15. TransformFeedback is a example of how
+ *  to do transform feedback on Android using OpenGLES 3.0. Closely
+ *  follows the example found at https://open.gl/feedback.
+ *
+ * Assumes you have a working instance of GLSurfaceVew. Remember to call
+ *  setEGLContextClientVersion(3) to set the OpenGLES context to API 3.0
+ *  and have the appropriate OpenGLES specified in the Android manifest file.
+ */
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+public class TransformFeedback {
+    private final String TAG = "TransformFeedback";
+
+
+// Vertex shader
+    private final String vertexShaderSrc =
+            "#version 300 es \n" +
+            "in float inValue;\n" +
+            "out float outValue;\n" +
+
+            "void main() {\n" +
+            "    outValue = sqrt(inValue);\n" +
+            "}";
+
+// Need a fragmentShader or glLinkProgram will throw
+    private final String fragmentShaderCode =
+            "#version 300 es \n" +
+            "precision mediump float;\n" +
+            "out vec4 fragColor;\n" +
+            "void main() {\n" +
+            "  fragColor = vec4(1.0,1.0,1.0,1.0);\n" +
+            "}";
+
+    private final int mProgram;
+
+    /**
+     * The TransformFeedback constructor contains all the code to initialize
+     *  and draw the TransformFeedback, so create an instance of TransformFeedback
+     *  i.e. 'new TransformFeedBack()' in your 'GLRenderer.OnDrawFrame()' method.
+     */
+    public TransformFeedback(){
+
+        // Compile shaders
+        int vertexShader   = loadShader(GLES30.GL_VERTEX_SHADER  , vertexShaderSrc   );
+        int fragmentShader = loadShader(GLES30.GL_FRAGMENT_SHADER, fragmentShaderCode);
+
+        // Create program and attach shaders
+        mProgram = GLES30.glCreateProgram();
+        GLES30.glAttachShader(mProgram, vertexShader);
+        GLES30.glAttachShader(mProgram, fragmentShader);
+
+        // Tell GL where the feedbackVaryings are in the shader before Linking
+        //  the shaders together to form a program.
+        final String[] feedbackVaryings = { "outValue" };
+        GLES30.glTransformFeedbackVaryings(mProgram, feedbackVaryings, GLES30.GL_INTERLEAVED_ATTRIBS);
+        checkGlError(TAG + " glTransformFeedbackVaryings");
+
+        // Link program and look for errors
+        GLES30.glLinkProgram(mProgram);
+
+        int[] linkSuccessful = new int[1];
+        GLES30.glGetProgramiv(mProgram, GLES30.GL_LINK_STATUS, linkSuccessful, 0);
+
+        if (linkSuccessful[0] != 1){
+            Log.d(TAG, "glLinkProgram failed");
+        }
+        checkGlError(TAG + " glLinkProgram");
+
+        /***********
+         * Begin Rendering process
+         *  everything before this can be moved to an initialization stage
+         ***********/
+
+        // Bring the program into use
+        GLES30.glUseProgram(mProgram);
+        checkGlError(TAG + " glUseProgram");
+
+        // Create data to fill VBO
+        float[] floatData = { 1.0f, 4.0f, 9.0f, 16.0f, 25.0f, 100.0f };
+        int bufferLength = floatData.length * 4;
+        FloatBuffer data = ByteBuffer.allocateDirect(bufferLength)
+                .order(ByteOrder.nativeOrder()).asFloatBuffer();
+        data.put(floatData).position(0);
+
+        // Create VBO and fill with data
+        int[] vbo = new int[1];
+        GLES30.glGenBuffers(1, vbo, 0);
+        GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, vbo[0]);
+        GLES30.glBufferData(GLES30.GL_ARRAY_BUFFER, bufferLength, data, GLES30.GL_STATIC_READ);
+        checkGlError(TAG + " glBufferData GL_ARRAY_BUFFER");
+
+        // Link created VBO to shader attribute "inValue"
+        int inputAttrib = GLES30.glGetAttribLocation(mProgram, "inValue");
+        GLES30.glEnableVertexAttribArray(inputAttrib);
+        GLES30.glVertexAttribPointer(inputAttrib, 1, GLES30.GL_FLOAT, false, 4, 0);
+        checkGlError(TAG + " glVertexAttribPointer");
+
+        // Create transform feedback buffer object and bind to transform feedback
+        //  this creates space in a buffer object for the TransformFeedback.
+        int[] tbo = new int[1];
+        GLES30.glGenBuffers(1, tbo, 0);
+        GLES30.glBindBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, tbo[0]);
+        GLES30.glBufferData(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, bufferLength, null, GLES30.GL_STATIC_READ);
+        GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, tbo[0]); //very important
+
+        checkGlError(TAG + " glBindBufferBase");
+
+        // Disable Rasterizer if you just need the data
+        GLES30.glEnable(GLES30.GL_RASTERIZER_DISCARD);
+
+        // Start the TransformFeedback, Draw the Arrays, then End the Transform Feedback
+        GLES30.glBeginTransformFeedback(GLES30.GL_POINTS);
+        GLES30.glDrawArrays(GLES30.GL_POINTS, 0, bufferLength);
+        checkGlError(TAG + " glDrawArrays");
+        GLES30.glEndTransformFeedback();
+
+        // Reenable Rasterizer if you need it, which you do if you are drawing anything.
+        GLES30.glDisable(GLES30.GL_RASTERIZER_DISCARD);
+
+        // Flush out anything in GL before mapping the buffer.
+        GLES30.glFlush();
+        checkGlError(TAG + " pre-glMapBufferRange ");
+
+        // Map the transform feedback buffer to local address space.
+        Buffer mappedBuffer =  GLES30.glMapBufferRange(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER,
+                0, bufferLength, GLES30.GL_MAP_READ_BIT);
+        checkGlError(TAG + " glMapBufferRange");
+
+        // Read out the data, here we write to logcat.
+        if (mappedBuffer!=null){
+            ByteBuffer bb = ((ByteBuffer) mappedBuffer);
+            bb.order(ByteOrder.nativeOrder());
+            FloatBuffer transformedData = bb.asFloatBuffer();
+
+            Log.d(TAG, String.format("output values = %f %f %f %f %f %f\n",
+                    transformedData.get(), transformedData.get(), transformedData.get(),
+                    transformedData.get(), transformedData.get(), transformedData.get() ));
+        }
+        // Don't forget to Unmap the Transform Feeback Buffer.
+        GLES30.glUnmapBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER);
+    }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private static void checkGlError(String op)
+      {
+      int error = GLES30.glGetError();
+
+      if (error != GLES30.GL_NO_ERROR)
+        {
+        String msg = op + ": glError 0x" + Integer.toHexString(error);
+        throw new RuntimeException(msg);
+        }
+      }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+    private static int loadShader(final int shaderType, final String shaderSource)
+      {
+      int shaderHandle = GLES30.glCreateShader(shaderType);
+
+      if (shaderHandle != 0)
+        {
+        GLES30.glShaderSource(shaderHandle, shaderSource);
+        GLES30.glCompileShader(shaderHandle);
+        final int[] compileStatus = new int[1];
+        GLES30.glGetShaderiv(shaderHandle, GLES30.GL_COMPILE_STATUS, compileStatus, 0);
+
+        if (compileStatus[0] != GLES30.GL_TRUE )
+          {
+          GLES30.glDeleteShader(shaderHandle);
+          shaderHandle = 0;
+          }
+        }
+
+      if (shaderHandle == 0)
+        {
+        String error = GLES30.glGetShaderInfoLog(shaderHandle);
+        android.util.Log.e("Program", "error compiling :"+error);
+        }
+
+      return shaderHandle;
+      }
+}
diff --git a/src/main/res/drawable-hdpi/icon_example_feedback.png b/src/main/res/drawable-hdpi/icon_example_feedback.png
new file mode 100644
index 0000000..3d73dbc
Binary files /dev/null and b/src/main/res/drawable-hdpi/icon_example_feedback.png differ
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index e5d2d12..31c2d17 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -138,6 +138,8 @@
     <string name="example_blur_subtitle">Postprocessing effect: Blur.</string>
     <string name="example_multiblur">Multiblur</string>
     <string name="example_multiblur_subtitle">Blur multiple objects which obstruct each other.</string>
+    <string name="example_feedback">Transform Feedback</string>
+    <string name="example_feedback_subtitle">Transform Feedback test.</string>
 
     <string name="example_movingeffects_toast">Click on \'RESET\' and define your path by touching the screen. Then click on one of the effects and see it move along your path.</string>
     <string name="example_rotate_toast">Rotate the scene by swiping the screen</string>
