Project

General

Profile

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

library / src / main / java / org / distorted / library / EffectNames.java @ c6e1c219

1 6a06a912 Leszek Koltunski
package org.distorted.library;
2
3
///////////////////////////////////////////////////////////////////////////////////////////////////
4
5
enum EffectNames 
6
  {
7
  // EFFECT NAME /////// EFFECT TYPE ////////////// UNITY /////////////////////////
8
   
9 1e438fc7 Leszek Koltunski
  ROTATE           ( EffectTypes.MATRIX  ,   new float[] {0.0f}           ),
10
  QUATERNION       ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),      // quaternion is a unity iff its axis (x,y,z) is (0,0,0)
11
  MOVE             ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),
12
  SCALE            ( EffectTypes.MATRIX  ,   new float[] {1.0f,1.0f,1.0f} ),
13
  SHEAR            ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),
14
  // add new Matrix effects here...
15 6a06a912 Leszek Koltunski
  
16 1e438fc7 Leszek Koltunski
  DISTORT          ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} ),      // keep this the first VERT effect (reason: getType)
17
  DEFORM           ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f}      ),
18
  SINK             ( EffectTypes.VERTEX  ,   new float[] {1.0f}           ),
19
  SWIRL            ( EffectTypes.VERTEX  ,   new float[] {0.0f}           ),
20
  WAVE             ( EffectTypes.VERTEX  ,   new float[] {0.0f}           ),
21 6a06a912 Leszek Koltunski
  // add new Vertex Effects here...
22
  
23 1e438fc7 Leszek Koltunski
  MACROBLOCK       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),      // keep this the first FRAG effect (reason: getType)
24
  ALPHA            ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
25
  SMOOTH_ALPHA     ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
26
  CHROMA           ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
27
  SMOOTH_CHROMA    ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
28
  BRIGHTNESS       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
29
  SMOOTH_BRIGHTNESS( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
30
  SATURATION       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
31
  SMOOTH_SATURATION( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
32
  CONTRAST         ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
33
  SMOOTH_CONTRAST  ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
34
  HUE              ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
35
  SMOOTH_HUE       ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
36 6a06a912 Leszek Koltunski
  // add new Fragment effects here...
37
38 1e438fc7 Leszek Koltunski
  SAVE_PNG         ( EffectTypes.OTHER   ,   null                         ),      // OTHER Effects don't have Unities.
39
  SAVE_MP4         ( EffectTypes.OTHER   ,   null                         );      //
40
  // add new Other effects here...
41 b3618cb5 Leszek Koltunski
42 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
43
  
44
  private static final int MAXDIM = 4;  // maximum supported dimension of an effect  
45
  
46 1e438fc7 Leszek Koltunski
  private EffectTypes type;
47 6a06a912 Leszek Koltunski
  private float[] unity;
48
  
49
  static private float[] unities;
50
  static private int[] dimensions;
51
  
52
  static
53
    {
54
    int len = values().length;
55
    int i=0;
56
    
57
    dimensions = new int[len];
58
    unities    = new float[MAXDIM*len];
59
    
60
    for(EffectNames name: EffectNames.values())
61
      {
62 b3618cb5 Leszek Koltunski
      dimensions[i] = (name.unity==null ? 0 : name.unity.length);
63 6a06a912 Leszek Koltunski
      
64
      switch(dimensions[i])
65
        {
66
        case 4: unities[MAXDIM*i+3] = name.unity[3];
67
        case 3: unities[MAXDIM*i+2] = name.unity[2];
68
        case 2: unities[MAXDIM*i+1] = name.unity[1];
69
        case 1: unities[MAXDIM*i+0] = name.unity[0];
70
        case 0: break;
71
        }
72
      
73
      i++;  
74
      }
75
    }
76
  
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
  
79 1e438fc7 Leszek Koltunski
  EffectNames(EffectTypes type, float[] unity)
80 6a06a912 Leszek Koltunski
    {
81
    this.type = type;  
82
    this.unity= unity;
83
    }
84
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86
  
87 1e438fc7 Leszek Koltunski
  public EffectTypes getType()
88 6a06a912 Leszek Koltunski
    {
89
    return type;  
90
    }
91
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93 c6e1c219 Leszek Koltunski
// yes, I know we could have used values(i)
94
95 1e438fc7 Leszek Koltunski
  static EffectTypes getType(int ordinal)
96 6a06a912 Leszek Koltunski
    {
97 1e438fc7 Leszek Koltunski
    if( ordinal<DISTORT.ordinal()     ) return EffectTypes.MATRIX;
98
    if( ordinal<MACROBLOCK.ordinal()  ) return EffectTypes.VERTEX;
99
    if( ordinal<SAVE_PNG.ordinal()    ) return EffectTypes.FRAGMENT;
100 b3618cb5 Leszek Koltunski
101 1e438fc7 Leszek Koltunski
    return EffectTypes.OTHER;
102 6a06a912 Leszek Koltunski
    }
103
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105
106
  static void fillWithUnities(int ordinal, float[] buffer, int index)
107
    {
108
    switch(dimensions[ordinal])
109
      {
110
      case 0: break;
111
      case 1: buffer[index+0]=unities[MAXDIM*ordinal+0];
112
              break;
113
      case 2: buffer[index+0]=unities[MAXDIM*ordinal+0]; 
114
              buffer[index+1]=unities[MAXDIM*ordinal+1];
115
              break;
116
      case 3: buffer[index+0]=unities[MAXDIM*ordinal+0]; 
117
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
118
              buffer[index+2]=unities[MAXDIM*ordinal+2];
119
              break;
120
      case 4: buffer[index+0]=unities[MAXDIM*ordinal+0]; 
121
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
122
              buffer[index+2]=unities[MAXDIM*ordinal+2];
123
              buffer[index+3]=unities[MAXDIM*ordinal+3];
124
              break;
125
      }  
126
    }
127
  
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129
  
130
  static boolean isUnity(int ordinal, float[] buffer, int index)
131
    {
132
    switch(dimensions[ordinal])
133
      {
134
      case 0: return true;
135
      case 1: return buffer[index+0]==unities[MAXDIM*ordinal+0];
136
      case 2: return buffer[index+0]==unities[MAXDIM*ordinal+0] && 
137
                     buffer[index+1]==unities[MAXDIM*ordinal+1];
138
      case 3: return buffer[index+0]==unities[MAXDIM*ordinal+0] && 
139
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
140
                     buffer[index+2]==unities[MAXDIM*ordinal+2];
141
      case 4: return buffer[index+0]==unities[MAXDIM*ordinal+0] && 
142
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
143
                     buffer[index+2]==unities[MAXDIM*ordinal+2] &&
144
                     buffer[index+3]==unities[MAXDIM*ordinal+3];
145
      }
146
   
147
    return false;
148
    }
149
  }
150
151
///////////////////////////////////////////////////////////////////////////////////////////////////