Project

General

Profile

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

library / src / main / java / org / distorted / library / effect / EffectName.java @ 7b2f81e8

1 da9b3f07 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4 46b572b5 Leszek Koltunski
// This file is part of Distorted.                                                               //
5 da9b3f07 Leszek Koltunski
//                                                                                               //
6 46b572b5 Leszek Koltunski
// Distorted is free software: you can redistribute it and/or modify                             //
7 da9b3f07 Leszek Koltunski
// 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 46b572b5 Leszek Koltunski
// Distorted is distributed in the hope that it will be useful,                                  //
12 da9b3f07 Leszek Koltunski
// 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 46b572b5 Leszek Koltunski
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18 da9b3f07 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 9d0d8530 leszek
 * </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 da9b3f07 Leszek Koltunski
 */
42
43
public enum EffectName
44
  {
45 143095f7 Leszek Koltunski
  // EFFECT NAME /////// EFFECT TYPE ////////// EFFECT UNITY //////////// DIM REGION CENTER // CLASS
46 b24e4719 Leszek Koltunski
  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 5e96393c Leszek Koltunski
  DISTORT          ( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 3, 4,     3    , VertexEffectDistort.class      ),
53 0f10a0b6 Leszek Koltunski
  DEFORM           ( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 4, 4,     3    , VertexEffectDeform.class       ),
54 5e96393c Leszek Koltunski
  SINK             ( EffectType.VERTEX  ,   new float[] {1.0f}           , 1, 4,     3    , VertexEffectSink.class         ),
55 aee0b581 Leszek Koltunski
  PINCH            ( EffectType.VERTEX  ,   new float[] {1.0f}           , 3, 4,     3    , VertexEffectPinch.class        ),
56 5e96393c Leszek Koltunski
  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 f0d1f003 Leszek Koltunski
  DISAPPEAR        ( EffectType.VERTEX  ,   new float[] {}               , 0, 0,     0    , VertexEffectDisappear.class    ),
59
60 e979d285 Leszek Koltunski
  VERTEX_MOVE      ( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 3, 0,     0    , VertexEffectMove.class         ),
61
  VERTEX_QUATERNION( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 4, 0,     3    , VertexEffectQuaternion.class   ),
62 9f34a0f6 Leszek Koltunski
  VERTEX_ROTATE    ( EffectType.VERTEX  ,   new float[] {0.0f}           , 4, 0,     3    , VertexEffectRotate.class       ),
63 a918bba1 Leszek Koltunski
  VERTEX_SCALE     ( EffectType.VERTEX  ,   new float[] {1.0f,1.0f,1.0f} , 3, 0,     0    , VertexEffectScale.class        ),
64 00be51f0 Leszek Koltunski
  VERTEX_SHEAR     ( EffectType.VERTEX  ,   new float[] {0.0f,0.0f,0.0f} , 3, 0,     3    , VertexEffectShear.class        ),
65 b24e4719 Leszek Koltunski
66 5e96393c Leszek Koltunski
  ALPHA            ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectAlpha.class      ),
67
  SMOOTH_ALPHA     ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectAlpha.class      ),
68
  CHROMA           ( EffectType.FRAGMENT,   new float[] {0.0f}           , 4, 3,     3    , FragmentEffectChroma.class     ),
69
  SMOOTH_CHROMA    ( EffectType.FRAGMENT,   new float[] {0.0f}           , 4, 3,     3    , FragmentEffectChroma.class     ),
70
  BRIGHTNESS       ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectBrightness.class ),
71
  SMOOTH_BRIGHTNESS( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectBrightness.class ),
72
  SATURATION       ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectSaturation.class ),
73
  SMOOTH_SATURATION( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectSaturation.class ),
74
  CONTRAST         ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectContrast.class   ),
75
  SMOOTH_CONTRAST  ( EffectType.FRAGMENT,   new float[] {1.0f}           , 1, 3,     3    , FragmentEffectContrast.class   ),
76 b24e4719 Leszek Koltunski
77 bb4755e2 Leszek Koltunski
  BLUR             ( EffectType.POSTPROCESS,new float[] {0.0f}           , 2, 0,     0    , PostprocessEffectBlur.class    ),
78 d58407a8 Leszek Koltunski
  GLOW             ( EffectType.POSTPROCESS,new float[] {0.0f}           , 6, 0,     0    , PostprocessEffectGlow.class    ),
79 7b2f81e8 Leszek Koltunski
  BORDER           ( EffectType.POSTPROCESS,new float[] {0.0f}           , 6, 0,     0    , PostprocessEffectBorder.class  ),
80 d58407a8 Leszek Koltunski
  ;
81 da9b3f07 Leszek Koltunski
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83
84 c3651001 Leszek Koltunski
  public static final int LENGTH = values().length;
85 9d0d8530 leszek
86 da9b3f07 Leszek Koltunski
  private final EffectType type;
87 9d0d8530 leszek
  private final float[] unity;
88
  private final int dimension;
89 b24e4719 Leszek Koltunski
  private final int regionDim;
90
  private final int centerDim;
91 2f1f7570 Leszek Koltunski
  private final Class<? extends Effect> effectClass;
92 9d0d8530 leszek
93
  private static final int[] dimensions;
94 b24e4719 Leszek Koltunski
  private static final int[] regionDimension;
95
  private static final int[] centerDimension;
96 c3651001 Leszek Koltunski
  private static final EffectName[] names;  // copy the values() to a local variable so that we
97
                                            // don't have to keep recreating the array every time
98
  static
99 da9b3f07 Leszek Koltunski
    {
100 c3651001 Leszek Koltunski
    int i=0;
101 9d0d8530 leszek
102
    dimensions      = new int[LENGTH];
103 b24e4719 Leszek Koltunski
    regionDimension = new int[LENGTH];
104
    centerDimension = new int[LENGTH];
105 9d0d8530 leszek
    names           = new EffectName[LENGTH];
106 c3651001 Leszek Koltunski
107
    for(EffectName name: EffectName.values())
108
      {
109 9d0d8530 leszek
      dimensions[i]      = name.dimension;
110 b24e4719 Leszek Koltunski
      regionDimension[i] = name.regionDim;
111
      centerDimension[i] = name.centerDim;
112 9d0d8530 leszek
      names[i]           = name;
113
114
      i++;
115 c3651001 Leszek Koltunski
      }
116 da9b3f07 Leszek Koltunski
    }
117
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119
120 9d0d8530 leszek
  float[] getUnity()
121
    {
122
    return unity;
123
    }
124
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126
127 b24e4719 Leszek Koltunski
  EffectName(EffectType type, float[] unity, int dimension, int regionDim,
128
             int centerDim, Class<? extends Effect> effectClass )
129 da9b3f07 Leszek Koltunski
    {
130 2f1f7570 Leszek Koltunski
    this.type        = type;
131
    this.unity       = unity;
132
    this.dimension   = dimension;
133 b24e4719 Leszek Koltunski
    this.regionDim   = regionDim;
134
    this.centerDim   = centerDim;
135 2f1f7570 Leszek Koltunski
    this.effectClass = effectClass;
136 da9b3f07 Leszek Koltunski
    }
137
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139
// PUBLIC API
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141
/**
142 143095f7 Leszek Koltunski
 * Returns the Type of an individual Effect. For example, EffectName.ROTATE.getType() will
143 da9b3f07 Leszek Koltunski
 * return EffectType.MATRIX.
144
 * @return type of the effect.
145
 */
146
  public EffectType getType()
147
    {
148
    return type;
149
    }
150 c3651001 Leszek Koltunski
151 2f1f7570 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
152 143095f7 Leszek Koltunski
/**
153
 * Returns the Class of an individual Effect. For example, EffectName.ROTATE.getEffectClass()
154
 * returns MatrixEffectRotate.class.
155
 * @return effect class.
156
 */
157 2f1f7570 Leszek Koltunski
  public Class<? extends Effect> getEffectClass()
158
    {
159
    return effectClass;
160
    }
161
162 c3651001 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
163
/**
164
 * Returns the i-th EffectName.
165
 * <p>
166
 * If you want to loop over all possible Effects, you need this.
167
 */
168
  public static EffectName getName(int ordinal)
169
    {
170
    return names[ordinal];
171
    }
172 9d0d8530 leszek
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174
/**
175
 * Returns the dimension of an Effect (in other words, the number of interpolated values).
176
 * @return dimension of the Effect.
177
 */
178 b24e4719 Leszek Koltunski
  public int getEffectDimension() { return dimensions[ordinal()]; }
179 9d0d8530 leszek
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181
/**
182 b24e4719 Leszek Koltunski
 * What is the dimension of the Region supported by this effect?
183
 * @return Dimension of the Region supported (0-region not supported at all).
184 9d0d8530 leszek
 */
185 b24e4719 Leszek Koltunski
  public int getRegionDimension() { return regionDimension[ordinal()]; }
186 9d0d8530 leszek
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188
/**
189 b24e4719 Leszek Koltunski
 * What is the dimension of the Center supported by this effect?
190
 * @return Dimension of the Center supported (0-center not supported at all).
191 9d0d8530 leszek
 */
192 b24e4719 Leszek Koltunski
  public int getCenterDimension() { return centerDimension[ordinal()]; }
193 da9b3f07 Leszek Koltunski
  }