Project

General

Profile

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

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

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 a0f644b7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
198 7691a39f leszek
// return the total number of render calls issued
199 a0f644b7 Leszek Koltunski
200 50642a86 Leszek Koltunski
  int drawRecursive(long currTime, DistortedOutputSurface surface)
201 a0f644b7 Leszek Koltunski
    {
202 7691a39f leszek
    int ret = 0;
203 a0f644b7 Leszek Koltunski
204 50642a86 Leszek Koltunski
    if( mNumChildren[0]>0 && mData.currTime!=currTime )
205 a0f644b7 Leszek Koltunski
      {
206 50642a86 Leszek Koltunski
      mData.currTime = currTime;
207 d03782c0 leszek
      mData.mFBO.setAsOutput();
208 a0f644b7 Leszek Koltunski
209 d03782c0 leszek
      GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
210
      GLES30.glClear( GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);
211 a0f644b7 Leszek Koltunski
212 d03782c0 leszek
      if( mSurface.setAsInput() )
213
        {
214
        ret++;
215 c1e24646 leszek
        DistortedEffects.blitPriv(mData.mFBO);
216 a0f644b7 Leszek Koltunski
        }
217
218 d03782c0 leszek
      for(int i=0; i<mNumChildren[0]; i++)
219
        {
220 50642a86 Leszek Koltunski
        ret += mChildren.get(i).drawRecursive(currTime, mData.mFBO);
221 d03782c0 leszek
        }
222 a0f644b7 Leszek Koltunski
      }
223
224 d03782c0 leszek
    DistortedInputSurface input = mNumChildren[0]==0 ? mSurface : mData.mFBO;
225 7691a39f leszek
226 d03782c0 leszek
    if( input.setAsInput() )
227
      {
228
      ret++;
229 c834348d leszek
      mState.apply();
230 d61fd515 leszek
      mEffects.drawPriv(mSurface.getWidth()/2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime);
231 d03782c0 leszek
      }
232
233
    return ret;
234 a0f644b7 Leszek Koltunski
    }
235
236 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
237
// PUBLIC API
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239
/**
240 a09ada4c Leszek Koltunski
 * Constructs new Node.
241 6a06a912 Leszek Koltunski
 *     
242 c5369f1b leszek
 * @param surface InputSurface to put into the new Node.
243 07d8ef09 Leszek Koltunski
 * @param effects DistortedEffects to put into the new Node.
244 05403bba Leszek Koltunski
 * @param mesh MeshObject to put into the new Node.
245 6a06a912 Leszek Koltunski
 */
246 a09ada4c Leszek Koltunski
  public DistortedNode(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
247 6a06a912 Leszek Koltunski
    {
248 c5369f1b leszek
    mSurface       = surface;
249 8ca9f899 Leszek Koltunski
    mEffects       = effects;
250
    mMesh          = mesh;
251 c834348d leszek
    mState         = new DistortedRenderState();
252 8ca9f899 Leszek Koltunski
    mChildren      = null;
253
    mNumChildren   = new int[1];
254
    mNumChildren[0]= 0;
255 f28fffc2 Leszek Koltunski
    mParent        = null;
256
257 9361b337 Leszek Koltunski
    ArrayList<Long> list = new ArrayList<>();
258 c5369f1b leszek
    list.add(mSurface.getID());
259 7691a39f leszek
    list.add(-mEffects.getID());
260 1942537e Leszek Koltunski
261 6a06a912 Leszek Koltunski
    mData = mMapNodeID.get(list);
262
   
263
    if( mData!=null )
264
      {
265
      mData.numPointingNodes++;
266
      }
267
    else
268
      {
269 af27df87 leszek
      mData = new NodeData(++mNextNodeID,list);
270 1942537e Leszek Koltunski
      mMapNodeID.put(list, mData);
271 6a06a912 Leszek Koltunski
      }
272
    }
273
274
///////////////////////////////////////////////////////////////////////////////////////////////////  
275
/**
276 a09ada4c Leszek Koltunski
 * Copy-constructs new Node from another Node.
277 6a06a912 Leszek Koltunski
 *     
278 a09ada4c Leszek Koltunski
 * @param node The DistortedNode to copy data from.
279 6a06a912 Leszek Koltunski
 * @param flags bit field composed of a subset of the following:
280 29a06526 Leszek Koltunski
 *        {@link Distorted#CLONE_SURFACE},  {@link Distorted#CLONE_MATRIX}, {@link Distorted#CLONE_VERTEX},
281 6a06a912 Leszek Koltunski
 *        {@link Distorted#CLONE_FRAGMENT} and {@link Distorted#CLONE_CHILDREN}.
282 29a06526 Leszek Koltunski
 *        For example flags = CLONE_SURFACE | CLONE_CHILDREN.
283 6a06a912 Leszek Koltunski
 */
284 a09ada4c Leszek Koltunski
  public DistortedNode(DistortedNode node, int flags)
285 6a06a912 Leszek Koltunski
    {
286 432442f9 Leszek Koltunski
    mEffects= new DistortedEffects(node.mEffects,flags);
287 f28fffc2 Leszek Koltunski
    mMesh   = node.mMesh;
288 c834348d leszek
    mState  = new DistortedRenderState();
289 f28fffc2 Leszek Koltunski
    mParent = null;
290 9361b337 Leszek Koltunski
291 29a06526 Leszek Koltunski
    if( (flags & Distorted.CLONE_SURFACE) != 0 )
292 e7a20702 Leszek Koltunski
      {
293 c5369f1b leszek
      mSurface = node.mSurface;
294 e7a20702 Leszek Koltunski
      }
295
    else
296
      {
297 c5369f1b leszek
      int w = node.mSurface.getWidth();
298
      int h = node.mSurface.getHeight();
299 8ca9f899 Leszek Koltunski
300 c5369f1b leszek
      if( node.mSurface instanceof DistortedTexture )
301 8ca9f899 Leszek Koltunski
        {
302 09ab7524 Leszek Koltunski
        mSurface = new DistortedTexture(w,h, DistortedSurface.TYPE_TREE);
303 8ca9f899 Leszek Koltunski
        }
304 c5369f1b leszek
      else if( node.mSurface instanceof DistortedFramebuffer )
305 8ca9f899 Leszek Koltunski
        {
306 c5369f1b leszek
        boolean hasDepth = ((DistortedFramebuffer) node.mSurface).hasDepth();
307 09ab7524 Leszek Koltunski
        mSurface = new DistortedFramebuffer(hasDepth,DistortedSurface.TYPE_TREE,w,h);
308 8ca9f899 Leszek Koltunski
        }
309 e7a20702 Leszek Koltunski
      }
310 9361b337 Leszek Koltunski
    if( (flags & Distorted.CLONE_CHILDREN) != 0 )
311 6a06a912 Leszek Koltunski
      {
312 c204c69d leszek
      if( node.mChildren==null )     // do NOT copy over the NULL!
313
        {
314
        node.mChildren = new ArrayList<>(2);
315
        }
316
317 6a06a912 Leszek Koltunski
      mChildren = node.mChildren;
318
      mNumChildren = node.mNumChildren;
319
      }
320
    else
321
      {
322
      mChildren = null;
323
      mNumChildren = new int[1];
324
      mNumChildren[0] = 0;
325
      }
326
   
327
    ArrayList<Long> list = generateIDList();
328
   
329
    mData = mMapNodeID.get(list);
330
   
331
    if( mData!=null )
332
      {
333
      mData.numPointingNodes++;
334
      }
335
    else
336
      {
337 af27df87 leszek
      mData = new NodeData(++mNextNodeID,list);
338 6a06a912 Leszek Koltunski
      mMapNodeID.put(list, mData);
339
      }
340
    }
341 c204c69d leszek
342 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
343
/**
344
 * Adds a new child to the last position in the list of our Node's children.
345 c204c69d leszek
 * <p>
346
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
347
 * DistortedAttachDeamon (by calling attachNow())
348
 *
349 6a06a912 Leszek Koltunski
 * @param node The new Node to add.
350
 */
351 c204c69d leszek
  public void attach(DistortedNode node)
352 6a06a912 Leszek Koltunski
    {
353 c204c69d leszek
    DistortedAttachDaemon.attach(this,node);
354 6a06a912 Leszek Koltunski
    }
355 c204c69d leszek
356 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
357
/**
358
 * Adds a new child to the last position in the list of our Node's children.
359 c204c69d leszek
 * <p>
360
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
361
 * DistortedAttachDeamon (by calling attachNow())
362
 *
363 c5369f1b leszek
 * @param surface InputSurface to initialize our child Node with.
364 07d8ef09 Leszek Koltunski
 * @param effects DistortedEffects to initialize our child Node with.
365 05403bba Leszek Koltunski
 * @param mesh MeshObject to initialize our child Node with.
366 6a06a912 Leszek Koltunski
 * @return the newly constructed child Node, or null if we couldn't allocate resources.
367
 */
368 c204c69d leszek
  public DistortedNode attach(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
369 6a06a912 Leszek Koltunski
    {
370 c204c69d leszek
    DistortedNode node = new DistortedNode(surface,effects,mesh);
371
    DistortedAttachDaemon.attach(this,node);
372
    return node;
373
    }
374 f8377ef8 leszek
375 c204c69d leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
376
/**
377
 * This is not really part of the public API. Has to be public only because it is a part of the
378
 * DistortedAttacheable interface, which should really be a class that we extend here instead but
379
 * Java has no multiple inheritance.
380
 *
381 d3725071 Leszek Koltunski
 * @y.exclude
382 c204c69d leszek
 * @param node The new Node to add.
383
 */
384
  public void attachNow(DistortedNode node)
385
    {
386 9361b337 Leszek Koltunski
    if( mChildren==null ) mChildren = new ArrayList<>(2);
387 c204c69d leszek
388 f28fffc2 Leszek Koltunski
    node.mParent = this;
389 6a06a912 Leszek Koltunski
    mChildren.add(node);
390
    mNumChildren[0]++;
391 f28fffc2 Leszek Koltunski
    adjustIsomorphism();
392 6a06a912 Leszek Koltunski
    }
393 c204c69d leszek
394 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
395
/**
396
 * Removes the first occurrence of a specified child from the list of children of our Node.
397 c204c69d leszek
 * <p>
398
 * We cannot do this mid-render - actual detachment will be done just before the next render, by the
399
 * DistortedAttachDeamon (by calling detachNow())
400
 *
401 6a06a912 Leszek Koltunski
 * @param node The Node to remove.
402
 */
403 c204c69d leszek
  public void detach(DistortedNode node)
404 6a06a912 Leszek Koltunski
    {
405 c204c69d leszek
    DistortedAttachDaemon.detach(this,node);
406 6a06a912 Leszek Koltunski
    }
407 a09ada4c Leszek Koltunski
408 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
409
/**
410
 * Removes the first occurrence of a specified child from the list of children of our Node.
411 a09ada4c Leszek Koltunski
 * <p>
412
 * A bit questionable method as there can be many different Nodes attached as children, some
413
 * of them having the same Effects but - for instance - different Mesh. Use with care.
414 c204c69d leszek
 * <p>
415
 * We cannot do this mid-render - actual detachment will be done just before the next render, by the
416
 * DistortedAttachDeamon (by calling detachNow())
417 a09ada4c Leszek Koltunski
 *
418 07d8ef09 Leszek Koltunski
 * @param effects DistortedEffects to remove.
419 6a06a912 Leszek Koltunski
 */
420 c204c69d leszek
  public void detach(DistortedEffects effects)
421 6a06a912 Leszek Koltunski
    {
422 07d8ef09 Leszek Koltunski
    long id = effects.getID();
423 a09ada4c Leszek Koltunski
    DistortedNode node;
424
425 6a06a912 Leszek Koltunski
    for(int i=0; i<mNumChildren[0]; i++)
426
      {
427
      node = mChildren.get(i);
428 a09ada4c Leszek Koltunski
429 07d8ef09 Leszek Koltunski
      if( node.mEffects.getID()==id )
430 6a06a912 Leszek Koltunski
        {
431 c204c69d leszek
        DistortedAttachDaemon.detach(this,node);
432
        break;
433 6a06a912 Leszek Koltunski
        }
434
      }
435
    }
436 a09ada4c Leszek Koltunski
437 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
438
/**
439 c204c69d leszek
 * This is not really part of the public API. Has to be public only because it is a part of the
440
 * DistortedAttacheable interface, which should really be a class that we extend here instead but
441
 * Java has no multiple inheritance.
442
 *
443 d3725071 Leszek Koltunski
 * @y.exclude
444 c204c69d leszek
 * @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 f28fffc2 Leszek Koltunski
      node.mParent = null;
451 c204c69d leszek
      mNumChildren[0]--;
452 f28fffc2 Leszek Koltunski
      adjustIsomorphism();
453 6a06a912 Leszek Koltunski
      }
454 c204c69d leszek
    }
455
456
///////////////////////////////////////////////////////////////////////////////////////////////////
457
/**
458
 * Removes all children Nodes.
459
 * <p>
460
 * We cannot do this mid-render - actual detachment will be done just before the next render, by the
461
 * DistortedAttachDeamon (by calling detachAllNow())
462
 */
463
  public void detachAll()
464
    {
465
    DistortedAttachDaemon.detachAll(this);
466
    }
467
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469
/**
470
 * 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 d3725071 Leszek Koltunski
 *
474
 * @y.exclude
475 c204c69d leszek
 */
476
  public void detachAllNow()
477
    {
478 6a06a912 Leszek Koltunski
    if( mNumChildren[0]>0 )
479
      {
480 f28fffc2 Leszek Koltunski
      DistortedNode tmp;
481 af27df87 leszek
482 f28fffc2 Leszek Koltunski
      for(int i=mNumChildren[0]-1; i>=0; i--)
483 af27df87 leszek
        {
484 f28fffc2 Leszek Koltunski
        tmp = mChildren.remove(i);
485
        tmp.mParent = null;
486 af27df87 leszek
        }
487 f28fffc2 Leszek Koltunski
488
      mNumChildren[0] = 0;
489
      adjustIsomorphism();
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 c834348d leszek
527
///////////////////////////////////////////////////////////////////////////////////////////////////
528
/**
529
 * When rendering this Node, use ColorMask (r,g,b,a).
530
 *
531
 * @param r Write to the RED color channel when rendering this Node?
532
 * @param g Write to the GREEN color channel when rendering this Node?
533
 * @param b Write to the BLUE color channel when rendering this Node?
534
 * @param a Write to the ALPHA channel when rendering this Node?
535
 */
536
  public void glColorMask(boolean r, boolean g, boolean b, boolean a)
537
    {
538
    mState.glColorMask(r,g,b,a);
539
    }
540
541
///////////////////////////////////////////////////////////////////////////////////////////////////
542
/**
543
 * When rendering this Node, switch on writing to Depth buffer?
544
 *
545
 * @param mask Write to the Depth buffer when rendering this Node?
546
 */
547
  public void glDepthMask(boolean mask)
548
    {
549
    mState.glDepthMask(mask);
550
    }
551
552
///////////////////////////////////////////////////////////////////////////////////////////////////
553
/**
554
 * When rendering this Node, which bits of the Stencil buffer to write to?
555
 *
556
 * @param mask Marks the bits of the Stencil buffer we will write to when rendering this Node.
557
 */
558
  public void glStencilMask(int mask)
559
    {
560
    mState.glStencilMask(mask);
561
    }
562
563
///////////////////////////////////////////////////////////////////////////////////////////////////
564
/**
565
 * When rendering this Node, which Tests to enable?
566
 *
567
 * @param test Valid values: GL_DEPTH_TEST, GL_STENCIL_TEST, GL_BLEND
568
 */
569
  public void glEnable(int test)
570
    {
571
    mState.glEnable(test);
572
    }
573
574
///////////////////////////////////////////////////////////////////////////////////////////////////
575
/**
576
 * When rendering this Node, which Tests to enable?
577
 *
578
 * @param test Valid values: GL_DEPTH_TEST, GL_STENCIL_TEST, GL_BLEND
579
 */
580
  public void glDisable(int test)
581
    {
582
    mState.glDisable(test);
583
    }
584
585
///////////////////////////////////////////////////////////////////////////////////////////////////
586
/**
587
 * When rendering this Node, use the following StencilFunc.
588
 *
589
 * @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
590
 * @param ref  Reference valut to compare our stencil with.
591
 * @param mask Mask used when comparing.
592
 */
593
  public void glStencilFunc(int func, int ref, int mask)
594
    {
595
    mState.glStencilFunc(func,ref,mask);
596
    }
597
598
///////////////////////////////////////////////////////////////////////////////////////////////////
599
/**
600
 * When rendering this Node, use the following StencilOp.
601
 * <p>
602
 * Valid values of all 3 parameters: GL_KEEP, GL_ZERO, GL_REPLACE, GL_INCR, GL_DECR, GL_INVERT, GL_INCR_WRAP, GL_DECR_WRAP
603
 *
604
 * @param sfail  What to do when Stencil Test fails.
605
 * @param dpfail What to do when Depth Test fails.
606
 * @param dppass What to do when Depth Test passes.
607
 */
608
  public void glStencilOp(int sfail, int dpfail, int dppass)
609
    {
610
    mState.glStencilOp(sfail,dpfail,dppass);
611
    }
612
613
///////////////////////////////////////////////////////////////////////////////////////////////////
614
/**
615
 * When rendering this Node, use the following DepthFunc.
616
 *
617
 * @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
618
 */
619
  public void glDepthFunc(int func)
620
    {
621
    mState.glDepthFunc(func);
622
    }
623
624
///////////////////////////////////////////////////////////////////////////////////////////////////
625
/**
626
 * When rendering this Node, use the following Blending mode.
627
 * <p>
628
 * Valid values: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
629
 *               GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
630
 *               GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_SRC_ALPHA_SATURATE
631
 *
632
 * @param src Source Blend function
633
 * @param dst Destination Blend function
634
 */
635
  public void glBlendFunc(int src, int dst)
636
    {
637
    mState.glBlendFunc(src,dst);
638
    }
639 8c327653 Leszek Koltunski
  }