1 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Distorted. //
|
5 |
|
|
// //
|
6 |
|
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
6a06a912
|
Leszek Koltunski
|
package org.distorted.library;
|
21 |
|
|
|
22 |
bd3da5b2
|
Leszek Koltunski
|
import java.util.LinkedList;
|
23 |
|
|
import java.util.Iterator;
|
24 |
6a06a912
|
Leszek Koltunski
|
|
25 |
b329f352
|
Leszek Koltunski
|
/**
|
26 |
dedacd82
|
Leszek Koltunski
|
* List of all DistortedFramebuffer objects currently created by the application.
|
27 |
bd3da5b2
|
Leszek Koltunski
|
*
|
28 |
dedacd82
|
Leszek Koltunski
|
* The point: we need to be able to mark Framebuffers for deletion, and delete all marked
|
29 |
|
|
* objects later at a convenient time (that's because we can only delete from a thread that
|
30 |
|
|
* holds the OpenGL context so here we provide a framework where one is able to mark for deletion
|
31 |
|
|
* at any place and actual deletion takes place on the next render).
|
32 |
b329f352
|
Leszek Koltunski
|
*/
|
33 |
bd3da5b2
|
Leszek Koltunski
|
|
34 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
35 |
|
|
|
36 |
ed13a5de
|
Leszek Koltunski
|
final class DistortedFramebufferList
|
37 |
6a06a912
|
Leszek Koltunski
|
{
|
38 |
bd3da5b2
|
Leszek Koltunski
|
private static boolean mMarked = false;
|
39 |
ed13a5de
|
Leszek Koltunski
|
private static LinkedList<DistortedFramebuffer> mList = new LinkedList<>();
|
40 |
b329f352
|
Leszek Koltunski
|
|
41 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42 |
bd3da5b2
|
Leszek Koltunski
|
|
43 |
ed13a5de
|
Leszek Koltunski
|
static synchronized void add(DistortedFramebuffer drt)
|
44 |
bd3da5b2
|
Leszek Koltunski
|
{
|
45 |
|
|
mList.add(drt);
|
46 |
|
|
}
|
47 |
6a06a912
|
Leszek Koltunski
|
|
48 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49 |
|
|
|
50 |
bd3da5b2
|
Leszek Koltunski
|
static synchronized void markForDeletion()
|
51 |
6a06a912
|
Leszek Koltunski
|
{
|
52 |
bd3da5b2
|
Leszek Koltunski
|
mMarked = true;
|
53 |
|
|
}
|
54 |
|
|
|
55 |
dedacd82
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56 |
|
|
|
57 |
|
|
static synchronized void release()
|
58 |
|
|
{
|
59 |
|
|
mMarked = false;
|
60 |
|
|
mList.clear();
|
61 |
|
|
}
|
62 |
|
|
|
63 |
bd3da5b2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
64 |
|
|
// must be called form a thread holding OpenGL Context
|
65 |
|
|
|
66 |
|
|
static synchronized void deleteAllMarked()
|
67 |
|
|
{
|
68 |
|
|
if( mMarked )
|
69 |
6a06a912
|
Leszek Koltunski
|
{
|
70 |
ed13a5de
|
Leszek Koltunski
|
DistortedFramebuffer tmp;
|
71 |
|
|
Iterator<DistortedFramebuffer> iterator = mList.iterator();
|
72 |
bd3da5b2
|
Leszek Koltunski
|
|
73 |
|
|
while(iterator.hasNext())
|
74 |
|
|
{
|
75 |
|
|
tmp = iterator.next();
|
76 |
|
|
|
77 |
|
|
if( tmp.mMarked )
|
78 |
|
|
{
|
79 |
|
|
tmp.release();
|
80 |
|
|
iterator.remove();
|
81 |
|
|
}
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
mMarked = false;
|
85 |
6a06a912
|
Leszek Koltunski
|
}
|
86 |
|
|
}
|
87 |
bd3da5b2
|
Leszek Koltunski
|
}
|