Revision bc208a9c
Added by Leszek Koltunski almost 4 years ago
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 |
} |
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)