Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffects.java @ 02de77c9

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.opengl.GLES20;
23

    
24
import org.distorted.library.message.EffectListener;
25
import org.distorted.library.type.Data1D;
26
import org.distorted.library.type.Data2D;
27
import org.distorted.library.type.Data3D;
28
import org.distorted.library.type.Data4D;
29
import org.distorted.library.type.Data5D;
30
import org.distorted.library.type.Static3D;
31

    
32
import java.nio.ByteBuffer;
33
import java.nio.ByteOrder;
34
import java.nio.FloatBuffer;
35

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37
/**
38
 * Class containing {@link EffectTypes#LENGTH} queues, each a class derived from EffectQueue.
39
 * <p>
40
 * The queues hold actual effects to be applied to a given (DistortedTexture,MeshObject) combo.
41
 */
42
public class DistortedEffects
43
  {
44
  private static final int BYTES_PER_FLOAT   = 4; //
45
  private static final int POSITION_DATA_SIZE= 2; // Size of the position data in elements
46
  private static final int TEX_DATA_SIZE     = 2; // Size of the texture coordinate data in elements.
47
  private static final FloatBuffer mQuadPositions, mQuadTexture;
48

    
49
  private static long mNextID =0;
50
  private long mID;
51

    
52
  private static DistortedFramebuffer mBufferFBO;
53

    
54
  private EffectQueueMatrix      mM;
55
  private EffectQueueFragment    mF;
56
  private EffectQueueVertex      mV;
57
  private EffectQueuePostprocess mP;
58

    
59
  private boolean matrixCloned, vertexCloned, fragmentCloned, postprocessCloned;
60

    
61
  static
62
    {
63
    int dataLength = 4;
64

    
65
    float[] positionData= { -0.5f, -0.5f,  -0.5f, 0.5f,  0.5f,-0.5f,  0.5f, 0.5f };
66
    float[] textureData = {  0.0f,  0.0f,   0.0f, 1.0f,  1.0f, 0.0f,  1.0f, 1.0f };
67

    
68
    mQuadPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
69
    mQuadPositions.put(positionData).position(0);
70
    mQuadTexture   = ByteBuffer.allocateDirect(TEX_DATA_SIZE     *dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
71
    mQuadTexture.put(textureData).position(0);
72

    
73
    mBufferFBO = new DistortedFramebuffer(1,1);
74
    }
75

    
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77
    
78
  private void initializeEffectLists(DistortedEffects d, int flags)
79
    {
80
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
81
      {
82
      mM = d.mM;
83
      matrixCloned = true;
84
      }
85
    else
86
      {
87
      mM = new EffectQueueMatrix(mID);
88
      matrixCloned = false;
89
      }
90
    
91
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
92
      {
93
      mV = d.mV;
94
      vertexCloned = true;
95
      }
96
    else
97
      {
98
      mV = new EffectQueueVertex(mID);
99
      vertexCloned = false;
100
      }
101
    
102
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
103
      {
104
      mF = d.mF;
105
      fragmentCloned = true;
106
      }
107
    else
108
      {
109
      mF = new EffectQueueFragment(mID);
110
      fragmentCloned = false;
111
      }
112

    
113
    if( (flags & Distorted.CLONE_POSTPROCESS) != 0 )
114
      {
115
      mP = d.mP;
116
      postprocessCloned = true;
117
      }
118
    else
119
      {
120
      mP = new EffectQueuePostprocess(mID);
121
      postprocessCloned = false;
122
      }
123
    }
124

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126
   
127
  void drawPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df, long currTime)
128
    {
129
    mM.compute(currTime);
130
    mV.compute(currTime);
131
    mF.compute(currTime);
132
    mP.compute(currTime);
133

    
134
    float halfZ = halfInputW*mesh.zFactor;
135

    
136
    if( mP.mNumEffects==0 )
137
      {
138
      Distorted.mMainProgram.useProgram();
139
      GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
140

    
141
      mM.send(df,halfInputW,halfInputH,halfZ);
142
      mV.send(halfInputW,halfInputH,halfZ);
143
      mF.send(halfInputW,halfInputH);
144

    
145
      mesh.draw();
146
      }
147
    else
148
      {
149
      if( mV.mNumEffects>0 || mF.mNumEffects>0 )
150
        {
151
        Distorted.mMainProgram.useProgram();
152
        GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
153

    
154
        mBufferFBO.resizeFast(df.mWidth, df.mHeight);
155
        mBufferFBO.setAsOutput();
156

    
157
        mM.send(mBufferFBO,halfInputW,halfInputH,halfZ);
158
        mV.send(halfInputW,halfInputH,halfZ);
159
        mF.send(halfInputW,halfInputH);
160

    
161
        mesh.draw();
162

    
163
        Distorted.mPostProgram.useProgram();
164
        mBufferFBO.setAsInput();
165
        df.setAsOutput();
166
        mP.send(df);
167

    
168
        GLES20.glVertexAttribPointer(Distorted.mPostProgram.mAttribute[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mQuadPositions);
169
        GLES20.glVertexAttribPointer(Distorted.mPostProgram.mAttribute[1], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mQuadTexture);
170
        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
171
        }
172
      else
173
        {
174
        Distorted.mPostProgram.useProgram();
175
        GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
176

    
177
        mM.constructMatrices(df,halfInputW,halfInputH);
178
        mP.send(2*halfInputW,2*halfInputH, mM.getMVP() );
179

    
180
        GLES20.glVertexAttribPointer(Distorted.mPostProgram.mAttribute[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mQuadPositions);
181
        GLES20.glVertexAttribPointer(Distorted.mPostProgram.mAttribute[1], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mQuadTexture);
182
        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
183
        }
184
      }
185
    }
186

    
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188
   
189
  static void drawNoEffectsPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df)
190
    {
191
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
192

    
193
    EffectQueueMatrix.sendZero(df,halfInputW,halfInputH,halfInputW*mesh.zFactor);
194
    EffectQueueVertex.sendZero();
195
    EffectQueueFragment.sendZero();
196
    EffectQueuePostprocess.sendZero(df);
197

    
198
    mesh.draw();
199
    }
200
    
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202
   
203
  private void releasePriv()
204
    {
205
    if( !matrixCloned     ) mM.abortAll(false);
206
    if( !vertexCloned     ) mV.abortAll(false);
207
    if( !fragmentCloned   ) mF.abortAll(false);
208
    if( !postprocessCloned) mP.abortAll(false);
209

    
210
    mM = null;
211
    mV = null;
212
    mF = null;
213
    mP = null;
214
    }
215

    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

    
218
  static void onDestroy()
219
    {
220
    mNextID = 0;
221
    }
222

    
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224
// PUBLIC API
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226
/**
227
 * Create empty effect queue.
228
 */
229
  public DistortedEffects()
230
    {
231
    mID = mNextID++;
232
    initializeEffectLists(this,0);
233
    }
234

    
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236
/**
237
 * Copy constructor.
238
 * <p>
239
 * Whatever we do not clone gets created just like in the default constructor.
240
 *
241
 * @param dc    Source object to create our object from
242
 * @param flags A bitmask of values specifying what to copy.
243
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
244
 */
245
  public DistortedEffects(DistortedEffects dc, int flags)
246
    {
247
    mID = mNextID++;
248
    initializeEffectLists(dc,flags);
249
    }
250

    
251
///////////////////////////////////////////////////////////////////////////////////////////////////
252
/**
253
 * Releases all resources. After this call, the queue should not be used anymore.
254
 */
255
  public synchronized void delete()
256
    {
257
    releasePriv();
258
    }
259

    
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261
/**
262
 * Returns unique ID of this instance.
263
 *
264
 * @return ID of the object.
265
 */
266
  public long getID()
267
      {
268
      return mID;
269
      }
270

    
271
///////////////////////////////////////////////////////////////////////////////////////////////////
272
/**
273
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
274
 * to one of the Effects in those queues. Nothing will happen if 'el' is already in the list.
275
 * 
276
 * @param el A class implementing the EffectListener interface that wants to get notifications.
277
 */
278
  public void registerForMessages(EffectListener el)
279
    {
280
    mV.registerForMessages(el);
281
    mF.registerForMessages(el);
282
    mM.registerForMessages(el);
283
    mP.registerForMessages(el);
284
    }
285

    
286
///////////////////////////////////////////////////////////////////////////////////////////////////
287
/**
288
 * Removes the calling class from the list of Listeners.
289
 * 
290
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
291
 */
292
  public void deregisterForMessages(EffectListener el)
293
    {
294
    mV.deregisterForMessages(el);
295
    mF.deregisterForMessages(el);
296
    mM.deregisterForMessages(el);
297
    mP.deregisterForMessages(el);
298
    }
299

    
300
///////////////////////////////////////////////////////////////////////////////////////////////////
301
/**
302
 * Aborts all Effects.
303
 * @return Number of effects aborted.
304
 */
305
  public int abortAllEffects()
306
      {
307
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true) + mP.abortAll(true);
308
      }
309

    
310
///////////////////////////////////////////////////////////////////////////////////////////////////
311
/**
312
 * Aborts all Effects of a given type, for example all MATRIX Effects.
313
 * 
314
 * @param type one of the constants defined in {@link EffectTypes}
315
 * @return Number of effects aborted.
316
 */
317
  public int abortEffects(EffectTypes type)
318
    {
319
    switch(type)
320
      {
321
      case MATRIX     : return mM.abortAll(true);
322
      case VERTEX     : return mV.abortAll(true);
323
      case FRAGMENT   : return mF.abortAll(true);
324
      case POSTPROCESS: return mP.abortAll(true);
325
      default         : return 0;
326
      }
327
    }
328
    
329
///////////////////////////////////////////////////////////////////////////////////////////////////
330
/**
331
 * Aborts a single Effect.
332
 * 
333
 * @param id ID of the Effect we want to abort.
334
 * @return number of Effects aborted. Always either 0 or 1.
335
 */
336
  public int abortEffect(long id)
337
    {
338
    int type = (int)(id&EffectTypes.MASK);
339

    
340
    if( type==EffectTypes.MATRIX.type      ) return mM.removeByID(id>>EffectTypes.LENGTH);
341
    if( type==EffectTypes.VERTEX.type      ) return mV.removeByID(id>>EffectTypes.LENGTH);
342
    if( type==EffectTypes.FRAGMENT.type    ) return mF.removeByID(id>>EffectTypes.LENGTH);
343
    if( type==EffectTypes.POSTPROCESS.type ) return mP.removeByID(id>>EffectTypes.LENGTH);
344

    
345
    return 0;
346
    }
347

    
348
///////////////////////////////////////////////////////////////////////////////////////////////////
349
/**
350
 * Abort all Effects of a given name, for example all rotations.
351
 * 
352
 * @param name one of the constants defined in {@link EffectNames}
353
 * @return number of Effects aborted.
354
 */
355
  public int abortEffects(EffectNames name)
356
    {
357
    switch(name.getType())
358
      {
359
      case MATRIX     : return mM.removeByType(name);
360
      case VERTEX     : return mV.removeByType(name);
361
      case FRAGMENT   : return mF.removeByType(name);
362
      case POSTPROCESS: return mP.removeByType(name);
363
      default         : return 0;
364
      }
365
    }
366
    
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368
/**
369
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
370
 * 
371
 * @param id Effect ID we want to print info about
372
 * @return <code>true</code> if a single Effect of type effectType has been found.
373
 */
374
    
375
  public boolean printEffect(long id)
376
    {
377
    int type = (int)(id&EffectTypes.MASK);
378

    
379
    if( type==EffectTypes.MATRIX.type      )  return mM.printByID(id>>EffectTypes.LENGTH);
380
    if( type==EffectTypes.VERTEX.type      )  return mV.printByID(id>>EffectTypes.LENGTH);
381
    if( type==EffectTypes.FRAGMENT.type    )  return mF.printByID(id>>EffectTypes.LENGTH);
382
    if( type==EffectTypes.POSTPROCESS.type )  return mP.printByID(id>>EffectTypes.LENGTH);
383

    
384
    return false;
385
    }
386

    
387
///////////////////////////////////////////////////////////////////////////////////////////////////
388
/**
389
 * Returns the maximum number of Matrix effects.
390
 *
391
 * @return The maximum number of Matrix effects
392
 */
393
  public static int getMaxMatrix()
394
    {
395
    return EffectQueue.getMax(EffectTypes.MATRIX.ordinal());
396
    }
397

    
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399
/**
400
 * Returns the maximum number of Vertex effects.
401
 *
402
 * @return The maximum number of Vertex effects
403
 */
404
  public static int getMaxVertex()
405
    {
406
    return EffectQueue.getMax(EffectTypes.VERTEX.ordinal());
407
    }
408

    
409
///////////////////////////////////////////////////////////////////////////////////////////////////
410
/**
411
 * Returns the maximum number of Fragment effects.
412
 *
413
 * @return The maximum number of Fragment effects
414
 */
415
  public static int getMaxFragment()
416
    {
417
    return EffectQueue.getMax(EffectTypes.FRAGMENT.ordinal());
418
    }
419

    
420
///////////////////////////////////////////////////////////////////////////////////////////////////
421
/**
422
 * Returns the maximum number of Postprocess effects.
423
 *
424
 * @return The maximum number of Postprocess effects
425
 */
426
  public static int getMaxPostprocess()
427
    {
428
    return EffectQueue.getMax(EffectTypes.POSTPROCESS.ordinal());
429
    }
430

    
431
///////////////////////////////////////////////////////////////////////////////////////////////////
432
/**
433
 * Sets the maximum number of Matrix effects that can be stored in a single EffectQueue at one time.
434
 * This can fail if:
435
 * <ul>
436
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
437
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
438
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
439
 *     time only decreasing the value of 'max' is permitted.
440
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
441
 * </ul>
442
 *
443
 * @param max new maximum number of simultaneous Matrix Effects. Has to be a non-negative number not greater
444
 *            than Byte.MAX_VALUE
445
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
446
 */
447
  public static boolean setMaxMatrix(int max)
448
    {
449
    return EffectQueue.setMax(EffectTypes.MATRIX.ordinal(),max);
450
    }
451

    
452
///////////////////////////////////////////////////////////////////////////////////////////////////
453
/**
454
 * Sets the maximum number of Vertex effects that can be stored in a single EffectQueue at one time.
455
 * This can fail if:
456
 * <ul>
457
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
458
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
459
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
460
 *     time only decreasing the value of 'max' is permitted.
461
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
462
 * </ul>
463
 *
464
 * @param max new maximum number of simultaneous Vertex Effects. Has to be a non-negative number not greater
465
 *            than Byte.MAX_VALUE
466
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
467
 */
468
  public static boolean setMaxVertex(int max)
469
    {
470
    return EffectQueue.setMax(EffectTypes.VERTEX.ordinal(),max);
471
    }
472

    
473
///////////////////////////////////////////////////////////////////////////////////////////////////
474
/**
475
 * Sets the maximum number of Fragment effects that can be stored in a single EffectQueue at one time.
476
 * This can fail if:
477
 * <ul>
478
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
479
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
480
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
481
 *     time only decreasing the value of 'max' is permitted.
482
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
483
 * </ul>
484
 *
485
 * @param max new maximum number of simultaneous Fragment Effects. Has to be a non-negative number not greater
486
 *            than Byte.MAX_VALUE
487
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
488
 */
489
  public static boolean setMaxFragment(int max)
490
    {
491
    return EffectQueue.setMax(EffectTypes.FRAGMENT.ordinal(),max);
492
    }
493

    
494
///////////////////////////////////////////////////////////////////////////////////////////////////
495
/**
496
 * Sets the maximum number of Postprocess effects that can be stored in a single EffectQueue at one time.
497
 * This can fail if:
498
 * <ul>
499
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
500
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
501
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
502
 *     time only decreasing the value of 'max' is permitted.
503
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
504
 * </ul>
505
 *
506
 * @param max new maximum number of simultaneous Postprocess Effects. Has to be a non-negative number not greater
507
 *            than Byte.MAX_VALUE
508
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
509
 */
510
  public static boolean setMaxPostprocess(int max)
511
    {
512
    return EffectQueue.setMax(EffectTypes.POSTPROCESS.ordinal(),max);
513
    }
514

    
515
///////////////////////////////////////////////////////////////////////////////////////////////////   
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517
// Individual effect functions.
518
///////////////////////////////////////////////////////////////////////////////////////////////////
519
// Matrix-based effects
520
///////////////////////////////////////////////////////////////////////////////////////////////////
521
/**
522
 * Moves the Object by a (possibly changing in time) vector.
523
 * 
524
 * @param vector 3-dimensional Data which at any given time will return a Static3D
525
 *               representing the current coordinates of the vector we want to move the Object with.
526
 * @return       ID of the effect added, or -1 if we failed to add one.
527
 */
528
  public long move(Data3D vector)
529
    {   
530
    return mM.add(EffectNames.MOVE,vector);
531
    }
532

    
533
///////////////////////////////////////////////////////////////////////////////////////////////////
534
/**
535
 * Scales the Object by (possibly changing in time) 3D scale factors.
536
 * 
537
 * @param scale 3-dimensional Data which at any given time returns a Static3D
538
 *              representing the current x- , y- and z- scale factors.
539
 * @return      ID of the effect added, or -1 if we failed to add one.
540
 */
541
  public long scale(Data3D scale)
542
    {   
543
    return mM.add(EffectNames.SCALE,scale);
544
    }
545

    
546
///////////////////////////////////////////////////////////////////////////////////////////////////
547
/**
548
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
549
 *
550
 * @param scale The factor to scale all 3 dimensions with.
551
 * @return      ID of the effect added, or -1 if we failed to add one.
552
 */
553
  public long scale(float scale)
554
    {
555
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
556
    }
557

    
558
///////////////////////////////////////////////////////////////////////////////////////////////////
559
/**
560
 * Rotates the Object by 'angle' degrees around the center.
561
 * Static axis of rotation is given by the last parameter.
562
 *
563
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
564
 * @param axis   Axis of rotation
565
 * @param center Coordinates of the Point we are rotating around.
566
 * @return       ID of the effect added, or -1 if we failed to add one.
567
 */
568
  public long rotate(Data1D angle, Static3D axis, Data3D center )
569
    {   
570
    return mM.add(EffectNames.ROTATE, angle, axis, center);
571
    }
572

    
573
///////////////////////////////////////////////////////////////////////////////////////////////////
574
/**
575
 * Rotates the Object by 'angle' degrees around the center.
576
 * Here both angle and axis can dynamically change.
577
 *
578
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
579
 * @param center    Coordinates of the Point we are rotating around.
580
 * @return          ID of the effect added, or -1 if we failed to add one.
581
 */
582
  public long rotate(Data4D angleaxis, Data3D center)
583
    {
584
    return mM.add(EffectNames.ROTATE, angleaxis, center);
585
    }
586

    
587
///////////////////////////////////////////////////////////////////////////////////////////////////
588
/**
589
 * Rotates the Object by quaternion.
590
 *
591
 * @param quaternion The quaternion describing the rotation.
592
 * @param center     Coordinates of the Point we are rotating around.
593
 * @return           ID of the effect added, or -1 if we failed to add one.
594
 */
595
  public long quaternion(Data4D quaternion, Data3D center )
596
    {
597
    return mM.add(EffectNames.QUATERNION,quaternion,center);
598
    }
599

    
600
///////////////////////////////////////////////////////////////////////////////////////////////////
601
/**
602
 * Shears the Object.
603
 *
604
 * @param shear   The 3-tuple of shear factors. The first controls level
605
 *                of shearing in the X-axis, second - Y-axis and the third -
606
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
607
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
608
 * @param center  Center of shearing, i.e. the point which stays unmoved.
609
 * @return        ID of the effect added, or -1 if we failed to add one.
610
 */
611
  public long shear(Data3D shear, Data3D center)
612
    {
613
    return mM.add(EffectNames.SHEAR, shear, center);
614
    }
615

    
616
///////////////////////////////////////////////////////////////////////////////////////////////////
617
// Fragment-based effects  
618
///////////////////////////////////////////////////////////////////////////////////////////////////
619
/**
620
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
621
 *        
622
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
623
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
624
 *               Valid range: <0,1>
625
 * @param color  Color to mix. (1,0,0) is RED.
626
 * @param region Region this Effect is limited to.
627
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
628
 * @return       ID of the effect added, or -1 if we failed to add one.
629
 */
630
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
631
    {
632
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
633
    }
634

    
635
///////////////////////////////////////////////////////////////////////////////////////////////////
636
/**
637
 * Makes the whole Object smoothly change all three of its RGB components.
638
 *
639
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
640
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
641
 *               Valid range: <0,1>
642
 * @param color  Color to mix. (1,0,0) is RED.
643
 * @return       ID of the effect added, or -1 if we failed to add one.
644
 */
645
  public long chroma(Data1D blend, Data3D color)
646
    {
647
    return mF.add(EffectNames.CHROMA, blend, color);
648
    }
649

    
650
///////////////////////////////////////////////////////////////////////////////////////////////////
651
/**
652
 * Makes a certain sub-region of the Object smoothly change its transparency level.
653
 *        
654
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
655
 *               moment: pixel.a *= alpha.
656
 *               Valid range: <0,1>
657
 * @param region Region this Effect is limited to. 
658
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
659
 * @return       ID of the effect added, or -1 if we failed to add one. 
660
 */
661
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
662
    {
663
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
664
    }
665

    
666
///////////////////////////////////////////////////////////////////////////////////////////////////
667
/**
668
 * Makes the whole Object smoothly change its transparency level.
669
 *
670
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
671
 *               given moment: pixel.a *= alpha.
672
 *               Valid range: <0,1>
673
 * @return       ID of the effect added, or -1 if we failed to add one.
674
 */
675
  public long alpha(Data1D alpha)
676
    {
677
    return mF.add(EffectNames.ALPHA, alpha);
678
    }
679

    
680
///////////////////////////////////////////////////////////////////////////////////////////////////
681
/**
682
 * Makes a certain sub-region of the Object smoothly change its brightness level.
683
 *        
684
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
685
 *                   at any given moment. Valid range: <0,infinity)
686
 * @param region     Region this Effect is limited to.
687
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
688
 * @return           ID of the effect added, or -1 if we failed to add one.
689
 */
690
  public long brightness(Data1D brightness, Data4D region, boolean smooth)
691
    {
692
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
693
    }
694

    
695
///////////////////////////////////////////////////////////////////////////////////////////////////
696
/**
697
 * Makes the whole Object smoothly change its brightness level.
698
 *
699
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
700
 *                   at any given moment. Valid range: <0,infinity)
701
 * @return           ID of the effect added, or -1 if we failed to add one.
702
 */
703
  public long brightness(Data1D brightness)
704
    {
705
    return mF.add(EffectNames.BRIGHTNESS, brightness);
706
    }
707

    
708
///////////////////////////////////////////////////////////////////////////////////////////////////
709
/**
710
 * Makes a certain sub-region of the Object smoothly change its contrast level.
711
 *        
712
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
713
 *                 at any given moment. Valid range: <0,infinity)
714
 * @param region   Region this Effect is limited to.
715
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
716
 * @return         ID of the effect added, or -1 if we failed to add one.
717
 */
718
  public long contrast(Data1D contrast, Data4D region, boolean smooth)
719
    {
720
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
721
    }
722

    
723
///////////////////////////////////////////////////////////////////////////////////////////////////
724
/**
725
 * Makes the whole Object smoothly change its contrast level.
726
 *
727
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
728
 *                 at any given moment. Valid range: <0,infinity)
729
 * @return         ID of the effect added, or -1 if we failed to add one.
730
 */
731
  public long contrast(Data1D contrast)
732
    {
733
    return mF.add(EffectNames.CONTRAST, contrast);
734
    }
735

    
736
///////////////////////////////////////////////////////////////////////////////////////////////////
737
/**
738
 * Makes a certain sub-region of the Object smoothly change its saturation level.
739
 *        
740
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
741
 *                   at any given moment. Valid range: <0,infinity)
742
 * @param region     Region this Effect is limited to.
743
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
744
 * @return           ID of the effect added, or -1 if we failed to add one.
745
 */
746
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
747
    {
748
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
749
    }
750

    
751
///////////////////////////////////////////////////////////////////////////////////////////////////
752
/**
753
 * Makes the whole Object smoothly change its saturation level.
754
 *
755
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
756
 *                   at any given moment. Valid range: <0,infinity)
757
 * @return           ID of the effect added, or -1 if we failed to add one.
758
 */
759
  public long saturation(Data1D saturation)
760
    {
761
    return mF.add(EffectNames.SATURATION, saturation);
762
    }
763

    
764
///////////////////////////////////////////////////////////////////////////////////////////////////
765
// Vertex-based effects  
766
///////////////////////////////////////////////////////////////////////////////////////////////////
767
/**
768
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
769
 *
770
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
771
 *               currently being dragged with.
772
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
773
 * @param region Region that masks the Effect.
774
 * @return       ID of the effect added, or -1 if we failed to add one.
775
 */
776
  public long distort(Data3D vector, Data3D center, Data4D region)
777
    {  
778
    return mV.add(EffectNames.DISTORT, vector, center, region);
779
    }
780

    
781
///////////////////////////////////////////////////////////////////////////////////////////////////
782
/**
783
 * Distort the whole Object by a (possibly changing in time) vector of force.
784
 *
785
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
786
 *               currently being dragged with.
787
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
788
 * @return       ID of the effect added, or -1 if we failed to add one.
789
 */
790
  public long distort(Data3D vector, Data3D center)
791
    {
792
    return mV.add(EffectNames.DISTORT, vector, center, null);
793
    }
794

    
795
///////////////////////////////////////////////////////////////////////////////////////////////////
796
/**
797
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
798
 * a (possibly changing in time) point on the Object.
799
 *
800
 * @param vector Vector of force that deforms the shape of the whole Object.
801
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
802
 * @param region Region that masks the Effect.
803
 * @return       ID of the effect added, or -1 if we failed to add one.
804
 */
805
  public long deform(Data3D vector, Data3D center, Data4D region)
806
    {
807
    return mV.add(EffectNames.DEFORM, vector, center, region);
808
    }
809

    
810
///////////////////////////////////////////////////////////////////////////////////////////////////
811
/**
812
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
813
 * a (possibly changing in time) point on the Object.
814
 *     
815
 * @param vector Vector of force that deforms the shape of the whole Object.
816
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
817
 * @return       ID of the effect added, or -1 if we failed to add one.
818
 */
819
  public long deform(Data3D vector, Data3D center)
820
    {  
821
    return mV.add(EffectNames.DEFORM, vector, center, null);
822
    }
823

    
824
///////////////////////////////////////////////////////////////////////////////////////////////////  
825
/**
826
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
827
 * away from the center (degree<=1)
828
 *
829
 * @param sink   The current degree of the Effect.
830
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
831
 * @param region Region that masks the Effect.
832
 * @return       ID of the effect added, or -1 if we failed to add one.
833
 */
834
  public long sink(Data1D sink, Data3D center, Data4D region)
835
    {
836
    return mV.add(EffectNames.SINK, sink, center, region);
837
    }
838

    
839
///////////////////////////////////////////////////////////////////////////////////////////////////
840
/**
841
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
842
 * away from the center (degree<=1)
843
 *
844
 * @param sink   The current degree of the Effect.
845
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
846
 * @return       ID of the effect added, or -1 if we failed to add one.
847
 */
848
  public long sink(Data1D sink, Data3D center)
849
    {
850
    return mV.add(EffectNames.SINK, sink, center);
851
    }
852

    
853
///////////////////////////////////////////////////////////////////////////////////////////////////
854
/**
855
 * Pull all points around the center of the Effect towards a line passing through the center
856
 * (that's if degree>=1) or push them away from the line (degree<=1)
857
 *
858
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
859
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
860
 * @param region Region that masks the Effect.
861
 * @return       ID of the effect added, or -1 if we failed to add one.
862
 */
863
  public long pinch(Data2D pinch, Data3D center, Data4D region)
864
    {
865
    return mV.add(EffectNames.PINCH, pinch, center, region);
866
    }
867

    
868
///////////////////////////////////////////////////////////////////////////////////////////////////
869
/**
870
 * Pull all points around the center of the Effect towards a line passing through the center
871
 * (that's if degree>=1) or push them away from the line (degree<=1)
872
 *
873
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
874
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
875
 * @return       ID of the effect added, or -1 if we failed to add one.
876
 */
877
  public long pinch(Data2D pinch, Data3D center)
878
    {
879
    return mV.add(EffectNames.PINCH, pinch, center);
880
    }
881

    
882
///////////////////////////////////////////////////////////////////////////////////////////////////  
883
/**
884
 * Rotate part of the Object around the Center of the Effect by a certain angle.
885
 *
886
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
887
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
888
 * @param region Region that masks the Effect.
889
 * @return       ID of the effect added, or -1 if we failed to add one.
890
 */
891
  public long swirl(Data1D swirl, Data3D center, Data4D region)
892
    {    
893
    return mV.add(EffectNames.SWIRL, swirl, center, region);
894
    }
895

    
896
///////////////////////////////////////////////////////////////////////////////////////////////////
897
/**
898
 * Rotate the whole Object around the Center of the Effect by a certain angle.
899
 *
900
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
901
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
902
 * @return       ID of the effect added, or -1 if we failed to add one.
903
 */
904
  public long swirl(Data1D swirl, Data3D center)
905
    {
906
    return mV.add(EffectNames.SWIRL, swirl, center);
907
    }
908

    
909
///////////////////////////////////////////////////////////////////////////////////////////////////
910
/**
911
 * Directional, sinusoidal wave effect.
912
 *
913
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
914
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
915
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
916
 *               describe the 'direction' of the wave.
917
 *               <p>
918
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
919
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
920
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
921
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
922
 *               <p>
923
 *               <p>
924
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
925
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
926
 *               will be sine shapes.
927
 *               <p>
928
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
929
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
930
 *               YZ-plane with be sine shapes.
931
 *               <p>
932
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
933
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
934
 *               value if sin at this point.
935
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
936
 * @return       ID of the effect added, or -1 if we failed to add one.
937
 */
938
  public long wave(Data5D wave, Data3D center)
939
    {
940
    return mV.add(EffectNames.WAVE, wave, center, null);
941
    }
942

    
943
///////////////////////////////////////////////////////////////////////////////////////////////////
944
/**
945
 * Directional, sinusoidal wave effect.
946
 *
947
 * @param wave   see {@link DistortedEffects#wave(Data5D,Data3D)}
948
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
949
 * @param region Region that masks the Effect.
950
 * @return       ID of the effect added, or -1 if we failed to add one.
951
 */
952
  public long wave(Data5D wave, Data3D center, Data4D region)
953
    {
954
    return mV.add(EffectNames.WAVE, wave, center, region);
955
    }
956

    
957
///////////////////////////////////////////////////////////////////////////////////////////////////
958
// Postprocess-based effects
959
///////////////////////////////////////////////////////////////////////////////////////////////////
960
/**
961
 * Blur the object.
962
 *
963
 * @param radius The 'strength' if the effect, in pixels. 0 = no blur, 10 = when blurring a given pixel,
964
 *               take into account 10 pixels in each direction.
965
 * @param center 2-dimensional Data that, at any given time, returns the Center of the Effect.
966
 * @return ID of the effect added, or -1 if we failed to add one.
967
 */
968
  public long blur(Data1D radius, Data2D center)
969
    {
970
    return mP.add(EffectNames.BLUR, radius, center);
971
    }
972
  }
(2-2/16)