Revision cee0369a
Added by Leszek Koltunski about 6 years ago
src/main/java/org/distorted/library/main/DistortedEffects.java | ||
---|---|---|
88 | 88 |
} |
89 | 89 |
|
90 | 90 |
private static int mBufferSize=(0x1<<23); // 8 million entries |
91 |
|
|
91 | 92 |
private static IntBuffer mIntBuffer; |
92 | 93 |
|
94 |
private static ByteBuffer mBuf; |
|
95 |
private static IntBuffer mIntBuf; |
|
96 |
|
|
93 | 97 |
/// BLIT DEPTH RENDER PROGRAM /// |
94 | 98 |
private static DistortedProgram mBlitDepthRenderProgram; |
95 | 99 |
private static int mBlitDepthRenderDepthTextureH; |
... | ... | |
118 | 122 |
throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException |
119 | 123 |
{ |
120 | 124 |
// MAIN PROGRAM //////////////////////////////////// |
125 |
android.util.Log.e("Effects", "creating main program"); |
|
126 |
|
|
121 | 127 |
final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader); |
122 | 128 |
final InputStream mainFragStream = resources.openRawResource(R.raw.main_fragment_shader); |
123 | 129 |
|
... | ... | |
136 | 142 |
|
137 | 143 |
String[] feedback = { "v_Position", "v_endPosition" }; |
138 | 144 |
|
139 |
mMainProgram = new DistortedProgram( mainVertStream, mainFragStream, mainVertHeader, mainFragHeader, |
|
140 |
enabledEffectV, enabledEffectF, Distorted.GLSL, feedback); |
|
145 |
try |
|
146 |
{ |
|
147 |
mMainProgram = new DistortedProgram(mainVertStream, mainFragStream, mainVertHeader, mainFragHeader, |
|
148 |
enabledEffectV, enabledEffectF, Distorted.GLSL, feedback); |
|
149 |
} |
|
150 |
catch(Exception e) |
|
151 |
{ |
|
152 |
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile MAIN program: "+e.getMessage()); |
|
153 |
throw new RuntimeException(e.getMessage()); |
|
154 |
} |
|
141 | 155 |
|
142 | 156 |
int mainProgramH = mMainProgram.getProgramHandle(); |
143 | 157 |
EffectQueueFragment.getUniforms(mainProgramH); |
... | ... | |
147 | 161 |
mCountIndexH = GLES31.glGetUniformLocation( mainProgramH, "u_currentIndex"); |
148 | 162 |
|
149 | 163 |
// BLIT PROGRAM //////////////////////////////////// |
164 |
android.util.Log.e("Effects", "creating blit program"); |
|
165 |
|
|
150 | 166 |
final InputStream blitVertStream = resources.openRawResource(R.raw.blit_vertex_shader); |
151 | 167 |
final InputStream blitFragStream = resources.openRawResource(R.raw.blit_fragment_shader); |
152 | 168 |
|
... | ... | |
159 | 175 |
} |
160 | 176 |
catch(Exception e) |
161 | 177 |
{ |
162 |
Log.e("EFFECTS", "exception trying to compile BLIT program: "+e.getMessage());
|
|
178 |
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile BLIT program: "+e.getMessage());
|
|
163 | 179 |
throw new RuntimeException(e.getMessage()); |
164 | 180 |
} |
165 | 181 |
|
... | ... | |
168 | 184 |
mBlitDepthH = GLES31.glGetUniformLocation( blitProgramH, "u_Depth"); |
169 | 185 |
|
170 | 186 |
// BLIT DEPTH PROGRAM //////////////////////////////////// |
187 |
android.util.Log.e("Effects", "creating blit depth program"); |
|
188 |
|
|
171 | 189 |
final InputStream blitDepthVertStream = resources.openRawResource(R.raw.blit_depth_vertex_shader); |
172 | 190 |
final InputStream blitDepthFragStream = resources.openRawResource(R.raw.blit_depth_fragment_shader); |
173 | 191 |
|
... | ... | |
177 | 195 |
} |
178 | 196 |
catch(Exception e) |
179 | 197 |
{ |
180 |
Log.e("EFFECTS", "exception trying to compile BLIT DEPTH program: "+e.getMessage());
|
|
198 |
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile BLIT DEPTH program: "+e.getMessage());
|
|
181 | 199 |
throw new RuntimeException(e.getMessage()); |
182 | 200 |
} |
183 | 201 |
|
... | ... | |
196 | 214 |
{ |
197 | 215 |
GLES31.glGenBuffers(1,mLinkedListSSBO,0); |
198 | 216 |
GLES31.glBindBuffer(GLES31.GL_SHADER_STORAGE_BUFFER, mLinkedListSSBO[0]); |
199 |
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, mBufferSize*4 , null, GLES31.GL_DYNAMIC_READ); |
|
217 |
GLES31.glBufferData(GLES31.GL_SHADER_STORAGE_BUFFER, mBufferSize*4 , null, GLES31.GL_DYNAMIC_READ|GLES31.GL_DYNAMIC_DRAW); |
|
218 |
|
|
219 |
mBuf = (ByteBuffer)GLES31.glMapBufferRange(GLES31.GL_SHADER_STORAGE_BUFFER, 0, mBufferSize*4, GLES31.GL_MAP_READ_BIT); |
|
220 |
mIntBuf = mBuf.order(ByteOrder.nativeOrder()).asIntBuffer(); |
|
221 |
|
|
200 | 222 |
GLES31.glBindBufferBase(GLES31.GL_SHADER_STORAGE_BUFFER, 1, mLinkedListSSBO[0]); |
201 | 223 |
} |
202 | 224 |
|
... | ... | |
209 | 231 |
} |
210 | 232 |
|
211 | 233 |
// BLIT DEPTH RENDER PROGRAM /////////////////////////// |
234 |
android.util.Log.e("Effects", "creating blit depth render program"); |
|
235 |
|
|
212 | 236 |
final InputStream blitDepthRenderVertStream = resources.openRawResource(R.raw.blit_depth_vertex_shader); |
213 | 237 |
final InputStream blitDepthRenderFragStream = resources.openRawResource(R.raw.blit_depth_render_fragment_shader); |
214 | 238 |
|
... | ... | |
218 | 242 |
} |
219 | 243 |
catch(Exception e) |
220 | 244 |
{ |
221 |
Log.e("EFFECTS", "exception trying to compile BLIT DEPTH RENDER program: "+e.getMessage());
|
|
245 |
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile BLIT DEPTH RENDER program: "+e.getMessage());
|
|
222 | 246 |
throw new RuntimeException(e.getMessage()); |
223 | 247 |
} |
224 | 248 |
|
... | ... | |
229 | 253 |
mBlitDepthRenderSizeH = GLES31.glGetUniformLocation( blitDepthRenderProgramH, "u_Size"); |
230 | 254 |
|
231 | 255 |
// NORMAL PROGRAM ////////////////////////////////////// |
256 |
android.util.Log.e("Effects", "creating normal program"); |
|
257 |
|
|
232 | 258 |
final InputStream normalVertexStream = resources.openRawResource(R.raw.normal_vertex_shader); |
233 | 259 |
final InputStream normalFragmentStream = resources.openRawResource(R.raw.normal_fragment_shader); |
234 | 260 |
|
... | ... | |
238 | 264 |
} |
239 | 265 |
catch(Exception e) |
240 | 266 |
{ |
241 |
Log.e("EFFECTS", "exception trying to compile NORMAL program: "+e.getMessage());
|
|
267 |
Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile NORMAL program: "+e.getMessage());
|
|
242 | 268 |
throw new RuntimeException(e.getMessage()); |
243 | 269 |
} |
244 | 270 |
|
... | ... | |
411 | 437 |
{ |
412 | 438 |
mBlitDepthRenderProgram.useProgram(); |
413 | 439 |
|
440 |
analyzeBuffer(surface.mWidth, surface.mHeight); |
|
441 |
|
|
414 | 442 |
GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight ); |
415 | 443 |
GLES31.glUniform1i(mBlitDepthRenderDepthTextureH, 1); |
416 | 444 |
GLES31.glUniform2f(mBlitDepthRenderTexCorrH, corrW, corrH ); |
... | ... | |
426 | 454 |
} |
427 | 455 |
|
428 | 456 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
429 |
|
|
457 |
|
|
458 |
|
|
459 |
private static void analyzeBuffer(int w, int h) |
|
460 |
{ |
|
461 |
int ptr; |
|
462 |
final int GREEN = (255<<16) + 255; |
|
463 |
final int RED = (255<<24) + 255; |
|
464 |
|
|
465 |
int left1=0, left2=0; |
|
466 |
int right1=0, right2=0; |
|
467 |
int overflow = 0; |
|
468 |
|
|
469 |
for(int row=0; row<h; row++) |
|
470 |
for(int col=0; col<w; col++) |
|
471 |
{ |
|
472 |
ptr = mIntBuf.get( col+row*w ); |
|
473 |
|
|
474 |
if( ptr!=0 ) |
|
475 |
{ |
|
476 |
if( ptr>0 && ptr<mBufferSize ) |
|
477 |
{ |
|
478 |
ptr = mIntBuf.get(ptr); |
|
479 |
|
|
480 |
if ((2*col>w) && ptr != RED) |
|
481 |
{ |
|
482 |
if (ptr==GREEN) right1++; |
|
483 |
else right2++; |
|
484 |
} |
|
485 |
if ((2*col<=w) && ptr != GREEN) |
|
486 |
{ |
|
487 |
if (ptr==RED) left1++; |
|
488 |
else left2++; |
|
489 |
} |
|
490 |
} |
|
491 |
else |
|
492 |
{ |
|
493 |
overflow++; |
|
494 |
} |
|
495 |
} |
|
496 |
} |
|
497 |
|
|
498 |
android.util.Log.e("surface", " left1: "+left1+" left2: "+left2+" right1: "+right1+" right2: "+right2+" overflow: "+overflow); |
|
499 |
} |
|
500 |
|
|
501 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
502 |
|
|
430 | 503 |
private void releasePriv() |
431 | 504 |
{ |
432 | 505 |
if( !matrixCloned ) mM.abortAll(false); |
Also available in: Unified diff
Order Independent Transparency: debugging