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 |
36d65d88
|
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 |
6c00149d
|
Leszek Koltunski
|
|
33 |
f046b159
|
Leszek Koltunski
|
import java.nio.ByteBuffer;
|
34 |
|
|
import java.nio.ByteOrder;
|
35 |
|
|
import java.nio.FloatBuffer;
|
36 |
c90aca24
|
Leszek Koltunski
|
import java.util.ArrayList;
|
37 |
6a06a912
|
Leszek Koltunski
|
|
38 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39 |
e0b6c593
|
Leszek Koltunski
|
/**
|
40 |
e5ba319d
|
Leszek Koltunski
|
* Abstract class which represents a Mesh, ie an array of vertices (rendered as a TRIANGLE_STRIP).
|
41 |
e0b6c593
|
Leszek Koltunski
|
* <p>
|
42 |
da681e7e
|
Leszek Koltunski
|
* If you want to render to a particular shape, extend from here, construct a float array
|
43 |
7a5e538a
|
Leszek Koltunski
|
* containing per-vertex attributes, and call back setAttribs().
|
44 |
e0b6c593
|
Leszek Koltunski
|
*/
|
45 |
715e7726
|
Leszek Koltunski
|
public abstract class MeshBase
|
46 |
6a06a912
|
Leszek Koltunski
|
{
|
47 |
e8925fcd
|
Leszek Koltunski
|
private static final int MAX_EFFECT_COMPONENTS= 100;
|
48 |
07206c71
|
Leszek Koltunski
|
private static final int DEFAULT_ASSOCIATION = 0xffffffff;
|
49 |
bc208a9c
|
Leszek Koltunski
|
|
50 |
227b9bca
|
Leszek Koltunski
|
// sizes of attributes of an individual vertex.
|
51 |
|
|
private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z
|
52 |
|
|
private static final int NOR_DATA_SIZE= 3; // normal vector: x,y,z
|
53 |
|
|
private static final int INF_DATA_SIZE= 3; // 'inflate' vector: x,y,z
|
54 |
7a5e538a
|
Leszek Koltunski
|
private static final int TEX_DATA_SIZE= 2; // texture coordinates: s,t
|
55 |
36d65d88
|
Leszek Koltunski
|
private static final int COM_DATA_SIZE= 1; // component number, a single float
|
56 |
6f2d931d
|
Leszek Koltunski
|
|
57 |
|
|
static final int POS_ATTRIB = 0;
|
58 |
|
|
static final int NOR_ATTRIB = POS_DATA_SIZE;
|
59 |
|
|
static final int INF_ATTRIB = POS_DATA_SIZE + NOR_DATA_SIZE;
|
60 |
e54bfada
|
Leszek Koltunski
|
static final int TEX_ATTRIB = 0;
|
61 |
36d65d88
|
Leszek Koltunski
|
static final int COM_ATTRIB = TEX_DATA_SIZE;
|
62 |
bc208a9c
|
Leszek Koltunski
|
|
63 |
e54bfada
|
Leszek Koltunski
|
static final int VERT1_ATTRIBS= POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE; // number of attributes of a vertex (the part changed by preapply)
|
64 |
36d65d88
|
Leszek Koltunski
|
static final int VERT2_ATTRIBS= TEX_DATA_SIZE + COM_DATA_SIZE; // number of attributes of a vertex (the 'preapply invariant' part)
|
65 |
e54bfada
|
Leszek Koltunski
|
static final int TRAN_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE; // number of attributes of a transform feedback vertex
|
66 |
6a06a912
|
Leszek Koltunski
|
|
67 |
da681e7e
|
Leszek Koltunski
|
private static final int BYTES_PER_FLOAT = 4;
|
68 |
3ef3364d
|
Leszek Koltunski
|
|
69 |
6f2d931d
|
Leszek Koltunski
|
private static final int OFFSET_POS = POS_ATTRIB*BYTES_PER_FLOAT;
|
70 |
|
|
private static final int OFFSET_NOR = NOR_ATTRIB*BYTES_PER_FLOAT;
|
71 |
|
|
private static final int OFFSET_INF = INF_ATTRIB*BYTES_PER_FLOAT;
|
72 |
|
|
private static final int OFFSET_TEX = TEX_ATTRIB*BYTES_PER_FLOAT;
|
73 |
36d65d88
|
Leszek Koltunski
|
private static final int OFFSET_COM = COM_ATTRIB*BYTES_PER_FLOAT;
|
74 |
bc208a9c
|
Leszek Koltunski
|
|
75 |
227b9bca
|
Leszek Koltunski
|
private static final int TRAN_SIZE = TRAN_ATTRIBS*BYTES_PER_FLOAT;
|
76 |
e54bfada
|
Leszek Koltunski
|
private static final int VERT1_SIZE = VERT1_ATTRIBS*BYTES_PER_FLOAT;
|
77 |
|
|
private static final int VERT2_SIZE = VERT2_ATTRIBS*BYTES_PER_FLOAT;
|
78 |
a51fe521
|
Leszek Koltunski
|
|
79 |
e54bfada
|
Leszek Koltunski
|
private boolean mShowNormals; // when rendering this mesh, draw normal vectors?
|
80 |
|
|
private InternalBuffer mVBO1, mVBO2, mTFO; // main vertex buffer and transform feedback buffer
|
81 |
da681e7e
|
Leszek Koltunski
|
private int mNumVertices;
|
82 |
e54bfada
|
Leszek Koltunski
|
private float[] mVertAttribs1; // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ
|
83 |
36d65d88
|
Leszek Koltunski
|
private float[] mVertAttribs2; // packed: TexS,TexT, Component
|
84 |
7a5e538a
|
Leszek Koltunski
|
private float mInflate;
|
85 |
2aeb75aa
|
Leszek Koltunski
|
private int[] mEquAssociation;
|
86 |
|
|
private int[] mAndAssociation;
|
87 |
36d65d88
|
Leszek Koltunski
|
|
88 |
71d8aba1
|
Leszek Koltunski
|
DeferredJobs.JobNode[] mJobNode;
|
89 |
07206c71
|
Leszek Koltunski
|
|
90 |
2aeb75aa
|
Leszek Koltunski
|
private static int[] mEquAssociationH = new int[EffectQueue.MAIN_VARIANTS];
|
91 |
|
|
private static int[] mAndAssociationH = new int[EffectQueue.MAIN_VARIANTS];
|
92 |
3ef3364d
|
Leszek Koltunski
|
|
93 |
e8925fcd
|
Leszek Koltunski
|
private static class TexComponent
|
94 |
c90aca24
|
Leszek Koltunski
|
{
|
95 |
|
|
private int mEndIndex;
|
96 |
a3a05347
|
Leszek Koltunski
|
private Static4D mTextureMap;
|
97 |
c90aca24
|
Leszek Koltunski
|
|
98 |
e8925fcd
|
Leszek Koltunski
|
TexComponent(int end)
|
99 |
c90aca24
|
Leszek Koltunski
|
{
|
100 |
a3a05347
|
Leszek Koltunski
|
mEndIndex = end;
|
101 |
|
|
mTextureMap= new Static4D(0,0,1,1);
|
102 |
c90aca24
|
Leszek Koltunski
|
}
|
103 |
e8925fcd
|
Leszek Koltunski
|
TexComponent(TexComponent original)
|
104 |
c90aca24
|
Leszek Koltunski
|
{
|
105 |
|
|
mEndIndex = original.mEndIndex;
|
106 |
a3a05347
|
Leszek Koltunski
|
|
107 |
|
|
float x = original.mTextureMap.get0();
|
108 |
|
|
float y = original.mTextureMap.get1();
|
109 |
|
|
float z = original.mTextureMap.get2();
|
110 |
|
|
float w = original.mTextureMap.get3();
|
111 |
|
|
mTextureMap = new Static4D(x,y,z,w);
|
112 |
0d4aae88
|
Leszek Koltunski
|
}
|
113 |
|
|
|
114 |
a3a05347
|
Leszek Koltunski
|
void setMap(Static4D map)
|
115 |
0d4aae88
|
Leszek Koltunski
|
{
|
116 |
a3a05347
|
Leszek Koltunski
|
mTextureMap.set(map.get0(),map.get1(),map.get2(),map.get3());
|
117 |
c90aca24
|
Leszek Koltunski
|
}
|
118 |
|
|
}
|
119 |
|
|
|
120 |
e8925fcd
|
Leszek Koltunski
|
private ArrayList<TexComponent> mTexComponent;
|
121 |
|
|
private ArrayList<Integer> mEffComponent;
|
122 |
c90aca24
|
Leszek Koltunski
|
|
123 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
124 |
3ef3364d
|
Leszek Koltunski
|
|
125 |
0f10a0b6
|
Leszek Koltunski
|
MeshBase()
|
126 |
3ef3364d
|
Leszek Koltunski
|
{
|
127 |
e8925fcd
|
Leszek Koltunski
|
mShowNormals = false;
|
128 |
|
|
mInflate = 0.0f;
|
129 |
|
|
mTexComponent = new ArrayList<>();
|
130 |
|
|
mEffComponent = new ArrayList<>();
|
131 |
|
|
|
132 |
|
|
mEquAssociation= new int[MAX_EFFECT_COMPONENTS];
|
133 |
|
|
mAndAssociation= new int[MAX_EFFECT_COMPONENTS];
|
134 |
36d65d88
|
Leszek Koltunski
|
|
135 |
71d8aba1
|
Leszek Koltunski
|
mJobNode = new DeferredJobs.JobNode[1];
|
136 |
|
|
|
137 |
e8925fcd
|
Leszek Koltunski
|
for(int i=0; i<MAX_EFFECT_COMPONENTS; i++)
|
138 |
2aeb75aa
|
Leszek Koltunski
|
{
|
139 |
|
|
mAndAssociation[i] = DEFAULT_ASSOCIATION;
|
140 |
|
|
mEquAssociation[i] = i;
|
141 |
|
|
}
|
142 |
4f81e0c8
|
Leszek Koltunski
|
|
143 |
e54bfada
|
Leszek Koltunski
|
mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ);
|
144 |
|
|
mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ);
|
145 |
b7074bc6
|
Leszek Koltunski
|
mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ);
|
146 |
c90aca24
|
Leszek Koltunski
|
}
|
147 |
|
|
|
148 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
149 |
|
|
// copy constructor
|
150 |
|
|
|
151 |
4f81e0c8
|
Leszek Koltunski
|
MeshBase(MeshBase original, boolean deep)
|
152 |
c90aca24
|
Leszek Koltunski
|
{
|
153 |
1fad573e
|
Leszek Koltunski
|
mShowNormals= original.mShowNormals;
|
154 |
|
|
mInflate = original.mInflate;
|
155 |
|
|
mNumVertices= original.mNumVertices;
|
156 |
42571056
|
Leszek Koltunski
|
|
157 |
e8925fcd
|
Leszek Koltunski
|
mAndAssociation= new int[MAX_EFFECT_COMPONENTS];
|
158 |
|
|
System.arraycopy(original.mAndAssociation, 0, mAndAssociation, 0, MAX_EFFECT_COMPONENTS);
|
159 |
|
|
mEquAssociation= new int[MAX_EFFECT_COMPONENTS];
|
160 |
|
|
System.arraycopy(original.mEquAssociation, 0, mEquAssociation, 0, MAX_EFFECT_COMPONENTS);
|
161 |
36d65d88
|
Leszek Koltunski
|
|
162 |
4f81e0c8
|
Leszek Koltunski
|
if( deep )
|
163 |
|
|
{
|
164 |
71d8aba1
|
Leszek Koltunski
|
mJobNode = new DeferredJobs.JobNode[1];
|
165 |
1fad573e
|
Leszek Koltunski
|
if( original.mJobNode[0]==null ) copy(original);
|
166 |
|
|
else mJobNode[0] = DeferredJobs.copy(this,original);
|
167 |
4f81e0c8
|
Leszek Koltunski
|
}
|
168 |
|
|
else
|
169 |
|
|
{
|
170 |
71d8aba1
|
Leszek Koltunski
|
mJobNode = original.mJobNode;
|
171 |
|
|
mVBO1 = original.mVBO1;
|
172 |
|
|
mVertAttribs1 = original.mVertAttribs1;
|
173 |
1fad573e
|
Leszek Koltunski
|
shallowCopy(original);
|
174 |
4f81e0c8
|
Leszek Koltunski
|
}
|
175 |
cbd502ec
|
Leszek Koltunski
|
|
176 |
4f81e0c8
|
Leszek Koltunski
|
mTFO = new InternalBuffer(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, GLES30.GL_STATIC_READ);
|
177 |
cbd502ec
|
Leszek Koltunski
|
mTFO.invalidate();
|
178 |
42571056
|
Leszek Koltunski
|
}
|
179 |
|
|
|
180 |
36d65d88
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
181 |
|
|
|
182 |
1fad573e
|
Leszek Koltunski
|
void copy(MeshBase original)
|
183 |
36d65d88
|
Leszek Koltunski
|
{
|
184 |
1fad573e
|
Leszek Koltunski
|
shallowCopy(original);
|
185 |
|
|
|
186 |
|
|
mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
|
187 |
|
|
mVertAttribs1= new float[mNumVertices*VERT1_ATTRIBS];
|
188 |
|
|
System.arraycopy(original.mVertAttribs1,0,mVertAttribs1,0,mNumVertices*VERT1_ATTRIBS);
|
189 |
|
|
mVBO1.invalidate();
|
190 |
36d65d88
|
Leszek Koltunski
|
}
|
191 |
|
|
|
192 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
193 |
|
|
|
194 |
1fad573e
|
Leszek Koltunski
|
private void shallowCopy(MeshBase original)
|
195 |
36d65d88
|
Leszek Koltunski
|
{
|
196 |
e8925fcd
|
Leszek Koltunski
|
int texComSize = original.mTexComponent.size();
|
197 |
|
|
mTexComponent = new ArrayList<>();
|
198 |
36d65d88
|
Leszek Koltunski
|
|
199 |
e8925fcd
|
Leszek Koltunski
|
for(int i=0; i<texComSize; i++)
|
200 |
1fad573e
|
Leszek Koltunski
|
{
|
201 |
e8925fcd
|
Leszek Koltunski
|
TexComponent comp = new TexComponent(original.mTexComponent.get(i));
|
202 |
|
|
mTexComponent.add(comp);
|
203 |
1fad573e
|
Leszek Koltunski
|
}
|
204 |
f4c5a46e
|
Leszek Koltunski
|
|
205 |
e8925fcd
|
Leszek Koltunski
|
mEffComponent = new ArrayList<>();
|
206 |
|
|
mEffComponent.addAll(original.mEffComponent);
|
207 |
|
|
|
208 |
1fad573e
|
Leszek Koltunski
|
mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER, GLES30.GL_STATIC_READ);
|
209 |
|
|
mVertAttribs2= new float[mNumVertices*VERT2_ATTRIBS];
|
210 |
|
|
System.arraycopy(original.mVertAttribs2,0,mVertAttribs2,0,mNumVertices*VERT2_ATTRIBS);
|
211 |
|
|
mVBO2.invalidate();
|
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 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
230 |
|
|
|
231 |
|
|
void mergeEffComponentsNow()
|
232 |
|
|
{
|
233 |
|
|
int num = mEffComponent.size();
|
234 |
|
|
|
235 |
|
|
if( num>1 )
|
236 |
|
|
{
|
237 |
|
|
mEffComponent.clear();
|
238 |
|
|
mEffComponent.add(mNumVertices-1);
|
239 |
a8dfedcc
|
Leszek Koltunski
|
|
240 |
|
|
for(int index=0; index<mNumVertices; index++)
|
241 |
|
|
{
|
242 |
|
|
mVertAttribs2[VERT2_ATTRIBS*index+COM_ATTRIB] = 0;
|
243 |
|
|
}
|
244 |
|
|
|
245 |
|
|
mVBO2.invalidate();
|
246 |
|
|
}
|
247 |
|
|
}
|
248 |
|
|
|
249 |
0d4aae88
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
250 |
|
|
|
251 |
e8925fcd
|
Leszek Koltunski
|
void applyMatrix(MatrixEffect effect, int andAssoc, int equAssoc)
|
252 |
|
|
{
|
253 |
|
|
float[] matrix = new float[16];
|
254 |
|
|
float[] uniforms = new float[7];
|
255 |
|
|
int start, end=-1, numComp = mEffComponent.size();
|
256 |
|
|
|
257 |
|
|
Matrix.setIdentityM(matrix,0);
|
258 |
|
|
effect.compute(uniforms,0,0,0);
|
259 |
|
|
effect.apply(matrix, uniforms, 0);
|
260 |
|
|
|
261 |
|
|
for(int i=0; i<numComp; i++)
|
262 |
|
|
{
|
263 |
f45e4279
|
Leszek Koltunski
|
start = end+1;
|
264 |
e8925fcd
|
Leszek Koltunski
|
end = mEffComponent.get(i);
|
265 |
|
|
|
266 |
|
|
if( (andAssoc & mAndAssociation[i]) != 0 || (equAssoc == mEquAssociation[i]) )
|
267 |
|
|
{
|
268 |
f45e4279
|
Leszek Koltunski
|
applyMatrixToComponent(matrix,start,end);
|
269 |
e8925fcd
|
Leszek Koltunski
|
}
|
270 |
|
|
}
|
271 |
|
|
|
272 |
|
|
mVBO1.invalidate();
|
273 |
|
|
}
|
274 |
|
|
|
275 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
276 |
|
|
|
277 |
|
|
private void applyMatrixToComponent(float[] matrix, int start, int end)
|
278 |
|
|
{
|
279 |
|
|
float x,y,z;
|
280 |
|
|
|
281 |
f45e4279
|
Leszek Koltunski
|
for(int index=start*VERT1_ATTRIBS; index<=end*VERT1_ATTRIBS; index+=VERT1_ATTRIBS )
|
282 |
e8925fcd
|
Leszek Koltunski
|
{
|
283 |
|
|
x = mVertAttribs1[index+POS_ATTRIB ];
|
284 |
|
|
y = mVertAttribs1[index+POS_ATTRIB+1];
|
285 |
|
|
z = mVertAttribs1[index+POS_ATTRIB+2];
|
286 |
|
|
|
287 |
|
|
mVertAttribs1[index+POS_ATTRIB ] = matrix[0]*x + matrix[4]*y + matrix[ 8]*z + matrix[12];
|
288 |
|
|
mVertAttribs1[index+POS_ATTRIB+1] = matrix[1]*x + matrix[5]*y + matrix[ 9]*z + matrix[13];
|
289 |
|
|
mVertAttribs1[index+POS_ATTRIB+2] = matrix[2]*x + matrix[6]*y + matrix[10]*z + matrix[14];
|
290 |
|
|
|
291 |
|
|
x = mVertAttribs1[index+NOR_ATTRIB ];
|
292 |
|
|
y = mVertAttribs1[index+NOR_ATTRIB+1];
|
293 |
|
|
z = mVertAttribs1[index+NOR_ATTRIB+2];
|
294 |
|
|
|
295 |
|
|
mVertAttribs1[index+NOR_ATTRIB ] = matrix[0]*x + matrix[4]*y + matrix[ 8]*z;
|
296 |
|
|
mVertAttribs1[index+NOR_ATTRIB+1] = matrix[1]*x + matrix[5]*y + matrix[ 9]*z;
|
297 |
|
|
mVertAttribs1[index+NOR_ATTRIB+2] = matrix[2]*x + matrix[6]*y + matrix[10]*z;
|
298 |
|
|
|
299 |
|
|
x = mVertAttribs1[index+INF_ATTRIB ];
|
300 |
|
|
y = mVertAttribs1[index+INF_ATTRIB+1];
|
301 |
|
|
z = mVertAttribs1[index+INF_ATTRIB+2];
|
302 |
|
|
|
303 |
|
|
mVertAttribs1[index+INF_ATTRIB ] = matrix[0]*x + matrix[4]*y + matrix[ 8]*z;
|
304 |
|
|
mVertAttribs1[index+INF_ATTRIB+1] = matrix[1]*x + matrix[5]*y + matrix[ 9]*z;
|
305 |
|
|
mVertAttribs1[index+INF_ATTRIB+2] = matrix[2]*x + matrix[6]*y + matrix[10]*z;
|
306 |
|
|
}
|
307 |
|
|
}
|
308 |
|
|
|
309 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
310 |
|
|
|
311 |
|
|
int numTexComponents()
|
312 |
|
|
{
|
313 |
|
|
return mTexComponent.size();
|
314 |
|
|
}
|
315 |
|
|
|
316 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
317 |
|
|
|
318 |
|
|
int numEffComponents()
|
319 |
0d4aae88
|
Leszek Koltunski
|
{
|
320 |
e8925fcd
|
Leszek Koltunski
|
return mEffComponent.size();
|
321 |
0d4aae88
|
Leszek Koltunski
|
}
|
322 |
|
|
|
323 |
42571056
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
324 |
6c00149d
|
Leszek Koltunski
|
// when a derived class is done computing its mesh, it has to call this method.
|
325 |
42571056
|
Leszek Koltunski
|
|
326 |
e54bfada
|
Leszek Koltunski
|
void setAttribs(float[] vert1Attribs, float[] vert2Attribs)
|
327 |
42571056
|
Leszek Koltunski
|
{
|
328 |
e54bfada
|
Leszek Koltunski
|
mNumVertices = vert1Attribs.length/VERT1_ATTRIBS;
|
329 |
|
|
mVertAttribs1= vert1Attribs;
|
330 |
|
|
mVertAttribs2= vert2Attribs;
|
331 |
da681e7e
|
Leszek Koltunski
|
|
332 |
e8925fcd
|
Leszek Koltunski
|
mTexComponent.add(new TexComponent(mNumVertices-1));
|
333 |
|
|
mEffComponent.add(mNumVertices-1);
|
334 |
c90aca24
|
Leszek Koltunski
|
|
335 |
e54bfada
|
Leszek Koltunski
|
mVBO1.invalidate();
|
336 |
|
|
mVBO2.invalidate();
|
337 |
42571056
|
Leszek Koltunski
|
}
|
338 |
|
|
|
339 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
340 |
|
|
|
341 |
1fad573e
|
Leszek Koltunski
|
void joinAttribs(MeshBase[] meshes)
|
342 |
226144d0
|
leszek
|
{
|
343 |
0d4aae88
|
Leszek Koltunski
|
MeshBase mesh;
|
344 |
e8925fcd
|
Leszek Koltunski
|
TexComponent comp;
|
345 |
a8dfedcc
|
Leszek Koltunski
|
int numMeshes = meshes.length;
|
346 |
e8925fcd
|
Leszek Koltunski
|
int numVertices,origVertices = mNumVertices;
|
347 |
|
|
int origTexComponents=0,numTexComponents;
|
348 |
|
|
int origEffComponents=0,numEffComponents;
|
349 |
044b5494
|
Leszek Koltunski
|
|
350 |
0d4aae88
|
Leszek Koltunski
|
if( origVertices>0 )
|
351 |
|
|
{
|
352 |
e8925fcd
|
Leszek Koltunski
|
origTexComponents = mTexComponent.size();
|
353 |
1fad573e
|
Leszek Koltunski
|
mNumVertices+= ( mNumVertices%2==1 ? 2:1 );
|
354 |
e8925fcd
|
Leszek Koltunski
|
mTexComponent.get(origTexComponents-1).mEndIndex = mNumVertices-1;
|
355 |
|
|
origEffComponents = mEffComponent.size();
|
356 |
|
|
mEffComponent.set(origEffComponents-1,mNumVertices-1);
|
357 |
0d4aae88
|
Leszek Koltunski
|
}
|
358 |
044b5494
|
Leszek Koltunski
|
|
359 |
e7f85322
|
Leszek Koltunski
|
for(int i=0; i<numMeshes; i++)
|
360 |
0d4aae88
|
Leszek Koltunski
|
{
|
361 |
|
|
mesh = meshes[i];
|
362 |
e8925fcd
|
Leszek Koltunski
|
numTexComponents = mesh.mTexComponent.size();
|
363 |
|
|
numEffComponents = mesh.mEffComponent.size();
|
364 |
36d65d88
|
Leszek Koltunski
|
numVertices = mesh.mNumVertices;
|
365 |
|
|
|
366 |
1fad573e
|
Leszek Koltunski
|
int extraVerticesBefore = mNumVertices==0 ? 0:1;
|
367 |
|
|
int extraVerticesAfter = (i==numMeshes-1) ? 0 : (numVertices%2==1 ? 2:1);
|
368 |
36d65d88
|
Leszek Koltunski
|
|
369 |
e8925fcd
|
Leszek Koltunski
|
for(int j=0; j<numTexComponents; j++)
|
370 |
0d4aae88
|
Leszek Koltunski
|
{
|
371 |
e8925fcd
|
Leszek Koltunski
|
comp = new TexComponent(mesh.mTexComponent.get(j));
|
372 |
1fad573e
|
Leszek Koltunski
|
comp.mEndIndex += (extraVerticesBefore+mNumVertices+extraVerticesAfter);
|
373 |
e8925fcd
|
Leszek Koltunski
|
mTexComponent.add(comp);
|
374 |
|
|
}
|
375 |
23b733db
|
Leszek Koltunski
|
|
376 |
e8925fcd
|
Leszek Koltunski
|
for(int j=0; j<numEffComponents; j++)
|
377 |
|
|
{
|
378 |
|
|
int index = mesh.mEffComponent.get(j);
|
379 |
|
|
index += (extraVerticesBefore+mNumVertices+extraVerticesAfter);
|
380 |
|
|
mEffComponent.add(index);
|
381 |
|
|
|
382 |
|
|
if( origEffComponents<MAX_EFFECT_COMPONENTS )
|
383 |
36d65d88
|
Leszek Koltunski
|
{
|
384 |
e8925fcd
|
Leszek Koltunski
|
mAndAssociation[origEffComponents] = mesh.mAndAssociation[j];
|
385 |
|
|
mEquAssociation[origEffComponents] = mesh.mEquAssociation[j];
|
386 |
|
|
origEffComponents++;
|
387 |
36d65d88
|
Leszek Koltunski
|
}
|
388 |
e7f85322
|
Leszek Koltunski
|
}
|
389 |
a8dfedcc
|
Leszek Koltunski
|
|
390 |
1fad573e
|
Leszek Koltunski
|
mNumVertices += (extraVerticesBefore+numVertices+extraVerticesAfter);
|
391 |
|
|
}
|
392 |
a8dfedcc
|
Leszek Koltunski
|
|
393 |
1fad573e
|
Leszek Koltunski
|
float[] newAttribs1 = new float[VERT1_ATTRIBS*mNumVertices];
|
394 |
e54bfada
|
Leszek Koltunski
|
float[] newAttribs2 = new float[VERT2_ATTRIBS*mNumVertices];
|
395 |
1fad573e
|
Leszek Koltunski
|
numVertices = origVertices;
|
396 |
0d4aae88
|
Leszek Koltunski
|
|
397 |
|
|
if( origVertices>0 )
|
398 |
|
|
{
|
399 |
e8925fcd
|
Leszek Koltunski
|
System.arraycopy(mVertAttribs1, 0, newAttribs1, 0, VERT1_ATTRIBS*numVertices);
|
400 |
|
|
System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS );
|
401 |
|
|
System.arraycopy(mVertAttribs2, 0, newAttribs2, 0, VERT2_ATTRIBS*numVertices);
|
402 |
|
|
System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS );
|
403 |
0d4aae88
|
Leszek Koltunski
|
origVertices++;
|
404 |
|
|
|
405 |
e7f85322
|
Leszek Koltunski
|
if( numVertices%2==1 )
|
406 |
0d4aae88
|
Leszek Koltunski
|
{
|
407 |
1fad573e
|
Leszek Koltunski
|
System.arraycopy(mVertAttribs1, VERT1_ATTRIBS*(origVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
|
408 |
e54bfada
|
Leszek Koltunski
|
System.arraycopy(mVertAttribs2, VERT2_ATTRIBS*(origVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
|
409 |
0d4aae88
|
Leszek Koltunski
|
origVertices++;
|
410 |
|
|
}
|
411 |
|
|
}
|
412 |
|
|
|
413 |
e7f85322
|
Leszek Koltunski
|
for(int i=0; i<numMeshes; i++)
|
414 |
0d4aae88
|
Leszek Koltunski
|
{
|
415 |
|
|
mesh = meshes[i];
|
416 |
e7f85322
|
Leszek Koltunski
|
numVertices = mesh.mNumVertices;
|
417 |
0d4aae88
|
Leszek Koltunski
|
|
418 |
22e60fba
|
Leszek Koltunski
|
if( origVertices>0 )
|
419 |
|
|
{
|
420 |
e8925fcd
|
Leszek Koltunski
|
System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
|
421 |
|
|
System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
|
422 |
22e60fba
|
Leszek Koltunski
|
origVertices++;
|
423 |
|
|
}
|
424 |
1fad573e
|
Leszek Koltunski
|
System.arraycopy(mesh.mVertAttribs1, 0, newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS*numVertices);
|
425 |
e54bfada
|
Leszek Koltunski
|
System.arraycopy(mesh.mVertAttribs2, 0, newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS*numVertices);
|
426 |
e7f85322
|
Leszek Koltunski
|
origVertices+=numVertices;
|
427 |
0d4aae88
|
Leszek Koltunski
|
|
428 |
e7f85322
|
Leszek Koltunski
|
if( i<numMeshes-1 )
|
429 |
0d4aae88
|
Leszek Koltunski
|
{
|
430 |
1fad573e
|
Leszek Koltunski
|
System.arraycopy(mesh.mVertAttribs1, VERT1_ATTRIBS*(numVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
|
431 |
e54bfada
|
Leszek Koltunski
|
System.arraycopy(mesh.mVertAttribs2, VERT2_ATTRIBS*(numVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
|
432 |
0d4aae88
|
Leszek Koltunski
|
origVertices++;
|
433 |
|
|
|
434 |
e7f85322
|
Leszek Koltunski
|
if( numVertices%2==1 )
|
435 |
0d4aae88
|
Leszek Koltunski
|
{
|
436 |
1fad573e
|
Leszek Koltunski
|
System.arraycopy(mesh.mVertAttribs1, VERT1_ATTRIBS*(numVertices-1), newAttribs1, VERT1_ATTRIBS*origVertices, VERT1_ATTRIBS);
|
437 |
e54bfada
|
Leszek Koltunski
|
System.arraycopy(mesh.mVertAttribs2, VERT2_ATTRIBS*(numVertices-1), newAttribs2, VERT2_ATTRIBS*origVertices, VERT2_ATTRIBS);
|
438 |
0d4aae88
|
Leszek Koltunski
|
origVertices++;
|
439 |
|
|
}
|
440 |
|
|
}
|
441 |
|
|
}
|
442 |
|
|
|
443 |
|
|
if( origVertices!=mNumVertices )
|
444 |
|
|
{
|
445 |
|
|
android.util.Log.e("mesh", "join: origVertices: "+origVertices+" numVertices: "+mNumVertices);
|
446 |
|
|
}
|
447 |
|
|
|
448 |
e8925fcd
|
Leszek Koltunski
|
int endIndex, index=0, numEffComp = mEffComponent.size();
|
449 |
36d65d88
|
Leszek Koltunski
|
|
450 |
e8925fcd
|
Leszek Koltunski
|
for(int component=0; component<numEffComp; component++)
|
451 |
36d65d88
|
Leszek Koltunski
|
{
|
452 |
e8925fcd
|
Leszek Koltunski
|
endIndex = mEffComponent.get(component);
|
453 |
36d65d88
|
Leszek Koltunski
|
|
454 |
|
|
for( ; index<=endIndex; index++) newAttribs2[VERT2_ATTRIBS*index+COM_ATTRIB] = component;
|
455 |
|
|
}
|
456 |
|
|
|
457 |
1fad573e
|
Leszek Koltunski
|
mVertAttribs1 = newAttribs1;
|
458 |
e54bfada
|
Leszek Koltunski
|
mVertAttribs2 = newAttribs2;
|
459 |
1fad573e
|
Leszek Koltunski
|
mVBO1.invalidate();
|
460 |
e54bfada
|
Leszek Koltunski
|
mVBO2.invalidate();
|
461 |
23b733db
|
Leszek Koltunski
|
}
|
462 |
|
|
|
463 |
a8dfedcc
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
464 |
|
|
// called from MeshJoined
|
465 |
|
|
|
466 |
|
|
void join(MeshBase[] meshes)
|
467 |
|
|
{
|
468 |
1fad573e
|
Leszek Koltunski
|
boolean immediateJoin = true;
|
469 |
a8dfedcc
|
Leszek Koltunski
|
|
470 |
1fad573e
|
Leszek Koltunski
|
for (MeshBase mesh : meshes)
|
471 |
a8dfedcc
|
Leszek Koltunski
|
{
|
472 |
1fad573e
|
Leszek Koltunski
|
if (mesh.mJobNode[0] != null)
|
473 |
|
|
{
|
474 |
|
|
immediateJoin = false;
|
475 |
|
|
break;
|
476 |
|
|
}
|
477 |
a8dfedcc
|
Leszek Koltunski
|
}
|
478 |
|
|
|
479 |
1fad573e
|
Leszek Koltunski
|
if( immediateJoin ) joinAttribs(meshes);
|
480 |
|
|
else mJobNode[0] = DeferredJobs.join(this,meshes);
|
481 |
|
|
}
|
482 |
a8dfedcc
|
Leszek Koltunski
|
|
483 |
1fad573e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
484 |
a8dfedcc
|
Leszek Koltunski
|
|
485 |
1fad573e
|
Leszek Koltunski
|
void textureMap(Static4D[] maps)
|
486 |
|
|
{
|
487 |
e8925fcd
|
Leszek Koltunski
|
int num_comp = mTexComponent.size();
|
488 |
1fad573e
|
Leszek Koltunski
|
int num_maps = maps.length;
|
489 |
|
|
int min = Math.min(num_comp, num_maps);
|
490 |
|
|
int vertex = 0;
|
491 |
|
|
Static4D newMap, oldMap;
|
492 |
e8925fcd
|
Leszek Koltunski
|
TexComponent comp;
|
493 |
1fad573e
|
Leszek Koltunski
|
float newW, newH, ratW, ratH, movX, movY;
|
494 |
a8dfedcc
|
Leszek Koltunski
|
|
495 |
1fad573e
|
Leszek Koltunski
|
for(int i=0; i<min; i++)
|
496 |
|
|
{
|
497 |
|
|
newMap = maps[i];
|
498 |
e8925fcd
|
Leszek Koltunski
|
comp = mTexComponent.get(i);
|
499 |
1fad573e
|
Leszek Koltunski
|
|
500 |
|
|
if( newMap!=null )
|
501 |
a8dfedcc
|
Leszek Koltunski
|
{
|
502 |
1fad573e
|
Leszek Koltunski
|
newW = newMap.get2();
|
503 |
|
|
newH = newMap.get3();
|
504 |
a8dfedcc
|
Leszek Koltunski
|
|
505 |
1fad573e
|
Leszek Koltunski
|
if( newW!=0.0f && newH!=0.0f )
|
506 |
a8dfedcc
|
Leszek Koltunski
|
{
|
507 |
1fad573e
|
Leszek Koltunski
|
oldMap = comp.mTextureMap;
|
508 |
|
|
ratW = newW/oldMap.get2();
|
509 |
|
|
ratH = newH/oldMap.get3();
|
510 |
|
|
movX = newMap.get0() - ratW*oldMap.get0();
|
511 |
|
|
movY = newMap.get1() - ratH*oldMap.get1();
|
512 |
|
|
|
513 |
|
|
for( int index=vertex*VERT2_ATTRIBS+TEX_ATTRIB ; vertex<=comp.mEndIndex; vertex++, index+=VERT2_ATTRIBS)
|
514 |
|
|
{
|
515 |
|
|
mVertAttribs2[index ] = ratW*mVertAttribs2[index ] + movX;
|
516 |
|
|
mVertAttribs2[index+1] = ratH*mVertAttribs2[index+1] + movY;
|
517 |
|
|
}
|
518 |
|
|
comp.setMap(newMap);
|
519 |
a8dfedcc
|
Leszek Koltunski
|
}
|
520 |
|
|
}
|
521 |
|
|
|
522 |
1fad573e
|
Leszek Koltunski
|
vertex= comp.mEndIndex+1;
|
523 |
a8dfedcc
|
Leszek Koltunski
|
}
|
524 |
|
|
|
525 |
1fad573e
|
Leszek Koltunski
|
mVBO2.invalidate();
|
526 |
|
|
}
|
527 |
|
|
|
528 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
529 |
a8dfedcc
|
Leszek Koltunski
|
|
530 |
e8925fcd
|
Leszek Koltunski
|
public static int getMaxEffComponents()
|
531 |
1fad573e
|
Leszek Koltunski
|
{
|
532 |
e8925fcd
|
Leszek Koltunski
|
return MAX_EFFECT_COMPONENTS;
|
533 |
1fad573e
|
Leszek Koltunski
|
}
|
534 |
|
|
|
535 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
536 |
|
|
|
537 |
|
|
public static void getUniforms(int mProgramH, int variant)
|
538 |
|
|
{
|
539 |
2aeb75aa
|
Leszek Koltunski
|
mEquAssociationH[variant] = GLES30.glGetUniformLocation( mProgramH, "vComEquAssoc");
|
540 |
|
|
mAndAssociationH[variant] = GLES30.glGetUniformLocation( mProgramH, "vComAndAssoc");
|
541 |
a8dfedcc
|
Leszek Koltunski
|
}
|
542 |
|
|
|
543 |
f046b159
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
544 |
|
|
/**
|
545 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
546 |
|
|
*
|
547 |
|
|
* @y.exclude
|
548 |
|
|
*/
|
549 |
|
|
public void copyTransformToVertex()
|
550 |
|
|
{
|
551 |
e54bfada
|
Leszek Koltunski
|
ByteBuffer buffer = (ByteBuffer)GLES30.glMapBufferRange( GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0,
|
552 |
|
|
TRAN_SIZE*mNumVertices, GLES30.GL_MAP_READ_BIT);
|
553 |
f046b159
|
Leszek Koltunski
|
if( buffer!=null )
|
554 |
|
|
{
|
555 |
e54bfada
|
Leszek Koltunski
|
FloatBuffer feedback = buffer.order(ByteOrder.nativeOrder()).asFloatBuffer();
|
556 |
|
|
feedback.get(mVertAttribs1,0,VERT1_ATTRIBS*mNumVertices);
|
557 |
|
|
mVBO1.update(mVertAttribs1);
|
558 |
f046b159
|
Leszek Koltunski
|
}
|
559 |
|
|
else
|
560 |
|
|
{
|
561 |
b5be333a
|
Leszek Koltunski
|
int error = GLES30.glGetError();
|
562 |
|
|
Log.e("mesh", "failed to map tf buffer, error="+error);
|
563 |
f046b159
|
Leszek Koltunski
|
}
|
564 |
|
|
|
565 |
b5be333a
|
Leszek Koltunski
|
GLES30.glUnmapBuffer(GLES30.GL_TRANSFORM_FEEDBACK);
|
566 |
f046b159
|
Leszek Koltunski
|
}
|
567 |
|
|
|
568 |
1fad573e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
569 |
|
|
/**
|
570 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
571 |
|
|
*
|
572 |
|
|
* @y.exclude
|
573 |
|
|
*/
|
574 |
|
|
public void debug()
|
575 |
|
|
{
|
576 |
|
|
if( mJobNode[0]!=null )
|
577 |
|
|
{
|
578 |
|
|
mJobNode[0].print(0);
|
579 |
|
|
}
|
580 |
|
|
else
|
581 |
|
|
{
|
582 |
|
|
android.util.Log.e("mesh", "JobNode null");
|
583 |
|
|
}
|
584 |
|
|
}
|
585 |
|
|
|
586 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
587 |
|
|
/**
|
588 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
589 |
|
|
*
|
590 |
|
|
* @y.exclude
|
591 |
|
|
*/
|
592 |
|
|
public void print()
|
593 |
|
|
{
|
594 |
|
|
StringBuffer sb = new StringBuffer();
|
595 |
|
|
|
596 |
|
|
for(int i=0; i<mNumVertices; i++)
|
597 |
|
|
{
|
598 |
|
|
sb.append('(');
|
599 |
|
|
sb.append(mVertAttribs1[VERT1_ATTRIBS*i+POS_ATTRIB ]);
|
600 |
|
|
sb.append(',');
|
601 |
|
|
sb.append(mVertAttribs1[VERT1_ATTRIBS*i+POS_ATTRIB+1]);
|
602 |
|
|
sb.append(',');
|
603 |
|
|
sb.append(mVertAttribs1[VERT1_ATTRIBS*i+POS_ATTRIB+2]);
|
604 |
|
|
sb.append(") ");
|
605 |
|
|
}
|
606 |
|
|
|
607 |
|
|
StringBuffer sb2 = new StringBuffer();
|
608 |
|
|
|
609 |
|
|
for(int i=0; i<mNumVertices; i++)
|
610 |
|
|
{
|
611 |
|
|
sb2.append(mVertAttribs2[VERT2_ATTRIBS*i+COM_ATTRIB]);
|
612 |
|
|
sb2.append(' ');
|
613 |
|
|
}
|
614 |
|
|
|
615 |
|
|
Log.d("mesh", sb.toString()+"\n"+sb2.toString());
|
616 |
|
|
}
|
617 |
|
|
|
618 |
23b733db
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
619 |
|
|
/**
|
620 |
0d4aae88
|
Leszek Koltunski
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
621 |
|
|
*
|
622 |
|
|
* @y.exclude
|
623 |
23b733db
|
Leszek Koltunski
|
*/
|
624 |
0d4aae88
|
Leszek Koltunski
|
public int getTFO()
|
625 |
23b733db
|
Leszek Koltunski
|
{
|
626 |
b5be333a
|
Leszek Koltunski
|
return mTFO.createImmediately(mNumVertices*TRAN_SIZE, null);
|
627 |
23b733db
|
Leszek Koltunski
|
}
|
628 |
|
|
|
629 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
630 |
|
|
/**
|
631 |
0d4aae88
|
Leszek Koltunski
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
632 |
|
|
*
|
633 |
|
|
* @y.exclude
|
634 |
23b733db
|
Leszek Koltunski
|
*/
|
635 |
0d4aae88
|
Leszek Koltunski
|
public int getNumVertices()
|
636 |
23b733db
|
Leszek Koltunski
|
{
|
637 |
0d4aae88
|
Leszek Koltunski
|
return mNumVertices;
|
638 |
23b733db
|
Leszek Koltunski
|
}
|
639 |
|
|
|
640 |
36d65d88
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
641 |
|
|
/**
|
642 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
643 |
|
|
*
|
644 |
|
|
* @y.exclude
|
645 |
|
|
*/
|
646 |
|
|
public void send(int variant)
|
647 |
|
|
{
|
648 |
e8925fcd
|
Leszek Koltunski
|
GLES30.glUniform1iv( mEquAssociationH[variant], MAX_EFFECT_COMPONENTS, mEquAssociation, 0);
|
649 |
|
|
GLES30.glUniform1iv( mAndAssociationH[variant], MAX_EFFECT_COMPONENTS, mAndAssociation, 0);
|
650 |
36d65d88
|
Leszek Koltunski
|
}
|
651 |
|
|
|
652 |
044b5494
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
653 |
6c00149d
|
Leszek Koltunski
|
/**
|
654 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
655 |
|
|
*
|
656 |
|
|
* @y.exclude
|
657 |
|
|
*/
|
658 |
da681e7e
|
Leszek Koltunski
|
public void bindVertexAttribs(DistortedProgram program)
|
659 |
6c00149d
|
Leszek Koltunski
|
{
|
660 |
71d8aba1
|
Leszek Koltunski
|
if( mJobNode[0]!=null )
|
661 |
f046b159
|
Leszek Koltunski
|
{
|
662 |
71d8aba1
|
Leszek Koltunski
|
mJobNode[0].execute(); // this will set itself to null
|
663 |
f046b159
|
Leszek Koltunski
|
}
|
664 |
|
|
|
665 |
e54bfada
|
Leszek Koltunski
|
int index1 = mVBO1.createImmediately(mNumVertices*VERT1_SIZE, mVertAttribs1);
|
666 |
|
|
int index2 = mVBO2.createImmediately(mNumVertices*VERT2_SIZE, mVertAttribs2);
|
667 |
22e60fba
|
Leszek Koltunski
|
|
668 |
e54bfada
|
Leszek Koltunski
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index1 );
|
669 |
|
|
GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_POS);
|
670 |
|
|
GLES30.glVertexAttribPointer(program.mAttribute[1], NOR_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_NOR);
|
671 |
|
|
GLES30.glVertexAttribPointer(program.mAttribute[2], INF_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_INF);
|
672 |
|
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index2 );
|
673 |
|
|
GLES30.glVertexAttribPointer(program.mAttribute[3], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_TEX);
|
674 |
36d65d88
|
Leszek Koltunski
|
GLES30.glVertexAttribPointer(program.mAttribute[4], COM_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_COM);
|
675 |
b7074bc6
|
Leszek Koltunski
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
|
676 |
da681e7e
|
Leszek Koltunski
|
}
|
677 |
|
|
|
678 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
679 |
|
|
/**
|
680 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
681 |
|
|
*
|
682 |
|
|
* @y.exclude
|
683 |
|
|
*/
|
684 |
|
|
public void bindTransformAttribs(DistortedProgram program)
|
685 |
|
|
{
|
686 |
7e53a35f
|
Leszek Koltunski
|
int index = mTFO.createImmediately(mNumVertices*TRAN_SIZE, null);
|
687 |
22e60fba
|
Leszek Koltunski
|
|
688 |
b7074bc6
|
Leszek Koltunski
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index );
|
689 |
|
|
GLES30.glVertexAttribPointer(program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, 0);
|
690 |
|
|
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
|
691 |
6c00149d
|
Leszek Koltunski
|
}
|
692 |
|
|
|
693 |
7a5e538a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
694 |
|
|
/**
|
695 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
696 |
|
|
*
|
697 |
|
|
* @y.exclude
|
698 |
|
|
*/
|
699 |
|
|
public void setInflate(float inflate)
|
700 |
|
|
{
|
701 |
|
|
mInflate = inflate;
|
702 |
|
|
}
|
703 |
|
|
|
704 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
705 |
|
|
/**
|
706 |
|
|
* Not part of public API, do not document (public only because has to be used from the main package)
|
707 |
|
|
*
|
708 |
|
|
* @y.exclude
|
709 |
|
|
*/
|
710 |
|
|
public float getInflate()
|
711 |
|
|
{
|
712 |
|
|
return mInflate;
|
713 |
|
|
}
|
714 |
|
|
|
715 |
466450b5
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
716 |
|
|
// PUBLIC API
|
717 |
3fc9327a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
718 |
|
|
/**
|
719 |
|
|
* When rendering this Mesh, do we want to render the Normal vectors as well?
|
720 |
420836fc
|
leszek
|
* <p>
|
721 |
|
|
* Will work only on OpenGL ES >= 3.0 devices.
|
722 |
3fc9327a
|
Leszek Koltunski
|
*
|
723 |
|
|
* @param show Controls if we render the Normal vectors or not.
|
724 |
|
|
*/
|
725 |
|
|
public void setShowNormals(boolean show)
|
726 |
|
|
{
|
727 |
b7074bc6
|
Leszek Koltunski
|
mShowNormals = show;
|
728 |
3fc9327a
|
Leszek Koltunski
|
}
|
729 |
466450b5
|
Leszek Koltunski
|
|
730 |
6c00149d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
731 |
|
|
/**
|
732 |
|
|
* When rendering this mesh, should we also draw the normal vectors?
|
733 |
|
|
*
|
734 |
|
|
* @return <i>true</i> if we do render normal vectors
|
735 |
|
|
*/
|
736 |
|
|
public boolean getShowNormals()
|
737 |
|
|
{
|
738 |
|
|
return mShowNormals;
|
739 |
|
|
}
|
740 |
|
|
|
741 |
a8dfedcc
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
742 |
|
|
/**
|
743 |
e8925fcd
|
Leszek Koltunski
|
* Merge all texture components of this Mesh into a single one.
|
744 |
a8dfedcc
|
Leszek Koltunski
|
*/
|
745 |
e8925fcd
|
Leszek Koltunski
|
public void mergeTexComponents()
|
746 |
a8dfedcc
|
Leszek Koltunski
|
{
|
747 |
1fad573e
|
Leszek Koltunski
|
if( mJobNode[0]==null )
|
748 |
a8dfedcc
|
Leszek Koltunski
|
{
|
749 |
e8925fcd
|
Leszek Koltunski
|
mergeTexComponentsNow();
|
750 |
a8dfedcc
|
Leszek Koltunski
|
}
|
751 |
|
|
else
|
752 |
|
|
{
|
753 |
e8925fcd
|
Leszek Koltunski
|
mJobNode[0] = DeferredJobs.mergeTex(this);
|
754 |
|
|
}
|
755 |
|
|
}
|
756 |
|
|
|
757 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
758 |
|
|
/**
|
759 |
|
|
* Merge all effect components of this Mesh into a single one.
|
760 |
|
|
*/
|
761 |
|
|
public void mergeEffComponents()
|
762 |
|
|
{
|
763 |
|
|
if( mJobNode[0]==null )
|
764 |
|
|
{
|
765 |
|
|
mergeEffComponentsNow();
|
766 |
|
|
}
|
767 |
|
|
else
|
768 |
|
|
{
|
769 |
|
|
mJobNode[0] = DeferredJobs.mergeEff(this);
|
770 |
a8dfedcc
|
Leszek Koltunski
|
}
|
771 |
|
|
}
|
772 |
|
|
|
773 |
466450b5
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
774 |
|
|
/**
|
775 |
|
|
* Release all internal resources.
|
776 |
|
|
*/
|
777 |
|
|
public void markForDeletion()
|
778 |
|
|
{
|
779 |
e54bfada
|
Leszek Koltunski
|
mVertAttribs1 = null;
|
780 |
|
|
mVertAttribs2 = null;
|
781 |
466450b5
|
Leszek Koltunski
|
|
782 |
e54bfada
|
Leszek Koltunski
|
mVBO1.markForDeletion();
|
783 |
|
|
mVBO2.markForDeletion();
|
784 |
466450b5
|
Leszek Koltunski
|
mTFO.markForDeletion();
|
785 |
|
|
}
|
786 |
fa8bc998
|
Leszek Koltunski
|
|
787 |
e8925fcd
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
788 |
|
|
/**
|
789 |
|
|
* Apply a Matrix Effect to the components which match the (addAssoc,equAssoc) association.
|
790 |
|
|
* <p>
|
791 |
|
|
* This is a static, permanent modification of the vertices contained in this Mesh. If the effect
|
792 |
|
|
* contains any Dynamics, they will be evaluated at 0.
|
793 |
|
|
*
|
794 |
|
|
* @param effect List of Matrix Effects to apply to the Mesh.
|
795 |
|
|
* @param andAssoc 'Logical AND' association which defines which components will be affected.
|
796 |
|
|
* @param equAssoc 'equality' association which defines which components will be affected.
|
797 |
|
|
*/
|
798 |
|
|
public void apply(MatrixEffect effect, int andAssoc, int equAssoc)
|
799 |
|
|
{
|
800 |
|
|
if( mJobNode[0]==null )
|
801 |
|
|
{
|
802 |
|
|
applyMatrix(effect,andAssoc,equAssoc);
|
803 |
|
|
}
|
804 |
|
|
else
|
805 |
|
|
{
|
806 |
|
|
mJobNode[0] = DeferredJobs.matrix(this,effect,andAssoc,equAssoc);
|
807 |
|
|
}
|
808 |
|
|
}
|
809 |
|
|
|
810 |
fa8bc998
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
811 |
|
|
/**
|
812 |
f046b159
|
Leszek Koltunski
|
* Apply a Vertex Effect to the vertex mesh.
|
813 |
fa8bc998
|
Leszek Koltunski
|
* <p>
|
814 |
c90aca24
|
Leszek Koltunski
|
* This is a static, permanent modification of the vertices contained in this Mesh. If the effects
|
815 |
f046b159
|
Leszek Koltunski
|
* contain any Dynamics, the Dynamics will be evaluated at 0.
|
816 |
fa8bc998
|
Leszek Koltunski
|
*
|
817 |
f046b159
|
Leszek Koltunski
|
* We would call this several times building up a list of Effects to do. This list of effects gets
|
818 |
|
|
* lazily executed only when the Mesh is used for rendering for the first time.
|
819 |
e172985c
|
Leszek Koltunski
|
*
|
820 |
f046b159
|
Leszek Koltunski
|
* @param effect Vertex Effect to apply to the Mesh.
|
821 |
fa8bc998
|
Leszek Koltunski
|
*/
|
822 |
f046b159
|
Leszek Koltunski
|
public void apply(VertexEffect effect)
|
823 |
fa8bc998
|
Leszek Koltunski
|
{
|
824 |
71d8aba1
|
Leszek Koltunski
|
mJobNode[0] = DeferredJobs.vertex(this,effect);
|
825 |
c90aca24
|
Leszek Koltunski
|
}
|
826 |
|
|
|
827 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
828 |
|
|
/**
|
829 |
a3a05347
|
Leszek Koltunski
|
* Sets texture maps for (some of) the components of this mesh.
|
830 |
c90aca24
|
Leszek Koltunski
|
* <p>
|
831 |
a3a05347
|
Leszek Koltunski
|
* Format: ( x of lower-left corner, y of lower-left corner, width, height ).
|
832 |
|
|
* For example maps[0] = new Static4D( 0.0, 0.5, 0.5, 0.5 ) sets the 0th component texture map to the
|
833 |
0d4aae88
|
Leszek Koltunski
|
* upper-left quadrant of the texture.
|
834 |
a3a05347
|
Leszek Koltunski
|
* <p>
|
835 |
|
|
* Probably the most common user case would be sending as many maps as there are components in this
|
836 |
|
|
* Mesh. One can also send less, or more (the extraneous ones will be ignored) and set some of them
|
837 |
|
|
* to null (those will be ignored as well). So if there are 5 components, and we want to set the map
|
838 |
|
|
* of the 2nd and 4rd one, call this with
|
839 |
|
|
* maps = new Static4D[4]
|
840 |
|
|
* maps[0] = null
|
841 |
|
|
* maps[1] = the map for the 2nd component
|
842 |
|
|
* maps[2] = null
|
843 |
|
|
* maps[3] = the map for the 4th component
|
844 |
|
|
*
|
845 |
|
|
* A map's width and height have to be non-zero (but can be negative!)
|
846 |
e172985c
|
Leszek Koltunski
|
*
|
847 |
|
|
* @param maps List of texture maps to apply to the texture's components.
|
848 |
c90aca24
|
Leszek Koltunski
|
*/
|
849 |
a3a05347
|
Leszek Koltunski
|
public void setTextureMap(Static4D[] maps)
|
850 |
c90aca24
|
Leszek Koltunski
|
{
|
851 |
1fad573e
|
Leszek Koltunski
|
if( mJobNode[0]==null )
|
852 |
ea88d502
|
Leszek Koltunski
|
{
|
853 |
1fad573e
|
Leszek Koltunski
|
textureMap(maps);
|
854 |
|
|
}
|
855 |
|
|
else
|
856 |
|
|
{
|
857 |
|
|
mJobNode[0] = DeferredJobs.textureMap(this,maps);
|
858 |
ea88d502
|
Leszek Koltunski
|
}
|
859 |
fa8bc998
|
Leszek Koltunski
|
}
|
860 |
9099e567
|
Leszek Koltunski
|
|
861 |
e172985c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
862 |
|
|
/**
|
863 |
|
|
* Return the texture map of one of the components.
|
864 |
|
|
*
|
865 |
|
|
* @param component The component number whose texture map we want to retrieve.
|
866 |
|
|
*/
|
867 |
|
|
public Static4D getTextureMap(int component)
|
868 |
|
|
{
|
869 |
e8925fcd
|
Leszek Koltunski
|
return (component>=0 && component<mTexComponent.size()) ? mTexComponent.get(component).mTextureMap : null;
|
870 |
e172985c
|
Leszek Koltunski
|
}
|
871 |
cbd502ec
|
Leszek Koltunski
|
|
872 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
873 |
|
|
/**
|
874 |
1e672c1d
|
Leszek Koltunski
|
* Set Effect association.
|
875 |
bc208a9c
|
Leszek Koltunski
|
*
|
876 |
1e672c1d
|
Leszek Koltunski
|
* This creates an association between a Component of this Mesh and a Vertex Effect.
|
877 |
2aeb75aa
|
Leszek Koltunski
|
* One can set two types of associations - an 'logical and' and a 'equal' associations and the Effect
|
878 |
|
|
* will only be active on vertices of Components such that
|
879 |
36d65d88
|
Leszek Koltunski
|
*
|
880 |
2aeb75aa
|
Leszek Koltunski
|
* (effect andAssoc) & (component andAssoc) != 0 || (effect equAssoc) == (mesh equAssoc)
|
881 |
36d65d88
|
Leszek Koltunski
|
*
|
882 |
|
|
* (see main_vertex_shader)
|
883 |
bc208a9c
|
Leszek Koltunski
|
*
|
884 |
|
|
* The point: this way we can configure the system so that each Vertex Effect acts only on a certain
|
885 |
1e672c1d
|
Leszek Koltunski
|
* subset of a Mesh, thus potentially significantly reducing the number of render calls.
|
886 |
cbd502ec
|
Leszek Koltunski
|
*/
|
887 |
2aeb75aa
|
Leszek Koltunski
|
public void setEffectAssociation(int component, int andAssociation, int equAssociation)
|
888 |
bc208a9c
|
Leszek Koltunski
|
{
|
889 |
e8925fcd
|
Leszek Koltunski
|
if( component>=0 && component<MAX_EFFECT_COMPONENTS )
|
890 |
bc208a9c
|
Leszek Koltunski
|
{
|
891 |
2aeb75aa
|
Leszek Koltunski
|
mAndAssociation[component] = andAssociation;
|
892 |
|
|
mEquAssociation[component] = equAssociation;
|
893 |
bc208a9c
|
Leszek Koltunski
|
}
|
894 |
|
|
}
|
895 |
|
|
|
896 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
897 |
|
|
/**
|
898 |
4f81e0c8
|
Leszek Koltunski
|
* Copy the Mesh.
|
899 |
|
|
*
|
900 |
|
|
* @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices,
|
901 |
|
|
* normals and inflates (the rest, in particular the mVertAttribs2 containing texture
|
902 |
36d65d88
|
Leszek Koltunski
|
* coordinates and effect associations, is always deep copied)
|
903 |
bc208a9c
|
Leszek Koltunski
|
*/
|
904 |
4f81e0c8
|
Leszek Koltunski
|
public abstract MeshBase copy(boolean deep);
|
905 |
bc208a9c
|
Leszek Koltunski
|
}
|