Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedNode.java @ 60c1c622

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