Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffects.java @ 638b5b5c

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