Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffects.java @ 3fc9327a

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