Project

General

Profile

Download (22.4 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / DistortedNode.java @ 13687207

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 3a70bd6d leszek
 * will point to the same NodeData; only the first of this is rendered (mData.numRender!).
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 f28fffc2 Leszek Koltunski
  private DistortedNode mParent;
44 05403bba Leszek Koltunski
  private MeshObject mMesh;
45 07d8ef09 Leszek Koltunski
  private DistortedEffects mEffects;
46 13687207 leszek
  private DistortedEffectsPostprocess mPostprocess;
47 c5369f1b leszek
  private DistortedInputSurface mSurface;
48 c834348d leszek
  private DistortedRenderState mState;
49 6a06a912 Leszek Koltunski
  private NodeData mData;
50 bd3da5b2 Leszek Koltunski
51 a09ada4c Leszek Koltunski
  private ArrayList<DistortedNode> mChildren;
52 6a06a912 Leszek Koltunski
  private int[] mNumChildren;  // ==mChildren.length(), but we only create mChildren if the first one gets added
53
54
  private class NodeData
55
    {
56 bd3da5b2 Leszek Koltunski
    long ID;
57 6a06a912 Leszek Koltunski
    int numPointingNodes;
58 50642a86 Leszek Koltunski
    long currTime;
59 af27df87 leszek
    ArrayList<Long> key;
60 8c327653 Leszek Koltunski
    DistortedFramebuffer mFBO;
61 6a06a912 Leszek Koltunski
62 af27df87 leszek
    NodeData(long id, ArrayList<Long> k)
63 6a06a912 Leszek Koltunski
      {
64 bd3da5b2 Leszek Koltunski
      ID              = id;
65 af27df87 leszek
      key             = k;
66 bd3da5b2 Leszek Koltunski
      numPointingNodes= 1;
67 50642a86 Leszek Koltunski
      currTime        =-1;
68 8c327653 Leszek Koltunski
      mFBO            = null;
69 6a06a912 Leszek Koltunski
      }
70 bd3da5b2 Leszek Koltunski
    }
71 6a06a912 Leszek Koltunski
 
72 436899f2 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
73
74 7b8086eb Leszek Koltunski
  static synchronized void onDestroy()
75 436899f2 Leszek Koltunski
    {
76
    mNextNodeID = 0;
77
    mMapNodeID.clear();
78
    }
79
80 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
81
82
  private ArrayList<Long> generateIDList()
83
    {
84 9361b337 Leszek Koltunski
    ArrayList<Long> ret = new ArrayList<>();
85 6a06a912 Leszek Koltunski
     
86 c5369f1b leszek
    ret.add( mSurface.getID() );
87 7691a39f leszek
88
    if( mNumChildren[0]==0 )
89
      {
90
      ret.add(-mEffects.getID());
91
      }
92
93 a09ada4c Leszek Koltunski
    DistortedNode node;
94 6a06a912 Leszek Koltunski
   
95
    for(int i=0; i<mNumChildren[0]; i++)
96
      {
97
      node = mChildren.get(i);
98
      ret.add(node.mData.ID);
99
      }
100
   
101
    return ret;
102
    }
103
104 fee0865c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
105
// Debug - print all the Node IDs
106 c204c69d leszek
107 af27df87 leszek
  @SuppressWarnings("unused")
108 fee0865c Leszek Koltunski
  void debug(int depth)
109
    {
110
    String tmp="";
111
    int i;
112
113
    for(i=0; i<depth; i++) tmp +="   ";
114 07037b8a leszek
    tmp += ("NodeID="+mData.ID+" nodes pointing: "+mData.numPointingNodes+" surfaceID="+
115 f28fffc2 Leszek Koltunski
            mSurface.getID()+" FBO="+(mData.mFBO==null ? "null":mData.mFBO.getID()))+
116
            " parent sID="+(mParent==null ? "null": (mParent.mSurface.getID()));
117 fee0865c Leszek Koltunski
118 1942537e Leszek Koltunski
    android.util.Log.e("NODE", tmp);
119 fee0865c Leszek Koltunski
120
    for(i=0; i<mNumChildren[0]; i++)
121
      mChildren.get(i).debug(depth+1);
122
    }
123
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125
// Debug - print contents of the HashMap
126
127 af27df87 leszek
  @SuppressWarnings("unused")
128 fee0865c Leszek Koltunski
  static void debugMap()
129
    {
130
    NodeData tmp;
131
132
    for(ArrayList<Long> key: mMapNodeID.keySet())
133
      {
134
      tmp = mMapNodeID.get(key);
135 c204c69d leszek
      android.util.Log.e("NODE", "NodeID: "+tmp.ID+" <-- "+key);
136
      }
137
    }
138
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140 f28fffc2 Leszek Koltunski
// tree isomorphism algorithm
141 c204c69d leszek
142 f28fffc2 Leszek Koltunski
  private void adjustIsomorphism()
143 c204c69d leszek
    {
144
    ArrayList<Long> newList = generateIDList();
145
    NodeData newData = mMapNodeID.get(newList);
146
147 f28fffc2 Leszek Koltunski
    if( newData!=null )
148
      {
149
      newData.numPointingNodes++;
150
      }
151
    else
152 c204c69d leszek
      {
153 af27df87 leszek
      newData = new NodeData(++mNextNodeID,newList);
154 c204c69d leszek
      mMapNodeID.put(newList,newData);
155
      }
156 07037b8a leszek
157 f28fffc2 Leszek Koltunski
    boolean deleteOldFBO = false;
158
    boolean createNewFBO = false;
159 c204c69d leszek
160 f28fffc2 Leszek Koltunski
    if( --mData.numPointingNodes==0 )
161 c204c69d leszek
      {
162 f28fffc2 Leszek Koltunski
      mMapNodeID.remove(mData.key);
163
      if( mData.mFBO!=null ) deleteOldFBO=true;
164
      }
165
    if( mNumChildren[0]>0 && newData.mFBO==null )
166
      {
167
      createNewFBO = true;
168
      }
169
    if( mNumChildren[0]==0 && newData.mFBO!=null )
170
      {
171
      newData.mFBO.markForDeletion();
172
      android.util.Log.d("NODE", "ERROR!! this NodeData cannot possibly contain a non-null FBO!! "+newData.mFBO.getID() );
173
      newData.mFBO = null;
174
      }
175 c204c69d leszek
176 f28fffc2 Leszek Koltunski
    if( deleteOldFBO && createNewFBO )
177
      {
178
      newData.mFBO = mData.mFBO;  // just copy over
179 eadf0859 leszek
      //android.util.Log.d("NODE", "copying over FBOs "+mData.mFBO.getID() );
180 f28fffc2 Leszek Koltunski
      }
181
    else if( deleteOldFBO )
182
      {
183
      mData.mFBO.markForDeletion();
184 eadf0859 leszek
      //android.util.Log.d("NODE", "deleting old FBO "+mData.mFBO.getID() );
185 f28fffc2 Leszek Koltunski
      mData.mFBO = null;
186
      }
187
    else if( createNewFBO )
188
      {
189
      newData.mFBO = new DistortedFramebuffer(true, DistortedSurface.TYPE_TREE, mSurface.getWidth(),mSurface.getHeight());
190 eadf0859 leszek
      //android.util.Log.d("NODE", "creating new FBO "+newData.mFBO.getID() );
191 f28fffc2 Leszek Koltunski
      }
192 af27df87 leszek
193 f28fffc2 Leszek Koltunski
    mData = newData;
194 c204c69d leszek
195 f28fffc2 Leszek Koltunski
    if( mParent!=null ) mParent.adjustIsomorphism();
196 fee0865c Leszek Koltunski
    }
197 c204c69d leszek
198 39086ebb leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
199
// return the total number of render calls issued
200
201
  int draw(long currTime, DistortedOutputSurface surface)
202
    {
203
    DistortedInputSurface input = mNumChildren[0]==0 ? mSurface : mData.mFBO;
204
205
    if( input.setAsInput() )
206
      {
207
      mState.apply();
208
      mEffects.drawPriv(mSurface.getWidth()/2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime);
209
      return 1;
210
      }
211
212
    return 0;
213
    }
214
215 b9798977 leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
216
217 60c1c622 leszek
  EffectQueuePostprocess getPostprocess()
218 b9798977 leszek
    {
219 13687207 leszek
    return mPostprocess==null ? null : mPostprocess.getPostprocess();
220 b9798977 leszek
    }
221
222 39086ebb leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
223
// return the total number of render calls issued
224
225
  int renderRecursive(long currTime)
226
    {
227
    int numRenders = 0;
228
229
    if( mNumChildren[0]>0 && mData.currTime!=currTime )
230
      {
231
      mData.currTime = currTime;
232
233
      for (int i=0; i<mNumChildren[0]; i++)
234
        {
235
        numRenders += mChildren.get(i).renderRecursive(currTime);
236
        }
237
238 95c441a2 leszek
      mData.mFBO.setAsOutput(currTime);
239 39086ebb leszek
240
      if( mSurface.setAsInput() )
241
        {
242
        numRenders++;
243
        DistortedEffects.blitPriv(mData.mFBO);
244
        }
245
246 b2939df4 Leszek Koltunski
      numRenders += mData.mFBO.renderChildren(currTime,mNumChildren[0],mChildren);
247 39086ebb leszek
      }
248
249
    return numRenders;
250
    }
251
252 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
253
// PUBLIC API
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255
/**
256 a09ada4c Leszek Koltunski
 * Constructs new Node.
257 6a06a912 Leszek Koltunski
 *     
258 c5369f1b leszek
 * @param surface InputSurface to put into the new Node.
259 07d8ef09 Leszek Koltunski
 * @param effects DistortedEffects to put into the new Node.
260 05403bba Leszek Koltunski
 * @param mesh MeshObject to put into the new Node.
261 6a06a912 Leszek Koltunski
 */
262 a09ada4c Leszek Koltunski
  public DistortedNode(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
263 6a06a912 Leszek Koltunski
    {
264 c5369f1b leszek
    mSurface       = surface;
265 8ca9f899 Leszek Koltunski
    mEffects       = effects;
266 13687207 leszek
    mPostprocess   = null;
267 8ca9f899 Leszek Koltunski
    mMesh          = mesh;
268 c834348d leszek
    mState         = new DistortedRenderState();
269 8ca9f899 Leszek Koltunski
    mChildren      = null;
270
    mNumChildren   = new int[1];
271
    mNumChildren[0]= 0;
272 f28fffc2 Leszek Koltunski
    mParent        = null;
273
274 9361b337 Leszek Koltunski
    ArrayList<Long> list = new ArrayList<>();
275 c5369f1b leszek
    list.add(mSurface.getID());
276 7691a39f leszek
    list.add(-mEffects.getID());
277 1942537e Leszek Koltunski
278 6a06a912 Leszek Koltunski
    mData = mMapNodeID.get(list);
279
   
280
    if( mData!=null )
281
      {
282
      mData.numPointingNodes++;
283
      }
284
    else
285
      {
286 af27df87 leszek
      mData = new NodeData(++mNextNodeID,list);
287 1942537e Leszek Koltunski
      mMapNodeID.put(list, mData);
288 6a06a912 Leszek Koltunski
      }
289
    }
290
291
///////////////////////////////////////////////////////////////////////////////////////////////////  
292
/**
293 a09ada4c Leszek Koltunski
 * Copy-constructs new Node from another Node.
294 6a06a912 Leszek Koltunski
 *     
295 a09ada4c Leszek Koltunski
 * @param node The DistortedNode to copy data from.
296 6a06a912 Leszek Koltunski
 * @param flags bit field composed of a subset of the following:
297 29a06526 Leszek Koltunski
 *        {@link Distorted#CLONE_SURFACE},  {@link Distorted#CLONE_MATRIX}, {@link Distorted#CLONE_VERTEX},
298 6a06a912 Leszek Koltunski
 *        {@link Distorted#CLONE_FRAGMENT} and {@link Distorted#CLONE_CHILDREN}.
299 29a06526 Leszek Koltunski
 *        For example flags = CLONE_SURFACE | CLONE_CHILDREN.
300 6a06a912 Leszek Koltunski
 */
301 a09ada4c Leszek Koltunski
  public DistortedNode(DistortedNode node, int flags)
302 6a06a912 Leszek Koltunski
    {
303 13687207 leszek
    mEffects     = new DistortedEffects(node.mEffects,flags);
304
    mPostprocess = null;
305
    mMesh        = node.mMesh;
306
    mState       = new DistortedRenderState();
307
    mParent      = null;
308 9361b337 Leszek Koltunski
309 29a06526 Leszek Koltunski
    if( (flags & Distorted.CLONE_SURFACE) != 0 )
310 e7a20702 Leszek Koltunski
      {
311 c5369f1b leszek
      mSurface = node.mSurface;
312 e7a20702 Leszek Koltunski
      }
313
    else
314
      {
315 c5369f1b leszek
      int w = node.mSurface.getWidth();
316
      int h = node.mSurface.getHeight();
317 8ca9f899 Leszek Koltunski
318 c5369f1b leszek
      if( node.mSurface instanceof DistortedTexture )
319 8ca9f899 Leszek Koltunski
        {
320 09ab7524 Leszek Koltunski
        mSurface = new DistortedTexture(w,h, DistortedSurface.TYPE_TREE);
321 8ca9f899 Leszek Koltunski
        }
322 c5369f1b leszek
      else if( node.mSurface instanceof DistortedFramebuffer )
323 8ca9f899 Leszek Koltunski
        {
324 c5369f1b leszek
        boolean hasDepth = ((DistortedFramebuffer) node.mSurface).hasDepth();
325 09ab7524 Leszek Koltunski
        mSurface = new DistortedFramebuffer(hasDepth,DistortedSurface.TYPE_TREE,w,h);
326 8ca9f899 Leszek Koltunski
        }
327 e7a20702 Leszek Koltunski
      }
328 9361b337 Leszek Koltunski
    if( (flags & Distorted.CLONE_CHILDREN) != 0 )
329 6a06a912 Leszek Koltunski
      {
330 c204c69d leszek
      if( node.mChildren==null )     // do NOT copy over the NULL!
331
        {
332
        node.mChildren = new ArrayList<>(2);
333
        }
334
335 6a06a912 Leszek Koltunski
      mChildren = node.mChildren;
336
      mNumChildren = node.mNumChildren;
337
      }
338
    else
339
      {
340
      mChildren = null;
341
      mNumChildren = new int[1];
342
      mNumChildren[0] = 0;
343
      }
344
   
345
    ArrayList<Long> list = generateIDList();
346
   
347
    mData = mMapNodeID.get(list);
348
   
349
    if( mData!=null )
350
      {
351
      mData.numPointingNodes++;
352
      }
353
    else
354
      {
355 af27df87 leszek
      mData = new NodeData(++mNextNodeID,list);
356 6a06a912 Leszek Koltunski
      mMapNodeID.put(list, mData);
357
      }
358
    }
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 6a06a912 Leszek Koltunski
 * @param node The new Node to add.
368
 */
369 c204c69d leszek
  public void attach(DistortedNode node)
370 6a06a912 Leszek Koltunski
    {
371 c204c69d leszek
    DistortedAttachDaemon.attach(this,node);
372 6a06a912 Leszek Koltunski
    }
373 c204c69d leszek
374 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
375
/**
376
 * Adds a new child to the last position in the list of our Node's children.
377 c204c69d leszek
 * <p>
378
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
379
 * DistortedAttachDeamon (by calling attachNow())
380
 *
381 c5369f1b leszek
 * @param surface InputSurface to initialize our child Node with.
382 07d8ef09 Leszek Koltunski
 * @param effects DistortedEffects to initialize our child Node with.
383 05403bba Leszek Koltunski
 * @param mesh MeshObject to initialize our child Node with.
384 6a06a912 Leszek Koltunski
 * @return the newly constructed child Node, or null if we couldn't allocate resources.
385
 */
386 c204c69d leszek
  public DistortedNode attach(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
387 6a06a912 Leszek Koltunski
    {
388 c204c69d leszek
    DistortedNode node = new DistortedNode(surface,effects,mesh);
389
    DistortedAttachDaemon.attach(this,node);
390
    return node;
391
    }
392 f8377ef8 leszek
393 c204c69d leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
394
/**
395
 * This is not really part of the public API. Has to be public only because it is a part of the
396
 * DistortedAttacheable interface, which should really be a class that we extend here instead but
397
 * Java has no multiple inheritance.
398
 *
399 d3725071 Leszek Koltunski
 * @y.exclude
400 c204c69d leszek
 * @param node The new Node to add.
401
 */
402
  public void attachNow(DistortedNode node)
403
    {
404 9361b337 Leszek Koltunski
    if( mChildren==null ) mChildren = new ArrayList<>(2);
405 c204c69d leszek
406 f28fffc2 Leszek Koltunski
    node.mParent = this;
407 6a06a912 Leszek Koltunski
    mChildren.add(node);
408
    mNumChildren[0]++;
409 f28fffc2 Leszek Koltunski
    adjustIsomorphism();
410 6a06a912 Leszek Koltunski
    }
411 c204c69d leszek
412 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
413
/**
414
 * Removes the first occurrence of a specified child from the list of children of our Node.
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
 *
419 6a06a912 Leszek Koltunski
 * @param node The Node to remove.
420
 */
421 c204c69d leszek
  public void detach(DistortedNode node)
422 6a06a912 Leszek Koltunski
    {
423 c204c69d leszek
    DistortedAttachDaemon.detach(this,node);
424 6a06a912 Leszek Koltunski
    }
425 a09ada4c Leszek Koltunski
426 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
427
/**
428
 * Removes the first occurrence of a specified child from the list of children of our Node.
429 a09ada4c Leszek Koltunski
 * <p>
430
 * A bit questionable method as there can be many different Nodes attached as children, some
431
 * of them having the same Effects but - for instance - different Mesh. Use with care.
432 c204c69d leszek
 * <p>
433
 * We cannot do this mid-render - actual detachment will be done just before the next render, by the
434
 * DistortedAttachDeamon (by calling detachNow())
435 a09ada4c Leszek Koltunski
 *
436 07d8ef09 Leszek Koltunski
 * @param effects DistortedEffects to remove.
437 6a06a912 Leszek Koltunski
 */
438 c204c69d leszek
  public void detach(DistortedEffects effects)
439 6a06a912 Leszek Koltunski
    {
440 07d8ef09 Leszek Koltunski
    long id = effects.getID();
441 a09ada4c Leszek Koltunski
    DistortedNode node;
442 8baa1fe6 Leszek Koltunski
    boolean detached= false;
443 a09ada4c Leszek Koltunski
444 6a06a912 Leszek Koltunski
    for(int i=0; i<mNumChildren[0]; i++)
445
      {
446
      node = mChildren.get(i);
447 a09ada4c Leszek Koltunski
448 07d8ef09 Leszek Koltunski
      if( node.mEffects.getID()==id )
449 6a06a912 Leszek Koltunski
        {
450 8baa1fe6 Leszek Koltunski
        detached=true;
451 c204c69d leszek
        DistortedAttachDaemon.detach(this,node);
452
        break;
453 6a06a912 Leszek Koltunski
        }
454
      }
455 8baa1fe6 Leszek Koltunski
456
    if( !detached )
457
      {
458
      // if we failed to detach any, it still might be the case that
459
      // there's a job in Daemon's queue that we need to cancel.
460
      DistortedAttachDaemon.cancelAttachJobs(this,effects);
461
      }
462 6a06a912 Leszek Koltunski
    }
463 a09ada4c Leszek Koltunski
464 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
465
/**
466 c204c69d leszek
 * This is not really part of the public API. Has to be public only because it is a part of the
467
 * DistortedAttacheable interface, which should really be a class that we extend here instead but
468
 * Java has no multiple inheritance.
469
 *
470 d3725071 Leszek Koltunski
 * @y.exclude
471 c204c69d leszek
 * @param node The Node to remove.
472 6a06a912 Leszek Koltunski
 */
473 c204c69d leszek
  public void detachNow(DistortedNode node)
474 6a06a912 Leszek Koltunski
    {
475 c204c69d leszek
    if( mNumChildren[0]>0 && mChildren.remove(node) )
476 6a06a912 Leszek Koltunski
      {
477 f28fffc2 Leszek Koltunski
      node.mParent = null;
478 c204c69d leszek
      mNumChildren[0]--;
479 f28fffc2 Leszek Koltunski
      adjustIsomorphism();
480 6a06a912 Leszek Koltunski
      }
481 c204c69d leszek
    }
482
483
///////////////////////////////////////////////////////////////////////////////////////////////////
484
/**
485
 * Removes all children Nodes.
486
 * <p>
487
 * We cannot do this mid-render - actual detachment will be done just before the next render, by the
488
 * DistortedAttachDeamon (by calling detachAllNow())
489
 */
490
  public void detachAll()
491
    {
492
    DistortedAttachDaemon.detachAll(this);
493
    }
494
495
///////////////////////////////////////////////////////////////////////////////////////////////////
496
/**
497
 * This is not really part of the public API. Has to be public only because it is a part of the
498
 * DistortedAttacheable interface, which should really be a class that we extend here instead but
499
 * Java has no multiple inheritance.
500 d3725071 Leszek Koltunski
 *
501
 * @y.exclude
502 c204c69d leszek
 */
503
  public void detachAllNow()
504
    {
505 6a06a912 Leszek Koltunski
    if( mNumChildren[0]>0 )
506
      {
507 f28fffc2 Leszek Koltunski
      DistortedNode tmp;
508 af27df87 leszek
509 f28fffc2 Leszek Koltunski
      for(int i=mNumChildren[0]-1; i>=0; i--)
510 af27df87 leszek
        {
511 f28fffc2 Leszek Koltunski
        tmp = mChildren.remove(i);
512
        tmp.mParent = null;
513 af27df87 leszek
        }
514 f28fffc2 Leszek Koltunski
515
      mNumChildren[0] = 0;
516
      adjustIsomorphism();
517 6a06a912 Leszek Koltunski
      }
518
    }
519 d1e740c5 Leszek Koltunski
520 13687207 leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
521
/**
522
 * Sets the Postprocessing Effects we will apply to the temporary buffer this Node - and fellow siblings
523
 * with the same Effects - will get rendered to.
524
 * <p>
525
 * For efficiency reasons, it is very important to assign the very same DistortedEffectsPostprocess
526
 * object to all the DistortedNode siblings that are supposed to be postprocessed in the same way,
527
 * because only then will the library assign all such siblings to the same 'Bucket' which gets rendered
528
 * to the same offscreen buffer which then gets postprocessed in one go and subsequently merged to the
529
 * target Surface.
530
 */
531
  public void setPostprocessEffects(DistortedEffectsPostprocess dep)
532
    {
533
    mPostprocess = dep;
534
535
    // TODO: rearrange all the siblings so that all are sorted by the DistortedEffectsPostprocess' ID.
536
    }
537
538 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
539
/**
540 421c2728 Leszek Koltunski
 * Returns the DistortedEffects object that's in the Node.
541 6a06a912 Leszek Koltunski
 * 
542 421c2728 Leszek Koltunski
 * @return The DistortedEffects contained in the Node.
543 6a06a912 Leszek Koltunski
 */
544 421c2728 Leszek Koltunski
  public DistortedEffects getEffects()
545 6a06a912 Leszek Koltunski
    {
546 07d8ef09 Leszek Koltunski
    return mEffects;
547 4e2382f3 Leszek Koltunski
    }
548
549
///////////////////////////////////////////////////////////////////////////////////////////////////
550
/**
551 c5369f1b leszek
 * Returns the DistortedInputSurface object that's in the Node.
552 4e2382f3 Leszek Koltunski
 *
553 c5369f1b leszek
 * @return The DistortedInputSurface contained in the Node.
554 4e2382f3 Leszek Koltunski
 */
555 c5369f1b leszek
  public DistortedInputSurface getSurface()
556 4e2382f3 Leszek Koltunski
    {
557 c5369f1b leszek
    return mSurface;
558 6a06a912 Leszek Koltunski
    }
559
560 8c327653 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
561
/**
562
 * Returns the DistortedFramebuffer object that's in the Node.
563
 *
564
 * @return The DistortedFramebuffer contained in the Node.
565
 */
566
  public DistortedFramebuffer getFramebuffer()
567
    {
568
    return mData.mFBO;
569
    }
570 6a06a912 Leszek Koltunski
571 c834348d leszek
572
///////////////////////////////////////////////////////////////////////////////////////////////////
573
/**
574
 * When rendering this Node, use ColorMask (r,g,b,a).
575
 *
576
 * @param r Write to the RED color channel when rendering this Node?
577
 * @param g Write to the GREEN color channel when rendering this Node?
578
 * @param b Write to the BLUE color channel when rendering this Node?
579
 * @param a Write to the ALPHA channel when rendering this Node?
580
 */
581 13687207 leszek
  @SuppressWarnings("unused")
582 c834348d leszek
  public void glColorMask(boolean r, boolean g, boolean b, boolean a)
583
    {
584
    mState.glColorMask(r,g,b,a);
585
    }
586
587
///////////////////////////////////////////////////////////////////////////////////////////////////
588
/**
589
 * When rendering this Node, switch on writing to Depth buffer?
590
 *
591
 * @param mask Write to the Depth buffer when rendering this Node?
592
 */
593 13687207 leszek
  @SuppressWarnings("unused")
594 c834348d leszek
  public void glDepthMask(boolean mask)
595
    {
596
    mState.glDepthMask(mask);
597
    }
598
599
///////////////////////////////////////////////////////////////////////////////////////////////////
600
/**
601
 * When rendering this Node, which bits of the Stencil buffer to write to?
602
 *
603
 * @param mask Marks the bits of the Stencil buffer we will write to when rendering this Node.
604
 */
605 13687207 leszek
  @SuppressWarnings("unused")
606 c834348d leszek
  public void glStencilMask(int mask)
607
    {
608
    mState.glStencilMask(mask);
609
    }
610
611
///////////////////////////////////////////////////////////////////////////////////////////////////
612
/**
613
 * When rendering this Node, which Tests to enable?
614
 *
615
 * @param test Valid values: GL_DEPTH_TEST, GL_STENCIL_TEST, GL_BLEND
616
 */
617 13687207 leszek
  @SuppressWarnings("unused")
618 c834348d leszek
  public void glEnable(int test)
619
    {
620
    mState.glEnable(test);
621
    }
622
623
///////////////////////////////////////////////////////////////////////////////////////////////////
624
/**
625
 * When rendering this Node, which Tests to enable?
626
 *
627
 * @param test Valid values: GL_DEPTH_TEST, GL_STENCIL_TEST, GL_BLEND
628
 */
629 13687207 leszek
  @SuppressWarnings("unused")
630 c834348d leszek
  public void glDisable(int test)
631
    {
632
    mState.glDisable(test);
633
    }
634
635
///////////////////////////////////////////////////////////////////////////////////////////////////
636
/**
637
 * When rendering this Node, use the following StencilFunc.
638
 *
639
 * @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
640
 * @param ref  Reference valut to compare our stencil with.
641
 * @param mask Mask used when comparing.
642
 */
643 13687207 leszek
  @SuppressWarnings("unused")
644 c834348d leszek
  public void glStencilFunc(int func, int ref, int mask)
645
    {
646
    mState.glStencilFunc(func,ref,mask);
647
    }
648
649
///////////////////////////////////////////////////////////////////////////////////////////////////
650
/**
651
 * When rendering this Node, use the following StencilOp.
652
 * <p>
653
 * Valid values of all 3 parameters: GL_KEEP, GL_ZERO, GL_REPLACE, GL_INCR, GL_DECR, GL_INVERT, GL_INCR_WRAP, GL_DECR_WRAP
654
 *
655
 * @param sfail  What to do when Stencil Test fails.
656
 * @param dpfail What to do when Depth Test fails.
657
 * @param dppass What to do when Depth Test passes.
658
 */
659 13687207 leszek
  @SuppressWarnings("unused")
660 c834348d leszek
  public void glStencilOp(int sfail, int dpfail, int dppass)
661
    {
662
    mState.glStencilOp(sfail,dpfail,dppass);
663
    }
664
665
///////////////////////////////////////////////////////////////////////////////////////////////////
666
/**
667
 * When rendering this Node, use the following DepthFunc.
668
 *
669
 * @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
670
 */
671 13687207 leszek
  @SuppressWarnings("unused")
672 c834348d leszek
  public void glDepthFunc(int func)
673
    {
674
    mState.glDepthFunc(func);
675
    }
676
677
///////////////////////////////////////////////////////////////////////////////////////////////////
678
/**
679
 * When rendering this Node, use the following Blending mode.
680
 * <p>
681
 * Valid values: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
682
 *               GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
683
 *               GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_SRC_ALPHA_SATURATE
684
 *
685
 * @param src Source Blend function
686
 * @param dst Destination Blend function
687
 */
688 13687207 leszek
  @SuppressWarnings("unused")
689 c834348d leszek
  public void glBlendFunc(int src, int dst)
690
    {
691
    mState.glBlendFunc(src,dst);
692
    }
693 8c327653 Leszek Koltunski
  }