Project

General

Profile

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

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

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