Project

General

Profile

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

library / src / main / java / org / distorted / library / main / DistortedEffects.java @ fe82a979

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