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 |
a09ada4c
|
Leszek Koltunski
|
* Class which represents a Node in a Tree of (InputSurface,Mesh,Effects) triplets.
|
30 |
c204c69d
|
leszek
|
* <p>
|
31 |
a09ada4c
|
Leszek Koltunski
|
* Having organized such sets into a Tree, we can then render any Node to any OutputSurface.
|
32 |
7b8086eb
|
Leszek Koltunski
|
* That recursively renders the set held in the Node and all its children.
|
33 |
c204c69d
|
leszek
|
* <p>
|
34 |
|
|
* The class takes special care to only render identical sub-trees once. Each Node holds a reference
|
35 |
|
|
* to sub-class 'NodeData'. Two identical sub-trees attached at different points of the main tree
|
36 |
|
|
* will point to the same NodeData; only the first of this is rendered (when mData.numRendered==0).
|
37 |
6a06a912
|
Leszek Koltunski
|
*/
|
38 |
c204c69d
|
leszek
|
public class DistortedNode implements DistortedAttacheable
|
39 |
6a06a912
|
Leszek Koltunski
|
{
|
40 |
bd3da5b2
|
Leszek Koltunski
|
private static HashMap<ArrayList<Long>,NodeData> mMapNodeID = new HashMap<>();
|
41 |
|
|
private static long mNextNodeID =0;
|
42 |
|
|
|
43 |
05403bba
|
Leszek Koltunski
|
private MeshObject mMesh;
|
44 |
07d8ef09
|
Leszek Koltunski
|
private DistortedEffects mEffects;
|
45 |
c5369f1b
|
leszek
|
private DistortedInputSurface mSurface;
|
46 |
6a06a912
|
Leszek Koltunski
|
private NodeData mData;
|
47 |
bd3da5b2
|
Leszek Koltunski
|
|
48 |
a09ada4c
|
Leszek Koltunski
|
private ArrayList<DistortedNode> mChildren;
|
49 |
6a06a912
|
Leszek Koltunski
|
private int[] mNumChildren; // ==mChildren.length(), but we only create mChildren if the first one gets added
|
50 |
|
|
|
51 |
|
|
private class NodeData
|
52 |
|
|
{
|
53 |
bd3da5b2
|
Leszek Koltunski
|
long ID;
|
54 |
6a06a912
|
Leszek Koltunski
|
int numPointingNodes;
|
55 |
7691a39f
|
leszek
|
int numRender;
|
56 |
af27df87
|
leszek
|
ArrayList<Long> key;
|
57 |
8c327653
|
Leszek Koltunski
|
DistortedFramebuffer mFBO;
|
58 |
6a06a912
|
Leszek Koltunski
|
|
59 |
af27df87
|
leszek
|
NodeData(long id, ArrayList<Long> k)
|
60 |
6a06a912
|
Leszek Koltunski
|
{
|
61 |
bd3da5b2
|
Leszek Koltunski
|
ID = id;
|
62 |
af27df87
|
leszek
|
key = k;
|
63 |
bd3da5b2
|
Leszek Koltunski
|
numPointingNodes= 1;
|
64 |
7691a39f
|
leszek
|
numRender =-1;
|
65 |
8c327653
|
Leszek Koltunski
|
mFBO = null;
|
66 |
6a06a912
|
Leszek Koltunski
|
}
|
67 |
bd3da5b2
|
Leszek Koltunski
|
}
|
68 |
6a06a912
|
Leszek Koltunski
|
|
69 |
436899f2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70 |
|
|
|
71 |
7b8086eb
|
Leszek Koltunski
|
static synchronized void onDestroy()
|
72 |
436899f2
|
Leszek Koltunski
|
{
|
73 |
|
|
mNextNodeID = 0;
|
74 |
|
|
mMapNodeID.clear();
|
75 |
|
|
}
|
76 |
|
|
|
77 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78 |
|
|
|
79 |
|
|
private ArrayList<Long> generateIDList()
|
80 |
|
|
{
|
81 |
9361b337
|
Leszek Koltunski
|
ArrayList<Long> ret = new ArrayList<>();
|
82 |
6a06a912
|
Leszek Koltunski
|
|
83 |
c5369f1b
|
leszek
|
ret.add( mSurface.getID() );
|
84 |
7691a39f
|
leszek
|
|
85 |
|
|
if( mNumChildren[0]==0 )
|
86 |
|
|
{
|
87 |
|
|
ret.add(-mEffects.getID());
|
88 |
|
|
}
|
89 |
|
|
|
90 |
a09ada4c
|
Leszek Koltunski
|
DistortedNode node;
|
91 |
6a06a912
|
Leszek Koltunski
|
|
92 |
|
|
for(int i=0; i<mNumChildren[0]; i++)
|
93 |
|
|
{
|
94 |
|
|
node = mChildren.get(i);
|
95 |
|
|
ret.add(node.mData.ID);
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
return ret;
|
99 |
|
|
}
|
100 |
|
|
|
101 |
fee0865c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102 |
|
|
// Debug - print all the Node IDs
|
103 |
c204c69d
|
leszek
|
|
104 |
af27df87
|
leszek
|
@SuppressWarnings("unused")
|
105 |
fee0865c
|
Leszek Koltunski
|
void debug(int depth)
|
106 |
|
|
{
|
107 |
|
|
String tmp="";
|
108 |
|
|
int i;
|
109 |
|
|
|
110 |
|
|
for(i=0; i<depth; i++) tmp +=" ";
|
111 |
c204c69d
|
leszek
|
tmp += ("NodeID="+mData.ID+" (nodes pointing: "+mData.numPointingNodes+" surfaceID="+mSurface.getID()+")");
|
112 |
fee0865c
|
Leszek Koltunski
|
|
113 |
1942537e
|
Leszek Koltunski
|
android.util.Log.e("NODE", tmp);
|
114 |
fee0865c
|
Leszek Koltunski
|
|
115 |
|
|
for(i=0; i<mNumChildren[0]; i++)
|
116 |
|
|
mChildren.get(i).debug(depth+1);
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120 |
|
|
// Debug - print contents of the HashMap
|
121 |
|
|
|
122 |
af27df87
|
leszek
|
@SuppressWarnings("unused")
|
123 |
fee0865c
|
Leszek Koltunski
|
static void debugMap()
|
124 |
|
|
{
|
125 |
|
|
NodeData tmp;
|
126 |
|
|
|
127 |
|
|
for(ArrayList<Long> key: mMapNodeID.keySet())
|
128 |
|
|
{
|
129 |
|
|
tmp = mMapNodeID.get(key);
|
130 |
c204c69d
|
leszek
|
android.util.Log.e("NODE", "NodeID: "+tmp.ID+" <-- "+key);
|
131 |
|
|
}
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
135 |
|
|
|
136 |
|
|
void treeIsomorphism()
|
137 |
|
|
{
|
138 |
|
|
for(int i=0; i<mNumChildren[0]; i++)
|
139 |
|
|
{
|
140 |
|
|
mChildren.get(i).treeIsomorphism();
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
ArrayList<Long> newList = generateIDList();
|
144 |
|
|
NodeData newData = mMapNodeID.get(newList);
|
145 |
|
|
|
146 |
|
|
if( newData==null )
|
147 |
|
|
{
|
148 |
af27df87
|
leszek
|
newData = new NodeData(++mNextNodeID,newList);
|
149 |
c204c69d
|
leszek
|
mMapNodeID.put(newList,newData);
|
150 |
|
|
}
|
151 |
|
|
else if( newData.ID != mData.ID )
|
152 |
|
|
{
|
153 |
|
|
newData.numPointingNodes++;
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
if( newData.ID != mData.ID )
|
157 |
|
|
{
|
158 |
|
|
boolean fboUsed = false;
|
159 |
|
|
|
160 |
|
|
if( mNumChildren[0]>0 && newData.mFBO==null )
|
161 |
|
|
{
|
162 |
|
|
if( mData.mFBO!=null )
|
163 |
|
|
{
|
164 |
af27df87
|
leszek
|
android.util.Log.d("NODE", "copying over FBO of node surfaceID="+mSurface.getID());
|
165 |
|
|
|
166 |
c204c69d
|
leszek
|
newData.mFBO = mData.mFBO;
|
167 |
|
|
fboUsed = true;
|
168 |
|
|
}
|
169 |
|
|
else
|
170 |
|
|
{
|
171 |
af27df87
|
leszek
|
android.util.Log.d("NODE", "creating new FBO of node surfaceID="+mSurface.getID());
|
172 |
c204c69d
|
leszek
|
newData.mFBO = new DistortedFramebuffer(mSurface.getWidth(),mSurface.getHeight());
|
173 |
|
|
}
|
174 |
|
|
}
|
175 |
|
|
if( mNumChildren[0]==0 && newData.mFBO!=null )
|
176 |
|
|
{
|
177 |
af27df87
|
leszek
|
android.util.Log.d("NODE", "deleting FBO of newData node!!");
|
178 |
|
|
|
179 |
|
|
|
180 |
c204c69d
|
leszek
|
newData.mFBO.markForDeletion();
|
181 |
|
|
newData.mFBO = null;
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
if( --mData.numPointingNodes==0 )
|
185 |
|
|
{
|
186 |
af27df87
|
leszek
|
mMapNodeID.remove(mData.key);
|
187 |
c204c69d
|
leszek
|
|
188 |
|
|
if( !fboUsed && mData.mFBO!=null )
|
189 |
|
|
{
|
190 |
af27df87
|
leszek
|
android.util.Log.d("NODE", "deleting FBO of node surfaceID="+mSurface.getID());
|
191 |
|
|
|
192 |
c204c69d
|
leszek
|
mData.mFBO.markForDeletion();
|
193 |
|
|
mData.mFBO = null;
|
194 |
|
|
}
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
mData = newData;
|
198 |
fee0865c
|
Leszek Koltunski
|
}
|
199 |
|
|
}
|
200 |
c204c69d
|
leszek
|
|
201 |
a0f644b7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
202 |
7691a39f
|
leszek
|
// return the total number of render calls issued
|
203 |
a0f644b7
|
Leszek Koltunski
|
|
204 |
7691a39f
|
leszek
|
int drawRecursive(int render, long currTime, DistortedOutputSurface surface)
|
205 |
a0f644b7
|
Leszek Koltunski
|
{
|
206 |
7691a39f
|
leszek
|
int ret = 0;
|
207 |
c5369f1b
|
leszek
|
float halfX = mSurface.getWidth()/2.0f;
|
208 |
|
|
float halfY = mSurface.getHeight()/2.0f;
|
209 |
a0f644b7
|
Leszek Koltunski
|
|
210 |
|
|
if( mNumChildren[0]<=0 )
|
211 |
|
|
{
|
212 |
c5369f1b
|
leszek
|
mSurface.setAsInput();
|
213 |
a0f644b7
|
Leszek Koltunski
|
}
|
214 |
|
|
else
|
215 |
|
|
{
|
216 |
7691a39f
|
leszek
|
if( mData.numRender!=render )
|
217 |
a0f644b7
|
Leszek Koltunski
|
{
|
218 |
7691a39f
|
leszek
|
mData.numRender = render;
|
219 |
8c327653
|
Leszek Koltunski
|
mData.mFBO.setAsOutput();
|
220 |
a0f644b7
|
Leszek Koltunski
|
|
221 |
194ab46f
|
Leszek Koltunski
|
GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
222 |
|
|
GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
|
223 |
a0f644b7
|
Leszek Koltunski
|
|
224 |
c5369f1b
|
leszek
|
if( mSurface.setAsInput() )
|
225 |
7691a39f
|
leszek
|
{
|
226 |
|
|
ret++;
|
227 |
|
|
DistortedEffects.drawNoEffectsPriv(halfX, halfY, mMesh, mData.mFBO);
|
228 |
|
|
}
|
229 |
a0f644b7
|
Leszek Koltunski
|
|
230 |
a09ada4c
|
Leszek Koltunski
|
for(int i=0; i<mNumChildren[0]; i++)
|
231 |
a0f644b7
|
Leszek Koltunski
|
{
|
232 |
7691a39f
|
leszek
|
ret += mChildren.get(i).drawRecursive(render, currTime, mData.mFBO);
|
233 |
a0f644b7
|
Leszek Koltunski
|
}
|
234 |
|
|
}
|
235 |
|
|
|
236 |
8c327653
|
Leszek Koltunski
|
mData.mFBO.setAsInput();
|
237 |
a0f644b7
|
Leszek Koltunski
|
}
|
238 |
|
|
|
239 |
c5369f1b
|
leszek
|
mEffects.drawPriv(halfX, halfY, mMesh, surface, currTime);
|
240 |
7691a39f
|
leszek
|
|
241 |
|
|
return ret+1;
|
242 |
a0f644b7
|
Leszek Koltunski
|
}
|
243 |
|
|
|
244 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
245 |
|
|
// PUBLIC API
|
246 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
247 |
|
|
/**
|
248 |
a09ada4c
|
Leszek Koltunski
|
* Constructs new Node.
|
249 |
6a06a912
|
Leszek Koltunski
|
*
|
250 |
c5369f1b
|
leszek
|
* @param surface InputSurface to put into the new Node.
|
251 |
07d8ef09
|
Leszek Koltunski
|
* @param effects DistortedEffects to put into the new Node.
|
252 |
05403bba
|
Leszek Koltunski
|
* @param mesh MeshObject to put into the new Node.
|
253 |
6a06a912
|
Leszek Koltunski
|
*/
|
254 |
a09ada4c
|
Leszek Koltunski
|
public DistortedNode(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
|
255 |
6a06a912
|
Leszek Koltunski
|
{
|
256 |
c5369f1b
|
leszek
|
mSurface = surface;
|
257 |
8ca9f899
|
Leszek Koltunski
|
mEffects = effects;
|
258 |
|
|
mMesh = mesh;
|
259 |
|
|
mChildren = null;
|
260 |
|
|
mNumChildren = new int[1];
|
261 |
|
|
mNumChildren[0]= 0;
|
262 |
6a06a912
|
Leszek Koltunski
|
|
263 |
9361b337
|
Leszek Koltunski
|
ArrayList<Long> list = new ArrayList<>();
|
264 |
c5369f1b
|
leszek
|
list.add(mSurface.getID());
|
265 |
7691a39f
|
leszek
|
list.add(-mEffects.getID());
|
266 |
1942537e
|
Leszek Koltunski
|
|
267 |
6a06a912
|
Leszek Koltunski
|
mData = mMapNodeID.get(list);
|
268 |
|
|
|
269 |
|
|
if( mData!=null )
|
270 |
|
|
{
|
271 |
|
|
mData.numPointingNodes++;
|
272 |
|
|
}
|
273 |
|
|
else
|
274 |
|
|
{
|
275 |
af27df87
|
leszek
|
mData = new NodeData(++mNextNodeID,list);
|
276 |
1942537e
|
Leszek Koltunski
|
mMapNodeID.put(list, mData);
|
277 |
6a06a912
|
Leszek Koltunski
|
}
|
278 |
|
|
}
|
279 |
|
|
|
280 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
281 |
|
|
/**
|
282 |
a09ada4c
|
Leszek Koltunski
|
* Copy-constructs new Node from another Node.
|
283 |
6a06a912
|
Leszek Koltunski
|
*
|
284 |
a09ada4c
|
Leszek Koltunski
|
* @param node The DistortedNode to copy data from.
|
285 |
6a06a912
|
Leszek Koltunski
|
* @param flags bit field composed of a subset of the following:
|
286 |
29a06526
|
Leszek Koltunski
|
* {@link Distorted#CLONE_SURFACE}, {@link Distorted#CLONE_MATRIX}, {@link Distorted#CLONE_VERTEX},
|
287 |
6a06a912
|
Leszek Koltunski
|
* {@link Distorted#CLONE_FRAGMENT} and {@link Distorted#CLONE_CHILDREN}.
|
288 |
29a06526
|
Leszek Koltunski
|
* For example flags = CLONE_SURFACE | CLONE_CHILDREN.
|
289 |
6a06a912
|
Leszek Koltunski
|
*/
|
290 |
a09ada4c
|
Leszek Koltunski
|
public DistortedNode(DistortedNode node, int flags)
|
291 |
6a06a912
|
Leszek Koltunski
|
{
|
292 |
432442f9
|
Leszek Koltunski
|
mEffects= new DistortedEffects(node.mEffects,flags);
|
293 |
05403bba
|
Leszek Koltunski
|
mMesh = node.mMesh;
|
294 |
9361b337
|
Leszek Koltunski
|
|
295 |
29a06526
|
Leszek Koltunski
|
if( (flags & Distorted.CLONE_SURFACE) != 0 )
|
296 |
e7a20702
|
Leszek Koltunski
|
{
|
297 |
c5369f1b
|
leszek
|
mSurface = node.mSurface;
|
298 |
e7a20702
|
Leszek Koltunski
|
}
|
299 |
|
|
else
|
300 |
|
|
{
|
301 |
c5369f1b
|
leszek
|
int w = node.mSurface.getWidth();
|
302 |
|
|
int h = node.mSurface.getHeight();
|
303 |
8ca9f899
|
Leszek Koltunski
|
|
304 |
c5369f1b
|
leszek
|
if( node.mSurface instanceof DistortedTexture )
|
305 |
8ca9f899
|
Leszek Koltunski
|
{
|
306 |
c5369f1b
|
leszek
|
mSurface = new DistortedTexture(w,h);
|
307 |
8ca9f899
|
Leszek Koltunski
|
}
|
308 |
c5369f1b
|
leszek
|
else if( node.mSurface instanceof DistortedFramebuffer )
|
309 |
8ca9f899
|
Leszek Koltunski
|
{
|
310 |
c5369f1b
|
leszek
|
boolean hasDepth = ((DistortedFramebuffer) node.mSurface).hasDepth();
|
311 |
|
|
mSurface = new DistortedFramebuffer(w,h,hasDepth);
|
312 |
8ca9f899
|
Leszek Koltunski
|
}
|
313 |
e7a20702
|
Leszek Koltunski
|
}
|
314 |
9361b337
|
Leszek Koltunski
|
if( (flags & Distorted.CLONE_CHILDREN) != 0 )
|
315 |
6a06a912
|
Leszek Koltunski
|
{
|
316 |
c204c69d
|
leszek
|
if( node.mChildren==null ) // do NOT copy over the NULL!
|
317 |
|
|
{
|
318 |
|
|
node.mChildren = new ArrayList<>(2);
|
319 |
|
|
}
|
320 |
|
|
|
321 |
6a06a912
|
Leszek Koltunski
|
mChildren = node.mChildren;
|
322 |
|
|
mNumChildren = node.mNumChildren;
|
323 |
|
|
}
|
324 |
|
|
else
|
325 |
|
|
{
|
326 |
|
|
mChildren = null;
|
327 |
|
|
mNumChildren = new int[1];
|
328 |
|
|
mNumChildren[0] = 0;
|
329 |
|
|
}
|
330 |
|
|
|
331 |
|
|
ArrayList<Long> list = generateIDList();
|
332 |
|
|
|
333 |
|
|
mData = mMapNodeID.get(list);
|
334 |
|
|
|
335 |
|
|
if( mData!=null )
|
336 |
|
|
{
|
337 |
|
|
mData.numPointingNodes++;
|
338 |
|
|
}
|
339 |
|
|
else
|
340 |
|
|
{
|
341 |
af27df87
|
leszek
|
mData = new NodeData(++mNextNodeID,list);
|
342 |
6a06a912
|
Leszek Koltunski
|
mMapNodeID.put(list, mData);
|
343 |
|
|
}
|
344 |
|
|
}
|
345 |
c204c69d
|
leszek
|
|
346 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
347 |
|
|
/**
|
348 |
|
|
* Adds a new child to the last position in the list of our Node's children.
|
349 |
c204c69d
|
leszek
|
* <p>
|
350 |
|
|
* We cannot do this mid-render - actual attachment will be done just before the next render, by the
|
351 |
|
|
* DistortedAttachDeamon (by calling attachNow())
|
352 |
|
|
*
|
353 |
6a06a912
|
Leszek Koltunski
|
* @param node The new Node to add.
|
354 |
|
|
*/
|
355 |
c204c69d
|
leszek
|
public void attach(DistortedNode node)
|
356 |
6a06a912
|
Leszek Koltunski
|
{
|
357 |
c204c69d
|
leszek
|
DistortedAttachDaemon.attach(this,node);
|
358 |
6a06a912
|
Leszek Koltunski
|
}
|
359 |
c204c69d
|
leszek
|
|
360 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
361 |
|
|
/**
|
362 |
|
|
* Adds a new child to the last position in the list of our Node's children.
|
363 |
c204c69d
|
leszek
|
* <p>
|
364 |
|
|
* We cannot do this mid-render - actual attachment will be done just before the next render, by the
|
365 |
|
|
* DistortedAttachDeamon (by calling attachNow())
|
366 |
|
|
*
|
367 |
c5369f1b
|
leszek
|
* @param surface InputSurface to initialize our child Node with.
|
368 |
07d8ef09
|
Leszek Koltunski
|
* @param effects DistortedEffects to initialize our child Node with.
|
369 |
05403bba
|
Leszek Koltunski
|
* @param mesh MeshObject to initialize our child Node with.
|
370 |
6a06a912
|
Leszek Koltunski
|
* @return the newly constructed child Node, or null if we couldn't allocate resources.
|
371 |
|
|
*/
|
372 |
c204c69d
|
leszek
|
public DistortedNode attach(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
|
373 |
6a06a912
|
Leszek Koltunski
|
{
|
374 |
c204c69d
|
leszek
|
DistortedNode node = new DistortedNode(surface,effects,mesh);
|
375 |
|
|
DistortedAttachDaemon.attach(this,node);
|
376 |
|
|
return node;
|
377 |
|
|
}
|
378 |
f8377ef8
|
leszek
|
|
379 |
c204c69d
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
380 |
|
|
/**
|
381 |
|
|
* This is not really part of the public API. Has to be public only because it is a part of the
|
382 |
|
|
* DistortedAttacheable interface, which should really be a class that we extend here instead but
|
383 |
|
|
* Java has no multiple inheritance.
|
384 |
|
|
*
|
385 |
|
|
* @param node The new Node to add.
|
386 |
|
|
*/
|
387 |
|
|
public void attachNow(DistortedNode node)
|
388 |
|
|
{
|
389 |
9361b337
|
Leszek Koltunski
|
if( mChildren==null ) mChildren = new ArrayList<>(2);
|
390 |
c204c69d
|
leszek
|
|
391 |
6a06a912
|
Leszek Koltunski
|
mChildren.add(node);
|
392 |
|
|
mNumChildren[0]++;
|
393 |
|
|
}
|
394 |
c204c69d
|
leszek
|
|
395 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
396 |
|
|
/**
|
397 |
|
|
* Removes the first occurrence of a specified child from the list of children of our Node.
|
398 |
c204c69d
|
leszek
|
* <p>
|
399 |
|
|
* We cannot do this mid-render - actual detachment will be done just before the next render, by the
|
400 |
|
|
* DistortedAttachDeamon (by calling detachNow())
|
401 |
|
|
*
|
402 |
6a06a912
|
Leszek Koltunski
|
* @param node The Node to remove.
|
403 |
|
|
*/
|
404 |
c204c69d
|
leszek
|
public void detach(DistortedNode node)
|
405 |
6a06a912
|
Leszek Koltunski
|
{
|
406 |
c204c69d
|
leszek
|
DistortedAttachDaemon.detach(this,node);
|
407 |
6a06a912
|
Leszek Koltunski
|
}
|
408 |
a09ada4c
|
Leszek Koltunski
|
|
409 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
410 |
|
|
/**
|
411 |
|
|
* Removes the first occurrence of a specified child from the list of children of our Node.
|
412 |
a09ada4c
|
Leszek Koltunski
|
* <p>
|
413 |
|
|
* A bit questionable method as there can be many different Nodes attached as children, some
|
414 |
|
|
* of them having the same Effects but - for instance - different Mesh. Use with care.
|
415 |
c204c69d
|
leszek
|
* <p>
|
416 |
|
|
* We cannot do this mid-render - actual detachment will be done just before the next render, by the
|
417 |
|
|
* DistortedAttachDeamon (by calling detachNow())
|
418 |
a09ada4c
|
Leszek Koltunski
|
*
|
419 |
07d8ef09
|
Leszek Koltunski
|
* @param effects DistortedEffects to remove.
|
420 |
6a06a912
|
Leszek Koltunski
|
*/
|
421 |
c204c69d
|
leszek
|
public void detach(DistortedEffects effects)
|
422 |
6a06a912
|
Leszek Koltunski
|
{
|
423 |
07d8ef09
|
Leszek Koltunski
|
long id = effects.getID();
|
424 |
a09ada4c
|
Leszek Koltunski
|
DistortedNode node;
|
425 |
|
|
|
426 |
6a06a912
|
Leszek Koltunski
|
for(int i=0; i<mNumChildren[0]; i++)
|
427 |
|
|
{
|
428 |
|
|
node = mChildren.get(i);
|
429 |
a09ada4c
|
Leszek Koltunski
|
|
430 |
07d8ef09
|
Leszek Koltunski
|
if( node.mEffects.getID()==id )
|
431 |
6a06a912
|
Leszek Koltunski
|
{
|
432 |
c204c69d
|
leszek
|
DistortedAttachDaemon.detach(this,node);
|
433 |
|
|
break;
|
434 |
6a06a912
|
Leszek Koltunski
|
}
|
435 |
|
|
}
|
436 |
|
|
}
|
437 |
a09ada4c
|
Leszek Koltunski
|
|
438 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
439 |
|
|
/**
|
440 |
c204c69d
|
leszek
|
* This is not really part of the public API. Has to be public only because it is a part of the
|
441 |
|
|
* DistortedAttacheable interface, which should really be a class that we extend here instead but
|
442 |
|
|
* Java has no multiple inheritance.
|
443 |
|
|
*
|
444 |
|
|
* @param node The Node to remove.
|
445 |
6a06a912
|
Leszek Koltunski
|
*/
|
446 |
c204c69d
|
leszek
|
public void detachNow(DistortedNode node)
|
447 |
6a06a912
|
Leszek Koltunski
|
{
|
448 |
c204c69d
|
leszek
|
if( mNumChildren[0]>0 && mChildren.remove(node) )
|
449 |
6a06a912
|
Leszek Koltunski
|
{
|
450 |
c204c69d
|
leszek
|
mNumChildren[0]--;
|
451 |
af27df87
|
leszek
|
|
452 |
|
|
if( mNumChildren[0]==0 && mData.mFBO!=null )
|
453 |
|
|
{
|
454 |
|
|
mData.mFBO.markForDeletion();
|
455 |
|
|
mData.mFBO = null;
|
456 |
|
|
}
|
457 |
6a06a912
|
Leszek Koltunski
|
}
|
458 |
c204c69d
|
leszek
|
}
|
459 |
|
|
|
460 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
461 |
|
|
/**
|
462 |
|
|
* Removes all children Nodes.
|
463 |
|
|
* <p>
|
464 |
|
|
* We cannot do this mid-render - actual detachment will be done just before the next render, by the
|
465 |
|
|
* DistortedAttachDeamon (by calling detachAllNow())
|
466 |
|
|
*/
|
467 |
|
|
public void detachAll()
|
468 |
|
|
{
|
469 |
|
|
DistortedAttachDaemon.detachAll(this);
|
470 |
|
|
}
|
471 |
|
|
|
472 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
473 |
|
|
/**
|
474 |
|
|
* This is not really part of the public API. Has to be public only because it is a part of the
|
475 |
|
|
* DistortedAttacheable interface, which should really be a class that we extend here instead but
|
476 |
|
|
* Java has no multiple inheritance.
|
477 |
|
|
*/
|
478 |
|
|
public void detachAllNow()
|
479 |
|
|
{
|
480 |
6a06a912
|
Leszek Koltunski
|
if( mNumChildren[0]>0 )
|
481 |
|
|
{
|
482 |
|
|
mNumChildren[0] = 0;
|
483 |
|
|
mChildren.clear();
|
484 |
af27df87
|
leszek
|
|
485 |
|
|
if( mData.mFBO!=null )
|
486 |
|
|
{
|
487 |
|
|
mData.mFBO.markForDeletion();
|
488 |
|
|
mData.mFBO = null;
|
489 |
|
|
}
|
490 |
6a06a912
|
Leszek Koltunski
|
}
|
491 |
|
|
}
|
492 |
d1e740c5
|
Leszek Koltunski
|
|
493 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
494 |
|
|
/**
|
495 |
421c2728
|
Leszek Koltunski
|
* Returns the DistortedEffects object that's in the Node.
|
496 |
6a06a912
|
Leszek Koltunski
|
*
|
497 |
421c2728
|
Leszek Koltunski
|
* @return The DistortedEffects contained in the Node.
|
498 |
6a06a912
|
Leszek Koltunski
|
*/
|
499 |
421c2728
|
Leszek Koltunski
|
public DistortedEffects getEffects()
|
500 |
6a06a912
|
Leszek Koltunski
|
{
|
501 |
07d8ef09
|
Leszek Koltunski
|
return mEffects;
|
502 |
4e2382f3
|
Leszek Koltunski
|
}
|
503 |
|
|
|
504 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
505 |
|
|
/**
|
506 |
c5369f1b
|
leszek
|
* Returns the DistortedInputSurface object that's in the Node.
|
507 |
4e2382f3
|
Leszek Koltunski
|
*
|
508 |
c5369f1b
|
leszek
|
* @return The DistortedInputSurface contained in the Node.
|
509 |
4e2382f3
|
Leszek Koltunski
|
*/
|
510 |
c5369f1b
|
leszek
|
public DistortedInputSurface getSurface()
|
511 |
4e2382f3
|
Leszek Koltunski
|
{
|
512 |
c5369f1b
|
leszek
|
return mSurface;
|
513 |
6a06a912
|
Leszek Koltunski
|
}
|
514 |
|
|
|
515 |
8c327653
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
516 |
|
|
/**
|
517 |
|
|
* Returns the DistortedFramebuffer object that's in the Node.
|
518 |
|
|
*
|
519 |
|
|
* @return The DistortedFramebuffer contained in the Node.
|
520 |
|
|
*/
|
521 |
|
|
public DistortedFramebuffer getFramebuffer()
|
522 |
|
|
{
|
523 |
|
|
return mData.mFBO;
|
524 |
|
|
}
|
525 |
6a06a912
|
Leszek Koltunski
|
|
526 |
8c327653
|
Leszek Koltunski
|
}
|