Revision 66ace7f5
Added by Leszek Koltunski over 6 years ago
src/main/java/org/distorted/library/main/DistortedOutputSurface.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
import java.nio.ByteBuffer; |
28 | 28 |
import java.nio.ByteOrder; |
29 |
import java.nio.IntBuffer; |
|
29 | 30 |
import java.util.ArrayList; |
30 | 31 |
|
31 | 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
104 | 105 |
private static int mBufferSize =10; |
105 | 106 |
private static DistortedObjectCounter mSurfaceCounter = new DistortedObjectCounter(); |
106 | 107 |
private static int[] mSSBO = new int[1]; |
107 |
private static ByteBuffer mSSBOBuffer;
|
|
108 |
private static IntBuffer mIntBuffer;
|
|
108 | 109 |
|
109 | 110 |
static |
110 | 111 |
{ |
111 |
mSSBO[0] = -1; |
|
112 |
mSSBOBuffer = ByteBuffer.allocateDirect(BUFFERING*mBufferSize*4).order(ByteOrder.nativeOrder()); |
|
112 |
mSSBO[0]= -1; |
|
113 | 113 |
} |
114 | 114 |
|
115 | 115 |
private int mSurfaceID; |
116 | 116 |
private int mLastIndex; |
117 |
|
|
118 | 117 |
// end section |
119 | 118 |
//////////////////////////////////////////////////////////////////////////////// |
120 | 119 |
|
... | ... | |
162 | 161 |
createProjection(); |
163 | 162 |
} |
164 | 163 |
|
165 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
166 |
|
|
167 |
void error(String msg) |
|
168 |
{ |
|
169 |
int err = GLES31.glGetError(); |
|
170 |
|
|
171 |
if( err != GLES31.GL_NO_ERROR ) |
|
172 |
{ |
|
173 |
android.util.Log.e("surface", msg+" error: "+err); |
|
174 |
} |
|
175 |
} |
|
176 |
|
|
177 | 164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
178 | 165 |
// Must be called from a thread holding OpenGL Context |
179 | 166 |
|
... | ... | |
185 | 172 |
|
186 | 173 |
// here bind the new SSBO and map it |
187 | 174 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mSSBO[0]); |
188 |
error("pre1"); |
|
189 | 175 |
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, BUFFERING*mBufferSize*4 , null, GLES31.GL_DYNAMIC_READ); |
190 |
error("pre2"); |
|
191 |
mSSBOBuffer = (ByteBuffer) GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, BUFFERING*mBufferSize*4, GLES31.GL_MAP_READ_BIT ); |
|
192 |
error("pre3"); |
|
176 |
ByteBuffer buf = (ByteBuffer) GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, BUFFERING*mBufferSize*4, GLES31.GL_MAP_READ_BIT ); |
|
177 |
mIntBuffer = buf.order(ByteOrder.nativeOrder()).asIntBuffer(); |
|
193 | 178 |
GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER,0, mSSBO[0]); |
194 |
error("pre4"); |
|
195 | 179 |
} |
196 | 180 |
|
197 | 181 |
mSurfaceID = mSurfaceCounter.returnNext(); |
... | ... | |
227 | 211 |
|
228 | 212 |
int resetNewCounter() |
229 | 213 |
{ |
230 |
//mSSBOBuffer.putInt(BUFFERING*mSurfaceID+mLastIndex,0);
|
|
214 |
//mIntBuffer.put(BUFFERING*mSurfaceID+mLastIndex,0);
|
|
231 | 215 |
return BUFFERING*mSurfaceID + mLastIndex; |
232 | 216 |
} |
233 | 217 |
|
... | ... | |
235 | 219 |
|
236 | 220 |
int returnOldCounter() |
237 | 221 |
{ |
238 |
int ret = mSSBOBuffer.getInt(BUFFERING*mSurfaceID+mLastIndex);
|
|
222 |
int ret = mIntBuffer.get(BUFFERING*mSurfaceID+mLastIndex);
|
|
239 | 223 |
|
240 | 224 |
mLastIndex++; |
241 | 225 |
if( mLastIndex>=BUFFERING ) mLastIndex-=BUFFERING; |
... | ... | |
247 | 231 |
|
248 | 232 |
int returnCounter() |
249 | 233 |
{ |
250 |
return mSSBOBuffer.getInt(0);
|
|
234 |
return mIntBuffer.get(0);
|
|
251 | 235 |
} |
252 | 236 |
|
253 | 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
SSBO: fix problems with endianness.