Revision 86eb00a9
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/DistortedFramebuffer.java | ||
---|---|---|
55 | 55 |
private boolean mMarked; |
56 | 56 |
private boolean mDepthWanted; |
57 | 57 |
|
58 |
private int mTexWidth, mTexHeight; |
|
59 |
|
|
58 | 60 |
// Projection stuff |
59 | 61 |
private float mX, mY, mFOV; |
60 | 62 |
int mWidth,mHeight,mDepth; |
... | ... | |
74 | 76 |
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT); |
75 | 77 |
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); |
76 | 78 |
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); |
77 |
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, mWidth, mHeight, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
|
|
79 |
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, mTexWidth, mTexHeight, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
|
|
78 | 80 |
|
79 | 81 |
GLES20.glGenFramebuffers(1, fboIds, 0); |
80 | 82 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]); |
81 | 83 |
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, colorIds[0], 0); |
82 | 84 |
|
83 | 85 |
checkStatus("color"); |
84 |
|
|
85 |
mList.add(this); |
|
86 | 86 |
} |
87 |
|
|
88 |
if( mDepthWanted && depthIds[0]==NOT_CREATED_YET ) // we need to create a new DEPTH attachment |
|
87 |
if( mDepthWanted && depthIds[0]==NOT_CREATED_YET ) // we need to create a new DEPTH attachment |
|
89 | 88 |
{ |
90 | 89 |
GLES20.glGenTextures(1, depthIds, 0); |
91 | 90 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, depthIds[0]); |
... | ... | |
93 | 92 |
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT); |
94 | 93 |
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); |
95 | 94 |
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST); |
96 |
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_DEPTH_COMPONENT, mWidth, mHeight, 0, GLES20.GL_DEPTH_COMPONENT, GLES20.GL_UNSIGNED_SHORT, null);
|
|
95 |
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_DEPTH_COMPONENT, mTexWidth, mTexHeight, 0, GLES20.GL_DEPTH_COMPONENT, GLES20.GL_UNSIGNED_SHORT, null);
|
|
97 | 96 |
|
98 | 97 |
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fboIds[0]); |
99 | 98 |
GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_TEXTURE_2D, depthIds[0], 0); |
... | ... | |
265 | 264 |
} |
266 | 265 |
} |
267 | 266 |
|
267 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
268 |
// if new size fits into the size of the underlying Texture, just change the projection without |
|
269 |
// reallocating the Texture. Otherwise, we need to reallocate. |
|
270 |
// |
|
271 |
// Must be called form a thread holding the OpenGL context. |
|
272 |
|
|
273 |
void resizeFast(int width, int height) |
|
274 |
{ |
|
275 |
if( mWidth!=width || mHeight!=height ) |
|
276 |
{ |
|
277 |
mWidth = width; |
|
278 |
mHeight= height; |
|
279 |
|
|
280 |
createProjection(); |
|
281 |
|
|
282 |
if( mWidth>mTexWidth || mHeight>mTexHeight ) |
|
283 |
{ |
|
284 |
mTexWidth = mWidth; |
|
285 |
mTexHeight= mHeight; |
|
286 |
deleteFBO(); |
|
287 |
createFBO(); |
|
288 |
} |
|
289 |
} |
|
290 |
} |
|
291 |
|
|
268 | 292 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
269 | 293 |
// PUBLIC API |
270 | 294 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
281 | 305 |
|
282 | 306 |
mHeight = height; |
283 | 307 |
mWidth = width; |
308 |
mTexHeight = height; |
|
309 |
mTexWidth = width; |
|
284 | 310 |
mFOV = 60.0f; |
285 | 311 |
mX = 0.0f; |
286 | 312 |
mY = 0.0f; |
... | ... | |
292 | 318 |
depthIds[0]= NOT_CREATED_YET; |
293 | 319 |
|
294 | 320 |
createProjection(); |
321 |
|
|
322 |
mList.add(this); |
|
295 | 323 |
} |
296 | 324 |
|
297 | 325 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
345 | 373 |
{ |
346 | 374 |
tex.createTexture(); |
347 | 375 |
tex.setAsInput(); |
376 |
DistortedFramebuffer.deleteAllMarked(); |
|
377 |
DistortedTexture.deleteAllMarked(); |
|
348 | 378 |
createFBO(); |
349 | 379 |
setAsOutput(); |
350 | 380 |
effects.drawPriv(tex.mHalfX, tex.mHalfY, mesh, this, time); |
351 |
DistortedFramebuffer.deleteAllMarked(); |
|
352 |
DistortedTexture.deleteAllMarked(); |
|
353 | 381 |
} |
354 | 382 |
|
355 | 383 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
371 | 399 |
|
372 | 400 |
if( fbo.colorIds[0]>0 ) // fbo created with the first constructor |
373 | 401 |
{ |
402 |
DistortedFramebuffer.deleteAllMarked(); |
|
403 |
DistortedTexture.deleteAllMarked(); |
|
374 | 404 |
createFBO(); |
375 | 405 |
setAsOutput(); |
376 | 406 |
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, fbo.colorIds[0]); |
377 | 407 |
effects.drawPriv(fbo.mWidth/2, fbo.mHeight/2, mesh, this, time); |
378 |
DistortedFramebuffer.deleteAllMarked(); |
|
379 |
DistortedTexture.deleteAllMarked(); |
|
380 | 408 |
} |
381 | 409 |
} |
382 | 410 |
|
... | ... | |
391 | 419 |
*/ |
392 | 420 |
public void renderTo(DistortedTree dt, long time) |
393 | 421 |
{ |
422 |
DistortedFramebuffer.deleteAllMarked(); |
|
423 |
DistortedTexture.deleteAllMarked(); |
|
394 | 424 |
createFBO(); |
395 | 425 |
setAsOutput(); |
396 | 426 |
dt.drawRecursive(time,this); |
397 |
DistortedFramebuffer.deleteAllMarked(); |
|
398 |
DistortedTexture.deleteAllMarked(); |
|
399 | 427 |
} |
400 | 428 |
|
401 | 429 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
445 | 473 |
{ |
446 | 474 |
if( mWidth!=width || mHeight!=height ) |
447 | 475 |
{ |
448 |
mWidth = width; |
|
449 |
mHeight= height; |
|
476 |
mWidth = width; |
|
477 |
mHeight = height; |
|
478 |
mTexWidth = width; |
|
479 |
mTexHeight= height; |
|
450 | 480 |
|
451 | 481 |
createProjection(); |
452 | 482 |
|
Also available in: Unified diff
Initial version of the first post-processing effect - BLUR - ready for the first app!