Revision 1e672c1d
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;
|
|
46 |
static final float DEFAULT_ASSOCIATION = 0xffffffff;
|
|
47 | 47 |
|
48 | 48 |
// sizes of attributes of an individual vertex. |
49 | 49 |
private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z |
50 | 50 |
private static final int NOR_DATA_SIZE= 3; // normal vector: x,y,z |
51 | 51 |
private static final int INF_DATA_SIZE= 3; // 'inflate' vector: x,y,z |
52 | 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
|
|
53 |
private static final int ASS_DATA_SIZE= 1; // association, a single float
|
|
54 | 54 |
|
55 | 55 |
static final int POS_ATTRIB = 0; |
56 | 56 |
static final int NOR_ATTRIB = POS_DATA_SIZE; |
57 | 57 |
static final int INF_ATTRIB = POS_DATA_SIZE + NOR_DATA_SIZE; |
58 | 58 |
static final int TEX_ATTRIB = 0; |
59 |
static final int TAG_ATTRIB = TEX_DATA_SIZE;
|
|
59 |
static final int ASS_ATTRIB = TEX_DATA_SIZE;
|
|
60 | 60 |
|
61 | 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) |
62 |
static final int VERT2_ATTRIBS= TEX_DATA_SIZE + TAG_DATA_SIZE; // number of attributes of a vertex (the 'preapply invariant' part)
|
|
62 |
static final int VERT2_ATTRIBS= TEX_DATA_SIZE + ASS_DATA_SIZE; // number of attributes of a vertex (the 'preapply invariant' part)
|
|
63 | 63 |
static final int TRAN_ATTRIBS = POS_DATA_SIZE + NOR_DATA_SIZE + INF_DATA_SIZE; // number of attributes of a transform feedback vertex |
64 | 64 |
|
65 | 65 |
private static final int BYTES_PER_FLOAT = 4; |
... | ... | |
68 | 68 |
private static final int OFFSET_NOR = NOR_ATTRIB*BYTES_PER_FLOAT; |
69 | 69 |
private static final int OFFSET_INF = INF_ATTRIB*BYTES_PER_FLOAT; |
70 | 70 |
private static final int OFFSET_TEX = TEX_ATTRIB*BYTES_PER_FLOAT; |
71 |
private static final int OFFSET_TAG = TAG_ATTRIB*BYTES_PER_FLOAT;
|
|
71 |
private static final int OFFSET_TAG = ASS_ATTRIB*BYTES_PER_FLOAT;
|
|
72 | 72 |
|
73 | 73 |
private static final int TRAN_SIZE = TRAN_ATTRIBS*BYTES_PER_FLOAT; |
74 | 74 |
private static final int VERT1_SIZE = VERT1_ATTRIBS*BYTES_PER_FLOAT; |
... | ... | |
400 | 400 |
GLES30.glVertexAttribPointer(program.mAttribute[2], INF_DATA_SIZE, GLES30.GL_FLOAT, false, VERT1_SIZE, OFFSET_INF); |
401 | 401 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, index2 ); |
402 | 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);
|
|
403 |
GLES30.glVertexAttribPointer(program.mAttribute[4], ASS_DATA_SIZE, GLES30.GL_FLOAT, false, VERT2_SIZE, OFFSET_TAG);
|
|
404 | 404 |
GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0); |
405 | 405 |
} |
406 | 406 |
|
... | ... | |
583 | 583 |
|
584 | 584 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
585 | 585 |
/** |
586 |
* Set a component's tag.
|
|
586 |
* Set Effect association.
|
|
587 | 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.
|
|
588 |
* This creates an association between a Component of this Mesh and a Vertex Effect.
|
|
589 |
* One can set the association of an Effect and of a Component, and the Effect will only be active on
|
|
590 |
* vertices of Components such that (effect assoc) & (component assoc) != 0. (see VertexEffect.retSection() )
|
|
591 | 591 |
* |
592 | 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.
|
|
593 |
* subset of a Mesh, thus potentially significantly reducing the number of render calls.
|
|
594 | 594 |
*/ |
595 |
public void setTag(int component, int tag)
|
|
595 |
public void setEffectAssociation(int component, int association)
|
|
596 | 596 |
{ |
597 | 597 |
int num = mComponent.size(); |
598 | 598 |
|
... | ... | |
601 | 601 |
int sta = component>0 ? mComponent.get(component-1).mEndIndex+1 : 0; |
602 | 602 |
int end = mComponent.get(component).mEndIndex; |
603 | 603 |
|
604 |
sta = sta*VERT2_ATTRIBS + TAG_ATTRIB;
|
|
605 |
end = end*VERT2_ATTRIBS + TAG_ATTRIB;
|
|
604 |
sta = sta*VERT2_ATTRIBS + ASS_ATTRIB;
|
|
605 |
end = end*VERT2_ATTRIBS + ASS_ATTRIB;
|
|
606 | 606 |
|
607 | 607 |
for(int i=sta; i<=end; i+=VERT2_ATTRIBS) |
608 | 608 |
{ |
609 |
mVertAttribs2[i] = tag;
|
|
609 |
mVertAttribs2[i] = association;
|
|
610 | 610 |
} |
611 | 611 |
|
612 | 612 |
mVBO2.invalidate(); |
Also available in: Unified diff
Change 'tag' to a more appropriate name - 'association'.