Project

General

Profile

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

library / src / main / java / org / distorted / library / mesh / MeshBase.java @ 073e5a7a

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 e8925fcd Leszek Koltunski
import android.opengl.Matrix;
24 f046b159 Leszek Koltunski
import android.util.Log;
25 6c00149d Leszek Koltunski
26 e8925fcd Leszek Koltunski
import org.distorted.library.effect.MatrixEffect;
27 f046b159 Leszek Koltunski
import org.distorted.library.effect.VertexEffect;
28 9f9924f8 Leszek Koltunski
import org.distorted.library.effectqueue.EffectQueue;
29 7602a827 Leszek Koltunski
import org.distorted.library.main.InternalBuffer;
30 da681e7e Leszek Koltunski
import org.distorted.library.program.DistortedProgram;
31 a3a05347 Leszek Koltunski
import org.distorted.library.type.Static4D;
32 de77a6c5 Leszek Koltunski
import org.distorted.library.uniformblock.UniformBlockAssociation;
33
import org.distorted.library.uniformblock.UniformBlockCenter;
34 6c00149d Leszek Koltunski
35 bc2ab8c5 Leszek Koltunski
import java.io.DataOutputStream;
36 22422a76 Leszek Koltunski
import java.io.IOException;
37 bc2ab8c5 Leszek Koltunski
import java.io.DataInputStream;
38 f046b159 Leszek Koltunski
import java.nio.ByteBuffer;
39
import java.nio.ByteOrder;
40
import java.nio.FloatBuffer;
41 c90aca24 Leszek Koltunski
import java.util.ArrayList;
42 6a06a912 Leszek Koltunski
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44 e0b6c593 Leszek Koltunski
/**
45 e5ba319d Leszek Koltunski
 * Abstract class which represents a Mesh, ie an array of vertices (rendered as a TRIANGLE_STRIP).
46 e0b6c593 Leszek Koltunski
 * <p>
47 da681e7e Leszek Koltunski
 * If you want to render to a particular shape, extend from here, construct a float array
48 7a5e538a Leszek Koltunski
 * containing per-vertex attributes, and call back setAttribs().
49 e0b6c593 Leszek Koltunski
 */
50 715e7726 Leszek Koltunski
public abstract class MeshBase
51 6a06a912 Leszek Koltunski
   {
52 a2878a67 Leszek Koltunski
   private static final int ASSOC_UBO_BINDING  = 3;
53
   private static final int CENTER_UBO_BINDING = 4;
54 073e5a7a Leszek Koltunski
55
   public static int MAX_EFFECT_COMPONENTS= 100;
56 bc208a9c Leszek Koltunski
57 227b9bca Leszek Koltunski
   // sizes of attributes of an individual vertex.
58
   private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z
59
   private static final int NOR_DATA_SIZE= 3; // normal vector: x,y,z
60 7a5e538a Leszek Koltunski
   private static final int TEX_DATA_SIZE= 2; // texture coordinates: s,t
61 36d65d88 Leszek Koltunski
   private static final int COM_DATA_SIZE= 1; // component number, a single float
62 6f2d931d Leszek Koltunski
63
   static final int POS_ATTRIB   = 0;
64
   static final int NOR_ATTRIB   = POS_DATA_SIZE;
65 e54bfada Leszek Koltunski
   static final int TEX_ATTRIB   = 0;
66 36d65d88 Leszek Koltunski
   static final int COM_ATTRIB   = TEX_DATA_SIZE;
67 bc208a9c Leszek Koltunski
68 a2878a67 Leszek Koltunski
   static final int VERT1_ATTRIBS= POS_DATA_SIZE + NOR_DATA_SIZE;  // number of attributes of a vertex (the part changed by preapply)
69
   static final int VERT2_ATTRIBS= TEX_DATA_SIZE + COM_DATA_SIZE;  // number of attributes of a vertex (the 'preapply invariant' part)
70
   static final int TRAN_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE;  // number of attributes of a transform feedback vertex
71 6a06a912 Leszek Koltunski
72 da681e7e Leszek Koltunski
   private static final int BYTES_PER_FLOAT = 4;
73 3ef3364d Leszek Koltunski
74 6f2d931d Leszek Koltunski
   private static final int OFFSET_POS = POS_ATTRIB*BYTES_PER_FLOAT;
75
   private static final int OFFSET_NOR = NOR_ATTRIB*BYTES_PER_FLOAT;
76
   private static final int OFFSET_TEX = TEX_ATTRIB*BYTES_PER_FLOAT;
77 36d65d88 Leszek Koltunski
   private static final int OFFSET_COM = COM_ATTRIB*BYTES_PER_FLOAT;
78 bc208a9c Leszek Koltunski
79 227b9bca Leszek Koltunski
   private static final int TRAN_SIZE  = TRAN_ATTRIBS*BYTES_PER_FLOAT;
80 e54bfada Leszek Koltunski
   private static final int VERT1_SIZE = VERT1_ATTRIBS*BYTES_PER_FLOAT;
81
   private static final int VERT2_SIZE = VERT2_ATTRIBS*BYTES_PER_FLOAT;
82 a51fe521 Leszek Koltunski
83 46d463a4 Leszek Koltunski
   private static final int[] mCenterBlockIndex = new int[EffectQueue.MAIN_VARIANTS];
84
   private static final int[] mAssocBlockIndex  = new int[EffectQueue.MAIN_VARIANTS];
85
86
   private static final int TEX_COMP_SIZE = 5; // 5 four-byte entities inside the component
87
88
   private static boolean mUseCenters;
89
90 e54bfada Leszek Koltunski
   private boolean mShowNormals;              // when rendering this mesh, draw normal vectors?
91
   private InternalBuffer mVBO1, mVBO2, mTFO; // main vertex buffer and transform feedback buffer
92 da681e7e Leszek Koltunski
   private int mNumVertices;
93 a2878a67 Leszek Koltunski
   private float[] mVertAttribs1;             // packed: PosX,PosY,PosZ, NorX,NorY,NorZ
94 36d65d88 Leszek Koltunski
   private float[] mVertAttribs2;             // packed: TexS,TexT, Component
95 7a5e538a Leszek Koltunski
   private float mInflate;
96 78ff6ea9 Leszek Koltunski
   private final UniformBlockAssociation mUBA;
97 46d463a4 Leszek Koltunski
   private UniformBlockCenter mUBC;
98 80961fc1 Leszek Koltunski
   private boolean mStrideCorrected;
99
   private static int mStride;
100 36d65d88 Leszek Koltunski
101 71d8aba1 Leszek Koltunski
   DeferredJobs.JobNode[] mJobNode;
102 07206c71 Leszek Koltunski
103 e8925fcd Leszek Koltunski
   private static class TexComponent
104 c90aca24 Leszek Koltunski
     {
105
     private int mEndIndex;
106 78ff6ea9 Leszek Koltunski
     private final Static4D mTextureMap;
107 c90aca24 Leszek Koltunski
108 e8925fcd Leszek Koltunski
     TexComponent(int end)
109 c90aca24 Leszek Koltunski
       {
110 a3a05347 Leszek Koltunski
       mEndIndex  = end;
111
       mTextureMap= new Static4D(0,0,1,1);
112 c90aca24 Leszek Koltunski
       }
113 e8925fcd Leszek Koltunski
     TexComponent(TexComponent original)
114 c90aca24 Leszek Koltunski
       {
115
       mEndIndex = original.mEndIndex;
116 a3a05347 Leszek Koltunski
117
       float x = original.mTextureMap.get0();
118
       float y = original.mTextureMap.get1();
119
       float z = original.mTextureMap.get2();
120
       float w = original.mTextureMap.get3();
121
       mTextureMap = new Static4D(x,y,z,w);
122 0d4aae88 Leszek Koltunski
       }
123
124 a3a05347 Leszek Koltunski
     void setMap(Static4D map)
125 0d4aae88 Leszek Koltunski
       {
126 a3a05347 Leszek Koltunski
       mTextureMap.set(map.get0(),map.get1(),map.get2(),map.get3());
127 c90aca24 Leszek Koltunski
       }
128
     }
129
130 e8925fcd Leszek Koltunski
   private ArrayList<TexComponent> mTexComponent;
131
   private ArrayList<Integer> mEffComponent;
132 c90aca24 Leszek Koltunski
133 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
134 3ef3364d Leszek Koltunski
135 0f10a0b6 Leszek Koltunski
   MeshBase()
136 3ef3364d Leszek Koltunski
     {
137 e8925fcd Leszek Koltunski
     mShowNormals  = false;
138
     mInflate      = 0.0f;
139
     mTexComponent = new ArrayList<>();
140
     mEffComponent = new ArrayList<>();
141
142 71d8aba1 Leszek Koltunski
     mJobNode = new DeferredJobs.JobNode[1];
143
144 a2878a67 Leszek Koltunski
     mUBA = new UniformBlockAssociation();
145 46d463a4 Leszek Koltunski
146
     if( mUseCenters ) mUBC = new UniformBlockCenter();
147 4f81e0c8 Leszek Koltunski
148 e54bfada Leszek Koltunski
     mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
149
     mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER             , GLES30.GL_STATIC_READ);
150 b7074bc6 Leszek Koltunski
     mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ);
151 c90aca24 Leszek Koltunski
     }
152
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154
// copy constructor
155
156 4f81e0c8 Leszek Koltunski
   MeshBase(MeshBase original, boolean deep)
157 c90aca24 Leszek Koltunski
     {
158 1fad573e Leszek Koltunski
     mShowNormals= original.mShowNormals;
159
     mInflate    = original.mInflate;
160
     mNumVertices= original.mNumVertices;
161 42571056 Leszek Koltunski
162 a2878a67 Leszek Koltunski
     mUBA = new UniformBlockAssociation(original.mUBA);
163 46d463a4 Leszek Koltunski
164
     if( mUseCenters ) mUBC = new UniformBlockCenter(original.mUBC);
165 36d65d88 Leszek Koltunski
166 4f81e0c8 Leszek Koltunski
     if( deep )
167
       {
168 71d8aba1 Leszek Koltunski
       mJobNode = new DeferredJobs.JobNode[1];
169 1fad573e Leszek Koltunski
       if( original.mJobNode[0]==null ) copy(original);
170
       else mJobNode[0] = DeferredJobs.copy(this,original);
171 4f81e0c8 Leszek Koltunski
       }
172
     else
173
       {
174 71d8aba1 Leszek Koltunski
       mJobNode      = original.mJobNode;
175
       mVBO1         = original.mVBO1;
176
       mVertAttribs1 = original.mVertAttribs1;
177 1fad573e Leszek Koltunski
       shallowCopy(original);
178 4f81e0c8 Leszek Koltunski
       }
179 cbd502ec Leszek Koltunski
180 4f81e0c8 Leszek Koltunski
     mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ);
181 42571056 Leszek Koltunski
     }
182
183 36d65d88 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
184
185 1fad573e Leszek Koltunski
   void copy(MeshBase original)
186 36d65d88 Leszek Koltunski
     {
187 1fad573e Leszek Koltunski
     shallowCopy(original);
188
189
     mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
190
     mVertAttribs1= new float[mNumVertices*VERT1_ATTRIBS];
191
     System.arraycopy(original.mVertAttribs1,0,mVertAttribs1,0,mNumVertices*VERT1_ATTRIBS);
192 36d65d88 Leszek Koltunski
     }
193
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195
196 1fad573e Leszek Koltunski
   private void shallowCopy(MeshBase original)
197 36d65d88 Leszek Koltunski
     {
198 e8925fcd Leszek Koltunski
     int texComSize = original.mTexComponent.size();
199
     mTexComponent = new ArrayList<>();
200 36d65d88 Leszek Koltunski
201 e8925fcd Leszek Koltunski
     for(int i=0; i<texComSize; i++)
202 1fad573e Leszek Koltunski
       {
203 e8925fcd Leszek Koltunski
       TexComponent comp = new TexComponent(original.mTexComponent.get(i));
204
       mTexComponent.add(comp);
205 1fad573e Leszek Koltunski
       }
206 f4c5a46e Leszek Koltunski
207 e8925fcd Leszek Koltunski
     mEffComponent = new ArrayList<>();
208
     mEffComponent.addAll(original.mEffComponent);
209
210 1fad573e Leszek Koltunski
     mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
211
     mVertAttribs2= new float[mNumVertices*VERT2_ATTRIBS];
212
     System.arraycopy(original.mVertAttribs2,0,mVertAttribs2,0,mNumVertices*VERT2_ATTRIBS);
213 f4c5a46e Leszek Koltunski
     }
214
215 a8dfedcc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
216
217 e8925fcd Leszek Koltunski
   void mergeTexComponentsNow()
218 a8dfedcc Leszek Koltunski
     {
219 e8925fcd Leszek Koltunski
     int num = mTexComponent.size();
220 a8dfedcc Leszek Koltunski
221
     if( num>1 )
222
       {
223 e8925fcd Leszek Koltunski
       mTexComponent.clear();
224
       mTexComponent.add(new TexComponent(mNumVertices-1));
225
226
       mVBO2.invalidate();
227
       }
228
     }
229
230 c92c163c Leszek Koltunski
231
///////////////////////////////////////////////////////////////////////////////////////////////////
232
233
   void addEmptyTexComponentNow()
234
     {
235
     mTexComponent.add(new TexComponent(mNumVertices-1));
236
     }
237
238 e8925fcd Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
239
240
   void mergeEffComponentsNow()
241
     {
242
     int num = mEffComponent.size();
243
244
     if( num>1 )
245
       {
246
       mEffComponent.clear();
247
       mEffComponent.add(mNumVertices-1);
248 a8dfedcc Leszek Koltunski
249
       for(int index=0; index<mNumVertices; index++)
250
         {
251
         mVertAttribs2[VERT2_ATTRIBS*index+COM_ATTRIB] = 0;
252
         }
253
254
       mVBO2.invalidate();
255
       }
256
     }
257
258 0d4aae88 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
259
260 e8925fcd Leszek Koltunski
   void applyMatrix(MatrixEffect effect, int andAssoc, int equAssoc)
261
     {
262 62c869ad Leszek Koltunski
     float[] matrixP  = new float[16];
263
     float[] matrixV  = new float[16];
264 e8925fcd Leszek Koltunski
     float[] uniforms = new float[7];
265
     int start, end=-1, numComp = mEffComponent.size();
266
267 62c869ad Leszek Koltunski
     Matrix.setIdentityM(matrixP,0);
268
     Matrix.setIdentityM(matrixV,0);
269 e8925fcd Leszek Koltunski
     effect.compute(uniforms,0,0,0);
270 62c869ad Leszek Koltunski
     effect.apply(matrixP, matrixV, uniforms, 0);
271 e8925fcd Leszek Koltunski
272 97755c02 Leszek Koltunski
     for(int comp=0; comp<numComp; comp++)
273 e8925fcd Leszek Koltunski
       {
274 f45e4279 Leszek Koltunski
       start = end+1;
275 97755c02 Leszek Koltunski
       end   = mEffComponent.get(comp);
276 e8925fcd Leszek Koltunski
277 a2878a67 Leszek Koltunski
       if( mUBA.matchesAssociation(comp, andAssoc, equAssoc) )
278 e8925fcd Leszek Koltunski
         {
279 62c869ad Leszek Koltunski
         applyMatrixToComponent(matrixP, matrixV, start, end);
280 e8925fcd Leszek Koltunski
         }
281
       }
282
283
     mVBO1.invalidate();
284
     }
285
286
///////////////////////////////////////////////////////////////////////////////////////////////////
287
288 62c869ad Leszek Koltunski
   private void applyMatrixToComponent(float[] matrixP, float[] matrixV, int start, int end)
289 e8925fcd Leszek Koltunski
     {
290
     float x,y,z;
291
292 f45e4279 Leszek Koltunski
     for(int index=start*VERT1_ATTRIBS; index<=end*VERT1_ATTRIBS; index+=VERT1_ATTRIBS )
293 e8925fcd Leszek Koltunski
       {
294
       x = mVertAttribs1[index+POS_ATTRIB  ];
295
       y = mVertAttribs1[index+POS_ATTRIB+1];
296
       z = mVertAttribs1[index+POS_ATTRIB+2];
297
298 62c869ad Leszek Koltunski
       mVertAttribs1[index+POS_ATTRIB  ] = matrixP[0]*x + matrixP[4]*y + matrixP[ 8]*z + matrixP[12];
299
       mVertAttribs1[index+POS_ATTRIB+1] = matrixP[1]*x + matrixP[5]*y + matrixP[ 9]*z + matrixP[13];
300
       mVertAttribs1[index+POS_ATTRIB+2] = matrixP[2]*x + matrixP[6]*y + matrixP[10]*z + matrixP[14];
301 e8925fcd Leszek Koltunski
302
       x = mVertAttribs1[index+NOR_ATTRIB  ];
303
       y = mVertAttribs1[index+NOR_ATTRIB+1];
304
       z = mVertAttribs1[index+NOR_ATTRIB+2];
305
306 62c869ad Leszek Koltunski
       mVertAttribs1[index+NOR_ATTRIB  ] = matrixV[0]*x + matrixV[4]*y + matrixV[ 8]*z;
307
       mVertAttribs1[index+NOR_ATTRIB+1] = matrixV[1]*x + matrixV[5]*y + matrixV[ 9]*z;
308
       mVertAttribs1[index+NOR_ATTRIB+2] = matrixV[2]*x + matrixV[6]*y + matrixV[10]*z;
309
310
       x = mVertAttribs1[index+NOR_ATTRIB  ];
311
       y = mVertAttribs1[index+NOR_ATTRIB+1];
312
       z = mVertAttribs1[index+NOR_ATTRIB+2];
313
314
       float len1 = (float)Math.sqrt(x*x + y*y + z*z);
315
316
       if( len1>0.0f )
317
         {
318
         mVertAttribs1[index+NOR_ATTRIB  ] /= len1;
319
         mVertAttribs1[index+NOR_ATTRIB+1] /= len1;
320
         mVertAttribs1[index+NOR_ATTRIB+2] /= len1;
321
         }
322 e8925fcd Leszek Koltunski
       }
323
     }
324
325 26671ef8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
326
327
   void setEffectAssociationNow(int component, int andAssociation, int equAssociation)
328
     {
329 a2878a67 Leszek Koltunski
     mUBA.setEffectAssociationNow(component, andAssociation, equAssociation);
330
     }
331
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333
334 7a9edb92 Leszek Koltunski
   void setComponentCenterNow(int component, float x, float y, float z)
335 a2878a67 Leszek Koltunski
     {
336 46d463a4 Leszek Koltunski
     if( mUBC!=null )
337
       {
338
       mUBC.setEffectCenterNow(component, x, y, z);
339
       }
340 26671ef8 Leszek Koltunski
     }
341
342 42571056 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
343 6c00149d Leszek Koltunski
// when a derived class is done computing its mesh, it has to call this method.
344 42571056 Leszek Koltunski
345 e54bfada Leszek Koltunski
   void setAttribs(float[] vert1Attribs, float[] vert2Attribs)
346 42571056 Leszek Koltunski
     {
347 e54bfada Leszek Koltunski
     mNumVertices = vert1Attribs.length/VERT1_ATTRIBS;
348
     mVertAttribs1= vert1Attribs;
349
     mVertAttribs2= vert2Attribs;
350 da681e7e Leszek Koltunski
351 e8925fcd Leszek Koltunski
     mTexComponent.add(new TexComponent(mNumVertices-1));
352
     mEffComponent.add(mNumVertices-1);
353 c90aca24 Leszek Koltunski
354 e54bfada Leszek Koltunski
     mVBO1.invalidate();
355
     mVBO2.invalidate();
356 42571056 Leszek Koltunski
     }
357
358
///////////////////////////////////////////////////////////////////////////////////////////////////
359
360 1fad573e Leszek Koltunski
   void joinAttribs(MeshBase[] meshes)
361 226144d0 leszek
     {
362 0d4aae88 Leszek Koltunski
     MeshBase mesh;
363 e8925fcd Leszek Koltunski
     TexComponent comp;
364 a8dfedcc Leszek Koltunski
     int numMeshes = meshes.length;
365 e8925fcd Leszek Koltunski
     int numVertices,origVertices = mNumVertices;
366 26671ef8 Leszek Koltunski
     int origTexComponents,numTexComponents;
367 e8925fcd Leszek Koltunski
     int origEffComponents=0,numEffComponents;
368 044b5494 Leszek Koltunski
369 0d4aae88 Leszek Koltunski
     if( origVertices>0 )
370
       {
371 e8925fcd Leszek Koltunski
       origTexComponents = mTexComponent.size();
372 1fad573e Leszek Koltunski
       mNumVertices+= ( mNumVertices%2==1 ? 2:1 );
373 e8925fcd Leszek Koltunski
       mTexComponent.get(origTexComponents-1).mEndIndex = mNumVertices-1;
374
       origEffComponents = mEffComponent.size();
375
       mEffComponent.set(origEffComponents-1,mNumVertices-1);
376 0d4aae88 Leszek Koltunski
       }
377 044b5494 Leszek Koltunski
378 e7f85322 Leszek Koltunski
     for(int i=0; i<numMeshes; i++)
379 0d4aae88 Leszek Koltunski
       {
380
       mesh = meshes[i];
381 e8925fcd Leszek Koltunski
       numTexComponents = mesh.mTexComponent.size();
382
       numEffComponents = mesh.mEffComponent.size();
383 36d65d88 Leszek Koltunski
       numVertices = mesh.mNumVertices;
384
385 1fad573e Leszek Koltunski
       int extraVerticesBefore = mNumVertices==0 ? 0:1;
386
       int extraVerticesAfter  = (i==numMeshes-1) ? 0 : (numVertices%2==1 ? 2:1);
387 36d65d88 Leszek Koltunski
388 e8925fcd Leszek Koltunski
       for(int j=0; j<numTexComponents; j++)
389 0d4aae88 Leszek Koltunski
         {
390 e8925fcd Leszek Koltunski
         comp = new TexComponent(mesh.mTexComponent.get(j));
391 e0343804 Leszek Koltunski
         comp.mEndIndex += (extraVerticesBefore+mNumVertices);
392
         if( j==numTexComponents-1) comp.mEndIndex += extraVerticesAfter;
393 e8925fcd Leszek Koltunski
         mTexComponent.add(comp);
394
         }
395 23b733db Leszek Koltunski
396 e8925fcd Leszek Koltunski
       for(int j=0; j<numEffComponents; j++)
397
         {
398
         int index = mesh.mEffComponent.get(j);
399 e0343804 Leszek Koltunski
         index += (extraVerticesBefore+mNumVertices);
400
         if( j==numEffComponents-1 ) index += extraVerticesAfter;
401 e8925fcd Leszek Koltunski
         mEffComponent.add(index);
402
403
         if( origEffComponents<MAX_EFFECT_COMPONENTS )
404 36d65d88 Leszek Koltunski
           {
405 a2878a67 Leszek Koltunski
           mUBA.copy(origEffComponents, mesh.mUBA, j);
406 46d463a4 Leszek Koltunski
           if( mUseCenters ) mUBC.copy(origEffComponents, mesh.mUBC, j);
407 e8925fcd Leszek Koltunski
           origEffComponents++;
408 36d65d88 Leszek Koltunski
           }
409 e7f85322 Leszek Koltunski
         }
410 a8dfedcc Leszek Koltunski
411 1fad573e Leszek Koltunski
       mNumVertices += (extraVerticesBefore+numVertices+extraVerticesAfter);
412
       }
413 a8dfedcc Leszek Koltunski
414 1fad573e Leszek Koltunski
     float[] newAttribs1 = new float[VERT1_ATTRIBS*mNumVertices];
415 e54bfada Leszek Koltunski
     float[] newAttribs2 = new float[VERT2_ATTRIBS*mNumVertices];
416 1fad573e Leszek Koltunski
     numVertices = origVertices;
417 0d4aae88 Leszek Koltunski
418
     if( origVertices>0 )
419
       {
420 e8925fcd Leszek Koltunski
       System.arraycopy(mVertAttribs1,                              0, newAttribs1,                          0, VERT1_ATTRIBS*numVertices);
421
       System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS            );
422
       System.arraycopy(mVertAttribs2,                              0, newAttribs2,                          0, VERT2_ATTRIBS*numVertices);
423
       System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS            );
424 0d4aae88 Leszek Koltunski
       origVertices++;
425
426 e7f85322 Leszek Koltunski
       if( numVertices%2==1 )
427 0d4aae88 Leszek Koltunski
         {
428 1fad573e Leszek Koltunski
         System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
429 e54bfada Leszek Koltunski
         System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
430 0d4aae88 Leszek Koltunski
         origVertices++;
431
         }
432
       }
433
434 e7f85322 Leszek Koltunski
     for(int i=0; i<numMeshes; i++)
435 0d4aae88 Leszek Koltunski
       {
436
       mesh = meshes[i];
437 e7f85322 Leszek Koltunski
       numVertices = mesh.mNumVertices;
438 0d4aae88 Leszek Koltunski
439 22e60fba Leszek Koltunski
       if( origVertices>0 )
440
         {
441 e8925fcd Leszek Koltunski
         System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
442
         System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
443 22e60fba Leszek Koltunski
         origVertices++;
444
         }
445 1fad573e Leszek Koltunski
       System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS*numVertices);
446 e54bfada Leszek Koltunski
       System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS*numVertices);
447 e7f85322 Leszek Koltunski
       origVertices+=numVertices;
448 0d4aae88 Leszek Koltunski
449 e7f85322 Leszek Koltunski
       if( i<numMeshes-1 )
450 0d4aae88 Leszek Koltunski
         {
451 1fad573e Leszek Koltunski
         System.arraycopy(mesh.mVertAttribs1, VERT1_ATTRIBS*(numVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
452 e54bfada Leszek Koltunski
         System.arraycopy(mesh.mVertAttribs2, VERT2_ATTRIBS*(numVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
453 0d4aae88 Leszek Koltunski
         origVertices++;
454
455 e7f85322 Leszek Koltunski
         if( numVertices%2==1 )
456 0d4aae88 Leszek Koltunski
           {
457 1fad573e Leszek Koltunski
           System.arraycopy(mesh.mVertAttribs1, VERT1_ATTRIBS*(numVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
458 e54bfada Leszek Koltunski
           System.arraycopy(mesh.mVertAttribs2, VERT2_ATTRIBS*(numVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
459 0d4aae88 Leszek Koltunski
           origVertices++;
460
           }
461
         }
462
       }
463
464
     if( origVertices!=mNumVertices )
465
       {
466
       android.util.Log.e("mesh", "join: origVertices: "+origVertices+" numVertices: "+mNumVertices);
467
       }
468
469 e8925fcd Leszek Koltunski
     int endIndex, index=0, numEffComp = mEffComponent.size();
470 36d65d88 Leszek Koltunski
471 e8925fcd Leszek Koltunski
     for(int component=0; component<numEffComp; component++)
472 36d65d88 Leszek Koltunski
       {
473 e8925fcd Leszek Koltunski
       endIndex = mEffComponent.get(component);
474 36d65d88 Leszek Koltunski
475
       for( ; index<=endIndex; index++) newAttribs2[VERT2_ATTRIBS*index+COM_ATTRIB] = component;
476
       }
477
478 1fad573e Leszek Koltunski
     mVertAttribs1 = newAttribs1;
479 e54bfada Leszek Koltunski
     mVertAttribs2 = newAttribs2;
480 1fad573e Leszek Koltunski
     mVBO1.invalidate();
481 e54bfada Leszek Koltunski
     mVBO2.invalidate();
482 23b733db Leszek Koltunski
     }
483
484 a8dfedcc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
485
// called from MeshJoined
486
487
   void join(MeshBase[] meshes)
488
     {
489 1fad573e Leszek Koltunski
     boolean immediateJoin = true;
490 a8dfedcc Leszek Koltunski
491 1fad573e Leszek Koltunski
     for (MeshBase mesh : meshes)
492 a8dfedcc Leszek Koltunski
       {
493 1fad573e Leszek Koltunski
       if (mesh.mJobNode[0] != null)
494
         {
495
         immediateJoin = false;
496
         break;
497
         }
498 a8dfedcc Leszek Koltunski
       }
499
500 1fad573e Leszek Koltunski
     if( immediateJoin ) joinAttribs(meshes);
501
     else                mJobNode[0] = DeferredJobs.join(this,meshes);
502
     }
503 a8dfedcc Leszek Koltunski
504 1fad573e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
505 a8dfedcc Leszek Koltunski
506 dbe3079d Leszek Koltunski
   void textureMap(Static4D[] maps, int startComponent)
507 1fad573e Leszek Koltunski
     {
508 e8925fcd Leszek Koltunski
     int num_comp = mTexComponent.size();
509 92403ff8 Leszek Koltunski
     if( startComponent>num_comp ) return;
510
511 1fad573e Leszek Koltunski
     int num_maps = maps.length;
512 dbe3079d Leszek Koltunski
     int min = Math.min(num_comp-startComponent, num_maps);
513 96877ab4 Leszek Koltunski
     int vertex = startComponent>0 ? mTexComponent.get(startComponent-1).mEndIndex+1 : 0;
514 1fad573e Leszek Koltunski
     Static4D newMap, oldMap;
515 e8925fcd Leszek Koltunski
     TexComponent comp;
516 1fad573e Leszek Koltunski
     float newW, newH, ratW, ratH, movX, movY;
517 a8dfedcc Leszek Koltunski
518 1fad573e Leszek Koltunski
     for(int i=0; i<min; i++)
519
       {
520
       newMap = maps[i];
521 dbe3079d Leszek Koltunski
       comp = mTexComponent.get(i+startComponent);
522 1fad573e Leszek Koltunski
523
       if( newMap!=null )
524 a8dfedcc Leszek Koltunski
         {
525 1fad573e Leszek Koltunski
         newW = newMap.get2();
526
         newH = newMap.get3();
527 a8dfedcc Leszek Koltunski
528 1fad573e Leszek Koltunski
         if( newW!=0.0f && newH!=0.0f )
529 a8dfedcc Leszek Koltunski
           {
530 1fad573e Leszek Koltunski
           oldMap = comp.mTextureMap;
531
           ratW = newW/oldMap.get2();
532
           ratH = newH/oldMap.get3();
533
           movX = newMap.get0() - ratW*oldMap.get0();
534
           movY = newMap.get1() - ratH*oldMap.get1();
535
536
           for( int index=vertex*VERT2_ATTRIBS+TEX_ATTRIB ; vertex<=comp.mEndIndex; vertex++, index+=VERT2_ATTRIBS)
537
             {
538
             mVertAttribs2[index  ] = ratW*mVertAttribs2[index  ] + movX;
539
             mVertAttribs2[index+1] = ratH*mVertAttribs2[index+1] + movY;
540
             }
541
           comp.setMap(newMap);
542 a8dfedcc Leszek Koltunski
           }
543
         }
544
545 1fad573e Leszek Koltunski
       vertex= comp.mEndIndex+1;
546 a8dfedcc Leszek Koltunski
       }
547
548 1fad573e Leszek Koltunski
     mVBO2.invalidate();
549
     }
550
551 46d463a4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
552
/**
553
 * Are we going to need per-component centers (needed for correct postprocessing of concave meshes)
554
 * Switching this on allocates 16*MAX_EFFECT_COMPONENTS bytes for uniforms in the vertex shader.
555
 */
556
   public static void setUseCenters()
557
     {
558
     mUseCenters = true;
559
     }
560
561
///////////////////////////////////////////////////////////////////////////////////////////////////
562
/**
563
 * Are we using per-component centers?
564
 */
565
   public static boolean getUseCenters()
566
     {
567
     return mUseCenters;
568
     }
569
570 1fad573e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
571 a8dfedcc Leszek Koltunski
572 e8925fcd Leszek Koltunski
   public static int getMaxEffComponents()
573 1fad573e Leszek Koltunski
     {
574 e8925fcd Leszek Koltunski
     return MAX_EFFECT_COMPONENTS;
575 1fad573e Leszek Koltunski
     }
576
577 073e5a7a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
578
/**
579
 * How many mesh components are we going to need? Call before compilation of the shaders.
580
 */
581
   public static void setMaxEffComponents(int max)
582
     {
583
     MAX_EFFECT_COMPONENTS = max;
584
     }
585
586 9f9924f8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
587
588
   public static void getUniforms(int programH, int variant)
589
     {
590
     mCenterBlockIndex[variant]= GLES30.glGetUniformBlockIndex(programH, "componentCenter");
591
     mAssocBlockIndex[variant] = GLES30.glGetUniformBlockIndex(programH, "componentAssociation");
592 80961fc1 Leszek Koltunski
593
     if( mStride==0 )
594
       {
595
       String[] uniformNames = { "vComAssoc" };
596
       int[] indices = new int[1];
597
       int[] params  = new int[1];
598
599
       GLES30.glGetUniformIndices(programH, uniformNames, indices, 0);
600
       GLES30.glGetActiveUniformsiv( programH, 1, indices, 0, GLES30.GL_UNIFORM_ARRAY_STRIDE, params,0 );
601
602
       mStride = params[0]/4;
603
       }
604 9f9924f8 Leszek Koltunski
     }
605
606 f046b159 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
607
/**
608
 * Not part of public API, do not document (public only because has to be used from the main package)
609
 *
610
 * @y.exclude
611
 */
612
   public void copyTransformToVertex()
613
     {
614 e54bfada Leszek Koltunski
     ByteBuffer buffer = (ByteBuffer)GLES30.glMapBufferRange( GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0,
615
                                                              TRAN_SIZE*mNumVertices, GLES30.GL_MAP_READ_BIT);
616 f046b159 Leszek Koltunski
     if( buffer!=null )
617
       {
618 e54bfada Leszek Koltunski
       FloatBuffer feedback = buffer.order(ByteOrder.nativeOrder()).asFloatBuffer();
619
       feedback.get(mVertAttribs1,0,VERT1_ATTRIBS*mNumVertices);
620 0bd9f644 Leszek Koltunski
       mVBO1.updateFloat(mVertAttribs1);
621 f046b159 Leszek Koltunski
       }
622
     else
623
       {
624 b5be333a Leszek Koltunski
       int error = GLES30.glGetError();
625
       Log.e("mesh", "failed to map tf buffer, error="+error);
626 f046b159 Leszek Koltunski
       }
627
628 b5be333a Leszek Koltunski
     GLES30.glUnmapBuffer(GLES30.GL_TRANSFORM_FEEDBACK);
629 f046b159 Leszek Koltunski
     }
630
631 1fad573e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
632
/**
633
 * Not part of public API, do not document (public only because has to be used from the main package)
634
 *
635
 * @y.exclude
636
 */
637
   public void debug()
638
     {
639
     if( mJobNode[0]!=null )
640
       {
641
       mJobNode[0].print(0);
642
       }
643
     else
644
       {
645
       android.util.Log.e("mesh", "JobNode null");
646
       }
647
     }
648
649
///////////////////////////////////////////////////////////////////////////////////////////////////
650
/**
651
 * Not part of public API, do not document (public only because has to be used from the main package)
652
 *
653
 * @y.exclude
654
 */
655 e0343804 Leszek Koltunski
   public void printPos()
656 1fad573e Leszek Koltunski
     {
657 26671ef8 Leszek Koltunski
     StringBuilder sb = new StringBuilder();
658 1fad573e Leszek Koltunski
659
     for(int i=0; i<mNumVertices; i++)
660
       {
661
       sb.append('(');
662
       sb.append(mVertAttribs1[VERT1_ATTRIBS*i+POS_ATTRIB  ]);
663
       sb.append(',');
664
       sb.append(mVertAttribs1[VERT1_ATTRIBS*i+POS_ATTRIB+1]);
665
       sb.append(',');
666
       sb.append(mVertAttribs1[VERT1_ATTRIBS*i+POS_ATTRIB+2]);
667
       sb.append(") ");
668
       }
669 e0343804 Leszek Koltunski
     Log.d("mesh", sb.toString());
670
     }
671 1fad573e Leszek Koltunski
672 e0343804 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
673
/**
674
 * Not part of public API, do not document (public only because has to be used from the main package)
675
 *
676
 * @y.exclude
677
 */
678
   public void printCom()
679
     {
680
     StringBuilder sb = new StringBuilder();
681 1fad573e Leszek Koltunski
682
     for(int i=0; i<mNumVertices; i++)
683
       {
684 e0343804 Leszek Koltunski
       sb.append(mVertAttribs2[VERT2_ATTRIBS*i+COM_ATTRIB]);
685
       sb.append(' ');
686
       }
687
688
     Log.d("mesh", sb.toString());
689
     }
690
691
///////////////////////////////////////////////////////////////////////////////////////////////////
692
/**
693
 * Not part of public API, do not document (public only because has to be used from the main package)
694
 *
695
 * @y.exclude
696
 */
697
   public void printTex()
698
     {
699
     int vert=0;
700
     int num = numTexComponents();
701
     StringBuilder sb = new StringBuilder();
702
     sb.append("tex components: ").append(num);
703
704
     for(int i=0; i<num; i++)
705
       {
706
       int end = mTexComponent.get(i).mEndIndex;
707
       sb.append("\n");
708
709
       for( ; vert<=end; vert++)
710
         {
711
         sb.append(' ');
712
         sb.append('(');
713
         sb.append(mVertAttribs2[VERT2_ATTRIBS*vert+TEX_ATTRIB]);
714
         sb.append(',');
715
         sb.append(mVertAttribs2[VERT2_ATTRIBS*vert+TEX_ATTRIB+1]);
716
         sb.append(')');
717
         }
718 1fad573e Leszek Koltunski
       }
719
720 e0343804 Leszek Koltunski
     Log.d("mesh", sb.toString());
721 1fad573e Leszek Koltunski
     }
722
723 23b733db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
724
/**
725 0d4aae88 Leszek Koltunski
 * Not part of public API, do not document (public only because has to be used from the main package)
726
 *
727
 * @y.exclude
728 23b733db Leszek Koltunski
 */
729 0d4aae88 Leszek Koltunski
   public int getTFO()
730 23b733db Leszek Koltunski
     {
731 0bd9f644 Leszek Koltunski
     return mTFO.createImmediatelyFloat(mNumVertices*TRAN_SIZE, null);
732 23b733db Leszek Koltunski
     }
733
734
///////////////////////////////////////////////////////////////////////////////////////////////////
735
/**
736 0d4aae88 Leszek Koltunski
 * Not part of public API, do not document (public only because has to be used from the main package)
737
 *
738
 * @y.exclude
739 23b733db Leszek Koltunski
 */
740 0d4aae88 Leszek Koltunski
   public int getNumVertices()
741 23b733db Leszek Koltunski
     {
742 0d4aae88 Leszek Koltunski
     return mNumVertices;
743 23b733db Leszek Koltunski
     }
744
745 36d65d88 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
746
/**
747
 * Not part of public API, do not document (public only because has to be used from the main package)
748
 *
749
 * @y.exclude
750
 */
751 9f9924f8 Leszek Koltunski
   public void send(int programH, int variant)
752 36d65d88 Leszek Koltunski
     {
753 80961fc1 Leszek Koltunski
     if( !mStrideCorrected )
754
       {
755
       mStrideCorrected = true;
756
       mUBA.correctStride(mStride);
757
       }
758
759 a2878a67 Leszek Koltunski
     int indexA = mUBA.getIndex();
760
     GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, ASSOC_UBO_BINDING, indexA);
761 9f9924f8 Leszek Koltunski
     GLES30.glUniformBlockBinding(programH, mAssocBlockIndex[variant], ASSOC_UBO_BINDING);
762 a2878a67 Leszek Koltunski
763 46d463a4 Leszek Koltunski
     if( mUseCenters )
764
       {
765
       int indexC = mUBC.getIndex();
766
       GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, CENTER_UBO_BINDING, indexC);
767
       GLES30.glUniformBlockBinding(programH, mCenterBlockIndex[variant], CENTER_UBO_BINDING);
768
       }
769 36d65d88 Leszek Koltunski
     }
770
771 044b5494 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
772 6c00149d Leszek Koltunski
/**
773
 * Not part of public API, do not document (public only because has to be used from the main package)
774
 *
775
 * @y.exclude
776
 */
777 da681e7e Leszek Koltunski
   public void bindVertexAttribs(DistortedProgram program)
778 6c00149d Leszek Koltunski
     {
779 71d8aba1 Leszek Koltunski
     if( mJobNode[0]!=null )
780 f046b159 Leszek Koltunski
       {
781 71d8aba1 Leszek Koltunski
       mJobNode[0].execute();  // this will set itself to null
782 bc2ab8c5 Leszek Koltunski
/*
783
       try
784
         {
785
         String name = "/sdcard/"+mNumVertices+".dmesh";
786 7a9edb92 Leszek Koltunski
         DataOutputStream dos = new DataOutputStream(new java.io.FileOutputStream(name));
787 bc2ab8c5 Leszek Koltunski
         write(dos);
788 9f28e9b6 Leszek Koltunski
         android.util.Log.e("mesh", "file written: "+name);
789 bc2ab8c5 Leszek Koltunski
         }
790 7a9edb92 Leszek Koltunski
       catch(java.io.FileNotFoundException ex)
791 bc2ab8c5 Leszek Koltunski
         {
792
         android.util.Log.e("mesh", "file not found exception: "+ex.toString());
793
         }
794
 */
795 f046b159 Leszek Koltunski
       }
796
797 0bd9f644 Leszek Koltunski
     int index1 = mVBO1.createImmediatelyFloat(mNumVertices*VERT1_SIZE, mVertAttribs1);
798
     int index2 = mVBO2.createImmediatelyFloat(mNumVertices*VERT2_SIZE, mVertAttribs2);
799 22e60fba Leszek Koltunski
800 e54bfada Leszek Koltunski
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index1 );
801
     GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_POS);
802
     GLES30.glVertexAttribPointer(program.mAttribute[1], NOR_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_NOR);
803
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index2 );
804 a2878a67 Leszek Koltunski
     GLES30.glVertexAttribPointer(program.mAttribute[2], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_TEX);
805
     GLES30.glVertexAttribPointer(program.mAttribute[3], COM_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_COM);
806 b7074bc6 Leszek Koltunski
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
807 da681e7e Leszek Koltunski
     }
808
809
///////////////////////////////////////////////////////////////////////////////////////////////////
810
/**
811
 * Not part of public API, do not document (public only because has to be used from the main package)
812
 *
813
 * @y.exclude
814
 */
815
   public void bindTransformAttribs(DistortedProgram program)
816
     {
817 0bd9f644 Leszek Koltunski
     int index = mTFO.createImmediatelyFloat(mNumVertices*TRAN_SIZE, null);
818 22e60fba Leszek Koltunski
819 b7074bc6 Leszek Koltunski
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index );
820
     GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, 0);
821
     GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
822 6c00149d Leszek Koltunski
     }
823
824 7a5e538a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
825
/**
826
 * Not part of public API, do not document (public only because has to be used from the main package)
827
 *
828
 * @y.exclude
829
 */
830
   public void setInflate(float inflate)
831
     {
832
     mInflate = inflate;
833
     }
834
835
///////////////////////////////////////////////////////////////////////////////////////////////////
836
/**
837
 * Not part of public API, do not document (public only because has to be used from the main package)
838
 *
839
 * @y.exclude
840
 */
841
   public float getInflate()
842
     {
843
     return mInflate;
844
     }
845
846 466450b5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
847 54ce4c6f Leszek Koltunski
// Return the number of bytes read.
848 22422a76 Leszek Koltunski
849 54ce4c6f Leszek Koltunski
   int read(DataInputStream stream)
850 10836924 Leszek Koltunski
     {
851 bc2ab8c5 Leszek Koltunski
     byte[] buffer = new byte[BYTES_PER_FLOAT*4];
852
     int version, numEff, numTex;
853 22422a76 Leszek Koltunski
854 7a9edb92 Leszek Koltunski
     //////////////////////////////////////////////////////////////////////////////////////////
855
     // read version, number of vertices, number of tex components, number of effect components
856
     //////////////////////////////////////////////////////////////////////////////////////////
857
858 22422a76 Leszek Koltunski
     try
859
       {
860 bc2ab8c5 Leszek Koltunski
       stream.read(buffer);
861
       ByteBuffer byteBuf = ByteBuffer.wrap(buffer);
862 22422a76 Leszek Koltunski
863 bc2ab8c5 Leszek Koltunski
       version = byteBuf.getInt(0);
864 22422a76 Leszek Koltunski
865 a2878a67 Leszek Koltunski
       if( version==1 || version==2 )
866 22422a76 Leszek Koltunski
         {
867 bc2ab8c5 Leszek Koltunski
         mNumVertices= byteBuf.getInt(4);
868
         numTex      = byteBuf.getInt(8);
869
         numEff      = byteBuf.getInt(12);
870 22422a76 Leszek Koltunski
         }
871
       else
872
         {
873 bc2ab8c5 Leszek Koltunski
         android.util.Log.e("mesh", "Error: unknown mesh file version "+String.format("0x%08X", version));
874 54ce4c6f Leszek Koltunski
         return 0;
875 22422a76 Leszek Koltunski
         }
876
       }
877
     catch(IOException e)
878
       {
879 bc2ab8c5 Leszek Koltunski
       android.util.Log.e("mesh", "IOException1 trying to read file: "+e.toString());
880 54ce4c6f Leszek Koltunski
       return 0;
881 22422a76 Leszek Koltunski
       }
882
883 7a9edb92 Leszek Koltunski
     //////////////////////////////////////////////////////////////////////////////////////////
884
     // read contents of all texture and effect components
885
     //////////////////////////////////////////////////////////////////////////////////////////
886
887 bc2ab8c5 Leszek Koltunski
     if( mNumVertices>0 && numEff>0 && numTex>0 )
888 22422a76 Leszek Koltunski
       {
889
       int size = numEff+TEX_COMP_SIZE*numTex;
890
       float[] tmp = new float[size];
891 bc2ab8c5 Leszek Koltunski
       mVertAttribs1 = new float[VERT1_ATTRIBS*mNumVertices];
892
       mVertAttribs2 = new float[VERT2_ATTRIBS*mNumVertices];
893 22422a76 Leszek Koltunski
894 a2878a67 Leszek Koltunski
       // version 1 had extra 3 floats (the 'inflate' vector) in its vert1 array
895 7a9edb92 Leszek Koltunski
       int vert1InFile = version==2 ? VERT1_ATTRIBS : VERT1_ATTRIBS+3;
896
       // ... and there was no center.
897
       int centerSize  = version==2 ? 3*numEff : 0;
898 a2878a67 Leszek Koltunski
899 7a9edb92 Leszek Koltunski
       buffer = new byte[BYTES_PER_FLOAT*(size + centerSize + mNumVertices*(vert1InFile+VERT2_ATTRIBS))];
900 22422a76 Leszek Koltunski
901 bc2ab8c5 Leszek Koltunski
       try
902
         {
903
         stream.read(buffer);
904
         }
905
       catch(IOException e)
906
         {
907
         android.util.Log.e("mesh", "IOException2 trying to read file: "+e.toString());
908 54ce4c6f Leszek Koltunski
         return 0;
909 bc2ab8c5 Leszek Koltunski
         }
910
911
       ByteBuffer byteBuf = ByteBuffer.wrap(buffer);
912
       FloatBuffer floatBuf = byteBuf.asFloatBuffer();
913 22422a76 Leszek Koltunski
914 bc2ab8c5 Leszek Koltunski
       floatBuf.get(tmp,0,size);
915 a2878a67 Leszek Koltunski
916 22422a76 Leszek Koltunski
       TexComponent tex;
917
       int index, texComp;
918
       float x, y, z, w;
919
920
       for(texComp=0; texComp<numTex; texComp++)
921
         {
922
         index = (int)tmp[TEX_COMP_SIZE*texComp];
923
924
         x= tmp[TEX_COMP_SIZE*texComp+1];
925
         y= tmp[TEX_COMP_SIZE*texComp+2];
926
         z= tmp[TEX_COMP_SIZE*texComp+3];
927
         w= tmp[TEX_COMP_SIZE*texComp+4];
928
929
         tex = new TexComponent(index);
930
         tex.setMap(new Static4D(x,y,z,w));
931 10836924 Leszek Koltunski
932 22422a76 Leszek Koltunski
         mTexComponent.add(tex);
933
         }
934
935
       for(int effComp=0; effComp<numEff; effComp++)
936
         {
937
         index = (int)tmp[TEX_COMP_SIZE*texComp + effComp ];
938
         mEffComponent.add(index);
939
         }
940 7a9edb92 Leszek Koltunski
941
       //////////////////////////////////////////////////////////////////////////////////////////
942
       // read vert1 array, vert2 array and (if version>1) the component centers.
943
       //////////////////////////////////////////////////////////////////////////////////////////
944
945
       switch(version)
946
         {
947
         case 1 : index = floatBuf.position();
948
949
                  for(int vert=0; vert<mNumVertices; vert++)
950
                    {
951
                    mVertAttribs1[VERT1_ATTRIBS*vert+POS_ATTRIB  ] = floatBuf.get(index+POS_ATTRIB  );
952
                    mVertAttribs1[VERT1_ATTRIBS*vert+POS_ATTRIB+1] = floatBuf.get(index+POS_ATTRIB+1);
953
                    mVertAttribs1[VERT1_ATTRIBS*vert+POS_ATTRIB+2] = floatBuf.get(index+POS_ATTRIB+2);
954
                    mVertAttribs1[VERT1_ATTRIBS*vert+NOR_ATTRIB  ] = floatBuf.get(index+NOR_ATTRIB  );
955
                    mVertAttribs1[VERT1_ATTRIBS*vert+NOR_ATTRIB+1] = floatBuf.get(index+NOR_ATTRIB+1);
956
                    mVertAttribs1[VERT1_ATTRIBS*vert+NOR_ATTRIB+2] = floatBuf.get(index+NOR_ATTRIB+2);
957
                    index+=vert1InFile;
958
                    }
959
                  floatBuf.position(index);
960
                  break;
961
         case 2 : float[] centers = new float[3*numEff];
962
                  floatBuf.get(centers,0,3*numEff);
963
964 46d463a4 Leszek Koltunski
                  if( mUseCenters )
965 7a9edb92 Leszek Koltunski
                    {
966 46d463a4 Leszek Koltunski
                    for(int eff=0; eff<numEff; eff++)
967
                      {
968
                      mUBC.setEffectCenterNow(eff, centers[3*eff], centers[3*eff+1], centers[3*eff+2]);
969
                      }
970 7a9edb92 Leszek Koltunski
                    }
971
972
                  floatBuf.get(mVertAttribs1, 0, VERT1_ATTRIBS*mNumVertices);
973
                  break;
974
         default: android.util.Log.e("mesh", "Error: unknown mesh file version "+String.format("0x%08X", version));
975
                  return 0;
976
         }
977
978
       floatBuf.get(mVertAttribs2, 0, VERT2_ATTRIBS*mNumVertices);
979 22422a76 Leszek Koltunski
       }
980 54ce4c6f Leszek Koltunski
981
     return BYTES_PER_FLOAT*( 4 + numEff+TEX_COMP_SIZE*numTex + VERT1_ATTRIBS*mNumVertices + VERT2_ATTRIBS*mNumVertices );
982 10836924 Leszek Koltunski
     }
983
984 524e4fe7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
985
/**
986
 * @y.exclude
987
 */
988
   public int getLastVertexEff(int effComponent)
989
     {
990
     if( effComponent>=0 && effComponent<mTexComponent.size() )
991
       {
992
       return mEffComponent.get(effComponent);
993
       }
994
995
     return 0;
996
     }
997
998
///////////////////////////////////////////////////////////////////////////////////////////////////
999
/**
1000
 * @y.exclude
1001
 */
1002
   public int getLastVertexTex(int texComponent)
1003
     {
1004
     if( texComponent>=0 && texComponent<mTexComponent.size() )
1005
       {
1006
       return mTexComponent.get(texComponent).mEndIndex;
1007
       }
1008
1009
     return 0;
1010
     }
1011
1012 22422a76 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1013
// PUBLIC API
1014 10836924 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1015
/**
1016 22422a76 Leszek Koltunski
 * Write the Mesh to a File.
1017 10836924 Leszek Koltunski
 */
1018 bc2ab8c5 Leszek Koltunski
   public void write(DataOutputStream stream)
1019 10836924 Leszek Koltunski
     {
1020 22422a76 Leszek Koltunski
     TexComponent tex;
1021
1022
     int numTex = mTexComponent.size();
1023
     int numEff = mEffComponent.size();
1024
1025 bc2ab8c5 Leszek Koltunski
     try
1026 22422a76 Leszek Koltunski
       {
1027 a2878a67 Leszek Koltunski
       stream.writeInt(2);  // version
1028 bc2ab8c5 Leszek Koltunski
       stream.writeInt(mNumVertices);
1029
       stream.writeInt(numTex);
1030
       stream.writeInt(numEff);
1031 22422a76 Leszek Koltunski
1032 bc2ab8c5 Leszek Koltunski
       for(int i=0; i<numTex; i++)
1033
         {
1034
         tex = mTexComponent.get(i);
1035 22422a76 Leszek Koltunski
1036 bc2ab8c5 Leszek Koltunski
         stream.writeFloat((float)tex.mEndIndex);
1037
         stream.writeFloat(tex.mTextureMap.get0());
1038
         stream.writeFloat(tex.mTextureMap.get1());
1039
         stream.writeFloat(tex.mTextureMap.get2());
1040
         stream.writeFloat(tex.mTextureMap.get3());
1041
         }
1042 22422a76 Leszek Koltunski
1043 bc2ab8c5 Leszek Koltunski
       for(int i=0; i<numEff; i++)
1044
         {
1045
         stream.writeFloat((float)mEffComponent.get(i));
1046
         }
1047 10836924 Leszek Koltunski
1048 46d463a4 Leszek Koltunski
       float[] centers = mUseCenters ? mUBC.getBackingArray() : new float[4*numEff];
1049 7a9edb92 Leszek Koltunski
1050
       for(int i=0; i<numEff; i++)
1051
         {
1052
         stream.writeFloat(centers[4*i  ]);
1053
         stream.writeFloat(centers[4*i+1]);
1054
         stream.writeFloat(centers[4*i+2]);
1055
         }
1056
1057 bc2ab8c5 Leszek Koltunski
       ByteBuffer vertBuf1 = ByteBuffer.allocate(VERT1_SIZE*mNumVertices);
1058
       vertBuf1.asFloatBuffer().put(mVertAttribs1);
1059
       ByteBuffer vertBuf2 = ByteBuffer.allocate(VERT2_SIZE*mNumVertices);
1060
       vertBuf2.asFloatBuffer().put(mVertAttribs2);
1061
1062
       stream.write(vertBuf1.array());
1063
       stream.write(vertBuf2.array());
1064 22422a76 Leszek Koltunski
       }
1065 bc2ab8c5 Leszek Koltunski
     catch(IOException ex)
1066 22422a76 Leszek Koltunski
       {
1067 bc2ab8c5 Leszek Koltunski
       android.util.Log.e("mesh", "IOException trying to write a mesh: "+ex.toString());
1068 22422a76 Leszek Koltunski
       }
1069 10836924 Leszek Koltunski
     }
1070
1071
///////////////////////////////////////////////////////////////////////////////////////////////////
1072 3fc9327a Leszek Koltunski
/**
1073
 * When rendering this Mesh, do we want to render the Normal vectors as well?
1074 420836fc leszek
 * <p>
1075
 * Will work only on OpenGL ES >= 3.0 devices.
1076 3fc9327a Leszek Koltunski
 *
1077
 * @param show Controls if we render the Normal vectors or not.
1078
 */
1079
   public void setShowNormals(boolean show)
1080
     {
1081 b7074bc6 Leszek Koltunski
     mShowNormals = show;
1082 3fc9327a Leszek Koltunski
     }
1083 466450b5 Leszek Koltunski
1084 6c00149d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1085
/**
1086
 * When rendering this mesh, should we also draw the normal vectors?
1087
 *
1088
 * @return <i>true</i> if we do render normal vectors
1089
 */
1090
   public boolean getShowNormals()
1091
     {
1092
     return mShowNormals;
1093
     }
1094
1095 a8dfedcc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1096
/**
1097 e8925fcd Leszek Koltunski
 * Merge all texture components of this Mesh into a single one.
1098 a8dfedcc Leszek Koltunski
 */
1099 e8925fcd Leszek Koltunski
   public void mergeTexComponents()
1100 a8dfedcc Leszek Koltunski
     {
1101 1fad573e Leszek Koltunski
     if( mJobNode[0]==null )
1102 a8dfedcc Leszek Koltunski
       {
1103 e8925fcd Leszek Koltunski
       mergeTexComponentsNow();
1104 a8dfedcc Leszek Koltunski
       }
1105
     else
1106
       {
1107 e8925fcd Leszek Koltunski
       mJobNode[0] = DeferredJobs.mergeTex(this);
1108
       }
1109
     }
1110
1111
///////////////////////////////////////////////////////////////////////////////////////////////////
1112
/**
1113
 * Merge all effect components of this Mesh into a single one.
1114
 */
1115
   public void mergeEffComponents()
1116
     {
1117
     if( mJobNode[0]==null )
1118
       {
1119
       mergeEffComponentsNow();
1120
       }
1121
     else
1122
       {
1123
       mJobNode[0] = DeferredJobs.mergeEff(this);
1124 a8dfedcc Leszek Koltunski
       }
1125
     }
1126
1127 466450b5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1128
/**
1129
 * Release all internal resources.
1130
 */
1131
   public void markForDeletion()
1132
     {
1133 e54bfada Leszek Koltunski
     mVertAttribs1 = null;
1134
     mVertAttribs2 = null;
1135 466450b5 Leszek Koltunski
1136 e54bfada Leszek Koltunski
     mVBO1.markForDeletion();
1137
     mVBO2.markForDeletion();
1138 466450b5 Leszek Koltunski
     mTFO.markForDeletion();
1139 8b36dabf Leszek Koltunski
     mUBA.markForDeletion();
1140 46d463a4 Leszek Koltunski
1141
     if( mUBC!=null )
1142
       {
1143
       mUBC.markForDeletion();
1144
       }
1145 466450b5 Leszek Koltunski
     }
1146 fa8bc998 Leszek Koltunski
1147 e8925fcd Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1148
/**
1149
 * Apply a Matrix Effect to the components which match the (addAssoc,equAssoc) association.
1150
 * <p>
1151
 * This is a static, permanent modification of the vertices contained in this Mesh. If the effect
1152
 * contains any Dynamics, they will be evaluated at 0.
1153
 *
1154
 * @param effect List of Matrix Effects to apply to the Mesh.
1155
 * @param andAssoc 'Logical AND' association which defines which components will be affected.
1156
 * @param equAssoc 'equality' association which defines which components will be affected.
1157
 */
1158
   public void apply(MatrixEffect effect, int andAssoc, int equAssoc)
1159
     {
1160
     if( mJobNode[0]==null )
1161
       {
1162
       applyMatrix(effect,andAssoc,equAssoc);
1163
       }
1164
     else
1165
       {
1166
       mJobNode[0] = DeferredJobs.matrix(this,effect,andAssoc,equAssoc);
1167
       }
1168
     }
1169
1170 fa8bc998 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1171
/**
1172 f046b159 Leszek Koltunski
 * Apply a Vertex Effect to the vertex mesh.
1173 fa8bc998 Leszek Koltunski
 * <p>
1174 c90aca24 Leszek Koltunski
 * This is a static, permanent modification of the vertices contained in this Mesh. If the effects
1175 f046b159 Leszek Koltunski
 * contain any Dynamics, the Dynamics will be evaluated at 0.
1176 fa8bc998 Leszek Koltunski
 *
1177 f046b159 Leszek Koltunski
 * We would call this several times building up a list of Effects to do. This list of effects gets
1178
 * lazily executed only when the Mesh is used for rendering for the first time.
1179 e172985c Leszek Koltunski
 *
1180 f046b159 Leszek Koltunski
 * @param effect Vertex Effect to apply to the Mesh.
1181 fa8bc998 Leszek Koltunski
 */
1182 f046b159 Leszek Koltunski
   public void apply(VertexEffect effect)
1183 fa8bc998 Leszek Koltunski
     {
1184 71d8aba1 Leszek Koltunski
     mJobNode[0] = DeferredJobs.vertex(this,effect);
1185 c90aca24 Leszek Koltunski
     }
1186
1187
///////////////////////////////////////////////////////////////////////////////////////////////////
1188
/**
1189 a3a05347 Leszek Koltunski
 * Sets texture maps for (some of) the components of this mesh.
1190 c90aca24 Leszek Koltunski
 * <p>
1191 a3a05347 Leszek Koltunski
 * Format: ( x of lower-left corner, y of lower-left corner, width, height ).
1192
 * For example maps[0] = new Static4D( 0.0, 0.5, 0.5, 0.5 ) sets the 0th component texture map to the
1193 0d4aae88 Leszek Koltunski
 * upper-left quadrant of the texture.
1194 a3a05347 Leszek Koltunski
 * <p>
1195
 * Probably the most common user case would be sending as many maps as there are components in this
1196
 * Mesh. One can also send less, or more (the extraneous ones will be ignored) and set some of them
1197
 * to null (those will be ignored as well). So if there are 5 components, and we want to set the map
1198
 * of the 2nd and 4rd one, call this with
1199
 * maps = new Static4D[4]
1200
 * maps[0] = null
1201
 * maps[1] = the map for the 2nd component
1202
 * maps[2] = null
1203
 * maps[3] = the map for the 4th component
1204
 *
1205
 * A map's width and height have to be non-zero (but can be negative!)
1206 e172985c Leszek Koltunski
 *
1207 dbe3079d Leszek Koltunski
 * @param maps            List of texture maps to apply to the texture's components.
1208
 * @param startComponent  the component the first of the maps refers to.
1209 c90aca24 Leszek Koltunski
 */
1210 dbe3079d Leszek Koltunski
   public void setTextureMap(Static4D[] maps, int startComponent)
1211 c90aca24 Leszek Koltunski
     {
1212 1fad573e Leszek Koltunski
     if( mJobNode[0]==null )
1213 ea88d502 Leszek Koltunski
       {
1214 dbe3079d Leszek Koltunski
       textureMap(maps,startComponent);
1215 1fad573e Leszek Koltunski
       }
1216
     else
1217
       {
1218 dbe3079d Leszek Koltunski
       mJobNode[0] = DeferredJobs.textureMap(this,maps,startComponent);
1219 ea88d502 Leszek Koltunski
       }
1220 fa8bc998 Leszek Koltunski
     }
1221 9099e567 Leszek Koltunski
1222 e172985c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1223
/**
1224
 * Return the texture map of one of the components.
1225
 *
1226
 * @param component The component number whose texture map we want to retrieve.
1227
 */
1228
   public Static4D getTextureMap(int component)
1229
     {
1230 e8925fcd Leszek Koltunski
     return (component>=0 && component<mTexComponent.size()) ? mTexComponent.get(component).mTextureMap : null;
1231 e172985c Leszek Koltunski
     }
1232 cbd502ec Leszek Koltunski
1233
///////////////////////////////////////////////////////////////////////////////////////////////////
1234
/**
1235 1e672c1d Leszek Koltunski
 * Set Effect association.
1236 bc208a9c Leszek Koltunski
 *
1237 1e672c1d Leszek Koltunski
 * This creates an association between a Component of this Mesh and a Vertex Effect.
1238 2aeb75aa Leszek Koltunski
 * One can set two types of associations - an 'logical and' and a 'equal' associations and the Effect
1239
 * will only be active on vertices of Components such that
1240 36d65d88 Leszek Koltunski
 *
1241 2aeb75aa Leszek Koltunski
 * (effect andAssoc) & (component andAssoc) != 0 || (effect equAssoc) == (mesh equAssoc)
1242 36d65d88 Leszek Koltunski
 *
1243
 * (see main_vertex_shader)
1244 bc208a9c Leszek Koltunski
 *
1245
 * The point: this way we can configure the system so that each Vertex Effect acts only on a certain
1246 1e672c1d Leszek Koltunski
 * subset of a Mesh, thus potentially significantly reducing the number of render calls.
1247 cbd502ec Leszek Koltunski
 */
1248 26671ef8 Leszek Koltunski
   public void setEffectAssociation(int component, int andAssociation, int equAssociation)
1249
     {
1250
     if( component>=0 && component<MAX_EFFECT_COMPONENTS )
1251
       {
1252
       if( mJobNode[0]==null )
1253
         {
1254
         setEffectAssociationNow(component, andAssociation, equAssociation);
1255
         }
1256
       else
1257
         {
1258
         mJobNode[0] = DeferredJobs.effectAssoc(this,component,andAssociation,equAssociation);
1259
         }
1260
       }
1261
     }
1262 bc208a9c Leszek Koltunski
1263 7a9edb92 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1264
/**
1265
 * Set center of a Component.
1266
 *
1267
 * A 'center' of a (effect) component is a 3D point in space. The array of centers gets sent to
1268
 * the vertex shader as a Uniform Buffer Object; in the vertex shader we can then use it to compute
1269
 * the 'Inflation' of the whole Mesh per-component. 'Inflation' is needed by postprocess effects to
1270
 * add the 'halo' around an object.
1271
 *
1272
 * This is all 'per-component' so that a user has a chance to make the halo look right in case of
1273
 * non-convex meshes: then we need to ensure that each component of such a mesh is a convex
1274
 * sub-mesh with its center being more-or-less the center of gravity of the sub-mesh.
1275
 */
1276
   public void setComponentCenter(int component, float centerX, float centerY, float centerZ)
1277
     {
1278
     if( component>=0 && component<MAX_EFFECT_COMPONENTS )
1279
       {
1280
       if( mJobNode[0]==null )
1281
         {
1282
         setComponentCenterNow(component, centerX, centerY, centerZ);
1283
         }
1284
       else
1285
         {
1286
         mJobNode[0] = DeferredJobs.componentCenter(this,component,centerX, centerY, centerZ);
1287
         }
1288
       }
1289
     }
1290
1291 c92c163c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1292
/**
1293
 * Adds an empty (no vertices) texture component to the end of the text component list.
1294
 *
1295
 * Sometimes we want to do this to have several Meshes with equal number of tex components each.
1296
 */
1297
   public void addEmptyTexComponent()
1298
     {
1299
      if( mJobNode[0]==null )
1300
       {
1301
       addEmptyTexComponentNow();
1302
       }
1303
     else
1304
       {
1305
       mJobNode[0] = DeferredJobs.addEmptyTex(this);
1306
       }
1307
     }
1308
1309 524e4fe7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1310
/**
1311
 * Return the number of texture components, i.e. individual subsets of the whole set of vertices
1312
 * which can be independently textured.
1313
 *
1314
 * @return The number of Texture Components of this Mesh.
1315
 */
1316
   public int numTexComponents()
1317
     {
1318
     return mTexComponent.size();
1319
     }
1320
1321
///////////////////////////////////////////////////////////////////////////////////////////////////
1322
/**
1323
 * Return the number of 'effect' components, i.e. individual subsets of the whole set of vertices
1324
 * to which a VertexEffect can be addressed, independently of other vertices.
1325
 *
1326
 * @return The number of Effect Components of this Mesh.
1327
 */
1328
   public int numEffComponents()
1329
     {
1330
     return mEffComponent.size();
1331
     }
1332
1333 bc208a9c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1334
/**
1335 4f81e0c8 Leszek Koltunski
 * Copy the Mesh.
1336
 *
1337
 * @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
1338 a2878a67 Leszek Koltunski
 *             and normals (the rest, in particular the mVertAttribs2 containing texture
1339 36d65d88 Leszek Koltunski
 *             coordinates and effect associations, is always deep copied)
1340 bc208a9c Leszek Koltunski
 */
1341 4f81e0c8 Leszek Koltunski
   public abstract MeshBase copy(boolean deep);
1342 bc208a9c Leszek Koltunski
   }