Project

General

Profile

« Previous | Next » 

Revision c3651001

Added by Leszek Koltunski over 7 years ago

Convert the first few Apps to the new Effect API.

View differences:

src/main/java/org/distorted/library/effect/Effect.java
24 24
public abstract class Effect
25 25
  {
26 26
  private final static int MAX_UNITY_DIM = 4;
27
  private final static int NUM_EFFECTS = EffectName.size();
27
  private final static int NUM_EFFECTS = EffectName.LENGTH;
28 28

  
29 29
  private final long mID;
30 30
  private final EffectType mType;
src/main/java/org/distorted/library/effect/EffectName.java
63 63

  
64 64
///////////////////////////////////////////////////////////////////////////////////////////////////
65 65

  
66
  public static final int LENGTH = values().length;
66 67
  private final EffectType type;
67

  
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

  
70
  EffectName(EffectType type)
68
  private static final EffectName[] names;  // copy the values() to a local variable so that we
69
                                            // don't have to keep recreating the array every time
70
  static
71 71
    {
72
    this.type = type;
72
    int i=0;
73
    names = new EffectName[LENGTH];
74

  
75
    for(EffectName name: EffectName.values())
76
      {
77
      names[i++] = name;
78
      }
73 79
    }
74 80

  
75 81
///////////////////////////////////////////////////////////////////////////////////////////////////
76 82

  
77
  static int size()
83
  EffectName(EffectType type)
78 84
    {
79
    return values().length;
85
    this.type = type;
80 86
    }
81 87

  
82 88
///////////////////////////////////////////////////////////////////////////////////////////////////
......
91 97
    {
92 98
    return type;
93 99
    }
100

  
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102
/**
103
 * Returns the i-th EffectName.
104
 * <p>
105
 * If you want to loop over all possible Effects, you need this.
106
 */
107
  public static EffectName getName(int ordinal)
108
    {
109
    return names[ordinal];
110
    }
94 111
  }
95 112

  
src/main/java/org/distorted/library/main/DistortedEffects.java
52 52
  /// MAIN PROGRAM ///
53 53
  private static DistortedProgram mMainProgram;
54 54
  private static int mMainTextureH;
55
  private static ArrayList<EffectName> mEnabledEffects = new ArrayList<>();
55
  private static boolean[] mEffectEnabled = new boolean[EffectName.LENGTH];
56

  
57
  static
58
    {
59
    int len = EffectName.LENGTH;
60
    for(int i=0; i<len; i++)
61
      {
62
      mEffectEnabled[i] = false;
63
      }
64
    }
56 65

  
57 66
  /// BLIT PROGRAM ///
58 67
  private static DistortedProgram mBlitProgram;
......
99 108
    String mainVertHeader= Distorted.GLSL_VERSION;
100 109
    String mainFragHeader= Distorted.GLSL_VERSION;
101 110

  
111
    EffectName name;
112
    EffectType type;
102 113
    boolean foundF = false;
103 114
    boolean foundV = false;
104
    int effects = mEnabledEffects.size();
105
    EffectName effect;
106
    EffectType type;
107 115

  
108
    for(int i=0; i<effects; i++)
116
    for(int i=0; i<mEffectEnabled.length; i++)
109 117
      {
110
      effect = mEnabledEffects.remove(0);
111
      type   = effect.getType();
112

  
113
      if( type == EffectType.VERTEX )
114
        {
115
        mainVertHeader += ("#define "+effect.name()+" "+effect.ordinal()+"\n");
116
        foundV = true;
117
        }
118
      else if( type == EffectType.FRAGMENT )
118
      if( mEffectEnabled[i] )
119 119
        {
120
        mainFragHeader += ("#define "+effect.name()+" "+effect.ordinal()+"\n");
121
        foundF = true;
120
        name = EffectName.getName(i);
121
        type = name.getType();
122

  
123
        if( type == EffectType.VERTEX )
124
          {
125
          mainVertHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
126
          foundV = true;
127
          }
128
        else if( type == EffectType.FRAGMENT )
129
          {
130
          mainFragHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
131
          foundF = true;
132
          }
122 133
        }
123 134
      }
124 135

  
......
342 353
  static void onDestroy()
343 354
    {
344 355
    mNextID = 0;
356

  
357
    for(int i=0; i<EffectName.LENGTH; i++)
358
      {
359
      mEffectEnabled[i] = false;
360
      }
345 361
    }
346 362

  
347 363
///////////////////////////////////////////////////////////////////////////////////////////////////
......
501 517
 */
502 518
  public static void enableEffect(EffectName name)
503 519
    {
504
    mEnabledEffects.add(name);
520
    mEffectEnabled[name.ordinal()] = true;
505 521
    }
506 522

  
507 523
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff