Project

General

Profile

« Previous | Next » 

Revision bbf09f75

Added by Leszek Koltunski over 7 years ago

Progress with TransferFeedback app - introduce two modes: USEPOINTS 'true' or 'false'.

On Nexus5X, it works with 'true' and 'false'. On Nexus 4, it works with 'true', but returns GL_INVALID_OPERATION with 'false'.

View differences:

src/main/java/org/distorted/examples/feedback/FeedbackRenderer.java
22 22
import android.content.res.Resources;
23 23
import android.opengl.GLES30;
24 24
import android.opengl.GLSurfaceView;
25
import android.util.Log;
26 25

  
27 26
import org.distorted.library.Distorted;
28 27
import org.distorted.library.program.DistortedProgram;
......
41 40
class FeedbackRenderer implements GLSurfaceView.Renderer
42 41
{
43 42
    private final int BYTESFLOAT = 4;
43
    private final int POSITION   = 3;
44

  
45
    private final boolean USEPOINTS=false;
44 46

  
45 47
    private GLSurfaceView mView;
46 48
    private DistortedProgram mFeedbackProgram;
47
    private int mBufferLength;
49
    private int mVertices;
48 50
    private int[] mVBO, mTBO;
49 51

  
50 52
///////////////////////////////////////////////////////////////////////////////////////////////////
......
60 62
      {
61 63
      mFeedbackProgram.useProgram();
62 64

  
65
      int numVertices = (USEPOINTS ? mVertices : 3*(mVertices-2));
66

  
63 67
      GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mVBO[0]);
64
      GLES30.glVertexAttribPointer(mFeedbackProgram.mAttribute[0], 1, GLES30.GL_FLOAT, false, 0, 0);
68
      GLES30.glVertexAttribPointer(mFeedbackProgram.mAttribute[0], USEPOINTS ? 1:POSITION, GLES30.GL_FLOAT, false, 0, 0);
65 69
      GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, mTBO[0]);
66 70

  
67 71
      GLES30.glEnable(GLES30.GL_RASTERIZER_DISCARD);
68
      GLES30.glBeginTransformFeedback(GLES30.GL_POINTS);
69
      GLES30.glDrawArrays(GLES30.GL_POINTS, 0, mBufferLength);
72
      GLES30.glBeginTransformFeedback( USEPOINTS ? GLES30.GL_POINTS : GLES30.GL_TRIANGLES);
73
      GLES30.glDrawArrays( USEPOINTS ? GLES30.GL_POINTS : GLES30.GL_TRIANGLE_STRIP, 0, USEPOINTS ? mVertices*POSITION : mVertices);
70 74
      GLES30.glEndTransformFeedback();
71 75
      GLES30.glDisable(GLES30.GL_RASTERIZER_DISCARD);
72 76
      GLES30.glFlush();
73 77

  
74
      Buffer mappedBuffer =  GLES30.glMapBufferRange(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, mBufferLength*BYTESFLOAT, GLES30.GL_MAP_READ_BIT);
78
      Buffer mappedBuffer =  GLES30.glMapBufferRange(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, numVertices*POSITION*BYTESFLOAT, GLES30.GL_MAP_READ_BIT);
79
      FloatBuffer fb = ((ByteBuffer) mappedBuffer).order(ByteOrder.nativeOrder()).asFloatBuffer();
80
      String msg = "";
75 81

  
76
      if (mappedBuffer!=null)
77
        {
78
        FloatBuffer fb = ((ByteBuffer) mappedBuffer).order(ByteOrder.nativeOrder()).asFloatBuffer();
79
        Log.d( "Feedback", String.format("values = %.2f %.2f %.2f %.2f %.2f %.2f\n",  fb.get(), fb.get(), fb.get(), fb.get(), fb.get(), fb.get() ));
80
        }
82
      for(int i=0; i<numVertices*POSITION; i++) msg += (" "+fb.get(i));
83

  
84
      android.util.Log.d( "Feedback", msg);
81 85

  
82 86
      GLES30.glUnmapBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER);
83 87
      GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
......
111 115
      String header= "#version 300 es\n";
112 116
      String[] feedback = { "outValue" };
113 117

  
118
      if(USEPOINTS)
119
        {
120
        header += "#define USEPOINTS 1\n";
121
        }
122
      else
123
        {
124
        header += "#define USEPOINTS 0\n";
125
        }
126

  
114 127
      try
115 128
        {
116 129
        mFeedbackProgram = new DistortedProgram(vertStream,fragStream, header, header, glsl, feedback );
117 130
        }
118 131
      catch(Exception ex)
119 132
        {
120
        Log.e("TransformFeedback", "exception creating feedback program: "+ex.getMessage());
133
        android.util.Log.e("Feedback", "exception creating feedback program: "+ex.getMessage());
121 134
        }
122 135

  
123
      float[] floatData = { 1.0f, 4.0f, 9.0f, 16.0f, 25.0f, 100.0f };
124
      mBufferLength = floatData.length;
125
      FloatBuffer data = ByteBuffer.allocateDirect(mBufferLength*BYTESFLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
136
      float[] floatData = { 1.0f,4.0f,9.0f, 16.0f,25.0f,36.0f, 49.0f,64.0f,81.0f,  100.0f,121.0f,144.0f};
137
      mVertices = floatData.length/POSITION;
138
      FloatBuffer data = ByteBuffer.allocateDirect(mVertices*POSITION*BYTESFLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
126 139
      data.put(floatData).position(0);
127 140

  
128 141
      mVBO = new int[1];
129 142
      GLES30.glGenBuffers(1, mVBO, 0);
130 143
      GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mVBO[0]);
131
      GLES30.glBufferData(GLES30.GL_ARRAY_BUFFER, mBufferLength*BYTESFLOAT, data, GLES30.GL_STATIC_READ);
144
      GLES30.glBufferData(GLES30.GL_ARRAY_BUFFER, mVertices*POSITION*BYTESFLOAT, data, GLES30.GL_STATIC_READ);
132 145
      GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
133 146

  
147
      int numVertices = (USEPOINTS ? mVertices : 3*(mVertices-2));
148

  
134 149
      mTBO = new int[1];
135 150
      GLES30.glGenBuffers(1, mTBO, 0);
136 151
      GLES30.glBindBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, mTBO[0]);
137
      GLES30.glBufferData(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, mBufferLength*BYTESFLOAT, null, GLES30.GL_STATIC_READ);
152
      GLES30.glBufferData(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, numVertices*POSITION*BYTESFLOAT, null, GLES30.GL_STATIC_READ);
138 153
      GLES30.glBindBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0);
139 154
      }
140 155
}
src/main/java/org/distorted/examples/monalisa/MonaLisaRenderer.java
137 137
      if( mTexture==null ) mTexture = new DistortedTexture(bmpWidth,bmpHeight);
138 138

  
139 139
      // likewise the Mesh
140
      if( mMesh==null ) mMesh = new MeshFlat(1,1);//(9,9*bmpHeight/bmpWidth);
140
      if( mMesh==null ) mMesh = new MeshFlat(2,2);//(9,9*bmpHeight/bmpWidth);
141 141

  
142 142
      // even if mTexture wasn't null, we still need to call setTexture() on it
143 143
      // because every time activity goes to background, its OpenGL resources

Also available in: Unified diff