Revision af27df87
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/library/DistortedEffects.java | ||
---|---|---|
77 | 77 |
private static long mNextID =0; |
78 | 78 |
private long mID; |
79 | 79 |
|
80 |
private static DistortedFramebuffer mBufferFBO = new DistortedFramebuffer(1,1,true);
|
|
80 |
private static DistortedFramebuffer mBufferFBO = new DistortedFramebuffer(true,1,1);
|
|
81 | 81 |
|
82 | 82 |
private EffectQueueMatrix mM; |
83 | 83 |
private EffectQueueFragment mF; |
src/main/java/org/distorted/library/DistortedFramebuffer.java | ||
---|---|---|
156 | 156 |
create(); |
157 | 157 |
} |
158 | 158 |
|
159 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
160 |
// create 'system' Framebuffers, i.e. those that are used internally by the library. |
|
161 |
// Those do not get removed in onDestroy(); |
|
162 |
|
|
163 |
public DistortedFramebuffer(boolean depthEnabled, int width, int height) |
|
164 |
{ |
|
165 |
super(width,height,NOT_CREATED_YET,true); |
|
166 |
mDepthEnabled= depthEnabled; |
|
167 |
mFBOH[0] = NOT_CREATED_YET; |
|
168 |
mDepthH[0] = NOT_CREATED_YET; |
|
169 |
} |
|
170 |
|
|
159 | 171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
160 | 172 |
// PUBLIC API |
161 | 173 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
169 | 181 |
@SuppressWarnings("unused") |
170 | 182 |
public DistortedFramebuffer(int width, int height, boolean depthEnabled) |
171 | 183 |
{ |
172 |
super(width,height,NOT_CREATED_YET); |
|
184 |
super(width,height,NOT_CREATED_YET,false);
|
|
173 | 185 |
mDepthEnabled= depthEnabled; |
174 | 186 |
mFBOH[0] = NOT_CREATED_YET; |
175 | 187 |
mDepthH[0] = NOT_CREATED_YET; |
... | ... | |
186 | 198 |
@SuppressWarnings("unused") |
187 | 199 |
public DistortedFramebuffer(int width, int height) |
188 | 200 |
{ |
189 |
super(width,height,NOT_CREATED_YET); |
|
201 |
super(width,height,NOT_CREATED_YET,false);
|
|
190 | 202 |
mDepthEnabled= false; |
191 | 203 |
mFBOH[0] = NOT_CREATED_YET; |
192 | 204 |
mDepthH[0] = NOT_CREATED_YET; |
src/main/java/org/distorted/library/DistortedNode.java | ||
---|---|---|
53 | 53 |
long ID; |
54 | 54 |
int numPointingNodes; |
55 | 55 |
int numRendered; |
56 |
ArrayList<Long> key; |
|
56 | 57 |
DistortedFramebuffer mFBO; |
57 | 58 |
|
58 |
NodeData(long id) |
|
59 |
NodeData(long id, ArrayList<Long> k)
|
|
59 | 60 |
{ |
60 | 61 |
ID = id; |
62 |
key = k; |
|
61 | 63 |
numPointingNodes= 1; |
62 | 64 |
numRendered = 0; |
63 | 65 |
mFBO = null; |
... | ... | |
108 | 110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
109 | 111 |
// Debug - print all the Node IDs |
110 | 112 |
|
113 |
@SuppressWarnings("unused") |
|
111 | 114 |
void debug(int depth) |
112 | 115 |
{ |
113 | 116 |
String tmp=""; |
... | ... | |
125 | 128 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
126 | 129 |
// Debug - print contents of the HashMap |
127 | 130 |
|
131 |
@SuppressWarnings("unused") |
|
128 | 132 |
static void debugMap() |
129 | 133 |
{ |
130 | 134 |
NodeData tmp; |
... | ... | |
140 | 144 |
|
141 | 145 |
void treeIsomorphism() |
142 | 146 |
{ |
143 |
android.util.Log.e("NODE", "begin treeIso for Node Surface ID="+mSurface.getID()); |
|
144 |
debug(0); |
|
145 |
debugMap(); |
|
146 |
android.util.Log.e("NODE", "begin treeIso for Node Surface ID="+mSurface.getID()); |
|
147 |
|
|
148 |
ArrayList<Long> oldList = generateIDList(); |
|
149 |
|
|
150 | 147 |
for(int i=0; i<mNumChildren[0]; i++) |
151 | 148 |
{ |
152 | 149 |
mChildren.get(i).treeIsomorphism(); |
... | ... | |
157 | 154 |
|
158 | 155 |
if( newData==null ) |
159 | 156 |
{ |
160 |
android.util.Log.d("NODE", " inserted newData to map, newList="+newList); |
|
161 |
|
|
162 |
|
|
163 |
newData = new NodeData(++mNextNodeID); |
|
157 |
newData = new NodeData(++mNextNodeID,newList); |
|
164 | 158 |
mMapNodeID.put(newList,newData); |
165 |
debugMap(); |
|
166 | 159 |
} |
167 | 160 |
else if( newData.ID != mData.ID ) |
168 | 161 |
{ |
... | ... | |
177 | 170 |
{ |
178 | 171 |
if( mData.mFBO!=null ) |
179 | 172 |
{ |
173 |
android.util.Log.d("NODE", "copying over FBO of node surfaceID="+mSurface.getID()); |
|
174 |
|
|
180 | 175 |
newData.mFBO = mData.mFBO; |
181 | 176 |
fboUsed = true; |
182 | 177 |
} |
183 | 178 |
else |
184 | 179 |
{ |
180 |
android.util.Log.d("NODE", "creating new FBO of node surfaceID="+mSurface.getID()); |
|
185 | 181 |
newData.mFBO = new DistortedFramebuffer(mSurface.getWidth(),mSurface.getHeight()); |
186 | 182 |
} |
187 | 183 |
} |
188 | 184 |
if( mNumChildren[0]==0 && newData.mFBO!=null ) |
189 | 185 |
{ |
186 |
android.util.Log.d("NODE", "deleting FBO of newData node!!"); |
|
187 |
|
|
188 |
|
|
190 | 189 |
newData.mFBO.markForDeletion(); |
191 | 190 |
newData.mFBO = null; |
192 | 191 |
} |
193 | 192 |
|
194 | 193 |
if( --mData.numPointingNodes==0 ) |
195 | 194 |
{ |
196 |
android.util.Log.d("NODE", " removed oldData to map, oldList="+oldList); |
|
197 |
|
|
198 |
|
|
199 |
mMapNodeID.remove(oldList); |
|
200 |
debugMap(); |
|
195 |
mMapNodeID.remove(mData.key); |
|
201 | 196 |
|
202 | 197 |
if( !fboUsed && mData.mFBO!=null ) |
203 | 198 |
{ |
199 |
android.util.Log.d("NODE", "deleting FBO of node surfaceID="+mSurface.getID()); |
|
200 |
|
|
204 | 201 |
mData.mFBO.markForDeletion(); |
205 | 202 |
mData.mFBO = null; |
206 | 203 |
} |
... | ... | |
208 | 205 |
|
209 | 206 |
mData = newData; |
210 | 207 |
} |
211 |
|
|
212 |
android.util.Log.e("NODE", "end treeIso for Node SurfaceID="+mSurface.getID()+" newList="+newList); |
|
213 |
debug(0); |
|
214 |
debugMap(); |
|
215 |
android.util.Log.e("NODE", "end treeIso for Node SurfaceID="+mSurface.getID()+" newList="+newList); |
|
216 | 208 |
} |
217 | 209 |
|
218 | 210 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
282 | 274 |
} |
283 | 275 |
else |
284 | 276 |
{ |
285 |
mData = new NodeData(++mNextNodeID);
|
|
277 |
mData = new NodeData(++mNextNodeID,list);
|
|
286 | 278 |
mMapNodeID.put(list, mData); |
287 | 279 |
} |
288 | 280 |
} |
... | ... | |
348 | 340 |
} |
349 | 341 |
else |
350 | 342 |
{ |
351 |
mData = new NodeData(++mNextNodeID);
|
|
343 |
mData = new NodeData(++mNextNodeID,list);
|
|
352 | 344 |
mMapNodeID.put(list, mData); |
353 | 345 |
} |
354 | 346 |
} |
... | ... | |
458 | 450 |
if( mNumChildren[0]>0 && mChildren.remove(node) ) |
459 | 451 |
{ |
460 | 452 |
mNumChildren[0]--; |
453 |
|
|
454 |
if( mNumChildren[0]==0 && mData.mFBO!=null ) |
|
455 |
{ |
|
456 |
mData.mFBO.markForDeletion(); |
|
457 |
mData.mFBO = null; |
|
458 |
} |
|
461 | 459 |
} |
462 | 460 |
} |
463 | 461 |
|
... | ... | |
485 | 483 |
{ |
486 | 484 |
mNumChildren[0] = 0; |
487 | 485 |
mChildren.clear(); |
486 |
|
|
487 |
if( mData.mFBO!=null ) |
|
488 |
{ |
|
489 |
mData.mFBO.markForDeletion(); |
|
490 |
mData.mFBO = null; |
|
491 |
} |
|
488 | 492 |
} |
489 | 493 |
} |
490 | 494 |
|
src/main/java/org/distorted/library/DistortedOutputSurface.java | ||
---|---|---|
36 | 36 |
|
37 | 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
38 | 38 |
|
39 |
DistortedOutputSurface(int width, int height, int color) |
|
39 |
DistortedOutputSurface(int width, int height, int color, boolean system)
|
|
40 | 40 |
{ |
41 |
super(width,height,color); |
|
41 |
super(width,height,color,system);
|
|
42 | 42 |
|
43 | 43 |
mProjectionMatrix = new float[16]; |
44 | 44 |
|
... | ... | |
106 | 106 |
// can result in additional Framebuffers that would need |
107 | 107 |
// to be created immediately, before the calls to drawRecursive() |
108 | 108 |
|
109 |
if( DistortedAttachDaemon.toDo() ) |
|
109 |
boolean changed = DistortedAttachDaemon.toDo(); |
|
110 |
|
|
111 |
if( changed ) |
|
110 | 112 |
{ |
111 | 113 |
for(int i=0; i<mNumChildren; i++) |
112 | 114 |
{ |
113 | 115 |
mChildren.get(i).treeIsomorphism(); |
116 |
mChildren.get(i).debug(0); |
|
114 | 117 |
} |
118 |
|
|
119 |
//DistortedNode.debugMap(); |
|
115 | 120 |
} |
116 | 121 |
|
117 | 122 |
toDo(); |
118 | 123 |
|
124 |
if( changed ) |
|
125 |
{ |
|
126 |
DistortedSurface.debugLists(); |
|
127 |
} |
|
128 |
|
|
119 | 129 |
for(int i=0; i<mNumChildren; i++) |
120 | 130 |
{ |
121 | 131 |
mChildren.get(i).drawRecursive(time,this); |
... | ... | |
219 | 229 |
mNumChildren++; |
220 | 230 |
} |
221 | 231 |
|
232 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
233 |
/** |
|
234 |
* Removes the first occurrence of a specified child from the list of children of our Surface. |
|
235 |
* <p> |
|
236 |
* A bit questionable method as there can be many different Nodes attached as children, some |
|
237 |
* of them having the same Effects but - for instance - different Mesh. Use with care. |
|
238 |
* <p> |
|
239 |
* We cannot do this mid-render - actual detachment will be done just before the next render, by the |
|
240 |
* DistortedAttachDeamon (by calling detachNow()) |
|
241 |
* |
|
242 |
* @param effects DistortedEffects to remove. |
|
243 |
*/ |
|
244 |
public void detach(DistortedEffects effects) |
|
245 |
{ |
|
246 |
long id = effects.getID(); |
|
247 |
DistortedNode node; |
|
248 |
|
|
249 |
for(int i=0; i<mNumChildren; i++) |
|
250 |
{ |
|
251 |
node = mChildren.get(i); |
|
252 |
|
|
253 |
if( node.getEffects().getID()==id ) |
|
254 |
{ |
|
255 |
DistortedAttachDaemon.detach(this,node); |
|
256 |
break; |
|
257 |
} |
|
258 |
} |
|
259 |
} |
|
260 |
|
|
222 | 261 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
223 | 262 |
/** |
224 | 263 |
* Removes the first occurrence of a specified child from the list of children of our Surface. |
src/main/java/org/distorted/library/DistortedScreen.java | ||
---|---|---|
46 | 46 |
*/ |
47 | 47 |
public DistortedScreen() |
48 | 48 |
{ |
49 |
super(0,0,DONT_CREATE); |
|
49 |
super(0,0,DONT_CREATE,false);
|
|
50 | 50 |
} |
51 | 51 |
|
52 | 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/DistortedSurface.java | ||
---|---|---|
38 | 38 |
private static boolean mToDo = false; |
39 | 39 |
private static LinkedList<DistortedSurface> mDoneList = new LinkedList<>(); |
40 | 40 |
private static LinkedList<DistortedSurface> mToDoList = new LinkedList<>(); |
41 |
private static long mNextID = 0; |
|
41 |
private static long mNextClientID = 0; |
|
42 |
private static long mNextSystemID = 0; |
|
42 | 43 |
|
43 | 44 |
private long mID; |
44 | 45 |
private boolean mMarked; |
46 |
private boolean mSystem; |
|
45 | 47 |
int[] mColorH = new int[1]; |
46 | 48 |
int mSizeX, mSizeY; // in screen space |
47 | 49 |
|
... | ... | |
93 | 95 |
for(int i=0; i<num; i++) |
94 | 96 |
{ |
95 | 97 |
surface = mDoneList.removeFirst(); |
98 |
if( surface.mSystem ) mToDoList.add(surface); |
|
99 |
} |
|
100 |
|
|
101 |
num = mToDoList.size(); |
|
102 |
|
|
103 |
for(int i=0; i<num; i++) |
|
104 |
{ |
|
105 |
surface = mToDoList.get(i); |
|
96 | 106 |
|
97 |
if( !surface.mMarked )
|
|
107 |
if( !surface.mSystem )
|
|
98 | 108 |
{ |
99 |
surface.recreate(); |
|
100 |
mToDoList.add(surface); |
|
109 |
mDoneList.remove(i); |
|
110 |
i--; |
|
111 |
num--; |
|
101 | 112 |
} |
102 | 113 |
} |
103 | 114 |
|
104 |
mToDo = true;
|
|
105 |
mNextID = 0; |
|
115 |
mToDo = (num>0);
|
|
116 |
mNextClientID = 0;
|
|
106 | 117 |
} |
107 | 118 |
|
108 | 119 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
118 | 129 |
|
119 | 130 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
120 | 131 |
|
121 |
DistortedSurface(int width, int height, int color) |
|
132 |
@SuppressWarnings("unused") |
|
133 |
static void debugLists() |
|
134 |
{ |
|
135 |
android.util.Log.e("Surface", "Done list:"); |
|
136 |
debugList(mDoneList); |
|
137 |
android.util.Log.e("Surface", "ToDo list:"); |
|
138 |
debugList(mToDoList); |
|
139 |
} |
|
140 |
|
|
141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
142 |
|
|
143 |
private static void debugList(LinkedList<DistortedSurface> list) |
|
144 |
{ |
|
145 |
DistortedSurface surface; |
|
146 |
String str; |
|
147 |
|
|
148 |
int num = list.size(); |
|
149 |
|
|
150 |
for(int i=0; i<num; i++) |
|
151 |
{ |
|
152 |
surface = list.get(i); |
|
153 |
|
|
154 |
if( surface instanceof DistortedFramebuffer ) str = (i+": Framebuffer "); |
|
155 |
else if( surface instanceof DistortedTexture) str = (i+": Texture "); |
|
156 |
else if( surface instanceof DistortedScreen ) str = (i+": Screen "); |
|
157 |
else str = (i+": UNKNOWN "); |
|
158 |
|
|
159 |
str += ("("+surface.getWidth()+","+surface.getHeight()+") surfaceID:"+surface.getID()); |
|
160 |
|
|
161 |
android.util.Log.e("Surface", str); |
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
166 |
|
|
167 |
DistortedSurface(int width, int height, int color, boolean system) |
|
122 | 168 |
{ |
123 | 169 |
mSizeX = width ; |
124 | 170 |
mSizeY = height; |
125 | 171 |
mColorH[0]= color; |
126 | 172 |
mMarked = false; |
127 |
mID = mNextID++; |
|
173 |
mID = system ? --mNextSystemID : ++mNextClientID; |
|
174 |
mSystem = system; |
|
128 | 175 |
|
129 | 176 |
if( color!=DONT_CREATE ) |
130 | 177 |
{ |
src/main/java/org/distorted/library/DistortedTexture.java | ||
---|---|---|
117 | 117 |
*/ |
118 | 118 |
public DistortedTexture(int width, int height) |
119 | 119 |
{ |
120 |
super(width,height,NOT_CREATED_YET); |
|
120 |
super(width,height,NOT_CREATED_YET,false);
|
|
121 | 121 |
mBmp= null; |
122 | 122 |
} |
123 | 123 |
|
src/main/java/org/distorted/library/EffectQueuePostprocess.java | ||
---|---|---|
69 | 69 |
mQuadTextureInv.put(textureInv).position(0); |
70 | 70 |
} |
71 | 71 |
|
72 |
private static DistortedFramebuffer mBufferFBO = new DistortedFramebuffer(1,1,true);
|
|
72 |
private static DistortedFramebuffer mBufferFBO = new DistortedFramebuffer(true,1,1);
|
|
73 | 73 |
|
74 | 74 |
private static float[] mMVPMatrix = new float[16]; |
75 | 75 |
private static float[] mTmpMatrix = new float[16]; |
Also available in: Unified diff
A lot of different fixes.
A lot of issues still there:
1) if we only render part of the tree, tree isomorphism will sometimes not work correctly
2) when we change Effects that are inside Trees mid-render, even if we detach() the affected parts of the Tree first, for the last frame the new Effects will be used
3) Something is wrong wil the System FBOs after app restart (Blur & MultiBlur apps work erratically)