Project

General

Profile

Download (21.3 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / mesh / MeshBase.java @ e54bfada

1 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4 46b572b5 Leszek Koltunski
// This file is part of Distorted.                                                               //
5 d333eb6b Leszek Koltunski
//                                                                                               //
6 46b572b5 Leszek Koltunski
// Distorted is free software: you can redistribute it and/or modify                             //
7 d333eb6b Leszek Koltunski
// 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 46b572b5 Leszek Koltunski
// Distorted is distributed in the hope that it will be useful,                                  //
12 d333eb6b Leszek Koltunski
// 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 46b572b5 Leszek Koltunski
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 6c00149d Leszek Koltunski
package org.distorted.library.mesh;
21 6a06a912 Leszek Koltunski
22 b7074bc6 Leszek Koltunski
import android.opengl.GLES30;
23 f046b159 Leszek Koltunski
import android.util.Log;
24 6c00149d Leszek Koltunski
25 f046b159 Leszek Koltunski
import org.distorted.library.effect.VertexEffect;
26
import org.distorted.library.effectqueue.EffectQueueVertex;
27
import org.distorted.library.main.DistortedLibrary;
28 7602a827 Leszek Koltunski
import org.distorted.library.main.InternalBuffer;
29 da681e7e Leszek Koltunski
import org.distorted.library.program.DistortedProgram;
30 a3a05347 Leszek Koltunski
import org.distorted.library.type.Static4D;
31 6c00149d Leszek Koltunski
32 f046b159 Leszek Koltunski
import java.nio.ByteBuffer;
33
import java.nio.ByteOrder;
34
import java.nio.FloatBuffer;
35 c90aca24 Leszek Koltunski
import java.util.ArrayList;
36 6a06a912 Leszek Koltunski
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38 e0b6c593 Leszek Koltunski
/**
39 e5ba319d Leszek Koltunski
 * Abstract class which represents a Mesh, ie an array of vertices (rendered as a TRIANGLE_STRIP).
40 e0b6c593 Leszek Koltunski
 * <p>
41 da681e7e Leszek Koltunski
 * If you want to render to a particular shape, extend from here, construct a float array
42 7a5e538a Leszek Koltunski
 * containing per-vertex attributes, and call back setAttribs().
43 e0b6c593 Leszek Koltunski
 */
44 715e7726 Leszek Koltunski
public abstract class MeshBase
45 6a06a912 Leszek Koltunski
   {
46 227b9bca Leszek Koltunski
   // sizes of attributes of an individual vertex.
47
   private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z
48
   private static final int NOR_DATA_SIZE= 3; // normal vector: x,y,z
49
   private static final int INF_DATA_SIZE= 3; // 'inflate' vector: x,y,z
50 7a5e538a Leszek Koltunski
   private static final int TEX_DATA_SIZE= 2; // texture coordinates: s,t
51 6f2d931d Leszek Koltunski
52
   static final int POS_ATTRIB   = 0;
53
   static final int NOR_ATTRIB   = POS_DATA_SIZE;
54
   static final int INF_ATTRIB   = POS_DATA_SIZE + NOR_DATA_SIZE;
55 e54bfada Leszek Koltunski
   static final int TEX_ATTRIB   = 0;
56
   static final int VERT1_ATTRIBS= POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE;  // number of attributes of a vertex (the part changed by preapply)
57
   static final int VERT2_ATTRIBS= TEX_DATA_SIZE;                                  // number of attributes of a vertex (the 'preapply invariant' part)
58
   static final int TRAN_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE;  // number of attributes of a transform feedback vertex
59 6a06a912 Leszek Koltunski
60 da681e7e Leszek Koltunski
   private static final int BYTES_PER_FLOAT = 4;
61 3ef3364d Leszek Koltunski
62 6f2d931d Leszek Koltunski
   private static final int OFFSET_POS = POS_ATTRIB*BYTES_PER_FLOAT;
63
   private static final int OFFSET_NOR = NOR_ATTRIB*BYTES_PER_FLOAT;
64
   private static final int OFFSET_INF = INF_ATTRIB*BYTES_PER_FLOAT;
65
   private static final int OFFSET_TEX = TEX_ATTRIB*BYTES_PER_FLOAT;
66 227b9bca Leszek Koltunski
   private static final int TRAN_SIZE  = TRAN_ATTRIBS*BYTES_PER_FLOAT;
67 e54bfada Leszek Koltunski
   private static final int VERT1_SIZE = VERT1_ATTRIBS*BYTES_PER_FLOAT;
68
   private static final int VERT2_SIZE = VERT2_ATTRIBS*BYTES_PER_FLOAT;
69 a51fe521 Leszek Koltunski
70 e54bfada Leszek Koltunski
   private boolean mShowNormals;              // when rendering this mesh, draw normal vectors?
71
   private InternalBuffer mVBO1, mVBO2, mTFO; // main vertex buffer and transform feedback buffer
72 da681e7e Leszek Koltunski
   private int mNumVertices;
73 e54bfada Leszek Koltunski
   private float[] mVertAttribs1;             // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ
74
   private float[] mVertAttribs2;             // packed: TexS,TexT
75 7a5e538a Leszek Koltunski
   private float mInflate;
76 f046b159 Leszek Koltunski
   private boolean mNeedsAdjustment;
77 3ef3364d Leszek Koltunski
78 7e53a35f Leszek Koltunski
   private static class Component
79 c90aca24 Leszek Koltunski
     {
80
     private int mEndIndex;
81 a3a05347 Leszek Koltunski
     private Static4D mTextureMap;
82 f046b159 Leszek Koltunski
     private EffectQueueVertex mQueue;
83 c90aca24 Leszek Koltunski
84 0d4aae88 Leszek Koltunski
     Component(int end)
85 c90aca24 Leszek Koltunski
       {
86 a3a05347 Leszek Koltunski
       mEndIndex  = end;
87
       mTextureMap= new Static4D(0,0,1,1);
88 f046b159 Leszek Koltunski
       mQueue     = new EffectQueueVertex();
89 c90aca24 Leszek Koltunski
       }
90
     Component(Component original)
91
       {
92
       mEndIndex = original.mEndIndex;
93 a3a05347 Leszek Koltunski
94
       float x = original.mTextureMap.get0();
95
       float y = original.mTextureMap.get1();
96
       float z = original.mTextureMap.get2();
97
       float w = original.mTextureMap.get3();
98
       mTextureMap = new Static4D(x,y,z,w);
99 f046b159 Leszek Koltunski
       mQueue = new EffectQueueVertex(original.mQueue);
100 0d4aae88 Leszek Koltunski
       }
101
102 a3a05347 Leszek Koltunski
     void setMap(Static4D map)
103 0d4aae88 Leszek Koltunski
       {
104 a3a05347 Leszek Koltunski
       mTextureMap.set(map.get0(),map.get1(),map.get2(),map.get3());
105 c90aca24 Leszek Koltunski
       }
106
     }
107
108
   private ArrayList<Component> mComponent;
109
110 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
111 3ef3364d Leszek Koltunski
112 0f10a0b6 Leszek Koltunski
   MeshBase()
113 3ef3364d Leszek Koltunski
     {
114 f046b159 Leszek Koltunski
     mShowNormals     = false;
115
     mInflate         = 0.0f;
116
     mNeedsAdjustment = false;
117
     mComponent       = new ArrayList<>();
118 c90aca24 Leszek Koltunski
119 e54bfada Leszek Koltunski
     mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
120
     mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
121 b7074bc6 Leszek Koltunski
     mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ);
122 c90aca24 Leszek Koltunski
     }
123
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125
// copy constructor
126
127
   MeshBase(MeshBase original)
128
     {
129 f046b159 Leszek Koltunski
     mShowNormals     = original.mShowNormals;
130
     mInflate         = original.mInflate;
131
     mNeedsAdjustment = original.mNeedsAdjustment;
132 c90aca24 Leszek Koltunski
133
     int size = original.mComponent.size();
134
     mComponent = new ArrayList<>();
135
     for(int i=0; i<size; i++)
136
       {
137
       Component comp = new Component(original.mComponent.get(i));
138
       mComponent.add(comp);
139
       }
140 42571056 Leszek Koltunski
141 e54bfada Leszek Koltunski
     mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
142
     mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
143 b7074bc6 Leszek Koltunski
     mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ);
144 c90aca24 Leszek Koltunski
145 cbd502ec Leszek Koltunski
     mNumVertices = original.mNumVertices;
146 e54bfada Leszek Koltunski
     mVertAttribs1= new float[mNumVertices*VERT1_ATTRIBS];
147
     mVertAttribs2= new float[mNumVertices*VERT2_ATTRIBS];
148 cbd502ec Leszek Koltunski
149 e54bfada Leszek Koltunski
     System.arraycopy(original.mVertAttribs1,0,mVertAttribs1,0,mNumVertices*VERT1_ATTRIBS);
150
     System.arraycopy(original.mVertAttribs2,0,mVertAttribs2,0,mNumVertices*VERT2_ATTRIBS);
151
152
     mVBO1.invalidate();
153
     mVBO2.invalidate();
154 cbd502ec Leszek Koltunski
     mTFO.invalidate();
155 42571056 Leszek Koltunski
     }
156
157 0d4aae88 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
158
159
   int numComponents()
160
     {
161
     return mComponent.size();
162
     }
163
164 42571056 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
165 6c00149d Leszek Koltunski
// when a derived class is done computing its mesh, it has to call this method.
166 42571056 Leszek Koltunski
167 e54bfada Leszek Koltunski
   void setAttribs(float[] vert1Attribs, float[] vert2Attribs)
168 42571056 Leszek Koltunski
     {
169 e54bfada Leszek Koltunski
     mNumVertices = vert1Attribs.length/VERT1_ATTRIBS;
170
     mVertAttribs1= vert1Attribs;
171
     mVertAttribs2= vert2Attribs;
172 da681e7e Leszek Koltunski
173 0d4aae88 Leszek Koltunski
     mComponent.add(new Component(mNumVertices));
174 c90aca24 Leszek Koltunski
175 e54bfada Leszek Koltunski
     mVBO1.invalidate();
176
     mVBO2.invalidate();
177 42571056 Leszek Koltunski
     }
178
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180 0d4aae88 Leszek Koltunski
// called from MeshJoined
181 42571056 Leszek Koltunski
182 0d4aae88 Leszek Koltunski
   void join(MeshBase[] meshes)
183 226144d0 leszek
     {
184 0d4aae88 Leszek Koltunski
     MeshBase mesh;
185
     Component comp;
186 e7f85322 Leszek Koltunski
     int numComponents, numVertices, numMeshes = meshes.length;
187 0d4aae88 Leszek Koltunski
     int origVertices = mNumVertices;
188 42571056 Leszek Koltunski
189 0d4aae88 Leszek Koltunski
     // compute new numVertices; take care of Components
190 044b5494 Leszek Koltunski
191 0d4aae88 Leszek Koltunski
     if( origVertices>0 )
192
       {
193 e7f85322 Leszek Koltunski
       numComponents = mComponent.size();
194 0d4aae88 Leszek Koltunski
       mNumVertices+= ( mNumVertices%2==1 ? 2:1 );
195 e7f85322 Leszek Koltunski
       mComponent.get(numComponents-1).mEndIndex = mNumVertices;
196 0d4aae88 Leszek Koltunski
       }
197 044b5494 Leszek Koltunski
198 e7f85322 Leszek Koltunski
     for(int i=0; i<numMeshes; i++)
199 0d4aae88 Leszek Koltunski
       {
200
       mesh = meshes[i];
201 e7f85322 Leszek Koltunski
       numComponents = mesh.mComponent.size();
202 044b5494 Leszek Koltunski
203 e7f85322 Leszek Koltunski
       for(int j=0; j<numComponents; j++)
204 0d4aae88 Leszek Koltunski
         {
205
         comp = new Component(mesh.mComponent.get(j));
206
         comp.mEndIndex += mNumVertices;
207
         mComponent.add(comp);
208
         }
209 23b733db Leszek Koltunski
210 e7f85322 Leszek Koltunski
       numVertices = mesh.mNumVertices;
211 22e60fba Leszek Koltunski
212 e7f85322 Leszek Koltunski
       if( mNumVertices==0 )
213
         {
214
         if( numMeshes>1 )
215
            mNumVertices += (numVertices%2==1 ? numVertices+2 : numVertices+1);
216
         else
217
            mNumVertices +=  numVertices;
218
         }
219
       else if( i==numMeshes-1 ) mNumVertices += (numVertices+1);
220
       else                      mNumVertices += (numVertices%2==1 ? numVertices+3 : numVertices+2);
221 0d4aae88 Leszek Koltunski
       }
222
223
     // allocate new attrib array
224 e54bfada Leszek Koltunski
     float[] newAttribs1 = new float[VERT1_ATTRIBS*mNumVertices];
225
     float[] newAttribs2 = new float[VERT2_ATTRIBS*mNumVertices];
226 e7f85322 Leszek Koltunski
     numVertices = origVertices;
227 0d4aae88 Leszek Koltunski
228
     if( origVertices>0 )
229
       {
230 e54bfada Leszek Koltunski
       System.arraycopy(mVertAttribs1,                              0, newAttribs1,                         0, VERT1_ATTRIBS*numVertices);
231
       System.arraycopy(mVertAttribs2,                              0, newAttribs2,                         0, VERT2_ATTRIBS*numVertices);
232
       System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS    );
233
       System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS    );
234 0d4aae88 Leszek Koltunski
       origVertices++;
235
236 e7f85322 Leszek Koltunski
       if( numVertices%2==1 )
237 0d4aae88 Leszek Koltunski
         {
238 e54bfada Leszek Koltunski
         System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
239
         System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
240 0d4aae88 Leszek Koltunski
         origVertices++;
241
         }
242
       }
243
244 e7f85322 Leszek Koltunski
     for(int i=0; i<numMeshes; i++)
245 0d4aae88 Leszek Koltunski
       {
246
       mesh = meshes[i];
247 e7f85322 Leszek Koltunski
       numVertices = mesh.mNumVertices;
248 0d4aae88 Leszek Koltunski
249 22e60fba Leszek Koltunski
       if( origVertices>0 )
250
         {
251 e54bfada Leszek Koltunski
         System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS    );
252
         System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS    );
253 22e60fba Leszek Koltunski
         origVertices++;
254
         }
255 e54bfada Leszek Koltunski
       System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS*numVertices);
256
       System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS*numVertices);
257 e7f85322 Leszek Koltunski
       origVertices+=numVertices;
258 0d4aae88 Leszek Koltunski
259 e7f85322 Leszek Koltunski
       if( i<numMeshes-1 )
260 0d4aae88 Leszek Koltunski
         {
261 e54bfada Leszek Koltunski
         System.arraycopy(mesh.mVertAttribs1, VERT1_ATTRIBS*(numVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
262
         System.arraycopy(mesh.mVertAttribs2, VERT2_ATTRIBS*(numVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
263 0d4aae88 Leszek Koltunski
         origVertices++;
264
265 e7f85322 Leszek Koltunski
         if( numVertices%2==1 )
266 0d4aae88 Leszek Koltunski
           {
267 e54bfada Leszek Koltunski
           System.arraycopy(mesh.mVertAttribs1, VERT1_ATTRIBS*(numVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
268
           System.arraycopy(mesh.mVertAttribs2, VERT2_ATTRIBS*(numVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
269 0d4aae88 Leszek Koltunski
           origVertices++;
270
           }
271
         }
272
       }
273
274
     if( origVertices!=mNumVertices )
275
       {
276
       android.util.Log.e("mesh", "join: origVertices: "+origVertices+" numVertices: "+mNumVertices);
277
       }
278
279 e54bfada Leszek Koltunski
     mVertAttribs1 = newAttribs1;
280
     mVertAttribs2 = newAttribs2;
281 0d4aae88 Leszek Koltunski
282 e54bfada Leszek Koltunski
     mVBO1.invalidate();
283
     mVBO2.invalidate();
284 23b733db Leszek Koltunski
     }
285
286 f046b159 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
287
/**
288
 * Not part of public API, do not document (public only because has to be used from the main package)
289
 *
290
 * @y.exclude
291
 */
292
   public void copyTransformToVertex()
293
     {
294 e54bfada Leszek Koltunski
     ByteBuffer buffer = (ByteBuffer)GLES30.glMapBufferRange( GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0,
295
                                                              TRAN_SIZE*mNumVertices, GLES30.GL_MAP_READ_BIT);
296 f046b159 Leszek Koltunski
     if( buffer!=null )
297
       {
298 e54bfada Leszek Koltunski
       FloatBuffer feedback = buffer.order(ByteOrder.nativeOrder()).asFloatBuffer();
299
       feedback.get(mVertAttribs1,0,VERT1_ATTRIBS*mNumVertices);
300
       mVBO1.update(mVertAttribs1);
301 f046b159 Leszek Koltunski
       }
302
     else
303
       {
304 b5be333a Leszek Koltunski
       int error = GLES30.glGetError();
305
       Log.e("mesh", "failed to map tf buffer, error="+error);
306 f046b159 Leszek Koltunski
       }
307
308 b5be333a Leszek Koltunski
     GLES30.glUnmapBuffer(GLES30.GL_TRANSFORM_FEEDBACK);
309 ceed2df6 Leszek Koltunski
310
     int numComp = mComponent.size();
311
312
     for(int i=0; i<numComp; i++)
313
       {
314
       mComponent.get(i).mQueue.removeAll(false);
315
       }
316 f046b159 Leszek Koltunski
     }
317
318
///////////////////////////////////////////////////////////////////////////////////////////////////
319
/**
320
 * Not part of public API, do not document (public only because has to be used from the main package)
321
 *
322
 * @y.exclude
323
 */
324
   public void computeQueue()
325
     {
326
     int numComp = mComponent.size();
327
328
     for(int i=0; i<numComp; i++)
329
       {
330
       mComponent.get(i).mQueue.compute(1);
331
       }
332
     }
333
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335
/**
336
 * Not part of public API, do not document (public only because has to be used from the main package)
337
 *
338
 * @y.exclude
339
 */
340
   public void sendQueue()
341
     {
342
     int numComp = mComponent.size();
343
344
     for(int i=0; i<numComp; i++)
345
       {
346 cbd502ec Leszek Koltunski
       mComponent.get(i).mQueue.send(0.0f,3);
347 f046b159 Leszek Koltunski
       }
348
     }
349
350 23b733db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
351
/**
352 0d4aae88 Leszek Koltunski
 * Not part of public API, do not document (public only because has to be used from the main package)
353
 *
354
 * @y.exclude
355 23b733db Leszek Koltunski
 */
356 0d4aae88 Leszek Koltunski
   public int getTFO()
357 23b733db Leszek Koltunski
     {
358 b5be333a Leszek Koltunski
     return mTFO.createImmediately(mNumVertices*TRAN_SIZE, null);
359 23b733db Leszek Koltunski
     }
360
361
///////////////////////////////////////////////////////////////////////////////////////////////////
362
/**
363 0d4aae88 Leszek Koltunski
 * Not part of public API, do not document (public only because has to be used from the main package)
364
 *
365
 * @y.exclude
366 23b733db Leszek Koltunski
 */
367 0d4aae88 Leszek Koltunski
   public int getNumVertices()
368 23b733db Leszek Koltunski
     {
369 0d4aae88 Leszek Koltunski
     return mNumVertices;
370 23b733db Leszek Koltunski
     }
371
372 044b5494 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
373 6c00149d Leszek Koltunski
/**
374
 * Not part of public API, do not document (public only because has to be used from the main package)
375
 *
376
 * @y.exclude
377
 */
378 da681e7e Leszek Koltunski
   public void bindVertexAttribs(DistortedProgram program)
379 6c00149d Leszek Koltunski
     {
380 f046b159 Leszek Koltunski
     if( mNeedsAdjustment )
381
       {
382
       mNeedsAdjustment = false;
383
       DistortedLibrary.adjustVertices(this);
384
       }
385
386 e54bfada Leszek Koltunski
     int index1 = mVBO1.createImmediately(mNumVertices*VERT1_SIZE, mVertAttribs1);
387
     int index2 = mVBO2.createImmediately(mNumVertices*VERT2_SIZE, mVertAttribs2);
388 22e60fba Leszek Koltunski
389 e54bfada Leszek Koltunski
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index1 );
390
     GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_POS);
391
     GLES30.glVertexAttribPointer(program.mAttribute[1], NOR_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_NOR);
392
     GLES30.glVertexAttribPointer(program.mAttribute[2], INF_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_INF);
393
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index2 );
394
     GLES30.glVertexAttribPointer(program.mAttribute[3], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_TEX);
395 b7074bc6 Leszek Koltunski
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
396 da681e7e Leszek Koltunski
     }
397
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399
/**
400
 * Not part of public API, do not document (public only because has to be used from the main package)
401
 *
402
 * @y.exclude
403
 */
404
   public void bindTransformAttribs(DistortedProgram program)
405
     {
406 7e53a35f Leszek Koltunski
     int index = mTFO.createImmediately(mNumVertices*TRAN_SIZE, null);
407 22e60fba Leszek Koltunski
408 b7074bc6 Leszek Koltunski
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index );
409
     GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, 0);
410
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
411 6c00149d Leszek Koltunski
     }
412
413 7a5e538a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
414
/**
415
 * Not part of public API, do not document (public only because has to be used from the main package)
416
 *
417
 * @y.exclude
418
 */
419
   public void setInflate(float inflate)
420
     {
421
     mInflate = inflate;
422
     }
423
424
///////////////////////////////////////////////////////////////////////////////////////////////////
425
/**
426
 * Not part of public API, do not document (public only because has to be used from the main package)
427
 *
428
 * @y.exclude
429
 */
430
   public float getInflate()
431
     {
432
     return mInflate;
433
     }
434
435 466450b5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
436
// PUBLIC API
437 3fc9327a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
438
/**
439
 * When rendering this Mesh, do we want to render the Normal vectors as well?
440 420836fc leszek
 * <p>
441
 * Will work only on OpenGL ES >= 3.0 devices.
442 3fc9327a Leszek Koltunski
 *
443
 * @param show Controls if we render the Normal vectors or not.
444
 */
445
   public void setShowNormals(boolean show)
446
     {
447 b7074bc6 Leszek Koltunski
     mShowNormals = show;
448 3fc9327a Leszek Koltunski
     }
449 466450b5 Leszek Koltunski
450 6c00149d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
451
/**
452
 * When rendering this mesh, should we also draw the normal vectors?
453
 *
454
 * @return <i>true</i> if we do render normal vectors
455
 */
456
   public boolean getShowNormals()
457
     {
458
     return mShowNormals;
459
     }
460
461 466450b5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
462
/**
463
 * Release all internal resources.
464
 */
465
   public void markForDeletion()
466
     {
467 e54bfada Leszek Koltunski
     mVertAttribs1 = null;
468
     mVertAttribs2 = null;
469 466450b5 Leszek Koltunski
470 e54bfada Leszek Koltunski
     mVBO1.markForDeletion();
471
     mVBO2.markForDeletion();
472 466450b5 Leszek Koltunski
     mTFO.markForDeletion();
473
     }
474 fa8bc998 Leszek Koltunski
475
///////////////////////////////////////////////////////////////////////////////////////////////////
476
/**
477 f046b159 Leszek Koltunski
 * Apply a Vertex Effect to the vertex mesh.
478 fa8bc998 Leszek Koltunski
 * <p>
479 c90aca24 Leszek Koltunski
 * This is a static, permanent modification of the vertices contained in this Mesh. If the effects
480 f046b159 Leszek Koltunski
 * contain any Dynamics, the Dynamics will be evaluated at 0.
481 fa8bc998 Leszek Koltunski
 *
482 f046b159 Leszek Koltunski
 * We would call this several times building up a list of Effects to do. This list of effects gets
483
 * lazily executed only when the Mesh is used for rendering for the first time.
484 e172985c Leszek Koltunski
 *
485 f046b159 Leszek Koltunski
 * @param effect Vertex Effect to apply to the Mesh.
486 fa8bc998 Leszek Koltunski
 */
487 f046b159 Leszek Koltunski
   public void apply(VertexEffect effect)
488 fa8bc998 Leszek Koltunski
     {
489 f046b159 Leszek Koltunski
     int numComp = mComponent.size();
490 c90aca24 Leszek Koltunski
491 f046b159 Leszek Koltunski
     for(int i=0; i<numComp; i++)
492 fa8bc998 Leszek Koltunski
       {
493 f046b159 Leszek Koltunski
       mComponent.get(i).mQueue.add(effect);
494 fa8bc998 Leszek Koltunski
       }
495
496 f046b159 Leszek Koltunski
     mNeedsAdjustment = true;
497 c90aca24 Leszek Koltunski
     }
498
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500
/**
501 a3a05347 Leszek Koltunski
 * Sets texture maps for (some of) the components of this mesh.
502 c90aca24 Leszek Koltunski
 * <p>
503 a3a05347 Leszek Koltunski
 * Format: ( x of lower-left corner, y of lower-left corner, width, height ).
504
 * For example maps[0] = new Static4D( 0.0, 0.5, 0.5, 0.5 ) sets the 0th component texture map to the
505 0d4aae88 Leszek Koltunski
 * upper-left quadrant of the texture.
506 a3a05347 Leszek Koltunski
 * <p>
507
 * Probably the most common user case would be sending as many maps as there are components in this
508
 * Mesh. One can also send less, or more (the extraneous ones will be ignored) and set some of them
509
 * to null (those will be ignored as well). So if there are 5 components, and we want to set the map
510
 * of the 2nd and 4rd one, call this with
511
 * maps = new Static4D[4]
512
 * maps[0] = null
513
 * maps[1] = the map for the 2nd component
514
 * maps[2] = null
515
 * maps[3] = the map for the 4th component
516
 *
517
 * A map's width and height have to be non-zero (but can be negative!)
518 e172985c Leszek Koltunski
 *
519
 * @param maps List of texture maps to apply to the texture's components.
520 c90aca24 Leszek Koltunski
 */
521 a3a05347 Leszek Koltunski
   public void setTextureMap(Static4D[] maps)
522 c90aca24 Leszek Koltunski
     {
523 0d4aae88 Leszek Koltunski
     int num_comp = mComponent.size();
524
     int num_maps = maps.length;
525 d917f059 Leszek Koltunski
     int min = Math.min(num_comp, num_maps);
526 de53cf3e Leszek Koltunski
     int vertex = 0;
527 a3a05347 Leszek Koltunski
     Static4D newMap, oldMap;
528 de53cf3e Leszek Koltunski
     Component comp;
529 a3a05347 Leszek Koltunski
     float newW, newH, ratW, ratH, movX, movY;
530 ea88d502 Leszek Koltunski
531 0d4aae88 Leszek Koltunski
     for(int i=0; i<min; i++)
532 ea88d502 Leszek Koltunski
       {
533 a3a05347 Leszek Koltunski
       newMap = maps[i];
534 7e53a35f Leszek Koltunski
       comp = mComponent.get(i);
535 a3a05347 Leszek Koltunski
536
       if( newMap!=null )
537 ea88d502 Leszek Koltunski
         {
538 a3a05347 Leszek Koltunski
         newW = newMap.get2();
539
         newH = newMap.get3();
540 de53cf3e Leszek Koltunski
541 a3a05347 Leszek Koltunski
         if( newW!=0.0f && newH!=0.0f )
542 de53cf3e Leszek Koltunski
           {
543 a3a05347 Leszek Koltunski
           oldMap = comp.mTextureMap;
544
           ratW = newW/oldMap.get2();
545
           ratH = newH/oldMap.get3();
546
           movX = newMap.get0() - ratW*oldMap.get0();
547
           movY = newMap.get1() - ratH*oldMap.get1();
548
549 e54bfada Leszek Koltunski
           for( int index=vertex*VERT2_ATTRIBS+TEX_ATTRIB ; vertex<=comp.mEndIndex; vertex++, index+=VERT2_ATTRIBS)
550 a3a05347 Leszek Koltunski
             {
551 e54bfada Leszek Koltunski
             mVertAttribs2[index  ] = ratW*mVertAttribs2[index  ] + movX;
552
             mVertAttribs2[index+1] = ratH*mVertAttribs2[index+1] + movY;
553 a3a05347 Leszek Koltunski
             }
554
           comp.setMap(newMap);
555 de53cf3e Leszek Koltunski
           }
556 ea88d502 Leszek Koltunski
         }
557 7e53a35f Leszek Koltunski
558
       vertex= comp.mEndIndex+1;
559 ea88d502 Leszek Koltunski
       }
560 c90aca24 Leszek Koltunski
561 e54bfada Leszek Koltunski
     mVBO2.invalidate();
562 fa8bc998 Leszek Koltunski
     }
563 9099e567 Leszek Koltunski
564 e172985c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
565
/**
566
 * Return the texture map of one of the components.
567
 *
568
 * @param component The component number whose texture map we want to retrieve.
569
 */
570
   public Static4D getTextureMap(int component)
571
     {
572
     return (component>=0 && component<mComponent.size()) ? mComponent.get(component).mTextureMap : null;
573
     }
574 cbd502ec Leszek Koltunski
575
///////////////////////////////////////////////////////////////////////////////////////////////////
576
/**
577
 * Deep copy
578
 */
579
   public abstract MeshBase deepCopy();
580 6a06a912 Leszek Koltunski
   }
581 226144d0 leszek
582 3fc9327a Leszek Koltunski