Project

General

Profile

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

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

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(true, 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(true, 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
        boolean hasDepth = ((DistortedFramebuffer) node.mSurface).hasDepth();
406
        mSurface = new DistortedFramebuffer(hasDepth,DistortedSurface.TYPE_TREE,w,h);
407
        }
408
      }
409
    if( (flags & Distorted.CLONE_CHILDREN) != 0 )
410
      {
411
      if( node.mChildren==null )     // do NOT copy over the NULL!
412
        {
413
        node.mChildren = new ArrayList<>(2);
414
        }
415

    
416
      mChildren = node.mChildren;
417
      mNumChildren = node.mNumChildren;
418
      }
419
    else
420
      {
421
      mChildren = null;
422
      mNumChildren = new int[1];
423
      mNumChildren[0] = 0;
424
      }
425
   
426
    ArrayList<Long> list = generateIDList();
427
   
428
    mData = mMapNodeID.get(list);
429
   
430
    if( mData!=null )
431
      {
432
      mData.numPointingNodes++;
433
      }
434
    else
435
      {
436
      mData = new NodeData(++mNextNodeID,list);
437
      mMapNodeID.put(list, mData);
438
      }
439
    }
440

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

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

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

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

    
509
    for(int i=0; i<mNumChildren[0]; i++)
510
      {
511
      node = mChildren.get(i);
512

    
513
      if( node.getEffects().getID()==id )
514
        {
515
        detached = true;
516
        mJobs.add(new Job(DETACH,node,null));
517
        DistortedMaster.newSlave(this);
518
        break;
519
        }
520
      }
521

    
522
    if( !detached )
523
      {
524
      // if we failed to detach any, it still might be the case that
525
      // there's an ATTACH job that we need to cancel.
526
      int num = mJobs.size();
527
      Job job;
528

    
529
      for(int i=0; i<num; i++)
530
        {
531
        job = mJobs.get(i);
532

    
533
        if( job.type==ATTACH && job.node.getEffects()==effects )
534
          {
535
          mJobs.remove(i);
536
          break;
537
          }
538
        }
539
      }
540
    }
541

    
542
///////////////////////////////////////////////////////////////////////////////////////////////////
543
/**
544
 * Removes all children Nodes.
545
 * <p>
546
 * We cannot do this mid-render - actual detachment will be done just before the next render, by the
547
 * DistortedMaster (by calling doWork())
548
 */
549
  public void detachAll()
550
    {
551
    mJobs.add(new Job(DETALL,null,null));
552
    DistortedMaster.newSlave(this);
553
    }
554

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

    
568
    int numChanges=0;
569

    
570
    for(int i=0; i<num; i++)
571
      {
572
      job = mJobs.remove(0);
573

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

    
596
                       for(int j=mNumChildren[0]-1; j>=0; j--)
597
                         {
598
                         tmp = mChildren.remove(j);
599
                         tmp.mParent = null;
600
                         tmp.mSurfaceParent = null;
601
                         }
602

    
603
                       mNumChildren[0] = 0;
604
                       }
605
                     break;
606
        case SORT  : job.node.mPostprocess = job.dep;
607
                     mChildren.remove(job.node);
608
                     DistortedMaster.addSorted(mChildren,job.node);
609
                     break;
610
        }
611
      }
612

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

    
644
///////////////////////////////////////////////////////////////////////////////////////////////////
645
/**
646
 * Returns the DistortedEffectsPostprocess object that's in the Node.
647
 *
648
 * @return The DistortedEffectsPostprocess contained in the Node.
649
 */
650
  public DistortedEffectsPostprocess getEffectsPostprocess()
651
    {
652
    return mPostprocess;
653
    }
654

    
655
///////////////////////////////////////////////////////////////////////////////////////////////////
656
/**
657
 * Returns the DistortedEffects object that's in the Node.
658
 * 
659
 * @return The DistortedEffects contained in the Node.
660
 */
661
  public DistortedEffects getEffects()
662
    {
663
    return mEffects;
664
    }
665

    
666
///////////////////////////////////////////////////////////////////////////////////////////////////
667
/**
668
 * Returns the DistortedInputSurface object that's in the Node.
669
 *
670
 * @return The DistortedInputSurface contained in the Node.
671
 */
672
  public DistortedInputSurface getSurface()
673
    {
674
    return mSurface;
675
    }
676

    
677
///////////////////////////////////////////////////////////////////////////////////////////////////
678
/**
679
 * Returns the DistortedFramebuffer object that's in the Node.
680
 *
681
 * @return The DistortedFramebuffer contained in the Node.
682
 */
683
  public DistortedFramebuffer getFramebuffer()
684
    {
685
    return mData.mFBO;
686
    }
687

    
688

    
689
///////////////////////////////////////////////////////////////////////////////////////////////////
690
/**
691
 * When rendering this Node, use ColorMask (r,g,b,a).
692
 *
693
 * @param r Write to the RED color channel when rendering this Node?
694
 * @param g Write to the GREEN color channel when rendering this Node?
695
 * @param b Write to the BLUE color channel when rendering this Node?
696
 * @param a Write to the ALPHA channel when rendering this Node?
697
 */
698
  @SuppressWarnings("unused")
699
  public void glColorMask(boolean r, boolean g, boolean b, boolean a)
700
    {
701
    mState.glColorMask(r,g,b,a);
702
    }
703

    
704
///////////////////////////////////////////////////////////////////////////////////////////////////
705
/**
706
 * When rendering this Node, switch on writing to Depth buffer?
707
 *
708
 * @param mask Write to the Depth buffer when rendering this Node?
709
 */
710
  @SuppressWarnings("unused")
711
  public void glDepthMask(boolean mask)
712
    {
713
    mState.glDepthMask(mask);
714
    }
715

    
716
///////////////////////////////////////////////////////////////////////////////////////////////////
717
/**
718
 * When rendering this Node, which bits of the Stencil buffer to write to?
719
 *
720
 * @param mask Marks the bits of the Stencil buffer we will write to when rendering this Node.
721
 */
722
  @SuppressWarnings("unused")
723
  public void glStencilMask(int mask)
724
    {
725
    mState.glStencilMask(mask);
726
    }
727

    
728
///////////////////////////////////////////////////////////////////////////////////////////////////
729
/**
730
 * When rendering this Node, which Tests to enable?
731
 *
732
 * @param test Valid values: GL_DEPTH_TEST, GL_STENCIL_TEST, GL_BLEND
733
 */
734
  @SuppressWarnings("unused")
735
  public void glEnable(int test)
736
    {
737
    mState.glEnable(test);
738
    }
739

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

    
752
///////////////////////////////////////////////////////////////////////////////////////////////////
753
/**
754
 * When rendering this Node, use the following StencilFunc.
755
 *
756
 * @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
757
 * @param ref  Reference valut to compare our stencil with.
758
 * @param mask Mask used when comparing.
759
 */
760
  @SuppressWarnings("unused")
761
  public void glStencilFunc(int func, int ref, int mask)
762
    {
763
    mState.glStencilFunc(func,ref,mask);
764
    }
765

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

    
782
///////////////////////////////////////////////////////////////////////////////////////////////////
783
/**
784
 * When rendering this Node, use the following DepthFunc.
785
 *
786
 * @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
787
 */
788
  @SuppressWarnings("unused")
789
  public void glDepthFunc(int func)
790
    {
791
    mState.glDepthFunc(func);
792
    }
793

    
794
///////////////////////////////////////////////////////////////////////////////////////////////////
795
/**
796
 * When rendering this Node, use the following Blending mode.
797
 * <p>
798
 * Valid values: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
799
 *               GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
800
 *               GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_SRC_ALPHA_SATURATE
801
 *
802
 * @param src Source Blend function
803
 * @param dst Destination Blend function
804
 */
805
  @SuppressWarnings("unused")
806
  public void glBlendFunc(int src, int dst)
807
    {
808
    mState.glBlendFunc(src,dst);
809
    }
810
  }
(7-7/24)