Project

General

Profile

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

library / src / main / java / org / distorted / library / main / DistortedEffects.java @ eff6e3d3

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

    
22
import org.distorted.library.effect.Effect;
23
import org.distorted.library.effect.EffectName;
24
import org.distorted.library.effectqueue.EffectQueue;
25
import org.distorted.library.effect.EffectType;
26

    
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28
/**
29
 * Class containing Matrix, Vertex, Fragment and Postprocessing effect queues.
30
 * <p>
31
 * The queues hold actual effects to be applied to a given (InputSurface,MeshBase) combo.
32
 */
33
public class DistortedEffects
34
  {
35
  private final long mID;
36
  private final EffectQueue[] mQueues;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39
/**
40
 * @y.exclude
41
 */
42
  public EffectQueue[] getQueues()
43
    {
44
    return mQueues;
45
    }
46

    
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48
// PUBLIC API
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
/**
51
 * Create empty effect queue.
52
 */
53
 public DistortedEffects()
54
    {
55
    mID = InternalStackFrameList.getNextEffectsID();
56
    mQueues = new EffectQueue[EffectType.LENGTH];
57
    EffectQueue.allocateQueues(mQueues,null,0);
58
    }
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61
/**
62
 * Copy constructor.
63
 * <p>
64
 * Whatever we do not clone gets created just like in the default constructor.
65
 *
66
 * @param dc    Source object to create our object from
67
 * @param flags A bitmask of values specifying what to copy.
68
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
69
 */
70
  public DistortedEffects(DistortedEffects dc, int flags)
71
    {
72
    mID = InternalStackFrameList.getNextEffectsID();
73
    mQueues = new EffectQueue[EffectType.LENGTH];
74
    EffectQueue.allocateQueues(mQueues,dc.getQueues(),flags);
75
    }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
/**
79
 * Returns unique ID of this instance.
80
 *
81
 * @return ID of the object.
82
 */
83
  public long getID()
84
      {
85
      return mID;
86
      }
87

    
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89
/**
90
 * Return if this queue contains effect with a given ID.
91
 */
92
  public boolean exists(long id)
93
    {
94
    int num = (int)(id&EffectType.MASK);
95
    return mQueues[num].exists(id);
96
    }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99
/**
100
 * Aborts all Effects.
101
 * @return Number of effects aborted.
102
 */
103
  public int abortAllEffects()
104
    {
105
    int aborted = 0;
106

    
107
    for( int i=0; i<EffectType.LENGTH; i++)
108
      {
109
      aborted += mQueues[i].removeAll(true);
110
      }
111

    
112
    return aborted;
113
    }
114

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116
/**
117
 * Aborts all Effects of a given type, for example all MATRIX Effects.
118
 * 
119
 * @param type one of the constants defined in {@link EffectType}
120
 * @return Number of effects aborted.
121
 */
122
  public int abortByType(EffectType type)
123
    {
124
    int num = type.ordinal();
125
    return mQueues[num].removeAll(true);
126
    }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129
/**
130
 * Aborts an Effect by its ID.
131
 *
132
 * @param id the Id of the Effect to be removed, as returned by getID().
133
 * @return Number of effects aborted.
134
 */
135
  public int abortById(long id)
136
    {
137
    int num = (int)(id&EffectType.MASK);
138
    return mQueues[num].removeById(id);
139
    }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142
/**
143
 * Aborts a single Effect.
144
 * 
145
 * @param effect the Effect we want to abort.
146
 * @return number of Effects aborted. Always either 0 or 1.
147
 */
148
  public int abortEffect(Effect effect)
149
    {
150
    int num = effect.getType().ordinal();
151
    return mQueues[num].removeEffect(effect);
152
    }
153

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155
/**
156
 * Abort all Effects of a given name, for example all rotations.
157
 * 
158
 * @param name one of the constants defined in {@link EffectName}
159
 * @return number of Effects aborted.
160
 */
161
  public int abortByName(EffectName name)
162
    {
163
    int num = name.getType().ordinal();
164
    return mQueues[num].removeByName(name);
165
    }
166

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168
/**
169
 * Add a new Effect to the tail of our queue.
170
 *
171
 * @param effect The Effect to add.
172
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
173
 */
174
  public boolean apply(Effect effect)
175
    {
176
    int num = effect.getType().ordinal();
177
    return mQueues[num].add(effect);
178
    }
179

    
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181
/**
182
 * Add a new Effect to our queue at a specified position.
183
 *
184
 * @param effect The Effect to add.
185
 * @param position the place in the effects queue where to add the new effect.
186
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
187
 */
188
  public boolean apply(Effect effect, int position)
189
    {
190
    int num = effect.getType().ordinal();
191
    return mQueues[num].add(effect,position);
192
    }
193

    
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195
/**
196
 * Mark the underlying OpenGL object for deletion. Actual deletion will take place on the next render.
197
 */
198
  public void markForDeletion()
199
    {
200
    for( int i=0; i<EffectType.LENGTH; i++)
201
      {
202
      mQueues[i].markForDeletion();
203
      }
204
    }
205

    
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207
/**
208
 * Return number of effects of the given type currently in the Queue.
209
 *
210
 * @param type The EffectType.
211
 * @return Number of effects of the given type currently in the Queue.
212
 */
213
  public int getNumEffects(EffectType type)
214
    {
215
    int num = type.ordinal();
216
    return mQueues[num].getNumEffects();
217
    }
218
  }
(1-1/16)