Revision 2e49718d
Added by Leszek Koltunski about 7 years ago
src/main/java/org/distorted/library/DistortedFramebuffer.java | ||
---|---|---|
22 | 22 |
import android.opengl.GLES30; |
23 | 23 |
import android.opengl.Matrix; |
24 | 24 |
|
25 |
import java.util.Iterator; |
|
26 |
import java.util.LinkedList; |
|
27 |
|
|
28 | 25 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
29 | 26 |
/** |
30 | 27 |
* Class which represents a OpenGL Framebuffer object. |
... | ... | |
41 | 38 |
*/ |
42 | 39 |
public class DistortedFramebuffer extends DistortedRenderable |
43 | 40 |
{ |
44 |
private static boolean mListMarked = false; |
|
45 |
private static LinkedList<DistortedFramebuffer> mList = new LinkedList<>(); |
|
46 |
|
|
47 | 41 |
private int[] mDepthH = new int[1]; |
48 | 42 |
private int[] mFBOH = new int[1]; |
49 | 43 |
|
50 |
private boolean mMarked; |
|
51 | 44 |
private boolean mDepthEnabled; |
52 | 45 |
|
53 | 46 |
// Projection stuff |
... | ... | |
142 | 135 |
GLES30.glDeleteFramebuffers(1, mFBOH, 0); |
143 | 136 |
mFBOH[0] = 0; |
144 | 137 |
} |
145 |
|
|
146 |
mMarked = false; |
|
147 | 138 |
} |
148 | 139 |
|
149 | 140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
199 | 190 |
} |
200 | 191 |
} |
201 | 192 |
|
202 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
203 |
|
|
204 |
static synchronized void onDestroy() |
|
205 |
{ |
|
206 |
for( DistortedFramebuffer fbo : mList) |
|
207 |
{ |
|
208 |
if( fbo.mColorH[0]!=DONT_CREATE ) fbo.mColorH[0] = NOT_CREATED_YET; |
|
209 |
if( fbo.mDepthEnabled ) fbo.mDepthH[0] = NOT_CREATED_YET; |
|
210 |
} |
|
211 |
} |
|
212 |
|
|
213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
214 |
// must be called form a thread holding OpenGL Context |
|
215 |
|
|
216 |
private static synchronized void deleteAllMarked() |
|
217 |
{ |
|
218 |
if( mListMarked ) |
|
219 |
{ |
|
220 |
DistortedFramebuffer tmp; |
|
221 |
Iterator<DistortedFramebuffer> iterator = mList.iterator(); |
|
222 |
|
|
223 |
while(iterator.hasNext()) |
|
224 |
{ |
|
225 |
tmp = iterator.next(); |
|
226 |
|
|
227 |
if( tmp.mMarked ) |
|
228 |
{ |
|
229 |
tmp.delete(); |
|
230 |
iterator.remove(); |
|
231 |
} |
|
232 |
} |
|
233 |
|
|
234 |
mListMarked = false; |
|
235 |
} |
|
236 |
} |
|
237 |
|
|
238 | 193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
239 | 194 |
// if new size fits into the size of the underlying Texture, just change the projection without |
240 | 195 |
// reallocating the Texture. Otherwise, we need to reallocate. |
... | ... | |
274 | 229 |
@SuppressWarnings("unused") |
275 | 230 |
public DistortedFramebuffer(int width, int height, boolean depthEnabled) |
276 | 231 |
{ |
232 |
super(width,height,NOT_CREATED_YET); |
|
233 |
|
|
277 | 234 |
mProjectionMatrix = new float[16]; |
278 | 235 |
|
279 | 236 |
mHeight = height; |
280 | 237 |
mWidth = width; |
281 |
mSizeY = height; |
|
282 |
mSizeX = width; |
|
283 | 238 |
mFOV = 60.0f; |
284 | 239 |
mX = 0.0f; |
285 | 240 |
mY = 0.0f; |
286 |
mMarked = false; |
|
287 | 241 |
mDepthEnabled= depthEnabled; |
288 |
|
|
289 |
mFBOH[0] =-1; |
|
290 |
mColorH[0]= NOT_CREATED_YET; |
|
291 |
mDepthH[0]= NOT_CREATED_YET; |
|
242 |
mFBOH[0] = NOT_CREATED_YET; |
|
243 |
mDepthH[0] = NOT_CREATED_YET; |
|
292 | 244 |
|
293 | 245 |
createProjection(); |
294 |
|
|
295 |
mList.add(this); |
|
296 | 246 |
} |
297 | 247 |
|
298 | 248 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
306 | 256 |
@SuppressWarnings("unused") |
307 | 257 |
public DistortedFramebuffer(int width, int height) |
308 | 258 |
{ |
259 |
super(width,height,NOT_CREATED_YET); |
|
260 |
|
|
309 | 261 |
mProjectionMatrix = new float[16]; |
310 | 262 |
|
311 | 263 |
mHeight = height; |
312 | 264 |
mWidth = width; |
313 |
mSizeY = height; |
|
314 |
mSizeX = width; |
|
315 | 265 |
mFOV = 60.0f; |
316 | 266 |
mX = 0.0f; |
317 | 267 |
mY = 0.0f; |
318 |
mMarked = false; |
|
319 | 268 |
mDepthEnabled= false; |
320 |
|
|
321 |
mFBOH[0] =-1; |
|
322 |
mColorH[0]= NOT_CREATED_YET; |
|
323 |
mDepthH[0]= NOT_CREATED_YET; |
|
269 |
mFBOH[0] = NOT_CREATED_YET; |
|
270 |
mDepthH[0] = NOT_CREATED_YET; |
|
324 | 271 |
|
325 | 272 |
createProjection(); |
326 |
|
|
327 |
mList.add(this); |
|
328 | 273 |
} |
329 | 274 |
|
330 | 275 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
337 | 282 |
*/ |
338 | 283 |
public DistortedFramebuffer(int fbo) |
339 | 284 |
{ |
285 |
super(0,0,DONT_CREATE); |
|
286 |
|
|
340 | 287 |
mProjectionMatrix = new float[16]; |
341 | 288 |
|
342 | 289 |
mFOV = 60.0f; |
343 | 290 |
mX = 0.0f; |
344 | 291 |
mY = 0.0f; |
345 |
mMarked = false; |
|
346 | 292 |
mDepthEnabled= true; |
347 |
|
|
348 |
mFBOH[0] = fbo; |
|
349 |
mColorH[0]= DONT_CREATE; |
|
350 |
mDepthH[0]= DONT_CREATE; |
|
293 |
mFBOH[0] = fbo; |
|
294 |
mDepthH[0] = DONT_CREATE; |
|
351 | 295 |
} |
352 | 296 |
|
353 | 297 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
381 | 325 |
|
382 | 326 |
if( ren.setAsInput() ) |
383 | 327 |
{ |
384 |
DistortedFramebuffer.deleteAllMarked(); |
|
385 |
DistortedTexture.deleteAllMarked(); |
|
328 |
DistortedRenderable.deleteAllMarked(); |
|
386 | 329 |
effects.drawPriv(ren.getWidth()/2.0f, ren.getHeight()/2.0f, mesh, this, time); |
387 | 330 |
} |
388 | 331 |
} |
... | ... | |
398 | 341 |
*/ |
399 | 342 |
public void renderTo(DistortedTree dt, long time) |
400 | 343 |
{ |
401 |
DistortedFramebuffer.deleteAllMarked(); |
|
402 |
DistortedTexture.deleteAllMarked(); |
|
344 |
DistortedRenderable.deleteAllMarked(); |
|
403 | 345 |
create(); |
404 | 346 |
dt.drawRecursive(time,this); |
405 | 347 |
} |
406 | 348 |
|
407 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
408 |
/** |
|
409 |
* Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render. |
|
410 |
*/ |
|
411 |
public void markForDeletion() |
|
412 |
{ |
|
413 |
mListMarked = true; |
|
414 |
mMarked = true; |
|
415 |
} |
|
416 |
|
|
417 | 349 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
418 | 350 |
/** |
419 | 351 |
* Create new Projection matrix. |
Also available in: Unified diff
progress with DistortedRenderable.
This introduces a regression with MultiBlur!