Project

General

Profile

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

library / src / main / java / org / distorted / library / main / DistortedEffects.java @ 9b94626c

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 android.content.res.Resources;
23
import android.opengl.GLES31;
24
import android.util.Log;
25

    
26
import org.distorted.library.R;
27
import org.distorted.library.effect.Effect;
28
import org.distorted.library.effect.EffectName;
29
import org.distorted.library.effect.EffectType;
30
import org.distorted.library.effect.FragmentEffect;
31
import org.distorted.library.effect.VertexEffect;
32
import org.distorted.library.message.EffectListener;
33
import org.distorted.library.program.DistortedProgram;
34

    
35
import java.io.InputStream;
36
import java.nio.ByteBuffer;
37
import java.nio.ByteOrder;
38
import java.nio.FloatBuffer;
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41
/**
42
 * Class containing Matrix, Vertex, Fragment and Postprocessing effect queues.
43
 * <p>
44
 * The queues hold actual effects to be applied to a given (InputSurface,MeshObject) combo.
45
 */
46
public class DistortedEffects
47
  {
48
  /// MAIN PROGRAM ///
49
  private static DistortedProgram mMainProgram;
50
  private static int mMainTextureH;
51

    
52
  /// BLIT PROGRAM ///
53
  private static DistortedProgram mBlitProgram;
54
  private static int mBlitTextureH;
55
  private static int mBlitDepthH;
56
  private static final FloatBuffer mQuadPositions;
57

    
58
  static
59
    {
60
    float[] positionData= { -0.5f, -0.5f,  -0.5f, 0.5f,  0.5f,-0.5f,  0.5f, 0.5f };
61
    mQuadPositions = ByteBuffer.allocateDirect(32).order(ByteOrder.nativeOrder()).asFloatBuffer();
62
    mQuadPositions.put(positionData).position(0);
63
    }
64

    
65
  /// BLIT DEPTH PROGRAM ///
66
  private static DistortedProgram mBlitDepthProgram;
67
  private static int mBlitDepthTextureH;
68
  private static int mBlitDepthDepthTextureH;
69
  private static int mBlitDepthDepthH;
70
  private static int mBlitDepthTexCorrH;
71

    
72
  /// NORMAL PROGRAM /////
73
  private static DistortedProgram mNormalProgram;
74
  private static int mNormalMVPMatrixH;
75
  /// END PROGRAMS //////
76

    
77
  private static long mNextID =0;
78
  private long mID;
79

    
80
  private EffectQueueMatrix mM;
81
  private EffectQueueFragment mF;
82
  private EffectQueueVertex mV;
83
  private EffectQueuePostprocess mP;
84

    
85
  private boolean matrixCloned, vertexCloned, fragmentCloned, postprocessCloned;
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
  static void createProgram(Resources resources)
90
    {
91
    // MAIN PROGRAM ////////////////////////////////////
92
    final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader);
93
    final InputStream mainFragStream = resources.openRawResource(R.raw.main_fragment_shader);
94

    
95
    int numF = FragmentEffect.getNumEnabled();
96
    int numV = VertexEffect.getNumEnabled();
97

    
98
    String mainVertHeader= Distorted.GLSL_VERSION + ("#define NUM_VERTEX "   + ( numV>0 ? getMax(EffectType.VERTEX  ) : 0 ) + "\n");
99
    String mainFragHeader= Distorted.GLSL_VERSION + ("#define NUM_FRAGMENT " + ( numF>0 ? getMax(EffectType.FRAGMENT) : 0 ) + "\n");
100
    String enabledEffectV= VertexEffect.getGLSL();
101
    String enabledEffectF= FragmentEffect.getGLSL();
102

    
103
    //android.util.Log.e("Effects", "vertHeader= "+mainVertHeader);
104
    //android.util.Log.e("Effects", "fragHeader= "+mainFragHeader);
105
    //android.util.Log.e("Effects", "enabledV= "+enabledEffectV);
106
    //android.util.Log.e("Effects", "enabledF= "+enabledEffectF);
107

    
108
    String[] feedback = { "v_Position", "v_endPosition" };
109

    
110
    try
111
      {
112
      mMainProgram = new DistortedProgram(mainVertStream, mainFragStream, mainVertHeader, mainFragHeader,
113
                                          enabledEffectV, enabledEffectF, Distorted.GLSL, feedback);
114
      }
115
    catch(Exception e)
116
      {
117
      Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile MAIN program: "+e.getMessage());
118
      throw new RuntimeException(e.getMessage());
119
      }
120

    
121
    int mainProgramH = mMainProgram.getProgramHandle();
122
    EffectQueueFragment.getUniforms(mainProgramH);
123
    EffectQueueVertex.getUniforms(mainProgramH);
124
    EffectQueueMatrix.getUniforms(mainProgramH);
125
    mMainTextureH= GLES31.glGetUniformLocation( mainProgramH, "u_Texture");
126

    
127
    // BLIT PROGRAM ////////////////////////////////////
128
    final InputStream blitVertStream = resources.openRawResource(R.raw.blit_vertex_shader);
129
    final InputStream blitFragStream = resources.openRawResource(R.raw.blit_fragment_shader);
130

    
131
    String blitVertHeader= (Distorted.GLSL_VERSION + "#define NUM_VERTEX 0\n"  );
132
    String blitFragHeader= (Distorted.GLSL_VERSION + "#define NUM_FRAGMENT 0\n");
133

    
134
    try
135
      {
136
      mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream,blitVertHeader,blitFragHeader, Distorted.GLSL);
137
      }
138
    catch(Exception e)
139
      {
140
      Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile BLIT program: "+e.getMessage());
141
      throw new RuntimeException(e.getMessage());
142
      }
143

    
144
    int blitProgramH = mBlitProgram.getProgramHandle();
145
    mBlitTextureH  = GLES31.glGetUniformLocation( blitProgramH, "u_Texture");
146
    mBlitDepthH    = GLES31.glGetUniformLocation( blitProgramH, "u_Depth");
147

    
148
    // BLIT DEPTH PROGRAM ////////////////////////////////////
149
    final InputStream blitDepthVertStream = resources.openRawResource(R.raw.blit_depth_vertex_shader);
150
    final InputStream blitDepthFragStream = resources.openRawResource(R.raw.blit_depth_fragment_shader);
151

    
152
    try
153
      {
154
      mBlitDepthProgram = new DistortedProgram(blitDepthVertStream,blitDepthFragStream,blitVertHeader,blitFragHeader, Distorted.GLSL);
155
      }
156
    catch(Exception e)
157
      {
158
      Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile BLIT DEPTH program: "+e.getMessage());
159
      throw new RuntimeException(e.getMessage());
160
      }
161

    
162
    int blitDepthProgramH   = mBlitDepthProgram.getProgramHandle();
163
    mBlitDepthTextureH      = GLES31.glGetUniformLocation( blitDepthProgramH, "u_Texture");
164
    mBlitDepthDepthTextureH = GLES31.glGetUniformLocation( blitDepthProgramH, "u_DepthTexture");
165
    mBlitDepthDepthH        = GLES31.glGetUniformLocation( blitDepthProgramH, "u_Depth");
166
    mBlitDepthTexCorrH      = GLES31.glGetUniformLocation( blitDepthProgramH, "u_TexCorr");
167

    
168
    // NORMAL PROGRAM //////////////////////////////////////
169
    final InputStream normalVertexStream   = resources.openRawResource(R.raw.normal_vertex_shader);
170
    final InputStream normalFragmentStream = resources.openRawResource(R.raw.normal_fragment_shader);
171

    
172
    try
173
      {
174
      mNormalProgram = new DistortedProgram(normalVertexStream,normalFragmentStream, Distorted.GLSL_VERSION, Distorted.GLSL_VERSION, Distorted.GLSL);
175
      }
176
    catch(Exception e)
177
      {
178
      Log.e("EFFECTS", e.getClass().getSimpleName()+" trying to compile NORMAL program: "+e.getMessage());
179
      throw new RuntimeException(e.getMessage());
180
      }
181

    
182
    int normalProgramH = mNormalProgram.getProgramHandle();
183
    mNormalMVPMatrixH  = GLES31.glGetUniformLocation( normalProgramH, "u_MVPMatrix");
184
    }
185

    
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187

    
188
  private void initializeEffectLists(DistortedEffects d, int flags)
189
    {
190
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
191
      {
192
      mM = d.mM;
193
      matrixCloned = true;
194
      }
195
    else
196
      {
197
      mM = new EffectQueueMatrix(mID);
198
      matrixCloned = false;
199
      }
200
    
201
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
202
      {
203
      mV = d.mV;
204
      vertexCloned = true;
205
      }
206
    else
207
      {
208
      mV = new EffectQueueVertex(mID);
209
      vertexCloned = false;
210
      }
211
    
212
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
213
      {
214
      mF = d.mF;
215
      fragmentCloned = true;
216
      }
217
    else
218
      {
219
      mF = new EffectQueueFragment(mID);
220
      fragmentCloned = false;
221
      }
222

    
223
    if( (flags & Distorted.CLONE_POSTPROCESS) != 0 )
224
      {
225
      mP = d.mP;
226
      postprocessCloned = true;
227
      }
228
    else
229
      {
230
      mP = new EffectQueuePostprocess(mID);
231
      postprocessCloned = false;
232
      }
233
    }
234

    
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236

    
237
  EffectQueuePostprocess getPostprocess()
238
    {
239
    return mP;
240
    }
241

    
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

    
244
  void newNode(DistortedNode node)
245
    {
246
    mM.newNode(node);
247
    mF.newNode(node);
248
    mV.newNode(node);
249
    mP.newNode(node);
250
    }
251

    
252
///////////////////////////////////////////////////////////////////////////////////////////////////
253

    
254
  private void displayNormals(MeshObject mesh)
255
    {
256
    GLES31.glBindBufferBase(GLES31.GL_TRANSFORM_FEEDBACK_BUFFER, 0, mesh.mAttTFO[0]);
257
    GLES31.glBeginTransformFeedback( GLES31.GL_POINTS);
258
    DistortedRenderState.switchOffDrawing();
259
    GLES31.glDrawArrays( GLES31.GL_POINTS, 0, mesh.numVertices);
260
    DistortedRenderState.restoreDrawing();
261
    GLES31.glEndTransformFeedback();
262
    GLES31.glBindBufferBase(GLES31.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
263

    
264
    mNormalProgram.useProgram();
265
    GLES31.glUniformMatrix4fv(mNormalMVPMatrixH, 1, false, mM.getMVP() , 0);
266
    GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, mesh.mAttTFO[0]);
267
    GLES31.glVertexAttribPointer(mNormalProgram.mAttribute[0], MeshObject.POS_DATA_SIZE, GLES31.GL_FLOAT, false, 0, 0);
268
    GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
269
    GLES31.glLineWidth(8.0f);
270
    GLES31.glDrawArrays(GLES31.GL_LINES, 0, 2*mesh.numVertices);
271
    }
272

    
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274

    
275
  void drawPriv(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime, float marginInPixels)
276
    {
277
    float halfZ = halfW*mesh.zFactor;
278

    
279
    mM.compute(currTime);
280
    mV.compute(currTime,halfW,halfH,halfZ);
281
    mF.compute(currTime,halfW,halfH);
282
    mP.compute(currTime);
283

    
284
    GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
285

    
286
    mMainProgram.useProgram();
287
    GLES31.glUniform1i(mMainTextureH, 0);
288

    
289
    GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, mesh.mAttVBO[0]);
290
    GLES31.glVertexAttribPointer(mMainProgram.mAttribute[0], MeshObject.POS_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET0);
291
    GLES31.glVertexAttribPointer(mMainProgram.mAttribute[1], MeshObject.NOR_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET1);
292
    GLES31.glVertexAttribPointer(mMainProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE, GLES31.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET2);
293
    GLES31.glBindBuffer(GLES31.GL_ARRAY_BUFFER, 0);
294

    
295
    mM.send(surface,halfW,halfH,halfZ,marginInPixels);
296
    mV.send();
297
    mF.send();
298

    
299
    GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, mesh.numVertices);
300

    
301
    if( mesh.mShowNormals ) displayNormals(mesh);
302
    }
303

    
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305
/**
306
 * Only for use by the library itself.
307
 *
308
 * @y.exclude
309
 */
310
  public static void blitPriv(DistortedOutputSurface surface)
311
    {
312
    mBlitProgram.useProgram();
313

    
314
    GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
315
    GLES31.glUniform1i(mBlitTextureH, 0);
316
    GLES31.glUniform1f( mBlitDepthH , 1.0f-surface.mNear);
317
    GLES31.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
318
    GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
319
    }
320

    
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322

    
323
  static void blitDepthPriv(DistortedOutputSurface surface, float corrW, float corrH)
324
    {
325
    mBlitDepthProgram.useProgram();
326

    
327
    GLES31.glViewport(0, 0, surface.mWidth, surface.mHeight );
328
    GLES31.glUniform1i(mBlitDepthTextureH, 0);
329
    GLES31.glUniform1i(mBlitDepthDepthTextureH, 1);
330
    GLES31.glUniform2f(mBlitDepthTexCorrH, corrW, corrH );
331
    GLES31.glUniform1f( mBlitDepthDepthH , 1.0f-surface.mNear);
332
    GLES31.glVertexAttribPointer(mBlitDepthProgram.mAttribute[0], 2, GLES31.GL_FLOAT, false, 0, mQuadPositions);
333
    GLES31.glDrawArrays(GLES31.GL_TRIANGLE_STRIP, 0, 4);
334
    }
335

    
336
///////////////////////////////////////////////////////////////////////////////////////////////////
337

    
338
  private void releasePriv()
339
    {
340
    if( !matrixCloned      ) mM.abortAll(false);
341
    if( !vertexCloned      ) mV.abortAll(false);
342
    if( !fragmentCloned    ) mF.abortAll(false);
343
    if( !postprocessCloned ) mP.abortAll(false);
344

    
345
    mM = null;
346
    mV = null;
347
    mF = null;
348
    mP = null;
349
    }
350

    
351
///////////////////////////////////////////////////////////////////////////////////////////////////
352

    
353
  static void onDestroy()
354
    {
355
    mNextID =  0;
356
    }
357

    
358
///////////////////////////////////////////////////////////////////////////////////////////////////
359
// PUBLIC API
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361
/**
362
 * Create empty effect queue.
363
 */
364
  public DistortedEffects()
365
    {
366
    mID = ++mNextID;
367
    initializeEffectLists(this,0);
368
    }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371
/**
372
 * Copy constructor.
373
 * <p>
374
 * Whatever we do not clone gets created just like in the default constructor.
375
 *
376
 * @param dc    Source object to create our object from
377
 * @param flags A bitmask of values specifying what to copy.
378
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
379
 */
380
  public DistortedEffects(DistortedEffects dc, int flags)
381
    {
382
    mID = ++mNextID;
383
    initializeEffectLists(dc,flags);
384
    }
385

    
386
///////////////////////////////////////////////////////////////////////////////////////////////////
387
/**
388
 * Releases all resources. After this call, the queue should not be used anymore.
389
 */
390
  @SuppressWarnings("unused")
391
  public synchronized void delete()
392
    {
393
    releasePriv();
394
    }
395

    
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397
/**
398
 * Returns unique ID of this instance.
399
 *
400
 * @return ID of the object.
401
 */
402
  public long getID()
403
      {
404
      return mID;
405
      }
406

    
407
///////////////////////////////////////////////////////////////////////////////////////////////////
408
/**
409
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
410
 * to one of the Effects in our queues. Nothing will happen if 'el' is already in the list.
411
 * 
412
 * @param el A class implementing the EffectListener interface that wants to get notifications.
413
 */
414
  @SuppressWarnings("unused")
415
  public void registerForMessages(EffectListener el)
416
    {
417
    mM.registerForMessages(el);
418
    mV.registerForMessages(el);
419
    mF.registerForMessages(el);
420
    mP.registerForMessages(el);
421
    }
422

    
423
///////////////////////////////////////////////////////////////////////////////////////////////////
424
/**
425
 * Removes the calling class from the list of Listeners that get notified if something happens to Effects in our queue.
426
 * 
427
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
428
 */
429
  @SuppressWarnings("unused")
430
  public void deregisterForMessages(EffectListener el)
431
    {
432
    mM.deregisterForMessages(el);
433
    mV.deregisterForMessages(el);
434
    mF.deregisterForMessages(el);
435
    mP.deregisterForMessages(el);
436
    }
437

    
438
///////////////////////////////////////////////////////////////////////////////////////////////////
439
/**
440
 * Aborts all Effects.
441
 * @return Number of effects aborted.
442
 */
443
  public int abortAllEffects()
444
    {
445
    return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
446
    }
447

    
448
///////////////////////////////////////////////////////////////////////////////////////////////////
449
/**
450
 * Aborts all Effects of a given type, for example all MATRIX Effects.
451
 * 
452
 * @param type one of the constants defined in {@link EffectType}
453
 * @return Number of effects aborted.
454
 */
455
  public int abortByType(EffectType type)
456
    {
457
    switch(type)
458
      {
459
      case MATRIX     : return mM.abortAll(true);
460
      case VERTEX     : return mV.abortAll(true);
461
      case FRAGMENT   : return mF.abortAll(true);
462
      case POSTPROCESS: return mP.abortAll(true);
463
      default         : return 0;
464
      }
465
    }
466

    
467
///////////////////////////////////////////////////////////////////////////////////////////////////
468
/**
469
 * Aborts an Effect by its ID.
470
 *
471
 * @param id the Id of the Effect to be removed, as returned by getID().
472
 * @return Number of effects aborted.
473
 */
474
  public int abortById(long id)
475
    {
476
    long type = id&EffectType.MASK;
477

    
478
    if( type == EffectType.MATRIX.ordinal()      ) return mM.removeById(id);
479
    if( type == EffectType.VERTEX.ordinal()      ) return mV.removeById(id);
480
    if( type == EffectType.FRAGMENT.ordinal()    ) return mF.removeById(id);
481
    if( type == EffectType.POSTPROCESS.ordinal() ) return mP.removeById(id);
482

    
483
    return 0;
484
    }
485

    
486
///////////////////////////////////////////////////////////////////////////////////////////////////
487
/**
488
 * Aborts a single Effect.
489
 * 
490
 * @param effect the Effect we want to abort.
491
 * @return number of Effects aborted. Always either 0 or 1.
492
 */
493
  public int abortEffect(Effect effect)
494
    {
495
    switch(effect.getType())
496
      {
497
      case MATRIX     : return mM.removeEffect(effect);
498
      case VERTEX     : return mV.removeEffect(effect);
499
      case FRAGMENT   : return mF.removeEffect(effect);
500
      case POSTPROCESS: return mP.removeEffect(effect);
501
      default         : return 0;
502
      }
503
    }
504

    
505
///////////////////////////////////////////////////////////////////////////////////////////////////
506
/**
507
 * Abort all Effects of a given name, for example all rotations.
508
 * 
509
 * @param name one of the constants defined in {@link EffectName}
510
 * @return number of Effects aborted.
511
 */
512
  public int abortByName(EffectName name)
513
    {
514
    switch(name.getType())
515
      {
516
      case MATRIX     : return mM.removeByName(name);
517
      case VERTEX     : return mV.removeByName(name);
518
      case FRAGMENT   : return mF.removeByName(name);
519
      case POSTPROCESS: return mP.removeByName(name);
520
      default                : return 0;
521
      }
522
    }
523

    
524
///////////////////////////////////////////////////////////////////////////////////////////////////
525
/**
526
 * Returns the maximum number of effects of a given type that can be simultaneously applied to a
527
 * single (InputSurface,MeshObject) combo.
528
 *
529
 * @param type {@link EffectType}
530
 * @return The maximum number of effects of a given type.
531
 */
532
  @SuppressWarnings("unused")
533
  public static int getMax(EffectType type)
534
    {
535
    return EffectQueue.getMax(type.ordinal());
536
    }
537

    
538
///////////////////////////////////////////////////////////////////////////////////////////////////
539
/**
540
 * Sets the maximum number of effects that can be stored in a single EffectQueue at one time.
541
 * This can fail if:
542
 * <ul>
543
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
544
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
545
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
546
 *     time only decreasing the value of 'max' is permitted.
547
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
548
 * </ul>
549
 *
550
 * @param type {@link EffectType}
551
 * @param max new maximum number of simultaneous effects. Has to be a non-negative number not greater
552
 *            than Byte.MAX_VALUE
553
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
554
 */
555
  @SuppressWarnings("unused")
556
  public static boolean setMax(EffectType type, int max)
557
    {
558
    return EffectQueue.setMax(type.ordinal(),max);
559
    }
560

    
561
///////////////////////////////////////////////////////////////////////////////////////////////////
562
/**
563
 * Add a new Effect to our queue.
564
 *
565
 * @param effect The Effect to add.
566
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
567
 */
568
  public boolean apply(Effect effect)
569
    {
570
    switch(effect.getType())
571
      {
572
      case MATRIX      : return mM.add(effect);
573
      case VERTEX      : return mV.add(effect);
574
      case FRAGMENT    : return mF.add(effect);
575
      case POSTPROCESS : return mP.add(effect);
576
      }
577

    
578
    return false;
579
    }
580
  }
(2-2/21)