Project

General

Profile

« Previous | Next » 

Revision 13687207

Added by Leszek Koltunski about 7 years ago

Separate the Postprocessing Effects to their own DistortedEffectsPostprocess queue.
This partly breaks Multiblur (to be debugged)

View differences:

src/main/java/org/distorted/library/DistortedEffects.java
44 44

  
45 45
///////////////////////////////////////////////////////////////////////////////////////////////////
46 46
/**
47
 * Class containing {@link EffectTypes#LENGTH} queues, each a class derived from EffectQueue.
47
 * Class containing Matrix,Vertex and Fragment effect queues. Postprocessing queue is held in a separate
48
 * class.
48 49
 * <p>
49 50
 * The queues hold actual effects to be applied to a given (DistortedTexture,MeshObject) combo.
50 51
 */
......
98 99
  private EffectQueueMatrix      mM;
99 100
  private EffectQueueFragment    mF;
100 101
  private EffectQueueVertex      mV;
101
  private EffectQueuePostprocess mP;
102 102

  
103
  private boolean matrixCloned, vertexCloned, fragmentCloned, postprocessCloned;
103
  private boolean matrixCloned, vertexCloned, fragmentCloned;
104 104

  
105 105
///////////////////////////////////////////////////////////////////////////////////////////////////
106 106

  
......
229 229
      mF = new EffectQueueFragment(mID);
230 230
      fragmentCloned = false;
231 231
      }
232

  
233
    if( (flags & Distorted.CLONE_POSTPROCESS) != 0 )
234
      {
235
      mP = d.mP;
236
      postprocessCloned = true;
237
      }
238
    else
239
      {
240
      mP = new EffectQueuePostprocess(mID);
241
      postprocessCloned = false;
242
      }
243 232
    }
244 233

  
245 234
///////////////////////////////////////////////////////////////////////////////////////////////////
......
295 284
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
296 285
    }
297 286

  
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299

  
300
  EffectQueuePostprocess getPostprocess()
301
    {
302
    return mP;
303
    }
304

  
305
///////////////////////////////////////////////////////////////////////////////////////////////////
306

  
307
  int postprocessPriv(long currTime, DistortedOutputSurface surface)
308
    {
309
    return mP.postprocess(currTime,surface);
310
    }
311

  
312 287
///////////////////////////////////////////////////////////////////////////////////////////////////
313 288

  
314 289
  void drawPriv(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime)
......
356 331
    if( !matrixCloned     ) mM.abortAll(false);
357 332
    if( !vertexCloned     ) mV.abortAll(false);
358 333
    if( !fragmentCloned   ) mF.abortAll(false);
359
    if( !postprocessCloned) mP.abortAll(false);
360 334

  
361 335
    mM = null;
362 336
    mV = null;
363 337
    mF = null;
364
    mP = null;
365 338
    }
366 339

  
367 340
///////////////////////////////////////////////////////////////////////////////////////////////////
......
410 383
/**
411 384
 * Releases all resources. After this call, the queue should not be used anymore.
412 385
 */
386
  @SuppressWarnings("unused")
413 387
  public synchronized void delete()
414 388
    {
415 389
    releasePriv();
......
433 407
 * 
434 408
 * @param el A class implementing the EffectListener interface that wants to get notifications.
435 409
 */
410
  @SuppressWarnings("unused")
436 411
  public void registerForMessages(EffectListener el)
437 412
    {
438 413
    mV.registerForMessages(el);
439 414
    mF.registerForMessages(el);
440 415
    mM.registerForMessages(el);
441
    mP.registerForMessages(el);
442 416
    }
443 417

  
444 418
///////////////////////////////////////////////////////////////////////////////////////////////////
......
447 421
 * 
448 422
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
449 423
 */
424
  @SuppressWarnings("unused")
450 425
  public void deregisterForMessages(EffectListener el)
451 426
    {
452 427
    mV.deregisterForMessages(el);
453 428
    mF.deregisterForMessages(el);
454 429
    mM.deregisterForMessages(el);
455
    mP.deregisterForMessages(el);
456 430
    }
457 431

  
458 432
///////////////////////////////////////////////////////////////////////////////////////////////////
......
461 435
 * @return Number of effects aborted.
462 436
 */
463 437
  public int abortAllEffects()
464
      {
465
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true) + mP.abortAll(true);
466
      }
438
    {
439
    return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
440
    }
467 441

  
468 442
///////////////////////////////////////////////////////////////////////////////////////////////////
469 443
/**
......
479 453
      case MATRIX     : return mM.abortAll(true);
480 454
      case VERTEX     : return mV.abortAll(true);
481 455
      case FRAGMENT   : return mF.abortAll(true);
482
      case POSTPROCESS: return mP.abortAll(true);
483 456
      default         : return 0;
484 457
      }
485 458
    }
......
498 471
    if( type==EffectTypes.MATRIX.type      ) return mM.removeByID(id>>EffectTypes.LENGTH);
499 472
    if( type==EffectTypes.VERTEX.type      ) return mV.removeByID(id>>EffectTypes.LENGTH);
500 473
    if( type==EffectTypes.FRAGMENT.type    ) return mF.removeByID(id>>EffectTypes.LENGTH);
501
    if( type==EffectTypes.POSTPROCESS.type ) return mP.removeByID(id>>EffectTypes.LENGTH);
502 474

  
503 475
    return 0;
504 476
    }
......
517 489
      case MATRIX     : return mM.removeByType(name);
518 490
      case VERTEX     : return mV.removeByType(name);
519 491
      case FRAGMENT   : return mF.removeByType(name);
520
      case POSTPROCESS: return mP.removeByType(name);
521 492
      default         : return 0;
522 493
      }
523 494
    }
......
529 500
 * @param id Effect ID we want to print info about
530 501
 * @return <code>true</code> if a single Effect of type effectType has been found.
531 502
 */
532
    
503
  @SuppressWarnings("unused")
533 504
  public boolean printEffect(long id)
534 505
    {
535 506
    int type = (int)(id&EffectTypes.MASK);
536 507

  
537
    if( type==EffectTypes.MATRIX.type      )  return mM.printByID(id>>EffectTypes.LENGTH);
538
    if( type==EffectTypes.VERTEX.type      )  return mV.printByID(id>>EffectTypes.LENGTH);
539
    if( type==EffectTypes.FRAGMENT.type    )  return mF.printByID(id>>EffectTypes.LENGTH);
540
    if( type==EffectTypes.POSTPROCESS.type )  return mP.printByID(id>>EffectTypes.LENGTH);
508
    if( type==EffectTypes.MATRIX.type  )  return mM.printByID(id>>EffectTypes.LENGTH);
509
    if( type==EffectTypes.VERTEX.type  )  return mV.printByID(id>>EffectTypes.LENGTH);
510
    if( type==EffectTypes.FRAGMENT.type)  return mF.printByID(id>>EffectTypes.LENGTH);
541 511

  
542 512
    return false;
543 513
    }
......
563 533
 *
564 534
 * @return The maximum number of Matrix effects
565 535
 */
536
  @SuppressWarnings("unused")
566 537
  public static int getMaxMatrix()
567 538
    {
568 539
    return EffectQueue.getMax(EffectTypes.MATRIX.ordinal());
......
574 545
 *
575 546
 * @return The maximum number of Vertex effects
576 547
 */
548
  @SuppressWarnings("unused")
577 549
  public static int getMaxVertex()
578 550
    {
579 551
    return EffectQueue.getMax(EffectTypes.VERTEX.ordinal());
......
585 557
 *
586 558
 * @return The maximum number of Fragment effects
587 559
 */
560
  @SuppressWarnings("unused")
588 561
  public static int getMaxFragment()
589 562
    {
590 563
    return EffectQueue.getMax(EffectTypes.FRAGMENT.ordinal());
591 564
    }
592 565

  
593
///////////////////////////////////////////////////////////////////////////////////////////////////
594
/**
595
 * Returns the maximum number of Postprocess effects.
596
 *
597
 * @return The maximum number of Postprocess effects
598
 */
599
  public static int getMaxPostprocess()
600
    {
601
    return EffectQueue.getMax(EffectTypes.POSTPROCESS.ordinal());
602
    }
603

  
604 566
///////////////////////////////////////////////////////////////////////////////////////////////////
605 567
/**
606 568
 * Sets the maximum number of Matrix effects that can be stored in a single EffectQueue at one time.
......
617 579
 *            than Byte.MAX_VALUE
618 580
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
619 581
 */
582
  @SuppressWarnings("unused")
620 583
  public static boolean setMaxMatrix(int max)
621 584
    {
622 585
    return EffectQueue.setMax(EffectTypes.MATRIX.ordinal(),max);
......
638 601
 *            than Byte.MAX_VALUE
639 602
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
640 603
 */
604
  @SuppressWarnings("unused")
641 605
  public static boolean setMaxVertex(int max)
642 606
    {
643 607
    return EffectQueue.setMax(EffectTypes.VERTEX.ordinal(),max);
......
659 623
 *            than Byte.MAX_VALUE
660 624
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
661 625
 */
626
  @SuppressWarnings("unused")
662 627
  public static boolean setMaxFragment(int max)
663 628
    {
664 629
    return EffectQueue.setMax(EffectTypes.FRAGMENT.ordinal(),max);
665 630
    }
666 631

  
667
///////////////////////////////////////////////////////////////////////////////////////////////////
668
/**
669
 * Sets the maximum number of Postprocess effects that can be stored in a single EffectQueue at one time.
670
 * This can fail if:
671
 * <ul>
672
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
673
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
674
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
675
 *     time only decreasing the value of 'max' is permitted.
676
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
677
 * </ul>
678
 *
679
 * @param max new maximum number of simultaneous Postprocess Effects. Has to be a non-negative number not greater
680
 *            than Byte.MAX_VALUE
681
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
682
 */
683
  public static boolean setMaxPostprocess(int max)
684
    {
685
    return EffectQueue.setMax(EffectTypes.POSTPROCESS.ordinal(),max);
686
    }
687

  
688 632
///////////////////////////////////////////////////////////////////////////////////////////////////   
689 633
///////////////////////////////////////////////////////////////////////////////////////////////////
690 634
// Individual effect functions.
......
1126 1070
    {
1127 1071
    return mV.add(EffectNames.WAVE, wave, center, region);
1128 1072
    }
1129

  
1130
///////////////////////////////////////////////////////////////////////////////////////////////////
1131
// Postprocess-based effects
1132
///////////////////////////////////////////////////////////////////////////////////////////////////
1133
/**
1134
 * Blur the object.
1135
 *
1136
 * @param radius The 'strength' if the effect, in pixels. 0 = no blur, 10 = when blurring a given pixel,
1137
 *               take into account 10 pixels in each direction.
1138
 * @return ID of the effect added, or -1 if we failed to add one.
1139
 */
1140
  public long blur(Data1D radius)
1141
    {
1142
    return mP.add(EffectNames.BLUR, radius);
1143
    }
1144 1073
  }

Also available in: Unified diff