Revision 36d65d88
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/library/effect/Effect.java | ||
---|---|---|
49 | 49 |
private final static int[] mUnityDim = new int[NUM_EFFECTS]; |
50 | 50 |
|
51 | 51 |
int mAssociation; |
52 |
int mComponent; |
|
52 | 53 |
|
53 | 54 |
static boolean[] mEnabled = new boolean[NUM_EFFECTS]; |
54 | 55 |
|
... | ... | |
68 | 69 |
mRegionDim = name.getRegionDimension(); |
69 | 70 |
|
70 | 71 |
mAssociation = 0xffffffff; |
72 |
mComponent = 0; |
|
71 | 73 |
|
72 | 74 |
int n = name.ordinal(); |
73 | 75 |
float[] u = name.getUnity(); |
... | ... | |
145 | 147 |
return mAssociation; |
146 | 148 |
} |
147 | 149 |
|
150 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
151 |
/** |
|
152 |
* Only for use by the library itself. |
|
153 |
* |
|
154 |
* @y.exclude |
|
155 |
*/ |
|
156 |
public int getComponent() |
|
157 |
{ |
|
158 |
return mComponent; |
|
159 |
} |
|
160 |
|
|
148 | 161 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
149 | 162 |
// PUBLIC API |
150 | 163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/effect/VertexEffect.java | ||
---|---|---|
58 | 58 |
{ |
59 | 59 |
return |
60 | 60 |
|
61 |
"if( vName[i]=="+effect+" && (int(a_Association) & vAssociation[i]) != 0 )\n" +
|
|
61 |
"if( vName[i]=="+effect+" )\n" + |
|
62 | 62 |
"{\n" + |
63 | 63 |
code +"\n" + |
64 | 64 |
"}\n" + |
... | ... | |
194 | 194 |
* |
195 | 195 |
* This creates an association between this Vertex Effect and a Component of a Mesh. |
196 | 196 |
* One can set the association of an Effect and of a Component, and the Effect will only be active on |
197 |
* vertices of Components such that (effect assoc) & (component assoc) != 0. (see retSection() above) |
|
197 |
* vertices of Components such that |
|
198 |
* |
|
199 |
* (effect assoc) & (component assoc) != 0 || (effect component) == (mesh component) |
|
200 |
* |
|
201 |
* (see main_vertex_shader) |
|
198 | 202 |
* |
199 | 203 |
* The point: this way we can configure the system so that each Vertex Effect acts only on a certain |
200 | 204 |
* subset of a Mesh, thus potentially significantly reducing the number of render calls. |
201 | 205 |
*/ |
202 |
public void setMeshAssociation(int association) |
|
206 |
public void setMeshAssociation(int component, int association)
|
|
203 | 207 |
{ |
208 |
mComponent = component; |
|
204 | 209 |
mAssociation = association; |
205 | 210 |
} |
206 | 211 |
} |
src/main/java/org/distorted/library/effectqueue/EffectQueue.java | ||
---|---|---|
37 | 37 |
*/ |
38 | 38 |
public abstract class EffectQueue implements InternalMaster.Slave |
39 | 39 |
{ |
40 |
static final int MAIN_VARIANTS = 4; // Number of Main program variants (ATM 4: MAIN, MAIN OIT, PREPROCESS, FULL) |
|
40 |
public static final int MAIN_VARIANTS = 4; // Number of Main program variants (ATM 4: MAIN, MAIN OIT, PREPROCESS, FULL)
|
|
41 | 41 |
|
42 | 42 |
private static final int CREATE = 0; |
43 | 43 |
private static final int ATTACH = 1; |
... | ... | |
52 | 52 |
Effect[] mEffects; |
53 | 53 |
int[] mName; |
54 | 54 |
int[] mAssociation; |
55 |
int[] mComponent; |
|
55 | 56 |
long mTime; |
56 | 57 |
|
57 | 58 |
private static int[] mMax = new int[EffectType.LENGTH]; |
... | ... | |
143 | 144 |
mEffects = new Effect[max]; |
144 | 145 |
mName = new int[max]; |
145 | 146 |
mAssociation = new int[max]; |
147 |
mComponent = new int[max]; |
|
146 | 148 |
} |
147 | 149 |
|
148 | 150 |
for(int i=0; i<mNumEffects; i++ ) |
... | ... | |
151 | 153 |
mCurrentDuration[i] = source.mCurrentDuration[i]; |
152 | 154 |
mName[i] = source.mName[i]; |
153 | 155 |
mAssociation[i] = source.mAssociation[i]; |
156 |
mComponent[i] = source.mComponent[i]; |
|
154 | 157 |
} |
155 | 158 |
} |
156 | 159 |
} |
... | ... | |
280 | 283 |
mCurrentDuration[j] = mCurrentDuration[j+1]; |
281 | 284 |
mName[j] = mName[j+1]; |
282 | 285 |
mAssociation[j] = mAssociation[j+1]; |
286 |
mComponent[j] = mComponent[j+1]; |
|
283 | 287 |
} |
284 | 288 |
|
285 | 289 |
mEffects[mNumEffects] = null; |
... | ... | |
431 | 435 |
mEffects = new Effect[max]; |
432 | 436 |
mName = new int[max]; |
433 | 437 |
mAssociation = new int[max]; |
438 |
mComponent = new int[max]; |
|
434 | 439 |
} |
435 | 440 |
mCreated = true; |
436 | 441 |
|
... | ... | |
445 | 450 |
mEffects[mNumEffects] = job.effect; |
446 | 451 |
mName[mNumEffects] = job.effect.getName().ordinal(); |
447 | 452 |
mAssociation[mNumEffects]= job.effect.getAssociation(); |
453 |
mComponent[mNumEffects] = job.effect.getComponent(); |
|
448 | 454 |
|
449 | 455 |
mNumEffects++; |
450 | 456 |
changed = true; |
... | ... | |
457 | 463 |
mEffects[j] = mEffects[j-1]; |
458 | 464 |
mName[j] = mName[j-1]; |
459 | 465 |
mAssociation[j] = mAssociation[j-1]; |
466 |
mComponent[j] = mComponent[j-1]; |
|
460 | 467 |
} |
461 | 468 |
|
462 | 469 |
mCurrentDuration[position] = 0; |
463 | 470 |
mEffects[position] = job.effect; |
464 | 471 |
mName[position] = job.effect.getName().ordinal(); |
465 | 472 |
mAssociation[position]= job.effect.getAssociation(); |
473 |
mComponent[position] = job.effect.getComponent(); |
|
466 | 474 |
|
467 | 475 |
mNumEffects++; |
468 | 476 |
changed = true; |
src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java | ||
---|---|---|
126 | 126 |
String mainVertHeader= version + ("#define NUM_VERTEX " + ( numV>0 ? DistortedLibrary.getMax(EffectType.VERTEX ) : 0 ) + "\n"); |
127 | 127 |
String mainFragHeader= version + "\n"; |
128 | 128 |
|
129 |
mainVertHeader += "#define MAX_COMPON " + MeshBase.getMaxComponents() + "\n"; |
|
130 |
|
|
129 | 131 |
String enabledEffectV= VertexEffect.getGLSL(); |
130 | 132 |
|
131 | 133 |
try |
... | ... | |
142 | 144 |
int preProgramH = mPreProgram.getProgramHandle(); |
143 | 145 |
EffectQueueVertex.getUniforms( preProgramH,2 ); |
144 | 146 |
EffectQueueMatrix.getUniforms( preProgramH,2 ); |
147 |
MeshBase.getUniforms(preProgramH,2); |
|
145 | 148 |
mPreColorH = GLES30.glGetUniformLocation( preProgramH, "u_Color" ); |
146 | 149 |
mPreTextureH= GLES30.glGetUniformLocation( preProgramH, "u_Texture"); |
147 | 150 |
} |
... | ... | |
159 | 162 |
|
160 | 163 |
public boolean getRender() |
161 | 164 |
{ |
162 |
return mNumEffects>0 ? ((PostprocessEffect)mEffects[0]).getRender() : false;
|
|
165 |
return mNumEffects > 0 && ((PostprocessEffect) mEffects[0]).getRender();
|
|
163 | 166 |
} |
164 | 167 |
|
165 | 168 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
180 | 183 |
mPreProgram.useProgram(); |
181 | 184 |
|
182 | 185 |
mesh.bindVertexAttribs(mPreProgram); |
186 |
mesh.send(2); |
|
183 | 187 |
|
184 | 188 |
EffectQueue[] queues = effects.getQueues(); |
185 | 189 |
EffectQueueMatrix matrix = (EffectQueueMatrix)queues[0]; |
src/main/java/org/distorted/library/effectqueue/EffectQueueVertex.java | ||
---|---|---|
40 | 40 |
private static int[] mNameH = new int[MAIN_VARIANTS]; |
41 | 41 |
private static int[] mUniformsH = new int[MAIN_VARIANTS]; |
42 | 42 |
private static int[] mAssociationH= new int[MAIN_VARIANTS]; |
43 |
private static int[] mComponentH = new int[MAIN_VARIANTS]; |
|
43 | 44 |
private static int[] mInflateH = new int[MAIN_VARIANTS]; |
44 | 45 |
|
45 | 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
63 | 64 |
mNumEffectsH[variant] = GLES30.glGetUniformLocation( mProgramH, "vNumEffects"); |
64 | 65 |
mNameH[variant] = GLES30.glGetUniformLocation( mProgramH, "vName"); |
65 | 66 |
mUniformsH[variant] = GLES30.glGetUniformLocation( mProgramH, "vUniforms"); |
66 |
mAssociationH[variant]= GLES30.glGetUniformLocation( mProgramH, "vAssociation"); |
|
67 |
mAssociationH[variant]= GLES30.glGetUniformLocation( mProgramH, "vEffectAssoc"); |
|
68 |
mComponentH[variant] = GLES30.glGetUniformLocation( mProgramH, "vEffectCompo"); |
|
67 | 69 |
mInflateH[variant] = GLES30.glGetUniformLocation( mProgramH, "u_Inflate"); |
68 | 70 |
} |
69 | 71 |
|
... | ... | |
83 | 85 |
{ |
84 | 86 |
mCurrentDuration[i] += step; |
85 | 87 |
mAssociation[i] = mEffects[i].getAssociation(); |
88 |
mComponent[i] = mEffects[i].getComponent(); |
|
86 | 89 |
|
87 | 90 |
if( mEffects[i].compute(mUniforms, NUM_UNIFORMS*i, mCurrentDuration[i], step) ) |
88 | 91 |
{ |
... | ... | |
108 | 111 |
{ |
109 | 112 |
GLES30.glUniform1iv( mNameH[variant] , mNumEffects, mName , 0); |
110 | 113 |
GLES30.glUniform1iv( mAssociationH[variant], mNumEffects, mAssociation, 0); |
114 |
GLES30.glUniform1iv( mComponentH[variant] , mNumEffects, mComponent , 0); |
|
111 | 115 |
GLES30.glUniform4fv( mUniformsH[variant] ,(NUM_UNIFORMS/4)*mNumEffects, mUniforms , 0); |
112 | 116 |
} |
113 | 117 |
} |
src/main/java/org/distorted/library/main/DistortedLibrary.java | ||
---|---|---|
215 | 215 |
|
216 | 216 |
String mainVertHeader= mGLSL_VERSION + ("#define NUM_VERTEX " + ( numV>0 ? getMax(EffectType.VERTEX ) : 0 ) + "\n"); |
217 | 217 |
String mainFragHeader= mGLSL_VERSION + ("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n"); |
218 |
|
|
219 |
mainVertHeader += "#define MAX_COMPON " + MeshBase.getMaxComponents() + "\n"; |
|
220 |
|
|
218 | 221 |
String enabledEffectV= VertexEffect.getGLSL(); |
219 | 222 |
String enabledEffectF= FragmentEffect.getGLSL(); |
220 | 223 |
|
... | ... | |
233 | 236 |
|
234 | 237 |
int mainProgramH = mMainProgram.getProgramHandle(); |
235 | 238 |
EffectQueue.getUniforms(mainProgramH,0); |
239 |
MeshBase.getUniforms(mainProgramH,0); |
|
236 | 240 |
mMainTextureH= GLES30.glGetUniformLocation( mainProgramH, "u_Texture"); |
237 | 241 |
|
238 | 242 |
// BLIT PROGRAM //////////////////////////////////// |
... | ... | |
302 | 306 |
|
303 | 307 |
String fullVertHeader= mGLSL_VERSION + ("#define NUM_VERTEX " + ( numV>0 ? getMax(EffectType.VERTEX ) : 0 ) + "\n"); |
304 | 308 |
String fullFragHeader= mGLSL_VERSION + ("#define NUM_FRAGMENT " + 0 + "\n"); |
309 |
|
|
310 |
fullVertHeader += "#define MAX_COMPON " + MeshBase.getMaxComponents() + "\n"; |
|
311 |
|
|
305 | 312 |
String enabledEffectV= VertexEffect.getAllGLSL(); |
306 | 313 |
String enabledEffectF= "{}"; |
307 | 314 |
|
... | ... | |
322 | 329 |
|
323 | 330 |
int fullProgramH = mFullProgram.getProgramHandle(); |
324 | 331 |
EffectQueue.getUniforms(fullProgramH,3); |
332 |
MeshBase.getUniforms(fullProgramH,3); |
|
325 | 333 |
} |
326 | 334 |
|
327 | 335 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
338 | 346 |
String mainVertHeader= mGLSL_VERSION + ("#define NUM_VERTEX " + ( numV>0 ? getMax(EffectType.VERTEX ) : 0 ) + "\n") + ("#define OIT\n"); |
339 | 347 |
String mainFragHeader= mGLSL_VERSION + ("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n") + ("#define OIT\n"); |
340 | 348 |
|
349 |
mainVertHeader += "#define MAX_COMPON " + MeshBase.getMaxComponents() + "\n"; |
|
350 |
|
|
341 | 351 |
String enabledEffectV= VertexEffect.getGLSL(); |
342 | 352 |
String enabledEffectF= FragmentEffect.getGLSL(); |
343 | 353 |
|
... | ... | |
354 | 364 |
|
355 | 365 |
int mainOITProgramH = mMainOITProgram.getProgramHandle(); |
356 | 366 |
EffectQueue.getUniforms(mainOITProgramH,1); |
367 |
MeshBase.getUniforms(mainOITProgramH,1); |
|
357 | 368 |
mMainOITTextureH = GLES30.glGetUniformLocation( mainOITProgramH, "u_Texture"); |
358 | 369 |
mMainOITSizeH = GLES30.glGetUniformLocation( mainOITProgramH, "u_Size"); |
359 | 370 |
mMainOITNumRecordsH = GLES30.glGetUniformLocation( mainOITProgramH, "u_numRecords"); |
... | ... | |
468 | 479 |
{ |
469 | 480 |
if( mFullProgram!=null ) |
470 | 481 |
{ |
471 |
GLES30.glViewport(0, 0, 500, 500 ); // TODO ???
|
|
482 |
GLES30.glViewport(0, 0, 500, 500 ); // this is fine, we don't need viewport at all
|
|
472 | 483 |
|
473 | 484 |
int num = mesh.getNumVertices(); |
474 | 485 |
int tfo = mesh.getTFO(); |
... | ... | |
477 | 488 |
mesh.bindVertexAttribs(mFullProgram); |
478 | 489 |
mesh.computeQueue(); |
479 | 490 |
mesh.sendQueue(); |
491 |
mesh.send(3); |
|
480 | 492 |
|
481 | 493 |
GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfo ); |
482 | 494 |
GLES30.glBeginTransformFeedback( GLES30.GL_POINTS); |
... | ... | |
503 | 515 |
GLES30.glUniform2ui(DistortedLibrary.mMainOITSizeH, surface.mWidth, surface.mHeight); |
504 | 516 |
GLES30.glUniform1ui(DistortedLibrary.mMainOITNumRecordsH, (int)(DistortedLibrary.mBufferSize*surface.mWidth*surface.mHeight) ); |
505 | 517 |
mesh.bindVertexAttribs(DistortedLibrary.mMainOITProgram); |
518 |
mesh.send(1); |
|
506 | 519 |
|
507 | 520 |
float inflate = mesh.getInflate(); |
508 | 521 |
float distance = surface.mDistance; |
... | ... | |
515 | 528 |
if( mesh.getShowNormals() ) |
516 | 529 |
{ |
517 | 530 |
DistortedLibrary.mMainProgram.useProgram(); |
531 |
mesh.send(0); |
|
518 | 532 |
EffectQueue.send(queues, distance, mipmap, projection, inflate, mesh, 0 ); |
519 | 533 |
displayNormals(queues,mesh); |
520 | 534 |
} |
... | ... | |
534 | 548 |
mMainProgram.useProgram(); |
535 | 549 |
GLES30.glUniform1i(DistortedLibrary.mMainTextureH, 0); |
536 | 550 |
mesh.bindVertexAttribs(DistortedLibrary.mMainProgram); |
551 |
mesh.send(0); |
|
537 | 552 |
|
538 | 553 |
float inflate = mesh.getInflate(); |
539 | 554 |
float distance = surface.mDistance; |
src/main/java/org/distorted/library/mesh/MeshBase.java | ||
---|---|---|
23 | 23 |
import android.util.Log; |
24 | 24 |
|
25 | 25 |
import org.distorted.library.effect.VertexEffect; |
26 |
import org.distorted.library.effectqueue.EffectQueue; |
|
26 | 27 |
import org.distorted.library.effectqueue.EffectQueueVertex; |
27 | 28 |
import org.distorted.library.main.DistortedLibrary; |
28 | 29 |
import org.distorted.library.main.InternalBuffer; |
... | ... | |
43 | 44 |
*/ |
44 | 45 |
public abstract class MeshBase |
45 | 46 |
{ |
46 |
static final float DEFAULT_ASSOCIATION = 0xffffffff; |
|
47 |
private static final int MAX_COMPONENTS= 100; |
|
48 |
static final int DEFAULT_ASSOCIATION = 0xffffffff; |
|
47 | 49 |
|
48 | 50 |
// sizes of attributes of an individual vertex. |
49 | 51 |
private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z |
50 | 52 |
private static final int NOR_DATA_SIZE= 3; // normal vector: x,y,z |
51 | 53 |
private static final int INF_DATA_SIZE= 3; // 'inflate' vector: x,y,z |
52 | 54 |
private static final int TEX_DATA_SIZE= 2; // texture coordinates: s,t |
53 |
private static final int ASS_DATA_SIZE= 1; // association, a single float
|
|
55 |
private static final int COM_DATA_SIZE= 1; // component number, a single float
|
|
54 | 56 |
|
55 | 57 |
static final int POS_ATTRIB = 0; |
56 | 58 |
static final int NOR_ATTRIB = POS_DATA_SIZE; |
57 | 59 |
static final int INF_ATTRIB = POS_DATA_SIZE + NOR_DATA_SIZE; |
58 | 60 |
static final int TEX_ATTRIB = 0; |
59 |
static final int ASS_ATTRIB = TEX_DATA_SIZE;
|
|
61 |
static final int COM_ATTRIB = TEX_DATA_SIZE;
|
|
60 | 62 |
|
61 | 63 |
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) |
62 |
static final int VERT2_ATTRIBS= TEX_DATA_SIZE + ASS_DATA_SIZE; // number of attributes of a vertex (the 'preapply invariant' part)
|
|
64 |
static final int VERT2_ATTRIBS= TEX_DATA_SIZE + COM_DATA_SIZE; // number of attributes of a vertex (the 'preapply invariant' part)
|
|
63 | 65 |
static final int TRAN_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE; // number of attributes of a transform feedback vertex |
64 | 66 |
|
65 | 67 |
private static final int BYTES_PER_FLOAT = 4; |
... | ... | |
68 | 70 |
private static final int OFFSET_NOR = NOR_ATTRIB*BYTES_PER_FLOAT; |
69 | 71 |
private static final int OFFSET_INF = INF_ATTRIB*BYTES_PER_FLOAT; |
70 | 72 |
private static final int OFFSET_TEX = TEX_ATTRIB*BYTES_PER_FLOAT; |
71 |
private static final int OFFSET_TAG = ASS_ATTRIB*BYTES_PER_FLOAT;
|
|
73 |
private static final int OFFSET_COM = COM_ATTRIB*BYTES_PER_FLOAT;
|
|
72 | 74 |
|
73 | 75 |
private static final int TRAN_SIZE = TRAN_ATTRIBS*BYTES_PER_FLOAT; |
74 | 76 |
private static final int VERT1_SIZE = VERT1_ATTRIBS*BYTES_PER_FLOAT; |
... | ... | |
78 | 80 |
private InternalBuffer mVBO1, mVBO2, mTFO; // main vertex buffer and transform feedback buffer |
79 | 81 |
private int mNumVertices; |
80 | 82 |
private float[] mVertAttribs1; // packed: PosX,PosY,PosZ, NorX,NorY,NorZ, InfX,InfY,InfZ |
81 |
private float[] mVertAttribs2; // packed: TexS,TexT |
|
83 |
private float[] mVertAttribs2; // packed: TexS,TexT, Component
|
|
82 | 84 |
private float mInflate; |
83 | 85 |
private boolean[] mNeedsAdjustment; |
86 |
private int[] mAssociation; |
|
87 |
|
|
88 |
private static int[] mComponentAssociationH = new int[EffectQueue.MAIN_VARIANTS]; |
|
84 | 89 |
|
85 | 90 |
private static class Component |
86 | 91 |
{ |
... | ... | |
121 | 126 |
mShowNormals= false; |
122 | 127 |
mInflate = 0.0f; |
123 | 128 |
mComponent = new ArrayList<>(); |
129 |
mAssociation= new int[MAX_COMPONENTS]; |
|
130 |
|
|
131 |
for(int i=0; i<MAX_COMPONENTS; i++) mAssociation[i] = DEFAULT_ASSOCIATION; |
|
124 | 132 |
|
125 | 133 |
mNeedsAdjustment = new boolean[1]; |
126 |
mNeedsAdjustment[0] = false; |
|
127 | 134 |
|
128 | 135 |
mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
129 | 136 |
mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
... | ... | |
148 | 155 |
mComponent.add(comp); |
149 | 156 |
} |
150 | 157 |
|
158 |
mAssociation= new int[MAX_COMPONENTS]; |
|
159 |
System.arraycopy(original.mAssociation, 0, mAssociation, 0, MAX_COMPONENTS); |
|
160 |
|
|
151 | 161 |
if( deep ) |
152 | 162 |
{ |
153 | 163 |
mNeedsAdjustment = new boolean[1]; |
... | ... | |
174 | 184 |
mTFO.invalidate(); |
175 | 185 |
} |
176 | 186 |
|
187 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
188 |
|
|
189 |
public static int getMaxComponents() |
|
190 |
{ |
|
191 |
return MAX_COMPONENTS; |
|
192 |
} |
|
193 |
|
|
194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
195 |
|
|
196 |
public static void getUniforms(int mProgramH, int variant) |
|
197 |
{ |
|
198 |
mComponentAssociationH[variant] = GLES30.glGetUniformLocation( mProgramH, "vComponAssoc"); |
|
199 |
} |
|
200 |
|
|
177 | 201 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
178 | 202 |
|
179 | 203 |
int numComponents() |
... | ... | |
190 | 214 |
mVertAttribs1= vert1Attribs; |
191 | 215 |
mVertAttribs2= vert2Attribs; |
192 | 216 |
|
193 |
mComponent.add(new Component(mNumVertices)); |
|
217 |
mComponent.add(new Component(mNumVertices-1));
|
|
194 | 218 |
|
195 | 219 |
mVBO1.invalidate(); |
196 | 220 |
mVBO2.invalidate(); |
... | ... | |
203 | 227 |
{ |
204 | 228 |
MeshBase mesh; |
205 | 229 |
Component comp; |
206 |
int numComponents, numVertices, numMeshes = meshes.length; |
|
230 |
int origComponents=0, numComponents, numVertices, numMeshes = meshes.length;
|
|
207 | 231 |
int origVertices = mNumVertices; |
208 | 232 |
|
209 | 233 |
// compute new numVertices; take care of Components |
210 | 234 |
|
211 | 235 |
if( origVertices>0 ) |
212 | 236 |
{ |
213 |
numComponents = mComponent.size();
|
|
237 |
origComponents = mComponent.size();
|
|
214 | 238 |
mNumVertices+= ( mNumVertices%2==1 ? 2:1 ); |
215 |
mComponent.get(numComponents-1).mEndIndex = mNumVertices;
|
|
239 |
mComponent.get(origComponents-1).mEndIndex = mNumVertices-1;
|
|
216 | 240 |
} |
217 | 241 |
|
218 | 242 |
for(int i=0; i<numMeshes; i++) |
... | ... | |
220 | 244 |
mesh = meshes[i]; |
221 | 245 |
numComponents = mesh.mComponent.size(); |
222 | 246 |
|
247 |
numVertices = mesh.mNumVertices; |
|
248 |
|
|
249 |
int extraVerticesBefore = mNumVertices==0 ? 0:1; |
|
250 |
int extraVerticesAfter = (i==numMeshes-1) ? 0 : (numVertices%2==1 ? 2:1); |
|
251 |
|
|
223 | 252 |
for(int j=0; j<numComponents; j++) |
224 | 253 |
{ |
225 | 254 |
comp = new Component(mesh.mComponent.get(j)); |
226 |
comp.mEndIndex += mNumVertices;
|
|
255 |
comp.mEndIndex += (extraVerticesBefore+mNumVertices+extraVerticesAfter);
|
|
227 | 256 |
mComponent.add(comp); |
228 |
} |
|
229 | 257 |
|
230 |
numVertices = mesh.mNumVertices; |
|
231 |
|
|
232 |
if( mNumVertices==0 ) |
|
233 |
{ |
|
234 |
if( numMeshes>1 ) |
|
235 |
mNumVertices += (numVertices%2==1 ? numVertices+2 : numVertices+1); |
|
236 |
else |
|
237 |
mNumVertices += numVertices; |
|
258 |
if( origComponents<MAX_COMPONENTS ) |
|
259 |
{ |
|
260 |
mAssociation[origComponents] = mesh.mAssociation[j]; |
|
261 |
origComponents++; |
|
262 |
} |
|
238 | 263 |
} |
239 |
else if( i==numMeshes-1 ) mNumVertices += (numVertices+1); |
|
240 |
else mNumVertices += (numVertices%2==1 ? numVertices+3 : numVertices+2);
|
|
264 |
|
|
265 |
mNumVertices += (extraVerticesBefore+numVertices+extraVerticesAfter);
|
|
241 | 266 |
} |
242 | 267 |
|
243 | 268 |
// allocate new attrib array |
... | ... | |
296 | 321 |
android.util.Log.e("mesh", "join: origVertices: "+origVertices+" numVertices: "+mNumVertices); |
297 | 322 |
} |
298 | 323 |
|
324 |
int endIndex, index=0, numComp = mComponent.size(); |
|
325 |
|
|
326 |
for(int component=0; component<numComp; component++) |
|
327 |
{ |
|
328 |
endIndex = mComponent.get(component).mEndIndex; |
|
329 |
|
|
330 |
for( ; index<=endIndex; index++) newAttribs2[VERT2_ATTRIBS*index+COM_ATTRIB] = component; |
|
331 |
} |
|
332 |
|
|
299 | 333 |
mVertAttribs1 = newAttribs1; |
300 | 334 |
mVertAttribs2 = newAttribs2; |
301 | 335 |
|
... | ... | |
389 | 423 |
return mNumVertices; |
390 | 424 |
} |
391 | 425 |
|
426 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
427 |
/** |
|
428 |
* Not part of public API, do not document (public only because has to be used from the main package) |
|
429 |
* |
|
430 |
* @y.exclude |
|
431 |
*/ |
|
432 |
public void send(int variant) |
|
433 |
{ |
|
434 |
GLES30.glUniform1iv( mComponentAssociationH[variant], MAX_COMPONENTS, mAssociation, 0); |
|
435 |
} |
|
436 |
|
|
392 | 437 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
393 | 438 |
/** |
394 | 439 |
* Not part of public API, do not document (public only because has to be used from the main package) |
... | ... | |
412 | 457 |
GLES30.glVertexAttribPointer(program.mAttribute[2], INF_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_INF); |
413 | 458 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index2 ); |
414 | 459 |
GLES30.glVertexAttribPointer(program.mAttribute[3], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_TEX); |
415 |
GLES30.glVertexAttribPointer(program.mAttribute[4], ASS_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_TAG);
|
|
460 |
GLES30.glVertexAttribPointer(program.mAttribute[4], COM_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_COM);
|
|
416 | 461 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0); |
417 | 462 |
} |
418 | 463 |
|
... | ... | |
599 | 644 |
* |
600 | 645 |
* This creates an association between a Component of this Mesh and a Vertex Effect. |
601 | 646 |
* One can set the association of an Effect and of a Component, and the Effect will only be active on |
602 |
* vertices of Components such that (effect assoc) & (component assoc) != 0. (see VertexEffect.retSection() ) |
|
647 |
* vertices of Components such that |
|
648 |
* |
|
649 |
* (effect assoc) & (component assoc) != 0 || (effect component) == (mesh component) |
|
650 |
* |
|
651 |
* (see main_vertex_shader) |
|
603 | 652 |
* |
604 | 653 |
* The point: this way we can configure the system so that each Vertex Effect acts only on a certain |
605 | 654 |
* subset of a Mesh, thus potentially significantly reducing the number of render calls. |
606 | 655 |
*/ |
607 | 656 |
public void setEffectAssociation(int component, int association) |
608 | 657 |
{ |
609 |
int num = mComponent.size(); |
|
610 |
|
|
611 |
if( component>=0 && component<num ) |
|
658 |
if( component>=0 && component<MAX_COMPONENTS ) |
|
612 | 659 |
{ |
613 |
int sta = component>0 ? mComponent.get(component-1).mEndIndex : 0; |
|
614 |
int end = mComponent.get(component).mEndIndex; |
|
615 |
|
|
616 |
sta = sta*VERT2_ATTRIBS + ASS_ATTRIB; |
|
617 |
end = end*VERT2_ATTRIBS + ASS_ATTRIB; |
|
618 |
|
|
619 |
for(int i=sta; i<end; i+=VERT2_ATTRIBS) |
|
620 |
{ |
|
621 |
mVertAttribs2[i] = association; |
|
622 |
} |
|
623 |
|
|
624 |
mVBO2.invalidate(); |
|
660 |
mAssociation[component] = association; |
|
625 | 661 |
} |
626 | 662 |
} |
627 | 663 |
|
... | ... | |
631 | 667 |
* |
632 | 668 |
* @param deep If to be a deep or shallow copy of mVertAttribs1, i.e. the array holding vertices, |
633 | 669 |
* normals and inflates (the rest, in particular the mVertAttribs2 containing texture |
634 |
* coordinates and effect assocciations, is always deep copied)
|
|
670 |
* coordinates and effect associations, is always deep copied) |
|
635 | 671 |
*/ |
636 | 672 |
public abstract MeshBase copy(boolean deep); |
637 | 673 |
} |
src/main/java/org/distorted/library/mesh/MeshCubes.java | ||
---|---|---|
643 | 643 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[BACK] + (1.0f-y) * mTexMappingH[BACK]; |
644 | 644 |
} |
645 | 645 |
|
646 |
attribs2[VERT2_ATTRIBS*currVert + ASS_ATTRIB] = DEFAULT_ASSOCIATION; |
|
647 |
|
|
648 | 646 |
currVert++; |
649 | 647 |
} |
650 | 648 |
|
... | ... | |
677 | 675 |
|
678 | 676 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[TOP] + x * mTexMappingW[TOP]; |
679 | 677 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[TOP] + (0.5f-z) * mTexMappingH[TOP]; |
680 |
attribs2[VERT2_ATTRIBS*currVert + ASS_ATTRIB ] = DEFAULT_ASSOCIATION; |
|
681 | 678 |
|
682 | 679 |
break; |
683 | 680 |
case SOUTH: row = curr.row+1; |
... | ... | |
700 | 697 |
|
701 | 698 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[BOTTOM] + x * mTexMappingW[BOTTOM]; |
702 | 699 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[BOTTOM] + (0.5f-z) * mTexMappingH[BOTTOM]; |
703 |
attribs2[VERT2_ATTRIBS*currVert + ASS_ATTRIB ] = DEFAULT_ASSOCIATION; |
|
704 | 700 |
|
705 | 701 |
break; |
706 | 702 |
case WEST : row = (back ? (curr.row+1):(curr.row)); |
... | ... | |
723 | 719 |
|
724 | 720 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[LEFT] + (0.5f-z) * mTexMappingW[LEFT]; |
725 | 721 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[LEFT] + (1.0f-y) * mTexMappingH[LEFT]; |
726 |
attribs2[VERT2_ATTRIBS*currVert + ASS_ATTRIB ] = DEFAULT_ASSOCIATION; |
|
727 | 722 |
|
728 | 723 |
break; |
729 | 724 |
case EAST : row = (back ? (curr.row):(curr.row+1)); |
... | ... | |
746 | 741 |
|
747 | 742 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[RIGHT] + (0.5f-z) * mTexMappingW[RIGHT]; |
748 | 743 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[RIGHT] + (1.0f-y) * mTexMappingH[RIGHT]; |
749 |
attribs2[VERT2_ATTRIBS*currVert + ASS_ATTRIB ] = DEFAULT_ASSOCIATION; |
|
750 | 744 |
|
751 | 745 |
break; |
752 | 746 |
} |
... | ... | |
772 | 766 |
|
773 | 767 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = attribs2[VERT2_ATTRIBS*(currVert-1) + TEX_ATTRIB ]; |
774 | 768 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = attribs2[VERT2_ATTRIBS*(currVert-1) + TEX_ATTRIB+1]; |
775 |
attribs2[VERT2_ATTRIBS*currVert + ASS_ATTRIB ] = DEFAULT_ASSOCIATION; |
|
776 | 769 |
|
777 | 770 |
currVert++; |
778 | 771 |
} |
src/main/java/org/distorted/library/mesh/MeshQuad.java | ||
---|---|---|
46 | 46 |
|
47 | 47 |
attribs2[VERT2_ATTRIBS*index + TEX_ATTRIB ] = x; |
48 | 48 |
attribs2[VERT2_ATTRIBS*index + TEX_ATTRIB+1] = 1.0f-y; |
49 |
attribs2[VERT2_ATTRIBS*index + ASS_ATTRIB ] = DEFAULT_ASSOCIATION; |
|
50 | 49 |
} |
51 | 50 |
|
52 | 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/mesh/MeshRectangles.java | ||
---|---|---|
73 | 73 |
|
74 | 74 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB ] = x; |
75 | 75 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB+1] = 1.0f-y; |
76 |
attribs2[VERT2_ATTRIBS*vertex + ASS_ATTRIB ] = DEFAULT_ASSOCIATION; |
|
77 | 76 |
|
78 | 77 |
return vertex+1; |
79 | 78 |
} |
... | ... | |
100 | 99 |
|
101 | 100 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB ] = attribs2[VERT2_ATTRIBS*(vertex-1) + TEX_ATTRIB ]; |
102 | 101 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB+1] = attribs2[VERT2_ATTRIBS*(vertex-1) + TEX_ATTRIB+1]; |
103 |
attribs2[VERT2_ATTRIBS*vertex + ASS_ATTRIB ] = DEFAULT_ASSOCIATION; |
|
104 | 102 |
|
105 | 103 |
vertex++; |
106 | 104 |
} |
src/main/java/org/distorted/library/mesh/MeshSphere.java | ||
---|---|---|
95 | 95 |
|
96 | 96 |
attribs2[VERT2_ATTRIBS*currentVert + TEX_ATTRIB ] = attribs2[VERT2_ATTRIBS*(currentVert-1) + TEX_ATTRIB ]; |
97 | 97 |
attribs2[VERT2_ATTRIBS*currentVert + TEX_ATTRIB+1] = attribs2[VERT2_ATTRIBS*(currentVert-1) + TEX_ATTRIB+1]; |
98 |
attribs2[VERT2_ATTRIBS*currentVert + ASS_ATTRIB ] = DEFAULT_ASSOCIATION; |
|
99 | 98 |
|
100 | 99 |
currentVert++; |
101 | 100 |
} |
... | ... | |
199 | 198 |
|
200 | 199 |
attribs2[VERT2_ATTRIBS*currentVert + TEX_ATTRIB ] = (float)texX; |
201 | 200 |
attribs2[VERT2_ATTRIBS*currentVert + TEX_ATTRIB+1] = (float)texY; |
202 |
attribs2[VERT2_ATTRIBS*currentVert + ASS_ATTRIB ] = DEFAULT_ASSOCIATION; |
|
203 | 201 |
|
204 | 202 |
currentVert++; |
205 | 203 |
|
src/main/java/org/distorted/library/mesh/MeshTriangles.java | ||
---|---|---|
48 | 48 |
|
49 | 49 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB ] = x; |
50 | 50 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB+1] = y; |
51 |
attribs2[VERT2_ATTRIBS*vertex + ASS_ATTRIB ] = DEFAULT_ASSOCIATION; |
|
52 | 51 |
|
53 | 52 |
return vertex+1; |
54 | 53 |
} |
src/main/java/org/distorted/library/program/DistortedProgram.java | ||
---|---|---|
185 | 185 |
|
186 | 186 |
if( subline.startsWith(mAttributeStr)) |
187 | 187 |
{ |
188 |
//android.util.Log.e("program", "GOOD LINE: " +subline+" subLen="+subLen); |
|
189 |
|
|
190 | 188 |
for(nameBegin=subLen-1; nameBegin>mAttributeLen-2; nameBegin--) |
191 | 189 |
{ |
192 | 190 |
currChar=subline.charAt(nameBegin); |
... | ... | |
209 | 207 |
{ |
210 | 208 |
String attribute, attrList="", uniform; |
211 | 209 |
String[] lines = shader.split("\n"); |
212 |
int length = lines.length; |
|
213 | 210 |
|
214 |
for(int i=0; i<length; i++)
|
|
211 |
for (String line : lines)
|
|
215 | 212 |
{ |
216 |
if( doAttributes )
|
|
213 |
if (doAttributes)
|
|
217 | 214 |
{ |
218 |
attribute = parseOutAttribute(lines[i]);
|
|
215 |
attribute = parseOutAttribute(line); |
|
219 | 216 |
|
220 |
if( attribute!=null )
|
|
217 |
if (attribute != null)
|
|
221 | 218 |
{ |
222 |
//android.util.Log.d("program", "new attribute: "+attribute); |
|
223 |
if( attrList.length()>0 ) attrList+=" "; |
|
219 |
if (attrList.length() > 0) attrList += " "; |
|
224 | 220 |
attrList += attribute; |
225 | 221 |
} |
226 | 222 |
} |
227 | 223 |
|
228 |
uniform = parseOutUniform(lines[i]);
|
|
224 |
uniform = parseOutUniform(line); |
|
229 | 225 |
|
230 |
if( uniform!=null )
|
|
226 |
if (uniform != null)
|
|
231 | 227 |
{ |
232 |
//android.util.Log.d("program", "new uniform: "+uniform); |
|
233 |
if( mUniList.length()>0 ) mUniList+=" "; |
|
228 |
if (mUniList.length() > 0) mUniList += " "; |
|
234 | 229 |
mUniList += uniform; |
235 | 230 |
} |
236 | 231 |
} |
... | ... | |
323 | 318 |
{ |
324 | 319 |
String begin = code.substring(0,place-1); |
325 | 320 |
String end = code.substring(place+length); |
326 |
/* |
|
327 |
int len = begin.length(); |
|
328 | 321 |
|
329 |
android.util.Log.d("Program", begin.substring(len-40)); |
|
330 |
android.util.Log.d("Program", effects); |
|
331 |
android.util.Log.d("Program", end.substring(0,40)); |
|
332 |
*/ |
|
333 | 322 |
return begin + effects + end; |
334 | 323 |
} |
335 | 324 |
else |
src/main/res/raw/main_vertex_shader.glsl | ||
---|---|---|
25 | 25 |
in vec3 a_Inflate; // This vector describes the direction this vertex needs to go when we 'inflate' the whole mesh. |
26 | 26 |
// If the mesh is locally smooth, this is equal to the normal vector. Otherwise (on sharp edges) - no. |
27 | 27 |
in vec2 a_TexCoordinate; // Per-vertex texture coordinate. |
28 |
in float a_Association; // Per-vertex association. Connects the vertex (really the mesh component the vertex is a member of)
|
|
28 |
in float a_Component; // The component a vertex belongs to.
|
|
29 | 29 |
// to a vertex effect. An effect will only be active on a vertex iff (a_Association & vAssociation[effect]) != 0. |
30 | 30 |
// ( see VertexEffect.retSection() ) |
31 | 31 |
|
... | ... | |
49 | 49 |
uniform vec4 vUniforms[3*NUM_VERTEX];// i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2]. |
50 | 50 |
// The first vec4 is the Interpolated values, |
51 | 51 |
// second vec4: first float - cache, next 3: Center, the third - the Region. |
52 |
uniform int vAssociation[NUM_VERTEX];// Associations of the vertex effects. Those are used to connect an effect to a Mesh component. |
|
52 |
uniform int vEffectAssoc[NUM_VERTEX];// Associations of the vertex effects. Those are used to connect an effect to a Mesh component. |
|
53 |
uniform int vEffectCompo[NUM_VERTEX];// Components the vertex effects work on. Likewise used to conneect an effect to a Mesh component. |
|
54 |
uniform int vComponAssoc[MAX_COMPON];// Associations of the component. |
|
53 | 55 |
|
54 | 56 |
////////////////////////////////////////////////////////////////////////////////////////////// |
55 | 57 |
// HELPER FUNCTIONS |
... | ... | |
104 | 106 |
|
105 | 107 |
#if NUM_VERTEX>0 |
106 | 108 |
int effect=0; |
109 |
int component = int(a_Component); |
|
107 | 110 |
|
108 | 111 |
for(int i=0; i<vNumEffects; i++) |
109 | 112 |
{ |
110 |
// ENABLED EFFECTS WILL BE INSERTED HERE |
|
113 |
if( ((vComponAssoc[component] & vEffectAssoc[i]) != 0) || (component == vEffectCompo[i]) ) |
|
114 |
{ |
|
115 |
// ENABLED EFFECTS WILL BE INSERTED HERE |
|
111 | 116 |
|
117 |
} |
|
112 | 118 |
effect+=3; |
113 | 119 |
} |
114 | 120 |
#endif |
Also available in: Unified diff
Progress making it possible to apply Vertex Effects only to some Components of a Mesh.