Revision 46d463a4
Added by Leszek Koltunski about 3 years ago
src/main/java/org/distorted/library/mesh/MeshBase.java | ||
---|---|---|
51 | 51 |
{ |
52 | 52 |
private static final int ASSOC_UBO_BINDING = 3; |
53 | 53 |
private static final int CENTER_UBO_BINDING = 4; |
54 |
public static final int MAX_EFFECT_COMPONENTS= 100;
|
|
54 |
public static final int MAX_EFFECT_COMPONENTS= 98;
|
|
55 | 55 |
|
56 | 56 |
// sizes of attributes of an individual vertex. |
57 | 57 |
private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z |
... | ... | |
79 | 79 |
private static final int VERT1_SIZE = VERT1_ATTRIBS*BYTES_PER_FLOAT; |
80 | 80 |
private static final int VERT2_SIZE = VERT2_ATTRIBS*BYTES_PER_FLOAT; |
81 | 81 |
|
82 |
private static final int[] mCenterBlockIndex = new int[EffectQueue.MAIN_VARIANTS]; |
|
83 |
private static final int[] mAssocBlockIndex = new int[EffectQueue.MAIN_VARIANTS]; |
|
84 |
|
|
85 |
private static final int TEX_COMP_SIZE = 5; // 5 four-byte entities inside the component |
|
86 |
|
|
87 |
private static boolean mUseCenters; |
|
88 |
|
|
82 | 89 |
private boolean mShowNormals; // when rendering this mesh, draw normal vectors? |
83 | 90 |
private InternalBuffer mVBO1, mVBO2, mTFO; // main vertex buffer and transform feedback buffer |
84 | 91 |
private int mNumVertices; |
... | ... | |
86 | 93 |
private float[] mVertAttribs2; // packed: TexS,TexT, Component |
87 | 94 |
private float mInflate; |
88 | 95 |
private final UniformBlockAssociation mUBA; |
89 |
private final UniformBlockCenter mUBC;
|
|
96 |
private UniformBlockCenter mUBC; |
|
90 | 97 |
|
91 | 98 |
DeferredJobs.JobNode[] mJobNode; |
92 | 99 |
|
93 |
private static final int[] mCenterBlockIndex = new int[EffectQueue.MAIN_VARIANTS]; |
|
94 |
private static final int[] mAssocBlockIndex = new int[EffectQueue.MAIN_VARIANTS]; |
|
95 |
|
|
96 |
private static final int TEX_COMP_SIZE = 5; // 5 four-byte entities inside the component |
|
97 |
|
|
98 | 100 |
private static class TexComponent |
99 | 101 |
{ |
100 | 102 |
private int mEndIndex; |
... | ... | |
137 | 139 |
mJobNode = new DeferredJobs.JobNode[1]; |
138 | 140 |
|
139 | 141 |
mUBA = new UniformBlockAssociation(); |
140 |
mUBC = new UniformBlockCenter(); |
|
142 |
|
|
143 |
if( mUseCenters ) mUBC = new UniformBlockCenter(); |
|
141 | 144 |
|
142 | 145 |
mVBO1= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
143 | 146 |
mVBO2= new InternalBuffer(GLES30.GL_ARRAY_BUFFER , GLES30.GL_STATIC_READ); |
... | ... | |
154 | 157 |
mNumVertices= original.mNumVertices; |
155 | 158 |
|
156 | 159 |
mUBA = new UniformBlockAssociation(original.mUBA); |
157 |
mUBC = new UniformBlockCenter(original.mUBC); |
|
160 |
|
|
161 |
if( mUseCenters ) mUBC = new UniformBlockCenter(original.mUBC); |
|
158 | 162 |
|
159 | 163 |
if( deep ) |
160 | 164 |
{ |
... | ... | |
326 | 330 |
|
327 | 331 |
void setComponentCenterNow(int component, float x, float y, float z) |
328 | 332 |
{ |
329 |
mUBC.setEffectCenterNow(component, x, y, z); |
|
333 |
if( mUBC!=null ) |
|
334 |
{ |
|
335 |
mUBC.setEffectCenterNow(component, x, y, z); |
|
336 |
} |
|
330 | 337 |
} |
331 | 338 |
|
332 | 339 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
393 | 400 |
if( origEffComponents<MAX_EFFECT_COMPONENTS ) |
394 | 401 |
{ |
395 | 402 |
mUBA.copy(origEffComponents, mesh.mUBA, j); |
396 |
mUBC.copy(origEffComponents, mesh.mUBC, j); |
|
403 |
if( mUseCenters ) mUBC.copy(origEffComponents, mesh.mUBC, j);
|
|
397 | 404 |
origEffComponents++; |
398 | 405 |
} |
399 | 406 |
} |
... | ... | |
538 | 545 |
mVBO2.invalidate(); |
539 | 546 |
} |
540 | 547 |
|
548 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
549 |
/** |
|
550 |
* Are we going to need per-component centers (needed for correct postprocessing of concave meshes) |
|
551 |
* Switching this on allocates 16*MAX_EFFECT_COMPONENTS bytes for uniforms in the vertex shader. |
|
552 |
*/ |
|
553 |
public static void setUseCenters() |
|
554 |
{ |
|
555 |
mUseCenters = true; |
|
556 |
} |
|
557 |
|
|
558 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
559 |
/** |
|
560 |
* Are we using per-component centers? |
|
561 |
*/ |
|
562 |
public static boolean getUseCenters() |
|
563 |
{ |
|
564 |
return mUseCenters; |
|
565 |
} |
|
566 |
|
|
541 | 567 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
542 | 568 |
|
543 | 569 |
public static int getMaxEffComponents() |
... | ... | |
704 | 730 |
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, ASSOC_UBO_BINDING, indexA); |
705 | 731 |
GLES30.glUniformBlockBinding(programH, mAssocBlockIndex[variant], ASSOC_UBO_BINDING); |
706 | 732 |
|
707 |
int indexC = mUBC.getIndex(); |
|
708 |
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, CENTER_UBO_BINDING, indexC); |
|
709 |
GLES30.glUniformBlockBinding(programH, mCenterBlockIndex[variant], CENTER_UBO_BINDING); |
|
733 |
if( mUseCenters ) |
|
734 |
{ |
|
735 |
int indexC = mUBC.getIndex(); |
|
736 |
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, CENTER_UBO_BINDING, indexC); |
|
737 |
GLES30.glUniformBlockBinding(programH, mCenterBlockIndex[variant], CENTER_UBO_BINDING); |
|
738 |
} |
|
710 | 739 |
} |
711 | 740 |
|
712 | 741 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
902 | 931 |
case 2 : float[] centers = new float[3*numEff]; |
903 | 932 |
floatBuf.get(centers,0,3*numEff); |
904 | 933 |
|
905 |
for(int eff=0; eff<numEff; eff++)
|
|
934 |
if( mUseCenters )
|
|
906 | 935 |
{ |
907 |
mUBC.setEffectCenterNow(eff, centers[3*eff], centers[3*eff+1], centers[3*eff+2]); |
|
936 |
for(int eff=0; eff<numEff; eff++) |
|
937 |
{ |
|
938 |
mUBC.setEffectCenterNow(eff, centers[3*eff], centers[3*eff+1], centers[3*eff+2]); |
|
939 |
} |
|
908 | 940 |
} |
909 | 941 |
|
910 | 942 |
floatBuf.get(mVertAttribs1, 0, VERT1_ATTRIBS*mNumVertices); |
... | ... | |
983 | 1015 |
stream.writeFloat((float)mEffComponent.get(i)); |
984 | 1016 |
} |
985 | 1017 |
|
986 |
float[] centers = mUBC.getBackingArray();
|
|
1018 |
float[] centers = mUseCenters ? mUBC.getBackingArray() : new float[4*numEff];
|
|
987 | 1019 |
|
988 | 1020 |
for(int i=0; i<numEff; i++) |
989 | 1021 |
{ |
... | ... | |
1075 | 1107 |
mVBO2.markForDeletion(); |
1076 | 1108 |
mTFO.markForDeletion(); |
1077 | 1109 |
mUBA.markForDeletion(); |
1078 |
mUBC.markForDeletion(); |
|
1110 |
|
|
1111 |
if( mUBC!=null ) |
|
1112 |
{ |
|
1113 |
mUBC.markForDeletion(); |
|
1114 |
} |
|
1079 | 1115 |
} |
1080 | 1116 |
|
1081 | 1117 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Make per-component centers optional, controlled by API MeshBase.setUseCenters()