Revision 0f011027
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/DistortedFramebuffer.java | ||
---|---|---|
50 | 50 |
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST); |
51 | 51 |
GLES30.glTexParameterf(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR); |
52 | 52 |
GLES30.glTexImage2D(GLES30.GL_TEXTURE_2D, 0, GLES30.GL_RGBA, mWidth, mHeight, 0, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, null); |
53 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0+i, GLES30.GL_TEXTURE_2D, mColorH[i], 0); |
|
54 | 53 |
} |
55 |
|
|
54 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mColorH[0], 0); |
|
56 | 55 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0); |
57 | 56 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0); |
58 | 57 |
|
src/main/java/org/distorted/library/DistortedNode.java | ||
---|---|---|
266 | 266 |
if( input.setAsInput() ) |
267 | 267 |
{ |
268 | 268 |
int quality = effects.getQuality(); |
269 |
DistortedFramebuffer buffer1 = surface.mBuffer1[quality]; |
|
270 |
DistortedFramebuffer buffer2 = surface.mBuffer2[quality]; |
|
269 |
DistortedFramebuffer buffer = surface.mBuffer[quality]; |
|
271 | 270 |
float w = mSurface.getWidth() /2.0f; |
272 | 271 |
float h = mSurface.getHeight()/2.0f; |
272 |
buffer.setAsOutput(); |
|
273 | 273 |
|
274 | 274 |
// Draw the color buffer of the object. |
275 |
buffer1.setAsOutput(); |
|
276 | 275 |
mState.apply(); |
277 |
mEffects.drawPriv(w, h, mMesh, buffer1, currTime, 0);
|
|
276 |
mEffects.drawPriv(w, h, mMesh, buffer, currTime, 0); |
|
278 | 277 |
|
279 | 278 |
// Draw stencil + depth buffers of the object enlarged by HALO pixels around. |
280 |
buffer2.setAsOutput(); |
|
281 | 279 |
DistortedRenderState.setUpStencilMark(); |
282 |
mEffects.drawPriv(w, h, mMesh, buffer2, currTime, effects.getHalo()*buffer2.mMipmap);
|
|
280 |
mEffects.drawPriv(w, h, mMesh, buffer, currTime, effects.getHalo()*buffer.mMipmap);
|
|
283 | 281 |
DistortedRenderState.unsetUpStencilMark(); |
284 | 282 |
|
285 | 283 |
return 1; |
src/main/java/org/distorted/library/DistortedOutputSurface.java | ||
---|---|---|
64 | 64 |
|
65 | 65 |
private ArrayList<Job> mJobs = new ArrayList<>(); |
66 | 66 |
|
67 |
DistortedFramebuffer[] mBuffer1, mBuffer2;
|
|
67 |
DistortedFramebuffer[] mBuffer; |
|
68 | 68 |
|
69 | 69 |
private long mTime; |
70 | 70 |
private float mFOV; |
... | ... | |
110 | 110 |
mClearStencil = 0; |
111 | 111 |
mClear = GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT; |
112 | 112 |
|
113 |
mBuffer1 = new DistortedFramebuffer[EffectQuality.LENGTH]; |
|
114 |
mBuffer2 = new DistortedFramebuffer[EffectQuality.LENGTH]; |
|
113 |
mBuffer = new DistortedFramebuffer[EffectQuality.LENGTH]; |
|
115 | 114 |
|
116 | 115 |
mMipmap = 1.0f; |
117 | 116 |
|
... | ... | |
164 | 163 |
|
165 | 164 |
for(int j=0; j<EffectQuality.LENGTH; j++) |
166 | 165 |
{ |
167 |
mBuffer1[j] = new DistortedFramebuffer(1,BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) ); |
|
168 |
mBuffer2[j] = new DistortedFramebuffer(1,BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) ); |
|
169 |
mBuffer1[j].mMipmap = mipmap; |
|
170 |
mBuffer2[j].mMipmap = mipmap; |
|
166 |
mBuffer[j] = new DistortedFramebuffer(2,BOTH_DEPTH_STENCIL,TYPE_SYST, (int)(mWidth*mipmap), (int)(mHeight*mipmap) ); |
|
167 |
mBuffer[j].mMipmap = mipmap; |
|
171 | 168 |
mipmap *= EffectQuality.MULTIPLIER; |
172 | 169 |
} |
173 | 170 |
|
... | ... | |
182 | 179 |
|
183 | 180 |
for(int j=0; j<EffectQuality.LENGTH; j++) |
184 | 181 |
{ |
185 |
mBuffer1[j].setAsOutput(); |
|
186 |
GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT|GLES30.GL_DEPTH_BUFFER_BIT|GLES30.GL_STENCIL_BUFFER_BIT); |
|
187 |
mBuffer2[j].setAsOutput(); |
|
182 |
mBuffer[j].setAsOutput(); |
|
183 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mBuffer[j].mColorH[1], 0); |
|
188 | 184 |
GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT|GLES30.GL_DEPTH_BUFFER_BIT|GLES30.GL_STENCIL_BUFFER_BIT); |
185 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, mBuffer[j].mColorH[0], 0); |
|
186 |
GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT); |
|
189 | 187 |
} |
190 | 188 |
} |
191 | 189 |
|
... | ... | |
212 | 210 |
if( currB==0 ) numRenders += child.draw(time,this); |
213 | 211 |
else |
214 | 212 |
{ |
215 |
if( mBuffer1[0]==null ) createBuffers();
|
|
213 |
if( mBuffer[0]==null ) createBuffers(); |
|
216 | 214 |
numRenders += child.markStencilAndDraw(time,this,currP); |
217 | 215 |
if( i==num-1 ) numRenders += currP.postprocess(time,this); |
218 | 216 |
} |
src/main/java/org/distorted/library/EffectQueuePostprocess.java | ||
---|---|---|
271 | 271 |
{ |
272 | 272 |
compute(time); |
273 | 273 |
|
274 |
DistortedFramebuffer buffer1 = surface.mBuffer1[mQualityLevel];
|
|
275 |
DistortedFramebuffer buffer2 = surface.mBuffer2[mQualityLevel];
|
|
274 |
DistortedFramebuffer buffer = surface.mBuffer[mQualityLevel];
|
|
275 |
GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, buffer.mFBOH[0]);
|
|
276 | 276 |
|
277 |
float w1 = buffer1.mWidth;
|
|
278 |
float h1 = buffer1.mHeight;
|
|
277 |
float w1 = buffer.mWidth; |
|
278 |
float h1 = buffer.mHeight; |
|
279 | 279 |
float w2 = surface.mWidth; |
280 | 280 |
float h2 = surface.mHeight; |
281 | 281 |
|
... | ... | |
289 | 289 |
// horizontal blur |
290 | 290 |
GLES30.glViewport(0, 0, (int)w1, (int)h1); |
291 | 291 |
mBlur1Program.useProgram(); |
292 |
buffer1.setAsInput(); |
|
293 |
buffer2.setAsOutput(); |
|
292 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, buffer.mColorH[1], 0); |
|
293 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0); |
|
294 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, buffer.mColorH[0]); |
|
294 | 295 |
|
295 | 296 |
GLES30.glUniform1fv( mWeights1H, radius+1, weightsCache,offset); |
296 | 297 |
GLES30.glUniform1i( mRadius1H, radius); |
... | ... | |
304 | 305 |
DistortedRenderState.useStencilMark(); |
305 | 306 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
306 | 307 |
DistortedRenderState.unuseStencilMark(); |
308 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0); |
|
309 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0); |
|
307 | 310 |
|
308 | 311 |
// vertical blur |
309 | 312 |
mBlur2Program.useProgram(); |
310 |
buffer2.setAsInput(); |
|
311 |
buffer1.setAsOutput(); |
|
313 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, buffer.mColorH[0], 0); |
|
314 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0); |
|
315 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, buffer.mColorH[1]); |
|
312 | 316 |
|
313 | 317 |
GLES30.glColorMask(true,true,true,true); |
314 | 318 |
GLES30.glClearColor(0.0f,0.0f,0.0f,0.0f); |
... | ... | |
323 | 327 |
GLES30.glVertexAttribPointer(mBlur2Program.mAttribute[0], POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadPositions); |
324 | 328 |
GLES30.glVertexAttribPointer(mBlur2Program.mAttribute[1], TEX_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mQuadTexture); |
325 | 329 |
|
326 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_STENCIL_ATTACHMENT, GLES30.GL_TEXTURE_2D, buffer2.mDepthStencilH[0], 0); |
|
327 | 330 |
DistortedRenderState.useStencilMark(); |
328 | 331 |
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4); |
329 | 332 |
DistortedRenderState.unuseStencilMark(); |
330 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_STENCIL_ATTACHMENT, GLES30.GL_TEXTURE_2D, buffer1.mDepthStencilH[0], 0); |
|
333 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0); |
|
334 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0); |
|
331 | 335 |
|
332 | 336 |
// blit the results with DEPTH to surface. |
333 | 337 |
GLES30.glViewport(0, 0, (int)w2, (int)h2); |
334 |
buffer1.setAsInput(); |
|
335 |
buffer2.setAsDepth(); |
|
336 | 338 |
surface.setAsOutput(time); |
339 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0); |
|
340 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, buffer.mColorH[0]); |
|
341 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE1); |
|
342 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, buffer.mDepthStencilH[0]); |
|
343 |
|
|
344 |
GLES30.glDisable(GLES30.GL_STENCIL_TEST); |
|
345 |
GLES30.glStencilMask(0x00); |
|
346 |
|
|
337 | 347 |
DistortedEffects.blitDepthPriv(surface); |
348 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE0); |
|
349 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0); |
|
350 |
GLES30.glActiveTexture(GLES30.GL_TEXTURE1); |
|
351 |
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, 0); |
|
338 | 352 |
|
339 | 353 |
// after each postprocess, clear buffers |
340 | 354 |
GLES30.glStencilMask(0xff); |
... | ... | |
343 | 357 |
GLES30.glClearColor(0.0f,0.0f,0.0f,0.0f); |
344 | 358 |
GLES30.glClearDepthf(1.0f); |
345 | 359 |
GLES30.glClearStencil(0); |
346 |
buffer1.setAsOutput(); |
|
347 |
GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT|GLES30.GL_DEPTH_BUFFER_BIT|GLES30.GL_STENCIL_BUFFER_BIT);
|
|
348 |
buffer2.setAsOutput();
|
|
360 |
|
|
361 |
buffer.setAsOutput();
|
|
362 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, buffer.mColorH[1], 0);
|
|
349 | 363 |
GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT|GLES30.GL_DEPTH_BUFFER_BIT|GLES30.GL_STENCIL_BUFFER_BIT); |
364 |
GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, GLES30.GL_TEXTURE_2D, buffer.mColorH[0], 0); |
|
365 |
GLES30.glClear(GLES30.GL_COLOR_BUFFER_BIT); |
|
350 | 366 |
} |
351 | 367 |
|
352 | 368 |
return mNumEffects; |
Also available in: Unified diff
Major speedup, BLUR fully optimized now.
Multiblur app, worst case (all 8 cubes blurred with max radius, HIGHEST quality: Nexus5X: 46.7 FPS, Nexus 4: 29.7 FPS.