Project

General

Profile

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

library / src / main / java / org / distorted / library / main / DistortedEffects.java @ 2ef5dd9e

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 boolean[] mEffectEnabled = new boolean[EffectName.LENGTH];
56

    
57
  static
58
    {
59
    int len = EffectName.LENGTH;
60
    for(int i=0; i<len; i++)
61
      {
62
      mEffectEnabled[i] = false;
63
      }
64
    }
65

    
66
  /// BLIT PROGRAM ///
67
  private static DistortedProgram mBlitProgram;
68
  private static int mBlitTextureH;
69
  private static int mBlitDepthH;
70
  private static final FloatBuffer mQuadPositions;
71

    
72
  static
73
    {
74
    float[] positionData= { -0.5f, -0.5f,  -0.5f, 0.5f,  0.5f,-0.5f,  0.5f, 0.5f };
75
    mQuadPositions = ByteBuffer.allocateDirect(32).order(ByteOrder.nativeOrder()).asFloatBuffer();
76
    mQuadPositions.put(positionData).position(0);
77
    }
78

    
79
  /// BLIT DEPTH PROGRAM ///
80
  private static DistortedProgram mBlitDepthProgram;
81
  private static int mBlitDepthTextureH;
82
  private static int mBlitDepthDepthTextureH;
83
  private static int mBlitDepthDepthH;
84

    
85
  /// NORMAL PROGRAM /////
86
  private static DistortedProgram mNormalProgram;
87
  private static int mNormalMVPMatrixH;
88
  /// END PROGRAMS //////
89

    
90
  private static long mNextID =0;
91
  private long mID;
92

    
93
  private EffectQueueMatrix mM;
94
  private EffectQueueFragment mF;
95
  private EffectQueueVertex mV;
96

    
97
  private boolean matrixCloned, vertexCloned, fragmentCloned;
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  static void createProgram(Resources resources)
102
  throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
103
    {
104
    // MAIN PROGRAM ////////////////////////////////////
105
    final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader);
106
    final InputStream mainFragStream = resources.openRawResource(R.raw.main_fragment_shader);
107

    
108
    String mainVertHeader= Distorted.GLSL_VERSION;
109
    String mainFragHeader= Distorted.GLSL_VERSION;
110

    
111
    EffectName name;
112
    EffectType type;
113
    boolean foundF = false;
114
    boolean foundV = false;
115

    
116
    for(int i=0; i<mEffectEnabled.length; i++)
117
      {
118
      if( mEffectEnabled[i] )
119
        {
120
        name = EffectName.getName(i);
121
        type = name.getType();
122

    
123
        if( type == EffectType.VERTEX )
124
          {
125
          mainVertHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
126
          foundV = true;
127
          }
128
        else if( type == EffectType.FRAGMENT )
129
          {
130
          mainFragHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
131
          foundF = true;
132
          }
133
        }
134
      }
135

    
136
    mainVertHeader += ("#define NUM_VERTEX "   + ( foundV ? getMaxVertex()   : 0 ) + "\n");
137
    mainFragHeader += ("#define NUM_FRAGMENT " + ( foundF ? getMaxFragment() : 0 ) + "\n");
138

    
139
    //android.util.Log.e("Effects", "vertHeader= "+mainVertHeader);
140
    //android.util.Log.e("Effects", "fragHeader= "+mainFragHeader);
141

    
142
    String[] feedback = { "v_Position", "v_endPosition" };
143

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

    
146
    int mainProgramH = mMainProgram.getProgramHandle();
147
    EffectQueueFragment.getUniforms(mainProgramH);
148
    EffectQueueVertex.getUniforms(mainProgramH);
149
    EffectQueueMatrix.getUniforms(mainProgramH);
150
    mMainTextureH= GLES30.glGetUniformLocation( mainProgramH, "u_Texture");
151

    
152
    // BLIT PROGRAM ////////////////////////////////////
153
    final InputStream blitVertStream = resources.openRawResource(R.raw.blit_vertex_shader);
154
    final InputStream blitFragStream = resources.openRawResource(R.raw.blit_fragment_shader);
155

    
156
    String blitVertHeader= (Distorted.GLSL_VERSION + "#define NUM_VERTEX 0\n"  );
157
    String blitFragHeader= (Distorted.GLSL_VERSION + "#define NUM_FRAGMENT 0\n");
158

    
159
    try
160
      {
161
      mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream,blitVertHeader,blitFragHeader, Distorted.GLSL);
162
      }
163
    catch(Exception e)
164
      {
165
      android.util.Log.e("EFFECTS", "exception trying to compile BLIT program: "+e.getMessage());
166
      throw new RuntimeException(e.getMessage());
167
      }
168

    
169
    int blitProgramH = mBlitProgram.getProgramHandle();
170
    mBlitTextureH  = GLES30.glGetUniformLocation( blitProgramH, "u_Texture");
171
    mBlitDepthH    = GLES30.glGetUniformLocation( blitProgramH, "u_Depth");
172

    
173
    // BLIT DEPTH PROGRAM ////////////////////////////////////
174
    final InputStream blitDepthVertStream = resources.openRawResource(R.raw.blit_depth_vertex_shader);
175
    final InputStream blitDepthFragStream = resources.openRawResource(R.raw.blit_depth_fragment_shader);
176

    
177
    try
178
      {
179
      mBlitDepthProgram = new DistortedProgram(blitDepthVertStream,blitDepthFragStream,blitVertHeader,blitFragHeader, Distorted.GLSL);
180
      }
181
    catch(Exception e)
182
      {
183
      android.util.Log.e("EFFECTS", "exception trying to compile BLIT DEPTH program: "+e.getMessage());
184
      throw new RuntimeException(e.getMessage());
185
      }
186

    
187
    int blitDepthProgramH   = mBlitDepthProgram.getProgramHandle();
188
    mBlitDepthTextureH      = GLES30.glGetUniformLocation( blitDepthProgramH, "u_Texture");
189
    mBlitDepthDepthTextureH = GLES30.glGetUniformLocation( blitDepthProgramH, "u_DepthTexture");
190
    mBlitDepthDepthH        = GLES30.glGetUniformLocation( blitDepthProgramH, "u_Depth");
191

    
192
    // NORMAL PROGRAM //////////////////////////////////////
193
    final InputStream normalVertexStream   = resources.openRawResource(R.raw.normal_vertex_shader);
194
    final InputStream normalFragmentStream = resources.openRawResource(R.raw.normal_fragment_shader);
195

    
196
    try
197
      {
198
      mNormalProgram = new DistortedProgram(normalVertexStream,normalFragmentStream, Distorted.GLSL_VERSION, Distorted.GLSL_VERSION, Distorted.GLSL);
199
      }
200
    catch(Exception e)
201
      {
202
      android.util.Log.e("EFFECTS", "exception trying to compile NORMAL program: "+e.getMessage());
203
      throw new RuntimeException(e.getMessage());
204
      }
205

    
206
    int normalProgramH = mNormalProgram.getProgramHandle();
207
    mNormalMVPMatrixH  = GLES30.glGetUniformLocation( normalProgramH, "u_MVPMatrix");
208
    }
209

    
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211

    
212
  private void initializeEffectLists(DistortedEffects d, int flags)
213
    {
214
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
215
      {
216
      mM = d.mM;
217
      matrixCloned = true;
218
      }
219
    else
220
      {
221
      mM = new EffectQueueMatrix(mID);
222
      matrixCloned = false;
223
      }
224
    
225
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
226
      {
227
      mV = d.mV;
228
      vertexCloned = true;
229
      }
230
    else
231
      {
232
      mV = new EffectQueueVertex(mID);
233
      vertexCloned = false;
234
      }
235
    
236
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
237
      {
238
      mF = d.mF;
239
      fragmentCloned = true;
240
      }
241
    else
242
      {
243
      mF = new EffectQueueFragment(mID);
244
      fragmentCloned = false;
245
      }
246
    }
247

    
248
///////////////////////////////////////////////////////////////////////////////////////////////////
249

    
250
  private void displayNormals(MeshObject mesh)
251
    {
252
    GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, mesh.mAttTFO[0]);
253
    GLES30.glBeginTransformFeedback( GLES30.GL_POINTS);
254
    DistortedRenderState.switchOffDrawing();
255
    GLES30.glDrawArrays( GLES30.GL_POINTS, 0, mesh.numVertices);
256
    DistortedRenderState.restoreDrawing();
257
    GLES30.glEndTransformFeedback();
258
    GLES30.glBindBufferBase(GLES30.GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
259

    
260
    mNormalProgram.useProgram();
261
    GLES30.glUniformMatrix4fv(mNormalMVPMatrixH, 1, false, mM.getMVP() , 0);
262
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mAttTFO[0]);
263
    GLES30.glVertexAttribPointer(mNormalProgram.mAttribute[0], MeshObject.POS_DATA_SIZE, GLES30.GL_FLOAT, false, 0, 0);
264
    GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
265
    GLES30.glLineWidth(8.0f);
266
    GLES30.glDrawArrays(GLES30.GL_LINES, 0, 2*mesh.numVertices);
267
    }
268

    
269
///////////////////////////////////////////////////////////////////////////////////////////////////
270

    
271
  void drawPriv(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime, float marginInPixels)
272
    {
273
    mM.compute(currTime);
274
    mV.compute(currTime);
275
    mF.compute(currTime);
276

    
277
    float halfZ = halfW*mesh.zFactor;
278

    
279
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
280

    
281
    mMainProgram.useProgram();
282
    GLES30.glUniform1i(mMainTextureH, 0);
283

    
284
    if( Distorted.GLSL >= 300 )
285
      {
286
      GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, mesh.mAttVBO[0]);
287
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], MeshObject.POS_DATA_SIZE, GLES30.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET0);
288
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], MeshObject.NOR_DATA_SIZE, GLES30.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET1);
289
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE, GLES30.GL_FLOAT, false, MeshObject.VERTSIZE, MeshObject.OFFSET2);
290
      GLES30.glBindBuffer(GLES30.GL_ARRAY_BUFFER, 0);
291
      }
292
    else
293
      {
294
      mesh.mVertAttribs.position(0);
295
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], MeshObject.POS_DATA_SIZE, GLES30.GL_FLOAT, false, MeshObject.VERTSIZE, mesh.mVertAttribs);
296
      mesh.mVertAttribs.position(MeshObject.POS_DATA_SIZE);
297
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], MeshObject.NOR_DATA_SIZE, GLES30.GL_FLOAT, false, MeshObject.VERTSIZE, mesh.mVertAttribs);
298
      mesh.mVertAttribs.position(MeshObject.POS_DATA_SIZE+MeshObject.NOR_DATA_SIZE);
299
      GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], MeshObject.TEX_DATA_SIZE, GLES30.GL_FLOAT, false, MeshObject.VERTSIZE, mesh.mVertAttribs);
300
      }
301

    
302
    mM.send(surface,halfW,halfH,halfZ,marginInPixels);
303
    mV.send(halfW,halfH,halfZ);
304
    mF.send(halfW,halfH);
305

    
306
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.numVertices);
307

    
308
    if( mesh.mShowNormals ) displayNormals(mesh);
309
    }
310

    
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312
   
313
  static void blitPriv(DistortedOutputSurface surface)
314
    {
315
    mBlitProgram.useProgram();
316

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

    
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325

    
326
  static void blitDepthPriv(DistortedOutputSurface surface)
327
    {
328
    mBlitDepthProgram.useProgram();
329

    
330
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight );
331
    GLES30.glUniform1i(mBlitDepthTextureH, 0);
332
    GLES30.glUniform1i(mBlitDepthDepthTextureH, 1);
333
    GLES30.glUniform1f( mBlitDepthDepthH , 1.0f-surface.mNear);
334
    GLES30.glVertexAttribPointer(mBlitDepthProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
335
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
336
    }
337

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

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

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

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

    
357
    for(int i=0; i<EffectName.LENGTH; i++)
358
      {
359
      mEffectEnabled[i] = false;
360
      }
361
    }
362

    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364
// PUBLIC API
365
///////////////////////////////////////////////////////////////////////////////////////////////////
366
/**
367
 * Create empty effect queue.
368
 */
369
  public DistortedEffects()
370
    {
371
    mID = ++mNextID;
372
    initializeEffectLists(this,0);
373
    }
374

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

    
391
///////////////////////////////////////////////////////////////////////////////////////////////////
392
/**
393
 * Releases all resources. After this call, the queue should not be used anymore.
394
 */
395
  @SuppressWarnings("unused")
396
  public synchronized void delete()
397
    {
398
    releasePriv();
399
    }
400

    
401
///////////////////////////////////////////////////////////////////////////////////////////////////
402
/**
403
 * Returns unique ID of this instance.
404
 *
405
 * @return ID of the object.
406
 */
407
  public long getID()
408
      {
409
      return mID;
410
      }
411

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

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428
/**
429
 * Removes the calling class from the list of Listeners.
430
 * 
431
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
432
 */
433
  @SuppressWarnings("unused")
434
  public void deregisterForMessages(EffectListener el)
435
    {
436
    mV.deregisterForMessages(el);
437
    mF.deregisterForMessages(el);
438
    mM.deregisterForMessages(el);
439
    }
440

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

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

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

    
481
    if( type == EffectType.MATRIX.ordinal()      ) return mM.removeById(id);
482
    if( type == EffectType.VERTEX.ordinal()      ) return mV.removeById(id);
483
    if( type == EffectType.FRAGMENT.ordinal()    ) return mF.removeById(id);
484
//  if( type == EffectType.POSTPROCESS.ordinal() ) return mP.removeById(id);
485

    
486
    return 0;
487
    }
488

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

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

    
527
///////////////////////////////////////////////////////////////////////////////////////////////////
528
/**
529
 * Enables a given Effect.
530
 * <p>
531
 * By default, all effects are disabled. One has to explicitly enable each effect one intends to use.
532
 * This needs to be called BEFORE shaders get compiled, i.e. before the call to Distorted.onCreate().
533
 * The point: by enabling only the effects we need, we can optimize the shaders.
534
 *
535
 * @param name one of the constants defined in {@link EffectName}
536
 */
537
  public static void enableEffect(EffectName name)
538
    {
539
    mEffectEnabled[name.ordinal()] = true;
540
    }
541

    
542
///////////////////////////////////////////////////////////////////////////////////////////////////
543
/**
544
 * Returns the maximum number of Matrix effects.
545
 *
546
 * @return The maximum number of Matrix effects
547
 */
548
  @SuppressWarnings("unused")
549
  public static int getMaxMatrix()
550
    {
551
    return EffectQueue.getMax(EffectType.MATRIX.ordinal());
552
    }
553

    
554
///////////////////////////////////////////////////////////////////////////////////////////////////
555
/**
556
 * Returns the maximum number of Vertex effects.
557
 *
558
 * @return The maximum number of Vertex effects
559
 */
560
  @SuppressWarnings("unused")
561
  public static int getMaxVertex()
562
    {
563
    return EffectQueue.getMax(EffectType.VERTEX.ordinal());
564
    }
565

    
566
///////////////////////////////////////////////////////////////////////////////////////////////////
567
/**
568
 * Returns the maximum number of Fragment effects.
569
 *
570
 * @return The maximum number of Fragment effects
571
 */
572
  @SuppressWarnings("unused")
573
  public static int getMaxFragment()
574
    {
575
    return EffectQueue.getMax(EffectType.FRAGMENT.ordinal());
576
    }
577

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

    
600
///////////////////////////////////////////////////////////////////////////////////////////////////
601
/**
602
 * Sets the maximum number of Vertex effects that can be stored in a single EffectQueue at one time.
603
 * This can fail if:
604
 * <ul>
605
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
606
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
607
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
608
 *     time only decreasing the value of 'max' is permitted.
609
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
610
 * </ul>
611
 *
612
 * @param max new maximum number of simultaneous Vertex Effects. Has to be a non-negative number not greater
613
 *            than Byte.MAX_VALUE
614
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
615
 */
616
  @SuppressWarnings("unused")
617
  public static boolean setMaxVertex(int max)
618
    {
619
    return EffectQueue.setMax(EffectType.VERTEX.ordinal(),max);
620
    }
621

    
622
///////////////////////////////////////////////////////////////////////////////////////////////////
623
/**
624
 * Sets the maximum number of Fragment effects that can be stored in a single EffectQueue at one time.
625
 * This can fail if:
626
 * <ul>
627
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
628
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
629
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
630
 *     time only decreasing the value of 'max' is permitted.
631
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
632
 * </ul>
633
 *
634
 * @param max new maximum number of simultaneous Fragment Effects. Has to be a non-negative number not greater
635
 *            than Byte.MAX_VALUE
636
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
637
 */
638
  @SuppressWarnings("unused")
639
  public static boolean setMaxFragment(int max)
640
    {
641
    return EffectQueue.setMax(EffectType.FRAGMENT.ordinal(),max);
642
    }
643

    
644
///////////////////////////////////////////////////////////////////////////////////////////////////
645
/**
646
 * Add a new Effect to our queue.
647
 *
648
 * @param effect The Effect to add.
649
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
650
 */
651
  public boolean apply(Effect effect)
652
    {
653
    switch(effect.getType())
654
      {
655
      case VERTEX      : return mV.add(effect);
656
      case FRAGMENT    : return mF.add(effect);
657
      case MATRIX      : return mM.add(effect);
658
   // case POSTPROCESS : return mP.add(effect);
659
      }
660

    
661
    return false;
662
    }
663
  }
(2-2/24)