Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / Effect.java @ aa2f0486

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
public abstract class Effect
25
  {
26
  private final static int MAX_UNITY_DIM = 4;
27
  private final static int NUM_EFFECTS = EffectName.LENGTH;
28

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

    
36
  private static long mNextID = 0;
37

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

    
41
  static boolean[] mEnabled = new boolean[NUM_EFFECTS];
42

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

    
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

    
50
  public abstract boolean compute(float[] uniforms, int index, long currentDuration, long step );
51

    
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

    
54
  public static void onDestroy()
55
    {
56
    mNextID = 0;
57

    
58
    for(int i=0; i<NUM_EFFECTS; i++) mEnabled[i] = false;
59
    }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
  public boolean isUnity(float[] buffer, int index)
64
    {
65
    int name = mName.ordinal();
66

    
67
    switch(mUnityDim[name])
68
      {
69
      case 0: return true;
70
      case 1: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ];
71
      case 2: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ] &&
72
                     buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1];
73
      case 3: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ] &&
74
                     buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1] &&
75
                     buffer[index+2]==mUnity[MAX_UNITY_DIM*name+2];
76
      case 4: return buffer[index  ]==mUnity[MAX_UNITY_DIM*name  ] &&
77
                     buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1] &&
78
                     buffer[index+2]==mUnity[MAX_UNITY_DIM*name+2] &&
79
                     buffer[index+3]==mUnity[MAX_UNITY_DIM*name+3];
80
      }
81

    
82
    return false;
83
    }
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

    
86
  public EffectType getType()
87
    {
88
    return mType;
89
    }
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

    
93
  public EffectName getName()
94
    {
95
    return mName;
96
    }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

    
100
  public long getID()
101
    {
102
    return mID;
103
    }
104

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

    
107
  public String getString()
108
    {
109
    return mName.name();
110
    }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
  public boolean supportsCenter()
115
    {
116
    return mSupportsC;
117
    }
118

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

    
121
  public boolean supportsRegion()
122
    {
123
    return mSupportsR;
124
    }
125

    
126
///////////////////////////////////////////////////////////////////////////////////////////////////
127

    
128
  public int getDimension()
129
    {
130
    return mDimension;
131
    }
132

    
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

    
135
  Effect(EffectName name)
136
    {
137
    mName      = name;
138
    mType      = name.getType();
139
    mDimension = name.getDimension();
140
    mSupportsC = name.supportsCenter();
141
    mSupportsR = name.supportsRegion();
142

    
143
    int n = name.ordinal();
144
    float[] u = name.getUnity();
145
    int l = name.getUnity().length;
146

    
147
    for(int i=0; i<l; i++)
148
      {
149
      mUnity[n*MAX_UNITY_DIM+i] = u[i];
150
      }
151

    
152
    mUnityDim[n] = l;
153

    
154
    mID = ((mNextID++)<<EffectType.LENGTH) + mType.ordinal();
155
    }
156
  }
(1-1/25)