Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 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;
21

    
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23
/**
24
 * Names of Effects one can apply to DistortedObjects.
25
 */
26
public enum EffectNames
27
  {
28
  // EFFECT NAME /////// EFFECT TYPE ////////////// UNITY /////////////////////////
29
   
30
  ROTATE           ( EffectTypes.MATRIX  ,   new float[] {0.0f}           ),
31
  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)
32
  MOVE             ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),
33
  SCALE            ( EffectTypes.MATRIX  ,   new float[] {1.0f,1.0f,1.0f} ),
34
  SHEAR            ( EffectTypes.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} ),
35
  // add new Matrix effects here...
36
  
37
  DISTORT          ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} ),      // keep this the first VERT effect (reason: getType)
38
  DEFORM           ( EffectTypes.VERTEX  ,   new float[] {0.0f,0.0f}      ),
39
  SINK             ( EffectTypes.VERTEX  ,   new float[] {1.0f}           ),
40
  SWIRL            ( EffectTypes.VERTEX  ,   new float[] {0.0f}           ),
41
  WAVE             ( EffectTypes.VERTEX  ,   new float[] {0.0f}           ),
42
  // add new Vertex Effects here...
43
  
44
  MACROBLOCK       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),      // keep this the first FRAG effect (reason: getType)
45
  ALPHA            ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
46
  SMOOTH_ALPHA     ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
47
  CHROMA           ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
48
  SMOOTH_CHROMA    ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
49
  BRIGHTNESS       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
50
  SMOOTH_BRIGHTNESS( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
51
  SATURATION       ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
52
  SMOOTH_SATURATION( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
53
  CONTRAST         ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
54
  SMOOTH_CONTRAST  ( EffectTypes.FRAGMENT,   new float[] {1.0f}           ),
55
  HUE              ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
56
  SMOOTH_HUE       ( EffectTypes.FRAGMENT,   new float[] {0.0f}           ),
57
  // add new Fragment effects here...
58

    
59
  SAVE_PNG         ( EffectTypes.OTHER   ,   null                         ),      // OTHER Effects don't have Unities.
60
  SAVE_MP4         ( EffectTypes.OTHER   ,   null                         );      //
61
  // add new Other effects here...
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64
  
65
  private static final int MAXDIM = 4;  // maximum supported dimension of an effect  
66
  
67
  private EffectTypes type;
68
  private float[] unity;
69
  
70
  static private float[] unities;
71
  static private int[] dimensions;
72
  
73
  static
74
    {
75
    int len = values().length;
76
    int i=0;
77
    
78
    dimensions = new int[len];
79
    unities    = new float[MAXDIM*len];
80
    
81
    for(EffectNames name: EffectNames.values())
82
      {
83
      dimensions[i] = (name.unity==null ? 0 : name.unity.length);
84
      
85
      switch(dimensions[i])
86
        {
87
        case 4: unities[MAXDIM*i+3] = name.unity[3];
88
        case 3: unities[MAXDIM*i+2] = name.unity[2];
89
        case 2: unities[MAXDIM*i+1] = name.unity[1];
90
        case 1: unities[MAXDIM*i+0] = name.unity[0];
91
        case 0: break;
92
        }
93
      
94
      i++;  
95
      }
96
    }
97
  
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99
  
100
  EffectNames(EffectTypes type, float[] unity)
101
    {
102
    this.type = type;  
103
    this.unity= unity;
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107
// yes, I know we could have used values(i) but that allocates a new copy each time!
108

    
109
  static EffectTypes getType(int ordinal)
110
    {
111
    if( ordinal<DISTORT.ordinal()     ) return EffectTypes.MATRIX;
112
    if( ordinal<MACROBLOCK.ordinal()  ) return EffectTypes.VERTEX;
113
    if( ordinal<SAVE_PNG.ordinal()    ) return EffectTypes.FRAGMENT;
114

    
115
    return EffectTypes.OTHER;
116
    }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
  static void fillWithUnities(int ordinal, float[] buffer, int index)
121
    {
122
    switch(dimensions[ordinal])
123
      {
124
      case 0: break;
125
      case 1: buffer[index+0]=unities[MAXDIM*ordinal+0];
126
              break;
127
      case 2: buffer[index+0]=unities[MAXDIM*ordinal+0]; 
128
              buffer[index+1]=unities[MAXDIM*ordinal+1];
129
              break;
130
      case 3: buffer[index+0]=unities[MAXDIM*ordinal+0]; 
131
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
132
              buffer[index+2]=unities[MAXDIM*ordinal+2];
133
              break;
134
      case 4: buffer[index+0]=unities[MAXDIM*ordinal+0]; 
135
              buffer[index+1]=unities[MAXDIM*ordinal+1]; 
136
              buffer[index+2]=unities[MAXDIM*ordinal+2];
137
              buffer[index+3]=unities[MAXDIM*ordinal+3];
138
              break;
139
      }  
140
    }
141
  
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143
  
144
  static boolean isUnity(int ordinal, float[] buffer, int index)
145
    {
146
    switch(dimensions[ordinal])
147
      {
148
      case 0: return true;
149
      case 1: return buffer[index+0]==unities[MAXDIM*ordinal+0];
150
      case 2: return buffer[index+0]==unities[MAXDIM*ordinal+0] && 
151
                     buffer[index+1]==unities[MAXDIM*ordinal+1];
152
      case 3: return buffer[index+0]==unities[MAXDIM*ordinal+0] && 
153
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
154
                     buffer[index+2]==unities[MAXDIM*ordinal+2];
155
      case 4: return buffer[index+0]==unities[MAXDIM*ordinal+0] && 
156
                     buffer[index+1]==unities[MAXDIM*ordinal+1] && 
157
                     buffer[index+2]==unities[MAXDIM*ordinal+2] &&
158
                     buffer[index+3]==unities[MAXDIM*ordinal+3];
159
      }
160
   
161
    return false;
162
    }
163

    
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165
// PUBLIC API
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167
/**
168
 * Returns the Type of an individual Effect. For example, EffectNames.ROTATION.getType() will
169
 * return EffectTypes.MATRIX.
170
 * @return type of the effect.
171
 */
172
  public EffectTypes getType()
173
    {
174
    return type;
175
    }
176
  }
(11-11/30)