Project

General

Profile

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

library / src / main / java / org / distorted / library / mesh / MeshBase.java @ 7958d843

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