Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / EffectName.java @ 9f34a0f6

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.effect;
21

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

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

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

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

    
73
  BLUR             ( EffectType.POSTPROCESS,new float[] {0.0f}           , 1, 0,     0    , PostprocessEffectBlur.class    ),
74
  GLOW             ( EffectType.POSTPROCESS,new float[] {0.0f}           , 5, 0,     0    , PostprocessEffectGlow.class    );
75

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

    
78
  public static final int LENGTH = values().length;
79

    
80
  private final EffectType type;
81
  private final float[] unity;
82
  private final int dimension;
83
  private final int regionDim;
84
  private final int centerDim;
85
  private final Class<? extends Effect> effectClass;
86

    
87
  private static final int[] dimensions;
88
  private static final int[] regionDimension;
89
  private static final int[] centerDimension;
90
  private static final EffectName[] names;  // copy the values() to a local variable so that we
91
                                            // don't have to keep recreating the array every time
92
  static
93
    {
94
    int i=0;
95

    
96
    dimensions      = new int[LENGTH];
97
    regionDimension = new int[LENGTH];
98
    centerDimension = new int[LENGTH];
99
    names           = new EffectName[LENGTH];
100

    
101
    for(EffectName name: EffectName.values())
102
      {
103
      dimensions[i]      = name.dimension;
104
      regionDimension[i] = name.regionDim;
105
      centerDimension[i] = name.centerDim;
106
      names[i]           = name;
107

    
108
      i++;
109
      }
110
    }
111

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

    
114
  float[] getUnity()
115
    {
116
    return unity;
117
    }
118

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

    
121
  EffectName(EffectType type, float[] unity, int dimension, int regionDim,
122
             int centerDim, Class<? extends Effect> effectClass )
123
    {
124
    this.type        = type;
125
    this.unity       = unity;
126
    this.dimension   = dimension;
127
    this.regionDim   = regionDim;
128
    this.centerDim   = centerDim;
129
    this.effectClass = effectClass;
130
    }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133
// PUBLIC API
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135
/**
136
 * Returns the Type of an individual Effect. For example, EffectName.ROTATE.getType() will
137
 * return EffectType.MATRIX.
138
 * @return type of the effect.
139
 */
140
  public EffectType getType()
141
    {
142
    return type;
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146
/**
147
 * Returns the Class of an individual Effect. For example, EffectName.ROTATE.getEffectClass()
148
 * returns MatrixEffectRotate.class.
149
 * @return effect class.
150
 */
151
  public Class<? extends Effect> getEffectClass()
152
    {
153
    return effectClass;
154
    }
155

    
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157
/**
158
 * Returns the i-th EffectName.
159
 * <p>
160
 * If you want to loop over all possible Effects, you need this.
161
 */
162
  public static EffectName getName(int ordinal)
163
    {
164
    return names[ordinal];
165
    }
166

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168
/**
169
 * Returns the dimension of an Effect (in other words, the number of interpolated values).
170
 * @return dimension of the Effect.
171
 */
172
  public int getEffectDimension() { return dimensions[ordinal()]; }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175
/**
176
 * What is the dimension of the Region supported by this effect?
177
 * @return Dimension of the Region supported (0-region not supported at all).
178
 */
179
  public int getRegionDimension() { return regionDimension[ordinal()]; }
180

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

    
(2-2/29)