Project

General

Profile

« Previous | Next » 

Revision 4782b4e6

Added by Leszek Koltunski about 7 years ago

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

View differences:

src/main/java/org/distorted/library/Distorted.java
31 31
 */
32 32
public class Distorted 
33 33
  {
34
  static int GLSL;
35
  static String GLSL_VERSION;
34
  public static int GLSL;
35
  public static String GLSL_VERSION;
36 36

  
37 37
  /**
38 38
   * When creating an instance of a DistortedTexture from another instance, clone the Bitmap that's
src/main/java/org/distorted/library/program/DistortedProgram.java
46 46

  
47 47
///////////////////////////////////////////////////////////////////////////////////////////////////
48 48

  
49
  private int createAndLinkProgram(final int vertexShaderHandle, final int fragmentShaderHandle, final String[] attributes)
49
  private int createAndLinkProgram(final int vertexShaderHandle, final int fragmentShaderHandle, final String[] attributes, final String[] feedbackVaryings)
50 50
  throws LinkingException
51 51
    {
52 52
    int programHandle = GLES30.glCreateProgram();
......
56 56
      GLES30.glAttachShader(programHandle, vertexShaderHandle);
57 57
      GLES30.glAttachShader(programHandle, fragmentShaderHandle);
58 58

  
59
      if( feedbackVaryings!=null )
60
        {
61
        GLES30.glTransformFeedbackVaryings(programHandle, feedbackVaryings, GLES30.GL_INTERLEAVED_ATTRIBS);
62
        }
63

  
59 64
      if (attributes != null)
60 65
        {
61 66
        final int size = attributes.length;
......
246 251
    }
247 252

  
248 253
///////////////////////////////////////////////////////////////////////////////////////////////////
249
// PUBLIC API
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251
  /**
252
   * Create a new Shader Program from source stored in resource files.
253
   * <p>
254
   * Needs to be called from a thread holding the OpenGL context.
255
   *
256
   * @param vertex   InputStream containing the opened Resource file from where to read vertex shader code.
257
   * @param fragment InputStream containing the opened Resource file from where to read fragment shader code.
258
   * @throws FragmentCompilationException
259
   * @throws VertexCompilationException
260
   * @throws VertexUniformsException
261
   * @throws FragmentUniformsException
262
   * @throws LinkingException
263
   */
254
// feedback: List of 'out' variables (OpenGL ES >= 3.0 only!) that will be transferred back to CPU
255
// using Transform Feedback.
264 256

  
265
  public DistortedProgram(final InputStream vertex, final InputStream fragment, final String vertexHeader, final String fragmentHeader, int glslVersion)
257
  public DistortedProgram(final InputStream vertex, final InputStream fragment, final String vertexHeader, final String fragmentHeader, int glslVersion, final String[] feedback )
266 258
  throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
267 259
    {
268 260
    mAttributeStr = (glslVersion == 100 ? "attribute " : "in ");
......
278 270
    final int vertexShaderHandle   = compileShader(GLES30.GL_VERTEX_SHADER  , vertexHeader   + vertexShader  );
279 271
    final int fragmentShaderHandle = compileShader(GLES30.GL_FRAGMENT_SHADER, fragmentHeader + fragmentShader);
280 272

  
281
    mProgramHandle = createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, mAttributeName);
273
    mProgramHandle = createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, mAttributeName, feedback);
282 274

  
283 275
    mAttribute = new int[mNumAttributes];
284 276

  
......
288 280
      }
289 281
    }
290 282

  
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284
// PUBLIC API
285
///////////////////////////////////////////////////////////////////////////////////////////////////
286
  /**
287
   * Create a new Shader Program from source stored in resource files.
288
   * <p>
289
   * Needs to be called from a thread holding the OpenGL context.
290
   *
291
   * @param vertex   InputStream containing the opened Resource file from where to read vertex shader code.
292
   * @param fragment InputStream containing the opened Resource file from where to read fragment shader code.
293
   * @throws FragmentCompilationException
294
   * @throws VertexCompilationException
295
   * @throws VertexUniformsException
296
   * @throws FragmentUniformsException
297
   * @throws LinkingException
298
   */
299

  
300
  public DistortedProgram(final InputStream vertex, final InputStream fragment, final String vertexHeader, final String fragmentHeader, int glslVersion )
301
  throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
302
    {
303
    this(vertex,fragment,vertexHeader,fragmentHeader,glslVersion,null);
304
    }
305

  
291 306
///////////////////////////////////////////////////////////////////////////////////////////////////
292 307
/**
293 308
 * Return the handle of the created program so that we can later, say, call glUseProgram.
src/main/res/raw/feedback_fragment_shader.glsl
1
//////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                          //
3
//                                                                                          //
4
// This file is part of Distorted.                                                          //
5
//                                                                                          //
6
// Distorted is free software: you can redistribute it and/or modify                        //
7
// it under the terms of the GNU General Public License as published by                     //
8
// the Free Software Foundation, either version 2 of the License, or                        //
9
// (at your option) any later version.                                                      //
10
//                                                                                          //
11
// Distorted is distributed in the hope that it will be useful,                             //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                           //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                            //
14
// GNU General Public License for more details.                                             //
15
//                                                                                          //
16
// You should have received a copy of the GNU General Public License                        //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                       //
18
//////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
precision mediump float;
21

  
22
#if __VERSION__ != 100
23
out vec4 fragColor;           // The output color
24
#define FRAG_COLOR fragColor
25
#else
26
#define FRAG_COLOR gl_FragColor
27
#endif
28

  
29
//////////////////////////////////////////////////////////////////////////////////////////////
30

  
31
void main()                    		
32
  {
33
  FRAG_COLOR = vec4(1.0,1.0,1.0,1.0);
34
  }
src/main/res/raw/feedback_vertex_shader.glsl
1
//////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                          //
3
//                                                                                          //
4
// This file is part of Distorted.                                                          //
5
//                                                                                          //
6
// Distorted is free software: you can redistribute it and/or modify                        //
7
// it under the terms of the GNU General Public License as published by                     //
8
// the Free Software Foundation, either version 2 of the License, or                        //
9
// (at your option) any later version.                                                      //
10
//                                                                                          //
11
// Distorted is distributed in the hope that it will be useful,                             //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                           //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                            //
14
// GNU General Public License for more details.                                             //
15
//                                                                                          //
16
// You should have received a copy of the GNU General Public License                        // 
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                       //
18
//////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
precision lowp float;
21

  
22
#if __VERSION__ != 100
23
in float inValue;
24
out float outValue;
25
#else
26
attribute float inValue;
27
varying float outValue;
28
#endif
29

  
30
//////////////////////////////////////////////////////////////////////////////////////////////
31

  
32
void main()
33
  {
34
  outValue = sqrt(inValue);
35
  }

Also available in: Unified diff