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 |
|
|
import java.util.ArrayList;
|
23 |
|
|
import java.util.HashMap;
|
24 |
|
|
|
25 |
194ab46f
|
Leszek Koltunski
|
import android.opengl.GLES30;
|
26 |
6a06a912
|
Leszek Koltunski
|
|
27 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
28 |
|
|
/**
|
29 |
05403bba
|
Leszek Koltunski
|
* Class which represents a Node in a Tree of (Texture,Mesh,Effects) objects.
|
30 |
6a06a912
|
Leszek Koltunski
|
*
|
31 |
7b8086eb
|
Leszek Koltunski
|
* Having organized such sets into a Tree, we can then render any Node to any Framebuffer.
|
32 |
|
|
* That recursively renders the set held in the Node and all its children.
|
33 |
6a06a912
|
Leszek Koltunski
|
*/
|
34 |
421c2728
|
Leszek Koltunski
|
public class DistortedTree
|
35 |
6a06a912
|
Leszek Koltunski
|
{
|
36 |
bd3da5b2
|
Leszek Koltunski
|
private static HashMap<ArrayList<Long>,NodeData> mMapNodeID = new HashMap<>();
|
37 |
|
|
private static long mNextNodeID =0;
|
38 |
|
|
|
39 |
05403bba
|
Leszek Koltunski
|
private MeshObject mMesh;
|
40 |
07d8ef09
|
Leszek Koltunski
|
private DistortedEffects mEffects;
|
41 |
4e2382f3
|
Leszek Koltunski
|
private DistortedTexture mTexture;
|
42 |
6a06a912
|
Leszek Koltunski
|
private NodeData mData;
|
43 |
bd3da5b2
|
Leszek Koltunski
|
|
44 |
421c2728
|
Leszek Koltunski
|
private DistortedTree mParent;
|
45 |
|
|
private ArrayList<DistortedTree> mChildren;
|
46 |
6a06a912
|
Leszek Koltunski
|
private int[] mNumChildren; // ==mChildren.length(), but we only create mChildren if the first one gets added
|
47 |
|
|
|
48 |
|
|
private class NodeData
|
49 |
|
|
{
|
50 |
bd3da5b2
|
Leszek Koltunski
|
long ID;
|
51 |
6a06a912
|
Leszek Koltunski
|
int numPointingNodes;
|
52 |
d620ff06
|
Leszek Koltunski
|
int numRendered;
|
53 |
8c327653
|
Leszek Koltunski
|
DistortedFramebuffer mFBO;
|
54 |
6a06a912
|
Leszek Koltunski
|
|
55 |
bd3da5b2
|
Leszek Koltunski
|
NodeData(long id)
|
56 |
6a06a912
|
Leszek Koltunski
|
{
|
57 |
bd3da5b2
|
Leszek Koltunski
|
ID = id;
|
58 |
|
|
numPointingNodes= 1;
|
59 |
d620ff06
|
Leszek Koltunski
|
numRendered = 0;
|
60 |
8c327653
|
Leszek Koltunski
|
mFBO = null;
|
61 |
6a06a912
|
Leszek Koltunski
|
}
|
62 |
bd3da5b2
|
Leszek Koltunski
|
}
|
63 |
6a06a912
|
Leszek Koltunski
|
|
64 |
436899f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
65 |
|
|
|
66 |
7b8086eb
|
Leszek Koltunski
|
static synchronized void onDestroy()
|
67 |
436899f2
|
Leszek Koltunski
|
{
|
68 |
|
|
mNextNodeID = 0;
|
69 |
|
|
mMapNodeID.clear();
|
70 |
|
|
}
|
71 |
|
|
|
72 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
73 |
|
|
// tree isomorphism
|
74 |
|
|
|
75 |
|
|
private void RecomputeNodeID(ArrayList<Long> prev)
|
76 |
|
|
{
|
77 |
|
|
ArrayList<Long> curr = generateIDList();
|
78 |
|
|
|
79 |
|
|
if( mParent==null )
|
80 |
|
|
{
|
81 |
|
|
adjustNodeData(prev,curr);
|
82 |
|
|
}
|
83 |
|
|
else
|
84 |
|
|
{
|
85 |
|
|
ArrayList<Long> parentPrev = mParent.generateIDList();
|
86 |
|
|
adjustNodeData(prev,curr);
|
87 |
|
|
mParent.RecomputeNodeID(parentPrev);
|
88 |
|
|
}
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
92 |
|
|
|
93 |
|
|
private ArrayList<Long> generateIDList()
|
94 |
|
|
{
|
95 |
9361b337
|
Leszek Koltunski
|
ArrayList<Long> ret = new ArrayList<>();
|
96 |
6a06a912
|
Leszek Koltunski
|
|
97 |
1942537e
|
Leszek Koltunski
|
ret.add( mTexture.getID() );
|
98 |
421c2728
|
Leszek Koltunski
|
DistortedTree node;
|
99 |
6a06a912
|
Leszek Koltunski
|
|
100 |
|
|
for(int i=0; i<mNumChildren[0]; i++)
|
101 |
|
|
{
|
102 |
|
|
node = mChildren.get(i);
|
103 |
|
|
ret.add(node.mData.ID);
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
return ret;
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
110 |
|
|
|
111 |
|
|
private void adjustNodeData(ArrayList<Long> oldList, ArrayList<Long> newList)
|
112 |
|
|
{
|
113 |
fee0865c
|
Leszek Koltunski
|
boolean otherNodesPoint = (mData.numPointingNodes>1);
|
114 |
|
|
|
115 |
|
|
if( otherNodesPoint ) mData.numPointingNodes--;
|
116 |
|
|
else mMapNodeID.remove(oldList);
|
117 |
1942537e
|
Leszek Koltunski
|
|
118 |
6a06a912
|
Leszek Koltunski
|
NodeData newData = mMapNodeID.get(newList);
|
119 |
|
|
|
120 |
|
|
if( newData==null )
|
121 |
|
|
{
|
122 |
fee0865c
|
Leszek Koltunski
|
if( otherNodesPoint ) mData = new NodeData(++mNextNodeID);
|
123 |
|
|
else mData.ID = ++mNextNodeID; // numPointingNodes must be 1 already
|
124 |
|
|
|
125 |
16d8b8f3
|
Leszek Koltunski
|
if( newList.size()>1 )
|
126 |
|
|
{
|
127 |
8c327653
|
Leszek Koltunski
|
if( mData.mFBO ==null )
|
128 |
|
|
mData.mFBO = new DistortedFramebuffer(mTexture.getWidth(), mTexture.getHeight());
|
129 |
16d8b8f3
|
Leszek Koltunski
|
}
|
130 |
|
|
else
|
131 |
|
|
{
|
132 |
8c327653
|
Leszek Koltunski
|
if( mData.mFBO !=null )
|
133 |
16d8b8f3
|
Leszek Koltunski
|
{
|
134 |
8c327653
|
Leszek Koltunski
|
mData.mFBO.markForDeletion();
|
135 |
|
|
mData.mFBO = null;
|
136 |
16d8b8f3
|
Leszek Koltunski
|
}
|
137 |
|
|
else
|
138 |
|
|
{
|
139 |
421c2728
|
Leszek Koltunski
|
android.util.Log.e("DistortedTree", "adjustNodeData: impossible situation??");
|
140 |
16d8b8f3
|
Leszek Koltunski
|
}
|
141 |
|
|
}
|
142 |
bd3da5b2
|
Leszek Koltunski
|
|
143 |
6a06a912
|
Leszek Koltunski
|
mMapNodeID.put(newList, mData);
|
144 |
|
|
}
|
145 |
|
|
else
|
146 |
fee0865c
|
Leszek Koltunski
|
{
|
147 |
6a06a912
|
Leszek Koltunski
|
newData.numPointingNodes++;
|
148 |
|
|
mData = newData;
|
149 |
|
|
}
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
153 |
|
|
// this will be called on startup and every time OpenGL context has been lost
|
154 |
d620ff06
|
Leszek Koltunski
|
|
155 |
6a06a912
|
Leszek Koltunski
|
static void reset()
|
156 |
|
|
{
|
157 |
|
|
NodeData tmp;
|
158 |
|
|
|
159 |
|
|
for(ArrayList<Long> key: mMapNodeID.keySet())
|
160 |
|
|
{
|
161 |
|
|
tmp = mMapNodeID.get(key);
|
162 |
|
|
|
163 |
02de77c9
|
Leszek Koltunski
|
if( tmp.mFBO != null ) tmp.numRendered = 0;
|
164 |
6a06a912
|
Leszek Koltunski
|
}
|
165 |
|
|
}
|
166 |
fee0865c
|
Leszek Koltunski
|
|
167 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
168 |
|
|
// Debug - print all the Node IDs
|
169 |
ab12f06b
|
Leszek Koltunski
|
/*
|
170 |
fee0865c
|
Leszek Koltunski
|
void debug(int depth)
|
171 |
|
|
{
|
172 |
|
|
String tmp="";
|
173 |
|
|
int i;
|
174 |
|
|
|
175 |
|
|
for(i=0; i<depth; i++) tmp +=" ";
|
176 |
1942537e
|
Leszek Koltunski
|
tmp += (mData.ID+" (nodes: "+mData.numPointingNodes+")");
|
177 |
fee0865c
|
Leszek Koltunski
|
|
178 |
1942537e
|
Leszek Koltunski
|
android.util.Log.e("NODE", tmp);
|
179 |
fee0865c
|
Leszek Koltunski
|
|
180 |
|
|
for(i=0; i<mNumChildren[0]; i++)
|
181 |
|
|
mChildren.get(i).debug(depth+1);
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
185 |
|
|
// Debug - print contents of the HashMap
|
186 |
|
|
|
187 |
|
|
static void debugMap()
|
188 |
|
|
{
|
189 |
|
|
NodeData tmp;
|
190 |
|
|
|
191 |
|
|
for(ArrayList<Long> key: mMapNodeID.keySet())
|
192 |
|
|
{
|
193 |
|
|
tmp = mMapNodeID.get(key);
|
194 |
|
|
|
195 |
|
|
android.util.Log.e("NODE", "key="+key+" NodeID: "+tmp.ID);
|
196 |
|
|
}
|
197 |
|
|
}
|
198 |
ab12f06b
|
Leszek Koltunski
|
*/
|
199 |
a0f644b7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
200 |
|
|
|
201 |
|
|
void drawRecursive(long currTime, DistortedFramebuffer df)
|
202 |
|
|
{
|
203 |
133cbb2b
|
Leszek Koltunski
|
mTexture.create();
|
204 |
|
|
float halfX = mTexture.getWidth()/2.0f;
|
205 |
|
|
float halfY = mTexture.getHeight()/2.0f;
|
206 |
a0f644b7
|
Leszek Koltunski
|
|
207 |
|
|
if( mNumChildren[0]<=0 )
|
208 |
|
|
{
|
209 |
e7a20702
|
Leszek Koltunski
|
mTexture.setAsInput();
|
210 |
a0f644b7
|
Leszek Koltunski
|
}
|
211 |
|
|
else
|
212 |
|
|
{
|
213 |
133cbb2b
|
Leszek Koltunski
|
mData.mFBO.create();
|
214 |
a0f644b7
|
Leszek Koltunski
|
|
215 |
|
|
if( mData.numRendered==0 )
|
216 |
|
|
{
|
217 |
8c327653
|
Leszek Koltunski
|
mData.mFBO.setAsOutput();
|
218 |
a0f644b7
|
Leszek Koltunski
|
|
219 |
194ab46f
|
Leszek Koltunski
|
GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
220 |
|
|
GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
|
221 |
a0f644b7
|
Leszek Koltunski
|
|
222 |
e7a20702
|
Leszek Koltunski
|
if( mTexture.setAsInput() )
|
223 |
133cbb2b
|
Leszek Koltunski
|
DistortedEffects.drawNoEffectsPriv(halfX, halfY, mMesh, mData.mFBO);
|
224 |
a0f644b7
|
Leszek Koltunski
|
|
225 |
|
|
synchronized(this)
|
226 |
|
|
{
|
227 |
|
|
for(int i=0; i<mNumChildren[0]; i++)
|
228 |
|
|
{
|
229 |
8c327653
|
Leszek Koltunski
|
mChildren.get(i).drawRecursive(currTime, mData.mFBO);
|
230 |
a0f644b7
|
Leszek Koltunski
|
}
|
231 |
|
|
}
|
232 |
|
|
}
|
233 |
|
|
|
234 |
|
|
mData.numRendered++;
|
235 |
|
|
mData.numRendered %= mData.numPointingNodes;
|
236 |
8c327653
|
Leszek Koltunski
|
mData.mFBO.setAsInput();
|
237 |
a0f644b7
|
Leszek Koltunski
|
}
|
238 |
|
|
|
239 |
133cbb2b
|
Leszek Koltunski
|
mEffects.drawPriv(halfX, halfY, mMesh, df, currTime);
|
240 |
a0f644b7
|
Leszek Koltunski
|
}
|
241 |
|
|
|
242 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
243 |
|
|
// PUBLIC API
|
244 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
245 |
|
|
/**
|
246 |
|
|
* Constructs new Node of the Tree.
|
247 |
|
|
*
|
248 |
4e2382f3
|
Leszek Koltunski
|
* @param texture DistortedTexture to put into the new Node.
|
249 |
07d8ef09
|
Leszek Koltunski
|
* @param effects DistortedEffects to put into the new Node.
|
250 |
05403bba
|
Leszek Koltunski
|
* @param mesh MeshObject to put into the new Node.
|
251 |
6a06a912
|
Leszek Koltunski
|
*/
|
252 |
05403bba
|
Leszek Koltunski
|
public DistortedTree(DistortedTexture texture, DistortedEffects effects, MeshObject mesh)
|
253 |
6a06a912
|
Leszek Koltunski
|
{
|
254 |
4e2382f3
|
Leszek Koltunski
|
mTexture= texture;
|
255 |
07d8ef09
|
Leszek Koltunski
|
mEffects= effects;
|
256 |
05403bba
|
Leszek Koltunski
|
mMesh = mesh;
|
257 |
6a06a912
|
Leszek Koltunski
|
mParent = null;
|
258 |
|
|
mChildren = null;
|
259 |
|
|
mNumChildren = new int[1];
|
260 |
|
|
mNumChildren[0] = 0;
|
261 |
|
|
|
262 |
9361b337
|
Leszek Koltunski
|
ArrayList<Long> list = new ArrayList<>();
|
263 |
1942537e
|
Leszek Koltunski
|
list.add(mTexture.getID());
|
264 |
|
|
|
265 |
6a06a912
|
Leszek Koltunski
|
mData = mMapNodeID.get(list);
|
266 |
|
|
|
267 |
|
|
if( mData!=null )
|
268 |
|
|
{
|
269 |
|
|
mData.numPointingNodes++;
|
270 |
|
|
}
|
271 |
|
|
else
|
272 |
|
|
{
|
273 |
|
|
mData = new NodeData(++mNextNodeID);
|
274 |
1942537e
|
Leszek Koltunski
|
mMapNodeID.put(list, mData);
|
275 |
6a06a912
|
Leszek Koltunski
|
}
|
276 |
|
|
}
|
277 |
|
|
|
278 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
279 |
|
|
/**
|
280 |
|
|
* Copy-constructs new Node of the Tree from another Node.
|
281 |
|
|
*
|
282 |
421c2728
|
Leszek Koltunski
|
* @param node The DistortedTree to copy data from.
|
283 |
6a06a912
|
Leszek Koltunski
|
* @param flags bit field composed of a subset of the following:
|
284 |
015642fb
|
Leszek Koltunski
|
* {@link Distorted#CLONE_BITMAP}, {@link Distorted#CLONE_MATRIX}, {@link Distorted#CLONE_VERTEX},
|
285 |
6a06a912
|
Leszek Koltunski
|
* {@link Distorted#CLONE_FRAGMENT} and {@link Distorted#CLONE_CHILDREN}.
|
286 |
|
|
* For example flags = CLONE_BITMAP | CLONE_CHILDREN.
|
287 |
|
|
*/
|
288 |
421c2728
|
Leszek Koltunski
|
public DistortedTree(DistortedTree node, int flags)
|
289 |
6a06a912
|
Leszek Koltunski
|
{
|
290 |
9361b337
|
Leszek Koltunski
|
mParent = null;
|
291 |
432442f9
|
Leszek Koltunski
|
mEffects= new DistortedEffects(node.mEffects,flags);
|
292 |
05403bba
|
Leszek Koltunski
|
mMesh = node.mMesh;
|
293 |
9361b337
|
Leszek Koltunski
|
|
294 |
e7a20702
|
Leszek Koltunski
|
if( (flags & Distorted.CLONE_BITMAP) != 0 )
|
295 |
|
|
{
|
296 |
|
|
mTexture = node.mTexture;
|
297 |
|
|
}
|
298 |
|
|
else
|
299 |
|
|
{
|
300 |
|
|
mTexture = new DistortedTexture(node.mTexture.getWidth(), node.mTexture.getHeight());
|
301 |
|
|
}
|
302 |
9361b337
|
Leszek Koltunski
|
if( (flags & Distorted.CLONE_CHILDREN) != 0 )
|
303 |
6a06a912
|
Leszek Koltunski
|
{
|
304 |
|
|
mChildren = node.mChildren;
|
305 |
|
|
mNumChildren = node.mNumChildren;
|
306 |
|
|
}
|
307 |
|
|
else
|
308 |
|
|
{
|
309 |
|
|
mChildren = null;
|
310 |
|
|
mNumChildren = new int[1];
|
311 |
|
|
mNumChildren[0] = 0;
|
312 |
|
|
}
|
313 |
|
|
|
314 |
|
|
ArrayList<Long> list = generateIDList();
|
315 |
|
|
|
316 |
|
|
mData = mMapNodeID.get(list);
|
317 |
|
|
|
318 |
|
|
if( mData!=null )
|
319 |
|
|
{
|
320 |
|
|
mData.numPointingNodes++;
|
321 |
|
|
}
|
322 |
|
|
else
|
323 |
|
|
{
|
324 |
|
|
mData = new NodeData(++mNextNodeID);
|
325 |
|
|
mMapNodeID.put(list, mData);
|
326 |
|
|
}
|
327 |
|
|
}
|
328 |
|
|
|
329 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
330 |
|
|
/**
|
331 |
|
|
* Adds a new child to the last position in the list of our Node's children.
|
332 |
|
|
*
|
333 |
|
|
* @param node The new Node to add.
|
334 |
|
|
*/
|
335 |
421c2728
|
Leszek Koltunski
|
public synchronized void attach(DistortedTree node)
|
336 |
6a06a912
|
Leszek Koltunski
|
{
|
337 |
|
|
ArrayList<Long> prev = generateIDList();
|
338 |
|
|
|
339 |
9361b337
|
Leszek Koltunski
|
if( mChildren==null ) mChildren = new ArrayList<>(2);
|
340 |
6a06a912
|
Leszek Koltunski
|
|
341 |
|
|
node.mParent = this;
|
342 |
|
|
mChildren.add(node);
|
343 |
|
|
mNumChildren[0]++;
|
344 |
|
|
|
345 |
|
|
RecomputeNodeID(prev);
|
346 |
|
|
}
|
347 |
|
|
|
348 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
349 |
|
|
/**
|
350 |
|
|
* Adds a new child to the last position in the list of our Node's children.
|
351 |
|
|
*
|
352 |
4e2382f3
|
Leszek Koltunski
|
* @param texture DistortedTexture to initialize our child Node with.
|
353 |
07d8ef09
|
Leszek Koltunski
|
* @param effects DistortedEffects to initialize our child Node with.
|
354 |
05403bba
|
Leszek Koltunski
|
* @param mesh MeshObject to initialize our child Node with.
|
355 |
6a06a912
|
Leszek Koltunski
|
* @return the newly constructed child Node, or null if we couldn't allocate resources.
|
356 |
|
|
*/
|
357 |
05403bba
|
Leszek Koltunski
|
public synchronized DistortedTree attach(DistortedTexture texture, DistortedEffects effects, MeshObject mesh)
|
358 |
6a06a912
|
Leszek Koltunski
|
{
|
359 |
|
|
ArrayList<Long> prev = generateIDList();
|
360 |
|
|
|
361 |
9361b337
|
Leszek Koltunski
|
if( mChildren==null ) mChildren = new ArrayList<>(2);
|
362 |
05403bba
|
Leszek Koltunski
|
DistortedTree node = new DistortedTree(texture,effects,mesh);
|
363 |
6a06a912
|
Leszek Koltunski
|
node.mParent = this;
|
364 |
|
|
mChildren.add(node);
|
365 |
|
|
mNumChildren[0]++;
|
366 |
|
|
|
367 |
|
|
RecomputeNodeID(prev);
|
368 |
fee0865c
|
Leszek Koltunski
|
|
369 |
6a06a912
|
Leszek Koltunski
|
return node;
|
370 |
|
|
}
|
371 |
|
|
|
372 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
373 |
|
|
/**
|
374 |
|
|
* Removes the first occurrence of a specified child from the list of children of our Node.
|
375 |
|
|
*
|
376 |
|
|
* @param node The Node to remove.
|
377 |
|
|
* @return <code>true</code> if the child was successfully removed.
|
378 |
|
|
*/
|
379 |
421c2728
|
Leszek Koltunski
|
public synchronized boolean detach(DistortedTree node)
|
380 |
6a06a912
|
Leszek Koltunski
|
{
|
381 |
|
|
if( mNumChildren[0]>0 )
|
382 |
|
|
{
|
383 |
|
|
ArrayList<Long> prev = generateIDList();
|
384 |
|
|
|
385 |
|
|
if( mChildren.remove(node) )
|
386 |
|
|
{
|
387 |
|
|
node.mParent = null;
|
388 |
|
|
mNumChildren[0]--;
|
389 |
|
|
|
390 |
|
|
RecomputeNodeID(prev);
|
391 |
|
|
|
392 |
|
|
return true;
|
393 |
|
|
}
|
394 |
|
|
}
|
395 |
|
|
|
396 |
|
|
return false;
|
397 |
|
|
}
|
398 |
|
|
|
399 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
400 |
|
|
/**
|
401 |
|
|
* Removes the first occurrence of a specified child from the list of children of our Node.
|
402 |
|
|
*
|
403 |
07d8ef09
|
Leszek Koltunski
|
* @param effects DistortedEffects to remove.
|
404 |
6a06a912
|
Leszek Koltunski
|
* @return <code>true</code> if the child was successfully removed.
|
405 |
|
|
*/
|
406 |
07d8ef09
|
Leszek Koltunski
|
public synchronized boolean detach(DistortedEffects effects)
|
407 |
6a06a912
|
Leszek Koltunski
|
{
|
408 |
07d8ef09
|
Leszek Koltunski
|
long id = effects.getID();
|
409 |
421c2728
|
Leszek Koltunski
|
DistortedTree node;
|
410 |
6a06a912
|
Leszek Koltunski
|
|
411 |
|
|
for(int i=0; i<mNumChildren[0]; i++)
|
412 |
|
|
{
|
413 |
|
|
node = mChildren.get(i);
|
414 |
|
|
|
415 |
07d8ef09
|
Leszek Koltunski
|
if( node.mEffects.getID()==id )
|
416 |
6a06a912
|
Leszek Koltunski
|
{
|
417 |
|
|
ArrayList<Long> prev = generateIDList();
|
418 |
|
|
|
419 |
|
|
node.mParent = null;
|
420 |
|
|
mChildren.remove(i);
|
421 |
|
|
mNumChildren[0]--;
|
422 |
|
|
|
423 |
|
|
RecomputeNodeID(prev);
|
424 |
|
|
|
425 |
|
|
return true;
|
426 |
|
|
}
|
427 |
|
|
}
|
428 |
|
|
|
429 |
|
|
return false;
|
430 |
|
|
}
|
431 |
|
|
|
432 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
433 |
|
|
/**
|
434 |
|
|
* Removes all children Nodes.
|
435 |
|
|
*/
|
436 |
|
|
public synchronized void detachAll()
|
437 |
|
|
{
|
438 |
|
|
for(int i=0; i<mNumChildren[0]; i++)
|
439 |
|
|
{
|
440 |
|
|
mChildren.get(i).mParent = null;
|
441 |
|
|
}
|
442 |
|
|
|
443 |
|
|
if( mNumChildren[0]>0 )
|
444 |
|
|
{
|
445 |
|
|
ArrayList<Long> prev = generateIDList();
|
446 |
|
|
|
447 |
|
|
mNumChildren[0] = 0;
|
448 |
|
|
mChildren.clear();
|
449 |
|
|
RecomputeNodeID(prev);
|
450 |
|
|
}
|
451 |
|
|
}
|
452 |
d1e740c5
|
Leszek Koltunski
|
|
453 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
454 |
|
|
/**
|
455 |
421c2728
|
Leszek Koltunski
|
* Returns the DistortedEffects object that's in the Node.
|
456 |
6a06a912
|
Leszek Koltunski
|
*
|
457 |
421c2728
|
Leszek Koltunski
|
* @return The DistortedEffects contained in the Node.
|
458 |
6a06a912
|
Leszek Koltunski
|
*/
|
459 |
421c2728
|
Leszek Koltunski
|
public DistortedEffects getEffects()
|
460 |
6a06a912
|
Leszek Koltunski
|
{
|
461 |
07d8ef09
|
Leszek Koltunski
|
return mEffects;
|
462 |
4e2382f3
|
Leszek Koltunski
|
}
|
463 |
|
|
|
464 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
465 |
|
|
/**
|
466 |
|
|
* Returns the DistortedTexture object that's in the Node.
|
467 |
|
|
*
|
468 |
|
|
* @return The DistortedTexture contained in the Node.
|
469 |
|
|
*/
|
470 |
|
|
public DistortedTexture getTexture()
|
471 |
|
|
{
|
472 |
|
|
return mTexture;
|
473 |
6a06a912
|
Leszek Koltunski
|
}
|
474 |
|
|
|
475 |
8c327653
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
476 |
|
|
/**
|
477 |
|
|
* Returns the DistortedFramebuffer object that's in the Node.
|
478 |
|
|
*
|
479 |
|
|
* @return The DistortedFramebuffer contained in the Node.
|
480 |
|
|
*/
|
481 |
|
|
public DistortedFramebuffer getFramebuffer()
|
482 |
|
|
{
|
483 |
|
|
return mData.mFBO;
|
484 |
|
|
}
|
485 |
6a06a912
|
Leszek Koltunski
|
|
486 |
8c327653
|
Leszek Koltunski
|
}
|