Revision df4d7edc
Added by Leszek Koltunski about 6 years ago
src/main/java/org/distorted/library/main/DistortedOutputSurface.java | ||
---|---|---|
101 | 101 |
|
102 | 102 |
//////////////////////////////////////////////////////////////////////////////// |
103 | 103 |
// section dealing with Shader Storage Buffer Object (for counting transparency) |
104 |
private static final int BUFFERING = 3;
|
|
105 |
private static int mBufferSize =10; |
|
104 |
private static final int FRAME_DELAY = 3;
|
|
105 |
private static int mBufferSize =10;
|
|
106 | 106 |
private static DistortedObjectCounter mSurfaceCounter = new DistortedObjectCounter(); |
107 | 107 |
private static int[] mSSBO = new int[1]; |
108 | 108 |
private static IntBuffer mIntBuffer; |
... | ... | |
114 | 114 |
|
115 | 115 |
private int mSurfaceID; |
116 | 116 |
private int mLastIndex; |
117 |
private int mLastValue =-1;
|
|
117 |
private int[] mLastValue = new int[FRAME_DELAY];
|
|
118 | 118 |
// end section |
119 | 119 |
//////////////////////////////////////////////////////////////////////////////// |
120 | 120 |
|
... | ... | |
173 | 173 |
|
174 | 174 |
// here bind the new SSBO and map it |
175 | 175 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mSSBO[0]); |
176 |
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, BUFFERING*mBufferSize*4 , null, GLES31.GL_DYNAMIC_READ);
|
|
177 |
ByteBuffer buf = (ByteBuffer) GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, BUFFERING*mBufferSize*4, GLES31.GL_MAP_READ_BIT );
|
|
176 |
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, FRAME_DELAY *mBufferSize*4 , null, GLES31.GL_DYNAMIC_READ);
|
|
177 |
ByteBuffer buf = (ByteBuffer) GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, FRAME_DELAY *mBufferSize*4, GLES31.GL_MAP_READ_BIT );
|
|
178 | 178 |
mIntBuffer = buf.order(ByteOrder.nativeOrder()).asIntBuffer(); |
179 | 179 |
GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER,0, mSSBO[0]); |
180 | 180 |
} |
... | ... | |
184 | 184 |
if( mSurfaceID>=mBufferSize ) |
185 | 185 |
{ |
186 | 186 |
// increase size of the Buffer, copy over old values, remap. |
187 |
int[] tmp = new int[BUFFERING*mBufferSize];
|
|
188 |
for(int i=0;i<BUFFERING*mBufferSize;i++) tmp[i] = mIntBuffer.get(i);
|
|
187 |
int[] tmp = new int[FRAME_DELAY *mBufferSize];
|
|
188 |
for(int i = 0; i< FRAME_DELAY *mBufferSize; i++) tmp[i] = mIntBuffer.get(i);
|
|
189 | 189 |
|
190 | 190 |
mBufferSize*= 2; |
191 | 191 |
|
... | ... | |
194 | 194 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER,0); |
195 | 195 |
|
196 | 196 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mSSBO[0]); |
197 |
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, BUFFERING*mBufferSize*4 , null, GLES31.GL_DYNAMIC_READ);
|
|
198 |
ByteBuffer buf = (ByteBuffer) GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, BUFFERING*mBufferSize*4, GLES31.GL_MAP_READ_BIT );
|
|
197 |
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, FRAME_DELAY *mBufferSize*4 , null, GLES31.GL_DYNAMIC_READ);
|
|
198 |
ByteBuffer buf = (ByteBuffer) GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, FRAME_DELAY *mBufferSize*4, GLES31.GL_MAP_READ_BIT );
|
|
199 | 199 |
mIntBuffer = buf.order(ByteOrder.nativeOrder()).asIntBuffer(); |
200 | 200 |
GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER,0, mSSBO[0]); |
201 | 201 |
|
... | ... | |
218 | 218 |
|
219 | 219 |
void recreate() |
220 | 220 |
{ |
221 |
mSSBO[0] = -1;
|
|
222 |
mLastValue = -1;
|
|
221 |
for(int i = 0; i< FRAME_DELAY; i++) mLastValue[i] = 0;
|
|
222 |
mSSBO[0]= -1;
|
|
223 | 223 |
mSurfaceCounter.releaseAll(); |
224 | 224 |
recreateSurface(); |
225 | 225 |
} |
... | ... | |
228 | 228 |
|
229 | 229 |
int getNewCounter() |
230 | 230 |
{ |
231 |
int value = mIntBuffer.get(BUFFERING*mSurfaceID+(mLastIndex==0 ? BUFFERING-1:mLastIndex-1)); |
|
232 |
|
|
233 |
if( value!=mLastValue ) |
|
234 |
{ |
|
235 |
mLastValue = value; |
|
236 |
android.util.Log.d("surface", "surface id: "+mSurfaceID+" value now: "+mLastValue); |
|
237 |
} |
|
238 |
|
|
239 |
return BUFFERING*mSurfaceID + mLastIndex; |
|
231 |
return FRAME_DELAY*mSurfaceID + mLastIndex; |
|
240 | 232 |
} |
241 | 233 |
|
242 | 234 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
524 | 516 |
GLES31.glClear(mClear); |
525 | 517 |
DistortedRenderState.colorDepthStencilRestore(); |
526 | 518 |
|
527 |
mLastIndex++; |
|
528 |
if( mLastIndex>=BUFFERING ) mLastIndex=0; |
|
529 |
mIntBuffer.put(BUFFERING*mSurfaceID+mLastIndex,0); |
|
519 |
if( ++mLastIndex >= FRAME_DELAY ) mLastIndex=0; |
|
520 |
|
|
521 |
int index = (mLastIndex==0 ? FRAME_DELAY-1 : mLastIndex-1); |
|
522 |
int value = mIntBuffer.get(FRAME_DELAY *mSurfaceID+index); |
|
523 |
|
|
524 |
if( value!=mLastValue[index] ) |
|
525 |
{ |
|
526 |
// yes, this DOES keep on working when 'value' overflows into negative territory. |
|
527 |
android.util.Log.d("surface", "surface id: "+mSurfaceID+" last frame: "+(value-mLastValue[index]) ); |
|
528 |
mLastValue[index] = value; |
|
529 |
} |
|
530 | 530 |
} |
531 | 531 |
} |
532 | 532 |
|
Also available in: Unified diff
SSBO: correct various things.