Project

General

Profile

« Previous | Next » 

Revision be60d4ff

Added by Leszek Koltunski about 7 years ago

Children now properly sorted into Postprocessing Buckets.

View differences:

src/main/java/org/distorted/library/DistortedMaster.java
75 75
    if( !found ) mSlaves.add(s);
76 76
    }
77 77

  
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

  
80
  static void addSorted(ArrayList<DistortedNode> mChildren, DistortedNode newChild)
81
    {
82
    DistortedNode child;
83
    DistortedEffectsPostprocess dep;
84
    int i,num = mChildren.size();
85
    long bucket, newBucket;
86

  
87
    dep = newChild.getEffectsPostprocess();
88
    newBucket = dep==null ? 0 : dep.getBucket();
89

  
90
    for(i=0; i<num; i++)
91
      {
92
      child = mChildren.get(i);
93
      dep   = child.getEffectsPostprocess();
94
      bucket= dep==null ? 0 : dep.getBucket();
95

  
96
      if( bucket>newBucket ) break;
97
      }
98

  
99
    mChildren.add(i,newChild);
100

  
101
    //android.util.Log.e("newChild", "newBucket="+newBucket+" new child at "+i+" total num ="+num);
102
    }
103

  
78 104
///////////////////////////////////////////////////////////////////////////////////////////////////
79 105

  
80 106
  static void onDestroy()
src/main/java/org/distorted/library/DistortedNode.java
63 63
  private static long mNextNodeID =0;
64 64

  
65 65
  private DistortedNode mParent;
66
  private DistortedOutputSurface mSurfaceParent;
66 67
  private MeshObject mMesh;
67 68
  private DistortedEffects mEffects;
68 69
  private DistortedEffectsPostprocess mPostprocess;
......
261 262
    return numRenders;
262 263
    }
263 264

  
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266

  
267
  private void newJob(int t, DistortedNode n, DistortedEffectsPostprocess d)
268
    {
269
    mJobs.add(new Job(t,n,d));
270
    }
271

  
272
///////////////////////////////////////////////////////////////////////////////////////////////////
273

  
274
  void setPost(DistortedEffectsPostprocess dep)
275
    {
276
    mPostprocess = dep;
277
    }
278

  
279
///////////////////////////////////////////////////////////////////////////////////////////////////
280

  
281
  void setSurfaceParent(DistortedOutputSurface dep)
282
    {
283
    mSurfaceParent = dep;
284
    mParent = null;
285
    }
286

  
264 287
///////////////////////////////////////////////////////////////////////////////////////////////////
265 288
// PUBLIC API
266 289
///////////////////////////////////////////////////////////////////////////////////////////////////
......
282 305
    mNumChildren   = new int[1];
283 306
    mNumChildren[0]= 0;
284 307
    mParent        = null;
308
    mSurfaceParent = null;
285 309

  
286 310
    ArrayList<Long> list = new ArrayList<>();
287 311
    list.add(mSurface.getID());
......
312 336
 */
313 337
  public DistortedNode(DistortedNode node, int flags)
314 338
    {
315
    mEffects     = new DistortedEffects(node.mEffects,flags);
316
    mPostprocess = null;
317
    mMesh        = node.mMesh;
318
    mState       = new DistortedRenderState();
319
    mParent      = null;
339
    mEffects      = new DistortedEffects(node.mEffects,flags);
340
    mPostprocess  = null;
341
    mMesh         = node.mMesh;
342
    mState        = new DistortedRenderState();
343
    mParent       = null;
344
    mSurfaceParent= null;
320 345

  
321 346
    if( (flags & Distorted.CLONE_SURFACE) != 0 )
322 347
      {
......
497 522
    Job job;
498 523

  
499 524
    int numChanges=0;
500
    int numSorts  =0;
501 525

  
502 526
    for(int i=0; i<num; i++)
503 527
      {
......
508 532
        case ATTACH: numChanges++;
509 533
                     if( mChildren==null ) mChildren = new ArrayList<>(2);
510 534
                     job.node.mParent = this;
511
                     mChildren.add(job.node);
535
                     job.node.mSurfaceParent = null;
536
                     DistortedMaster.addSorted(mChildren,job.node);
512 537
                     mNumChildren[0]++;
513 538
                     break;
514 539
        case DETACH: numChanges++;
515 540
                     if( mNumChildren[0]>0 && mChildren.remove(job.node) )
516 541
                       {
517 542
                       job.node.mParent = null;
543
                       job.node.mSurfaceParent = null;
518 544
                       mNumChildren[0]--;
519 545
                       }
520 546
                     break;
......
527 553
                         {
528 554
                         tmp = mChildren.remove(j);
529 555
                         tmp.mParent = null;
556
                         tmp.mSurfaceParent = null;
530 557
                         }
531 558

  
532 559
                       mNumChildren[0] = 0;
533 560
                       }
534 561
                     break;
535
        case SORT  : numSorts++;
536
                     // TODO: sort
562
        case SORT  : job.node.mPostprocess = job.dep;
563
                     mChildren.remove(job.node);
564
                     DistortedMaster.addSorted(mChildren,job.node);
537 565
                     break;
538 566
        }
539 567
      }
540 568

  
541
    if( numChanges>0 )
542
      {
543
      adjustIsomorphism();
544

  
545
      if( numSorts==0 )
546
        {
547
        // TODO: sort
548
        }
549
      }
569
    if( numChanges>0 ) adjustIsomorphism();
550 570
    }
551 571
///////////////////////////////////////////////////////////////////////////////////////////////////
552 572
/**
......
561 581
 */
562 582
  public void setPostprocessEffects(DistortedEffectsPostprocess dep)
563 583
    {
564
    mPostprocess = dep;
565

  
566
    // TODO: rearrange all the siblings so that all are sorted by the DistortedEffectsPostprocess' ID.
584
    if( mParent!=null )
585
      {
586
      mParent.newJob(SORT, this, dep);
587
      DistortedMaster.newSlave(mParent);
588
      }
589
    else if( mSurfaceParent!=null )
590
      {
591
      mSurfaceParent.newJob(SORT, this, dep);
592
      DistortedMaster.newSlave(mSurfaceParent);
593
      }
594
    else
595
      {
596
      mPostprocess = dep;
597
      }
567 598
    }
568 599

  
569 600
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/DistortedOutputSurface.java
39 39
    {
40 40
    int type;
41 41
    DistortedNode node;
42
    DistortedEffectsPostprocess dep;
42 43

  
43
    Job(int t, DistortedNode n)
44
    Job(int t, DistortedNode n, DistortedEffectsPostprocess d)
44 45
      {
45 46
      type = t;
46 47
      node = n;
48
      dep  = d;
47 49
      }
48 50
    }
49 51

  
......
63 65

  
64 66
  private float mClearR, mClearG, mClearB, mClearA;
65 67
  private float mClearDepth;
66

  
68
/*
69
private String sNew="", sOld="";
70
*/
67 71
///////////////////////////////////////////////////////////////////////////////////////////////////
68 72

  
69 73
  DistortedOutputSurface(int width, int height, int createColor, int createDepth, int fbo, int type)
......
96 100

  
97 101
///////////////////////////////////////////////////////////////////////////////////////////////////
98 102

  
99
  void createProjection()
103
  private void createProjection()
100 104
    {
101 105
    if( mWidth>0 && mHeight>1 )
102 106
      {
......
145 149
    DistortedNode child;
146 150
    DistortedEffectsPostprocess lastP=null, currP;
147 151
    long lastB=0, currB;
148

  
152
/*
153
sNew = "";
154
*/
149 155
    for(int i=0; i<num; i++)
150 156
      {
151 157
      child = children.get(i);
152 158
      currP = child.getEffectsPostprocess();
153 159
      currB = currP==null ? 0 : currP.getBucket();
154

  
160
/*
161
sNew += currB;
162
*/
155 163
      if( lastB!=currB && lastB!=0 )
156 164
        {
157 165
        numRenders += lastP.postprocess(time,this);
......
179 187
      lastP = currP;
180 188
      lastB = currB;
181 189
      }
182

  
190
/*
191
if( !sNew.equals(sOld) )
192
  {
193
  sOld = sNew;
194
  android.util.Log.e("surface", "Surface"+getID()+": "+sOld);
195
  }
196
*/
183 197
    return numRenders;
184 198
    }
185 199

  
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201

  
202
  void newJob(int t, DistortedNode n, DistortedEffectsPostprocess d)
203
    {
204
    mJobs.add(new Job(t,n,d));
205
    }
206

  
186 207
///////////////////////////////////////////////////////////////////////////////////////////////////
187 208
// PUBLIC API
188 209
///////////////////////////////////////////////////////////////////////////////////////////////////
......
399 420
 */
400 421
  public void attach(DistortedNode node)
401 422
    {
402
    mJobs.add(new Job(ATTACH,node));
423
    mJobs.add(new Job(ATTACH,node,null));
403 424
    DistortedMaster.newSlave(this);
404 425
    }
405 426

  
......
418 439
  public DistortedNode attach(DistortedInputSurface surface, DistortedEffects effects, MeshObject mesh)
419 440
    {
420 441
    DistortedNode node = new DistortedNode(surface,effects,mesh);
421
    mJobs.add(new Job(ATTACH,node));
442
    mJobs.add(new Job(ATTACH,node,null));
422 443
    DistortedMaster.newSlave(this);
423 444
    return node;
424 445
    }
......
448 469
      if( node.getEffects().getID()==id )
449 470
        {
450 471
        detached = true;
451
        mJobs.add(new Job(DETACH,node));
472
        mJobs.add(new Job(DETACH,node,null));
452 473
        DistortedMaster.newSlave(this);
453 474
        break;
454 475
        }
......
485 506
 */
486 507
  public void detach(DistortedNode node)
487 508
    {
488
    mJobs.add(new Job(DETACH,node));
509
    mJobs.add(new Job(DETACH,node,null));
489 510
    DistortedMaster.newSlave(this);
490 511
    }
491 512

  
......
498 519
 */
499 520
  public void detachAll()
500 521
    {
501
    mJobs.add(new Job(DETALL,null));
522
    mJobs.add(new Job(DETALL,null,null));
502 523
    DistortedMaster.newSlave(this);
503 524
    }
504 525

  
......
515 536
    int num = mJobs.size();
516 537
    Job job;
517 538

  
518
    int numChanges=0;
519
    int numSorts  =0;
520

  
521 539
    for(int i=0; i<num; i++)
522 540
      {
523 541
      job = mJobs.remove(0);
524 542

  
525 543
      switch(job.type)
526 544
        {
527
        case ATTACH: numChanges++;
528
                     if( mChildren==null ) mChildren = new ArrayList<>(2);
529
                     mChildren.add(job.node);
545
        case ATTACH: if( mChildren==null ) mChildren = new ArrayList<>(2);
546
                     job.node.setSurfaceParent(this);
547
                     DistortedMaster.addSorted(mChildren,job.node);
530 548
                     mNumChildren++;
531 549
                     break;
532
        case DETACH: numChanges++;
533
                     if( mNumChildren>0 && mChildren.remove(job.node) )
550
        case DETACH: if( mNumChildren>0 && mChildren.remove(job.node) )
534 551
                       {
552
                       job.node.setSurfaceParent(null);
535 553
                       mNumChildren--;
536 554
                       }
537 555
                     break;
538
        case DETALL: numChanges++;
539
                     if( mNumChildren>0 )
556
        case DETALL: if( mNumChildren>0 )
540 557
                       {
558
                       DistortedNode tmp;
559

  
560
                       for(int j=mNumChildren-1; j>=0; j--)
561
                         {
562
                         tmp = mChildren.remove(j);
563
                         tmp.setSurfaceParent(null);
564
                         }
565

  
541 566
                       mNumChildren = 0;
542
                       mChildren.clear();
543 567
                       }
544 568
                     break;
545
        case SORT  : numSorts++;
546
                     // TODO: sort
569
        case SORT  : job.node.setPost(job.dep);
570
                     mChildren.remove(job.node);
571
                     DistortedMaster.addSorted(mChildren,job.node);
547 572
                     break;
548 573
        }
549 574
      }
550

  
551
    if( numChanges>0 && numSorts==0 )
552
      {
553
      // TODO: sort
554
      }
555 575
    }
556 576
}

Also available in: Unified diff