Revision 80961fc1
Added by Leszek Koltunski almost 4 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= 98;
|
|
54 |
public static final int MAX_EFFECT_COMPONENTS= 242;
|
|
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 |
... | ... | |
94 | 94 |
private float mInflate; |
95 | 95 |
private final UniformBlockAssociation mUBA; |
96 | 96 |
private UniformBlockCenter mUBC; |
97 |
private boolean mStrideCorrected; |
|
98 |
private static int mStride; |
|
97 | 99 |
|
98 | 100 |
DeferredJobs.JobNode[] mJobNode; |
99 | 101 |
|
... | ... | |
577 | 579 |
{ |
578 | 580 |
mCenterBlockIndex[variant]= GLES30.glGetUniformBlockIndex(programH, "componentCenter"); |
579 | 581 |
mAssocBlockIndex[variant] = GLES30.glGetUniformBlockIndex(programH, "componentAssociation"); |
582 |
|
|
583 |
if( mStride==0 ) |
|
584 |
{ |
|
585 |
String[] uniformNames = { "vComAssoc" }; |
|
586 |
int[] indices = new int[1]; |
|
587 |
int[] params = new int[1]; |
|
588 |
|
|
589 |
GLES30.glGetUniformIndices(programH, uniformNames, indices, 0); |
|
590 |
GLES30.glGetActiveUniformsiv( programH, 1, indices, 0, GLES30.GL_UNIFORM_ARRAY_STRIDE, params,0 ); |
|
591 |
|
|
592 |
mStride = params[0]/4; |
|
593 |
} |
|
580 | 594 |
} |
581 | 595 |
|
582 | 596 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
726 | 740 |
*/ |
727 | 741 |
public void send(int programH, int variant) |
728 | 742 |
{ |
743 |
if( !mStrideCorrected ) |
|
744 |
{ |
|
745 |
mStrideCorrected = true; |
|
746 |
mUBA.correctStride(mStride); |
|
747 |
} |
|
748 |
|
|
729 | 749 |
int indexA = mUBA.getIndex(); |
730 | 750 |
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, ASSOC_UBO_BINDING, indexA); |
731 | 751 |
GLES30.glUniformBlockBinding(programH, mAssocBlockIndex[variant], ASSOC_UBO_BINDING); |
src/main/java/org/distorted/library/uniformblock/UniformBlockAssociation.java | ||
---|---|---|
33 | 33 |
*/ |
34 | 34 |
public class UniformBlockAssociation |
35 | 35 |
{ |
36 |
private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS; |
|
37 | 36 |
private static final int DEFAULT_ASSOCIATION = 0xffffffff; |
37 |
private static final int DEFAULT_STRIDE = 2; |
|
38 |
private static final int LOC_AND = 0; |
|
39 |
private static final int LOC_EQU = 1; |
|
38 | 40 |
|
39 | 41 |
private final InternalBuffer mUBO; |
40 |
private final int[] mAssociations; |
|
42 |
private int[] mAssociations; |
|
43 |
private int mStride; |
|
41 | 44 |
|
42 | 45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
43 | 46 |
|
44 | 47 |
public UniformBlockAssociation() |
45 | 48 |
{ |
46 |
mAssociations= new int[BLOCK_SIZE/4]; |
|
49 |
mStride = DEFAULT_STRIDE; |
|
50 |
mAssociations= new int[mStride*MAX_EFFECT_COMPONENTS]; |
|
47 | 51 |
|
48 | 52 |
for(int i=0; i<MAX_EFFECT_COMPONENTS; i++) |
49 | 53 |
{ |
50 |
mAssociations[4*i ] = DEFAULT_ASSOCIATION;
|
|
51 |
mAssociations[4*i+2] = i;
|
|
54 |
mAssociations[mStride*i+LOC_AND] = DEFAULT_ASSOCIATION;
|
|
55 |
mAssociations[mStride*i+LOC_EQU] = i;
|
|
52 | 56 |
} |
53 | 57 |
|
54 | 58 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
... | ... | |
58 | 62 |
|
59 | 63 |
public UniformBlockAssociation(UniformBlockAssociation original) |
60 | 64 |
{ |
65 |
mStride = original.mStride; |
|
61 | 66 |
int size = original.mAssociations.length; |
62 | 67 |
mAssociations= new int[size]; |
63 | 68 |
System.arraycopy(original.mAssociations, 0, mAssociations, 0, size); |
... | ... | |
65 | 70 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
66 | 71 |
} |
67 | 72 |
|
73 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
74 |
|
|
75 |
public void correctStride(int stride) |
|
76 |
{ |
|
77 |
if( mStride != stride ) |
|
78 |
{ |
|
79 |
int[] tmp = new int[stride*MAX_EFFECT_COMPONENTS]; |
|
80 |
|
|
81 |
for(int i=0; i<MAX_EFFECT_COMPONENTS; i++) |
|
82 |
{ |
|
83 |
tmp[stride*i+LOC_AND] = mAssociations[mStride*i+LOC_AND]; |
|
84 |
tmp[stride*i+LOC_EQU] = mAssociations[mStride*i+LOC_EQU]; |
|
85 |
} |
|
86 |
|
|
87 |
mAssociations = tmp; |
|
88 |
mStride = stride; |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
68 | 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
69 | 93 |
|
70 | 94 |
public boolean matchesAssociation( int comp, int andAssoc, int equAssoc) |
71 | 95 |
{ |
72 |
return (andAssoc & mAssociations[4*comp]) != 0 || (equAssoc == mAssociations[4*comp+2]);
|
|
96 |
return (andAssoc & mAssociations[mStride*comp+LOC_AND]) != 0 || (equAssoc == mAssociations[mStride*comp+LOC_EQU]);
|
|
73 | 97 |
} |
74 | 98 |
|
75 | 99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
76 | 100 |
|
77 | 101 |
public void setEffectAssociationNow(int comp, int andAssociation, int equAssociation) |
78 | 102 |
{ |
79 |
mAssociations[4*comp ] = andAssociation;
|
|
80 |
mAssociations[4*comp+2] = equAssociation;
|
|
103 |
mAssociations[mStride*comp+LOC_AND] = andAssociation;
|
|
104 |
mAssociations[mStride*comp+LOC_EQU] = equAssociation;
|
|
81 | 105 |
|
82 | 106 |
mUBO.invalidate(); |
83 | 107 |
} |
... | ... | |
86 | 110 |
|
87 | 111 |
public int getIndex() |
88 | 112 |
{ |
89 |
return mUBO.createImmediatelyInt( BLOCK_SIZE, mAssociations);
|
|
113 |
return mUBO.createImmediatelyInt( 4*mStride*MAX_EFFECT_COMPONENTS, mAssociations);
|
|
90 | 114 |
} |
91 | 115 |
|
92 | 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
93 | 117 |
|
94 | 118 |
public void copy(int compTo, UniformBlockAssociation assocFrom, int compFrom) |
95 | 119 |
{ |
96 |
mAssociations[4*compTo ] = assocFrom.mAssociations[4*compFrom ];
|
|
97 |
mAssociations[4*compTo+2] = assocFrom.mAssociations[4*compFrom+2];
|
|
120 |
mAssociations[mStride*compTo+LOC_AND] = assocFrom.mAssociations[mStride*compFrom+LOC_AND];
|
|
121 |
mAssociations[mStride*compTo+LOC_EQU] = assocFrom.mAssociations[mStride*compFrom+LOC_EQU];
|
|
98 | 122 |
} |
99 | 123 |
|
100 | 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
115 | 139 |
|
116 | 140 |
for(int i=0; i<8; i++) |
117 | 141 |
{ |
118 |
builder.append(mAssociations[4*i]);
|
|
142 |
builder.append(mAssociations[mStride*i+LOC_AND]);
|
|
119 | 143 |
builder.append(' '); |
120 |
builder.append(mAssociations[4*i+2]);
|
|
144 |
builder.append(mAssociations[mStride*i+LOC_EQU]);
|
|
121 | 145 |
builder.append(' '); |
122 | 146 |
} |
123 | 147 |
|
src/main/res/raw/main_vertex_shader.glsl | ||
---|---|---|
65 | 65 |
// second vec4: first float - cache, next 3: Center, the third - the Region. |
66 | 66 |
}; |
67 | 67 |
|
68 |
layout (std140) uniform componentAssociation
|
|
68 |
layout (packed) uniform componentAssociation
|
|
69 | 69 |
{ |
70 |
ivec4 vComAssoc[MAX_COMPON]; // component Associations, 4 ints: |
|
71 |
// 1: component's AND association |
|
72 |
// 2: reserved. Probably another AND assoc in the future. |
|
73 |
// 3: component's EQU association |
|
74 |
// 4: reserved |
|
70 |
ivec2 vComAssoc[MAX_COMPON]; // component 'AND' and 'EQU' Associations |
|
75 | 71 |
}; |
76 | 72 |
|
77 | 73 |
////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
131 | 127 |
|
132 | 128 |
for(int i=0; i<vNumEffects; i++) |
133 | 129 |
{ |
134 |
if( ((vComAssoc[component].x & vProperties[i].y) != 0) || (vComAssoc[component].z == vProperties[i].w) )
|
|
130 |
if( ((vComAssoc[component].x & vProperties[i].y) != 0) || (vComAssoc[component].y == vProperties[i].w) )
|
|
135 | 131 |
{ |
136 | 132 |
// ENABLED EFFECTS WILL BE INSERTED HERE |
137 | 133 |
|
Also available in: Unified diff
Make the 'Component Associations' UBO (on most devices) twice smaller -
use the 'packed' layout and 'ivec2' in place of 'ivec4'.
This forces us to dynamically probe the 'Stride' - number of 4-byte entities that the UBO's 'ivec4' takes - and correct the already-constructed UniformBlockAssociation objects in case this turns out to be different than the expected 2, i.e. tightly-packed.
The point: this saves a lot of uniform space in th vertex shader, which lets us declare larger MAX_NUM_COMPONENTS - needed for the Gigaminx.
(and no, we cannot assume an UBO can hold at least 16KB since this is not the case on Samsung Galaxy J4+)