Revision de77a6c5
Added by Leszek Koltunski almost 4 years ago
src/main/java/org/distorted/library/effect/EffectType.java | ||
---|---|---|
71 | 71 |
*/ |
72 | 72 |
public static void reset(int[] maxtable) |
73 | 73 |
{ |
74 |
maxtable[0] =10; // By default, there can be a maximum 10 MATRIX effects in a single
|
|
75 |
// EffectQueueMatrix at any given time. This can be changed with a call |
|
76 |
// to EffectQueueMatrix.setMax(int) |
|
77 |
maxtable[1] = 5; // Max 5 VERTEX Effects
|
|
78 |
maxtable[2] = 5; // Max 5 FRAGMENT Effects
|
|
79 |
maxtable[3] = 3; // Max 3 POSTPROCESSING Effects |
|
74 |
maxtable[0] =100; // By default, there can be a maximum 100 MATRIX effects in a single
|
|
75 |
// EffectQueueMatrix at any given time. This can be changed with a call
|
|
76 |
// to EffectQueueMatrix.setMax(int)
|
|
77 |
maxtable[1] =100; // Max 100 VERTEX Effects
|
|
78 |
maxtable[2] =100; // Max 100 FRAGMENT Effects
|
|
79 |
maxtable[3] = 3; // Max 3 POSTPROCESSING Effects
|
|
80 | 80 |
} |
81 | 81 |
|
82 | 82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/effectqueue/EffectQueue.java | ||
---|---|---|
25 | 25 |
import org.distorted.library.main.DistortedLibrary; |
26 | 26 |
import org.distorted.library.main.InternalMaster; |
27 | 27 |
import org.distorted.library.main.InternalStackFrameList; |
28 |
import org.distorted.library.uniformblock.UniformBlockFloatUniforms; |
|
29 |
import org.distorted.library.uniformblock.UniformBlockIntUniforms; |
|
28 | 30 |
|
29 | 31 |
import java.util.ArrayList; |
30 | 32 |
import java.util.HashMap; |
... | ... | |
39 | 41 |
{ |
40 | 42 |
public static final int MAIN_VARIANTS = 4; // Number of Main program variants (ATM 4: MAIN, MAIN OIT, PREPROCESS, FULL) |
41 | 43 |
|
42 |
static final int PROP_VERT_UBO_BINDING = 5; |
|
43 |
static final int PROP_FRAG_UBO_BINDING = 6; |
|
44 |
static final int VERT_INT_UBO_BINDING = 5; |
|
45 |
static final int VERT_FLO_UBO_BINDING = 6; |
|
46 |
static final int FRAG_INT_UBO_BINDING = 7; |
|
47 |
static final int FRAG_FLO_UBO_BINDING = 8; |
|
44 | 48 |
|
45 | 49 |
private static final int CREATE = 0; |
46 | 50 |
private static final int ATTACH = 1; |
... | ... | |
50 | 54 |
long mTime; |
51 | 55 |
int mNumEffects; // 'ToBe' will be more than mNumEffects if doWork() hasn't |
52 | 56 |
private int mNumEffectsToBe; // added them yet (or less if it hasn't removed some yet) |
53 |
private final int mNumFloatUniforms; |
|
54 | 57 |
Effect[] mEffects; |
55 | 58 |
|
56 |
float[] mFloatUniforms;
|
|
57 |
UniformBlockProperties mUBP;
|
|
59 |
UniformBlockFloatUniforms mUBF;
|
|
60 |
UniformBlockIntUniforms mUBI;
|
|
58 | 61 |
|
59 | 62 |
private long mID; |
60 | 63 |
private final int mIndex; |
... | ... | |
83 | 86 |
|
84 | 87 |
EffectQueue(int numFloatUniforms, int numIntUniforms, int index) |
85 | 88 |
{ |
86 |
mCreated = false; |
|
87 |
mTime = 0; |
|
88 |
mID = 0; |
|
89 |
mNumEffects = 0; |
|
90 |
mNumEffectsToBe = 0; |
|
91 |
mIndex = index; |
|
92 |
mNumFloatUniforms = numFloatUniforms; |
|
93 |
|
|
94 |
mUBP = new UniformBlockProperties(numIntUniforms); |
|
89 |
mCreated = false; |
|
90 |
mTime = 0; |
|
91 |
mID = 0; |
|
92 |
mNumEffects = 0; |
|
93 |
mNumEffectsToBe = 0; |
|
94 |
mIndex = index; |
|
95 |
|
|
95 | 96 |
mJobs = new ArrayList<>(); |
96 | 97 |
|
97 | 98 |
mJobs.add(new Job(CREATE,numFloatUniforms,numIntUniforms, false,null)); // create the stuff that depends on max number |
... | ... | |
105 | 106 |
{ |
106 | 107 |
if( !source.mCreated ) |
107 | 108 |
{ |
108 |
mCreated = false; |
|
109 |
mTime = 0; |
|
110 |
mID = 0; |
|
111 |
mNumEffects = 0; |
|
112 |
mNumEffectsToBe = 0; |
|
113 |
mIndex = source.mIndex; |
|
114 |
mNumFloatUniforms = source.mNumFloatUniforms; |
|
115 |
|
|
116 |
mUBP = new UniformBlockProperties(source.mUBP); |
|
109 |
mCreated = false; |
|
110 |
mTime = 0; |
|
111 |
mID = 0; |
|
112 |
mNumEffects = 0; |
|
113 |
mNumEffectsToBe = 0; |
|
114 |
mIndex = source.mIndex; |
|
115 |
|
|
117 | 116 |
mJobs = new ArrayList<>(); |
118 | 117 |
|
119 | 118 |
int numJobs = source.mJobs.size(); |
... | ... | |
128 | 127 |
} |
129 | 128 |
else |
130 | 129 |
{ |
131 |
mCreated = true; |
|
132 |
mTime = source.mTime; |
|
133 |
mID = source.mID; |
|
134 |
mNumEffects = source.mNumEffects; |
|
135 |
mNumEffectsToBe = source.mNumEffectsToBe; |
|
136 |
mIndex = source.mIndex; |
|
137 |
mNumFloatUniforms = source.mNumFloatUniforms; |
|
138 |
|
|
139 |
mUBP = new UniformBlockProperties(source.mUBP); |
|
130 |
mCreated = true; |
|
131 |
mTime = source.mTime; |
|
132 |
mID = source.mID; |
|
133 |
mNumEffects = source.mNumEffects; |
|
134 |
mNumEffectsToBe = source.mNumEffectsToBe; |
|
135 |
mIndex = source.mIndex; |
|
136 |
|
|
140 | 137 |
mJobs = new ArrayList<>(); |
141 | 138 |
|
142 | 139 |
int max = InternalStackFrameList.getMax(mIndex); |
143 | 140 |
|
144 | 141 |
if( max>0 ) |
145 | 142 |
{ |
146 |
mEffects = new Effect[max]; |
|
147 |
mFloatUniforms = new float[max*source.mNumFloatUniforms]; |
|
143 |
mEffects= new Effect[max]; |
|
144 |
mUBI = new UniformBlockIntUniforms(source.mUBI); |
|
145 |
mUBF = new UniformBlockFloatUniforms(source.mUBF); |
|
148 | 146 |
|
149 | 147 |
if( mNumEffects>=0 ) |
150 | 148 |
{ |
... | ... | |
255 | 253 |
mNumEffects--; |
256 | 254 |
mEffects[pos].remQueue(this); |
257 | 255 |
System.arraycopy(mEffects, pos+1, mEffects, pos, mNumEffects-pos); |
258 |
mUBP.remove(pos, mNumEffects);
|
|
256 |
mUBI.remove(pos, mNumEffects);
|
|
259 | 257 |
mEffects[mNumEffects] = null; |
260 | 258 |
} |
261 | 259 |
} |
... | ... | |
265 | 263 |
private void addNow(int pos, Effect effect) |
266 | 264 |
{ |
267 | 265 |
mEffects[pos] = effect; |
268 |
mUBP.addOrdinal(pos, effect.getName().ordinal() );
|
|
266 |
mUBI.addOrdinal(pos, effect.getName().ordinal() );
|
|
269 | 267 |
effect.addQueue(this); |
270 | 268 |
|
271 | 269 |
if( mIndex==EffectType.VERTEX.ordinal() ) |
272 | 270 |
{ |
273 |
mUBP.addAssociations(pos,effect);
|
|
271 |
mUBI.addAssociations(pos,effect);
|
|
274 | 272 |
} |
275 | 273 |
} |
276 | 274 |
|
... | ... | |
413 | 411 |
{ |
414 | 412 |
if (mEffects[j].getID() == effectID) |
415 | 413 |
{ |
416 |
mUBP.addAssociations(j,mEffects[j]);
|
|
414 |
mUBI.addAssociations(j,mEffects[j]);
|
|
417 | 415 |
} |
418 | 416 |
} |
419 | 417 |
} |
... | ... | |
422 | 420 |
|
423 | 421 |
public void markForDeletion() |
424 | 422 |
{ |
425 |
mUBP.markForDeletion(); |
|
423 |
mUBI.markForDeletion(); |
|
424 |
mUBF.markForDeletion(); |
|
426 | 425 |
} |
427 | 426 |
|
428 | 427 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
442 | 441 |
case CREATE: int max = InternalStackFrameList.getMax(mIndex); |
443 | 442 |
if( max>0 ) |
444 | 443 |
{ |
445 |
mEffects = new Effect[max];
|
|
446 |
mFloatUniforms = new float[max*job.num1];
|
|
447 |
mUBP = new UniformBlockProperties(job.num2);
|
|
444 |
mEffects= new Effect[max]; |
|
445 |
mUBF = new UniformBlockFloatUniforms(job.num1, max);
|
|
446 |
mUBI = new UniformBlockIntUniforms (job.num2, max);
|
|
448 | 447 |
} |
449 | 448 |
mCreated = true; |
450 | 449 |
|
... | ... | |
462 | 461 |
else if( position<=mNumEffects ) |
463 | 462 |
{ |
464 | 463 |
System.arraycopy(mEffects, position, mEffects, position+1, mNumEffects-position); |
465 |
mUBP.makeHole(position, mNumEffects);
|
|
464 |
mUBI.makeHole(position, mNumEffects);
|
|
466 | 465 |
addNow(position,job.effect); |
467 | 466 |
mNumEffects++; |
468 | 467 |
changed = true; |
src/main/java/org/distorted/library/effectqueue/EffectQueueFragment.java | ||
---|---|---|
34 | 34 |
|
35 | 35 |
private static final int INDEX = EffectType.FRAGMENT.ordinal(); |
36 | 36 |
|
37 |
private final static int[] mNumEffectsH = new int[MAIN_VARIANTS];
|
|
38 |
private final static int[] mUniformsH = new int[MAIN_VARIANTS];
|
|
39 |
private final static int[] mPropBlockIndex= new int[MAIN_VARIANTS];
|
|
37 |
private final static int[] mNumEffectsH = new int[MAIN_VARIANTS]; |
|
38 |
private final static int[] mIntBlockIndex= new int[MAIN_VARIANTS];
|
|
39 |
private final static int[] mFloBlockIndex= new int[MAIN_VARIANTS];
|
|
40 | 40 |
|
41 | 41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
42 | 42 |
|
... | ... | |
56 | 56 |
|
57 | 57 |
static void uniforms(int mProgramH, int variant) |
58 | 58 |
{ |
59 |
mNumEffectsH[variant] = GLES30.glGetUniformLocation ( mProgramH, "fNumEffects");
|
|
60 |
mUniformsH[variant] = GLES30.glGetUniformLocation ( mProgramH, "fUniforms");
|
|
61 |
mPropBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "fUniformProperties");
|
|
59 |
mNumEffectsH[variant] = GLES30.glGetUniformLocation ( mProgramH, "fNumEffects"); |
|
60 |
mIntBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "fUniformProperties");
|
|
61 |
mFloBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "fUniformFloats");
|
|
62 | 62 |
} |
63 | 63 |
|
64 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
67 | 67 |
{ |
68 | 68 |
if( currTime==mTime ) return; |
69 | 69 |
if( mTime==0 ) mTime = currTime; |
70 |
long step = (currTime-mTime); |
|
71 | 70 |
|
72 |
for(int i=0; i<mNumEffects; i++)
|
|
71 |
if( mNumEffects>0 )
|
|
73 | 72 |
{ |
74 |
if( mEffects[i].compute(mFloatUniforms, NUM_FLOAT_UNIFORMS*i, currTime, step) ) |
|
73 |
long step = (currTime-mTime); |
|
74 |
float[] array = mUBF.getBackingArray(); |
|
75 |
|
|
76 |
for(int i=0; i<mNumEffects; i++) |
|
75 | 77 |
{ |
76 |
EffectMessageSender.newMessage(mEffects[i]); |
|
78 |
if( mEffects[i].compute(array, NUM_FLOAT_UNIFORMS*i, currTime, step) ) |
|
79 |
{ |
|
80 |
EffectMessageSender.newMessage(mEffects[i]); |
|
81 |
} |
|
77 | 82 |
} |
83 |
|
|
84 |
mUBF.invalidate(); |
|
78 | 85 |
} |
79 | 86 |
|
80 | 87 |
mTime = currTime; |
... | ... | |
88 | 95 |
|
89 | 96 |
if( mNumEffects>0 ) |
90 | 97 |
{ |
91 |
int index = mUBP.getIndex(); |
|
92 |
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, PROP_FRAG_UBO_BINDING, index); |
|
93 |
GLES30.glUniformBlockBinding(programH, mPropBlockIndex[variant], PROP_FRAG_UBO_BINDING); |
|
94 |
GLES30.glUniform4fv( mUniformsH[variant],(NUM_FLOAT_UNIFORMS/4)*mNumEffects, mFloatUniforms, 0); |
|
98 |
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, FRAG_INT_UBO_BINDING, mUBI.getIndex()); |
|
99 |
GLES30.glUniformBlockBinding(programH, mIntBlockIndex[variant], FRAG_INT_UBO_BINDING); |
|
100 |
|
|
101 |
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, FRAG_FLO_UBO_BINDING, mUBF.getIndex()); |
|
102 |
GLES30.glUniformBlockBinding(programH, mFloBlockIndex[variant], FRAG_FLO_UBO_BINDING); |
|
95 | 103 |
} |
96 | 104 |
} |
97 | 105 |
} |
src/main/java/org/distorted/library/effectqueue/EffectQueueMatrix.java | ||
---|---|---|
35 | 35 |
|
36 | 36 |
private static final int INDEX = EffectType.MATRIX.ordinal(); |
37 | 37 |
|
38 |
private static float[] mMVPMatrix = new float[16]; |
|
39 |
private static float[] mModelViewMatrixP= new float[16]; |
|
40 |
private static float[] mModelViewMatrixV= new float[16]; |
|
38 |
private static final float[] mMVPMatrix = new float[16];
|
|
39 |
private static final float[] mModelViewMatrixP= new float[16];
|
|
40 |
private static final float[] mModelViewMatrixV= new float[16];
|
|
41 | 41 |
|
42 |
private static int[] mMVPMatrixH = new int[MAIN_VARIANTS]; |
|
43 |
private static int[] mMVMatrixPH = new int[MAIN_VARIANTS]; |
|
44 |
private static int[] mMVMatrixVH = new int[MAIN_VARIANTS]; |
|
42 |
private static final int[] mMVPMatrixH = new int[MAIN_VARIANTS];
|
|
43 |
private static final int[] mMVMatrixPH = new int[MAIN_VARIANTS];
|
|
44 |
private static final int[] mMVMatrixVH = new int[MAIN_VARIANTS];
|
|
45 | 45 |
|
46 | 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
47 | 47 |
|
... | ... | |
73 | 73 |
if( currTime==mTime ) return; |
74 | 74 |
if( mTime==0 ) mTime = currTime; |
75 | 75 |
long step = (currTime-mTime); |
76 |
float[] array = mUBF.getBackingArray(); |
|
76 | 77 |
|
77 | 78 |
for(int i=0; i<mNumEffects; i++) |
78 | 79 |
{ |
79 |
if( mEffects[i].compute(mFloatUniforms, NUM_FLOAT_UNIFORMS*i, currTime, step) )
|
|
80 |
if( mEffects[i].compute(array, NUM_FLOAT_UNIFORMS*i, currTime, step) )
|
|
80 | 81 |
{ |
81 | 82 |
EffectMessageSender.newMessage(mEffects[i]); |
82 | 83 |
} |
... | ... | |
114 | 115 |
mModelViewMatrixV[14] = mModelViewMatrixP[14]; |
115 | 116 |
mModelViewMatrixV[15] = mModelViewMatrixP[15]; |
116 | 117 |
|
118 |
float[] array = mUBF.getBackingArray(); |
|
119 |
|
|
117 | 120 |
// the 'Model' part of the MV matrix |
118 | 121 |
for(int i=mNumEffects-1; i>=0; i--) |
119 | 122 |
{ |
120 |
((MatrixEffect)mEffects[i]).apply(mModelViewMatrixP,mModelViewMatrixV,mFloatUniforms,i);
|
|
123 |
((MatrixEffect)mEffects[i]).apply(mModelViewMatrixP,mModelViewMatrixV,array,i);
|
|
121 | 124 |
} |
122 | 125 |
|
123 | 126 |
// combined Model-View-Projection matrix |
src/main/java/org/distorted/library/effectqueue/EffectQueuePostprocess.java | ||
---|---|---|
85 | 85 |
mR = mG = mB = mA = 0.0f; |
86 | 86 |
mHalo = 0; |
87 | 87 |
int halo; |
88 |
float[] array = mUBF.getBackingArray(); |
|
88 | 89 |
|
89 | 90 |
for(int i=0; i<mNumEffects; i++) |
90 | 91 |
{ |
91 | 92 |
// first zero out the 'alpha' because BLUR effect will not overwrite this (it is a 1D effect) |
92 | 93 |
// and if previously there was a GLOW effect here then mA would be non-zero and we don't want |
93 | 94 |
// that (see preprocess()) |
94 |
mFloatUniforms[NUM_FLOAT_UNIFORMS*i+5]=0.0f;
|
|
95 |
array[NUM_FLOAT_UNIFORMS*i+5]=0.0f;
|
|
95 | 96 |
|
96 |
if( mEffects[i].compute(mFloatUniforms, NUM_FLOAT_UNIFORMS*i, currTime, step) )
|
|
97 |
if( mEffects[i].compute(array, NUM_FLOAT_UNIFORMS*i, currTime, step) )
|
|
97 | 98 |
{ |
98 | 99 |
EffectMessageSender.newMessage(mEffects[i]); |
99 | 100 |
} |
100 | 101 |
|
101 |
halo = (int)mFloatUniforms[NUM_FLOAT_UNIFORMS*i];
|
|
102 |
halo = (int)array[NUM_FLOAT_UNIFORMS*i];
|
|
102 | 103 |
if( halo>mHalo ) mHalo = halo; |
103 | 104 |
} |
104 | 105 |
|
105 | 106 |
// TODO (now only really works in case of 1 effect!) |
106 | 107 |
if( mNumEffects>0 ) |
107 | 108 |
{ |
108 |
mR = mFloatUniforms[2];
|
|
109 |
mG = mFloatUniforms[3];
|
|
110 |
mB = mFloatUniforms[4];
|
|
111 |
mA = mFloatUniforms[5];
|
|
109 |
mR = array[2];
|
|
110 |
mG = array[3];
|
|
111 |
mB = array[4];
|
|
112 |
mA = array[5];
|
|
112 | 113 |
} |
113 | 114 |
|
114 | 115 |
mTime = currTime; |
... | ... | |
211 | 212 |
public int postprocess(DistortedFramebuffer buffer) |
212 | 213 |
{ |
213 | 214 |
int numRenders = 0; |
215 |
float[] array = mUBF.getBackingArray(); |
|
214 | 216 |
|
215 | 217 |
GLES30.glDisable(GLES30.GL_BLEND); |
216 | 218 |
|
217 | 219 |
for(int i=0; i<mNumEffects; i++) |
218 | 220 |
{ |
219 |
numRenders += ((PostprocessEffect)mEffects[i]).apply(mFloatUniforms,NUM_FLOAT_UNIFORMS*i, buffer);
|
|
221 |
numRenders += ((PostprocessEffect)mEffects[i]).apply(array,NUM_FLOAT_UNIFORMS*i, buffer);
|
|
220 | 222 |
} |
221 | 223 |
|
222 | 224 |
GLES30.glEnable(GLES30.GL_BLEND); |
src/main/java/org/distorted/library/effectqueue/EffectQueueVertex.java | ||
---|---|---|
38 | 38 |
|
39 | 39 |
private static final int INDEX = EffectType.VERTEX.ordinal(); |
40 | 40 |
|
41 |
private final static int[] mNumEffectsH = new int[MAIN_VARIANTS];
|
|
42 |
private final static int[] mInflateH = new int[MAIN_VARIANTS];
|
|
43 |
private final static int[] mUniformsH = new int[MAIN_VARIANTS];
|
|
44 |
private final static int[] mPropBlockIndex= new int[MAIN_VARIANTS];
|
|
41 |
private final static int[] mNumEffectsH = new int[MAIN_VARIANTS]; |
|
42 |
private final static int[] mInflateH = new int[MAIN_VARIANTS]; |
|
43 |
private final static int[] mIntBlockIndex= new int[MAIN_VARIANTS];
|
|
44 |
private final static int[] mFloBlockIndex= new int[MAIN_VARIANTS];
|
|
45 | 45 |
|
46 | 46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
47 | 47 |
|
... | ... | |
61 | 61 |
|
62 | 62 |
static void uniforms(int mProgramH, int variant) |
63 | 63 |
{ |
64 |
mNumEffectsH[variant] = GLES30.glGetUniformLocation ( mProgramH, "vNumEffects");
|
|
65 |
mInflateH[variant] = GLES30.glGetUniformLocation ( mProgramH, "u_Inflate");
|
|
66 |
mUniformsH[variant] = GLES30.glGetUniformLocation ( mProgramH, "vUniforms");
|
|
67 |
mPropBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "vUniformProperties");
|
|
64 |
mNumEffectsH[variant] = GLES30.glGetUniformLocation ( mProgramH, "vNumEffects"); |
|
65 |
mInflateH[variant] = GLES30.glGetUniformLocation ( mProgramH, "u_Inflate"); |
|
66 |
mIntBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "vUniformProperties");
|
|
67 |
mFloBlockIndex[variant] = GLES30.glGetUniformBlockIndex( mProgramH, "vUniformFloats");
|
|
68 | 68 |
} |
69 | 69 |
|
70 | 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
77 | 77 |
{ |
78 | 78 |
if( currTime==mTime ) return; |
79 | 79 |
if( mTime==0 ) mTime = currTime; |
80 |
long step = (currTime-mTime); |
|
81 | 80 |
|
82 |
for(int i=0; i<mNumEffects; i++)
|
|
81 |
if( mNumEffects>0 )
|
|
83 | 82 |
{ |
84 |
if( mEffects[i].compute(mFloatUniforms, NUM_FLOAT_UNIFORMS*i, currTime, step) ) |
|
83 |
long step = (currTime-mTime); |
|
84 |
float[] array = mUBF.getBackingArray(); |
|
85 |
|
|
86 |
for(int i=0; i<mNumEffects; i++) |
|
85 | 87 |
{ |
86 |
EffectMessageSender.newMessage(mEffects[i]); |
|
88 |
if( mEffects[i].compute(array, NUM_FLOAT_UNIFORMS*i, currTime, step) ) |
|
89 |
{ |
|
90 |
EffectMessageSender.newMessage(mEffects[i]); |
|
91 |
} |
|
87 | 92 |
} |
93 |
|
|
94 |
mUBF.invalidate(); |
|
88 | 95 |
} |
89 | 96 |
|
90 | 97 |
mTime = currTime; |
... | ... | |
103 | 110 |
|
104 | 111 |
if( mNumEffects>0 ) |
105 | 112 |
{ |
106 |
int index = mUBP.getIndex(); |
|
107 |
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, PROP_VERT_UBO_BINDING, index); |
|
108 |
GLES30.glUniformBlockBinding(programH, mPropBlockIndex[variant], PROP_VERT_UBO_BINDING); |
|
109 |
GLES30.glUniform4fv( mUniformsH[variant] ,(NUM_FLOAT_UNIFORMS/4)*mNumEffects, mFloatUniforms , 0); |
|
113 |
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, VERT_INT_UBO_BINDING, mUBI.getIndex()); |
|
114 |
GLES30.glUniformBlockBinding(programH, mIntBlockIndex[variant], VERT_INT_UBO_BINDING); |
|
115 |
|
|
116 |
GLES30.glBindBufferBase(GLES30.GL_UNIFORM_BUFFER, VERT_FLO_UBO_BINDING, mUBF.getIndex()); |
|
117 |
GLES30.glUniformBlockBinding(programH, mFloBlockIndex[variant], VERT_FLO_UBO_BINDING); |
|
110 | 118 |
} |
111 | 119 |
} |
112 | 120 |
} |
src/main/java/org/distorted/library/effectqueue/UniformBlockProperties.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2021 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.library.effectqueue; |
|
21 |
|
|
22 |
import android.opengl.GLES30; |
|
23 |
|
|
24 |
import org.distorted.library.effect.Effect; |
|
25 |
import org.distorted.library.main.InternalBuffer; |
|
26 |
|
|
27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
28 |
|
|
29 |
class UniformBlockProperties |
|
30 |
{ |
|
31 |
private static final int NUM_BYTES = 4*100; |
|
32 |
|
|
33 |
private final InternalBuffer mUBO; |
|
34 |
private final int[] mProperties; |
|
35 |
private final int mNumIntUniforms; |
|
36 |
|
|
37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
38 |
|
|
39 |
UniformBlockProperties(int numUniforms) |
|
40 |
{ |
|
41 |
mProperties= new int[NUM_BYTES/4]; |
|
42 |
mNumIntUniforms = numUniforms; |
|
43 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
44 |
} |
|
45 |
|
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
|
48 |
UniformBlockProperties(UniformBlockProperties original) |
|
49 |
{ |
|
50 |
int size = original.mProperties.length; |
|
51 |
mProperties= new int[size]; |
|
52 |
System.arraycopy(original.mProperties, 0, mProperties, 0, size); |
|
53 |
mNumIntUniforms = original.mNumIntUniforms; |
|
54 |
|
|
55 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
56 |
} |
|
57 |
|
|
58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
59 |
|
|
60 |
int getIndex() |
|
61 |
{ |
|
62 |
return mUBO.createImmediatelyInt( NUM_BYTES, mProperties); |
|
63 |
} |
|
64 |
|
|
65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
66 |
|
|
67 |
void remove(int pos, int numEffects) |
|
68 |
{ |
|
69 |
System.arraycopy(mProperties, mNumIntUniforms*(pos+1), mProperties, mNumIntUniforms*pos, mNumIntUniforms*(numEffects-pos) ); |
|
70 |
mUBO.invalidate(); |
|
71 |
} |
|
72 |
|
|
73 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
74 |
|
|
75 |
void makeHole(int pos, int numEffects) |
|
76 |
{ |
|
77 |
System.arraycopy(mProperties, mNumIntUniforms*pos, mProperties, mNumIntUniforms*(pos+1), mNumIntUniforms*(numEffects-pos) ); |
|
78 |
mUBO.invalidate(); |
|
79 |
} |
|
80 |
|
|
81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 |
|
|
83 |
void addOrdinal(int pos, int ordinal) |
|
84 |
{ |
|
85 |
mProperties[mNumIntUniforms*pos] = ordinal; |
|
86 |
mUBO.invalidate(); |
|
87 |
} |
|
88 |
|
|
89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
90 |
|
|
91 |
void addAssociations(int pos, Effect effect) |
|
92 |
{ |
|
93 |
effect.writeAssociations(mProperties, mNumIntUniforms*pos+1, mNumIntUniforms*pos+3); |
|
94 |
mUBO.invalidate(); |
|
95 |
} |
|
96 |
|
|
97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
98 |
|
|
99 |
void markForDeletion() |
|
100 |
{ |
|
101 |
mUBO.markForDeletion(); |
|
102 |
} |
|
103 |
|
|
104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
105 |
|
|
106 |
void print(int num) |
|
107 |
{ |
|
108 |
StringBuilder builder = new StringBuilder(); |
|
109 |
|
|
110 |
builder.append(mUBO.getID()); |
|
111 |
builder.append(':'); |
|
112 |
|
|
113 |
for(int i=0; i<6; i++) |
|
114 |
{ |
|
115 |
builder.append(' '); |
|
116 |
builder.append(mProperties[4*i ]); |
|
117 |
builder.append(' '); |
|
118 |
builder.append(mProperties[4*i+1]); |
|
119 |
builder.append(' '); |
|
120 |
builder.append(mProperties[4*i+2]); |
|
121 |
builder.append(','); |
|
122 |
} |
|
123 |
|
|
124 |
builder.append(' '); |
|
125 |
builder.append('('); |
|
126 |
builder.append(num); |
|
127 |
builder.append(')'); |
|
128 |
|
|
129 |
String res = builder.toString(); |
|
130 |
|
|
131 |
android.util.Log.e("ubp", res); |
|
132 |
} |
|
133 |
} |
src/main/java/org/distorted/library/main/InternalBuffer.java | ||
---|---|---|
42 | 42 |
private static final int RECREATE = 1; |
43 | 43 |
private static final int UPDATE = 2; |
44 | 44 |
|
45 |
private int mStatus; |
|
45 |
private int mStatus, mSize;
|
|
46 | 46 |
private final int[] mIndex; |
47 |
private int mTarget, mSize, mUsage;
|
|
47 |
private final int mTarget, mUsage;
|
|
48 | 48 |
private Buffer mBuffer; |
49 | 49 |
|
50 | 50 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/mesh/MeshBase.java | ||
---|---|---|
29 | 29 |
import org.distorted.library.main.InternalBuffer; |
30 | 30 |
import org.distorted.library.program.DistortedProgram; |
31 | 31 |
import org.distorted.library.type.Static4D; |
32 |
import org.distorted.library.uniformblock.UniformBlockAssociation; |
|
33 |
import org.distorted.library.uniformblock.UniformBlockCenter; |
|
32 | 34 |
|
33 | 35 |
import java.io.DataOutputStream; |
34 | 36 |
import java.io.IOException; |
... | ... | |
49 | 51 |
{ |
50 | 52 |
private static final int ASSOC_UBO_BINDING = 3; |
51 | 53 |
private static final int CENTER_UBO_BINDING = 4; |
52 |
static final int MAX_EFFECT_COMPONENTS= 100;
|
|
54 |
public static final int MAX_EFFECT_COMPONENTS= 100;
|
|
53 | 55 |
|
54 | 56 |
// sizes of attributes of an individual vertex. |
55 | 57 |
private static final int POS_DATA_SIZE= 3; // vertex coordinates: x,y,z |
src/main/java/org/distorted/library/mesh/UniformBlockAssociation.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.library.mesh; |
|
21 |
|
|
22 |
import android.opengl.GLES30; |
|
23 |
|
|
24 |
import org.distorted.library.main.InternalBuffer; |
|
25 |
|
|
26 |
import static org.distorted.library.mesh.MeshBase.MAX_EFFECT_COMPONENTS; |
|
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
|
|
30 |
class UniformBlockAssociation |
|
31 |
{ |
|
32 |
private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS; |
|
33 |
private static final int DEFAULT_ASSOCIATION = 0xffffffff; |
|
34 |
|
|
35 |
private final InternalBuffer mUBO; |
|
36 |
private final int[] mAssociations; |
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
UniformBlockAssociation() |
|
41 |
{ |
|
42 |
mAssociations= new int[BLOCK_SIZE/4]; |
|
43 |
|
|
44 |
for(int i=0; i<MAX_EFFECT_COMPONENTS; i++) |
|
45 |
{ |
|
46 |
mAssociations[4*i ] = DEFAULT_ASSOCIATION; |
|
47 |
mAssociations[4*i+2] = i; |
|
48 |
} |
|
49 |
|
|
50 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
51 |
} |
|
52 |
|
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
|
|
55 |
UniformBlockAssociation(UniformBlockAssociation original) |
|
56 |
{ |
|
57 |
int size = original.mAssociations.length; |
|
58 |
mAssociations= new int[size]; |
|
59 |
System.arraycopy(original.mAssociations, 0, mAssociations, 0, size); |
|
60 |
|
|
61 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
62 |
} |
|
63 |
|
|
64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 |
|
|
66 |
boolean matchesAssociation( int comp, int andAssoc, int equAssoc) |
|
67 |
{ |
|
68 |
return (andAssoc & mAssociations[4*comp]) != 0 || (equAssoc == mAssociations[4*comp+2]); |
|
69 |
} |
|
70 |
|
|
71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
72 |
|
|
73 |
void setEffectAssociationNow(int comp, int andAssociation, int equAssociation) |
|
74 |
{ |
|
75 |
mAssociations[4*comp ] = andAssociation; |
|
76 |
mAssociations[4*comp+2] = equAssociation; |
|
77 |
|
|
78 |
mUBO.invalidate(); |
|
79 |
} |
|
80 |
|
|
81 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 |
|
|
83 |
int getIndex() |
|
84 |
{ |
|
85 |
return mUBO.createImmediatelyInt( BLOCK_SIZE, mAssociations); |
|
86 |
} |
|
87 |
|
|
88 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
89 |
|
|
90 |
void copy(int compTo, UniformBlockAssociation assocFrom, int compFrom) |
|
91 |
{ |
|
92 |
mAssociations[4*compTo ] = assocFrom.mAssociations[4*compFrom ]; |
|
93 |
mAssociations[4*compTo+2] = assocFrom.mAssociations[4*compFrom+2]; |
|
94 |
} |
|
95 |
|
|
96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
97 |
|
|
98 |
void markForDeletion() |
|
99 |
{ |
|
100 |
mUBO.markForDeletion(); |
|
101 |
} |
|
102 |
|
|
103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
104 |
|
|
105 |
void print() |
|
106 |
{ |
|
107 |
StringBuilder builder = new StringBuilder(); |
|
108 |
|
|
109 |
builder.append(mUBO.getID()); |
|
110 |
builder.append(' '); |
|
111 |
|
|
112 |
for(int i=0; i<8; i++) |
|
113 |
{ |
|
114 |
builder.append(mAssociations[4*i]); |
|
115 |
builder.append(' '); |
|
116 |
builder.append(mAssociations[4*i+2]); |
|
117 |
builder.append(' '); |
|
118 |
} |
|
119 |
|
|
120 |
String res = builder.toString(); |
|
121 |
|
|
122 |
android.util.Log.e("uba", res); |
|
123 |
} |
|
124 |
} |
src/main/java/org/distorted/library/mesh/UniformBlockCenter.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.library.mesh; |
|
21 |
|
|
22 |
import android.opengl.GLES30; |
|
23 |
|
|
24 |
import org.distorted.library.main.InternalBuffer; |
|
25 |
|
|
26 |
import static org.distorted.library.mesh.MeshBase.MAX_EFFECT_COMPONENTS; |
|
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
|
|
30 |
class UniformBlockCenter |
|
31 |
{ |
|
32 |
private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS; |
|
33 |
|
|
34 |
private final InternalBuffer mUBO; |
|
35 |
private final float[] mCenter; |
|
36 |
|
|
37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
38 |
|
|
39 |
UniformBlockCenter() |
|
40 |
{ |
|
41 |
mCenter= new float[BLOCK_SIZE/4]; |
|
42 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
43 |
} |
|
44 |
|
|
45 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
46 |
|
|
47 |
UniformBlockCenter(UniformBlockCenter original) |
|
48 |
{ |
|
49 |
int size = original.mCenter.length; |
|
50 |
mCenter= new float[size]; |
|
51 |
System.arraycopy(original.mCenter, 0, mCenter, 0, size); |
|
52 |
|
|
53 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
54 |
} |
|
55 |
|
|
56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
57 |
|
|
58 |
void setEffectCenterNow(int comp, float x, float y, float z) |
|
59 |
{ |
|
60 |
mCenter[4*comp ] = x; |
|
61 |
mCenter[4*comp+1] = y; |
|
62 |
mCenter[4*comp+2] = z; |
|
63 |
|
|
64 |
mUBO.invalidate(); |
|
65 |
} |
|
66 |
|
|
67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
68 |
|
|
69 |
int getIndex() |
|
70 |
{ |
|
71 |
return mUBO.createImmediatelyFloat( BLOCK_SIZE, mCenter); |
|
72 |
} |
|
73 |
|
|
74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
75 |
|
|
76 |
void copy(int compTo, UniformBlockCenter blockFrom, int compFrom) |
|
77 |
{ |
|
78 |
mCenter[4*compTo ] = blockFrom.mCenter[4*compFrom ]; |
|
79 |
mCenter[4*compTo+1] = blockFrom.mCenter[4*compFrom+1]; |
|
80 |
mCenter[4*compTo+2] = blockFrom.mCenter[4*compFrom+2]; |
|
81 |
} |
|
82 |
|
|
83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
84 |
|
|
85 |
void markForDeletion() |
|
86 |
{ |
|
87 |
mUBO.markForDeletion(); |
|
88 |
} |
|
89 |
|
|
90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
91 |
|
|
92 |
float[] getBackingArray() |
|
93 |
{ |
|
94 |
return mCenter; |
|
95 |
} |
|
96 |
} |
src/main/java/org/distorted/library/uniformblock/UniformBlockAssociation.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.library.uniformblock; |
|
21 |
|
|
22 |
import android.opengl.GLES30; |
|
23 |
|
|
24 |
import org.distorted.library.main.InternalBuffer; |
|
25 |
|
|
26 |
import static org.distorted.library.mesh.MeshBase.MAX_EFFECT_COMPONENTS; |
|
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
/** |
|
30 |
* Not part of public API, do not document |
|
31 |
* |
|
32 |
* @y.exclude |
|
33 |
*/ |
|
34 |
public class UniformBlockAssociation |
|
35 |
{ |
|
36 |
private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS; |
|
37 |
private static final int DEFAULT_ASSOCIATION = 0xffffffff; |
|
38 |
|
|
39 |
private final InternalBuffer mUBO; |
|
40 |
private final int[] mAssociations; |
|
41 |
|
|
42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
43 |
|
|
44 |
public UniformBlockAssociation() |
|
45 |
{ |
|
46 |
mAssociations= new int[BLOCK_SIZE/4]; |
|
47 |
|
|
48 |
for(int i=0; i<MAX_EFFECT_COMPONENTS; i++) |
|
49 |
{ |
|
50 |
mAssociations[4*i ] = DEFAULT_ASSOCIATION; |
|
51 |
mAssociations[4*i+2] = i; |
|
52 |
} |
|
53 |
|
|
54 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
55 |
} |
|
56 |
|
|
57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 |
|
|
59 |
public UniformBlockAssociation(UniformBlockAssociation original) |
|
60 |
{ |
|
61 |
int size = original.mAssociations.length; |
|
62 |
mAssociations= new int[size]; |
|
63 |
System.arraycopy(original.mAssociations, 0, mAssociations, 0, size); |
|
64 |
|
|
65 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
66 |
} |
|
67 |
|
|
68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
69 |
|
|
70 |
public boolean matchesAssociation( int comp, int andAssoc, int equAssoc) |
|
71 |
{ |
|
72 |
return (andAssoc & mAssociations[4*comp]) != 0 || (equAssoc == mAssociations[4*comp+2]); |
|
73 |
} |
|
74 |
|
|
75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
76 |
|
|
77 |
public void setEffectAssociationNow(int comp, int andAssociation, int equAssociation) |
|
78 |
{ |
|
79 |
mAssociations[4*comp ] = andAssociation; |
|
80 |
mAssociations[4*comp+2] = equAssociation; |
|
81 |
|
|
82 |
mUBO.invalidate(); |
|
83 |
} |
|
84 |
|
|
85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
86 |
|
|
87 |
public int getIndex() |
|
88 |
{ |
|
89 |
return mUBO.createImmediatelyInt( BLOCK_SIZE, mAssociations); |
|
90 |
} |
|
91 |
|
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
|
|
94 |
public void copy(int compTo, UniformBlockAssociation assocFrom, int compFrom) |
|
95 |
{ |
|
96 |
mAssociations[4*compTo ] = assocFrom.mAssociations[4*compFrom ]; |
|
97 |
mAssociations[4*compTo+2] = assocFrom.mAssociations[4*compFrom+2]; |
|
98 |
} |
|
99 |
|
|
100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
101 |
|
|
102 |
public void markForDeletion() |
|
103 |
{ |
|
104 |
mUBO.markForDeletion(); |
|
105 |
} |
|
106 |
|
|
107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
108 |
|
|
109 |
public void print() |
|
110 |
{ |
|
111 |
StringBuilder builder = new StringBuilder(); |
|
112 |
|
|
113 |
builder.append(mUBO.getID()); |
|
114 |
builder.append(' '); |
|
115 |
|
|
116 |
for(int i=0; i<8; i++) |
|
117 |
{ |
|
118 |
builder.append(mAssociations[4*i]); |
|
119 |
builder.append(' '); |
|
120 |
builder.append(mAssociations[4*i+2]); |
|
121 |
builder.append(' '); |
|
122 |
} |
|
123 |
|
|
124 |
String res = builder.toString(); |
|
125 |
|
|
126 |
android.util.Log.e("uba", res); |
|
127 |
} |
|
128 |
} |
src/main/java/org/distorted/library/uniformblock/UniformBlockCenter.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2020 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.library.uniformblock; |
|
21 |
|
|
22 |
import android.opengl.GLES30; |
|
23 |
|
|
24 |
import org.distorted.library.main.InternalBuffer; |
|
25 |
|
|
26 |
import static org.distorted.library.mesh.MeshBase.MAX_EFFECT_COMPONENTS; |
|
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
/** |
|
30 |
* Not part of public API, do not document |
|
31 |
* |
|
32 |
* @y.exclude |
|
33 |
*/ |
|
34 |
public class UniformBlockCenter |
|
35 |
{ |
|
36 |
private static final int BLOCK_SIZE = 16*MAX_EFFECT_COMPONENTS; |
|
37 |
|
|
38 |
private final InternalBuffer mUBO; |
|
39 |
private final float[] mArray; |
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
|
|
43 |
public UniformBlockCenter() |
|
44 |
{ |
|
45 |
mArray= new float[BLOCK_SIZE/4]; |
|
46 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
47 |
} |
|
48 |
|
|
49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
50 |
|
|
51 |
public UniformBlockCenter(UniformBlockCenter original) |
|
52 |
{ |
|
53 |
int size = original.mArray.length; |
|
54 |
mArray= new float[size]; |
|
55 |
System.arraycopy(original.mArray, 0, mArray, 0, size); |
|
56 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
57 |
} |
|
58 |
|
|
59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
60 |
|
|
61 |
public void setEffectCenterNow(int comp, float x, float y, float z) |
|
62 |
{ |
|
63 |
mArray[4*comp ] = x; |
|
64 |
mArray[4*comp+1] = y; |
|
65 |
mArray[4*comp+2] = z; |
|
66 |
|
|
67 |
mUBO.invalidate(); |
|
68 |
} |
|
69 |
|
|
70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
71 |
|
|
72 |
public int getIndex() |
|
73 |
{ |
|
74 |
return mUBO.createImmediatelyFloat( BLOCK_SIZE, mArray); |
|
75 |
} |
|
76 |
|
|
77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
78 |
|
|
79 |
public void copy(int compTo, UniformBlockCenter blockFrom, int compFrom) |
|
80 |
{ |
|
81 |
mArray[4*compTo ] = blockFrom.mArray[4*compFrom ]; |
|
82 |
mArray[4*compTo+1] = blockFrom.mArray[4*compFrom+1]; |
|
83 |
mArray[4*compTo+2] = blockFrom.mArray[4*compFrom+2]; |
|
84 |
} |
|
85 |
|
|
86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
87 |
|
|
88 |
public void markForDeletion() |
|
89 |
{ |
|
90 |
mUBO.markForDeletion(); |
|
91 |
} |
|
92 |
|
|
93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
94 |
|
|
95 |
public float[] getBackingArray() |
|
96 |
{ |
|
97 |
return mArray; |
|
98 |
} |
|
99 |
} |
src/main/java/org/distorted/library/uniformblock/UniformBlockFloatUniforms.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2021 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.library.uniformblock; |
|
21 |
|
|
22 |
import android.opengl.GLES30; |
|
23 |
|
|
24 |
import org.distorted.library.main.InternalBuffer; |
|
25 |
|
|
26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
|
28 |
/** |
|
29 |
* Not part of public API, do not document |
|
30 |
* |
|
31 |
* @y.exclude |
|
32 |
*/ |
|
33 |
public class UniformBlockFloatUniforms |
|
34 |
{ |
|
35 |
private final InternalBuffer mUBO; |
|
36 |
private final float[] mArray; |
|
37 |
private final int mNumUniforms, mSize; |
|
38 |
|
|
39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
40 |
|
|
41 |
public UniformBlockFloatUniforms(int numUniforms, int size) |
|
42 |
{ |
|
43 |
mNumUniforms = numUniforms; |
|
44 |
mSize = size; |
|
45 |
mArray= new float[mNumUniforms*mSize]; |
|
46 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
47 |
} |
|
48 |
|
|
49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
50 |
|
|
51 |
public UniformBlockFloatUniforms(UniformBlockFloatUniforms original) |
|
52 |
{ |
|
53 |
mNumUniforms = original.mNumUniforms; |
|
54 |
mSize = original.mSize; |
|
55 |
mArray= new float[mNumUniforms*mSize]; |
|
56 |
System.arraycopy(original.mArray, 0, mArray, 0, 3*mSize); |
|
57 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
58 |
} |
|
59 |
|
|
60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
61 |
|
|
62 |
public int getIndex() |
|
63 |
{ |
|
64 |
return mUBO.createImmediatelyFloat( 4*mNumUniforms*mSize, mArray); |
|
65 |
} |
|
66 |
|
|
67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
68 |
|
|
69 |
public void remove(int pos, int numEffects) |
|
70 |
{ |
|
71 |
System.arraycopy(mArray, mNumUniforms*(pos+1), mArray, mNumUniforms*pos, mNumUniforms*(numEffects-pos) ); |
|
72 |
mUBO.invalidate(); |
|
73 |
} |
|
74 |
|
|
75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
76 |
|
|
77 |
public void markForDeletion() |
|
78 |
{ |
|
79 |
mUBO.markForDeletion(); |
|
80 |
} |
|
81 |
|
|
82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
83 |
|
|
84 |
public void invalidate() |
|
85 |
{ |
|
86 |
mUBO.invalidate(); |
|
87 |
} |
|
88 |
|
|
89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
90 |
|
|
91 |
public float[] getBackingArray() |
|
92 |
{ |
|
93 |
return mArray; |
|
94 |
} |
|
95 |
|
|
96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
97 |
|
|
98 |
public void print(int num) |
|
99 |
{ |
|
100 |
StringBuilder builder = new StringBuilder(); |
|
101 |
|
|
102 |
builder.append(mUBO.getID()); |
|
103 |
builder.append(':'); |
|
104 |
|
|
105 |
for(int i=0; i<6; i++) |
|
106 |
{ |
|
107 |
builder.append(' '); |
|
108 |
builder.append(mArray[4*i ]); |
|
109 |
builder.append(' '); |
|
110 |
builder.append(mArray[4*i+1]); |
|
111 |
builder.append(' '); |
|
112 |
builder.append(mArray[4*i+2]); |
|
113 |
builder.append(','); |
|
114 |
} |
|
115 |
|
|
116 |
builder.append(' '); |
|
117 |
builder.append('('); |
|
118 |
builder.append(num); |
|
119 |
builder.append(')'); |
|
120 |
|
|
121 |
String res = builder.toString(); |
|
122 |
|
|
123 |
android.util.Log.e("ubp", res); |
|
124 |
} |
|
125 |
} |
src/main/java/org/distorted/library/uniformblock/UniformBlockIntUniforms.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2021 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.library.uniformblock; |
|
21 |
|
|
22 |
import android.opengl.GLES30; |
|
23 |
|
|
24 |
import org.distorted.library.effect.Effect; |
|
25 |
import org.distorted.library.main.InternalBuffer; |
|
26 |
|
|
27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
28 |
/** |
|
29 |
* Not part of public API, do not document |
|
30 |
* |
|
31 |
* @y.exclude |
|
32 |
*/ |
|
33 |
public class UniformBlockIntUniforms |
|
34 |
{ |
|
35 |
private final InternalBuffer mUBO; |
|
36 |
private final int[] mArray; |
|
37 |
private final int mNumUniforms, mSize; |
|
38 |
|
|
39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
40 |
|
|
41 |
public UniformBlockIntUniforms(int numUniforms, int size) |
|
42 |
{ |
|
43 |
mNumUniforms = numUniforms; |
|
44 |
mSize = size; |
|
45 |
mArray= new int[mNumUniforms*mSize]; |
|
46 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
47 |
} |
|
48 |
|
|
49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
50 |
|
|
51 |
public UniformBlockIntUniforms(UniformBlockIntUniforms original) |
|
52 |
{ |
|
53 |
mNumUniforms = original.mNumUniforms; |
|
54 |
mSize = original.mSize; |
|
55 |
mArray= new int[mNumUniforms*mSize]; |
|
56 |
System.arraycopy(original.mArray, 0, mArray, 0, mSize); |
|
57 |
mUBO = new InternalBuffer(GLES30.GL_UNIFORM_BUFFER, GLES30.GL_STATIC_READ); |
|
58 |
} |
|
59 |
|
|
60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
61 |
|
|
62 |
public int getIndex() |
|
63 |
{ |
|
64 |
return mUBO.createImmediatelyInt( 4*mNumUniforms*mSize, mArray); |
|
65 |
} |
|
66 |
|
|
67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
68 |
|
|
69 |
public void remove(int pos, int numEffects) |
|
70 |
{ |
|
71 |
System.arraycopy(mArray, mNumUniforms*(pos+1), mArray, mNumUniforms*pos, mNumUniforms*(numEffects-pos) ); |
|
72 |
mUBO.invalidate(); |
|
73 |
} |
|
74 |
|
|
75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
76 |
|
|
77 |
public void makeHole(int pos, int numEffects) |
|
78 |
{ |
|
79 |
System.arraycopy(mArray, mNumUniforms*pos, mArray, mNumUniforms*(pos+1), mNumUniforms*(numEffects-pos) ); |
|
80 |
mUBO.invalidate(); |
|
81 |
} |
|
82 |
|
|
83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
84 |
|
|
85 |
public void addOrdinal(int pos, int ordinal) |
|
86 |
{ |
|
87 |
mArray[mNumUniforms*pos] = ordinal; |
|
88 |
mUBO.invalidate(); |
|
89 |
} |
|
90 |
|
|
91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
92 |
|
|
93 |
public void addAssociations(int pos, Effect effect) |
|
94 |
{ |
|
95 |
effect.writeAssociations(mArray, mNumUniforms*pos+1, mNumUniforms*pos+3); |
|
96 |
mUBO.invalidate(); |
|
97 |
} |
|
98 |
|
|
99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
100 |
|
|
101 |
public void markForDeletion() |
|
102 |
{ |
|
103 |
mUBO.markForDeletion(); |
|
104 |
} |
|
105 |
|
|
106 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
107 |
|
|
108 |
public void print(int num) |
|
109 |
{ |
|
110 |
StringBuilder builder = new StringBuilder(); |
|
111 |
|
|
112 |
builder.append(mUBO.getID()); |
|
113 |
builder.append(':'); |
|
114 |
|
|
115 |
for(int i=0; i<6; i++) |
|
116 |
{ |
|
117 |
builder.append(' '); |
|
118 |
builder.append(mArray[4*i ]); |
|
119 |
builder.append(' '); |
|
120 |
builder.append(mArray[4*i+1]); |
|
121 |
builder.append(' '); |
|
122 |
builder.append(mArray[4*i+2]); |
|
123 |
builder.append(','); |
|
124 |
} |
|
125 |
|
|
126 |
builder.append(' '); |
|
127 |
builder.append('('); |
|
128 |
builder.append(num); |
|
129 |
builder.append(')'); |
|
130 |
|
|
131 |
String res = builder.toString(); |
|
132 |
|
|
133 |
android.util.Log.e("ubp", res); |
|
134 |
} |
|
135 |
} |
src/main/res/raw/main_fragment_shader.glsl | ||
---|---|---|
45 | 45 |
#endif |
46 | 46 |
|
47 | 47 |
#if NUM_FRAGMENT>0 |
48 |
uniform int fNumEffects; // total number of fragment effects |
|
48 |
uniform int fNumEffects; // total number of fragment effects
|
|
49 | 49 |
|
50 | 50 |
layout (std140) uniform fUniformProperties |
51 | 51 |
{ |
52 |
ivec4 fProperties[NUM_FRAGMENT]; // their properties, 4 ints: |
|
53 |
// name of the effect, unused, unused, unused |
|
52 |
ivec4 fProperties[NUM_FRAGMENT]; // their properties, 4 ints: |
|
53 |
// name of the effect, unused, unused, unused |
|
54 |
}; |
|
55 |
|
|
56 |
layout (std140) uniform fUniformFloats |
|
57 |
{ |
|
58 |
vec4 fUniforms[3*NUM_FRAGMENT]; // i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2]. |
|
59 |
// The first vec4 is the Interpolated values, |
|
60 |
// second vec4: first float - cache, next 3: Center, the third - the Region. |
|
54 | 61 |
}; |
55 | 62 |
|
56 |
uniform vec4 fUniforms[3*NUM_FRAGMENT]; // i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2]. |
|
57 |
// The first vec4 is the Interpolated values, |
|
58 |
// second vec4: first float - cache, next 3: Center, the third - the Region. |
|
59 | 63 |
#endif // NUM_FRAGMENT>0 |
60 | 64 |
|
61 | 65 |
#ifdef OIT |
src/main/res/raw/main_vertex_shader.glsl | ||
---|---|---|
56 | 56 |
// 4: effect's EQU association |
57 | 57 |
}; |
58 | 58 |
|
59 |
uniform vec4 vUniforms[3*NUM_VERTEX]; // i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2]. |
|
59 |
layout (std140) uniform vUniformFloats |
|
60 |
{ |
|
61 |
vec4 vUniforms[3*NUM_VERTEX]; // i-th effect is 3 consecutive vec4's: [3*i], [3*i+1], [3*i+2]. |
|
60 | 62 |
// The first vec4 is the Interpolated values, |
61 | 63 |
// second vec4: first float - cache, next 3: Center, the third - the Region. |
64 |
}; |
|
62 | 65 |
|
63 | 66 |
layout (std140) uniform componentAssociation |
64 | 67 |
{ |
Also available in: Unified diff
Introduce another Uniform Block Object. Now we can have much more vertex and fragment effects - up their default number to 100.