1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2016 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.main;
|
22
|
|
23
|
import org.distorted.library.effect.Effect;
|
24
|
import org.distorted.library.effect.EffectName;
|
25
|
import org.distorted.library.effectqueue.EffectQueue;
|
26
|
import org.distorted.library.effect.EffectType;
|
27
|
|
28
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
29
|
/**
|
30
|
* Class containing Matrix, Vertex, Fragment and Postprocessing effect queues.
|
31
|
* <p>
|
32
|
* The queues hold actual effects to be applied to a given (InputSurface,MeshBase) combo.
|
33
|
*/
|
34
|
public class DistortedEffects
|
35
|
{
|
36
|
private final long mID;
|
37
|
private final EffectQueue[] mQueues;
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
/**
|
41
|
* @y.exclude
|
42
|
*/
|
43
|
public EffectQueue[] getQueues()
|
44
|
{
|
45
|
return mQueues;
|
46
|
}
|
47
|
|
48
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49
|
// PUBLIC API
|
50
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51
|
/**
|
52
|
* Create empty effect queue.
|
53
|
*/
|
54
|
public DistortedEffects()
|
55
|
{
|
56
|
mID = InternalStackFrameList.getNextEffectsID();
|
57
|
mQueues = new EffectQueue[EffectType.LENGTH];
|
58
|
EffectQueue.allocateQueues(mQueues,null,0);
|
59
|
}
|
60
|
|
61
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62
|
/**
|
63
|
* Copy constructor.
|
64
|
* <p>
|
65
|
* Whatever we do not clone gets created just like in the default constructor.
|
66
|
*
|
67
|
* @param dc Source object to create our object from
|
68
|
* @param flags A bitmask of values specifying what to copy.
|
69
|
* For example, CLONE_VERTEX | CLONE_MATRIX.
|
70
|
*/
|
71
|
public DistortedEffects(DistortedEffects dc, int flags)
|
72
|
{
|
73
|
mID = InternalStackFrameList.getNextEffectsID();
|
74
|
mQueues = new EffectQueue[EffectType.LENGTH];
|
75
|
EffectQueue.allocateQueues(mQueues,dc.getQueues(),flags);
|
76
|
}
|
77
|
|
78
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
79
|
/**
|
80
|
* Returns unique ID of this instance.
|
81
|
*
|
82
|
* @return ID of the object.
|
83
|
*/
|
84
|
public long getID()
|
85
|
{
|
86
|
return mID;
|
87
|
}
|
88
|
|
89
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
90
|
/**
|
91
|
* Return if this queue contains effect with a given ID.
|
92
|
*/
|
93
|
public boolean exists(long id)
|
94
|
{
|
95
|
int num = (int)(id&EffectType.MASK);
|
96
|
return mQueues[num].exists(id);
|
97
|
}
|
98
|
|
99
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
100
|
/**
|
101
|
* Aborts all Effects.
|
102
|
* @return Number of effects aborted.
|
103
|
*/
|
104
|
public int abortAllEffects()
|
105
|
{
|
106
|
int aborted = 0;
|
107
|
|
108
|
for( int i=0; i<EffectType.LENGTH; i++)
|
109
|
{
|
110
|
aborted += mQueues[i].removeAll(true);
|
111
|
}
|
112
|
|
113
|
return aborted;
|
114
|
}
|
115
|
|
116
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
117
|
/**
|
118
|
* Aborts all Effects of a given type, for example all MATRIX Effects.
|
119
|
*
|
120
|
* @param type one of the constants defined in {@link EffectType}
|
121
|
* @return Number of effects aborted.
|
122
|
*/
|
123
|
public int abortByType(EffectType type)
|
124
|
{
|
125
|
int num = type.ordinal();
|
126
|
return mQueues[num].removeAll(true);
|
127
|
}
|
128
|
|
129
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
130
|
/**
|
131
|
* Aborts an Effect by its ID.
|
132
|
*
|
133
|
* @param id the Id of the Effect to be removed, as returned by getID().
|
134
|
* @return Number of effects aborted.
|
135
|
*/
|
136
|
public int abortById(long id)
|
137
|
{
|
138
|
int num = (int)(id&EffectType.MASK);
|
139
|
return mQueues[num].removeById(id);
|
140
|
}
|
141
|
|
142
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
143
|
/**
|
144
|
* Aborts a single Effect.
|
145
|
*
|
146
|
* @param effect the Effect we want to abort.
|
147
|
* @return number of Effects aborted. Always either 0 or 1.
|
148
|
*/
|
149
|
public int abortEffect(Effect effect)
|
150
|
{
|
151
|
int num = effect.getType().ordinal();
|
152
|
return mQueues[num].removeEffect(effect);
|
153
|
}
|
154
|
|
155
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
156
|
/**
|
157
|
* Abort all Effects of a given name, for example all rotations.
|
158
|
*
|
159
|
* @param name one of the constants defined in {@link EffectName}
|
160
|
* @return number of Effects aborted.
|
161
|
*/
|
162
|
public int abortByName(EffectName name)
|
163
|
{
|
164
|
int num = name.getType().ordinal();
|
165
|
return mQueues[num].removeByName(name);
|
166
|
}
|
167
|
|
168
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
169
|
/**
|
170
|
* Add a new Effect to the tail of our queue.
|
171
|
*
|
172
|
* @param effect The Effect to add.
|
173
|
* @return <code>true</code> if operation was successful, <code>false</code> otherwise.
|
174
|
*/
|
175
|
public boolean apply(Effect effect)
|
176
|
{
|
177
|
int num = effect.getType().ordinal();
|
178
|
return mQueues[num].add(effect);
|
179
|
}
|
180
|
|
181
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
182
|
/**
|
183
|
* Add a new Effect to our queue at a specified position.
|
184
|
*
|
185
|
* @param effect The Effect to add.
|
186
|
* @param position the place in the effects queue where to add the new effect.
|
187
|
* @return <code>true</code> if operation was successful, <code>false</code> otherwise.
|
188
|
*/
|
189
|
public boolean apply(Effect effect, int position)
|
190
|
{
|
191
|
int num = effect.getType().ordinal();
|
192
|
return mQueues[num].add(effect,position);
|
193
|
}
|
194
|
|
195
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
196
|
/**
|
197
|
* Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render.
|
198
|
*/
|
199
|
public void markForDeletion()
|
200
|
{
|
201
|
for( int i=0; i<EffectType.LENGTH; i++)
|
202
|
{
|
203
|
mQueues[i].markForDeletion();
|
204
|
}
|
205
|
}
|
206
|
|
207
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
208
|
/**
|
209
|
* Return number of effects of the given type currently in the Queue.
|
210
|
*
|
211
|
* @param type The EffectType.
|
212
|
* @return Number of effects of the given type currently in the Queue.
|
213
|
*/
|
214
|
public int getNumEffects(EffectType type)
|
215
|
{
|
216
|
int num = type.ordinal();
|
217
|
return mQueues[num].getNumEffects();
|
218
|
}
|
219
|
|
220
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
221
|
/**
|
222
|
* Return a string describing all effects in the queues.
|
223
|
*/
|
224
|
public String debug(int depth)
|
225
|
{
|
226
|
StringBuilder s = new StringBuilder();
|
227
|
for(int i=0; i<depth; i++) s.append(" ");
|
228
|
String space = s.toString();
|
229
|
|
230
|
String mat = mQueues[0].retEffects();
|
231
|
String ver = mQueues[1].retEffects();
|
232
|
String fra = mQueues[2].retEffects();
|
233
|
String pos = mQueues[3].retEffects();
|
234
|
|
235
|
return space+"MAT: "+mat+"\n"+space+"VER: "+ver+"\n"+space+"FRA: "+fra+"\n"+space+"POS: "+pos;
|
236
|
}
|
237
|
}
|