Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffects.java @ 95c441a2

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

    
22
import android.content.res.Resources;
23
import android.opengl.GLES30;
24
import android.opengl.Matrix;
25

    
26
import org.distorted.library.message.EffectListener;
27
import org.distorted.library.program.DistortedProgram;
28
import org.distorted.library.program.FragmentCompilationException;
29
import org.distorted.library.program.FragmentUniformsException;
30
import org.distorted.library.program.LinkingException;
31
import org.distorted.library.program.VertexCompilationException;
32
import org.distorted.library.program.VertexUniformsException;
33
import org.distorted.library.type.Data1D;
34
import org.distorted.library.type.Data2D;
35
import org.distorted.library.type.Data3D;
36
import org.distorted.library.type.Data4D;
37
import org.distorted.library.type.Data5D;
38
import org.distorted.library.type.Static3D;
39

    
40
import java.io.InputStream;
41
import java.nio.ByteBuffer;
42
import java.nio.ByteOrder;
43
import java.nio.FloatBuffer;
44

    
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46
/**
47
 * Class containing {@link EffectTypes#LENGTH} queues, each a class derived from EffectQueue.
48
 * <p>
49
 * The queues hold actual effects to be applied to a given (DistortedTexture,MeshObject) combo.
50
 */
51
public class DistortedEffects
52
  {
53
  private static final int POSITION_DATA_SIZE= 3; // Main Program: size of the position data in elements
54
  private static final int NORMAL_DATA_SIZE  = 3; // Main Program: size of the normal data in elements
55
  private static final int TEX_DATA_SIZE     = 2; // Main Program: size of the texture coordinate data in elements.
56

    
57
  /// MAIN PROGRAM ///
58
  private static DistortedProgram mMainProgram;
59
  private static int mMainTextureH;
60
  private static boolean[] mEffectEnabled = new boolean[EffectNames.size()];
61

    
62
  static
63
    {
64
    int len = EffectNames.size();
65

    
66
    for(int i=0; i<len; i++)
67
      {
68
      mEffectEnabled[i] = false;
69
      }
70
    }
71

    
72
  /// BLIT PROGRAM ///
73
  private static DistortedProgram mBlitProgram;
74
  private static int mBlitTextureH;
75
  private static int mBlitDepthH;
76
  private static final FloatBuffer mQuadPositions;
77

    
78
  static
79
    {
80
    float[] positionData= { -0.5f, -0.5f,  -0.5f, 0.5f,  0.5f,-0.5f,  0.5f, 0.5f };
81
    mQuadPositions = ByteBuffer.allocateDirect(32).order(ByteOrder.nativeOrder()).asFloatBuffer();
82
    mQuadPositions.put(positionData).position(0);
83
    }
84

    
85
  /// DEBUG ONLY /////
86
  private static DistortedProgram mDebugProgram;
87

    
88
  private static int mDebugObjDH;
89
  private static int mDebugMVPMatrixH;
90
  /// END DEBUG //////
91

    
92
  private static float[] mMVPMatrix = new float[16];
93
  private static float[] mTmpMatrix = new float[16];
94

    
95
  private static long mNextID =0;
96
  private long mID;
97

    
98
  private EffectQueueMatrix      mM;
99
  private EffectQueueFragment    mF;
100
  private EffectQueueVertex      mV;
101
  private EffectQueuePostprocess mP;
102

    
103
  private boolean matrixCloned, vertexCloned, fragmentCloned, postprocessCloned;
104

    
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

    
107
  static void createProgram(Resources resources)
108
  throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
109
    {
110
    final InputStream mainVertStream = resources.openRawResource(R.raw.main_vertex_shader);
111
    final InputStream mainFragStream = resources.openRawResource(R.raw.main_fragment_shader);
112

    
113
    String mainVertHeader= ("#version 100\n");
114
    String mainFragHeader= ("#version 100\n");
115

    
116
    EffectNames name;
117
    EffectTypes type;
118
    boolean foundF = false;
119
    boolean foundV = false;
120

    
121
    for(int i=0; i<mEffectEnabled.length; i++)
122
      {
123
      if( mEffectEnabled[i] )
124
        {
125
        name = EffectNames.getName(i);
126
        type = EffectNames.getType(i);
127

    
128
        if( type == EffectTypes.VERTEX )
129
          {
130
          mainVertHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
131
          foundV = true;
132
          }
133
        else if( type == EffectTypes.FRAGMENT )
134
          {
135
          mainFragHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
136
          foundF = true;
137
          }
138
        }
139
      }
140

    
141
    mainVertHeader += ("#define NUM_VERTEX "   + ( foundV ? getMaxVertex()   : 0 ) + "\n");
142
    mainFragHeader += ("#define NUM_FRAGMENT " + ( foundF ? getMaxFragment() : 0 ) + "\n");
143

    
144
    //android.util.Log.e("Effects", "vertHeader= "+mainVertHeader);
145
    //android.util.Log.e("Effects", "fragHeader= "+mainFragHeader);
146

    
147
    mMainProgram = new DistortedProgram(mainVertStream,mainFragStream, mainVertHeader, mainFragHeader);
148

    
149
    int mainProgramH = mMainProgram.getProgramHandle();
150
    EffectQueueFragment.getUniforms(mainProgramH);
151
    EffectQueueVertex.getUniforms(mainProgramH);
152
    EffectQueueMatrix.getUniforms(mainProgramH);
153
    mMainTextureH= GLES30.glGetUniformLocation( mainProgramH, "u_Texture");
154

    
155
    // BLIT PROGRAM ////////////////////////////////////
156
    final InputStream blitVertStream = resources.openRawResource(R.raw.blit_vertex_shader);
157
    final InputStream blitFragStream = resources.openRawResource(R.raw.blit_fragment_shader);
158

    
159
    String blitVertHeader= ("#version 100\n#define NUM_VERTEX 0\n"  );
160
    String blitFragHeader= ("#version 100\n#define NUM_FRAGMENT 0\n");
161

    
162
    mBlitProgram = new DistortedProgram(blitVertStream,blitFragStream,blitVertHeader,blitFragHeader);
163

    
164
    int blitProgramH = mBlitProgram.getProgramHandle();
165
    mBlitTextureH  = GLES30.glGetUniformLocation( blitProgramH, "u_Texture");
166
    mBlitDepthH    = GLES30.glGetUniformLocation( blitProgramH, "u_Depth");
167

    
168
    // DEBUG ONLY //////////////////////////////////////
169
    final InputStream debugVertexStream   = resources.openRawResource(R.raw.test_vertex_shader);
170
    final InputStream debugFragmentStream = resources.openRawResource(R.raw.test_fragment_shader);
171

    
172
    mDebugProgram = new DistortedProgram(debugVertexStream,debugFragmentStream, "#version 100\n", "#version 100\n");
173

    
174
    int debugProgramH = mDebugProgram.getProgramHandle();
175
    mDebugObjDH = GLES30.glGetUniformLocation( debugProgramH, "u_objD");
176
    mDebugMVPMatrixH = GLES30.glGetUniformLocation( debugProgramH, "u_MVPMatrix");
177
    // END DEBUG  //////////////////////////////////////
178
    }
179

    
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181

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

    
217
    if( (flags & Distorted.CLONE_POSTPROCESS) != 0 )
218
      {
219
      mP = d.mP;
220
      postprocessCloned = true;
221
      }
222
    else
223
      {
224
      mP = new EffectQueuePostprocess(mID);
225
      postprocessCloned = false;
226
      }
227
    }
228

    
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230
// DEBUG ONLY
231

    
232
  @SuppressWarnings("unused")
233
  private void displayBoundingRect(float halfX, float halfY, float halfZ, DistortedOutputSurface surface, float[] mvp, float[] vertices, long currTime)
234
    {
235
    int len  = vertices.length/3;
236
    int minx = Integer.MAX_VALUE;
237
    int maxx = Integer.MIN_VALUE;
238
    int miny = Integer.MAX_VALUE;
239
    int maxy = Integer.MIN_VALUE;
240
    int wx,wy;
241

    
242
    float x,y,z, X,Y,W, ndcX,ndcY;
243

    
244
    for(int i=0; i<len; i++)
245
      {
246
      x = 2*halfX*vertices[3*i  ];
247
      y = 2*halfY*vertices[3*i+1];
248
      z = 2*halfZ*vertices[3*i+2];
249

    
250
      X = mvp[ 0]*x + mvp[ 4]*y + mvp[ 8]*z + mvp[12];
251
      Y = mvp[ 1]*x + mvp[ 5]*y + mvp[ 9]*z + mvp[13];
252
      W = mvp[ 3]*x + mvp[ 7]*y + mvp[11]*z + mvp[15];
253

    
254
      ndcX = X/W;
255
      ndcY = Y/W;
256

    
257
      wx = (int)(surface.mWidth *(ndcX+1)/2);
258
      wy = (int)(surface.mHeight*(ndcY+1)/2);
259

    
260
      if( wx<minx ) minx = wx;
261
      if( wx>maxx ) maxx = wx;
262
      if( wy<miny ) miny = wy;
263
      if( wy>maxy ) maxy = wy;
264
      }
265

    
266
    mDebugProgram.useProgram();
267
    surface.setAsOutput(currTime);
268

    
269
    Matrix.setIdentityM( mTmpMatrix, 0);
270
    Matrix.translateM  ( mTmpMatrix, 0, minx-surface.mWidth/2, maxy-surface.mHeight/2, -surface.mDistance);
271
    Matrix.scaleM      ( mTmpMatrix, 0, (float)(maxx-minx)/(2*halfX), (float)(maxy-miny)/(2*halfY), 1.0f);
272
    Matrix.translateM  ( mTmpMatrix, 0, halfX,-halfY, 0);
273
    Matrix.multiplyMM  ( mMVPMatrix, 0, surface.mProjectionMatrix, 0, mTmpMatrix, 0);
274

    
275
    GLES30.glUniform2f(mDebugObjDH, 2*halfX, 2*halfY);
276
    GLES30.glUniformMatrix4fv(mDebugMVPMatrixH, 1, false, mMVPMatrix , 0);
277

    
278
    GLES30.glVertexAttribPointer(mDebugProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
279
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4);
280
    }
281

    
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283

    
284
  DistortedFramebuffer getPostprocessingBuffer()
285
    {
286
    return mP.mNumEffects==0 ? null : mP.mMainBuffer;
287
    }
288

    
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290

    
291
  int postprocessPriv(long currTime, DistortedOutputSurface surface)
292
    {
293
    return mP.postprocess(currTime,surface);
294
    }
295

    
296
///////////////////////////////////////////////////////////////////////////////////////////////////
297

    
298
  void drawPriv(float halfW, float halfH, MeshObject mesh, DistortedOutputSurface surface, long currTime)
299
    {
300
    mM.compute(currTime);
301
    mV.compute(currTime);
302
    mF.compute(currTime);
303

    
304
    float halfZ = halfW*mesh.zFactor;
305
    GLES30.glViewport(0, 0, surface.mWidth, surface.mHeight);
306

    
307
    mMainProgram.useProgram();
308
    GLES30.glUniform1i(mMainTextureH, 0);
309
    surface.setAsOutput(currTime);
310
    mM.send(surface,halfW,halfH,halfZ);
311
    mV.send(halfW,halfH,halfZ);
312
    mF.send(halfW,halfH);
313
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[0], POSITION_DATA_SIZE, GLES30.GL_FLOAT, false, 0, mesh.mMeshPositions);
314
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES30.GL_FLOAT, false, 0, mesh.mMeshNormals);
315
    GLES30.glVertexAttribPointer(mMainProgram.mAttribute[2], TEX_DATA_SIZE     , GLES30.GL_FLOAT, false, 0, mesh.mMeshTexture);
316
    GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
317

    
318
    /// DEBUG ONLY //////
319
    // displayBoundingRect(halfInputW, halfInputH, halfZ, df, mM.getMVP(), mesh.getBoundingVertices() );
320
    /// END DEBUG ///////
321
    }
322

    
323
///////////////////////////////////////////////////////////////////////////////////////////////////
324
   
325
  static void blitPriv(DistortedOutputSurface projection)
326
    {
327
    mBlitProgram.useProgram();
328

    
329
    GLES30.glViewport(0, 0, projection.mWidth, projection.mHeight);
330
    GLES30.glUniform1i(mBlitTextureH, 0);
331
    GLES30.glUniform1f( mBlitDepthH , 1.0f-projection.mNear);
332
    GLES30.glVertexAttribPointer(mBlitProgram.mAttribute[0], 2, GLES30.GL_FLOAT, false, 0, mQuadPositions);
333
    GLES30.glDrawArrays(GLES30.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
    int len = EffectNames.size();
358

    
359
    for(int i=0; i<len; i++)
360
      {
361
      mEffectEnabled[i] = false;
362
      }
363
    }
364

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

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

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

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

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

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

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

    
452
///////////////////////////////////////////////////////////////////////////////////////////////////
453
/**
454
 * Aborts all Effects of a given type, for example all MATRIX Effects.
455
 * 
456
 * @param type one of the constants defined in {@link EffectTypes}
457
 * @return Number of effects aborted.
458
 */
459
  public int abortEffects(EffectTypes type)
460
    {
461
    switch(type)
462
      {
463
      case MATRIX     : return mM.abortAll(true);
464
      case VERTEX     : return mV.abortAll(true);
465
      case FRAGMENT   : return mF.abortAll(true);
466
      case POSTPROCESS: return mP.abortAll(true);
467
      default         : return 0;
468
      }
469
    }
470
    
471
///////////////////////////////////////////////////////////////////////////////////////////////////
472
/**
473
 * Aborts a single Effect.
474
 * 
475
 * @param id ID of the Effect we want to abort.
476
 * @return number of Effects aborted. Always either 0 or 1.
477
 */
478
  public int abortEffect(long id)
479
    {
480
    int type = (int)(id&EffectTypes.MASK);
481

    
482
    if( type==EffectTypes.MATRIX.type      ) return mM.removeByID(id>>EffectTypes.LENGTH);
483
    if( type==EffectTypes.VERTEX.type      ) return mV.removeByID(id>>EffectTypes.LENGTH);
484
    if( type==EffectTypes.FRAGMENT.type    ) return mF.removeByID(id>>EffectTypes.LENGTH);
485
    if( type==EffectTypes.POSTPROCESS.type ) return mP.removeByID(id>>EffectTypes.LENGTH);
486

    
487
    return 0;
488
    }
489

    
490
///////////////////////////////////////////////////////////////////////////////////////////////////
491
/**
492
 * Abort all Effects of a given name, for example all rotations.
493
 * 
494
 * @param name one of the constants defined in {@link EffectNames}
495
 * @return number of Effects aborted.
496
 */
497
  public int abortEffects(EffectNames name)
498
    {
499
    switch(name.getType())
500
      {
501
      case MATRIX     : return mM.removeByType(name);
502
      case VERTEX     : return mV.removeByType(name);
503
      case FRAGMENT   : return mF.removeByType(name);
504
      case POSTPROCESS: return mP.removeByType(name);
505
      default         : return 0;
506
      }
507
    }
508
    
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510
/**
511
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
512
 * 
513
 * @param id Effect ID we want to print info about
514
 * @return <code>true</code> if a single Effect of type effectType has been found.
515
 */
516
    
517
  public boolean printEffect(long id)
518
    {
519
    int type = (int)(id&EffectTypes.MASK);
520

    
521
    if( type==EffectTypes.MATRIX.type      )  return mM.printByID(id>>EffectTypes.LENGTH);
522
    if( type==EffectTypes.VERTEX.type      )  return mV.printByID(id>>EffectTypes.LENGTH);
523
    if( type==EffectTypes.FRAGMENT.type    )  return mF.printByID(id>>EffectTypes.LENGTH);
524
    if( type==EffectTypes.POSTPROCESS.type )  return mP.printByID(id>>EffectTypes.LENGTH);
525

    
526
    return false;
527
    }
528

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

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

    
555
///////////////////////////////////////////////////////////////////////////////////////////////////
556
/**
557
 * Returns the maximum number of Vertex effects.
558
 *
559
 * @return The maximum number of Vertex effects
560
 */
561
  public static int getMaxVertex()
562
    {
563
    return EffectQueue.getMax(EffectTypes.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
  public static int getMaxFragment()
573
    {
574
    return EffectQueue.getMax(EffectTypes.FRAGMENT.ordinal());
575
    }
576

    
577
///////////////////////////////////////////////////////////////////////////////////////////////////
578
/**
579
 * Returns the maximum number of Postprocess effects.
580
 *
581
 * @return The maximum number of Postprocess effects
582
 */
583
  public static int getMaxPostprocess()
584
    {
585
    return EffectQueue.getMax(EffectTypes.POSTPROCESS.ordinal());
586
    }
587

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

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

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

    
651
///////////////////////////////////////////////////////////////////////////////////////////////////
652
/**
653
 * Sets the maximum number of Postprocess effects that can be stored in a single EffectQueue at one time.
654
 * This can fail if:
655
 * <ul>
656
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
657
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
658
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
659
 *     time only decreasing the value of 'max' is permitted.
660
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
661
 * </ul>
662
 *
663
 * @param max new maximum number of simultaneous Postprocess Effects. Has to be a non-negative number not greater
664
 *            than Byte.MAX_VALUE
665
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
666
 */
667
  public static boolean setMaxPostprocess(int max)
668
    {
669
    return EffectQueue.setMax(EffectTypes.POSTPROCESS.ordinal(),max);
670
    }
671

    
672
///////////////////////////////////////////////////////////////////////////////////////////////////   
673
///////////////////////////////////////////////////////////////////////////////////////////////////
674
// Individual effect functions.
675
///////////////////////////////////////////////////////////////////////////////////////////////////
676
// Matrix-based effects
677
///////////////////////////////////////////////////////////////////////////////////////////////////
678
/**
679
 * Moves the Object by a (possibly changing in time) vector.
680
 * 
681
 * @param vector 3-dimensional Data which at any given time will return a Static3D
682
 *               representing the current coordinates of the vector we want to move the Object with.
683
 * @return       ID of the effect added, or -1 if we failed to add one.
684
 */
685
  public long move(Data3D vector)
686
    {   
687
    return mM.add(EffectNames.MOVE,vector);
688
    }
689

    
690
///////////////////////////////////////////////////////////////////////////////////////////////////
691
/**
692
 * Scales the Object by (possibly changing in time) 3D scale factors.
693
 * 
694
 * @param scale 3-dimensional Data which at any given time returns a Static3D
695
 *              representing the current x- , y- and z- scale factors.
696
 * @return      ID of the effect added, or -1 if we failed to add one.
697
 */
698
  public long scale(Data3D scale)
699
    {   
700
    return mM.add(EffectNames.SCALE,scale);
701
    }
702

    
703
///////////////////////////////////////////////////////////////////////////////////////////////////
704
/**
705
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
706
 *
707
 * @param scale The factor to scale all 3 dimensions with.
708
 * @return      ID of the effect added, or -1 if we failed to add one.
709
 */
710
  public long scale(float scale)
711
    {
712
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
713
    }
714

    
715
///////////////////////////////////////////////////////////////////////////////////////////////////
716
/**
717
 * Rotates the Object by 'angle' degrees around the center.
718
 * Static axis of rotation is given by the last parameter.
719
 *
720
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
721
 * @param axis   Axis of rotation
722
 * @param center Coordinates of the Point we are rotating around.
723
 * @return       ID of the effect added, or -1 if we failed to add one.
724
 */
725
  public long rotate(Data1D angle, Static3D axis, Data3D center )
726
    {   
727
    return mM.add(EffectNames.ROTATE, angle, axis, center);
728
    }
729

    
730
///////////////////////////////////////////////////////////////////////////////////////////////////
731
/**
732
 * Rotates the Object by 'angle' degrees around the center.
733
 * Here both angle and axis can dynamically change.
734
 *
735
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
736
 * @param center    Coordinates of the Point we are rotating around.
737
 * @return          ID of the effect added, or -1 if we failed to add one.
738
 */
739
  public long rotate(Data4D angleaxis, Data3D center)
740
    {
741
    return mM.add(EffectNames.ROTATE, angleaxis, center);
742
    }
743

    
744
///////////////////////////////////////////////////////////////////////////////////////////////////
745
/**
746
 * Rotates the Object by quaternion.
747
 *
748
 * @param quaternion The quaternion describing the rotation.
749
 * @param center     Coordinates of the Point we are rotating around.
750
 * @return           ID of the effect added, or -1 if we failed to add one.
751
 */
752
  public long quaternion(Data4D quaternion, Data3D center )
753
    {
754
    return mM.add(EffectNames.QUATERNION,quaternion,center);
755
    }
756

    
757
///////////////////////////////////////////////////////////////////////////////////////////////////
758
/**
759
 * Shears the Object.
760
 *
761
 * @param shear   The 3-tuple of shear factors. The first controls level
762
 *                of shearing in the X-axis, second - Y-axis and the third -
763
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
764
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
765
 * @param center  Center of shearing, i.e. the point which stays unmoved.
766
 * @return        ID of the effect added, or -1 if we failed to add one.
767
 */
768
  public long shear(Data3D shear, Data3D center)
769
    {
770
    return mM.add(EffectNames.SHEAR, shear, center);
771
    }
772

    
773
///////////////////////////////////////////////////////////////////////////////////////////////////
774
// Fragment-based effects  
775
///////////////////////////////////////////////////////////////////////////////////////////////////
776
/**
777
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
778
 *        
779
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
780
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
781
 *               Valid range: <0,1>
782
 * @param color  Color to mix. (1,0,0) is RED.
783
 * @param region Region this Effect is limited to.
784
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
785
 * @return       ID of the effect added, or -1 if we failed to add one.
786
 */
787
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
788
    {
789
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
790
    }
791

    
792
///////////////////////////////////////////////////////////////////////////////////////////////////
793
/**
794
 * Makes the whole Object smoothly change all three of its RGB components.
795
 *
796
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
797
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
798
 *               Valid range: <0,1>
799
 * @param color  Color to mix. (1,0,0) is RED.
800
 * @return       ID of the effect added, or -1 if we failed to add one.
801
 */
802
  public long chroma(Data1D blend, Data3D color)
803
    {
804
    return mF.add(EffectNames.CHROMA, blend, color);
805
    }
806

    
807
///////////////////////////////////////////////////////////////////////////////////////////////////
808
/**
809
 * Makes a certain sub-region of the Object smoothly change its transparency level.
810
 *        
811
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
812
 *               moment: pixel.a *= alpha.
813
 *               Valid range: <0,1>
814
 * @param region Region this Effect is limited to. 
815
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
816
 * @return       ID of the effect added, or -1 if we failed to add one. 
817
 */
818
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
819
    {
820
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
821
    }
822

    
823
///////////////////////////////////////////////////////////////////////////////////////////////////
824
/**
825
 * Makes the whole Object smoothly change its transparency level.
826
 *
827
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
828
 *               given moment: pixel.a *= alpha.
829
 *               Valid range: <0,1>
830
 * @return       ID of the effect added, or -1 if we failed to add one.
831
 */
832
  public long alpha(Data1D alpha)
833
    {
834
    return mF.add(EffectNames.ALPHA, alpha);
835
    }
836

    
837
///////////////////////////////////////////////////////////////////////////////////////////////////
838
/**
839
 * Makes a certain sub-region of the Object smoothly change its brightness level.
840
 *        
841
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
842
 *                   at any given moment. Valid range: <0,infinity)
843
 * @param region     Region this Effect is limited to.
844
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
845
 * @return           ID of the effect added, or -1 if we failed to add one.
846
 */
847
  public long brightness(Data1D brightness, Data4D region, boolean smooth)
848
    {
849
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
850
    }
851

    
852
///////////////////////////////////////////////////////////////////////////////////////////////////
853
/**
854
 * Makes the whole Object smoothly change its brightness level.
855
 *
856
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
857
 *                   at any given moment. Valid range: <0,infinity)
858
 * @return           ID of the effect added, or -1 if we failed to add one.
859
 */
860
  public long brightness(Data1D brightness)
861
    {
862
    return mF.add(EffectNames.BRIGHTNESS, brightness);
863
    }
864

    
865
///////////////////////////////////////////////////////////////////////////////////////////////////
866
/**
867
 * Makes a certain sub-region of the Object smoothly change its contrast level.
868
 *        
869
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
870
 *                 at any given moment. Valid range: <0,infinity)
871
 * @param region   Region this Effect is limited to.
872
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
873
 * @return         ID of the effect added, or -1 if we failed to add one.
874
 */
875
  public long contrast(Data1D contrast, Data4D region, boolean smooth)
876
    {
877
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
878
    }
879

    
880
///////////////////////////////////////////////////////////////////////////////////////////////////
881
/**
882
 * Makes the whole Object smoothly change its contrast level.
883
 *
884
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
885
 *                 at any given moment. Valid range: <0,infinity)
886
 * @return         ID of the effect added, or -1 if we failed to add one.
887
 */
888
  public long contrast(Data1D contrast)
889
    {
890
    return mF.add(EffectNames.CONTRAST, contrast);
891
    }
892

    
893
///////////////////////////////////////////////////////////////////////////////////////////////////
894
/**
895
 * Makes a certain sub-region of the Object smoothly change its saturation level.
896
 *        
897
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
898
 *                   at any given moment. Valid range: <0,infinity)
899
 * @param region     Region this Effect is limited to.
900
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
901
 * @return           ID of the effect added, or -1 if we failed to add one.
902
 */
903
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
904
    {
905
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
906
    }
907

    
908
///////////////////////////////////////////////////////////////////////////////////////////////////
909
/**
910
 * Makes the whole Object smoothly change its saturation level.
911
 *
912
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
913
 *                   at any given moment. Valid range: <0,infinity)
914
 * @return           ID of the effect added, or -1 if we failed to add one.
915
 */
916
  public long saturation(Data1D saturation)
917
    {
918
    return mF.add(EffectNames.SATURATION, saturation);
919
    }
920

    
921
///////////////////////////////////////////////////////////////////////////////////////////////////
922
// Vertex-based effects  
923
///////////////////////////////////////////////////////////////////////////////////////////////////
924
/**
925
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
926
 *
927
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
928
 *               currently being dragged with.
929
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
930
 * @param region Region that masks the Effect.
931
 * @return       ID of the effect added, or -1 if we failed to add one.
932
 */
933
  public long distort(Data3D vector, Data3D center, Data4D region)
934
    {  
935
    return mV.add(EffectNames.DISTORT, vector, center, region);
936
    }
937

    
938
///////////////////////////////////////////////////////////////////////////////////////////////////
939
/**
940
 * Distort the whole Object by a (possibly changing in time) vector of force.
941
 *
942
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
943
 *               currently being dragged with.
944
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
945
 * @return       ID of the effect added, or -1 if we failed to add one.
946
 */
947
  public long distort(Data3D vector, Data3D center)
948
    {
949
    return mV.add(EffectNames.DISTORT, vector, center, null);
950
    }
951

    
952
///////////////////////////////////////////////////////////////////////////////////////////////////
953
/**
954
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
955
 * a (possibly changing in time) point on the Object.
956
 *
957
 * @param vector Vector of force that deforms the shape of the whole Object.
958
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
959
 * @param region Region that masks the Effect.
960
 * @return       ID of the effect added, or -1 if we failed to add one.
961
 */
962
  public long deform(Data3D vector, Data3D center, Data4D region)
963
    {
964
    return mV.add(EffectNames.DEFORM, vector, center, region);
965
    }
966

    
967
///////////////////////////////////////////////////////////////////////////////////////////////////
968
/**
969
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
970
 * a (possibly changing in time) point on the Object.
971
 *     
972
 * @param vector Vector of force that deforms the shape of the whole Object.
973
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
974
 * @return       ID of the effect added, or -1 if we failed to add one.
975
 */
976
  public long deform(Data3D vector, Data3D center)
977
    {  
978
    return mV.add(EffectNames.DEFORM, vector, center, null);
979
    }
980

    
981
///////////////////////////////////////////////////////////////////////////////////////////////////  
982
/**
983
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
984
 * away from the center (degree<=1)
985
 *
986
 * @param sink   The current degree of the Effect.
987
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
988
 * @param region Region that masks the Effect.
989
 * @return       ID of the effect added, or -1 if we failed to add one.
990
 */
991
  public long sink(Data1D sink, Data3D center, Data4D region)
992
    {
993
    return mV.add(EffectNames.SINK, sink, center, region);
994
    }
995

    
996
///////////////////////////////////////////////////////////////////////////////////////////////////
997
/**
998
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
999
 * away from the center (degree<=1)
1000
 *
1001
 * @param sink   The current degree of the Effect.
1002
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1003
 * @return       ID of the effect added, or -1 if we failed to add one.
1004
 */
1005
  public long sink(Data1D sink, Data3D center)
1006
    {
1007
    return mV.add(EffectNames.SINK, sink, center);
1008
    }
1009

    
1010
///////////////////////////////////////////////////////////////////////////////////////////////////
1011
/**
1012
 * Pull all points around the center of the Effect towards a line passing through the center
1013
 * (that's if degree>=1) or push them away from the line (degree<=1)
1014
 *
1015
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
1016
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1017
 * @param region Region that masks the Effect.
1018
 * @return       ID of the effect added, or -1 if we failed to add one.
1019
 */
1020
  public long pinch(Data2D pinch, Data3D center, Data4D region)
1021
    {
1022
    return mV.add(EffectNames.PINCH, pinch, center, region);
1023
    }
1024

    
1025
///////////////////////////////////////////////////////////////////////////////////////////////////
1026
/**
1027
 * Pull all points around the center of the Effect towards a line passing through the center
1028
 * (that's if degree>=1) or push them away from the line (degree<=1)
1029
 *
1030
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
1031
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1032
 * @return       ID of the effect added, or -1 if we failed to add one.
1033
 */
1034
  public long pinch(Data2D pinch, Data3D center)
1035
    {
1036
    return mV.add(EffectNames.PINCH, pinch, center);
1037
    }
1038

    
1039
///////////////////////////////////////////////////////////////////////////////////////////////////  
1040
/**
1041
 * Rotate part of the Object around the Center of the Effect by a certain angle.
1042
 *
1043
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
1044
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1045
 * @param region Region that masks the Effect.
1046
 * @return       ID of the effect added, or -1 if we failed to add one.
1047
 */
1048
  public long swirl(Data1D swirl, Data3D center, Data4D region)
1049
    {    
1050
    return mV.add(EffectNames.SWIRL, swirl, center, region);
1051
    }
1052

    
1053
///////////////////////////////////////////////////////////////////////////////////////////////////
1054
/**
1055
 * Rotate the whole Object around the Center of the Effect by a certain angle.
1056
 *
1057
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
1058
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1059
 * @return       ID of the effect added, or -1 if we failed to add one.
1060
 */
1061
  public long swirl(Data1D swirl, Data3D center)
1062
    {
1063
    return mV.add(EffectNames.SWIRL, swirl, center);
1064
    }
1065

    
1066
///////////////////////////////////////////////////////////////////////////////////////////////////
1067
/**
1068
 * Directional, sinusoidal wave effect.
1069
 *
1070
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
1071
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
1072
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
1073
 *               describe the 'direction' of the wave.
1074
 *               <p>
1075
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
1076
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
1077
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
1078
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
1079
 *               <p>
1080
 *               <p>
1081
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
1082
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
1083
 *               will be sine shapes.
1084
 *               <p>
1085
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
1086
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
1087
 *               YZ-plane with be sine shapes.
1088
 *               <p>
1089
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
1090
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
1091
 *               value if sin at this point.
1092
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1093
 * @return       ID of the effect added, or -1 if we failed to add one.
1094
 */
1095
  public long wave(Data5D wave, Data3D center)
1096
    {
1097
    return mV.add(EffectNames.WAVE, wave, center, null);
1098
    }
1099

    
1100
///////////////////////////////////////////////////////////////////////////////////////////////////
1101
/**
1102
 * Directional, sinusoidal wave effect.
1103
 *
1104
 * @param wave   see {@link DistortedEffects#wave(Data5D,Data3D)}
1105
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1106
 * @param region Region that masks the Effect.
1107
 * @return       ID of the effect added, or -1 if we failed to add one.
1108
 */
1109
  public long wave(Data5D wave, Data3D center, Data4D region)
1110
    {
1111
    return mV.add(EffectNames.WAVE, wave, center, region);
1112
    }
1113

    
1114
///////////////////////////////////////////////////////////////////////////////////////////////////
1115
// Postprocess-based effects
1116
///////////////////////////////////////////////////////////////////////////////////////////////////
1117
/**
1118
 * Blur the object.
1119
 *
1120
 * @param radius The 'strength' if the effect, in pixels. 0 = no blur, 10 = when blurring a given pixel,
1121
 *               take into account 10 pixels in each direction.
1122
 * @return ID of the effect added, or -1 if we failed to add one.
1123
 */
1124
  public long blur(Data1D radius)
1125
    {
1126
    return mP.add(EffectNames.BLUR, radius);
1127
    }
1128
  }
(4-4/23)