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
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
60
|
|
61
|
private static final int MAXDIM = 4; // maximum supported dimension of an effect
|
62
|
|
63
|
private EffectTypes type;
|
64
|
private float[] unity;
|
65
|
|
66
|
static private float[] unities;
|
67
|
static private int[] dimensions;
|
68
|
|
69
|
static
|
70
|
{
|
71
|
int len = values().length;
|
72
|
int i=0;
|
73
|
|
74
|
dimensions = new int[len];
|
75
|
unities = new float[MAXDIM*len];
|
76
|
|
77
|
for(EffectNames name: EffectNames.values())
|
78
|
{
|
79
|
dimensions[i] = (name.unity==null ? 0 : name.unity.length);
|
80
|
|
81
|
switch(dimensions[i])
|
82
|
{
|
83
|
case 4: unities[MAXDIM*i+3] = name.unity[3];
|
84
|
case 3: unities[MAXDIM*i+2] = name.unity[2];
|
85
|
case 2: unities[MAXDIM*i+1] = name.unity[1];
|
86
|
case 1: unities[MAXDIM*i+0] = name.unity[0];
|
87
|
case 0: break;
|
88
|
}
|
89
|
|
90
|
i++;
|
91
|
}
|
92
|
}
|
93
|
|
94
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
95
|
|
96
|
EffectNames(EffectTypes type, float[] unity)
|
97
|
{
|
98
|
this.type = type;
|
99
|
this.unity= unity;
|
100
|
}
|
101
|
|
102
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
103
|
// yes, I know we could have used values(i) but that allocates a new copy each time!
|
104
|
|
105
|
static EffectTypes getType(int ordinal)
|
106
|
{
|
107
|
if( ordinal<DISTORT.ordinal() ) return EffectTypes.MATRIX;
|
108
|
if( ordinal<MACROBLOCK.ordinal() ) return EffectTypes.VERTEX;
|
109
|
|
110
|
return EffectTypes.FRAGMENT;
|
111
|
}
|
112
|
|
113
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114
|
|
115
|
static void fillWithUnities(int ordinal, float[] buffer, int index)
|
116
|
{
|
117
|
switch(dimensions[ordinal])
|
118
|
{
|
119
|
case 0: break;
|
120
|
case 1: buffer[index+0]=unities[MAXDIM*ordinal+0];
|
121
|
break;
|
122
|
case 2: buffer[index+0]=unities[MAXDIM*ordinal+0];
|
123
|
buffer[index+1]=unities[MAXDIM*ordinal+1];
|
124
|
break;
|
125
|
case 3: buffer[index+0]=unities[MAXDIM*ordinal+0];
|
126
|
buffer[index+1]=unities[MAXDIM*ordinal+1];
|
127
|
buffer[index+2]=unities[MAXDIM*ordinal+2];
|
128
|
break;
|
129
|
case 4: buffer[index+0]=unities[MAXDIM*ordinal+0];
|
130
|
buffer[index+1]=unities[MAXDIM*ordinal+1];
|
131
|
buffer[index+2]=unities[MAXDIM*ordinal+2];
|
132
|
buffer[index+3]=unities[MAXDIM*ordinal+3];
|
133
|
break;
|
134
|
}
|
135
|
}
|
136
|
|
137
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
138
|
|
139
|
static boolean isUnity(int ordinal, float[] buffer, int index)
|
140
|
{
|
141
|
switch(dimensions[ordinal])
|
142
|
{
|
143
|
case 0: return true;
|
144
|
case 1: return buffer[index+0]==unities[MAXDIM*ordinal+0];
|
145
|
case 2: return buffer[index+0]==unities[MAXDIM*ordinal+0] &&
|
146
|
buffer[index+1]==unities[MAXDIM*ordinal+1];
|
147
|
case 3: return buffer[index+0]==unities[MAXDIM*ordinal+0] &&
|
148
|
buffer[index+1]==unities[MAXDIM*ordinal+1] &&
|
149
|
buffer[index+2]==unities[MAXDIM*ordinal+2];
|
150
|
case 4: return buffer[index+0]==unities[MAXDIM*ordinal+0] &&
|
151
|
buffer[index+1]==unities[MAXDIM*ordinal+1] &&
|
152
|
buffer[index+2]==unities[MAXDIM*ordinal+2] &&
|
153
|
buffer[index+3]==unities[MAXDIM*ordinal+3];
|
154
|
}
|
155
|
|
156
|
return false;
|
157
|
}
|
158
|
|
159
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
160
|
// PUBLIC API
|
161
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
162
|
/**
|
163
|
* Returns the Type of an individual Effect. For example, EffectNames.ROTATION.getType() will
|
164
|
* return EffectTypes.MATRIX.
|
165
|
* @return type of the effect.
|
166
|
*/
|
167
|
public EffectTypes getType()
|
168
|
{
|
169
|
return type;
|
170
|
}
|
171
|
}
|