Project

General

Profile

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

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

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

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

    
59
  private ArrayList<Job> mJobs = new ArrayList<>();
60

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

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

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

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

    
93
  static synchronized void onPause()
94
    {
95
    NodeData data;
96

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

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

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

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

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

    
119
  private ArrayList<Long> generateIDList()
120
    {
121
    ArrayList<Long> ret = new ArrayList<>();
122

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

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

    
156
    ret.add( 0, mSurface.getID() );
157

    
158
    return ret;
159
    }
160

    
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162
// Debug - print all the Node IDs
163

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

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

    
175
    android.util.Log.e("NODE", tmp);
176

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

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182
// Debug - print contents of the HashMap
183

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

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

    
196
///////////////////////////////////////////////////////////////////////////////////////////////////
197
// tree isomorphism algorithm
198

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

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

    
214
    boolean deleteOldFBO = false;
215
    boolean createNewFBO = false;
216

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

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

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

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

    
270
      return 1;
271
      }
272
    return 0;
273
    }
274

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

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

    
282
    if( input.setAsInput() )
283
      {
284
      surface.setAsOutput(currTime);
285
      mState.apply();
286
      mEffects.drawPriv(mSurface.getWidth()/2.0f, mSurface.getHeight()/2.0f, mMesh, surface, currTime, 0);
287
      return 1;
288
      }
289

    
290
    return 0;
291
    }
292

    
293
///////////////////////////////////////////////////////////////////////////////////////////////////
294
// return the total number of render calls issued
295

    
296
  int renderRecursive(long currTime)
297
    {
298
    int numRenders = 0;
299

    
300
    if( mNumChildren[0]>0 && mData.currTime!=currTime )
301
      {
302
      mData.currTime = currTime;
303

    
304
      for (int i=0; i<mNumChildren[0]; i++)
305
        {
306
        numRenders += mChildren.get(i).renderRecursive(currTime);
307
        }
308

    
309
      if( mData.mFBO==null )
310
        {
311
        int width  = mFboW <= 0 ? mSurface.getWidth()  : mFboW;
312
        int height = mFboH <= 0 ? mSurface.getHeight() : mFboH;
313
        mData.mFBO = new DistortedFramebuffer(1,mFboDepthStencil, DistortedSurface.TYPE_TREE, width, height);
314
        }
315

    
316
      mData.mFBO.setAsOutput(currTime);
317

    
318
      if( mSurface.setAsInput() )
319
        {
320
        numRenders++;
321
        DistortedEffects.blitPriv(mData.mFBO);
322
        }
323

    
324
      numRenders += mData.mFBO.renderChildren(currTime,mNumChildren[0],mChildren);
325
      }
326

    
327
    return numRenders;
328
    }
329

    
330
///////////////////////////////////////////////////////////////////////////////////////////////////
331

    
332
  void setSurfaceParent(DistortedOutputSurface dep)
333
    {
334
    mSurfaceParent = dep;
335
    mParent = null;
336
    }
337

    
338
///////////////////////////////////////////////////////////////////////////////////////////////////
339

    
340
  void sort()
341
    {
342
    if( mParent!=null )
343
      {
344
      mParent.mChildren.remove(this);
345
      DistortedMaster.addSorted(mParent.mChildren,this);
346
      }
347
    else if( mSurfaceParent!=null )
348
      {
349
      ArrayList<DistortedNode> children = mSurfaceParent.getChildren();
350
      children.remove(this);
351
      DistortedMaster.addSorted(children,this);
352
      }
353
    }
354

    
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356
// PUBLIC API
357
///////////////////////////////////////////////////////////////////////////////////////////////////
358
/**
359
 * Constructs new Node.
360
 *     
361
 * @param surface InputSurface to put into the new Node.
362
 * @param effects DistortedEffects to put into the new Node.
363
 * @param mesh MeshObject to put into the new Node.
364
 */
365
  public DistortedNode(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
366
    {
367
    mSurface       = surface;
368
    mEffects       = effects;
369
    mMesh          = mesh;
370
    mState         = new DistortedRenderState();
371
    mChildren      = null;
372
    mNumChildren   = new int[1];
373
    mNumChildren[0]= 0;
374
    mParent        = null;
375
    mSurfaceParent = null;
376

    
377
    mFboW            = 0;  // i.e. take this from
378
    mFboH            = 0;  // mSurface's dimensions
379
    mFboDepthStencil = DistortedFramebuffer.DEPTH_NO_STENCIL;
380

    
381
    ArrayList<Long> list = new ArrayList<>();
382
    list.add(mSurface.getID());
383
    list.add(-mEffects.getID());
384

    
385
    mData = mMapNodeID.get(list);
386
   
387
    if( mData!=null )
388
      {
389
      mData.numPointingNodes++;
390
      }
391
    else
392
      {
393
      mData = new NodeData(++mNextNodeID,list);
394
      mMapNodeID.put(list, mData);
395
      }
396

    
397
    mEffects.newNode(this);
398
    }
399

    
400
///////////////////////////////////////////////////////////////////////////////////////////////////  
401
/**
402
 * Copy-constructs new Node from another Node.
403
 *     
404
 * @param node The DistortedNode to copy data from.
405
 * @param flags bit field composed of a subset of the following:
406
 *        {@link Distorted#CLONE_SURFACE},  {@link Distorted#CLONE_MATRIX}, {@link Distorted#CLONE_VERTEX},
407
 *        {@link Distorted#CLONE_FRAGMENT} and {@link Distorted#CLONE_CHILDREN}.
408
 *        For example flags = CLONE_SURFACE | CLONE_CHILDREN.
409
 */
410
  public DistortedNode(DistortedNode node, int flags)
411
    {
412
    mEffects      = new DistortedEffects(node.mEffects,flags);
413
    mMesh         = node.mMesh;
414
    mState        = new DistortedRenderState();
415
    mParent       = null;
416
    mSurfaceParent= null;
417

    
418
    mFboW            = node.mFboW;
419
    mFboH            = node.mFboH;
420
    mFboDepthStencil = node.mFboDepthStencil;
421

    
422
    if( (flags & Distorted.CLONE_SURFACE) != 0 )
423
      {
424
      mSurface = node.mSurface;
425
      }
426
    else
427
      {
428
      int w = node.mSurface.getWidth();
429
      int h = node.mSurface.getHeight();
430

    
431
      if( node.mSurface instanceof DistortedTexture )
432
        {
433
        mSurface = new DistortedTexture(w,h, DistortedSurface.TYPE_TREE);
434
        }
435
      else if( node.mSurface instanceof DistortedFramebuffer )
436
        {
437
        int depthStencil = DistortedFramebuffer.NO_DEPTH_NO_STENCIL;
438

    
439
        if( ((DistortedFramebuffer) node.mSurface).hasDepth() )
440
          {
441
          boolean hasStencil = ((DistortedFramebuffer) node.mSurface).hasStencil();
442
          depthStencil = (hasStencil ? DistortedFramebuffer.BOTH_DEPTH_STENCIL:DistortedFramebuffer.DEPTH_NO_STENCIL);
443
          }
444

    
445
        mSurface = new DistortedFramebuffer(1,depthStencil,DistortedSurface.TYPE_TREE,w,h);
446
        }
447
      }
448
    if( (flags & Distorted.CLONE_CHILDREN) != 0 )
449
      {
450
      if( node.mChildren==null )     // do NOT copy over the NULL!
451
        {
452
        node.mChildren = new ArrayList<>(2);
453
        }
454

    
455
      mChildren = node.mChildren;
456
      mNumChildren = node.mNumChildren;
457
      }
458
    else
459
      {
460
      mChildren = null;
461
      mNumChildren = new int[1];
462
      mNumChildren[0] = 0;
463
      }
464
   
465
    ArrayList<Long> list = generateIDList();
466
   
467
    mData = mMapNodeID.get(list);
468
   
469
    if( mData!=null )
470
      {
471
      mData.numPointingNodes++;
472
      }
473
    else
474
      {
475
      mData = new NodeData(++mNextNodeID,list);
476
      mMapNodeID.put(list, mData);
477
      }
478

    
479
    mEffects.newNode(this);
480
    }
481

    
482
///////////////////////////////////////////////////////////////////////////////////////////////////
483
/**
484
 * Adds a new child to the last position in the list of our Node's children.
485
 * <p>
486
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
487
 * DistortedMaster (by calling doWork())
488
 *
489
 * @param node The new Node to add.
490
 */
491
  public void attach(DistortedNode node)
492
    {
493
    mJobs.add(new Job(ATTACH,node));
494
    DistortedMaster.newSlave(this);
495
    }
496

    
497
///////////////////////////////////////////////////////////////////////////////////////////////////
498
/**
499
 * Adds a new child to the last position in the list of our Node's children.
500
 * <p>
501
 * We cannot do this mid-render - actual attachment will be done just before the next render, by the
502
 * DistortedMaster (by calling doWork())
503
 *
504
 * @param surface InputSurface to initialize our child Node with.
505
 * @param effects DistortedEffects to initialize our child Node with.
506
 * @param mesh MeshObject to initialize our child Node with.
507
 * @return the newly constructed child Node, or null if we couldn't allocate resources.
508
 */
509
  public DistortedNode attach(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
510
    {
511
    DistortedNode node = new DistortedNode(surface,effects,mesh);
512
    mJobs.add(new Job(ATTACH,node));
513
    DistortedMaster.newSlave(this);
514
    return node;
515
    }
516

    
517
///////////////////////////////////////////////////////////////////////////////////////////////////
518
/**
519
 * Removes the first occurrence of a specified child from the list of children of our Node.
520
 * <p>
521
 * We cannot do this mid-render - actual detachment will be done just before the next render, by the
522
 * DistortedMaster (by calling doWork())
523
 *
524
 * @param node The Node to remove.
525
 */
526
  public void detach(DistortedNode node)
527
    {
528
    mJobs.add(new Job(DETACH,node));
529
    DistortedMaster.newSlave(this);
530
    }
531

    
532
///////////////////////////////////////////////////////////////////////////////////////////////////
533
/**
534
 * Removes the first occurrence of a specified child from the list of children of our Node.
535
 * <p>
536
 * A bit questionable method as there can be many different Nodes attached as children, some
537
 * of them having the same Effects but - for instance - different Mesh. Use with care.
538
 * <p>
539
 * We cannot do this mid-render - actual detachment will be done just before the next render, by the
540
 * DistortedMaster (by calling doWork())
541
 *
542
 * @param effects DistortedEffects to remove.
543
 */
544
  public void detach(DistortedEffects effects)
545
    {
546
    long id = effects.getID();
547
    DistortedNode node;
548
    boolean detached = false;
549

    
550
    for(int i=0; i<mNumChildren[0]; i++)
551
      {
552
      node = mChildren.get(i);
553

    
554
      if( node.getEffects().getID()==id )
555
        {
556
        detached = true;
557
        mJobs.add(new Job(DETACH,node));
558
        DistortedMaster.newSlave(this);
559
        break;
560
        }
561
      }
562

    
563
    if( !detached )
564
      {
565
      // if we failed to detach any, it still might be the case that
566
      // there's an ATTACH job that we need to cancel.
567
      int num = mJobs.size();
568
      Job job;
569

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

    
574
        if( job.type==ATTACH && job.node.getEffects()==effects )
575
          {
576
          mJobs.remove(i);
577
          break;
578
          }
579
        }
580
      }
581
    }
582

    
583
///////////////////////////////////////////////////////////////////////////////////////////////////
584
/**
585
 * Removes all children Nodes.
586
 * <p>
587
 * We cannot do this mid-render - actual detachment will be done just before the next render, by the
588
 * DistortedMaster (by calling doWork())
589
 */
590
  public void detachAll()
591
    {
592
    mJobs.add(new Job(DETALL,null));
593
    DistortedMaster.newSlave(this);
594
    }
595

    
596
///////////////////////////////////////////////////////////////////////////////////////////////////
597
/**
598
 * This is not really part of the public API. Has to be public only because it is a part of the
599
 * DistortedSlave interface, which should really be a class that we extend here instead but
600
 * Java has no multiple inheritance.
601
 *
602
 * @y.exclude
603
 */
604
  public void doWork()
605
    {
606
    int num = mJobs.size();
607
    Job job;
608

    
609
    int numChanges=0;
610

    
611
    for(int i=0; i<num; i++)
612
      {
613
      job = mJobs.remove(0);
614

    
615
      switch(job.type)
616
        {
617
        case ATTACH: numChanges++;
618
                     if( mChildren==null ) mChildren = new ArrayList<>(2);
619
                     job.node.mParent = this;
620
                     job.node.mSurfaceParent = null;
621
                     DistortedMaster.addSorted(mChildren,job.node);
622
                     mNumChildren[0]++;
623
                     break;
624
        case DETACH: numChanges++;
625
                     if( mNumChildren[0]>0 && mChildren.remove(job.node) )
626
                       {
627
                       job.node.mParent = null;
628
                       job.node.mSurfaceParent = null;
629
                       mNumChildren[0]--;
630
                       }
631
                     break;
632
        case DETALL: numChanges++;
633
                     if( mNumChildren[0]>0 )
634
                       {
635
                       DistortedNode tmp;
636

    
637
                       for(int j=mNumChildren[0]-1; j>=0; j--)
638
                         {
639
                         tmp = mChildren.remove(j);
640
                         tmp.mParent = null;
641
                         tmp.mSurfaceParent = null;
642
                         }
643

    
644
                       mNumChildren[0] = 0;
645
                       }
646
                     break;
647
        case SORT  : mChildren.remove(job.node);
648
                     DistortedMaster.addSorted(mChildren,job.node);
649
                     break;
650
        }
651
      }
652

    
653
    if( numChanges>0 ) adjustIsomorphism();
654
    }
655

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

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

    
678
///////////////////////////////////////////////////////////////////////////////////////////////////
679
/**
680
 * Returns the Mesh object that's in the Node.
681
 *
682
 * @return Mesh contained in the Node.
683
 */
684
  public MeshObject getMesh()
685
    {
686
    return mMesh;
687
    }
688

    
689
///////////////////////////////////////////////////////////////////////////////////////////////////
690
/**
691
 * Resizes the DistortedFramebuffer object that we render this Node to.
692
 */
693
  public void resize(int width, int height)
694
    {
695
    mFboW = width;
696
    mFboH = height;
697

    
698
    if ( mData.mFBO !=null )
699
      {
700
      // TODO: potentially allocate a new NodeData if we have to
701
      mData.mFBO.resize(width,height);
702
      }
703
    }
704

    
705
///////////////////////////////////////////////////////////////////////////////////////////////////
706
/**
707
 * Enables/disables DEPTH and STENCIL buffers in the Framebuffer object that we render this Node to.
708
 */
709
  public void enableDepthStencil(int depthStencil)
710
    {
711
    mFboDepthStencil = depthStencil;
712

    
713
    if ( mData.mFBO !=null )
714
      {
715
      // TODO: potentially allocate a new NodeData if we have to
716
      mData.mFBO.enableDepthStencil(depthStencil);
717
      }
718
    }
719

    
720
///////////////////////////////////////////////////////////////////////////////////////////////////
721
// APIs that control how to set the OpenGL state just before rendering this Node.
722
///////////////////////////////////////////////////////////////////////////////////////////////////
723
/**
724
 * When rendering this Node, use ColorMask (r,g,b,a).
725
 *
726
 * @param r Write to the RED color channel when rendering this Node?
727
 * @param g Write to the GREEN color channel when rendering this Node?
728
 * @param b Write to the BLUE color channel when rendering this Node?
729
 * @param a Write to the ALPHA channel when rendering this Node?
730
 */
731
  @SuppressWarnings("unused")
732
  public void glColorMask(boolean r, boolean g, boolean b, boolean a)
733
    {
734
    mState.glColorMask(r,g,b,a);
735
    }
736

    
737
///////////////////////////////////////////////////////////////////////////////////////////////////
738
/**
739
 * When rendering this Node, switch on writing to Depth buffer?
740
 *
741
 * @param mask Write to the Depth buffer when rendering this Node?
742
 */
743
  @SuppressWarnings("unused")
744
  public void glDepthMask(boolean mask)
745
    {
746
    mState.glDepthMask(mask);
747
    }
748

    
749
///////////////////////////////////////////////////////////////////////////////////////////////////
750
/**
751
 * When rendering this Node, which bits of the Stencil buffer to write to?
752
 *
753
 * @param mask Marks the bits of the Stencil buffer we will write to when rendering this Node.
754
 */
755
  @SuppressWarnings("unused")
756
  public void glStencilMask(int mask)
757
    {
758
    mState.glStencilMask(mask);
759
    }
760

    
761
///////////////////////////////////////////////////////////////////////////////////////////////////
762
/**
763
 * When rendering this Node, which Tests to enable?
764
 *
765
 * @param test Valid values: GL_DEPTH_TEST, GL_STENCIL_TEST, GL_BLEND
766
 */
767
  @SuppressWarnings("unused")
768
  public void glEnable(int test)
769
    {
770
    mState.glEnable(test);
771
    }
772

    
773
///////////////////////////////////////////////////////////////////////////////////////////////////
774
/**
775
 * When rendering this Node, which Tests to enable?
776
 *
777
 * @param test Valid values: GL_DEPTH_TEST, GL_STENCIL_TEST, GL_BLEND
778
 */
779
  @SuppressWarnings("unused")
780
  public void glDisable(int test)
781
    {
782
    mState.glDisable(test);
783
    }
784

    
785
///////////////////////////////////////////////////////////////////////////////////////////////////
786
/**
787
 * When rendering this Node, use the following StencilFunc.
788
 *
789
 * @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
790
 * @param ref  Reference valut to compare our stencil with.
791
 * @param mask Mask used when comparing.
792
 */
793
  @SuppressWarnings("unused")
794
  public void glStencilFunc(int func, int ref, int mask)
795
    {
796
    mState.glStencilFunc(func,ref,mask);
797
    }
798

    
799
///////////////////////////////////////////////////////////////////////////////////////////////////
800
/**
801
 * When rendering this Node, use the following StencilOp.
802
 * <p>
803
 * Valid values of all 3 parameters: GL_KEEP, GL_ZERO, GL_REPLACE, GL_INCR, GL_DECR, GL_INVERT, GL_INCR_WRAP, GL_DECR_WRAP
804
 *
805
 * @param sfail  What to do when Stencil Test fails.
806
 * @param dpfail What to do when Depth Test fails.
807
 * @param dppass What to do when Depth Test passes.
808
 */
809
  @SuppressWarnings("unused")
810
  public void glStencilOp(int sfail, int dpfail, int dppass)
811
    {
812
    mState.glStencilOp(sfail,dpfail,dppass);
813
    }
814

    
815
///////////////////////////////////////////////////////////////////////////////////////////////////
816
/**
817
 * When rendering this Node, use the following DepthFunc.
818
 *
819
 * @param func Valid values: GL_NEVER, GL_ALWAYS, GL_LESS, GL_LEQUAL, GL_EQUAL, GL_GEQUAL, GL_GREATER, GL_NOTEQUAL
820
 */
821
  @SuppressWarnings("unused")
822
  public void glDepthFunc(int func)
823
    {
824
    mState.glDepthFunc(func);
825
    }
826

    
827
///////////////////////////////////////////////////////////////////////////////////////////////////
828
/**
829
 * When rendering this Node, use the following Blending mode.
830
 * <p>
831
 * Valid values: GL_ZERO, GL_ONE, GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
832
 *               GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
833
 *               GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, GL_SRC_ALPHA_SATURATE
834
 *
835
 * @param src Source Blend function
836
 * @param dst Destination Blend function
837
 */
838
  @SuppressWarnings("unused")
839
  public void glBlendFunc(int src, int dst)
840
    {
841
    mState.glBlendFunc(src,dst);
842
    }
843

    
844
///////////////////////////////////////////////////////////////////////////////////////////////////
845
/**
846
 * Before rendering this Node, clear the following buffers.
847
 * <p>
848
 * Valid values: 0, or bitwise OR of one or more values from the set GL_COLOR_BUFFER_BIT,
849
 *               GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT.
850
 * Default: 0
851
 *
852
 * @param mask bitwise OR of BUFFER_BITs to clear.
853
 */
854
  @SuppressWarnings("unused")
855
  public void glClear(int mask)
856
    {
857
    mState.glClear(mask);
858
    }
859
  }
(6-6/22)