Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffects.java @ 7d755851

1 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 6a06a912 Leszek Koltunski
package org.distorted.library;
21
22 c90b9e01 Leszek Koltunski
import android.content.res.Resources;
23 6a06a912 Leszek Koltunski
import android.opengl.GLES20;
24 8fa96e69 Leszek Koltunski
import android.opengl.Matrix;
25 6a06a912 Leszek Koltunski
26 e458a4ba Leszek Koltunski
import org.distorted.library.message.EffectListener;
27 55c14a19 Leszek Koltunski
import org.distorted.library.program.DistortedProgram;
28 c90b9e01 Leszek Koltunski
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 568b29d8 Leszek Koltunski
import org.distorted.library.type.Data1D;
34 f2fe7e28 Leszek Koltunski
import org.distorted.library.type.Data2D;
35 568b29d8 Leszek Koltunski
import org.distorted.library.type.Data3D;
36
import org.distorted.library.type.Data4D;
37 350cc2f5 Leszek Koltunski
import org.distorted.library.type.Data5D;
38 568b29d8 Leszek Koltunski
import org.distorted.library.type.Static3D;
39 a4835695 Leszek Koltunski
40 c90b9e01 Leszek Koltunski
import java.io.InputStream;
41 c638c1b0 Leszek Koltunski
import java.nio.ByteBuffer;
42
import java.nio.ByteOrder;
43
import java.nio.FloatBuffer;
44
45 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
46 b329f352 Leszek Koltunski
/**
47 4e2382f3 Leszek Koltunski
 * Class containing {@link EffectTypes#LENGTH} queues, each a class derived from EffectQueue.
48 b73dcaa7 Leszek Koltunski
 * <p>
49 26df012c Leszek Koltunski
 * The queues hold actual effects to be applied to a given (DistortedTexture,MeshObject) combo.
50 b329f352 Leszek Koltunski
 */
51 421c2728 Leszek Koltunski
public class DistortedEffects
52 d425545a Leszek Koltunski
  {
53 8fa96e69 Leszek Koltunski
  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 55c14a19 Leszek Koltunski
57 8fa96e69 Leszek Koltunski
  private static DistortedProgram mProgram;
58
59 c90b9e01 Leszek Koltunski
  /// DEBUG ONLY /////
60
  private static DistortedProgram mDebugProgram;
61
  private static final FloatBuffer mQuadPositions;
62
63
  static
64
    {
65
    float[] positionData= { -0.5f, -0.5f,  -0.5f, 0.5f,  0.5f,-0.5f,  0.5f, 0.5f };
66
    mQuadPositions = ByteBuffer.allocateDirect(32).order(ByteOrder.nativeOrder()).asFloatBuffer();
67
    mQuadPositions.put(positionData).position(0);
68
    }
69
70
  private static int mObjDH;
71
  private static int mMVPMatrixH;
72
  /// END DEBUG //////
73
74 8fa96e69 Leszek Koltunski
  private static float[] mMVPMatrix = new float[16];
75
  private static float[] mTmpMatrix = new float[16];
76 c638c1b0 Leszek Koltunski
77 8e34674e Leszek Koltunski
  private static long mNextID =0;
78 4e2382f3 Leszek Koltunski
  private long mID;
79 8e34674e Leszek Koltunski
80 8fa96e69 Leszek Koltunski
  private static DistortedFramebuffer mBufferFBO = new DistortedFramebuffer(1,1);
81 86eb00a9 Leszek Koltunski
82 d6e94c84 Leszek Koltunski
  private EffectQueueMatrix      mM;
83
  private EffectQueueFragment    mF;
84
  private EffectQueueVertex      mV;
85
  private EffectQueuePostprocess mP;
86 3d590d8d Leszek Koltunski
87 d6e94c84 Leszek Koltunski
  private boolean matrixCloned, vertexCloned, fragmentCloned, postprocessCloned;
88 985ea9c5 Leszek Koltunski
89 9361b337 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
90 55c14a19 Leszek Koltunski
91 c90b9e01 Leszek Koltunski
  static void createProgram(Resources resources)
92
  throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
93 55c14a19 Leszek Koltunski
    {
94 c90b9e01 Leszek Koltunski
    final InputStream mainVertexStream   = resources.openRawResource(R.raw.main_vertex_shader);
95
    final InputStream mainFragmentStream = resources.openRawResource(R.raw.main_fragment_shader);
96
97
    String mainVertexHeader= ("#version 100\n#define NUM_VERTEX "  + getMaxVertex()+"\n");
98
99
    for(EffectNames name: EffectNames.values() )
100
      {
101
      if( name.getType()== EffectTypes.VERTEX)
102
        mainVertexHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
103
      }
104
105
    String mainFragmentHeader= ("#version 100\n#define NUM_FRAGMENT "  + getMaxFragment()+"\n");
106
107
    for(EffectNames name: EffectNames.values() )
108
      {
109
      if( name.getType()== EffectTypes.FRAGMENT)
110
        mainFragmentHeader += ("#define "+name.name()+" "+name.ordinal()+"\n");
111
      }
112
113
    mProgram = new DistortedProgram(mainVertexStream,mainFragmentStream, mainVertexHeader, mainFragmentHeader);
114
115
    int mainProgramH = mProgram.getProgramHandle();
116
    EffectQueueFragment.getUniforms(mainProgramH);
117
    EffectQueueVertex.getUniforms(mainProgramH);
118
    EffectQueueMatrix.getUniforms(mainProgramH);
119
    DistortedTexture.getUniforms(mainProgramH);
120
121
    // DEBUG ONLY //////////////////////////////////////
122
    final InputStream debugVertexStream   = resources.openRawResource(R.raw.test_vertex_shader);
123
    final InputStream debugFragmentStream = resources.openRawResource(R.raw.test_fragment_shader);
124
125
    mDebugProgram = new DistortedProgram(debugVertexStream,debugFragmentStream, "#version 100\n", "#version 100\n");
126
127
    int debugProgramH = mDebugProgram.getProgramHandle();
128
    mObjDH      = GLES20.glGetUniformLocation( debugProgramH, "u_objD");
129
    mMVPMatrixH = GLES20.glGetUniformLocation( debugProgramH, "u_MVPMatrix");
130
    // END DEBUG  //////////////////////////////////////
131 55c14a19 Leszek Koltunski
    }
132
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134
135 421c2728 Leszek Koltunski
  private void initializeEffectLists(DistortedEffects d, int flags)
136 d425545a Leszek Koltunski
    {
137 015642fb Leszek Koltunski
    if( (flags & Distorted.CLONE_MATRIX) != 0 )
138 6a06a912 Leszek Koltunski
      {
139 d425545a Leszek Koltunski
      mM = d.mM;
140
      matrixCloned = true;
141
      }
142
    else
143
      {
144 4e2382f3 Leszek Koltunski
      mM = new EffectQueueMatrix(mID);
145 d425545a Leszek Koltunski
      matrixCloned = false;
146
      }
147 6a06a912 Leszek Koltunski
    
148 d425545a Leszek Koltunski
    if( (flags & Distorted.CLONE_VERTEX) != 0 )
149
      {
150
      mV = d.mV;
151
      vertexCloned = true;
152
      }
153
    else
154
      {
155 4e2382f3 Leszek Koltunski
      mV = new EffectQueueVertex(mID);
156 d425545a Leszek Koltunski
      vertexCloned = false;
157
      }
158 6a06a912 Leszek Koltunski
    
159 d425545a Leszek Koltunski
    if( (flags & Distorted.CLONE_FRAGMENT) != 0 )
160
      {
161
      mF = d.mF;
162
      fragmentCloned = true;
163 6a06a912 Leszek Koltunski
      }
164 d425545a Leszek Koltunski
    else
165
      {
166 4e2382f3 Leszek Koltunski
      mF = new EffectQueueFragment(mID);
167 d425545a Leszek Koltunski
      fragmentCloned = false;
168
      }
169 d6e94c84 Leszek Koltunski
170
    if( (flags & Distorted.CLONE_POSTPROCESS) != 0 )
171
      {
172
      mP = d.mP;
173
      postprocessCloned = true;
174
      }
175
    else
176
      {
177
      mP = new EffectQueuePostprocess(mID);
178
      postprocessCloned = false;
179
      }
180 d425545a Leszek Koltunski
    }
181 6a06a912 Leszek Koltunski
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183 c90b9e01 Leszek Koltunski
// DEBUG ONLY
184
185 e8b2f311 Leszek Koltunski
  @SuppressWarnings("unused")
186 c90b9e01 Leszek Koltunski
  private void displayBoundingRect(float halfX, float halfY, float halfZ, DistortedFramebuffer df, float[] mvp, float[] vertices)
187
    {
188
    int len  = vertices.length/3;
189
    int minx = Integer.MAX_VALUE;
190
    int maxx = Integer.MIN_VALUE;
191
    int miny = Integer.MAX_VALUE;
192
    int maxy = Integer.MIN_VALUE;
193
    int wx,wy;
194
195
    float x,y,z, X,Y,W, ndcX,ndcY;
196
197
    for(int i=0; i<len; i++)
198
      {
199
      x = 2*halfX*vertices[3*i  ];
200
      y = 2*halfY*vertices[3*i+1];
201
      z = 2*halfZ*vertices[3*i+2];
202
203
      X = mvp[ 0]*x + mvp[ 4]*y + mvp[ 8]*z + mvp[12];
204
      Y = mvp[ 1]*x + mvp[ 5]*y + mvp[ 9]*z + mvp[13];
205
      W = mvp[ 3]*x + mvp[ 7]*y + mvp[11]*z + mvp[15];
206
207
      ndcX = X/W;
208
      ndcY = Y/W;
209
210
      wx = (int)(df.mWidth *(ndcX+1)/2);
211
      wy = (int)(df.mHeight*(ndcY+1)/2);
212
213 e8b2f311 Leszek Koltunski
      if( wx<minx ) minx = wx;
214
      if( wx>maxx ) maxx = wx;
215
      if( wy<miny ) miny = wy;
216
      if( wy>maxy ) maxy = wy;
217 c90b9e01 Leszek Koltunski
      }
218
219
    mDebugProgram.useProgram();
220
    df.setAsOutput();
221
222
    Matrix.setIdentityM(mTmpMatrix, 0);
223
    Matrix.translateM(mTmpMatrix, 0, -df.mWidth/2, df.mHeight/2, -df.mDistance);
224
225
    Matrix.translateM(mTmpMatrix, 0, minx, -df.mHeight+maxy, 0.0f);
226
    Matrix.scaleM(mTmpMatrix, 0, (float)(maxx-minx)/(2*halfX), (float)(maxy-miny)/(2*halfY), 1.0f);
227
228
    Matrix.translateM(mTmpMatrix, 0, halfX,-halfY, 0);
229
    Matrix.multiplyMM(mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0);
230
231
    GLES20.glUniform2f( mObjDH , 2*halfX, 2*halfY);
232
    GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix , 0);
233
234
    GLES20.glVertexAttribPointer(mDebugProgram.mAttribute[0], 2, GLES20.GL_FLOAT, false, 0, mQuadPositions);
235
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
236
    }
237
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239
240 05403bba Leszek Koltunski
  void drawPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df, long currTime)
241 d425545a Leszek Koltunski
    {
242
    mM.compute(currTime);
243
    mV.compute(currTime);
244
    mF.compute(currTime);
245 d6e94c84 Leszek Koltunski
    mP.compute(currTime);
246 a56bc359 Leszek Koltunski
247 d6e94c84 Leszek Koltunski
    float halfZ = halfInputW*mesh.zFactor;
248 55c14a19 Leszek Koltunski
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
249 d6e94c84 Leszek Koltunski
250
    if( mP.mNumEffects==0 )
251
      {
252 8fa96e69 Leszek Koltunski
      mProgram.useProgram();
253
      df.setAsOutput();
254 d6e94c84 Leszek Koltunski
      mM.send(df,halfInputW,halfInputH,halfZ);
255
      mV.send(halfInputW,halfInputH,halfZ);
256
      mF.send(halfInputW,halfInputH);
257 8fa96e69 Leszek Koltunski
      GLES20.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mesh.mMeshPositions);
258
      GLES20.glVertexAttribPointer(mProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES20.GL_FLOAT, false, 0, mesh.mMeshNormals);
259
      GLES20.glVertexAttribPointer(mProgram.mAttribute[2], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mesh.mMeshTexture);
260 55c14a19 Leszek Koltunski
      GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
261 d6e94c84 Leszek Koltunski
      }
262
    else
263
      {
264 69ed1eb4 Leszek Koltunski
      if( mV.mNumEffects==0 && mF.mNumEffects==0 && (mesh instanceof MeshFlat) && mM.canUseShortcut() )
265 11fb6ce0 Leszek Koltunski
        {
266
        mM.constructMatrices(df,halfInputW,halfInputH);
267
        mP.render(2*halfInputW, 2*halfInputH, mM.getMVP(), df);
268
        }
269
      else
270 2b942cd0 Leszek Koltunski
        {
271 8fa96e69 Leszek Koltunski
        mProgram.useProgram();
272 2b942cd0 Leszek Koltunski
        mBufferFBO.resizeFast(df.mWidth, df.mHeight);
273
        mBufferFBO.setAsOutput();
274 8fa96e69 Leszek Koltunski
        GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
275
        GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
276 2b942cd0 Leszek Koltunski
        mM.send(mBufferFBO,halfInputW,halfInputH,halfZ);
277
        mV.send(halfInputW,halfInputH,halfZ);
278
        mF.send(halfInputW,halfInputH);
279 8fa96e69 Leszek Koltunski
        GLES20.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mesh.mMeshPositions);
280
        GLES20.glVertexAttribPointer(mProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES20.GL_FLOAT, false, 0, mesh.mMeshNormals);
281
        GLES20.glVertexAttribPointer(mProgram.mAttribute[2], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mesh.mMeshTexture);
282 55c14a19 Leszek Koltunski
        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
283 2b942cd0 Leszek Koltunski
284 8fa96e69 Leszek Koltunski
        Matrix.setIdentityM(mTmpMatrix, 0);
285
        Matrix.translateM(mTmpMatrix, 0, 0, 0, -df.mDistance);
286
        Matrix.multiplyMM(mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0);
287
288 2b942cd0 Leszek Koltunski
        mBufferFBO.setAsInput();
289 8fa96e69 Leszek Koltunski
        mP.render(df.mWidth, df.mHeight, mMVPMatrix, df);
290 2b942cd0 Leszek Koltunski
        }
291 d6e94c84 Leszek Koltunski
      }
292 c90b9e01 Leszek Koltunski
293
    /// DEBUG ONLY //////
294 7d755851 Leszek Koltunski
    // displayBoundingRect(halfInputW, halfInputH, halfZ, df, mM.getMVP(), mesh.getBoundingVertices() );
295 c90b9e01 Leszek Koltunski
    /// END DEBUG ///////
296 d425545a Leszek Koltunski
    }
297 6a06a912 Leszek Koltunski
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299
   
300 d6e94c84 Leszek Koltunski
  static void drawNoEffectsPriv(float halfInputW, float halfInputH, MeshObject mesh, DistortedFramebuffer df)
301 d425545a Leszek Koltunski
    {
302 ed13a5de Leszek Koltunski
    GLES20.glViewport(0, 0, df.mWidth, df.mHeight);
303 0a046359 Leszek Koltunski
304 8fa96e69 Leszek Koltunski
    Matrix.setIdentityM(mTmpMatrix, 0);
305
    Matrix.translateM(mTmpMatrix, 0, 0, 0, -df.mDistance);
306
    Matrix.multiplyMM(mMVPMatrix, 0, df.mProjectionMatrix, 0, mTmpMatrix, 0);
307
308 d6e94c84 Leszek Koltunski
    EffectQueueMatrix.sendZero(df,halfInputW,halfInputH,halfInputW*mesh.zFactor);
309
    EffectQueueVertex.sendZero();
310
    EffectQueueFragment.sendZero();
311 8fa96e69 Leszek Koltunski
    EffectQueuePostprocess.sendZero(df.mWidth, df.mHeight, mMVPMatrix);
312 a56bc359 Leszek Koltunski
313 8fa96e69 Leszek Koltunski
    GLES20.glVertexAttribPointer(mProgram.mAttribute[0], POSITION_DATA_SIZE, GLES20.GL_FLOAT, false, 0, mesh.mMeshPositions);
314
    GLES20.glVertexAttribPointer(mProgram.mAttribute[1], NORMAL_DATA_SIZE  , GLES20.GL_FLOAT, false, 0, mesh.mMeshNormals);
315
    GLES20.glVertexAttribPointer(mProgram.mAttribute[2], TEX_DATA_SIZE     , GLES20.GL_FLOAT, false, 0, mesh.mMeshTexture);
316 55c14a19 Leszek Koltunski
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mesh.dataLength);
317 d425545a Leszek Koltunski
    }
318 6a06a912 Leszek Koltunski
    
319
///////////////////////////////////////////////////////////////////////////////////////////////////
320
   
321 8e34674e Leszek Koltunski
  private void releasePriv()
322 d425545a Leszek Koltunski
    {
323 d6e94c84 Leszek Koltunski
    if( !matrixCloned     ) mM.abortAll(false);
324
    if( !vertexCloned     ) mV.abortAll(false);
325
    if( !fragmentCloned   ) mF.abortAll(false);
326
    if( !postprocessCloned) mP.abortAll(false);
327 d425545a Leszek Koltunski
328 4e2382f3 Leszek Koltunski
    mM = null;
329
    mV = null;
330
    mF = null;
331 d6e94c84 Leszek Koltunski
    mP = null;
332 8e34674e Leszek Koltunski
    }
333
334 1942537e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
335
336 7b8086eb Leszek Koltunski
  static void onDestroy()
337 1942537e Leszek Koltunski
    {
338
    mNextID = 0;
339
    }
340
341 8e34674e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
342
// PUBLIC API
343 ada90d33 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
344 d425545a Leszek Koltunski
/**
345 4e2382f3 Leszek Koltunski
 * Create empty effect queue.
346 d425545a Leszek Koltunski
 */
347 421c2728 Leszek Koltunski
  public DistortedEffects()
348 d425545a Leszek Koltunski
    {
349 4e2382f3 Leszek Koltunski
    mID = mNextID++;
350
    initializeEffectLists(this,0);
351 d425545a Leszek Koltunski
    }
352 ada90d33 Leszek Koltunski
353
///////////////////////////////////////////////////////////////////////////////////////////////////
354 d425545a Leszek Koltunski
/**
355 4e2382f3 Leszek Koltunski
 * Copy constructor.
356 d425545a Leszek Koltunski
 * <p>
357
 * Whatever we do not clone gets created just like in the default constructor.
358
 *
359
 * @param dc    Source object to create our object from
360
 * @param flags A bitmask of values specifying what to copy.
361 e6ab30eb Leszek Koltunski
 *              For example, CLONE_VERTEX | CLONE_MATRIX.
362 d425545a Leszek Koltunski
 */
363 421c2728 Leszek Koltunski
  public DistortedEffects(DistortedEffects dc, int flags)
364 d425545a Leszek Koltunski
    {
365 8e34674e Leszek Koltunski
    mID = mNextID++;
366 4e2382f3 Leszek Koltunski
    initializeEffectLists(dc,flags);
367 d425545a Leszek Koltunski
    }
368 ada90d33 Leszek Koltunski
369 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
370
/**
371 07305c87 Leszek Koltunski
 * Releases all resources. After this call, the queue should not be used anymore.
372 6a06a912 Leszek Koltunski
 */
373 8e34674e Leszek Koltunski
  public synchronized void delete()
374 d425545a Leszek Koltunski
    {
375
    releasePriv();
376
    }
377 6a06a912 Leszek Koltunski
378
///////////////////////////////////////////////////////////////////////////////////////////////////
379
/**
380 4e2382f3 Leszek Koltunski
 * Returns unique ID of this instance.
381
 *
382
 * @return ID of the object.
383 6a06a912 Leszek Koltunski
 */
384 4e2382f3 Leszek Koltunski
  public long getID()
385 d425545a Leszek Koltunski
      {
386 4e2382f3 Leszek Koltunski
      return mID;
387 d425545a Leszek Koltunski
      }
388 4e2382f3 Leszek Koltunski
389 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
390
/**
391
 * Adds the calling class to the list of Listeners that get notified each time some event happens 
392 07305c87 Leszek Koltunski
 * to one of the Effects in those queues. Nothing will happen if 'el' is already in the list.
393 6a06a912 Leszek Koltunski
 * 
394
 * @param el A class implementing the EffectListener interface that wants to get notifications.
395
 */
396 3fc994b2 Leszek Koltunski
  public void registerForMessages(EffectListener el)
397 d425545a Leszek Koltunski
    {
398 3fc994b2 Leszek Koltunski
    mV.registerForMessages(el);
399
    mF.registerForMessages(el);
400
    mM.registerForMessages(el);
401 d6e94c84 Leszek Koltunski
    mP.registerForMessages(el);
402 d425545a Leszek Koltunski
    }
403 6a06a912 Leszek Koltunski
404
///////////////////////////////////////////////////////////////////////////////////////////////////
405
/**
406
 * Removes the calling class from the list of Listeners.
407
 * 
408
 * @param el A class implementing the EffectListener interface that no longer wants to get notifications.
409
 */
410 3fc994b2 Leszek Koltunski
  public void deregisterForMessages(EffectListener el)
411 d425545a Leszek Koltunski
    {
412 3fc994b2 Leszek Koltunski
    mV.deregisterForMessages(el);
413
    mF.deregisterForMessages(el);
414
    mM.deregisterForMessages(el);
415 d6e94c84 Leszek Koltunski
    mP.deregisterForMessages(el);
416 d425545a Leszek Koltunski
    }
417 6a06a912 Leszek Koltunski
418
///////////////////////////////////////////////////////////////////////////////////////////////////
419
/**
420 d07f2950 Leszek Koltunski
 * Aborts all Effects.
421
 * @return Number of effects aborted.
422 6a06a912 Leszek Koltunski
 */
423 d425545a Leszek Koltunski
  public int abortAllEffects()
424 6a06a912 Leszek Koltunski
      {
425 d6e94c84 Leszek Koltunski
      return mM.abortAll(true) + mV.abortAll(true) + mF.abortAll(true) + mP.abortAll(true);
426 6a06a912 Leszek Koltunski
      }
427
428
///////////////////////////////////////////////////////////////////////////////////////////////////
429
/**
430 d07f2950 Leszek Koltunski
 * Aborts all Effects of a given type, for example all MATRIX Effects.
431 6a06a912 Leszek Koltunski
 * 
432 d07f2950 Leszek Koltunski
 * @param type one of the constants defined in {@link EffectTypes}
433
 * @return Number of effects aborted.
434 6a06a912 Leszek Koltunski
 */
435 d425545a Leszek Koltunski
  public int abortEffects(EffectTypes type)
436
    {
437
    switch(type)
438 6a06a912 Leszek Koltunski
      {
439 d6e94c84 Leszek Koltunski
      case MATRIX     : return mM.abortAll(true);
440
      case VERTEX     : return mV.abortAll(true);
441
      case FRAGMENT   : return mF.abortAll(true);
442
      case POSTPROCESS: return mP.abortAll(true);
443
      default         : return 0;
444 6a06a912 Leszek Koltunski
      }
445 d425545a Leszek Koltunski
    }
446 6a06a912 Leszek Koltunski
    
447
///////////////////////////////////////////////////////////////////////////////////////////////////
448
/**
449
 * Aborts a single Effect.
450
 * 
451
 * @param id ID of the Effect we want to abort.
452 476bbc81 Leszek Koltunski
 * @return number of Effects aborted. Always either 0 or 1.
453 6a06a912 Leszek Koltunski
 */
454 d425545a Leszek Koltunski
  public int abortEffect(long id)
455
    {
456
    int type = (int)(id&EffectTypes.MASK);
457 1e438fc7 Leszek Koltunski
458 d6e94c84 Leszek Koltunski
    if( type==EffectTypes.MATRIX.type      ) return mM.removeByID(id>>EffectTypes.LENGTH);
459
    if( type==EffectTypes.VERTEX.type      ) return mV.removeByID(id>>EffectTypes.LENGTH);
460
    if( type==EffectTypes.FRAGMENT.type    ) return mF.removeByID(id>>EffectTypes.LENGTH);
461
    if( type==EffectTypes.POSTPROCESS.type ) return mP.removeByID(id>>EffectTypes.LENGTH);
462 1e438fc7 Leszek Koltunski
463 d425545a Leszek Koltunski
    return 0;
464
    }
465 6a06a912 Leszek Koltunski
466
///////////////////////////////////////////////////////////////////////////////////////////////////
467
/**
468 e8c81a8e Leszek Koltunski
 * Abort all Effects of a given name, for example all rotations.
469 6a06a912 Leszek Koltunski
 * 
470 d07f2950 Leszek Koltunski
 * @param name one of the constants defined in {@link EffectNames}
471 476bbc81 Leszek Koltunski
 * @return number of Effects aborted.
472 6a06a912 Leszek Koltunski
 */
473 d425545a Leszek Koltunski
  public int abortEffects(EffectNames name)
474
    {
475
    switch(name.getType())
476 6a06a912 Leszek Koltunski
      {
477 d6e94c84 Leszek Koltunski
      case MATRIX     : return mM.removeByType(name);
478
      case VERTEX     : return mV.removeByType(name);
479
      case FRAGMENT   : return mF.removeByType(name);
480
      case POSTPROCESS: return mP.removeByType(name);
481
      default         : return 0;
482 6a06a912 Leszek Koltunski
      }
483 d425545a Leszek Koltunski
    }
484 6a06a912 Leszek Koltunski
    
485
///////////////////////////////////////////////////////////////////////////////////////////////////
486
/**
487
 * Print some info about a given Effect to Android's standard out. Used for debugging only.
488
 * 
489
 * @param id Effect ID we want to print info about
490
 * @return <code>true</code> if a single Effect of type effectType has been found.
491
 */
492
    
493 d425545a Leszek Koltunski
  public boolean printEffect(long id)
494
    {
495
    int type = (int)(id&EffectTypes.MASK);
496 1e438fc7 Leszek Koltunski
497 d6e94c84 Leszek Koltunski
    if( type==EffectTypes.MATRIX.type      )  return mM.printByID(id>>EffectTypes.LENGTH);
498
    if( type==EffectTypes.VERTEX.type      )  return mV.printByID(id>>EffectTypes.LENGTH);
499
    if( type==EffectTypes.FRAGMENT.type    )  return mF.printByID(id>>EffectTypes.LENGTH);
500
    if( type==EffectTypes.POSTPROCESS.type )  return mP.printByID(id>>EffectTypes.LENGTH);
501 1e438fc7 Leszek Koltunski
502 d425545a Leszek Koltunski
    return false;
503
    }
504 432442f9 Leszek Koltunski
505
///////////////////////////////////////////////////////////////////////////////////////////////////
506
/**
507
 * Returns the maximum number of Matrix effects.
508
 *
509
 * @return The maximum number of Matrix effects
510
 */
511
  public static int getMaxMatrix()
512
    {
513
    return EffectQueue.getMax(EffectTypes.MATRIX.ordinal());
514
    }
515
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517
/**
518
 * Returns the maximum number of Vertex effects.
519
 *
520
 * @return The maximum number of Vertex effects
521
 */
522
  public static int getMaxVertex()
523
    {
524
    return EffectQueue.getMax(EffectTypes.VERTEX.ordinal());
525
    }
526
527
///////////////////////////////////////////////////////////////////////////////////////////////////
528
/**
529
 * Returns the maximum number of Fragment effects.
530
 *
531
 * @return The maximum number of Fragment effects
532
 */
533
  public static int getMaxFragment()
534
    {
535
    return EffectQueue.getMax(EffectTypes.FRAGMENT.ordinal());
536
    }
537
538
///////////////////////////////////////////////////////////////////////////////////////////////////
539
/**
540
 * Returns the maximum number of Postprocess effects.
541
 *
542
 * @return The maximum number of Postprocess effects
543
 */
544
  public static int getMaxPostprocess()
545
    {
546
    return EffectQueue.getMax(EffectTypes.POSTPROCESS.ordinal());
547
    }
548
549
///////////////////////////////////////////////////////////////////////////////////////////////////
550
/**
551
 * Sets the maximum number of Matrix effects that can be stored in a single EffectQueue at one time.
552
 * This can fail if:
553
 * <ul>
554
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
555
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
556
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
557
 *     time only decreasing the value of 'max' is permitted.
558
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
559
 * </ul>
560
 *
561
 * @param max new maximum number of simultaneous Matrix Effects. Has to be a non-negative number not greater
562
 *            than Byte.MAX_VALUE
563
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
564
 */
565
  public static boolean setMaxMatrix(int max)
566
    {
567
    return EffectQueue.setMax(EffectTypes.MATRIX.ordinal(),max);
568
    }
569
570
///////////////////////////////////////////////////////////////////////////////////////////////////
571
/**
572
 * Sets the maximum number of Vertex effects that can be stored in a single EffectQueue at one time.
573
 * This can fail if:
574
 * <ul>
575
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
576
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
577
 *     before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
578
 *     time only decreasing the value of 'max' is permitted.
579
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
580
 * </ul>
581
 *
582
 * @param max new maximum number of simultaneous Vertex Effects. Has to be a non-negative number not greater
583
 *            than Byte.MAX_VALUE
584
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
585
 */
586
  public static boolean setMaxVertex(int max)
587
    {
588
    return EffectQueue.setMax(EffectTypes.VERTEX.ordinal(),max);
589
    }
590
591
///////////////////////////////////////////////////////////////////////////////////////////////////
592
/**
593
 * Sets the maximum number of Fragment effects that can be stored in a single EffectQueue at one time.
594
 * This can fail if:
595
 * <ul>
596
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
597
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
598
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
599
 *     time only decreasing the value of 'max' is permitted.
600
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
601
 * </ul>
602
 *
603
 * @param max new maximum number of simultaneous Fragment Effects. Has to be a non-negative number not greater
604
 *            than Byte.MAX_VALUE
605
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
606
 */
607
  public static boolean setMaxFragment(int max)
608
    {
609
    return EffectQueue.setMax(EffectTypes.FRAGMENT.ordinal(),max);
610
    }
611
612
///////////////////////////////////////////////////////////////////////////////////////////////////
613
/**
614
 * Sets the maximum number of Postprocess effects that can be stored in a single EffectQueue at one time.
615
 * This can fail if:
616
 * <ul>
617
 * <li>the value of 'max' is outside permitted range (0 &le; max &le; Byte.MAX_VALUE)
618
 * <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called
619
 *     before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
620
 *     time only decreasing the value of 'max' is permitted.
621
 * <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created.
622
 * </ul>
623
 *
624
 * @param max new maximum number of simultaneous Postprocess Effects. Has to be a non-negative number not greater
625
 *            than Byte.MAX_VALUE
626
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
627
 */
628
  public static boolean setMaxPostprocess(int max)
629
    {
630
    return EffectQueue.setMax(EffectTypes.POSTPROCESS.ordinal(),max);
631
    }
632
633 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////   
634
///////////////////////////////////////////////////////////////////////////////////////////////////
635
// Individual effect functions.
636
///////////////////////////////////////////////////////////////////////////////////////////////////
637
// Matrix-based effects
638
///////////////////////////////////////////////////////////////////////////////////////////////////
639
/**
640 e8c81a8e Leszek Koltunski
 * Moves the Object by a (possibly changing in time) vector.
641 6a06a912 Leszek Koltunski
 * 
642 568b29d8 Leszek Koltunski
 * @param vector 3-dimensional Data which at any given time will return a Static3D
643 e0a16874 Leszek Koltunski
 *               representing the current coordinates of the vector we want to move the Object with.
644
 * @return       ID of the effect added, or -1 if we failed to add one.
645 6a06a912 Leszek Koltunski
 */
646 568b29d8 Leszek Koltunski
  public long move(Data3D vector)
647 6a06a912 Leszek Koltunski
    {   
648 e0a16874 Leszek Koltunski
    return mM.add(EffectNames.MOVE,vector);
649 6a06a912 Leszek Koltunski
    }
650
651
///////////////////////////////////////////////////////////////////////////////////////////////////
652
/**
653 e8c81a8e Leszek Koltunski
 * Scales the Object by (possibly changing in time) 3D scale factors.
654 6a06a912 Leszek Koltunski
 * 
655 d1e740c5 Leszek Koltunski
 * @param scale 3-dimensional Data which at any given time returns a Static3D
656 e0a16874 Leszek Koltunski
 *              representing the current x- , y- and z- scale factors.
657
 * @return      ID of the effect added, or -1 if we failed to add one.
658 6a06a912 Leszek Koltunski
 */
659 568b29d8 Leszek Koltunski
  public long scale(Data3D scale)
660 6a06a912 Leszek Koltunski
    {   
661 e0a16874 Leszek Koltunski
    return mM.add(EffectNames.SCALE,scale);
662 6a06a912 Leszek Koltunski
    }
663
664 2fce34f4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
665
/**
666 e8c81a8e Leszek Koltunski
 * Scales the Object by one uniform, constant factor in all 3 dimensions. Convenience function.
667 2fce34f4 Leszek Koltunski
 *
668
 * @param scale The factor to scale all 3 dimensions with.
669
 * @return      ID of the effect added, or -1 if we failed to add one.
670
 */
671 d425545a Leszek Koltunski
  public long scale(float scale)
672
    {
673
    return mM.add(EffectNames.SCALE, new Static3D(scale,scale,scale));
674
    }
675 2fce34f4 Leszek Koltunski
676 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
677
/**
678 568b29d8 Leszek Koltunski
 * Rotates the Object by 'angle' degrees around the center.
679
 * Static axis of rotation is given by the last parameter.
680
 *
681 9351ad55 Leszek Koltunski
 * @param angle  Angle that we want to rotate the Object to. Unit: degrees
682 568b29d8 Leszek Koltunski
 * @param axis   Axis of rotation
683 0df17fad Leszek Koltunski
 * @param center Coordinates of the Point we are rotating around.
684 e0a16874 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
685
 */
686 0df17fad Leszek Koltunski
  public long rotate(Data1D angle, Static3D axis, Data3D center )
687 6a06a912 Leszek Koltunski
    {   
688 0df17fad Leszek Koltunski
    return mM.add(EffectNames.ROTATE, angle, axis, center);
689 6a06a912 Leszek Koltunski
    }
690
691
///////////////////////////////////////////////////////////////////////////////////////////////////
692
/**
693 568b29d8 Leszek Koltunski
 * Rotates the Object by 'angle' degrees around the center.
694 2fce34f4 Leszek Koltunski
 * Here both angle and axis can dynamically change.
695 568b29d8 Leszek Koltunski
 *
696
 * @param angleaxis Combined 4-tuple representing the (angle,axisX,axisY,axisZ).
697 0df17fad Leszek Koltunski
 * @param center    Coordinates of the Point we are rotating around.
698 568b29d8 Leszek Koltunski
 * @return          ID of the effect added, or -1 if we failed to add one.
699 e0a16874 Leszek Koltunski
 */
700 0df17fad Leszek Koltunski
  public long rotate(Data4D angleaxis, Data3D center)
701 568b29d8 Leszek Koltunski
    {
702 0df17fad Leszek Koltunski
    return mM.add(EffectNames.ROTATE, angleaxis, center);
703 6a06a912 Leszek Koltunski
    }
704
705
///////////////////////////////////////////////////////////////////////////////////////////////////
706
/**
707 568b29d8 Leszek Koltunski
 * Rotates the Object by quaternion.
708 0df17fad Leszek Koltunski
 *
709 568b29d8 Leszek Koltunski
 * @param quaternion The quaternion describing the rotation.
710 0df17fad Leszek Koltunski
 * @param center     Coordinates of the Point we are rotating around.
711 568b29d8 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
712 6a06a912 Leszek Koltunski
 */
713 0df17fad Leszek Koltunski
  public long quaternion(Data4D quaternion, Data3D center )
714 568b29d8 Leszek Koltunski
    {
715 0df17fad Leszek Koltunski
    return mM.add(EffectNames.QUATERNION,quaternion,center);
716 6a06a912 Leszek Koltunski
    }
717
718
///////////////////////////////////////////////////////////////////////////////////////////////////
719
/**
720 568b29d8 Leszek Koltunski
 * Shears the Object.
721 6a06a912 Leszek Koltunski
 *
722 8c3cdec5 Leszek Koltunski
 * @param shear   The 3-tuple of shear factors. The first controls level
723
 *                of shearing in the X-axis, second - Y-axis and the third -
724
 *                Z-axis. Each is the tangens of the shear angle, i.e 0 -
725
 *                no shear, 1 - shear by 45 degrees (tan(45deg)=1) etc.
726 0df17fad Leszek Koltunski
 * @param center  Center of shearing, i.e. the point which stays unmoved.
727 e0a16874 Leszek Koltunski
 * @return        ID of the effect added, or -1 if we failed to add one.
728 6a06a912 Leszek Koltunski
 */
729 0df17fad Leszek Koltunski
  public long shear(Data3D shear, Data3D center)
730 6a06a912 Leszek Koltunski
    {
731 0df17fad Leszek Koltunski
    return mM.add(EffectNames.SHEAR, shear, center);
732 6a06a912 Leszek Koltunski
    }
733
734
///////////////////////////////////////////////////////////////////////////////////////////////////
735
// Fragment-based effects  
736
///////////////////////////////////////////////////////////////////////////////////////////////////
737
/**
738 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change all three of its RGB components.
739 6a06a912 Leszek Koltunski
 *        
740 2fce34f4 Leszek Koltunski
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
741 e4878781 Leszek Koltunski
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
742
 *               Valid range: <0,1>
743 b1e91f2c Leszek Koltunski
 * @param color  Color to mix. (1,0,0) is RED.
744 2fce34f4 Leszek Koltunski
 * @param region Region this Effect is limited to.
745
 * @param smooth If true, the level of 'blend' will smoothly fade out towards the edges of the region.
746
 * @return       ID of the effect added, or -1 if we failed to add one.
747 6a06a912 Leszek Koltunski
 */
748 8c893ffc Leszek Koltunski
  public long chroma(Data1D blend, Data3D color, Data4D region, boolean smooth)
749 6a06a912 Leszek Koltunski
    {
750 2fce34f4 Leszek Koltunski
    return mF.add( smooth? EffectNames.SMOOTH_CHROMA:EffectNames.CHROMA, blend, color, region);
751 6a06a912 Leszek Koltunski
    }
752
753
///////////////////////////////////////////////////////////////////////////////////////////////////
754
/**
755 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change all three of its RGB components.
756
 *
757
 * @param blend  1-dimensional Data that returns the level of blend a given pixel will be
758 e4878781 Leszek Koltunski
 *               mixed with the next parameter 'color': pixel = (1-level)*pixel + level*color.
759
 *               Valid range: <0,1>
760 b1e91f2c Leszek Koltunski
 * @param color  Color to mix. (1,0,0) is RED.
761 2fce34f4 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
762 6a06a912 Leszek Koltunski
 */
763 8c893ffc Leszek Koltunski
  public long chroma(Data1D blend, Data3D color)
764 6a06a912 Leszek Koltunski
    {
765 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.CHROMA, blend, color);
766 6a06a912 Leszek Koltunski
    }
767
768
///////////////////////////////////////////////////////////////////////////////////////////////////
769
/**
770 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its transparency level.
771 6a06a912 Leszek Koltunski
 *        
772 2fce34f4 Leszek Koltunski
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any given
773 e4878781 Leszek Koltunski
 *               moment: pixel.a *= alpha.
774
 *               Valid range: <0,1>
775 d7bbef2f Leszek Koltunski
 * @param region Region this Effect is limited to. 
776 2fce34f4 Leszek Koltunski
 * @param smooth If true, the level of 'alpha' will smoothly fade out towards the edges of the region.
777 d7bbef2f Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one. 
778 6a06a912 Leszek Koltunski
 */
779 2fce34f4 Leszek Koltunski
  public long alpha(Data1D alpha, Data4D region, boolean smooth)
780 6a06a912 Leszek Koltunski
    {
781 2fce34f4 Leszek Koltunski
    return mF.add( smooth? EffectNames.SMOOTH_ALPHA:EffectNames.ALPHA, alpha, region);
782 6a06a912 Leszek Koltunski
    }
783
784
///////////////////////////////////////////////////////////////////////////////////////////////////
785
/**
786 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its transparency level.
787
 *
788
 * @param alpha  1-dimensional Data that returns the level of transparency we want to have at any
789 e4878781 Leszek Koltunski
 *               given moment: pixel.a *= alpha.
790
 *               Valid range: <0,1>
791 2fce34f4 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
792 6a06a912 Leszek Koltunski
 */
793 2fce34f4 Leszek Koltunski
  public long alpha(Data1D alpha)
794 6a06a912 Leszek Koltunski
    {
795 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.ALPHA, alpha);
796 6a06a912 Leszek Koltunski
    }
797
798
///////////////////////////////////////////////////////////////////////////////////////////////////
799
/**
800 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its brightness level.
801 6a06a912 Leszek Koltunski
 *        
802 2fce34f4 Leszek Koltunski
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
803 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
804 e0a16874 Leszek Koltunski
 * @param region     Region this Effect is limited to.
805 2fce34f4 Leszek Koltunski
 * @param smooth     If true, the level of 'brightness' will smoothly fade out towards the edges of the region.
806 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
807 6a06a912 Leszek Koltunski
 */
808 2fce34f4 Leszek Koltunski
  public long brightness(Data1D brightness, Data4D region, boolean smooth)
809 6a06a912 Leszek Koltunski
    {
810 2fce34f4 Leszek Koltunski
    return mF.add( smooth ? EffectNames.SMOOTH_BRIGHTNESS: EffectNames.BRIGHTNESS, brightness, region);
811 6a06a912 Leszek Koltunski
    }
812
813
///////////////////////////////////////////////////////////////////////////////////////////////////
814
/**
815 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its brightness level.
816
 *
817
 * @param brightness 1-dimensional Data that returns the level of brightness we want to have
818 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
819 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
820 6a06a912 Leszek Koltunski
 */
821 2fce34f4 Leszek Koltunski
  public long brightness(Data1D brightness)
822 6a06a912 Leszek Koltunski
    {
823 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.BRIGHTNESS, brightness);
824 6a06a912 Leszek Koltunski
    }
825
826
///////////////////////////////////////////////////////////////////////////////////////////////////
827
/**
828 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its contrast level.
829 6a06a912 Leszek Koltunski
 *        
830 2fce34f4 Leszek Koltunski
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
831 e4878781 Leszek Koltunski
 *                 at any given moment. Valid range: <0,infinity)
832 e0a16874 Leszek Koltunski
 * @param region   Region this Effect is limited to.
833 2fce34f4 Leszek Koltunski
 * @param smooth   If true, the level of 'contrast' will smoothly fade out towards the edges of the region.
834 e0a16874 Leszek Koltunski
 * @return         ID of the effect added, or -1 if we failed to add one.
835 6a06a912 Leszek Koltunski
 */
836 2fce34f4 Leszek Koltunski
  public long contrast(Data1D contrast, Data4D region, boolean smooth)
837 6a06a912 Leszek Koltunski
    {
838 2fce34f4 Leszek Koltunski
    return mF.add( smooth ? EffectNames.SMOOTH_CONTRAST:EffectNames.CONTRAST, contrast, region);
839 6a06a912 Leszek Koltunski
    }
840
841
///////////////////////////////////////////////////////////////////////////////////////////////////
842
/**
843 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its contrast level.
844
 *
845
 * @param contrast 1-dimensional Data that returns the level of contrast we want to have
846 e4878781 Leszek Koltunski
 *                 at any given moment. Valid range: <0,infinity)
847 e0a16874 Leszek Koltunski
 * @return         ID of the effect added, or -1 if we failed to add one.
848 6a06a912 Leszek Koltunski
 */
849 2fce34f4 Leszek Koltunski
  public long contrast(Data1D contrast)
850 6a06a912 Leszek Koltunski
    {
851 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.CONTRAST, contrast);
852 6a06a912 Leszek Koltunski
    }
853
854
///////////////////////////////////////////////////////////////////////////////////////////////////
855
/**
856 e0a16874 Leszek Koltunski
 * Makes a certain sub-region of the Object smoothly change its saturation level.
857 6a06a912 Leszek Koltunski
 *        
858 2fce34f4 Leszek Koltunski
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
859 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
860 e0a16874 Leszek Koltunski
 * @param region     Region this Effect is limited to.
861 2fce34f4 Leszek Koltunski
 * @param smooth     If true, the level of 'saturation' will smoothly fade out towards the edges of the region.
862 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
863 6a06a912 Leszek Koltunski
 */
864 2fce34f4 Leszek Koltunski
  public long saturation(Data1D saturation, Data4D region, boolean smooth)
865 6a06a912 Leszek Koltunski
    {
866 2fce34f4 Leszek Koltunski
    return mF.add( smooth ? EffectNames.SMOOTH_SATURATION:EffectNames.SATURATION, saturation, region);
867 6a06a912 Leszek Koltunski
    }
868
869
///////////////////////////////////////////////////////////////////////////////////////////////////
870
/**
871 2fce34f4 Leszek Koltunski
 * Makes the whole Object smoothly change its saturation level.
872
 *
873
 * @param saturation 1-dimensional Data that returns the level of saturation we want to have
874 e4878781 Leszek Koltunski
 *                   at any given moment. Valid range: <0,infinity)
875 e0a16874 Leszek Koltunski
 * @return           ID of the effect added, or -1 if we failed to add one.
876 6a06a912 Leszek Koltunski
 */
877 2fce34f4 Leszek Koltunski
  public long saturation(Data1D saturation)
878 6a06a912 Leszek Koltunski
    {
879 2fce34f4 Leszek Koltunski
    return mF.add(EffectNames.SATURATION, saturation);
880 6a06a912 Leszek Koltunski
    }
881
882
///////////////////////////////////////////////////////////////////////////////////////////////////
883
// Vertex-based effects  
884
///////////////////////////////////////////////////////////////////////////////////////////////////
885
/**
886 e0a16874 Leszek Koltunski
 * Distort a (possibly changing in time) part of the Object by a (possibly changing in time) vector of force.
887 f2fe7e28 Leszek Koltunski
 *
888
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
889
 *               currently being dragged with.
890 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
891 f2fe7e28 Leszek Koltunski
 * @param region Region that masks the Effect.
892
 * @return       ID of the effect added, or -1 if we failed to add one.
893 6a06a912 Leszek Koltunski
 */
894 fa6c352d Leszek Koltunski
  public long distort(Data3D vector, Data3D center, Data4D region)
895 6a06a912 Leszek Koltunski
    {  
896 f2fe7e28 Leszek Koltunski
    return mV.add(EffectNames.DISTORT, vector, center, region);
897 6a06a912 Leszek Koltunski
    }
898
899
///////////////////////////////////////////////////////////////////////////////////////////////////
900
/**
901 e0a16874 Leszek Koltunski
 * Distort the whole Object by a (possibly changing in time) vector of force.
902 f2fe7e28 Leszek Koltunski
 *
903
 * @param vector 3-dimensional Vector which represents the force the Center of the Effect is
904
 *               currently being dragged with.
905 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
906 e0a16874 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
907 6a06a912 Leszek Koltunski
 */
908 fa6c352d Leszek Koltunski
  public long distort(Data3D vector, Data3D center)
909 d425545a Leszek Koltunski
    {
910 02ef26bc Leszek Koltunski
    return mV.add(EffectNames.DISTORT, vector, center, null);
911 d425545a Leszek Koltunski
    }
912 6a06a912 Leszek Koltunski
913 6ebdbbf1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
914
/**
915
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
916
 * a (possibly changing in time) point on the Object.
917
 *
918
 * @param vector Vector of force that deforms the shape of the whole Object.
919
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
920
 * @param region Region that masks the Effect.
921
 * @return       ID of the effect added, or -1 if we failed to add one.
922
 */
923
  public long deform(Data3D vector, Data3D center, Data4D region)
924
    {
925
    return mV.add(EffectNames.DEFORM, vector, center, region);
926
    }
927
928 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
929
/**
930 e0a16874 Leszek Koltunski
 * Deform the shape of the whole Object with a (possibly changing in time) vector of force applied to
931 9351ad55 Leszek Koltunski
 * a (possibly changing in time) point on the Object.
932 6a06a912 Leszek Koltunski
 *     
933 f2fe7e28 Leszek Koltunski
 * @param vector Vector of force that deforms the shape of the whole Object.
934 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
935 e0a16874 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
936 6a06a912 Leszek Koltunski
 */
937 fa6c352d Leszek Koltunski
  public long deform(Data3D vector, Data3D center)
938 6a06a912 Leszek Koltunski
    {  
939 02ef26bc Leszek Koltunski
    return mV.add(EffectNames.DEFORM, vector, center, null);
940 6a06a912 Leszek Koltunski
    }
941
942
///////////////////////////////////////////////////////////////////////////////////////////////////  
943
/**
944 f2fe7e28 Leszek Koltunski
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
945 6a06a912 Leszek Koltunski
 * away from the center (degree<=1)
946 f2fe7e28 Leszek Koltunski
 *
947
 * @param sink   The current degree of the Effect.
948 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
949 f2fe7e28 Leszek Koltunski
 * @param region Region that masks the Effect.
950
 * @return       ID of the effect added, or -1 if we failed to add one.
951 6a06a912 Leszek Koltunski
 */
952 fa6c352d Leszek Koltunski
  public long sink(Data1D sink, Data3D center, Data4D region)
953 6a06a912 Leszek Koltunski
    {
954 f2fe7e28 Leszek Koltunski
    return mV.add(EffectNames.SINK, sink, center, region);
955 6a06a912 Leszek Koltunski
    }
956
957
///////////////////////////////////////////////////////////////////////////////////////////////////
958
/**
959 f2fe7e28 Leszek Koltunski
 * Pull all points around the center of the Effect towards the center (if degree>=1) or push them
960
 * away from the center (degree<=1)
961
 *
962
 * @param sink   The current degree of the Effect.
963 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
964 f2fe7e28 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
965 6a06a912 Leszek Koltunski
 */
966 fa6c352d Leszek Koltunski
  public long sink(Data1D sink, Data3D center)
967 d425545a Leszek Koltunski
    {
968
    return mV.add(EffectNames.SINK, sink, center);
969
    }
970 6a06a912 Leszek Koltunski
971 82ee855a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
972
/**
973
 * Pull all points around the center of the Effect towards a line passing through the center
974
 * (that's if degree>=1) or push them away from the line (degree<=1)
975
 *
976
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
977
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
978
 * @param region Region that masks the Effect.
979
 * @return       ID of the effect added, or -1 if we failed to add one.
980
 */
981
  public long pinch(Data2D pinch, Data3D center, Data4D region)
982
    {
983
    return mV.add(EffectNames.PINCH, pinch, center, region);
984
    }
985
986
///////////////////////////////////////////////////////////////////////////////////////////////////
987
/**
988
 * Pull all points around the center of the Effect towards a line passing through the center
989
 * (that's if degree>=1) or push them away from the line (degree<=1)
990
 *
991
 * @param pinch  The current degree of the Effect + angle the line forms with X-axis
992
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
993
 * @return       ID of the effect added, or -1 if we failed to add one.
994
 */
995
  public long pinch(Data2D pinch, Data3D center)
996
    {
997
    return mV.add(EffectNames.PINCH, pinch, center);
998
    }
999
1000 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////  
1001
/**
1002 f2fe7e28 Leszek Koltunski
 * Rotate part of the Object around the Center of the Effect by a certain angle.
1003
 *
1004 4fde55a0 Leszek Koltunski
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
1005 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1006 f2fe7e28 Leszek Koltunski
 * @param region Region that masks the Effect.
1007
 * @return       ID of the effect added, or -1 if we failed to add one.
1008 6a06a912 Leszek Koltunski
 */
1009 fa6c352d Leszek Koltunski
  public long swirl(Data1D swirl, Data3D center, Data4D region)
1010 6a06a912 Leszek Koltunski
    {    
1011 f2fe7e28 Leszek Koltunski
    return mV.add(EffectNames.SWIRL, swirl, center, region);
1012 6a06a912 Leszek Koltunski
    }
1013
1014
///////////////////////////////////////////////////////////////////////////////////////////////////
1015
/**
1016 f2fe7e28 Leszek Koltunski
 * Rotate the whole Object around the Center of the Effect by a certain angle.
1017
 *
1018 4fde55a0 Leszek Koltunski
 * @param swirl  The angle of Swirl (in degrees). Positive values swirl clockwise.
1019 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1020 f2fe7e28 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
1021 6a06a912 Leszek Koltunski
 */
1022 fa6c352d Leszek Koltunski
  public long swirl(Data1D swirl, Data3D center)
1023 d425545a Leszek Koltunski
    {
1024
    return mV.add(EffectNames.SWIRL, swirl, center);
1025
    }
1026 4fde55a0 Leszek Koltunski
1027
///////////////////////////////////////////////////////////////////////////////////////////////////
1028
/**
1029
 * Directional, sinusoidal wave effect.
1030
 *
1031 350cc2f5 Leszek Koltunski
 * @param wave   A 5-dimensional data structure describing the wave: first member is the amplitude,
1032 ea16dc89 Leszek Koltunski
 *               second is the wave length, third is the phase (i.e. when phase = PI/2, the sine
1033 350cc2f5 Leszek Koltunski
 *               wave at the center does not start from sin(0), but from sin(PI/2) ) and the next two
1034
 *               describe the 'direction' of the wave.
1035 3695d6fa Leszek Koltunski
 *               <p>
1036 d0c902b8 Leszek Koltunski
 *               Wave direction is defined to be a 3D vector of length 1. To define such vectors, we
1037
 *               need 2 floats: thus the third member is the angle Alpha (in degrees) which the vector
1038
 *               forms with the XY-plane, and the fourth is the angle Beta (again in degrees) which
1039
 *               the projection of the vector to the XY-plane forms with the Y-axis (counterclockwise).
1040 3695d6fa Leszek Koltunski
 *               <p>
1041
 *               <p>
1042 d0c902b8 Leszek Koltunski
 *               Example1: if Alpha = 90, Beta = 90, (then V=(0,0,1) ) and the wave acts 'vertically'
1043
 *               in the X-direction, i.e. cross-sections of the resulting surface with the XZ-plane
1044
 *               will be sine shapes.
1045 3695d6fa Leszek Koltunski
 *               <p>
1046 d0c902b8 Leszek Koltunski
 *               Example2: if Alpha = 90, Beta = 0, the again V=(0,0,1) and the wave is 'vertical',
1047
 *               but this time it waves in the Y-direction, i.e. cross sections of the surface and the
1048
 *               YZ-plane with be sine shapes.
1049 3695d6fa Leszek Koltunski
 *               <p>
1050 d0c902b8 Leszek Koltunski
 *               Example3: if Alpha = 0 and Beta = 45, then V=(sqrt(2)/2, -sqrt(2)/2, 0) and the wave
1051 350cc2f5 Leszek Koltunski
 *               is entirely 'horizontal' and moves point (x,y,0) in direction V by whatever is the
1052
 *               value if sin at this point.
1053 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1054 4fde55a0 Leszek Koltunski
 * @return       ID of the effect added, or -1 if we failed to add one.
1055
 */
1056 fa6c352d Leszek Koltunski
  public long wave(Data5D wave, Data3D center)
1057 4fde55a0 Leszek Koltunski
    {
1058 02ef26bc Leszek Koltunski
    return mV.add(EffectNames.WAVE, wave, center, null);
1059 4fde55a0 Leszek Koltunski
    }
1060
1061
///////////////////////////////////////////////////////////////////////////////////////////////////
1062
/**
1063
 * Directional, sinusoidal wave effect.
1064
 *
1065 421c2728 Leszek Koltunski
 * @param wave   see {@link DistortedEffects#wave(Data5D,Data3D)}
1066 fa6c352d Leszek Koltunski
 * @param center 3-dimensional Data that, at any given time, returns the Center of the Effect.
1067 4fde55a0 Leszek Koltunski
 * @param region Region that masks the Effect.
1068
 * @return       ID of the effect added, or -1 if we failed to add one.
1069
 */
1070 fa6c352d Leszek Koltunski
  public long wave(Data5D wave, Data3D center, Data4D region)
1071 4fde55a0 Leszek Koltunski
    {
1072
    return mV.add(EffectNames.WAVE, wave, center, region);
1073
    }
1074 d6e94c84 Leszek Koltunski
1075
///////////////////////////////////////////////////////////////////////////////////////////////////
1076
// Postprocess-based effects
1077
///////////////////////////////////////////////////////////////////////////////////////////////////
1078
/**
1079
 * Blur the object.
1080
 *
1081
 * @param radius The 'strength' if the effect, in pixels. 0 = no blur, 10 = when blurring a given pixel,
1082
 *               take into account 10 pixels in each direction.
1083
 * @return ID of the effect added, or -1 if we failed to add one.
1084
 */
1085 85cbbc5e Leszek Koltunski
  public long blur(Data1D radius)
1086 d6e94c84 Leszek Koltunski
    {
1087 85cbbc5e Leszek Koltunski
    return mP.add(EffectNames.BLUR, radius);
1088 d6e94c84 Leszek Koltunski
    }
1089 f2fe7e28 Leszek Koltunski
  }