Project

General

Profile

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

library / src / main / java / org / distorted / library / DistortedEffects.java @ 7170e4eb

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