commit 4782b4e6f7146c5a70bf7a51271b7aec63c9ae80
Author: Leszek Koltunski <leszek@distoretedandroid.org>
Date:   Tue May 2 16:22:31 2017 +0100

    Progress with moving the Transform Feedback functionality from the APP to the library.

diff --git a/src/main/java/org/distorted/library/Distorted.java b/src/main/java/org/distorted/library/Distorted.java
index eed6354..036507f 100644
--- a/src/main/java/org/distorted/library/Distorted.java
+++ b/src/main/java/org/distorted/library/Distorted.java
@@ -31,8 +31,8 @@ import org.distorted.library.program.*;
  */
 public class Distorted 
   {
-  static int GLSL;
-  static String GLSL_VERSION;
+  public static int GLSL;
+  public static String GLSL_VERSION;
 
   /**
    * When creating an instance of a DistortedTexture from another instance, clone the Bitmap that's
diff --git a/src/main/java/org/distorted/library/program/DistortedProgram.java b/src/main/java/org/distorted/library/program/DistortedProgram.java
index 825f56d..76d16a9 100644
--- a/src/main/java/org/distorted/library/program/DistortedProgram.java
+++ b/src/main/java/org/distorted/library/program/DistortedProgram.java
@@ -46,7 +46,7 @@ public class DistortedProgram
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-  private int createAndLinkProgram(final int vertexShaderHandle, final int fragmentShaderHandle, final String[] attributes)
+  private int createAndLinkProgram(final int vertexShaderHandle, final int fragmentShaderHandle, final String[] attributes, final String[] feedbackVaryings)
   throws LinkingException
     {
     int programHandle = GLES30.glCreateProgram();
@@ -56,6 +56,11 @@ public class DistortedProgram
       GLES30.glAttachShader(programHandle, vertexShaderHandle);
       GLES30.glAttachShader(programHandle, fragmentShaderHandle);
 
+      if( feedbackVaryings!=null )
+        {
+        GLES30.glTransformFeedbackVaryings(programHandle, feedbackVaryings, GLES30.GL_INTERLEAVED_ATTRIBS);
+        }
+
       if (attributes != null)
         {
         final int size = attributes.length;
@@ -246,23 +251,10 @@ public class DistortedProgram
     }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
-// PUBLIC API
-///////////////////////////////////////////////////////////////////////////////////////////////////
-  /**
-   * Create a new Shader Program from source stored in resource files.
-   * <p>
-   * Needs to be called from a thread holding the OpenGL context.
-   *
-   * @param vertex   InputStream containing the opened Resource file from where to read vertex shader code.
-   * @param fragment InputStream containing the opened Resource file from where to read fragment shader code.
-   * @throws FragmentCompilationException
-   * @throws VertexCompilationException
-   * @throws VertexUniformsException
-   * @throws FragmentUniformsException
-   * @throws LinkingException
-   */
+// feedback: List of 'out' variables (OpenGL ES >= 3.0 only!) that will be transferred back to CPU
+// using Transform Feedback.
 
-  public DistortedProgram(final InputStream vertex, final InputStream fragment, final String vertexHeader, final String fragmentHeader, int glslVersion)
+  public DistortedProgram(final InputStream vertex, final InputStream fragment, final String vertexHeader, final String fragmentHeader, int glslVersion, final String[] feedback )
   throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
     {
     mAttributeStr = (glslVersion == 100 ? "attribute " : "in ");
@@ -278,7 +270,7 @@ public class DistortedProgram
     final int vertexShaderHandle   = compileShader(GLES30.GL_VERTEX_SHADER  , vertexHeader   + vertexShader  );
     final int fragmentShaderHandle = compileShader(GLES30.GL_FRAGMENT_SHADER, fragmentHeader + fragmentShader);
 
-    mProgramHandle = createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, mAttributeName);
+    mProgramHandle = createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, mAttributeName, feedback);
 
     mAttribute = new int[mNumAttributes];
 
@@ -288,6 +280,29 @@ public class DistortedProgram
       }
     }
 
+///////////////////////////////////////////////////////////////////////////////////////////////////
+// PUBLIC API
+///////////////////////////////////////////////////////////////////////////////////////////////////
+  /**
+   * Create a new Shader Program from source stored in resource files.
+   * <p>
+   * Needs to be called from a thread holding the OpenGL context.
+   *
+   * @param vertex   InputStream containing the opened Resource file from where to read vertex shader code.
+   * @param fragment InputStream containing the opened Resource file from where to read fragment shader code.
+   * @throws FragmentCompilationException
+   * @throws VertexCompilationException
+   * @throws VertexUniformsException
+   * @throws FragmentUniformsException
+   * @throws LinkingException
+   */
+
+  public DistortedProgram(final InputStream vertex, final InputStream fragment, final String vertexHeader, final String fragmentHeader, int glslVersion )
+  throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
+    {
+    this(vertex,fragment,vertexHeader,fragmentHeader,glslVersion,null);
+    }
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 /**
  * Return the handle of the created program so that we can later, say, call glUseProgram.
diff --git a/src/main/res/raw/feedback_fragment_shader.glsl b/src/main/res/raw/feedback_fragment_shader.glsl
new file mode 100644
index 0000000..2f068f6
--- /dev/null
+++ b/src/main/res/raw/feedback_fragment_shader.glsl
@@ -0,0 +1,34 @@
+//////////////////////////////////////////////////////////////////////////////////////////////
+// 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/>.                       //
+//////////////////////////////////////////////////////////////////////////////////////////////
+
+precision mediump float;
+
+#if __VERSION__ != 100
+out vec4 fragColor;           // The output color
+#define FRAG_COLOR fragColor
+#else
+#define FRAG_COLOR gl_FragColor
+#endif
+
+//////////////////////////////////////////////////////////////////////////////////////////////
+
+void main()                    		
+  {
+  FRAG_COLOR = vec4(1.0,1.0,1.0,1.0);
+  }
\ No newline at end of file
diff --git a/src/main/res/raw/feedback_vertex_shader.glsl b/src/main/res/raw/feedback_vertex_shader.glsl
new file mode 100644
index 0000000..8482e63
--- /dev/null
+++ b/src/main/res/raw/feedback_vertex_shader.glsl
@@ -0,0 +1,35 @@
+//////////////////////////////////////////////////////////////////////////////////////////////
+// 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/>.                       //
+//////////////////////////////////////////////////////////////////////////////////////////////
+
+precision lowp float;
+
+#if __VERSION__ != 100
+in float inValue;
+out float outValue;
+#else
+attribute float inValue;
+varying float outValue;
+#endif
+
+//////////////////////////////////////////////////////////////////////////////////////////////
+
+void main()
+  {
+  outValue = sqrt(inValue);
+  }
