Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / Effect.java @ 2f1f7570

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2017 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.effect;
21

    
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23
/**
24
 * Abstract Effect of any type.
25
 */
26
public abstract class Effect
27
  {
28
  private final static int MAX_UNITY_DIM = 4;
29
  private final static int NUM_EFFECTS = EffectName.LENGTH;
30

    
31
  private final long mID;
32
  private final EffectType mType;
33
  private final EffectName mName;
34
  private final int mDimension;
35
  private final boolean mSupportsR;
36
  private final boolean mSupportsC;
37

    
38
  private static long mNextID = 0;
39

    
40
  private final static float[] mUnity= new float[MAX_UNITY_DIM*NUM_EFFECTS];
41
  private final static int[]   mUnityDim = new int[NUM_EFFECTS];
42

    
43
  static boolean[] mEnabled = new boolean[NUM_EFFECTS];
44

    
45
  static
46
    {
47
    for(int i=0; i<NUM_EFFECTS; i++) mEnabled[i] = false;
48
    }
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

    
52
  Effect(EffectName name)
53
    {
54
    mName      = name;
55
    mType      = name.getType();
56
    mDimension = name.getDimension();
57
    mSupportsC = name.supportsCenter();
58
    mSupportsR = name.supportsRegion();
59

    
60
    int n = name.ordinal();
61
    float[] u = name.getUnity();
62
    int l = u.length;
63

    
64
    for(int i=0; i<l; i++)
65
      {
66
      mUnity[n*MAX_UNITY_DIM+i] = u[i];
67
      }
68

    
69
    mUnityDim[n] = l;
70

    
71
    mID = ((mNextID++)<<EffectType.LENGTH) + mType.ordinal();
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75
/**
76
 * Only for use by the library itself.
77
 *
78
 * @y.exclude
79
 */
80
  public static void onDestroy()
81
    {
82
    mNextID = 0;
83

    
84
    for(int i=0; i<NUM_EFFECTS; i++) mEnabled[i] = false;
85

    
86
    MatrixEffect.destroyStatics();
87
    VertexEffect.destroyStatics();
88
    PostprocessEffect.destroyStatics();
89
    }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92
/**
93
 * Only for use by the library itself.
94
 *
95
 * @y.exclude
96
 */
97
  public abstract boolean compute(float[] uniforms, int index, long currentDuration, long step );
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100
// PUBLIC API
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102
/**
103
 * Do the set of Uniforms written in buffer[index], buffer[index+1], etc represent a Unity, i.e a
104
 * null Effect?
105
 */
106
  public boolean isUnity(float[] buffer, int index)
107
    {
108
    int name = mName.ordinal();
109

    
110
    switch(mUnityDim[name])
111
      {
112
      case 0: return true;
113
      case 1: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ];
114
      case 2: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ] &&
115
                     buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1];
116
      case 3: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ] &&
117
                     buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1] &&
118
                     buffer[index+2]==mUnity[MAX_UNITY_DIM*name+2];
119
      case 4: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ] &&
120
                     buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1] &&
121
                     buffer[index+2]==mUnity[MAX_UNITY_DIM*name+2] &&
122
                     buffer[index+3]==mUnity[MAX_UNITY_DIM*name+3];
123
      }
124

    
125
    return false;
126
    }
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128
/**
129
 * Return the EffectType enum corresponding to this Effect.
130
 *
131
 * @see EffectType
132
 */
133
  public EffectType getType()
134
    {
135
    return mType;
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139
/**
140
 * Return the EffectName enum corresponding to this Effect.
141
 *
142
 * @see EffectName
143
 */
144
  public EffectName getName()
145
    {
146
    return mName;
147
    }
148

    
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150
/**
151
 * Return the unique ID of this Effect.
152
 */
153
  public long getID()
154
    {
155
    return mID;
156
    }
157

    
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159
/**
160
 * Return a printable name of this Effect.
161
 */
162
  public String getString()
163
    {
164
    return mName.name();
165
    }
166

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168
/**
169
 * Does this effect have a Center?
170
 */
171
  public boolean supportsCenter()
172
    {
173
    return mSupportsC;
174
    }
175

    
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177
/**
178
 * Does this effect support being masked by a Region?
179
 */
180
  public boolean supportsRegion()
181
    {
182
    return mSupportsR;
183
    }
184

    
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186
/**
187
 * Return the number of Uniforms needed to describe this effect.
188
 */
189
  public int getDimension()
190
    {
191
    return mDimension;
192
    }
193
  }
(1-1/26)