Revision 2e49718d
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/DistortedRenderable.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import android.opengl.GLES30; |
23 | 23 |
|
24 |
import java.util.Iterator; |
|
25 |
import java.util.LinkedList; |
|
26 |
|
|
24 | 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
25 | 28 |
|
26 | 29 |
abstract class DistortedRenderable |
... | ... | |
29 | 32 |
static final int NOT_CREATED_YET = -2; |
30 | 33 |
static final int DONT_CREATE = -3; |
31 | 34 |
|
35 |
private static boolean mListMarked = false; |
|
36 |
private static LinkedList<DistortedRenderable> mList = new LinkedList<>(); |
|
37 |
|
|
38 |
private boolean mMarked; |
|
32 | 39 |
int[] mColorH = new int[1]; |
33 | 40 |
int mSizeX, mSizeY; // in screen space |
34 | 41 |
|
... | ... | |
37 | 44 |
abstract void create(); |
38 | 45 |
abstract void delete(); |
39 | 46 |
|
47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
48 |
// must be called form a thread holding OpenGL Context |
|
49 |
|
|
50 |
static synchronized void deleteAllMarked() |
|
51 |
{ |
|
52 |
if( mListMarked ) |
|
53 |
{ |
|
54 |
DistortedRenderable tmp; |
|
55 |
Iterator<DistortedRenderable> iterator = mList.iterator(); |
|
56 |
|
|
57 |
while(iterator.hasNext()) |
|
58 |
{ |
|
59 |
tmp = iterator.next(); |
|
60 |
|
|
61 |
if( tmp.mMarked ) |
|
62 |
{ |
|
63 |
tmp.delete(); |
|
64 |
tmp.mMarked = false; |
|
65 |
iterator.remove(); |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 |
mListMarked = false; |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
40 | 73 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
41 | 74 |
|
42 | 75 |
long getID() |
... | ... | |
57 | 90 |
return false; |
58 | 91 |
} |
59 | 92 |
|
93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
94 |
|
|
95 |
static synchronized void onDestroy() |
|
96 |
{ |
|
97 |
for( DistortedRenderable ren : mList) |
|
98 |
{ |
|
99 |
ren.delete(); |
|
100 |
ren.mMarked = false; |
|
101 |
} |
|
102 |
|
|
103 |
mListMarked = false; |
|
104 |
mList.clear(); |
|
105 |
} |
|
106 |
|
|
107 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
108 |
|
|
109 |
DistortedRenderable(int width, int height, int color) |
|
110 |
{ |
|
111 |
mSizeX = width ; |
|
112 |
mSizeY = height; |
|
113 |
mColorH[0]= color; |
|
114 |
mMarked = false; |
|
115 |
mList.add(this); |
|
116 |
} |
|
117 |
|
|
60 | 118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
61 | 119 |
// PUBLIC API |
62 | 120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
121 |
/** |
|
122 |
* Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render. |
|
123 |
*/ |
|
124 |
public void markForDeletion() |
|
125 |
{ |
|
126 |
mListMarked = true; |
|
127 |
mMarked = true; |
|
128 |
} |
|
129 |
|
|
130 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
131 |
|
|
63 | 132 |
/** |
64 | 133 |
* Returns the height of the Renderable. |
65 | 134 |
* |
Also available in: Unified diff
progress with DistortedRenderable.
This introduces a regression with MultiBlur!