Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedNode.java @ 89de975c

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;
21

    
22
import java.util.ArrayList;
23
import java.util.Collections;
24
import java.util.HashMap;
25

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

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

    
47
  private class Job
48
    {
49
    int type;
50
    DistortedNode node;
51
    DistortedEffectsPostprocess dep;
52

    
53
    Job(int t, DistortedNode n, DistortedEffectsPostprocess d)
54
      {
55
      type = t;
56
      node = n;
57
      dep  = d;
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 DistortedEffectsPostprocess mPostprocess;
71
  private DistortedInputSurface mSurface;
72
  private DistortedRenderState mState;
73
  private NodeData mData;
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
      newData.mFBO = new DistortedFramebuffer(DistortedFramebuffer.DEPTH_NO_STENCIL, DistortedSurface.TYPE_TREE, mSurface.getWidth(),mSurface.getHeight());
249
      //android.util.Log.d("NODE", "creating new FBO "+newData.mFBO.getID() );
250
      }
251

    
252
    mData = newData;
253

    
254
    if( mParent!=null ) mParent.adjustIsomorphism();
255
    }
256

    
257
///////////////////////////////////////////////////////////////////////////////////////////////////
258
// return the total number of render calls issued
259

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

    
264
    if( input.setAsInput() )
265
      {
266
      mState.apply();
267
      mEffects.drawPriv(mSurface.getWidth()/2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime);
268
      return 1;
269
      }
270

    
271
    return 0;
272
    }
273

    
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275
// return the total number of render calls issued
276

    
277
  int renderRecursive(long currTime)
278
    {
279
    int numRenders = 0;
280

    
281
    if( mNumChildren[0]>0 && mData.currTime!=currTime )
282
      {
283
      mData.currTime = currTime;
284

    
285
      for (int i=0; i<mNumChildren[0]; i++)
286
        {
287
        numRenders += mChildren.get(i).renderRecursive(currTime);
288
        }
289

    
290
      if( mData.mFBO==null )
291
        {
292
        mData.mFBO = new DistortedFramebuffer(DistortedFramebuffer.DEPTH_NO_STENCIL, DistortedSurface.TYPE_TREE, mSurface.getWidth(),mSurface.getHeight());
293
        }
294

    
295
      mData.mFBO.setAsOutput(currTime);
296

    
297
      if( mSurface.setAsInput() )
298
        {
299
        numRenders++;
300
        DistortedEffects.blitPriv(mData.mFBO);
301
        }
302

    
303
      numRenders += mData.mFBO.renderChildren(currTime,mNumChildren[0],mChildren);
304
      }
305

    
306
    return numRenders;
307
    }
308

    
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310

    
311
  private void newJob(int t, DistortedNode n, DistortedEffectsPostprocess d)
312
    {
313
    mJobs.add(new Job(t,n,d));
314
    }
315

    
316
///////////////////////////////////////////////////////////////////////////////////////////////////
317

    
318
  void setPost(DistortedEffectsPostprocess dep)
319
    {
320
    mPostprocess = dep;
321
    }
322

    
323
///////////////////////////////////////////////////////////////////////////////////////////////////
324

    
325
  void setSurfaceParent(DistortedOutputSurface dep)
326
    {
327
    mSurfaceParent = dep;
328
    mParent = null;
329
    }
330

    
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332
// PUBLIC API
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334
/**
335
 * Constructs new Node.
336
 *     
337
 * @param surface InputSurface to put into the new Node.
338
 * @param effects DistortedEffects to put into the new Node.
339
 * @param mesh MeshObject to put into the new Node.
340
 */
341
  public DistortedNode(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
342
    {
343
    mSurface       = surface;
344
    mEffects       = effects;
345
    mPostprocess   = null;
346
    mMesh          = mesh;
347
    mState         = new DistortedRenderState();
348
    mChildren      = null;
349
    mNumChildren   = new int[1];
350
    mNumChildren[0]= 0;
351
    mParent        = null;
352
    mSurfaceParent = null;
353

    
354
    ArrayList<Long> list = new ArrayList<>();
355
    list.add(mSurface.getID());
356
    list.add(-mEffects.getID());
357

    
358
    mData = mMapNodeID.get(list);
359
   
360
    if( mData!=null )
361
      {
362
      mData.numPointingNodes++;
363
      }
364
    else
365
      {
366
      mData = new NodeData(++mNextNodeID,list);
367
      mMapNodeID.put(list, mData);
368
      }
369
    }
370

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////  
372
/**
373
 * Copy-constructs new Node from another Node.
374
 *     
375
 * @param node The DistortedNode to copy data from.
376
 * @param flags bit field composed of a subset of the following:
377
 *        {@link Distorted#CLONE_SURFACE},  {@link Distorted#CLONE_MATRIX}, {@link Distorted#CLONE_VERTEX},
378
 *        {@link Distorted#CLONE_FRAGMENT} and {@link Distorted#CLONE_CHILDREN}.
379
 *        For example flags = CLONE_SURFACE | CLONE_CHILDREN.
380
 */
381
  public DistortedNode(DistortedNode node, int flags)
382
    {
383
    mEffects      = new DistortedEffects(node.mEffects,flags);
384
    mPostprocess  = null;
385
    mMesh         = node.mMesh;
386
    mState        = new DistortedRenderState();
387
    mParent       = null;
388
    mSurfaceParent= null;
389

    
390
    if( (flags & Distorted.CLONE_SURFACE) != 0 )
391
      {
392
      mSurface = node.mSurface;
393
      }
394
    else
395
      {
396
      int w = node.mSurface.getWidth();
397
      int h = node.mSurface.getHeight();
398

    
399
      if( node.mSurface instanceof DistortedTexture )
400
        {
401
        mSurface = new DistortedTexture(w,h, DistortedSurface.TYPE_TREE);
402
        }
403
      else if( node.mSurface instanceof DistortedFramebuffer )
404
        {
405
        int depthStencil = DistortedFramebuffer.NO_DEPTH_STENCIL;
406

    
407
        if( ((DistortedFramebuffer) node.mSurface).hasDepth() )
408
          {
409
          boolean hasStencil = ((DistortedFramebuffer) node.mSurface).hasStencil();
410
          depthStencil = (hasStencil ? DistortedFramebuffer.BOTH_DEPTH_STENCIL:DistortedFramebuffer.DEPTH_NO_STENCIL);
411
          }
412

    
413
        mSurface = new DistortedFramebuffer(depthStencil,DistortedSurface.TYPE_TREE,w,h);
414
        }
415
      }
416
    if( (flags & Distorted.CLONE_CHILDREN) != 0 )
417
      {
418
      if( node.mChildren==null )     // do NOT copy over the NULL!
419
        {
420
        node.mChildren = new ArrayList<>(2);
421
        }
422

    
423
      mChildren = node.mChildren;
424
      mNumChildren = node.mNumChildren;
425
      }
426
    else
427
      {
428
      mChildren = null;
429
      mNumChildren = new int[1];
430
      mNumChildren[0] = 0;
431
      }
432
   
433
    ArrayList<Long> list = generateIDList();
434
   
435
    mData = mMapNodeID.get(list);
436
   
437
    if( mData!=null )
438
      {
439
      mData.numPointingNodes++;
440
      }
441
    else
442
      {
443
      mData = new NodeData(++mNextNodeID,list);
444
      mMapNodeID.put(list, mData);
445
      }
446
    }
447

    
448
///////////////////////////////////////////////////////////////////////////////////////////////////
449
/**
450
 * Adds a new child to the last position in the list of our Node's children.
451
 * <p>
452
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
453
 * DistortedMaster (by calling doWork())
454
 *
455
 * @param node The new Node to add.
456
 */
457
  public void attach(DistortedNode node)
458
    {
459
    mJobs.add(new Job(ATTACH,node,null));
460
    DistortedMaster.newSlave(this);
461
    }
462

    
463
///////////////////////////////////////////////////////////////////////////////////////////////////
464
/**
465
 * Adds a new child to the last position in the list of our Node's children.
466
 * <p>
467
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
468
 * DistortedMaster (by calling doWork())
469
 *
470
 * @param surface InputSurface to initialize our child Node with.
471
 * @param effects DistortedEffects to initialize our child Node with.
472
 * @param mesh MeshObject to initialize our child Node with.
473
 * @return the newly constructed child Node, or null if we couldn't allocate resources.
474
 */
475
  public DistortedNode attach(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
476
    {
477
    DistortedNode node = new DistortedNode(surface,effects,mesh);
478
    mJobs.add(new Job(ATTACH,node,null));
479
    DistortedMaster.newSlave(this);
480
    return node;
481
    }
482

    
483
///////////////////////////////////////////////////////////////////////////////////////////////////
484
/**
485
 * Removes the first occurrence of a specified child from the list of children of our Node.
486
 * <p>
487
 * We cannot do this mid-render - actual detachment will be done just before the next render, by the
488
 * DistortedMaster (by calling doWork())
489
 *
490
 * @param node The Node to remove.
491
 */
492
  public void detach(DistortedNode node)
493
    {
494
    mJobs.add(new Job(DETACH,node,null));
495
    DistortedMaster.newSlave(this);
496
    }
497

    
498
///////////////////////////////////////////////////////////////////////////////////////////////////
499
/**
500
 * Removes the first occurrence of a specified child from the list of children of our Node.
501
 * <p>
502
 * A bit questionable method as there can be many different Nodes attached as children, some
503
 * of them having the same Effects but - for instance - different Mesh. Use with care.
504
 * <p>
505
 * We cannot do this mid-render - actual detachment will be done just before the next render, by the
506
 * DistortedMaster (by calling doWork())
507
 *
508
 * @param effects DistortedEffects to remove.
509
 */
510
  public void detach(DistortedEffects effects)
511
    {
512
    long id = effects.getID();
513
    DistortedNode node;
514
    boolean detached = false;
515

    
516
    for(int i=0; i<mNumChildren[0]; i++)
517
      {
518
      node = mChildren.get(i);
519

    
520
      if( node.getEffects().getID()==id )
521
        {
522
        detached = true;
523
        mJobs.add(new Job(DETACH,node,null));
524
        DistortedMaster.newSlave(this);
525
        break;
526
        }
527
      }
528

    
529
    if( !detached )
530
      {
531
      // if we failed to detach any, it still might be the case that
532
      // there's an ATTACH job that we need to cancel.
533
      int num = mJobs.size();
534
      Job job;
535

    
536
      for(int i=0; i<num; i++)
537
        {
538
        job = mJobs.get(i);
539

    
540
        if( job.type==ATTACH && job.node.getEffects()==effects )
541
          {
542
          mJobs.remove(i);
543
          break;
544
          }
545
        }
546
      }
547
    }
548

    
549
///////////////////////////////////////////////////////////////////////////////////////////////////
550
/**
551
 * Removes all children Nodes.
552
 * <p>
553
 * We cannot do this mid-render - actual detachment will be done just before the next render, by the
554
 * DistortedMaster (by calling doWork())
555
 */
556
  public void detachAll()
557
    {
558
    mJobs.add(new Job(DETALL,null,null));
559
    DistortedMaster.newSlave(this);
560
    }
561

    
562
///////////////////////////////////////////////////////////////////////////////////////////////////
563
/**
564
 * This is not really part of the public API. Has to be public only because it is a part of the
565
 * DistortedSlave interface, which should really be a class that we extend here instead but
566
 * Java has no multiple inheritance.
567
 *
568
 * @y.exclude
569
 */
570
  public void doWork()
571
    {
572
    int num = mJobs.size();
573
    Job job;
574

    
575
    int numChanges=0;
576

    
577
    for(int i=0; i<num; i++)
578
      {
579
      job = mJobs.remove(0);
580

    
581
      switch(job.type)
582
        {
583
        case ATTACH: numChanges++;
584
                     if( mChildren==null ) mChildren = new ArrayList<>(2);
585
                     job.node.mParent = this;
586
                     job.node.mSurfaceParent = null;
587
                     DistortedMaster.addSorted(mChildren,job.node);
588
                     mNumChildren[0]++;
589
                     break;
590
        case DETACH: numChanges++;
591
                     if( mNumChildren[0]>0 && mChildren.remove(job.node) )
592
                       {
593
                       job.node.mParent = null;
594
                       job.node.mSurfaceParent = null;
595
                       mNumChildren[0]--;
596
                       }
597
                     break;
598
        case DETALL: numChanges++;
599
                     if( mNumChildren[0]>0 )
600
                       {
601
                       DistortedNode tmp;
602

    
603
                       for(int j=mNumChildren[0]-1; j>=0; j--)
604
                         {
605
                         tmp = mChildren.remove(j);
606
                         tmp.mParent = null;
607
                         tmp.mSurfaceParent = null;
608
                         }
609

    
610
                       mNumChildren[0] = 0;
611
                       }
612
                     break;
613
        case SORT  : job.node.mPostprocess = job.dep;
614
                     mChildren.remove(job.node);
615
                     DistortedMaster.addSorted(mChildren,job.node);
616
                     break;
617
        }
618
      }
619

    
620
    if( numChanges>0 ) adjustIsomorphism();
621
    }
622
///////////////////////////////////////////////////////////////////////////////////////////////////
623
/**
624
 * Sets the Postprocessing Effects we will apply to the temporary buffer this Node - and fellow siblings
625
 * with the same Effects - will get rendered to.
626
 * <p>
627
 * For efficiency reasons, it is very important to assign the very same DistortedEffectsPostprocess
628
 * object to all the DistortedNode siblings that are supposed to be postprocessed in the same way,
629
 * because only then will the library assign all such siblings to the same 'Bucket' which gets rendered
630
 * to the same offscreen buffer which then gets postprocessed in one go and subsequently merged to the
631
 * target Surface.
632
 */
633
  public void setPostprocessEffects(DistortedEffectsPostprocess dep)
634
    {
635
    if( mParent!=null )
636
      {
637
      mParent.newJob(SORT, this, dep);
638
      DistortedMaster.newSlave(mParent);
639
      }
640
    else if( mSurfaceParent!=null )
641
      {
642
      mSurfaceParent.newJob(SORT, this, dep);
643
      DistortedMaster.newSlave(mSurfaceParent);
644
      }
645
    else
646
      {
647
      mPostprocess = dep;
648
      }
649
    }
650

    
651
///////////////////////////////////////////////////////////////////////////////////////////////////
652
/**
653
 * Returns the DistortedEffectsPostprocess object that's in the Node.
654
 *
655
 * @return The DistortedEffectsPostprocess contained in the Node.
656
 */
657
  public DistortedEffectsPostprocess getEffectsPostprocess()
658
    {
659
    return mPostprocess;
660
    }
661

    
662
///////////////////////////////////////////////////////////////////////////////////////////////////
663
/**
664
 * Returns the DistortedEffects object that's in the Node.
665
 * 
666
 * @return The DistortedEffects contained in the Node.
667
 */
668
  public DistortedEffects getEffects()
669
    {
670
    return mEffects;
671
    }
672

    
673
///////////////////////////////////////////////////////////////////////////////////////////////////
674
/**
675
 * Returns the DistortedInputSurface object that's in the Node.
676
 *
677
 * @return The DistortedInputSurface contained in the Node.
678
 */
679
  public DistortedInputSurface getSurface()
680
    {
681
    return mSurface;
682
    }
683

    
684
///////////////////////////////////////////////////////////////////////////////////////////////////
685
/**
686
 * Returns the DistortedFramebuffer object that's in the Node.
687
 *
688
 * @return The DistortedFramebuffer contained in the Node.
689
 */
690
  public DistortedFramebuffer getFramebuffer()
691
    {
692
    return mData.mFBO;
693
    }
694

    
695
///////////////////////////////////////////////////////////////////////////////////////////////////
696
// APIs that control how to set the OpenGL state just before rendering this Node.
697
///////////////////////////////////////////////////////////////////////////////////////////////////
698
/**
699
 * When rendering this Node, use ColorMask (r,g,b,a).
700
 *
701
 * @param r Write to the RED color channel when rendering this Node?
702
 * @param g Write to the GREEN color channel when rendering this Node?
703
 * @param b Write to the BLUE color channel when rendering this Node?
704
 * @param a Write to the ALPHA channel when rendering this Node?
705
 */
706
  @SuppressWarnings("unused")
707
  public void glColorMask(boolean r, boolean g, boolean b, boolean a)
708
    {
709
    mState.glColorMask(r,g,b,a);
710
    }
711

    
712
///////////////////////////////////////////////////////////////////////////////////////////////////
713
/**
714
 * When rendering this Node, switch on writing to Depth buffer?
715
 *
716
 * @param mask Write to the Depth buffer when rendering this Node?
717
 */
718
  @SuppressWarnings("unused")
719
  public void glDepthMask(boolean mask)
720
    {
721
    mState.glDepthMask(mask);
722
    }
723

    
724
///////////////////////////////////////////////////////////////////////////////////////////////////
725
/**
726
 * When rendering this Node, which bits of the Stencil buffer to write to?
727
 *
728
 * @param mask Marks the bits of the Stencil buffer we will write to when rendering this Node.
729
 */
730
  @SuppressWarnings("unused")
731
  public void glStencilMask(int mask)
732
    {
733
    mState.glStencilMask(mask);
734
    }
735

    
736
///////////////////////////////////////////////////////////////////////////////////////////////////
737
/**
738
 * When rendering this Node, which Tests to enable?
739
 *
740
 * @param test Valid values: GL_DEPTH_TEST, GL_STENCIL_TEST, GL_BLEND
741
 */
742
  @SuppressWarnings("unused")
743
  public void glEnable(int test)
744
    {
745
    mState.glEnable(test);
746
    }
747

    
748
///////////////////////////////////////////////////////////////////////////////////////////////////
749
/**
750
 * When rendering this Node, which Tests to enable?
751
 *
752
 * @param test Valid values: GL_DEPTH_TEST, GL_STENCIL_TEST, GL_BLEND
753
 */
754
  @SuppressWarnings("unused")
755
  public void glDisable(int test)
756
    {
757
    mState.glDisable(test);
758
    }
759

    
760
///////////////////////////////////////////////////////////////////////////////////////////////////
761
/**
762
 * When rendering this Node, use the following StencilFunc.
763
 *
764
 * @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
765
 * @param ref  Reference valut to compare our stencil with.
766
 * @param mask Mask used when comparing.
767
 */
768
  @SuppressWarnings("unused")
769
  public void glStencilFunc(int func, int ref, int mask)
770
    {
771
    mState.glStencilFunc(func,ref,mask);
772
    }
773

    
774
///////////////////////////////////////////////////////////////////////////////////////////////////
775
/**
776
 * When rendering this Node, use the following StencilOp.
777
 * <p>
778
 * Valid values of all 3 parameters: GL_KEEP, GL_ZERO, GL_REPLACE, GL_INCR, GL_DECR, GL_INVERT, GL_INCR_WRAP, GL_DECR_WRAP
779
 *
780
 * @param sfail  What to do when Stencil Test fails.
781
 * @param dpfail What to do when Depth Test fails.
782
 * @param dppass What to do when Depth Test passes.
783
 */
784
  @SuppressWarnings("unused")
785
  public void glStencilOp(int sfail, int dpfail, int dppass)
786
    {
787
    mState.glStencilOp(sfail,dpfail,dppass);
788
    }
789

    
790
///////////////////////////////////////////////////////////////////////////////////////////////////
791
/**
792
 * When rendering this Node, use the following DepthFunc.
793
 *
794
 * @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
795
 */
796
  @SuppressWarnings("unused")
797
  public void glDepthFunc(int func)
798
    {
799
    mState.glDepthFunc(func);
800
    }
801

    
802
///////////////////////////////////////////////////////////////////////////////////////////////////
803
/**
804
 * When rendering this Node, use the following Blending mode.
805
 * <p>
806
 * Valid values: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
807
 *               GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
808
 *               GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_SRC_ALPHA_SATURATE
809
 *
810
 * @param src Source Blend function
811
 * @param dst Destination Blend function
812
 */
813
  @SuppressWarnings("unused")
814
  public void glBlendFunc(int src, int dst)
815
    {
816
    mState.glBlendFunc(src,dst);
817
    }
818

    
819
///////////////////////////////////////////////////////////////////////////////////////////////////
820
/**
821
 * Before rendering this Node, clear the following buffers.
822
 * <p>
823
 * Valid values: 0, or bitwise OR of one or more values from the set GL_COLOR_BUFFER_BIT,
824
 *               GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT.
825
 * Default: 0
826
 *
827
 * @param mask bitwise OR of BUFFER_BITs to clear.
828
 */
829
  @SuppressWarnings("unused")
830
  public void glClear(int mask)
831
    {
832
    mState.glClear(mask);
833
    }
834
  }
(7-7/26)