Project

General

Profile

« Previous | Next » 

Revision fa8bc998

Added by Leszek Koltunski about 4 years ago

New API MeshBase.apply(MatrixEffect[])

View differences:

src/main/java/org/distorted/library/mesh/MeshBase.java
21 21

  
22 22
import android.opengl.GLES31;
23 23

  
24
import org.distorted.library.effect.MatrixEffect;
24 25
import org.distorted.library.main.DistortedLibrary;
25 26
import org.distorted.library.main.InternalBuffer;
26 27
import org.distorted.library.program.DistortedProgram;
......
60 61
   private static final int TRAN_SIZE  = TRAN_ATTRIBS*BYTES_PER_FLOAT;
61 62
   private static final int VERT_SIZE  = VERT_ATTRIBS*BYTES_PER_FLOAT;
62 63

  
63
   private boolean mShowNormals;       // when rendering this mesh, draw normal vectors?
64
   private InternalBuffer mVBO, mTFO;  // main vertex buffer and transform feedback buffer
65
   private final float zFactor;        // strange workaround for the fact that we need to somehow store the 'depth'
66
                                       // of the Mesh. Used in DistortedEffects. See DistortedTexture.getDepth().
64
   private boolean mShowNormals;      // when rendering this mesh, draw normal vectors?
65
   private InternalBuffer mVBO, mTFO; // main vertex buffer and transform feedback buffer
66
   private final float zFactor;       // strange workaround for the fact that we need to somehow store the 'depth'
67
                                      // of the Mesh. Used in DistortedEffects. See DistortedTexture.getDepth().
67 68
   private int mNumVertices;
68
   private FloatBuffer mVertAttribs;   // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ, TexS,TexT
69
   private float[] mVertAttribs;      // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ, TexS,TexT
69 70
   private float mInflate;
70 71

  
71 72
///////////////////////////////////////////////////////////////////////////////////////////////////
......
85 86
   void setAttribs(float[] vertexAttribs)
86 87
     {
87 88
     mNumVertices = vertexAttribs.length/VERT_ATTRIBS;
89
     mVertAttribs = vertexAttribs;
88 90

  
89
     mVertAttribs = ByteBuffer.allocateDirect(mNumVertices*VERT_SIZE).order(ByteOrder.nativeOrder()).asFloatBuffer();
90
     mVertAttribs.put(vertexAttribs).position(0);
91
     FloatBuffer attribs = ByteBuffer.allocateDirect(mNumVertices*VERT_SIZE).order(ByteOrder.nativeOrder()).asFloatBuffer();
92
     attribs.put(vertexAttribs).position(0);
91 93

  
92
     mVBO.setData(mNumVertices*VERT_SIZE, mVertAttribs);
93
     mTFO.setData(mNumVertices*TRAN_SIZE, null        );
94
     mVBO.setData(mNumVertices*VERT_SIZE, attribs);
95
     mTFO.setData(mNumVertices*TRAN_SIZE, null   );
94 96
     }
95 97

  
96 98
///////////////////////////////////////////////////////////////////////////////////////////////////
......
209 211
 */
210 212
   public void markForDeletion()
211 213
     {
212
     mVertAttribs.clear();
214
     mVertAttribs = null;
213 215

  
214 216
     mVBO.markForDeletion();
215 217
     mTFO.markForDeletion();
216 218
     }
219

  
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221
/**
222
 * Multiply all coordinates, normal and inflate vectors by the matrix.
223
 * <p>
224
 * This is a static, permanent modification of the vertices contained in this Mesh. If the Effect
225
 * contains any Dynamics, they will be evaluated at 0.
226
 *
227
 * Please note that calling this once with the complete list of Effects will be much faster than
228
 * calling it repeatedly with one Effect at a time, as we have to reallocate the array of vertices
229
 * each time.
230
 */
231
   public void apply(MatrixEffect[] effects)
232
     {
233
     for(int v=0; v<mNumVertices; v++)
234
       {
235
       for(MatrixEffect eff: effects)
236
         {
237
         if( eff!=null ) eff.applyToVertex( mVertAttribs, v*VERT_ATTRIBS );
238
         }
239
       }
240

  
241
     setAttribs(mVertAttribs);
242
     }
217 243
   }
218 244

  
219 245

  

Also available in: Unified diff