Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / EffectName.java @ c0255951

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2017 Leszek Koltunski  leszek@koltunski.pl                                          //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// This library is free software; you can redistribute it and/or                                 //
7
// modify it under the terms of the GNU Lesser General Public                                    //
8
// License as published by the Free Software Foundation; either                                  //
9
// version 2.1 of the License, or (at your option) any later version.                            //
10
//                                                                                               //
11
// This library 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 GNU                             //
14
// Lesser General Public License for more details.                                               //
15
//                                                                                               //
16
// You should have received a copy of the GNU Lesser General Public                              //
17
// License along with this library; if not, write to the Free Software                           //
18
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA                //
19
///////////////////////////////////////////////////////////////////////////////////////////////////
20

    
21
package org.distorted.library.effect;
22

    
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24
/**
25
 * Names of Effects one can add to the DistortedEffects queues.
26
 * <p>
27
 * Effect's 'Type' is one of the constants defined in {@link EffectType}.
28
 * </p>
29
 * <p>
30
 * Effect's 'Uniforms' are a vector of 7 (matrix effects) 12 (vertex) or 8 (fragment) floats, which
31
 * together form full information how to compute a given effect.
32
 * Typically, some of those values will be Interpolated in CPU (by one of the 'EffectQueueX.compute()'
33
 * methods) and the effect of such Interpolation sent to the Shaders.
34
 * </p>
35
 * <p>
36
 * Effect's 'Unity' is such a particular vector of its 'interpolated values' which makes the
37
 * effect NULL. For example, if the effect is 'MOVE' by a 3-dimensional vector, then a 'NULL
38
 * MOVE' is a MOVE by vector (0,0,0), thus (0,0,0) is the unity of the MOVE effect.
39
 * This is used by the EffectQueue classes to decide if the final form of the Effect is NULL - and
40
 * thus if it can safely be removed from Effect Queues without affecting the visual in any way.
41
 * </p>
42
 */
43

    
44
public enum EffectName
45
  {
46
  // EFFECT NAME /////// EFFECT TYPE ////////// EFFECT UNITY //////////// DIM REGION CENTER // CLASS
47
  ROTATE           ( EffectType.MATRIX  ,   new float[] {0.0f}           , 4, 0,     3    , MatrixEffectRotate.class       ),
48
  QUATERNION       ( EffectType.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} , 4, 0,     3    , MatrixEffectQuaternion.class   ),
49
  MOVE             ( EffectType.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} , 3, 0,     0    , MatrixEffectMove.class         ),
50
  SCALE            ( EffectType.MATRIX  ,   new float[] {1.0f,1.0f,1.0f} , 3, 0,     0    , MatrixEffectScale.class        ),
51
  SHEAR            ( EffectType.MATRIX  ,   new float[] {0.0f,0.0f,0.0f} , 3, 0,     3    , MatrixEffectShear.class        ),
52

    
53
  DISTORT          ( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 3, 4,     3    , VertexEffectDistort.class      ),
54
  DEFORM           ( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 4, 4,     3    , VertexEffectDeform.class       ),
55
  SINK             ( EffectType.VERTEX  ,   new float[] {1.0f}           , 1, 4,     3    , VertexEffectSink.class         ),
56
  PINCH            ( EffectType.VERTEX  ,   new float[] {1.0f}           , 3, 4,     3    , VertexEffectPinch.class        ),
57
  SWIRL            ( EffectType.VERTEX  ,   new float[] {0.0f}           , 1, 4,     3    , VertexEffectSwirl.class        ),
58
  WAVE             ( EffectType.VERTEX  ,   new float[] {0.0f}           , 5, 4,     3    , VertexEffectWave.class         ),
59
  DISAPPEAR        ( EffectType.VERTEX  ,   new float[] {}               , 0, 0,     0    , VertexEffectDisappear.class    ),
60

    
61
  VERTEX_MOVE      ( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 3, 0,     0    , VertexEffectMove.class         ),
62
  VERTEX_QUATERNION( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 4, 0,     3    , VertexEffectQuaternion.class   ),
63
  VERTEX_ROTATE    ( EffectType.VERTEX  ,   new float[] {0.0f}           , 4, 0,     3    , VertexEffectRotate.class       ),
64
  VERTEX_SCALE     ( EffectType.VERTEX  ,   new float[] {1.0f,1.0f,1.0f} , 3, 0,     0    , VertexEffectScale.class        ),
65
  VERTEX_SHEAR     ( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 3, 0,     3    , VertexEffectShear.class        ),
66

    
67
  ALPHA            ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectAlpha.class      ),
68
  SMOOTH_ALPHA     ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectAlpha.class      ),
69
  CHROMA           ( EffectType.FRAGMENT,   new float[] {0.0f}           , 4, 3,     3    , FragmentEffectChroma.class     ),
70
  SMOOTH_CHROMA    ( EffectType.FRAGMENT,   new float[] {0.0f}           , 4, 3,     3    , FragmentEffectChroma.class     ),
71
  BRIGHTNESS       ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectBrightness.class ),
72
  SMOOTH_BRIGHTNESS( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectBrightness.class ),
73
  SATURATION       ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectSaturation.class ),
74
  SMOOTH_SATURATION( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectSaturation.class ),
75
  CONTRAST         ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectContrast.class   ),
76
  SMOOTH_CONTRAST  ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectContrast.class   ),
77

    
78
  BLUR             ( EffectType.POSTPROCESS,new float[] {0.0f}           , 2, 0,     0    , PostprocessEffectBlur.class    ),
79
  GLOW             ( EffectType.POSTPROCESS,new float[] {0.0f}           , 6, 0,     0    , PostprocessEffectGlow.class    ),
80
  BORDER           ( EffectType.POSTPROCESS,new float[] {0.0f}           , 5, 0,     0    , PostprocessEffectBorder.class  ),
81
  ;
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

    
85
  public static final int LENGTH = values().length;
86

    
87
  private final EffectType type;
88
  private final float[] unity;
89
  private final int dimension;
90
  private final int regionDim;
91
  private final int centerDim;
92
  private final Class<? extends Effect> effectClass;
93

    
94
  private static final int[] dimensions;
95
  private static final int[] regionDimension;
96
  private static final int[] centerDimension;
97
  private static final EffectName[] names;  // copy the values() to a local variable so that we
98
                                            // don't have to keep recreating the array every time
99
  static
100
    {
101
    int i=0;
102

    
103
    dimensions      = new int[LENGTH];
104
    regionDimension = new int[LENGTH];
105
    centerDimension = new int[LENGTH];
106
    names           = new EffectName[LENGTH];
107

    
108
    for(EffectName name: EffectName.values())
109
      {
110
      dimensions[i]      = name.dimension;
111
      regionDimension[i] = name.regionDim;
112
      centerDimension[i] = name.centerDim;
113
      names[i]           = name;
114

    
115
      i++;
116
      }
117
    }
118

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

    
121
  float[] getUnity()
122
    {
123
    return unity;
124
    }
125

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

    
128
  EffectName(EffectType type, float[] unity, int dimension, int regionDim,
129
             int centerDim, Class<? extends Effect> effectClass )
130
    {
131
    this.type        = type;
132
    this.unity       = unity;
133
    this.dimension   = dimension;
134
    this.regionDim   = regionDim;
135
    this.centerDim   = centerDim;
136
    this.effectClass = effectClass;
137
    }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140
// PUBLIC API
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142
/**
143
 * Returns the Type of an individual Effect. For example, EffectName.ROTATE.getType() will
144
 * return EffectType.MATRIX.
145
 * @return type of the effect.
146
 */
147
  public EffectType getType()
148
    {
149
    return type;
150
    }
151

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153
/**
154
 * Returns the Class of an individual Effect. For example, EffectName.ROTATE.getEffectClass()
155
 * returns MatrixEffectRotate.class.
156
 * @return effect class.
157
 */
158
  public Class<? extends Effect> getEffectClass()
159
    {
160
    return effectClass;
161
    }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164
/**
165
 * Returns the i-th EffectName.
166
 * <p>
167
 * If you want to loop over all possible Effects, you need this.
168
 */
169
  public static EffectName getName(int ordinal)
170
    {
171
    return names[ordinal];
172
    }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175
/**
176
 * Returns the dimension of an Effect (in other words, the number of interpolated values).
177
 * @return dimension of the Effect.
178
 */
179
  public int getEffectDimension() { return dimensions[ordinal()]; }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182
/**
183
 * What is the dimension of the Region supported by this effect?
184
 * @return Dimension of the Region supported (0-region not supported at all).
185
 */
186
  public int getRegionDimension() { return regionDimension[ordinal()]; }
187

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189
/**
190
 * What is the dimension of the Center supported by this effect?
191
 * @return Dimension of the Center supported (0-center not supported at all).
192
 */
193
  public int getCenterDimension() { return centerDimension[ordinal()]; }
194
  }
195

    
(2-2/34)