Project

General

Profile

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

library / src / main / java / org / distorted / library / main / DistortedNode.java @ 8dccc3c2

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
package org.distorted.library.main;
21

    
22
import android.opengl.GLES31;
23

    
24
import java.util.ArrayList;
25
import java.util.Collections;
26
import java.util.HashMap;
27

    
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29
/**
30
 * Class which represents a Node in a Tree of (InputSurface,Mesh,Effects) triplets.
31
 * <p>
32
 * Having organized such sets into a Tree, we can then render any Node to any OutputSurface.
33
 * That recursively renders the set held in the Node and all its children.
34
 * <p>
35
 * The class takes special care to only render identical sub-trees once. Each Node holds a reference
36
 * to sub-class 'NodeData'. Two identical sub-trees attached at different points of the main tree
37
 * will point to the same NodeData; only the first of this is rendered (mData.numRender!).
38
 */
39
public class DistortedNode implements DistortedMaster.Slave
40
  {
41
  private static final int ATTACH = 0;
42
  private static final int DETACH = 1;
43
  private static final int DETALL = 2;
44
  private static final int SORT   = 3;
45

    
46
  private ArrayList<DistortedNode> mChildren;
47
  private int[] mNumChildren;  // ==mChildren.length(), but we only create mChildren if the first one gets added
48

    
49
  private class Job
50
    {
51
    int type;
52
    DistortedNode node;
53

    
54
    Job(int t, DistortedNode n)
55
      {
56
      type = t;
57
      node = n;
58
      }
59
    }
60

    
61
  private ArrayList<Job> mJobs = new ArrayList<>();
62

    
63
  private static HashMap<ArrayList<Long>,NodeData> mMapNodeID = new HashMap<>();
64
  private static long mNextNodeID =0;
65

    
66
  private DistortedNode mParent;
67
  private DistortedOutputSurface mSurfaceParent;
68
  private MeshObject mMesh;
69
  private DistortedEffects mEffects;
70
  private DistortedInputSurface mSurface;
71
  private DistortedRenderState mState;
72
  private NodeData mData;
73
  private int mFboW, mFboH, mFboDepthStencil;
74

    
75
  private class NodeData
76
    {
77
    long ID;
78
    int numPointingNodes;
79
    long currTime;
80
    ArrayList<Long> key;
81
    DistortedFramebuffer mFBO;
82

    
83
    NodeData(long id, ArrayList<Long> k)
84
      {
85
      ID              = id;
86
      key             = k;
87
      numPointingNodes= 1;
88
      currTime        =-1;
89
      mFBO            = null;
90
      }
91
    }
92
 
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

    
95
  static synchronized void onPause()
96
    {
97
    NodeData data;
98

    
99
    for (HashMap.Entry<ArrayList<Long>,NodeData> entry : mMapNodeID.entrySet())
100
      {
101
      data = entry.getValue();
102

    
103
      if( data.mFBO != null )
104
        {
105
        data.mFBO.markForDeletion();
106
        data.mFBO = null;
107
        }
108
      }
109
    }
110

    
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

    
113
  static synchronized void onDestroy()
114
    {
115
    mNextNodeID = 0;
116
    mMapNodeID.clear();
117
    }
118

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

    
121
  private ArrayList<Long> generateIDList()
122
    {
123
    ArrayList<Long> ret = new ArrayList<>();
124

    
125
    if( mNumChildren[0]==0 )
126
      {
127
      // add a negative number so this leaf never gets confused with a internal node
128
      // with a single child that happens to have ID identical to some leaf's Effects ID.
129
      ret.add(-mEffects.getID());
130
      }
131
    else
132
      {
133
      DistortedNode node;
134
   
135
      for(int i=0; i<mNumChildren[0]; i++)
136
        {
137
        node = mChildren.get(i);
138
        ret.add(node.mData.ID);
139
        }
140

    
141
      // A bit questionable decision here - we are sorting the children IDs, which means
142
      // that order in which we draw the children is going to be undefined (well, this is not
143
      // strictly speaking true - when rendering, if no postprocessing and isomorphism are
144
      // involved, we *DO* render the children in order they were added; if however there
145
      // are two internal nodes with the same list of identical children, just added in a
146
      // different order each time, then we consider them isomorphic, i.e. identical and only
147
      // render the first one. If then two children of such 'pseudo-isomorphic' nodes are at
148
      // exactly the same Z-height this might result in some unexpected sights).
149
      //
150
      // Reason: with the children being sorted by postprocessing buckets, the order is
151
      // undefined anyway (although only when postprocessing is applied).
152
      //
153
      // See the consequences in the 'Olympic' app - remove a few leaves and add them back in
154
      // different order. You will see the number of renders go back to the original 14.
155
      Collections.sort(ret);
156
      }
157

    
158
    ret.add( 0, mSurface.getID() );
159

    
160
    return ret;
161
    }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164
// Debug - print all the Node IDs
165

    
166
  @SuppressWarnings("unused")
167
  void debug(int depth)
168
    {
169
    String tmp="";
170
    int i;
171

    
172
    for(i=0; i<depth; i++) tmp +="   ";
173
    tmp += ("NodeID="+mData.ID+" nodes pointing: "+mData.numPointingNodes+" surfaceID="+
174
            mSurface.getID()+" FBO="+(mData.mFBO==null ? "null":mData.mFBO.getID()))+
175
            " parent sID="+(mParent==null ? "null": (mParent.mSurface.getID()));
176

    
177
    android.util.Log.e("NODE", tmp);
178

    
179
    for(i=0; i<mNumChildren[0]; i++)
180
      mChildren.get(i).debug(depth+1);
181
    }
182

    
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184
// Debug - print contents of the HashMap
185

    
186
  @SuppressWarnings("unused")
187
  static void debugMap()
188
    {
189
    NodeData tmp;
190

    
191
    for(ArrayList<Long> key: mMapNodeID.keySet())
192
      {
193
      tmp = mMapNodeID.get(key);
194
      android.util.Log.e("NODE", "NodeID: "+tmp.ID+" <-- "+key);
195
      }
196
    }
197

    
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199
// tree isomorphism algorithm
200

    
201
  private void adjustIsomorphism()
202
    {
203
    ArrayList<Long> newList = generateIDList();
204
    NodeData newData = mMapNodeID.get(newList);
205

    
206
    if( newData!=null )
207
      {
208
      newData.numPointingNodes++;
209
      }
210
    else
211
      {
212
      newData = new NodeData(++mNextNodeID,newList);
213
      mMapNodeID.put(newList,newData);
214
      }
215

    
216
    boolean deleteOldFBO = false;
217
    boolean createNewFBO = false;
218

    
219
    if( --mData.numPointingNodes==0 )
220
      {
221
      mMapNodeID.remove(mData.key);
222
      if( mData.mFBO!=null ) deleteOldFBO=true;
223
      }
224
    if( mNumChildren[0]>0 && newData.mFBO==null )
225
      {
226
      createNewFBO = true;
227
      }
228
    if( mNumChildren[0]==0 && newData.mFBO!=null )
229
      {
230
      newData.mFBO.markForDeletion();
231
      android.util.Log.d("NODE", "ERROR!! this NodeData cannot possibly contain a non-null FBO!! "+newData.mFBO.getID() );
232
      newData.mFBO = null;
233
      }
234

    
235
    if( deleteOldFBO && createNewFBO )
236
      {
237
      newData.mFBO = mData.mFBO;  // just copy over
238
      //android.util.Log.d("NODE", "copying over FBOs "+mData.mFBO.getID() );
239
      }
240
    else if( deleteOldFBO )
241
      {
242
      mData.mFBO.markForDeletion();
243
      //android.util.Log.d("NODE", "deleting old FBO "+mData.mFBO.getID() );
244
      mData.mFBO = null;
245
      }
246
    else if( createNewFBO )
247
      {
248
      int width  = mFboW <= 0 ? mSurface.getWidth()  : mFboW;
249
      int height = mFboH <= 0 ? mSurface.getHeight() : mFboH;
250
      newData.mFBO = new DistortedFramebuffer(1,mFboDepthStencil, DistortedSurface.TYPE_TREE, width, height);
251
      //android.util.Log.d("NODE", "creating new FBO "+newData.mFBO.getID() );
252
      }
253

    
254
    mData = newData;
255

    
256
    if( mParent!=null ) mParent.adjustIsomorphism();
257
    }
258

    
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260

    
261
  int markStencilAndDepth(long currTime, DistortedOutputSurface surface, EffectQueuePostprocess queue)
262
    {
263
    DistortedInputSurface input = mNumChildren[0]==0 ? mSurface : mData.mFBO;
264

    
265
    if( input.setAsInput() )
266
      {
267
      surface.setAsOutput();
268
      DistortedRenderState.setUpStencilMark();
269
      mEffects.drawPriv(mSurface.getWidth() /2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime, queue.getHalo()*surface.mMipmap);
270
      DistortedRenderState.unsetUpStencilMark();
271

    
272
      return 1;
273
      }
274
    return 0;
275
    }
276

    
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278
// return the total number of render calls issued
279

    
280
  int drawNoBlend(long currTime, DistortedOutputSurface surface)
281
    {
282
    DistortedInputSurface input = mNumChildren[0]==0 ? mSurface : mData.mFBO;
283

    
284
    if( input.setAsInput() )
285
      {
286
      surface.setAsOutput(currTime);
287
      mState.apply();
288
      GLES31.glDisable(GLES31.GL_BLEND);
289
      mEffects.drawPriv(mSurface.getWidth()/2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime, 0);
290
      GLES31.glEnable(GLES31.GL_BLEND);
291
      return 1;
292
      }
293

    
294
    return 0;
295
    }
296

    
297
///////////////////////////////////////////////////////////////////////////////////////////////////
298
// return the total number of render calls issued
299

    
300
  int draw(long currTime, DistortedOutputSurface surface)
301
    {
302
    DistortedInputSurface input = mNumChildren[0]==0 ? mSurface : mData.mFBO;
303

    
304
    if( input.setAsInput() )
305
      {
306
      surface.setAsOutput(currTime);
307
      mState.apply();
308
      mEffects.drawPriv(mSurface.getWidth()/2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime, 0);
309
      return 1;
310
      }
311

    
312
    return 0;
313
    }
314

    
315
///////////////////////////////////////////////////////////////////////////////////////////////////
316
// return the total number of render calls issued
317

    
318
  int renderRecursive(long currTime)
319
    {
320
    int numRenders = 0;
321

    
322
    if( mNumChildren[0]>0 && mData.currTime!=currTime )
323
      {
324
      mData.currTime = currTime;
325

    
326
      for (int i=0; i<mNumChildren[0]; i++)
327
        {
328
        numRenders += mChildren.get(i).renderRecursive(currTime);
329
        }
330

    
331
      if( mData.mFBO==null )
332
        {
333
        int width  = mFboW <= 0 ? mSurface.getWidth()  : mFboW;
334
        int height = mFboH <= 0 ? mSurface.getHeight() : mFboH;
335
        mData.mFBO = new DistortedFramebuffer(1,mFboDepthStencil, DistortedSurface.TYPE_TREE, width, height);
336
        }
337

    
338
      mData.mFBO.setAsOutput(currTime);
339

    
340
      if( mSurface.setAsInput() )
341
        {
342
        numRenders++;
343
        DistortedEffects.blitPriv(mData.mFBO);
344
        }
345

    
346
      numRenders += mData.mFBO.renderChildren(currTime,mNumChildren[0],mChildren);
347
      }
348

    
349
    return numRenders;
350
    }
351

    
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353

    
354
  void setSurfaceParent(DistortedOutputSurface dep)
355
    {
356
    mSurfaceParent = dep;
357
    mParent = null;
358
    }
359

    
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

    
362
  void sort()
363
    {
364
    if( mParent!=null )
365
      {
366
      mParent.mChildren.remove(this);
367
      DistortedMaster.addSorted(mParent.mChildren,this);
368
      }
369
    else if( mSurfaceParent!=null )
370
      {
371
      ArrayList<DistortedNode> children = mSurfaceParent.getChildren();
372
      children.remove(this);
373
      DistortedMaster.addSorted(children,this);
374
      }
375
    }
376

    
377
///////////////////////////////////////////////////////////////////////////////////////////////////
378
/**
379
 * Not part of the Public API.
380
 *
381
 * @y.exclude
382
 */
383
  public EffectQueuePostprocess getPostprocessQueue()
384
    {
385
    return mEffects.getPostprocess();
386
    }
387

    
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389
// PUBLIC API
390
///////////////////////////////////////////////////////////////////////////////////////////////////
391
/**
392
 * Constructs new Node.
393
 *     
394
 * @param surface InputSurface to put into the new Node.
395
 * @param effects DistortedEffects to put into the new Node.
396
 * @param mesh MeshObject to put into the new Node.
397
 */
398
  public DistortedNode(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
399
    {
400
    mSurface       = surface;
401
    mEffects       = effects;
402
    mMesh          = mesh;
403
    mState         = new DistortedRenderState();
404
    mChildren      = null;
405
    mNumChildren   = new int[1];
406
    mNumChildren[0]= 0;
407
    mParent        = null;
408
    mSurfaceParent = null;
409

    
410
    mFboW            = 0;  // i.e. take this from
411
    mFboH            = 0;  // mSurface's dimensions
412
    mFboDepthStencil = DistortedFramebuffer.DEPTH_NO_STENCIL;
413

    
414
    ArrayList<Long> list = new ArrayList<>();
415
    list.add(mSurface.getID());
416
    list.add(-mEffects.getID());
417

    
418
    mData = mMapNodeID.get(list);
419
   
420
    if( mData!=null )
421
      {
422
      mData.numPointingNodes++;
423
      }
424
    else
425
      {
426
      mData = new NodeData(++mNextNodeID,list);
427
      mMapNodeID.put(list, mData);
428
      }
429

    
430
    mEffects.newNode(this);
431
    }
432

    
433
///////////////////////////////////////////////////////////////////////////////////////////////////  
434
/**
435
 * Copy-constructs new Node from another Node.
436
 *     
437
 * @param node The DistortedNode to copy data from.
438
 * @param flags bit field composed of a subset of the following:
439
 *        {@link Distorted#CLONE_SURFACE},  {@link Distorted#CLONE_MATRIX}, {@link Distorted#CLONE_VERTEX},
440
 *        {@link Distorted#CLONE_FRAGMENT} and {@link Distorted#CLONE_CHILDREN}.
441
 *        For example flags = CLONE_SURFACE | CLONE_CHILDREN.
442
 */
443
  public DistortedNode(DistortedNode node, int flags)
444
    {
445
    mEffects      = new DistortedEffects(node.mEffects,flags);
446
    mMesh         = node.mMesh;
447
    mState        = new DistortedRenderState();
448
    mParent       = null;
449
    mSurfaceParent= null;
450

    
451
    mFboW            = node.mFboW;
452
    mFboH            = node.mFboH;
453
    mFboDepthStencil = node.mFboDepthStencil;
454

    
455
    if( (flags & Distorted.CLONE_SURFACE) != 0 )
456
      {
457
      mSurface = node.mSurface;
458
      }
459
    else
460
      {
461
      int w = node.mSurface.getWidth();
462
      int h = node.mSurface.getHeight();
463

    
464
      if( node.mSurface instanceof DistortedTexture )
465
        {
466
        mSurface = new DistortedTexture(w,h, DistortedSurface.TYPE_TREE);
467
        }
468
      else if( node.mSurface instanceof DistortedFramebuffer )
469
        {
470
        int depthStencil = DistortedFramebuffer.NO_DEPTH_NO_STENCIL;
471

    
472
        if( ((DistortedFramebuffer) node.mSurface).hasDepth() )
473
          {
474
          boolean hasStencil = ((DistortedFramebuffer) node.mSurface).hasStencil();
475
          depthStencil = (hasStencil ? DistortedFramebuffer.BOTH_DEPTH_STENCIL:DistortedFramebuffer.DEPTH_NO_STENCIL);
476
          }
477

    
478
        mSurface = new DistortedFramebuffer(1,depthStencil,DistortedSurface.TYPE_TREE,w,h);
479
        }
480
      }
481
    if( (flags & Distorted.CLONE_CHILDREN) != 0 )
482
      {
483
      if( node.mChildren==null )     // do NOT copy over the NULL!
484
        {
485
        node.mChildren = new ArrayList<>(2);
486
        }
487

    
488
      mChildren = node.mChildren;
489
      mNumChildren = node.mNumChildren;
490
      }
491
    else
492
      {
493
      mChildren = null;
494
      mNumChildren = new int[1];
495
      mNumChildren[0] = 0;
496
      }
497
   
498
    ArrayList<Long> list = generateIDList();
499
   
500
    mData = mMapNodeID.get(list);
501
   
502
    if( mData!=null )
503
      {
504
      mData.numPointingNodes++;
505
      }
506
    else
507
      {
508
      mData = new NodeData(++mNextNodeID,list);
509
      mMapNodeID.put(list, mData);
510
      }
511

    
512
    mEffects.newNode(this);
513
    }
514

    
515
///////////////////////////////////////////////////////////////////////////////////////////////////
516
/**
517
 * Adds a new child to the last position in the list of our Node's children.
518
 * <p>
519
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
520
 * DistortedMaster (by calling doWork())
521
 *
522
 * @param node The new Node to add.
523
 */
524
  public void attach(DistortedNode node)
525
    {
526
    mJobs.add(new Job(ATTACH,node));
527
    DistortedMaster.newSlave(this);
528
    }
529

    
530
///////////////////////////////////////////////////////////////////////////////////////////////////
531
/**
532
 * Adds a new child to the last position in the list of our Node's children.
533
 * <p>
534
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
535
 * DistortedMaster (by calling doWork())
536
 *
537
 * @param surface InputSurface to initialize our child Node with.
538
 * @param effects DistortedEffects to initialize our child Node with.
539
 * @param mesh MeshObject to initialize our child Node with.
540
 * @return the newly constructed child Node, or null if we couldn't allocate resources.
541
 */
542
  public DistortedNode attach(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
543
    {
544
    DistortedNode node = new DistortedNode(surface,effects,mesh);
545
    mJobs.add(new Job(ATTACH,node));
546
    DistortedMaster.newSlave(this);
547
    return node;
548
    }
549

    
550
///////////////////////////////////////////////////////////////////////////////////////////////////
551
/**
552
 * Removes the first occurrence of a specified child from the list of children of our Node.
553
 * <p>
554
 * We cannot do this mid-render - actual detachment will be done just before the next render, by the
555
 * DistortedMaster (by calling doWork())
556
 *
557
 * @param node The Node to remove.
558
 */
559
  public void detach(DistortedNode node)
560
    {
561
    mJobs.add(new Job(DETACH,node));
562
    DistortedMaster.newSlave(this);
563
    }
564

    
565
///////////////////////////////////////////////////////////////////////////////////////////////////
566
/**
567
 * Removes the first occurrence of a specified child from the list of children of our Node.
568
 * <p>
569
 * A bit questionable method as there can be many different Nodes attached as children, some
570
 * of them having the same Effects but - for instance - different Mesh. Use with care.
571
 * <p>
572
 * We cannot do this mid-render - actual detachment will be done just before the next render, by the
573
 * DistortedMaster (by calling doWork())
574
 *
575
 * @param effects DistortedEffects to remove.
576
 */
577
  public void detach(DistortedEffects effects)
578
    {
579
    long id = effects.getID();
580
    DistortedNode node;
581
    boolean detached = false;
582

    
583
    for(int i=0; i<mNumChildren[0]; i++)
584
      {
585
      node = mChildren.get(i);
586

    
587
      if( node.getEffects().getID()==id )
588
        {
589
        detached = true;
590
        mJobs.add(new Job(DETACH,node));
591
        DistortedMaster.newSlave(this);
592
        break;
593
        }
594
      }
595

    
596
    if( !detached )
597
      {
598
      // if we failed to detach any, it still might be the case that
599
      // there's an ATTACH job that we need to cancel.
600
      int num = mJobs.size();
601
      Job job;
602

    
603
      for(int i=0; i<num; i++)
604
        {
605
        job = mJobs.get(i);
606

    
607
        if( job.type==ATTACH && job.node.getEffects()==effects )
608
          {
609
          mJobs.remove(i);
610
          break;
611
          }
612
        }
613
      }
614
    }
615

    
616
///////////////////////////////////////////////////////////////////////////////////////////////////
617
/**
618
 * Removes all children Nodes.
619
 * <p>
620
 * We cannot do this mid-render - actual detachment will be done just before the next render, by the
621
 * DistortedMaster (by calling doWork())
622
 */
623
  public void detachAll()
624
    {
625
    mJobs.add(new Job(DETALL,null));
626
    DistortedMaster.newSlave(this);
627
    }
628

    
629
///////////////////////////////////////////////////////////////////////////////////////////////////
630
/**
631
 * This is not really part of the public API. Has to be public only because it is a part of the
632
 * DistortedSlave interface, which should really be a class that we extend here instead but
633
 * Java has no multiple inheritance.
634
 *
635
 * @y.exclude
636
 */
637
  public void doWork()
638
    {
639
    int num = mJobs.size();
640
    Job job;
641

    
642
    int numChanges=0;
643

    
644
    for(int i=0; i<num; i++)
645
      {
646
      job = mJobs.remove(0);
647

    
648
      switch(job.type)
649
        {
650
        case ATTACH: numChanges++;
651
                     if( mChildren==null ) mChildren = new ArrayList<>(2);
652
                     job.node.mParent = this;
653
                     job.node.mSurfaceParent = null;
654
                     DistortedMaster.addSorted(mChildren,job.node);
655
                     mNumChildren[0]++;
656
                     break;
657
        case DETACH: numChanges++;
658
                     if( mNumChildren[0]>0 && mChildren.remove(job.node) )
659
                       {
660
                       job.node.mParent = null;
661
                       job.node.mSurfaceParent = null;
662
                       mNumChildren[0]--;
663
                       }
664
                     break;
665
        case DETALL: numChanges++;
666
                     if( mNumChildren[0]>0 )
667
                       {
668
                       DistortedNode tmp;
669

    
670
                       for(int j=mNumChildren[0]-1; j>=0; j--)
671
                         {
672
                         tmp = mChildren.remove(j);
673
                         tmp.mParent = null;
674
                         tmp.mSurfaceParent = null;
675
                         }
676

    
677
                       mNumChildren[0] = 0;
678
                       }
679
                     break;
680
        case SORT  : mChildren.remove(job.node);
681
                     DistortedMaster.addSorted(mChildren,job.node);
682
                     break;
683
        }
684
      }
685

    
686
    if( numChanges>0 ) adjustIsomorphism();
687
    }
688

    
689
///////////////////////////////////////////////////////////////////////////////////////////////////
690
/**
691
 * Returns the DistortedEffects object that's in the Node.
692
 * 
693
 * @return The DistortedEffects contained in the Node.
694
 */
695
  public DistortedEffects getEffects()
696
    {
697
    return mEffects;
698
    }
699

    
700
///////////////////////////////////////////////////////////////////////////////////////////////////
701
/**
702
 * Returns the DistortedInputSurface object that's in the Node.
703
 *
704
 * @return The DistortedInputSurface contained in the Node.
705
 */
706
  public DistortedInputSurface getSurface()
707
    {
708
    return mSurface;
709
    }
710

    
711
///////////////////////////////////////////////////////////////////////////////////////////////////
712
/**
713
 * Returns the Mesh object that's in the Node.
714
 *
715
 * @return Mesh contained in the Node.
716
 */
717
  public MeshObject getMesh()
718
    {
719
    return mMesh;
720
    }
721

    
722
///////////////////////////////////////////////////////////////////////////////////////////////////
723
/**
724
 * Resizes the DistortedFramebuffer object that we render this Node to.
725
 */
726
  public void resize(int width, int height)
727
    {
728
    mFboW = width;
729
    mFboH = height;
730

    
731
    if ( mData.mFBO !=null )
732
      {
733
      // TODO: potentially allocate a new NodeData if we have to
734
      mData.mFBO.resize(width,height);
735
      }
736
    }
737

    
738
///////////////////////////////////////////////////////////////////////////////////////////////////
739
/**
740
 * Enables/disables DEPTH and STENCIL buffers in the Framebuffer object that we render this Node to.
741
 */
742
  public void enableDepthStencil(int depthStencil)
743
    {
744
    mFboDepthStencil = depthStencil;
745

    
746
    if ( mData.mFBO !=null )
747
      {
748
      // TODO: potentially allocate a new NodeData if we have to
749
      mData.mFBO.enableDepthStencil(depthStencil);
750
      }
751
    }
752

    
753
///////////////////////////////////////////////////////////////////////////////////////////////////
754
// APIs that control how to set the OpenGL state just before rendering this Node.
755
///////////////////////////////////////////////////////////////////////////////////////////////////
756
/**
757
 * When rendering this Node, use ColorMask (r,g,b,a).
758
 *
759
 * @param r Write to the RED color channel when rendering this Node?
760
 * @param g Write to the GREEN color channel when rendering this Node?
761
 * @param b Write to the BLUE color channel when rendering this Node?
762
 * @param a Write to the ALPHA channel when rendering this Node?
763
 */
764
  @SuppressWarnings("unused")
765
  public void glColorMask(boolean r, boolean g, boolean b, boolean a)
766
    {
767
    mState.glColorMask(r,g,b,a);
768
    }
769

    
770
///////////////////////////////////////////////////////////////////////////////////////////////////
771
/**
772
 * When rendering this Node, switch on writing to Depth buffer?
773
 *
774
 * @param mask Write to the Depth buffer when rendering this Node?
775
 */
776
  @SuppressWarnings("unused")
777
  public void glDepthMask(boolean mask)
778
    {
779
    mState.glDepthMask(mask);
780
    }
781

    
782
///////////////////////////////////////////////////////////////////////////////////////////////////
783
/**
784
 * When rendering this Node, which bits of the Stencil buffer to write to?
785
 *
786
 * @param mask Marks the bits of the Stencil buffer we will write to when rendering this Node.
787
 */
788
  @SuppressWarnings("unused")
789
  public void glStencilMask(int mask)
790
    {
791
    mState.glStencilMask(mask);
792
    }
793

    
794
///////////////////////////////////////////////////////////////////////////////////////////////////
795
/**
796
 * When rendering this Node, which Tests to enable?
797
 *
798
 * @param test Valid values: GL_DEPTH_TEST, GL_STENCIL_TEST, GL_BLEND
799
 */
800
  @SuppressWarnings("unused")
801
  public void glEnable(int test)
802
    {
803
    mState.glEnable(test);
804
    }
805

    
806
///////////////////////////////////////////////////////////////////////////////////////////////////
807
/**
808
 * When rendering this Node, which Tests to enable?
809
 *
810
 * @param test Valid values: GL_DEPTH_TEST, GL_STENCIL_TEST, GL_BLEND
811
 */
812
  @SuppressWarnings("unused")
813
  public void glDisable(int test)
814
    {
815
    mState.glDisable(test);
816
    }
817

    
818
///////////////////////////////////////////////////////////////////////////////////////////////////
819
/**
820
 * When rendering this Node, use the following StencilFunc.
821
 *
822
 * @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
823
 * @param ref  Reference valut to compare our stencil with.
824
 * @param mask Mask used when comparing.
825
 */
826
  @SuppressWarnings("unused")
827
  public void glStencilFunc(int func, int ref, int mask)
828
    {
829
    mState.glStencilFunc(func,ref,mask);
830
    }
831

    
832
///////////////////////////////////////////////////////////////////////////////////////////////////
833
/**
834
 * When rendering this Node, use the following StencilOp.
835
 * <p>
836
 * Valid values of all 3 parameters: GL_KEEP, GL_ZERO, GL_REPLACE, GL_INCR, GL_DECR, GL_INVERT, GL_INCR_WRAP, GL_DECR_WRAP
837
 *
838
 * @param sfail  What to do when Stencil Test fails.
839
 * @param dpfail What to do when Depth Test fails.
840
 * @param dppass What to do when Depth Test passes.
841
 */
842
  @SuppressWarnings("unused")
843
  public void glStencilOp(int sfail, int dpfail, int dppass)
844
    {
845
    mState.glStencilOp(sfail,dpfail,dppass);
846
    }
847

    
848
///////////////////////////////////////////////////////////////////////////////////////////////////
849
/**
850
 * When rendering this Node, use the following DepthFunc.
851
 *
852
 * @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
853
 */
854
  @SuppressWarnings("unused")
855
  public void glDepthFunc(int func)
856
    {
857
    mState.glDepthFunc(func);
858
    }
859

    
860
///////////////////////////////////////////////////////////////////////////////////////////////////
861
/**
862
 * When rendering this Node, use the following Blending mode.
863
 * <p>
864
 * Valid values: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
865
 *               GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
866
 *               GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_SRC_ALPHA_SATURATE
867
 *
868
 * @param src Source Blend function
869
 * @param dst Destination Blend function
870
 */
871
  @SuppressWarnings("unused")
872
  public void glBlendFunc(int src, int dst)
873
    {
874
    mState.glBlendFunc(src,dst);
875
    }
876

    
877
///////////////////////////////////////////////////////////////////////////////////////////////////
878
/**
879
 * Before rendering this Node, clear the following buffers.
880
 * <p>
881
 * Valid values: 0, or bitwise OR of one or more values from the set GL_COLOR_BUFFER_BIT,
882
 *               GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT.
883
 * Default: 0
884
 *
885
 * @param mask bitwise OR of BUFFER_BITs to clear.
886
 */
887
  @SuppressWarnings("unused")
888
  public void glClear(int mask)
889
    {
890
    mState.glClear(mask);
891
    }
892
  }
(6-6/22)