Project

General

Profile

« Previous | Next » 

Revision 6bb59aad

Added by Leszek Koltunski almost 7 years ago

Progress with support for Effect classes.

View differences:

src/main/java/org/distorted/library/main/DistortedEffects.java
31 31
import org.distorted.library.program.LinkingException;
32 32
import org.distorted.library.program.VertexCompilationException;
33 33
import org.distorted.library.program.VertexUniformsException;
34
import org.distorted.library.type.Data1D;
35
import org.distorted.library.type.Data2D;
36
import org.distorted.library.type.Data3D;
37
import org.distorted.library.type.Data4D;
38
import org.distorted.library.type.Data5D;
39
import org.distorted.library.type.Static3D;
40 34

  
41 35
import java.io.InputStream;
42 36
import java.nio.ByteBuffer;
43 37
import java.nio.ByteOrder;
44 38
import java.nio.FloatBuffer;
39
import java.util.ArrayList;
45 40

  
46 41
///////////////////////////////////////////////////////////////////////////////////////////////////
47 42
/**
......
55 50
  /// MAIN PROGRAM ///
56 51
  private static DistortedProgram mMainProgram;
57 52
  private static int mMainTextureH;
58
  private static boolean[] mEffectEnabled = new boolean[EffectNames.size()];
59

  
60
  static
61
    {
62
    int len = EffectNames.size();
63

  
64
    for(int i=0; i<len; i++)
65
      {
66
      mEffectEnabled[i] = false;
67
      }
68
    }
53
  private static ArrayList<Effect> mEnabledEffects = new ArrayList<>();
69 54

  
70 55
  /// BLIT PROGRAM ///
71 56
  private static DistortedProgram mBlitProgram;
......
112 97
    String mainVertHeader= Distorted.GLSL_VERSION;
113 98
    String mainFragHeader= Distorted.GLSL_VERSION;
114 99

  
115
    EffectNames name;
116
    EffectTypes type;
117 100
    boolean foundF = false;
118 101
    boolean foundV = false;
102
    int type, effects = mEnabledEffects.size();
103
    Effect effect;
119 104

  
120
    for(int i=0; i<mEffectEnabled.length; i++)
105
    for(int i=0; i<effects; i++)
121 106
      {
122
      if( mEffectEnabled[i] )
107
      effect = mEnabledEffects.remove(0);
108
      type   = effect.getType();
109

  
110
      if( type == Effect.VERTEX )
111
        {
112
        mainVertHeader += ("#define "+effect.getString()+" "+effect.getName()+"\n");
113
        foundV = true;
114
        }
115
      else if( type == Effect.FRAGMENT )
123 116
        {
124
        name = EffectNames.getName(i);
125
        type = EffectNames.getType(i);
126

  
127
        if( type == EffectTypes.VERTEX )
128
          {
129
          mainVertHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
130
          foundV = true;
131
          }
132
        else if( type == EffectTypes.FRAGMENT )
133
          {
134
          mainFragHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
135
          foundF = true;
136
          }
117
        mainFragHeader += ("#define "+effect.getString()+" "+effect.getName()+"\n");
118
        foundF = true;
137 119
        }
138 120
      }
139 121

  
......
357 339
  static void onDestroy()
358 340
    {
359 341
    mNextID = 0;
360

  
361
    int len = EffectNames.size();
362

  
363
    for(int i=0; i<len; i++)
364
      {
365
      mEffectEnabled[i] = false;
366
      }
367 342
    }
368 343

  
369 344
///////////////////////////////////////////////////////////////////////////////////////////////////
......
458 433
/**
459 434
 * Aborts all Effects of a given type, for example all MATRIX Effects.
460 435
 * 
461
 * @param type one of the constants defined in {@link EffectTypes}
436
 * @param type one of the constants defined in {@link Effect}
462 437
 * @return Number of effects aborted.
463 438
 */
464
  public int abortEffects(EffectTypes type)
439
  public int abortByType(int type)
465 440
    {
466 441
    switch(type)
467 442
      {
468
      case MATRIX     : return mM.abortAll(true);
469
      case VERTEX     : return mV.abortAll(true);
470
      case FRAGMENT   : return mF.abortAll(true);
471
      default         : return 0;
443
      case Effect.MATRIX     : return mM.abortAll(true);
444
      case Effect.VERTEX     : return mV.abortAll(true);
445
      case Effect.FRAGMENT   : return mF.abortAll(true);
446
  //  case Effect.POSTPROCESS: return mP.abortAll(true);
447
      default                : return 0;
472 448
      }
473 449
    }
474 450
    
......
476 452
/**
477 453
 * Aborts a single Effect.
478 454
 * 
479
 * @param id ID of the Effect we want to abort.
455
 * @param effect the Effect we want to abort.
480 456
 * @return number of Effects aborted. Always either 0 or 1.
481 457
 */
482
  public int abortEffect(long id)
458
  public int abortEffect(Effect effect)
483 459
    {
484
    int type = (int)(id&Effect.MASK);
485

  
486
    if( type==Effect.MATRIX   ) return mM.removeByID(id>>Effect.LENGTH);
487
    if( type==Effect.VERTEX   ) return mV.removeByID(id>>Effect.LENGTH);
488
    if( type==Effect.FRAGMENT ) return mF.removeByID(id>>Effect.LENGTH);
489

  
490
    return 0;
460
    switch(effect.getType())
461
      {
462
      case Effect.MATRIX     : return mM.removeEffect(effect);
463
      case Effect.VERTEX     : return mV.removeEffect(effect);
464
      case Effect.FRAGMENT   : return mF.removeEffect(effect);
465
  //  case Effect.POSTPROCESS: return mP.removeEffect(effect);
466
      default                : return 0;
467
      }
491 468
    }
492 469

  
493 470
///////////////////////////////////////////////////////////////////////////////////////////////////
494 471
/**
495 472
 * Abort all Effects of a given name, for example all rotations.
496 473
 * 
497
 * @param name one of the constants defined in {@link EffectNames}
474
 * @param name one of the constants defined in
475
 *             {@link org.distorted.library.effect.MatrixEffect},
476
 *             {@link org.distorted.library.effect.VertexEffect},
477
 *             {@link org.distorted.library.effect.FragmentEffect} or
478
 *             {@link org.distorted.library.effect.PostprocessEffect}
498 479
 * @return number of Effects aborted.
499 480
 */
500
  public int abortEffects(EffectNames name)
481
  public int abortByName(int name)
501 482
    {
502
    switch(name.getType())
483
    switch(Effect.getType(name))
503 484
      {
504
      case MATRIX     : return mM.removeByType(name);
505
      case VERTEX     : return mV.removeByType(name);
506
      case FRAGMENT   : return mF.removeByType(name);
507
      default         : return 0;
485
      case Effect.MATRIX     : return mM.removeByName(name);
486
      case Effect.VERTEX     : return mV.removeByName(name);
487
      case Effect.FRAGMENT   : return mF.removeByName(name);
488
  //  case Effect.POSTPROCESS: return mP.removeByName(name);
489
      default                : return 0;
508 490
      }
509 491
    }
510
    
511
///////////////////////////////////////////////////////////////////////////////////////////////////
512
/**
513
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
514
 * 
515
 * @param id Effect ID we want to print info about
516
 * @return <code>true</code> if a single Effect of type effectType has been found.
517
 */
518
  @SuppressWarnings("unused")
519
  public boolean printEffect(long id)
520
    {
521
    int type = (int)(id&EffectTypes.MASK);
522

  
523
    if( type==EffectTypes.MATRIX.type  )  return mM.printByID(id>>EffectTypes.LENGTH);
524
    if( type==EffectTypes.VERTEX.type  )  return mV.printByID(id>>EffectTypes.LENGTH);
525
    if( type==EffectTypes.FRAGMENT.type)  return mF.printByID(id>>EffectTypes.LENGTH);
526

  
527
    return false;
528
    }
529 492

  
530 493
///////////////////////////////////////////////////////////////////////////////////////////////////
531 494
/**
......
535 498
 * This needs to be called BEFORE shaders get compiled, i.e. before the call to Distorted.onCreate().
536 499
 * The point: by enabling only the effects we need, we can optimize the shaders.
537 500
 *
538
 * @param name Name of the Effect to enable.
501
 * @param name one of the constants defined in
502
 *             {@link org.distorted.library.effect.MatrixEffect},
503
 *             {@link org.distorted.library.effect.VertexEffect},
504
 *             {@link org.distorted.library.effect.FragmentEffect} or
505
 *             {@link org.distorted.library.effect.PostprocessEffect}
539 506
 */
540
  public static void enableEffect(EffectNames name)
507
  public static void enableEffect(int name)
541 508
    {
542
    mEffectEnabled[name.ordinal()] = true;
509
    mEffectEnabled[name] = true;
543 510
    }
544 511

  
545 512
///////////////////////////////////////////////////////////////////////////////////////////////////
......
551 518
  @SuppressWarnings("unused")
552 519
  public static int getMaxMatrix()
553 520
    {
554
    return EffectQueue.getMax(EffectTypes.MATRIX.ordinal());
521
    return EffectQueue.getMax(Effect.MATRIX);
555 522
    }
556 523

  
557 524
///////////////////////////////////////////////////////////////////////////////////////////////////
......
563 530
  @SuppressWarnings("unused")
564 531
  public static int getMaxVertex()
565 532
    {
566
    return EffectQueue.getMax(EffectTypes.VERTEX.ordinal());
533
    return EffectQueue.getMax(Effect.VERTEX);
567 534
    }
568 535

  
569 536
///////////////////////////////////////////////////////////////////////////////////////////////////
......
575 542
  @SuppressWarnings("unused")
576 543
  public static int getMaxFragment()
577 544
    {
578
    return EffectQueue.getMax(EffectTypes.FRAGMENT.ordinal());
545
    return EffectQueue.getMax(Effect.FRAGMENT);
579 546
    }
580 547

  
581 548
///////////////////////////////////////////////////////////////////////////////////////////////////
......
597 564
  @SuppressWarnings("unused")
598 565
  public static boolean setMaxMatrix(int max)
599 566
    {
600
    return EffectQueue.setMax(EffectTypes.MATRIX.ordinal(),max);
567
    return EffectQueue.setMax(Effect.MATRIX,max);
601 568
    }
602 569

  
603 570
///////////////////////////////////////////////////////////////////////////////////////////////////
......
619 586
  @SuppressWarnings("unused")
620 587
  public static boolean setMaxVertex(int max)
621 588
    {
622
    return EffectQueue.setMax(EffectTypes.VERTEX.ordinal(),max);
589
    return EffectQueue.setMax(Effect.VERTEX,max);
623 590
    }
624 591

  
625 592
///////////////////////////////////////////////////////////////////////////////////////////////////
......
641 608
  @SuppressWarnings("unused")
642 609
  public static boolean setMaxFragment(int max)
643 610
    {
644
    return EffectQueue.setMax(EffectTypes.FRAGMENT.ordinal(),max);
645
    }
646

  
647
///////////////////////////////////////////////////////////////////////////////////////////////////   
648
///////////////////////////////////////////////////////////////////////////////////////////////////
649
// Individual effect functions.
650
///////////////////////////////////////////////////////////////////////////////////////////////////
651
// Matrix-based effects
652
///////////////////////////////////////////////////////////////////////////////////////////////////
653
/**
654
 * Moves the Object by a (possibly changing in time) vector.
655
 * 
656
 * @param vector 3-dimensional Data which at any given time will return a Static3D
657
 *               representing the current coordinates of the vector we want to move the Object with.
658
 * @return       ID of the effect added, or -1 if we failed to add one.
659
 */
660
  public long move(Data3D vector)
661
    {   
662
    return mM.add(EffectNames.MOVE,vector);
663
    }
664

  
665
///////////////////////////////////////////////////////////////////////////////////////////////////
666
/**
667
 * Scales the Object by (possibly changing in time) 3D scale factors.
668
 * 
669
 * @param scale 3-dimensional Data which at any given time returns a Static3D
670
 *              representing the current x- , y- and z- scale factors.
671
 * @return      ID of the effect added, or -1 if we failed to add one.
672
 */
673
  public long scale(Data3D scale)
674
    {   
675
    return mM.add(EffectNames.SCALE,scale);
676
    }
677

  
678
///////////////////////////////////////////////////////////////////////////////////////////////////
679
/**
680
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
681
 *
682
 * @param scale The factor to scale all 3 dimensions with.
683
 * @return      ID of the effect added, or -1 if we failed to add one.
684
 */
685
  public long scale(float scale)
686
    {
687
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
688
    }
689

  
690
///////////////////////////////////////////////////////////////////////////////////////////////////
691
/**
692
 * Rotates the Object by 'angle' degrees around the center.
693
 * Static axis of rotation is given by the last parameter.
694
 *
695
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
696
 * @param axis   Axis of rotation
697
 * @param center Coordinates of the Point we are rotating around.
698
 * @return       ID of the effect added, or -1 if we failed to add one.
699
 */
700
  public long rotate(Data1D angle, Static3D axis, Data3D center )
701
    {   
702
    return mM.add(EffectNames.ROTATE, angle, axis, center);
703
    }
704

  
705
///////////////////////////////////////////////////////////////////////////////////////////////////
706
/**
707
 * Rotates the Object by 'angle' degrees around the center.
708
 * Here both angle and axis can dynamically change.
709
 *
710
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
711
 * @param center    Coordinates of the Point we are rotating around.
712
 * @return          ID of the effect added, or -1 if we failed to add one.
713
 */
714
  public long rotate(Data4D angleaxis, Data3D center)
715
    {
716
    return mM.add(EffectNames.ROTATE, angleaxis, center);
717
    }
718

  
719
///////////////////////////////////////////////////////////////////////////////////////////////////
720
/**
721
 * Rotates the Object by quaternion.
722
 *
723
 * @param quaternion The quaternion describing the rotation.
724
 * @param center     Coordinates of the Point we are rotating around.
725
 * @return           ID of the effect added, or -1 if we failed to add one.
726
 */
727
  public long quaternion(Data4D quaternion, Data3D center )
728
    {
729
    return mM.add(EffectNames.QUATERNION,quaternion,center);
730
    }
731

  
732
///////////////////////////////////////////////////////////////////////////////////////////////////
733
/**
734
 * Shears the Object.
735
 *
736
 * @param shear   The 3-tuple of shear factors. The first controls level
737
 *                of shearing in the X-axis, second - Y-axis and the third -
738
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
739
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
740
 * @param center  Center of shearing, i.e. the point which stays unmoved.
741
 * @return        ID of the effect added, or -1 if we failed to add one.
742
 */
743
  public long shear(Data3D shear, Data3D center)
744
    {
745
    return mM.add(EffectNames.SHEAR, shear, center);
746
    }
747

  
748
///////////////////////////////////////////////////////////////////////////////////////////////////
749
// Fragment-based effects  
750
///////////////////////////////////////////////////////////////////////////////////////////////////
751
/**
752
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
753
 *        
754
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
755
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
756
 *               Valid range: <0,1>
757
 * @param color  Color to mix. (1,0,0) is RED.
758
 * @param region Region this Effect is limited to.
759
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
760
 * @return       ID of the effect added, or -1 if we failed to add one.
761
 */
762
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
763
    {
764
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
765
    }
766

  
767
///////////////////////////////////////////////////////////////////////////////////////////////////
768
/**
769
 * Makes the whole Object smoothly change all three of its RGB components.
770
 *
771
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
772
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
773
 *               Valid range: <0,1>
774
 * @param color  Color to mix. (1,0,0) is RED.
775
 * @return       ID of the effect added, or -1 if we failed to add one.
776
 */
777
  public long chroma(Data1D blend, Data3D color)
778
    {
779
    return mF.add(EffectNames.CHROMA, blend, color);
780
    }
781

  
782
///////////////////////////////////////////////////////////////////////////////////////////////////
783
/**
784
 * Makes a certain sub-region of the Object smoothly change its transparency level.
785
 *        
786
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
787
 *               moment: pixel.a *= alpha.
788
 *               Valid range: <0,1>
789
 * @param region Region this Effect is limited to. 
790
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
791
 * @return       ID of the effect added, or -1 if we failed to add one. 
792
 */
793
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
794
    {
795
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
796
    }
797

  
798
///////////////////////////////////////////////////////////////////////////////////////////////////
799
/**
800
 * Makes the whole Object smoothly change its transparency level.
801
 *
802
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
803
 *               given moment: pixel.a *= alpha.
804
 *               Valid range: <0,1>
805
 * @return       ID of the effect added, or -1 if we failed to add one.
806
 */
807
  public long alpha(Data1D alpha)
808
    {
809
    return mF.add(EffectNames.ALPHA, alpha);
810
    }
811

  
812
///////////////////////////////////////////////////////////////////////////////////////////////////
813
/**
814
 * Makes a certain sub-region of the Object smoothly change its brightness level.
815
 *        
816
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
817
 *                   at any given moment. Valid range: <0,infinity)
818
 * @param region     Region this Effect is limited to.
819
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
820
 * @return           ID of the effect added, or -1 if we failed to add one.
821
 */
822
  public long brightness(Data1D brightness, Data4D region, boolean smooth)
823
    {
824
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
825
    }
826

  
827
///////////////////////////////////////////////////////////////////////////////////////////////////
828
/**
829
 * Makes the whole Object smoothly change its brightness level.
830
 *
831
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
832
 *                   at any given moment. Valid range: <0,infinity)
833
 * @return           ID of the effect added, or -1 if we failed to add one.
834
 */
835
  public long brightness(Data1D brightness)
836
    {
837
    return mF.add(EffectNames.BRIGHTNESS, brightness);
838
    }
839

  
840
///////////////////////////////////////////////////////////////////////////////////////////////////
841
/**
842
 * Makes a certain sub-region of the Object smoothly change its contrast level.
843
 *        
844
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
845
 *                 at any given moment. Valid range: <0,infinity)
846
 * @param region   Region this Effect is limited to.
847
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
848
 * @return         ID of the effect added, or -1 if we failed to add one.
849
 */
850
  public long contrast(Data1D contrast, Data4D region, boolean smooth)
851
    {
852
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
853
    }
854

  
855
///////////////////////////////////////////////////////////////////////////////////////////////////
856
/**
857
 * Makes the whole Object smoothly change its contrast level.
858
 *
859
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
860
 *                 at any given moment. Valid range: <0,infinity)
861
 * @return         ID of the effect added, or -1 if we failed to add one.
862
 */
863
  public long contrast(Data1D contrast)
864
    {
865
    return mF.add(EffectNames.CONTRAST, contrast);
866
    }
867

  
868
///////////////////////////////////////////////////////////////////////////////////////////////////
869
/**
870
 * Makes a certain sub-region of the Object smoothly change its saturation level.
871
 *        
872
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
873
 *                   at any given moment. Valid range: <0,infinity)
874
 * @param region     Region this Effect is limited to.
875
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
876
 * @return           ID of the effect added, or -1 if we failed to add one.
877
 */
878
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
879
    {
880
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
881
    }
882

  
883
///////////////////////////////////////////////////////////////////////////////////////////////////
884
/**
885
 * Makes the whole Object smoothly change its saturation level.
886
 *
887
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
888
 *                   at any given moment. Valid range: <0,infinity)
889
 * @return           ID of the effect added, or -1 if we failed to add one.
890
 */
891
  public long saturation(Data1D saturation)
892
    {
893
    return mF.add(EffectNames.SATURATION, saturation);
894
    }
895

  
896
///////////////////////////////////////////////////////////////////////////////////////////////////
897
// Vertex-based effects  
898
///////////////////////////////////////////////////////////////////////////////////////////////////
899
/**
900
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
901
 *
902
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
903
 *               currently being dragged with.
904
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
905
 * @param region Region that masks the Effect.
906
 * @return       ID of the effect added, or -1 if we failed to add one.
907
 */
908
  public long distort(Data3D vector, Data3D center, Data4D region)
909
    {  
910
    return mV.add(EffectNames.DISTORT, vector, center, region);
911
    }
912

  
913
///////////////////////////////////////////////////////////////////////////////////////////////////
914
/**
915
 * Distort the whole Object by a (possibly changing in time) vector of force.
916
 *
917
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
918
 *               currently being dragged with.
919
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
920
 * @return       ID of the effect added, or -1 if we failed to add one.
921
 */
922
  public long distort(Data3D vector, Data3D center)
923
    {
924
    return mV.add(EffectNames.DISTORT, vector, center, null);
925
    }
926

  
927
///////////////////////////////////////////////////////////////////////////////////////////////////
928
/**
929
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
930
 * a (possibly changing in time) point on the Object.
931
 *
932
 * @param vector Vector of force that deforms the shape of the whole Object.
933
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
934
 * @param region Region that masks the Effect.
935
 * @return       ID of the effect added, or -1 if we failed to add one.
936
 */
937
  public long deform(Data3D vector, Data3D center, Data4D region)
938
    {
939
    return mV.add(EffectNames.DEFORM, vector, center, region);
940
    }
941

  
942
///////////////////////////////////////////////////////////////////////////////////////////////////
943
/**
944
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
945
 * a (possibly changing in time) point on the Object.
946
 *     
947
 * @param vector Vector of force that deforms the shape of the whole Object.
948
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
949
 * @return       ID of the effect added, or -1 if we failed to add one.
950
 */
951
  public long deform(Data3D vector, Data3D center)
952
    {  
953
    return mV.add(EffectNames.DEFORM, vector, center, null);
954
    }
955

  
956
///////////////////////////////////////////////////////////////////////////////////////////////////  
957
/**
958
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
959
 * away from the center (degree<=1)
960
 *
961
 * @param sink   The current degree of the Effect.
962
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
963
 * @param region Region that masks the Effect.
964
 * @return       ID of the effect added, or -1 if we failed to add one.
965
 */
966
  public long sink(Data1D sink, Data3D center, Data4D region)
967
    {
968
    return mV.add(EffectNames.SINK, sink, center, region);
969
    }
970

  
971
///////////////////////////////////////////////////////////////////////////////////////////////////
972
/**
973
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
974
 * away from the center (degree<=1)
975
 *
976
 * @param sink   The current degree of the Effect.
977
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
978
 * @return       ID of the effect added, or -1 if we failed to add one.
979
 */
980
  public long sink(Data1D sink, Data3D center)
981
    {
982
    return mV.add(EffectNames.SINK, sink, center);
983
    }
984

  
985
///////////////////////////////////////////////////////////////////////////////////////////////////
986
/**
987
 * Pull all points around the center of the Effect towards a line passing through the center
988
 * (that's if degree>=1) or push them away from the line (degree<=1)
989
 *
990
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
991
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
992
 * @param region Region that masks the Effect.
993
 * @return       ID of the effect added, or -1 if we failed to add one.
994
 */
995
  public long pinch(Data2D pinch, Data3D center, Data4D region)
996
    {
997
    return mV.add(EffectNames.PINCH, pinch, center, region);
998
    }
999

  
1000
///////////////////////////////////////////////////////////////////////////////////////////////////
1001
/**
1002
 * Pull all points around the center of the Effect towards a line passing through the center
1003
 * (that's if degree>=1) or push them away from the line (degree<=1)
1004
 *
1005
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
1006
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1007
 * @return       ID of the effect added, or -1 if we failed to add one.
1008
 */
1009
  public long pinch(Data2D pinch, Data3D center)
1010
    {
1011
    return mV.add(EffectNames.PINCH, pinch, center);
1012
    }
1013

  
1014
///////////////////////////////////////////////////////////////////////////////////////////////////  
1015
/**
1016
 * Rotate part of the Object around the Center of the Effect by a certain angle.
1017
 *
1018
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
1019
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1020
 * @param region Region that masks the Effect.
1021
 * @return       ID of the effect added, or -1 if we failed to add one.
1022
 */
1023
  public long swirl(Data1D swirl, Data3D center, Data4D region)
1024
    {    
1025
    return mV.add(EffectNames.SWIRL, swirl, center, region);
611
    return EffectQueue.setMax(Effect.FRAGMENT,max);
1026 612
    }
1027 613

  
1028 614
///////////////////////////////////////////////////////////////////////////////////////////////////
1029 615
/**
1030
 * Rotate the whole Object around the Center of the Effect by a certain angle.
616
 * Add a new Effect to our queue.
1031 617
 *
1032
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
1033
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1034
 * @return       ID of the effect added, or -1 if we failed to add one.
618
 * @param effect The Effect to add.
1035 619
 */
1036
  public long swirl(Data1D swirl, Data3D center)
620
  public void apply(Effect effect)
1037 621
    {
1038
    return mV.add(EffectNames.SWIRL, swirl, center);
1039
    }
1040

  
1041
///////////////////////////////////////////////////////////////////////////////////////////////////
1042
/**
1043
 * Directional, sinusoidal wave effect.
1044
 *
1045
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
1046
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
1047
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
1048
 *               describe the 'direction' of the wave.
1049
 *               <p>
1050
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
1051
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
1052
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
1053
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
1054
 *               <p>
1055
 *               <p>
1056
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
1057
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
1058
 *               will be sine shapes.
1059
 *               <p>
1060
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
1061
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
1062
 *               YZ-plane with be sine shapes.
1063
 *               <p>
1064
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
1065
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
1066
 *               value if sin at this point.
1067
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1068
 * @return       ID of the effect added, or -1 if we failed to add one.
1069
 */
1070
  public long wave(Data5D wave, Data3D center)
1071
    {
1072
    return mV.add(EffectNames.WAVE, wave, center, null);
1073
    }
1074

  
1075
///////////////////////////////////////////////////////////////////////////////////////////////////
1076
/**
1077
 * Directional, sinusoidal wave effect.
1078
 *
1079
 * @param wave   see {@link DistortedEffects#wave(Data5D,Data3D)}
1080
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1081
 * @param region Region that masks the Effect.
1082
 * @return       ID of the effect added, or -1 if we failed to add one.
1083
 */
1084
  public long wave(Data5D wave, Data3D center, Data4D region)
1085
    {
1086
    return mV.add(EffectNames.WAVE, wave, center, region);
622
    switch(effect.getType())
623
      {
624
      case Effect.VERTEX      : mV.add(effect); break;
625
      case Effect.FRAGMENT    : mF.add(effect); break;
626
      case Effect.MATRIX      : mM.add(effect); break;
627
   // case Effect.POSTPROCESS : mP.add(effect); break;
628
      }
1087 629
    }
1088 630
  }

Also available in: Unified diff