Revision bc208a9c
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/library/effect/Effect.java | ||
---|---|---|
48 | 48 |
private final static float[] mUnity= new float[MAX_UNITY_DIM*NUM_EFFECTS]; |
49 | 49 |
private final static int[] mUnityDim = new int[NUM_EFFECTS]; |
50 | 50 |
|
51 |
int mTag; |
|
52 |
|
|
51 | 53 |
static boolean[] mEnabled = new boolean[NUM_EFFECTS]; |
52 | 54 |
|
53 | 55 |
static |
... | ... | |
65 | 67 |
mCenterDim = name.getCenterDimension(); |
66 | 68 |
mRegionDim = name.getRegionDimension(); |
67 | 69 |
|
70 |
mTag = 0xffffffff; |
|
71 |
|
|
68 | 72 |
int n = name.ordinal(); |
69 | 73 |
float[] u = name.getUnity(); |
70 | 74 |
int l = u.length; |
... | ... | |
130 | 134 |
return null; |
131 | 135 |
} |
132 | 136 |
|
137 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
138 |
/** |
|
139 |
* Only for use by the library itself. |
|
140 |
* |
|
141 |
* @y.exclude |
|
142 |
*/ |
|
143 |
public int getTag() |
|
144 |
{ |
|
145 |
return mTag; |
|
146 |
} |
|
147 |
|
|
133 | 148 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
134 | 149 |
// PUBLIC API |
135 | 150 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/effect/VertexEffect.java | ||
---|---|---|
58 | 58 |
{ |
59 | 59 |
return |
60 | 60 |
|
61 |
"if( vName[i]=="+effect+")\n" + |
|
61 |
"if( vName[i]=="+effect+" && (int(a_Tag) & vTag[i]) != 0 )\n" +
|
|
62 | 62 |
"{\n" + |
63 | 63 |
code +"\n" + |
64 | 64 |
"}\n" + |
... | ... | |
187 | 187 |
{ |
188 | 188 |
return mNumEnabled; |
189 | 189 |
} |
190 |
|
|
191 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
192 |
/** |
|
193 |
* Set a tag. |
|
194 |
* |
|
195 |
* A 'tag' of a Vertex Effect joins the effect with a component of a Mesh the effect gets applied to. |
|
196 |
* One can set a Tag of the effect and of a Component, and the Effect will only be active on vertices |
|
197 |
* of Components such that (effect tag) & (component tag) != 0. (see retSection() above) |
|
198 |
* |
|
199 |
* The point: this way we can configure the system so that each Vertex Effect acts only on a certain |
|
200 |
* subset of the Mesh, thus potentially significantly reducing the number of render calls. |
|
201 |
*/ |
|
202 |
public void setTag(int tag) |
|
203 |
{ |
|
204 |
mTag = tag; |
|
205 |
} |
|
190 | 206 |
} |
src/main/java/org/distorted/library/effectqueue/EffectQueue.java | ||
---|---|---|
51 | 51 |
long[] mCurrentDuration; |
52 | 52 |
Effect[] mEffects; |
53 | 53 |
int[] mName; |
54 |
int[] mTag; |
|
54 | 55 |
long mTime; |
55 | 56 |
|
56 | 57 |
private static int[] mMax = new int[EffectType.LENGTH]; |
... | ... | |
141 | 142 |
mCurrentDuration = new long[max]; |
142 | 143 |
mEffects = new Effect[max]; |
143 | 144 |
mName = new int[max]; |
145 |
mTag = new int[max]; |
|
144 | 146 |
} |
145 | 147 |
|
146 | 148 |
for(int i=0; i<mNumEffects; i++ ) |
... | ... | |
148 | 150 |
mEffects[i] = source.mEffects[i]; |
149 | 151 |
mCurrentDuration[i] = source.mCurrentDuration[i]; |
150 | 152 |
mName[i] = source.mName[i]; |
153 |
mTag[i] = source.mTag[i]; |
|
151 | 154 |
} |
152 | 155 |
} |
153 | 156 |
} |
... | ... | |
276 | 279 |
mEffects[j] = mEffects[j+1]; |
277 | 280 |
mCurrentDuration[j] = mCurrentDuration[j+1]; |
278 | 281 |
mName[j] = mName[j+1]; |
282 |
mTag[j] = mTag[j+1]; |
|
279 | 283 |
} |
280 | 284 |
|
281 | 285 |
mEffects[mNumEffects] = null; |
... | ... | |
426 | 430 |
mCurrentDuration = new long[max]; |
427 | 431 |
mEffects = new Effect[max]; |
428 | 432 |
mName = new int[max]; |
433 |
mTag = new int[max]; |
|
429 | 434 |
} |
430 | 435 |
mCreated = true; |
431 | 436 |
|
... | ... | |
439 | 444 |
mCurrentDuration[mNumEffects] = 0; |
440 | 445 |
mEffects[mNumEffects] = job.effect; |
441 | 446 |
mName[mNumEffects] = job.effect.getName().ordinal(); |
447 |
mTag[mNumEffects] = job.effect.getTag(); |
|
442 | 448 |
|
443 | 449 |
mNumEffects++; |
444 | 450 |
changed = true; |
... | ... | |
450 | 456 |
mCurrentDuration[j] = mCurrentDuration[j-1]; |
451 | 457 |
mEffects[j] = mEffects[j-1]; |
452 | 458 |
mName[j] = mName[j-1]; |
459 |
mTag[j] = mTag[j-1]; |
|
453 | 460 |
} |
454 | 461 |
|
455 | 462 |
mCurrentDuration[position] = 0; |
456 | 463 |
mEffects[position] = job.effect; |
457 | 464 |
mName[position] = job.effect.getName().ordinal(); |
465 |
mTag[position] = job.effect.getTag(); |
|
458 | 466 |
|
459 | 467 |
mNumEffects++; |
460 | 468 |
changed = true; |
src/main/java/org/distorted/library/effectqueue/EffectQueueVertex.java | ||
---|---|---|
39 | 39 |
private static int[] mNumEffectsH = new int[MAIN_VARIANTS]; |
40 | 40 |
private static int[] mNameH = new int[MAIN_VARIANTS]; |
41 | 41 |
private static int[] mUniformsH = new int[MAIN_VARIANTS]; |
42 |
private static int[] mTagH = new int[MAIN_VARIANTS]; |
|
42 | 43 |
private static int[] mInflateH = new int[MAIN_VARIANTS]; |
43 | 44 |
|
44 | 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
62 | 63 |
mNumEffectsH[variant]= GLES30.glGetUniformLocation( mProgramH, "vNumEffects"); |
63 | 64 |
mNameH[variant] = GLES30.glGetUniformLocation( mProgramH, "vName"); |
64 | 65 |
mUniformsH[variant] = GLES30.glGetUniformLocation( mProgramH, "vUniforms"); |
66 |
mTagH[variant] = GLES30.glGetUniformLocation( mProgramH, "vTag"); |
|
65 | 67 |
mInflateH[variant] = GLES30.glGetUniformLocation( mProgramH, "u_Inflate"); |
66 | 68 |
} |
67 | 69 |
|
... | ... | |
80 | 82 |
for(int i=0; i<mNumEffects; i++) |
81 | 83 |
{ |
82 | 84 |
mCurrentDuration[i] += step; |
85 |
mTag[i] = mEffects[i].getTag(); |
|
83 | 86 |
|
84 | 87 |
if( mEffects[i].compute(mUniforms, NUM_UNIFORMS*i, mCurrentDuration[i], step) ) |
85 | 88 |
{ |
... | ... | |
104 | 107 |
if( mNumEffects>0 ) |
105 | 108 |
{ |
106 | 109 |
GLES30.glUniform1iv( mNameH[variant] , mNumEffects, mName ,0); |
110 |
GLES30.glUniform1iv( mTagH[variant] , mNumEffects, mTag ,0); |
|
107 | 111 |
GLES30.glUniform4fv( mUniformsH[variant],(NUM_UNIFORMS/4)*mNumEffects, mUniforms,0); |
108 | 112 |
} |
109 | 113 |
} |
src/main/java/org/distorted/library/mesh/MeshBase.java | ||
---|---|---|
43 | 43 |
*/ |
44 | 44 |
public abstract class MeshBase |
45 | 45 |
{ |
46 |
static final float DEFAULT_TAG = 0xffffffff; |
|
47 |
|
|
46 | 48 |
// sizes of attributes of an individual vertex. |
47 | 49 |
private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z |
48 | 50 |
private static final int NOR_DATA_SIZE= 3; // normal vector: x,y,z |
49 | 51 |
private static final int INF_DATA_SIZE= 3; // 'inflate' vector: x,y,z |
50 | 52 |
private static final int TEX_DATA_SIZE= 2; // texture coordinates: s,t |
53 |
private static final int TAG_DATA_SIZE= 1; // tag, a single float |
|
51 | 54 |
|
52 | 55 |
static final int POS_ATTRIB = 0; |
53 | 56 |
static final int NOR_ATTRIB = POS_DATA_SIZE; |
54 | 57 |
static final int INF_ATTRIB = POS_DATA_SIZE + NOR_DATA_SIZE; |
55 | 58 |
static final int TEX_ATTRIB = 0; |
59 |
static final int TAG_ATTRIB = TEX_DATA_SIZE; |
|
60 |
|
|
56 | 61 |
static final int VERT1_ATTRIBS= POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE; // number of attributes of a vertex (the part changed by preapply) |
57 |
static final int VERT2_ATTRIBS= TEX_DATA_SIZE; // number of attributes of a vertex (the 'preapply invariant' part)
|
|
62 |
static final int VERT2_ATTRIBS= TEX_DATA_SIZE + TAG_DATA_SIZE; // number of attributes of a vertex (the 'preapply invariant' part)
|
|
58 | 63 |
static final int TRAN_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE; // number of attributes of a transform feedback vertex |
59 | 64 |
|
60 | 65 |
private static final int BYTES_PER_FLOAT = 4; |
... | ... | |
63 | 68 |
private static final int OFFSET_NOR = NOR_ATTRIB*BYTES_PER_FLOAT; |
64 | 69 |
private static final int OFFSET_INF = INF_ATTRIB*BYTES_PER_FLOAT; |
65 | 70 |
private static final int OFFSET_TEX = TEX_ATTRIB*BYTES_PER_FLOAT; |
71 |
private static final int OFFSET_TAG = TAG_ATTRIB*BYTES_PER_FLOAT; |
|
72 |
|
|
66 | 73 |
private static final int TRAN_SIZE = TRAN_ATTRIBS*BYTES_PER_FLOAT; |
67 | 74 |
private static final int VERT1_SIZE = VERT1_ATTRIBS*BYTES_PER_FLOAT; |
68 | 75 |
private static final int VERT2_SIZE = VERT2_ATTRIBS*BYTES_PER_FLOAT; |
... | ... | |
132 | 139 |
|
133 | 140 |
int size = original.mComponent.size(); |
134 | 141 |
mComponent = new ArrayList<>(); |
142 |
|
|
135 | 143 |
for(int i=0; i<size; i++) |
136 | 144 |
{ |
137 | 145 |
Component comp = new Component(original.mComponent.get(i)); |
... | ... | |
392 | 400 |
GLES30.glVertexAttribPointer(program.mAttribute[2], INF_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_INF); |
393 | 401 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index2 ); |
394 | 402 |
GLES30.glVertexAttribPointer(program.mAttribute[3], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_TEX); |
403 |
GLES30.glVertexAttribPointer(program.mAttribute[4], TAG_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_TAG); |
|
395 | 404 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0); |
396 | 405 |
} |
397 | 406 |
|
... | ... | |
574 | 583 |
|
575 | 584 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
576 | 585 |
/** |
577 |
* Deep copy |
|
586 |
* Set a component's tag. |
|
587 |
* |
|
588 |
* A 'tag' of a component associates all vertices which belong to the component with all Vertex Effects |
|
589 |
* with a matching tag - i.e. one can set a tag of an Effect and of a Component, and the Effect will |
|
590 |
* only be active on vertices of Components such that (effect tag) & (component tag) != 0. |
|
591 |
* |
|
592 |
* The point: this way we can configure the system so that each Vertex Effect acts only on a certain |
|
593 |
* subset of the Mesh, thus potentially significantly reducing the number of render calls. |
|
578 | 594 |
*/ |
579 |
public abstract MeshBase deepCopy(); |
|
580 |
} |
|
595 |
public void setTag(int component, int tag) |
|
596 |
{ |
|
597 |
int num = mComponent.size(); |
|
581 | 598 |
|
599 |
if( component>=0 && component<num ) |
|
600 |
{ |
|
601 |
int sta = component>0 ? mComponent.get(component-1).mEndIndex+1 : 0; |
|
602 |
int end = mComponent.get(component).mEndIndex; |
|
582 | 603 |
|
604 |
sta = sta*VERT2_ATTRIBS + TAG_ATTRIB; |
|
605 |
end = end*VERT2_ATTRIBS + TAG_ATTRIB; |
|
583 | 606 |
|
607 |
for(int i=sta; i<=end; i+=VERT2_ATTRIBS) |
|
608 |
{ |
|
609 |
mVertAttribs2[i] = tag; |
|
610 |
} |
|
611 |
|
|
612 |
mVBO2.invalidate(); |
|
613 |
} |
|
614 |
} |
|
615 |
|
|
616 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
617 |
/** |
|
618 |
* Deep copy |
|
619 |
*/ |
|
620 |
public abstract MeshBase deepCopy(); |
|
621 |
} |
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 + TAG_ATTRIB] = DEFAULT_TAG; |
|
647 |
|
|
646 | 648 |
currVert++; |
647 | 649 |
} |
648 | 650 |
|
... | ... | |
675 | 677 |
|
676 | 678 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[TOP] + x * mTexMappingW[TOP]; |
677 | 679 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[TOP] + (0.5f-z) * mTexMappingH[TOP]; |
680 |
attribs2[VERT2_ATTRIBS*currVert + TAG_ATTRIB ] = DEFAULT_TAG; |
|
678 | 681 |
|
679 | 682 |
break; |
680 | 683 |
case SOUTH: row = curr.row+1; |
... | ... | |
697 | 700 |
|
698 | 701 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[BOTTOM] + x * mTexMappingW[BOTTOM]; |
699 | 702 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[BOTTOM] + (0.5f-z) * mTexMappingH[BOTTOM]; |
703 |
attribs2[VERT2_ATTRIBS*currVert + TAG_ATTRIB ] = DEFAULT_TAG; |
|
700 | 704 |
|
701 | 705 |
break; |
702 | 706 |
case WEST : row = (back ? (curr.row+1):(curr.row)); |
... | ... | |
719 | 723 |
|
720 | 724 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[LEFT] + (0.5f-z) * mTexMappingW[LEFT]; |
721 | 725 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[LEFT] + (1.0f-y) * mTexMappingH[LEFT]; |
726 |
attribs2[VERT2_ATTRIBS*currVert + TAG_ATTRIB ] = DEFAULT_TAG; |
|
722 | 727 |
|
723 | 728 |
break; |
724 | 729 |
case EAST : row = (back ? (curr.row):(curr.row+1)); |
... | ... | |
741 | 746 |
|
742 | 747 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[RIGHT] + (0.5f-z) * mTexMappingW[RIGHT]; |
743 | 748 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[RIGHT] + (1.0f-y) * mTexMappingH[RIGHT]; |
749 |
attribs2[VERT2_ATTRIBS*currVert + TAG_ATTRIB ] = DEFAULT_TAG; |
|
744 | 750 |
|
745 | 751 |
break; |
746 | 752 |
} |
... | ... | |
766 | 772 |
|
767 | 773 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB ] = attribs2[VERT2_ATTRIBS*(currVert-1) + TEX_ATTRIB ]; |
768 | 774 |
attribs2[VERT2_ATTRIBS*currVert + TEX_ATTRIB+1] = attribs2[VERT2_ATTRIBS*(currVert-1) + TEX_ATTRIB+1]; |
775 |
attribs2[VERT2_ATTRIBS*currVert + TAG_ATTRIB ] = DEFAULT_TAG; |
|
769 | 776 |
|
770 | 777 |
currVert++; |
771 | 778 |
} |
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 + TAG_ATTRIB ] = DEFAULT_TAG; |
|
49 | 50 |
} |
50 | 51 |
|
51 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
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 + TAG_ATTRIB ] = DEFAULT_TAG; |
|
76 | 77 |
|
77 | 78 |
return vertex+1; |
78 | 79 |
} |
... | ... | |
99 | 100 |
|
100 | 101 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB ] = attribs2[VERT2_ATTRIBS*(vertex-1) + TEX_ATTRIB ]; |
101 | 102 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB+1] = attribs2[VERT2_ATTRIBS*(vertex-1) + TEX_ATTRIB+1]; |
103 |
attribs2[VERT2_ATTRIBS*vertex + TAG_ATTRIB ] = DEFAULT_TAG; |
|
102 | 104 |
|
103 | 105 |
vertex++; |
104 | 106 |
} |
src/main/java/org/distorted/library/mesh/MeshSphere.java | ||
---|---|---|
33 | 33 |
private static final int NUMFACES = 16; |
34 | 34 |
private static final double P = Math.PI; |
35 | 35 |
|
36 |
// An array of 16 entries, each describing a single face of the solid in an (admittedly) weird
|
|
36 |
// An array of 16 entries, each describing a single face of a solid in an (admittedly) weird
|
|
37 | 37 |
// fashion. Each face is a triangle, with 2 vertices on the same latitude. |
38 | 38 |
// Single row is (longitude of V1, longitude of V2, (common) latitude of V1 and V2, latitude of V3) |
39 | 39 |
// longitude of V3 is simply midpoint of V1 and V2 so we don't have to specify it here. |
... | ... | |
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 + TAG_ATTRIB ] = DEFAULT_TAG; |
|
98 | 99 |
|
99 | 100 |
currentVert++; |
100 | 101 |
} |
... | ... | |
198 | 199 |
|
199 | 200 |
attribs2[VERT2_ATTRIBS*currentVert + TEX_ATTRIB ] = (float)texX; |
200 | 201 |
attribs2[VERT2_ATTRIBS*currentVert + TEX_ATTRIB+1] = (float)texY; |
202 |
attribs2[VERT2_ATTRIBS*currentVert + TAG_ATTRIB ] = DEFAULT_TAG; |
|
201 | 203 |
|
202 | 204 |
currentVert++; |
203 | 205 |
|
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 + TAG_ATTRIB ] = DEFAULT_TAG; |
|
51 | 52 |
|
52 | 53 |
return vertex+1; |
53 | 54 |
} |
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_Tag; // Per-vertex tag. Connects the vertex (really the mesh component the vertex is a member of) to a vertex effect. |
|
29 |
// An effect will only be active on a vertex iff (a_Tag & vTag[effect]) != 0. ( see VertexEffect.retSection() ) |
|
28 | 30 |
|
29 | 31 |
out vec3 v_Position; // |
30 | 32 |
out vec3 v_endPosition; // for Transform Feedback only |
... | ... | |
46 | 48 |
uniform vec4 vUniforms[3*NUM_VERTEX];// i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2]. |
47 | 49 |
// The first vec4 is the Interpolated values, |
48 | 50 |
// second vec4: first float - cache, next 3: Center, the third - the Region. |
51 |
uniform int vTag[NUM_VERTEX]; // Tags of the vertex effects. Tags are used to connect an effect to a Mesh component. |
|
49 | 52 |
|
50 | 53 |
////////////////////////////////////////////////////////////////////////////////////////////// |
51 | 54 |
// HELPER FUNCTIONS |
Also available in: Unified diff
Introduce 'tags' (soon to be renamed to 'associations') to Mesh and VertexEffect.
A 'tag' is a way to associate a Vertex Effect only to a subgroup of a given Mesh's vertices (more precisely, only to an arbitrary subset of its Components)