Project

General

Profile

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

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

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.GLES30;
24

    
25
import org.distorted.library.R;
26
import org.distorted.library.effect.Effect;
27
import org.distorted.library.effect.EffectName;
28
import org.distorted.library.effect.EffectType;
29
import org.distorted.library.message.EffectListener;
30
import org.distorted.library.program.DistortedProgram;
31
import org.distorted.library.program.FragmentCompilationException;
32
import org.distorted.library.program.FragmentUniformsException;
33
import org.distorted.library.program.LinkingException;
34
import org.distorted.library.program.VertexCompilationException;
35
import org.distorted.library.program.VertexUniformsException;
36

    
37
import java.io.InputStream;
38
import java.nio.ByteBuffer;
39
import java.nio.ByteOrder;
40
import java.nio.FloatBuffer;
41
import java.util.ArrayList;
42

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44
/**
45
 * Class containing Matrix,Vertex and Fragment effect queues. Postprocessing queue is held in a separate
46
 * class.
47
 * <p>
48
 * The queues hold actual effects to be applied to a given (DistortedTexture,MeshObject) combo.
49
 */
50
public class DistortedEffects
51
  {
52
  /// MAIN PROGRAM ///
53
  private static DistortedProgram mMainProgram;
54
  private static int mMainTextureH;
55
  private static ArrayList<EffectName> mEnabledEffects = new ArrayList<>();
56

    
57
  /// BLIT PROGRAM ///
58
  private static DistortedProgram mBlitProgram;
59
  private static int mBlitTextureH;
60
  private static int mBlitDepthH;
61
  private static final FloatBuffer mQuadPositions;
62

    
63
  static
64
    {
65
    float[] positionData= { -0.5f, -0.5f,  -0.5f, 0.5f,  0.5f,-0.5f,  0.5f, 0.5f };
66
    mQuadPositions = ByteBuffer.allocateDirect(32).order(ByteOrder.nativeOrder()).asFloatBuffer();
67
    mQuadPositions.put(positionData).position(0);
68
    }
69

    
70
  /// BLIT DEPTH PROGRAM ///
71
  private static DistortedProgram mBlitDepthProgram;
72
  private static int mBlitDepthTextureH;
73
  private static int mBlitDepthDepthTextureH;
74
  private static int mBlitDepthDepthH;
75

    
76
  /// NORMAL PROGRAM /////
77
  private static DistortedProgram mNormalProgram;
78
  private static int mNormalMVPMatrixH;
79
  /// END PROGRAMS //////
80

    
81
  private static long mNextID =0;
82
  private long mID;
83

    
84
  private EffectQueueMatrix mM;
85
  private EffectQueueFragment mF;
86
  private EffectQueueVertex mV;
87

    
88
  private boolean matrixCloned, vertexCloned, fragmentCloned;
89

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

    
92
  static void createProgram(Resources resources)
93
  throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
94
    {
95
    // MAIN PROGRAM ////////////////////////////////////
96
    final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader);
97
    final InputStream mainFragStream = resources.openRawResource(R.raw.main_fragment_shader);
98

    
99
    String mainVertHeader= Distorted.GLSL_VERSION;
100
    String mainFragHeader= Distorted.GLSL_VERSION;
101

    
102
    boolean foundF = false;
103
    boolean foundV = false;
104
    int effects = mEnabledEffects.size();
105
    EffectName effect;
106
    EffectType type;
107

    
108
    for(int i=0; i<effects; i++)
109
      {
110
      effect = mEnabledEffects.remove(0);
111
      type   = effect.getType();
112

    
113
      if( type == EffectType.VERTEX )
114
        {
115
        mainVertHeader += ("#define "+effect.name()+" "+effect.ordinal()+"\n");
116
        foundV = true;
117
        }
118
      else if( type == EffectType.FRAGMENT )
119
        {
120
        mainFragHeader += ("#define "+effect.name()+" "+effect.ordinal()+"\n");
121
        foundF = true;
122
        }
123
      }
124

    
125
    mainVertHeader += ("#define NUM_VERTEX "   + ( foundV ? getMaxVertex()   : 0 ) + "\n");
126
    mainFragHeader += ("#define NUM_FRAGMENT " + ( foundF ? getMaxFragment() : 0 ) + "\n");
127

    
128
    //android.util.Log.e("Effects", "vertHeader= "+mainVertHeader);
129
    //android.util.Log.e("Effects", "fragHeader= "+mainFragHeader);
130

    
131
    String[] feedback = { "v_Position", "v_endPosition" };
132

    
133
    mMainProgram = new DistortedProgram(mainVertStream,mainFragStream, mainVertHeader, mainFragHeader, Distorted.GLSL, feedback);
134

    
135
    int mainProgramH = mMainProgram.getProgramHandle();
136
    EffectQueueFragment.getUniforms(mainProgramH);
137
    EffectQueueVertex.getUniforms(mainProgramH);
138
    EffectQueueMatrix.getUniforms(mainProgramH);
139
    mMainTextureH= GLES30.glGetUniformLocation( mainProgramH, "u_Texture");
140

    
141
    // BLIT PROGRAM ////////////////////////////////////
142
    final InputStream blitVertStream = resources.openRawResource(R.raw.blit_vertex_shader);
143
    final InputStream blitFragStream = resources.openRawResource(R.raw.blit_fragment_shader);
144

    
145
    String blitVertHeader= (Distorted.GLSL_VERSION + "#define NUM_VERTEX 0\n"  );
146
    String blitFragHeader= (Distorted.GLSL_VERSION + "#define NUM_FRAGMENT 0\n");
147

    
148
    try
149
      {
150
      mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream,blitVertHeader,blitFragHeader, Distorted.GLSL);
151
      }
152
    catch(Exception e)
153
      {
154
      android.util.Log.e("EFFECTS", "exception trying to compile BLIT program: "+e.getMessage());
155
      throw new RuntimeException(e.getMessage());
156
      }
157

    
158
    int blitProgramH = mBlitProgram.getProgramHandle();
159
    mBlitTextureH  = GLES30.glGetUniformLocation( blitProgramH, "u_Texture");
160
    mBlitDepthH    = GLES30.glGetUniformLocation( blitProgramH, "u_Depth");
161

    
162
    // BLIT DEPTH PROGRAM ////////////////////////////////////
163
    final InputStream blitDepthVertStream = resources.openRawResource(R.raw.blit_depth_vertex_shader);
164
    final InputStream blitDepthFragStream = resources.openRawResource(R.raw.blit_depth_fragment_shader);
165

    
166
    try
167
      {
168
      mBlitDepthProgram = new DistortedProgram(blitDepthVertStream,blitDepthFragStream,blitVertHeader,blitFragHeader, Distorted.GLSL);
169
      }
170
    catch(Exception e)
171
      {
172
      android.util.Log.e("EFFECTS", "exception trying to compile BLIT DEPTH program: "+e.getMessage());
173
      throw new RuntimeException(e.getMessage());
174
      }
175

    
176
    int blitDepthProgramH   = mBlitDepthProgram.getProgramHandle();
177
    mBlitDepthTextureH      = GLES30.glGetUniformLocation( blitDepthProgramH, "u_Texture");
178
    mBlitDepthDepthTextureH = GLES30.glGetUniformLocation( blitDepthProgramH, "u_DepthTexture");
179
    mBlitDepthDepthH        = GLES30.glGetUniformLocation( blitDepthProgramH, "u_Depth");
180

    
181
    // NORMAL PROGRAM //////////////////////////////////////
182
    final InputStream normalVertexStream   = resources.openRawResource(R.raw.normal_vertex_shader);
183
    final InputStream normalFragmentStream = resources.openRawResource(R.raw.normal_fragment_shader);
184

    
185
    try
186
      {
187
      mNormalProgram = new DistortedProgram(normalVertexStream,normalFragmentStream, Distorted.GLSL_VERSION, Distorted.GLSL_VERSION, Distorted.GLSL);
188
      }
189
    catch(Exception e)
190
      {
191
      android.util.Log.e("EFFECTS", "exception trying to compile NORMAL program: "+e.getMessage());
192
      throw new RuntimeException(e.getMessage());
193
      }
194

    
195
    int normalProgramH = mNormalProgram.getProgramHandle();
196
    mNormalMVPMatrixH  = GLES30.glGetUniformLocation( normalProgramH, "u_MVPMatrix");
197
    }
198

    
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

    
201
  private void initializeEffectLists(DistortedEffects d, int flags)
202
    {
203
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
204
      {
205
      mM = d.mM;
206
      matrixCloned = true;
207
      }
208
    else
209
      {
210
      mM = new EffectQueueMatrix(mID);
211
      matrixCloned = false;
212
      }
213
    
214
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
215
      {
216
      mV = d.mV;
217
      vertexCloned = true;
218
      }
219
    else
220
      {
221
      mV = new EffectQueueVertex(mID);
222
      vertexCloned = false;
223
      }
224
    
225
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
226
      {
227
      mF = d.mF;
228
      fragmentCloned = true;
229
      }
230
    else
231
      {
232
      mF = new EffectQueueFragment(mID);
233
      fragmentCloned = false;
234
      }
235
    }
236

    
237
///////////////////////////////////////////////////////////////////////////////////////////////////
238

    
239
  private void displayNormals(MeshObject mesh)
240
    {
241
    GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, mesh.mAttTFO[0]);
242
    GLES30.glBeginTransformFeedback( GLES30.GL_POINTS);
243
    DistortedRenderState.switchOffDrawing();
244
    GLES30.glDrawArrays( GLES30.GL_POINTS, 0, mesh.numVertices);
245
    DistortedRenderState.restoreDrawing();
246
    GLES30.glEndTransformFeedback();
247
    GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
248

    
249
    mNormalProgram.useProgram();
250
    GLES30.glUniformMatrix4fv(mNormalMVPMatrixH, 1, false, mM.getMVP() , 0);
251
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mAttTFO[0]);
252
    GLES30.glVertexAttribPointer(mNormalProgram.mAttribute[0], MeshObject.POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, 0);
253
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
254
    GLES30.glLineWidth(8.0f);
255
    GLES30.glDrawArrays(GLES30.GL_LINES, 0, 2*mesh.numVertices);
256
    }
257

    
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259

    
260
  void drawPriv(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime, float marginInPixels)
261
    {
262
    mM.compute(currTime);
263
    mV.compute(currTime);
264
    mF.compute(currTime);
265

    
266
    float halfZ = halfW*mesh.zFactor;
267

    
268
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
269

    
270
    mMainProgram.useProgram();
271
    GLES30.glUniform1i(mMainTextureH, 0);
272

    
273
    if( Distorted.GLSL >= 300 )
274
      {
275
      GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mAttVBO[0]);
276
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], MeshObject.POS_DATA_SIZE, GLES30.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET0);
277
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], MeshObject.NOR_DATA_SIZE, GLES30.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET1);
278
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE, GLES30.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET2);
279
      GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
280
      }
281
    else
282
      {
283
      mesh.mVertAttribs.position(0);
284
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], MeshObject.POS_DATA_SIZE, GLES30.GL_FLOAT, false, MeshObject.VERTSIZE, mesh.mVertAttribs);
285
      mesh.mVertAttribs.position(MeshObject.POS_DATA_SIZE);
286
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], MeshObject.NOR_DATA_SIZE, GLES30.GL_FLOAT, false, MeshObject.VERTSIZE, mesh.mVertAttribs);
287
      mesh.mVertAttribs.position(MeshObject.POS_DATA_SIZE+MeshObject.NOR_DATA_SIZE);
288
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE, GLES30.GL_FLOAT, false, MeshObject.VERTSIZE, mesh.mVertAttribs);
289
      }
290

    
291
    mM.send(surface,halfW,halfH,halfZ,marginInPixels);
292
    mV.send(halfW,halfH,halfZ);
293
    mF.send(halfW,halfH);
294

    
295
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.numVertices);
296

    
297
    if( mesh.mShowNormals ) displayNormals(mesh);
298
    }
299

    
300
///////////////////////////////////////////////////////////////////////////////////////////////////
301
   
302
  static void blitPriv(DistortedOutputSurface surface)
303
    {
304
    mBlitProgram.useProgram();
305

    
306
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
307
    GLES30.glUniform1i(mBlitTextureH, 0);
308
    GLES30.glUniform1f( mBlitDepthH , 1.0f-surface.mNear);
309
    GLES30.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
310
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
311
    }
312

    
313
///////////////////////////////////////////////////////////////////////////////////////////////////
314

    
315
  static void blitDepthPriv(DistortedOutputSurface surface)
316
    {
317
    mBlitDepthProgram.useProgram();
318

    
319
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
320
    GLES30.glUniform1i(mBlitDepthTextureH, 0);
321
    GLES30.glUniform1i(mBlitDepthDepthTextureH, 1);
322
    GLES30.glUniform1f( mBlitDepthDepthH , 1.0f-surface.mNear);
323
    GLES30.glVertexAttribPointer(mBlitDepthProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
324
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
325
    }
326

    
327
///////////////////////////////////////////////////////////////////////////////////////////////////
328
   
329
  private void releasePriv()
330
    {
331
    if( !matrixCloned   ) mM.abortAll(false);
332
    if( !vertexCloned   ) mV.abortAll(false);
333
    if( !fragmentCloned ) mF.abortAll(false);
334

    
335
    mM = null;
336
    mV = null;
337
    mF = null;
338
    }
339

    
340
///////////////////////////////////////////////////////////////////////////////////////////////////
341

    
342
  static void onDestroy()
343
    {
344
    mNextID = 0;
345
    }
346

    
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348
// PUBLIC API
349
///////////////////////////////////////////////////////////////////////////////////////////////////
350
/**
351
 * Create empty effect queue.
352
 */
353
  public DistortedEffects()
354
    {
355
    mID = ++mNextID;
356
    initializeEffectLists(this,0);
357
    }
358

    
359
///////////////////////////////////////////////////////////////////////////////////////////////////
360
/**
361
 * Copy constructor.
362
 * <p>
363
 * Whatever we do not clone gets created just like in the default constructor.
364
 *
365
 * @param dc    Source object to create our object from
366
 * @param flags A bitmask of values specifying what to copy.
367
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
368
 */
369
  public DistortedEffects(DistortedEffects dc, int flags)
370
    {
371
    mID = ++mNextID;
372
    initializeEffectLists(dc,flags);
373
    }
374

    
375
///////////////////////////////////////////////////////////////////////////////////////////////////
376
/**
377
 * Releases all resources. After this call, the queue should not be used anymore.
378
 */
379
  @SuppressWarnings("unused")
380
  public synchronized void delete()
381
    {
382
    releasePriv();
383
    }
384

    
385
///////////////////////////////////////////////////////////////////////////////////////////////////
386
/**
387
 * Returns unique ID of this instance.
388
 *
389
 * @return ID of the object.
390
 */
391
  public long getID()
392
      {
393
      return mID;
394
      }
395

    
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397
/**
398
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
399
 * to one of the Effects in those queues. Nothing will happen if 'el' is already in the list.
400
 * 
401
 * @param el A class implementing the EffectListener interface that wants to get notifications.
402
 */
403
  @SuppressWarnings("unused")
404
  public void registerForMessages(EffectListener el)
405
    {
406
    mV.registerForMessages(el);
407
    mF.registerForMessages(el);
408
    mM.registerForMessages(el);
409
    }
410

    
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412
/**
413
 * Removes the calling class from the list of Listeners.
414
 * 
415
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
416
 */
417
  @SuppressWarnings("unused")
418
  public void deregisterForMessages(EffectListener el)
419
    {
420
    mV.deregisterForMessages(el);
421
    mF.deregisterForMessages(el);
422
    mM.deregisterForMessages(el);
423
    }
424

    
425
///////////////////////////////////////////////////////////////////////////////////////////////////
426
/**
427
 * Aborts all Effects.
428
 * @return Number of effects aborted.
429
 */
430
  public int abortAllEffects()
431
    {
432
    return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true);
433
    }
434

    
435
///////////////////////////////////////////////////////////////////////////////////////////////////
436
/**
437
 * Aborts all Effects of a given type, for example all MATRIX Effects.
438
 * 
439
 * @param type one of the constants defined in {@link EffectType}
440
 * @return Number of effects aborted.
441
 */
442
  public int abortByType(EffectType type)
443
    {
444
    switch(type)
445
      {
446
      case MATRIX     : return mM.abortAll(true);
447
      case VERTEX     : return mV.abortAll(true);
448
      case FRAGMENT   : return mF.abortAll(true);
449
  //  case POSTPROCESS: return mP.abortAll(true);
450
      default         : return 0;
451
      }
452
    }
453
    
454
///////////////////////////////////////////////////////////////////////////////////////////////////
455
/**
456
 * Aborts a single Effect.
457
 * 
458
 * @param effect the Effect we want to abort.
459
 * @return number of Effects aborted. Always either 0 or 1.
460
 */
461
  public int abortEffect(Effect effect)
462
    {
463
    switch(effect.getType())
464
      {
465
      case MATRIX     : return mM.removeEffect(effect);
466
      case VERTEX     : return mV.removeEffect(effect);
467
      case FRAGMENT   : return mF.removeEffect(effect);
468
  //  case POSTPROCESS: return mP.removeEffect(effect);
469
      default         : return 0;
470
      }
471
    }
472

    
473
///////////////////////////////////////////////////////////////////////////////////////////////////
474
/**
475
 * Abort all Effects of a given name, for example all rotations.
476
 * 
477
 * @param name one of the constants defined in {@link EffectName}
478
 * @return number of Effects aborted.
479
 */
480
  public int abortByName(EffectName name)
481
    {
482
    switch(name.getType())
483
      {
484
      case MATRIX     : return mM.removeByName(name);
485
      case VERTEX     : return mV.removeByName(name);
486
      case FRAGMENT   : return mF.removeByName(name);
487
  //  case POSTPROCESS: return mP.removeByName(name);
488
      default                : return 0;
489
      }
490
    }
491

    
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493
/**
494
 * Enables a given Effect.
495
 * <p>
496
 * By default, all effects are disabled. One has to explicitly enable each effect one intends to use.
497
 * This needs to be called BEFORE shaders get compiled, i.e. before the call to Distorted.onCreate().
498
 * The point: by enabling only the effects we need, we can optimize the shaders.
499
 *
500
 * @param name one of the constants defined in {@link EffectName}
501
 */
502
  public static void enableEffect(EffectName name)
503
    {
504
    mEnabledEffects.add(name);
505
    }
506

    
507
///////////////////////////////////////////////////////////////////////////////////////////////////
508
/**
509
 * Returns the maximum number of Matrix effects.
510
 *
511
 * @return The maximum number of Matrix effects
512
 */
513
  @SuppressWarnings("unused")
514
  public static int getMaxMatrix()
515
    {
516
    return EffectQueue.getMax(EffectType.MATRIX.ordinal());
517
    }
518

    
519
///////////////////////////////////////////////////////////////////////////////////////////////////
520
/**
521
 * Returns the maximum number of Vertex effects.
522
 *
523
 * @return The maximum number of Vertex effects
524
 */
525
  @SuppressWarnings("unused")
526
  public static int getMaxVertex()
527
    {
528
    return EffectQueue.getMax(EffectType.VERTEX.ordinal());
529
    }
530

    
531
///////////////////////////////////////////////////////////////////////////////////////////////////
532
/**
533
 * Returns the maximum number of Fragment effects.
534
 *
535
 * @return The maximum number of Fragment effects
536
 */
537
  @SuppressWarnings("unused")
538
  public static int getMaxFragment()
539
    {
540
    return EffectQueue.getMax(EffectType.FRAGMENT.ordinal());
541
    }
542

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

    
565
///////////////////////////////////////////////////////////////////////////////////////////////////
566
/**
567
 * Sets the maximum number of Vertex effects that can be stored in a single EffectQueue at one time.
568
 * This can fail if:
569
 * <ul>
570
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
571
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
572
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
573
 *     time only decreasing the value of 'max' is permitted.
574
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
575
 * </ul>
576
 *
577
 * @param max new maximum number of simultaneous Vertex Effects. Has to be a non-negative number not greater
578
 *            than Byte.MAX_VALUE
579
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
580
 */
581
  @SuppressWarnings("unused")
582
  public static boolean setMaxVertex(int max)
583
    {
584
    return EffectQueue.setMax(EffectType.VERTEX.ordinal(),max);
585
    }
586

    
587
///////////////////////////////////////////////////////////////////////////////////////////////////
588
/**
589
 * Sets the maximum number of Fragment effects that can be stored in a single EffectQueue at one time.
590
 * This can fail if:
591
 * <ul>
592
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
593
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
594
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
595
 *     time only decreasing the value of 'max' is permitted.
596
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
597
 * </ul>
598
 *
599
 * @param max new maximum number of simultaneous Fragment Effects. Has to be a non-negative number not greater
600
 *            than Byte.MAX_VALUE
601
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
602
 */
603
  @SuppressWarnings("unused")
604
  public static boolean setMaxFragment(int max)
605
    {
606
    return EffectQueue.setMax(EffectType.FRAGMENT.ordinal(),max);
607
    }
608

    
609
///////////////////////////////////////////////////////////////////////////////////////////////////
610
/**
611
 * Add a new Effect to our queue.
612
 *
613
 * @param effect The Effect to add.
614
 */
615
  public void apply(Effect effect)
616
    {
617
    switch(effect.getType())
618
      {
619
      case VERTEX      : mV.add(effect); break;
620
      case FRAGMENT    : mF.add(effect); break;
621
      case MATRIX      : mM.add(effect); break;
622
   // case POSTPROCESS : mP.add(effect); break;
623
      }
624
    }
625
  }
(2-2/24)