Project

General

Profile

« Previous | Next » 

Revision b3618cb5

Added by Leszek Koltunski over 8 years ago

Beginnings of support for PostShader effects (SavePNG, SaveMP4)

View differences:

src/main/java/org/distorted/library/Distorted.java
32 32
   */
33 33
  public static final int CLONE_BITMAP  = 0x1;
34 34
  /**
35
   * When creating an instance of a DistortedObject from another instance, clone the Matrix Effects.
35
   * When creating an instance of a DistortedObject from another instance, clone the PreShader Effects.
36 36
   * <p>
37 37
   * This way we can have two different DistortedObjects with different Bitmaps behind them, both 
38 38
   * always displayed in exactly the same place on the screen. Applying any matrix-based effect to 
39 39
   * one of them automatically applies the effect to the other. Used in the copy constructor.
40 40
   */
41
  public static final int CLONE_MATRIX  = 0x2;
41
  public static final int CLONE_PRESHADER = 0x2;
42 42
  /**
43 43
   * When creating an instance of a DistortedObject from another instance, clone the Vertex Effects.
44 44
   * <p>
......
55 55
   * applies the effect to the other. Used in the copy constructor.
56 56
   */
57 57
  public static final int CLONE_FRAGMENT= 0x8;
58

  
59
  // Note: why no 'CLONE_POSTSHADER' constant? The only Postshader effects are the 'save to PNG file'
60
  // 'save to MP4 file'. Sharing those effects across multiple DistortedObject objects does not make any
61
  // sense - multiple Objects would then fight to get saved all to the same file.
62

  
58 63
  /**
59 64
   * When creating an instance of a DistortedNode from another instance, clone the children Nodes.
60 65
   * <p>
......
63 68
   */
64 69
  public static final int CLONE_CHILDREN= 0x10;
65 70
  /**
66
  * Constant used to represent a Matrix-based effect.
67
  */
68
  public static final int TYPE_MATR = 0x1;
71
   * Constant used to represent a PreShader-based effect.
72
   */
73
  public static final int TYPE_PRE  = 0x1;
69 74
  /**
70 75
   * Constant used to represent a Vertex-based effect.
71 76
   */
......
74 79
   * Constant used to represent a Fragment-based effect.
75 80
   */
76 81
  public static final int TYPE_FRAG = 0x4;
77
   
82
  /**
83
   * Constant used to represent a PostShader-based effect.
84
   */
85
  public static final int TYPE_POST = 0x8;
86

  
78 87
  private static final String TAG = Distorted.class.getSimpleName();
79 88
  private static boolean mInitialized = false;
80 89
  
......
351 360
    
352 361
    EffectListFragment.getUniforms(mProgramH);
353 362
    EffectListVertex.getUniforms(mProgramH);
354
    EffectListMatrix.getUniforms(mProgramH);
363
    EffectListPreShader.getUniforms(mProgramH);
355 364
    
356 365
    GLES20.glEnableVertexAttribArray(mPositionH);        
357 366
    GLES20.glEnableVertexAttribArray(mColorH);
......
388 397

  
389 398
    EffectListVertex.reset();
390 399
    EffectListFragment.reset();
391
    EffectListMatrix.reset();
400
    EffectListPreShader.reset();  // no need to reset PostShader stuff
401

  
392 402
    EffectMessageSender.stopSending();
393 403
   
394 404
    mInitialized = false;
......
408 418

  
409 419
///////////////////////////////////////////////////////////////////////////////////////////////////
410 420
/**
411
 * Returns the maximum number of Matrix effects.
421
 * Returns the maximum number of PreShader effects.
412 422
 *    
413
 * @return The maximum number of Matrix effects
423
 * @return The maximum number of PreShader effects
414 424
 */
415
  public static int getMaxMatrix()
425
  public static int getMaxPreShader()
416 426
    {
417
    return EffectListMatrix.getMax();  
427
    return EffectListPreShader.getMax();
418 428
    }
419 429
 
420 430
///////////////////////////////////////////////////////////////////////////////////////////////////
......
441 451
  
442 452
///////////////////////////////////////////////////////////////////////////////////////////////////
443 453
/**
444
 * Sets the maximum number of Matrix effects that can be applied to a single DistortedBitmap at one time.
454
 * Sets the maximum number of PreShader effects that can be applied to a single DistortedBitmap at one time.
445 455
 * This can fail if the value of 'max' is outside permitted range. 
446 456
 * 
447
 * @param max new maximum number of simultaneous Matrix Effects. Has to be a non-negative number not greater
457
 * @param max new maximum number of simultaneous PreShader Effects. Has to be a non-negative number not greater
448 458
 *            than Byte.MAX_VALUE 
449 459
 * @return <code>true</code> if operation was successful, <code>false</code> otherwise.
450 460
 */
451
  public static boolean setMaxMatrix(int max)
461
  public static boolean setMaxPreShader(int max)
452 462
    {
453
    return EffectListMatrix.setMax(max);  
463
    return EffectListPreShader.setMax(max);
454 464
    }
455 465
  
456 466
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/DistortedNode.java
300 300
 *     
301 301
 * @param node The DistortedNode to copy data from.
302 302
 * @param flags bit field composed of a subset of the following:
303
 *        {@link Distorted#CLONE_BITMAP},  {@link Distorted#CLONE_MATRIX}, {@link Distorted#CLONE_VERTEX},
303
 *        {@link Distorted#CLONE_BITMAP},  {@link Distorted#CLONE_PRESHADER}, {@link Distorted#CLONE_VERTEX},
304 304
 *        {@link Distorted#CLONE_FRAGMENT} and {@link Distorted#CLONE_CHILDREN}.
305 305
 *        For example flags = CLONE_BITMAP | CLONE_CHILDREN.
306 306
 */
src/main/java/org/distorted/library/DistortedObject.java
10 10
 */
11 11
public abstract class DistortedObject 
12 12
{ 
13
    static final int TYPE_NUM = 3;
13
    static final int TYPE_NUM = 4;
14 14
    private static final int TYPE_MASK= (1<<TYPE_NUM)-1;
15 15
    private static float[] mViewMatrix = new float[16];
16 16
   
17
    protected EffectListMatrix   mM;
18
    protected EffectListFragment mF;
19
    protected EffectListVertex   mV;
17
    protected EffectListPreShader  mM;
18
    protected EffectListFragment   mF;
19
    protected EffectListVertex     mV;
20
    protected EffectListPostShader mP;
20 21

  
21 22
    protected boolean matrixCloned, vertexCloned, fragmentCloned;
22 23
 
......
54 55
    
55 56
    protected void initializeEffectLists(DistortedObject d, int flags)
56 57
      {
57
      if( (flags & Distorted.CLONE_MATRIX) != 0 )
58
      if( (flags & Distorted.CLONE_PRESHADER) != 0 )
58 59
        {
59 60
        mM = d.mM;
60 61
        matrixCloned = true;
61 62
        } 
62 63
      else
63 64
        {
64
        mM = new EffectListMatrix(d);
65
        mM = new EffectListPreShader(d);
65 66
        matrixCloned = false;  
66 67
        }
67 68
    
......
86 87
        mF = new EffectListFragment(d);
87 88
        fragmentCloned = false;   
88 89
        }
90

  
91
      mP = new EffectListPostShader(d); // PostShader effects are never cloned.
89 92
      }
90 93
    
91 94
///////////////////////////////////////////////////////////////////////////////////////////////////
......
130 133
      mF.send();
131 134
       
132 135
      mGrid.draw();
136

  
137
      mP.send();
133 138
      }
134 139

  
135 140
///////////////////////////////////////////////////////////////////////////////////////////////////
......
151 156
      if( vertexCloned  ==false) mV.abortAll();
152 157
      if( fragmentCloned==false) mF.abortAll();
153 158

  
159
      mP.abortAll();
160

  
154 161
      mBmp          = null;
155 162
      mGrid         = null;
156 163
      mM            = null;
157 164
      mV            = null;
158 165
      mF            = null;
166
      mP            = null;
159 167
      mTextureDataH = null;
160 168
      }
161 169
 
......
184 192
   *
185 193
   * @param dc    Source object to create our object from
186 194
   * @param flags A bitmask of values specifying what to copy.
187
   *              For example, CLONE_BITMAP | CLONE_MATRIX.
195
   *              For example, CLONE_BITMAP | CLONE_PRESHADER.
188 196
   */
189 197
    public DistortedObject(DistortedObject dc, int flags)
190 198
      {
......
283 291
     mV.addListener(el);
284 292
     mF.addListener(el);
285 293
     mM.addListener(el);
294
     mP.addListener(el);
286 295
     }
287 296

  
288 297
///////////////////////////////////////////////////////////////////////////////////////////////////
......
296 305
     mV.removeListener(el);
297 306
     mF.removeListener(el);
298 307
     mM.removeListener(el);
308
     mP.removeListener(el);
299 309
     }
300 310
   
301 311
///////////////////////////////////////////////////////////////////////////////////////////////////
......
351 361
      mM.abortAll();
352 362
      mV.abortAll();
353 363
      mF.abortAll();
364
      mP.abortAll();
354 365
      }
355 366

  
356 367
///////////////////////////////////////////////////////////////////////////////////////////////////
357 368
/**
358 369
 * Aborts a subset of Effects.
359 370
 * 
360
 * @param mask Bitmask of the types of effects we want to abort, e.g. TYPE_MATR | TYPE_VERT | TYPE_FRAG.
371
 * @param mask Bitmask of the types of effects we want to abort, e.g. TYPE_PRE | TYPE_VERT | TYPE_FRAG.
361 372
 */
362 373
    public void abortAllEffects(int mask)
363 374
      {
364
      if( (mask & Distorted.TYPE_MATR) != 0 ) mM.abortAll();
375
      if( (mask & Distorted.TYPE_PRE ) != 0 ) mM.abortAll();
365 376
      if( (mask & Distorted.TYPE_VERT) != 0 ) mV.abortAll();
366 377
      if( (mask & Distorted.TYPE_FRAG) != 0 ) mF.abortAll();
378
      if( (mask & Distorted.TYPE_POST) != 0 ) mP.abortAll();
367 379
      }
368 380
    
369 381
///////////////////////////////////////////////////////////////////////////////////////////////////
......
377 389
      {
378 390
      switch( (int)(id&TYPE_MASK) )
379 391
        {
380
        case Distorted.TYPE_MATR: return mM.removeByID(id>>TYPE_NUM);
392
        case Distorted.TYPE_PRE : return mM.removeByID(id>>TYPE_NUM);
381 393
        case Distorted.TYPE_VERT: return mV.removeByID(id>>TYPE_NUM);
382 394
        case Distorted.TYPE_FRAG: return mF.removeByID(id>>TYPE_NUM);
395
        case Distorted.TYPE_POST: return mP.removeByID(id>>TYPE_NUM);
383 396
        default                 : return false;
384 397
        }
385 398
      }
......
395 408
      {
396 409
      switch(effectType.getType())
397 410
        {
398
        case Distorted.TYPE_MATR: return mM.removeByType(effectType);
411
        case Distorted.TYPE_PRE : return mM.removeByType(effectType);
399 412
        case Distorted.TYPE_VERT: return mV.removeByType(effectType);
400 413
        case Distorted.TYPE_FRAG: return mF.removeByType(effectType);
414
        case Distorted.TYPE_POST: return mP.removeByType(effectType);
401 415
        default                 : return false;
402 416
        }
403 417
      }
......
414 428
      {
415 429
      switch( (int)(id&TYPE_MASK) )
416 430
        {
417
        case Distorted.TYPE_MATR: return mM.printByID(id>>TYPE_NUM);
431
        case Distorted.TYPE_PRE : return mM.printByID(id>>TYPE_NUM);
418 432
        case Distorted.TYPE_VERT: return mV.printByID(id>>TYPE_NUM);
419 433
        case Distorted.TYPE_FRAG: return mF.printByID(id>>TYPE_NUM);
434
        case Distorted.TYPE_POST: return mP.printByID(id>>TYPE_NUM);
420 435
        default                 : return false;
421 436
        }
422 437
      }
src/main/java/org/distorted/library/EffectList.java
8 8
  {
9 9
  protected static final int DEFAULT_NUM_EFFECTS = 5;
10 10
  
11
  protected static final int MATRIX  =0;
12
  protected static final int VERTEX  =1;
13
  protected static final int FRAGMENT=2;
14
  
11
  protected static final int PRESHADER =0;
12
  protected static final int VERTEX    =1;
13
  protected static final int FRAGMENT  =2;
14

  
15 15
  protected byte mNumEffects;   // number of effects at the moment
16 16
  protected long mTotalEffects; // total number of effects ever created
17 17
  
......
37 37
  
38 38
  static
39 39
    {
40
    mMax[MATRIX]   = DEFAULT_NUM_EFFECTS;
40
    mMax[PRESHADER]= DEFAULT_NUM_EFFECTS;
41 41
    mMax[VERTEX]   = DEFAULT_NUM_EFFECTS;
42 42
    mMax[FRAGMENT] = DEFAULT_NUM_EFFECTS;
43 43
    }
......
84 84

  
85 85
  void addListener(EffectListener el)
86 86
    {
87
    if( mNumListeners==0 ) mListeners = new Vector<>(2,2);
87
    if( mListeners==null ) mListeners = new Vector<>(2,2);
88 88
   
89 89
    mListeners.add(el);
90 90
    mNumListeners++;
......
105 105

  
106 106
  static void reset()
107 107
    {
108
    mMax[MATRIX]   = DEFAULT_NUM_EFFECTS;
108
    mMax[PRESHADER]= DEFAULT_NUM_EFFECTS;
109 109
    mMax[VERTEX]   = DEFAULT_NUM_EFFECTS;
110 110
    mMax[FRAGMENT] = DEFAULT_NUM_EFFECTS;
111 111
   
src/main/java/org/distorted/library/EffectListFragment.java
14 14
  
15 15
///////////////////////////////////////////////////////////////////////////////////////////////////
16 16
   
17
  public EffectListFragment(DistortedObject bmp) 
17
  public EffectListFragment(DistortedObject obj)
18 18
    { 
19
    super(bmp,NUM_UNIFORMS,FRAGMENT);
19
    super(obj,NUM_UNIFORMS,FRAGMENT);
20 20
   
21 21
    if( mMax[FRAGMENT]>0 )
22 22
      {
src/main/java/org/distorted/library/EffectListMatrix.java
1
package org.distorted.library;
2

  
3
import android.opengl.GLES20;
4
import android.opengl.Matrix;
5

  
6
///////////////////////////////////////////////////////////////////////////////////////////////////
7

  
8
class EffectListMatrix extends EffectList
9
  {   
10
  private static final int NUM_UNIFORMS = 7; 
11
  private static float[] mMVPMatrix= new float[16];
12
  private static float[] mTmpMatrix= new float[16];
13
  
14
  private static int mBmpDH;      // This is a handle to half a bitmap dimensions
15
  private static int mDepthH;     // Handle to the max Depth, i.e (farplane-nearplane)/2
16
  private static int mMVPMatrixH; // pass in the transformation matrix
17
  private static int mMVMatrixH;  // pass in the modelview matrix.
18
  
19
///////////////////////////////////////////////////////////////////////////////////////////////////
20
   
21
  public EffectListMatrix(DistortedObject bmp) 
22
    { 
23
    super(bmp,NUM_UNIFORMS,MATRIX);
24
    }
25

  
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27

  
28
  private static void multiplyByQuat(float[] matrix, float X, float Y, float Z, float W)
29
    {
30
    float xx= X * X;
31
    float xy= X * Y;
32
    float xz= X * Z;
33
    float xw= X * W;
34
    float yy= Y * Y;
35
    float yz= Y * Z;
36
    float yw= Y * W;
37
    float zz= Z * Z;
38
    float zw= Z * W;
39

  
40
    mTmpMatrix[0]  = 1 - 2 * ( yy + zz );
41
    mTmpMatrix[1]  =     2 * ( xy - zw );
42
    mTmpMatrix[2]  =     2 * ( xz + yw );
43
    mTmpMatrix[4]  =     2 * ( xy + zw );
44
    mTmpMatrix[5]  = 1 - 2 * ( xx + zz );
45
    mTmpMatrix[6]  =     2 * ( yz - xw );
46
    mTmpMatrix[8]  =     2 * ( xz - yw );
47
    mTmpMatrix[9]  =     2 * ( yz + xw );
48
    mTmpMatrix[10] = 1 - 2 * ( xx + yy );
49
    mTmpMatrix[3]  = mTmpMatrix[7] = mTmpMatrix[11] = mTmpMatrix[12] = mTmpMatrix[13] = mTmpMatrix[14] = 0;
50
    mTmpMatrix[15] = 1;
51
    
52
    Matrix.multiplyMM(mMVPMatrix, 0, matrix, 0, mTmpMatrix, 0);  
53
    for(int j=0; j<16; j++) matrix[j] = mMVPMatrix[j];   
54
    }
55
  
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57
// Only max Byte.MAX_VALUE concurrent effects per bitmap.
58
// If you want more, change type of the mNumEffects, mIDIndex and mFreeIndexes variables to shorts.
59
  
60
  static boolean setMax(int m)
61
    {
62
    if( (mCreated==false && !Distorted.isInitialized()) || m<=mMax[MATRIX] ) 
63
      {
64
           if( m<0              ) m = 0;
65
      else if( m>Byte.MAX_VALUE ) m = Byte.MAX_VALUE;
66
      
67
      mMax[MATRIX] = m;
68
      return true;
69
      }
70
   
71
    return false;
72
    }
73
 
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

  
76
  static int getMax()
77
    {
78
    return mMax[MATRIX];
79
    }
80

  
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

  
83
  static void getUniforms(int mProgramH)
84
    {
85
    mBmpDH     = GLES20.glGetUniformLocation(mProgramH, "u_bmpD");
86
    mDepthH    = GLES20.glGetUniformLocation(mProgramH, "u_Depth");
87
    mMVPMatrixH= GLES20.glGetUniformLocation(mProgramH, "u_MVPMatrix");
88
    mMVMatrixH = GLES20.glGetUniformLocation(mProgramH, "u_MVMatrix"); 
89
    }
90

  
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92
  
93
  synchronized void compute(long currTime) 
94
    {
95
    if( currTime==mTime ) return;
96
    if( mTime==0 ) mTime = currTime;
97
    long step = (currTime-mTime);
98
   
99
    for(int i=0; i<mNumEffects; i++)
100
      {
101
      if( mInterI[i]==null ) continue;    
102
           
103
      if( mInterP[i]!=null ) 
104
        {
105
        mInterP[i].interpolateMain(mUniforms, NUM_UNIFORMS*i, mCurrentDuration[i]);
106
        }
107
        
108
      if( mInterI[i].interpolateMain(mUniforms ,NUM_UNIFORMS*i+3, mCurrentDuration[i], step) )      
109
        {   
110
        for(int j=0; j<mNumListeners; j++)   
111
          EffectMessageSender.newMessage( mListeners.elementAt(j),
112
                                          EffectMessage.EFFECT_FINISHED, 
113
                                         (mID[i]<<DistortedObject.TYPE_NUM)+Distorted.TYPE_MATR, 
114
                                          mType[i], 
115
                                          mBitmapID); 
116
       
117
        if( EffectNames.isUnity(mType[i], mUniforms, NUM_UNIFORMS*i+3) )
118
          {  
119
          remove(i);
120
          i--;
121
          continue;
122
          }
123
        }
124
    
125
      mCurrentDuration[i] += step;
126
      }
127
     
128
    mTime = currTime;  
129
    }  
130

  
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

  
133
  protected void moveEffect(int index)
134
    {
135
    mUniforms[NUM_UNIFORMS*index  ] = mUniforms[NUM_UNIFORMS*(index+1)  ];
136
    mUniforms[NUM_UNIFORMS*index+1] = mUniforms[NUM_UNIFORMS*(index+1)+1];
137
    mUniforms[NUM_UNIFORMS*index+2] = mUniforms[NUM_UNIFORMS*(index+1)+2];
138
    mUniforms[NUM_UNIFORMS*index+3] = mUniforms[NUM_UNIFORMS*(index+1)+3];
139
    mUniforms[NUM_UNIFORMS*index+4] = mUniforms[NUM_UNIFORMS*(index+1)+4];
140
    mUniforms[NUM_UNIFORMS*index+5] = mUniforms[NUM_UNIFORMS*(index+1)+5];
141
    mUniforms[NUM_UNIFORMS*index+6] = mUniforms[NUM_UNIFORMS*(index+1)+6];
142
    }
143

  
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145
// here construct the ModelView Matrix
146

  
147
  synchronized void send(float[] viewMatrix, DistortedProjection dp) 
148
    {
149
    Matrix.setIdentityM(viewMatrix, 0);
150
    Matrix.translateM(viewMatrix, 0, -dp.width/2, dp.height/2, -dp.distance);
151
    
152
    float x,y,z, sx,sy,sz=1.0f;
153
   
154
    for(int i=0; i<mNumEffects; i++)
155
      {
156
      if (mType[i] == EffectNames.ROTATE.ordinal() )
157
        {
158
        x = mUniforms[NUM_UNIFORMS*i  ];
159
        y = mUniforms[NUM_UNIFORMS*i+1];
160
        z = mUniforms[NUM_UNIFORMS*i+2];
161
     
162
        Matrix.translateM(viewMatrix, 0, x,-y, z); 
163
        Matrix.rotateM( viewMatrix, 0, mUniforms[NUM_UNIFORMS*i+3], mUniforms[NUM_UNIFORMS*i+4], mUniforms[NUM_UNIFORMS*i+5], mUniforms[NUM_UNIFORMS*i+6]);  
164
        Matrix.translateM(viewMatrix, 0,-x, y,-z);  
165
        }
166
      else if(mType[i] == EffectNames.QUATERNION.ordinal() )
167
        {
168
        x = mUniforms[NUM_UNIFORMS*i  ];
169
        y = mUniforms[NUM_UNIFORMS*i+1];
170
        z = mUniforms[NUM_UNIFORMS*i+2];
171
     	
172
        Matrix.translateM(viewMatrix, 0, x,-y, z); 
173
        multiplyByQuat(viewMatrix, mUniforms[NUM_UNIFORMS*i+3], mUniforms[NUM_UNIFORMS*i+4], mUniforms[NUM_UNIFORMS*i+5], mUniforms[NUM_UNIFORMS*i+6]);
174
        Matrix.translateM(viewMatrix, 0,-x, y,-z);  
175
        }
176
      else if(mType[i] == EffectNames.MOVE.ordinal() )
177
        {
178
        sx = mUniforms[NUM_UNIFORMS*i+3];   
179
        sy = mUniforms[NUM_UNIFORMS*i+4];   
180
        sz = mUniforms[NUM_UNIFORMS*i+5];   
181
        
182
        Matrix.translateM(viewMatrix, 0, sx,-sy, sz);   
183
        }
184
      else if(mType[i] == EffectNames.SCALE.ordinal() )
185
        {
186
        sx = mUniforms[NUM_UNIFORMS*i+3];   
187
        sy = mUniforms[NUM_UNIFORMS*i+4];   
188
        sz = mUniforms[NUM_UNIFORMS*i+5];   
189

  
190
        Matrix.scaleM(viewMatrix, 0, sx, sy, sz);  
191
        }
192
      else if(mType[i] == EffectNames.SHEAR.ordinal() )
193
        {
194
        x  = mUniforms[NUM_UNIFORMS*i  ];
195
        y  = mUniforms[NUM_UNIFORMS*i+1];
196
        z  = mUniforms[NUM_UNIFORMS*i+2];
197
        
198
        sx = mUniforms[NUM_UNIFORMS*i+3];   
199
        sy = mUniforms[NUM_UNIFORMS*i+4];   
200
        sz = mUniforms[NUM_UNIFORMS*i+5];   
201
        
202
        Matrix.translateM(viewMatrix, 0, x,-y, z); 
203
      
204
        viewMatrix[4] += sx*viewMatrix[0]; // Multiply viewMatrix by 1 x 0 0 , i.e. X-shear. TODO: change this so it is symmetric w respect to all the axis.
205
        viewMatrix[5] += sx*viewMatrix[1]; //                        0 1 0 0 
206
        viewMatrix[6] += sx*viewMatrix[2]; //                        0 0 1 0
207
        viewMatrix[7] += sx*viewMatrix[3]; //                        0 0 0 1
208
      
209
        viewMatrix[0] += sy*viewMatrix[4]; // Multiply viewMatrix by 1 0 0 0 , i.e. Y-shear. TODO: change this so it is symmetric w respect to all the axis.
210
        viewMatrix[1] += sy*viewMatrix[5]; //                        y 1 0 0
211
        viewMatrix[2] += sy*viewMatrix[6]; //                        0 0 1 0
212
        viewMatrix[3] += sy*viewMatrix[7]; //                        0 0 0 1      
213
      
214
        // TODO: implement Z-shear.
215
        
216
        Matrix.translateM(viewMatrix, 0,-x, y, -z);
217
        }
218
      }
219
   
220
    Matrix.translateM(viewMatrix, 0, mObjHalfX,-mObjHalfY, -mObjHalfZ);
221
    Matrix.multiplyMM(mMVPMatrix, 0, dp.projectionMatrix, 0, viewMatrix, 0);
222
    
223
    GLES20.glUniform3f( mBmpDH , mObjHalfX, mObjHalfY, mObjHalfZ);
224
    GLES20.glUniform1f( mDepthH, dp.depth);   
225
    GLES20.glUniformMatrix4fv(mMVMatrixH , 1, false, viewMatrix, 0);
226
    GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix, 0);
227
    }
228

  
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230
// here construct the ModelView Matrix, but without any effects
231

  
232
  synchronized void sendNoEffects(DistortedProjection dp) 
233
    {
234
    Matrix.setIdentityM(mTmpMatrix, 0);
235
    Matrix.translateM(mTmpMatrix, 0, mObjHalfX-dp.width/2, dp.height/2-mObjHalfY, mObjHalfZ-dp.distance);
236
    Matrix.multiplyMM(mMVPMatrix, 0, dp.projectionMatrix, 0, mTmpMatrix, 0);
237
    
238
    GLES20.glUniform3f( mBmpDH , mObjHalfX, mObjHalfY, mObjHalfZ);
239
    GLES20.glUniform1f( mDepthH, dp.depth);  
240
    GLES20.glUniformMatrix4fv(mMVMatrixH , 1, false, mTmpMatrix, 0);
241
    GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix, 0);
242
    }
243

  
244
///////////////////////////////////////////////////////////////////////////////////////////////////
245
  
246
  synchronized long add(EffectNames eln, Interpolator3D p, Interpolator i)
247
    {
248
    if( mMax[MATRIX]>mNumEffects )
249
      {
250
      mInterP[mNumEffects] = p;
251
      mInterI[mNumEffects] = i;
252
      
253
      return addBase(eln);
254
      }
255
      
256
    return -1;
257
    }
258

  
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260
  
261
  synchronized long add(EffectNames eln, float x, float y, float z, Interpolator i)
262
    {
263
    if( mMax[MATRIX]>mNumEffects )
264
      {
265
      mInterP[mNumEffects] = null;
266
      mInterI[mNumEffects] = i;
267
      
268
      mUniforms[NUM_UNIFORMS*mNumEffects  ] = x;
269
      mUniforms[NUM_UNIFORMS*mNumEffects+1] = y;
270
      mUniforms[NUM_UNIFORMS*mNumEffects+2] = z;
271
            
272
      return addBase(eln);
273
      }
274
      
275
    return -1;
276
    }
277

  
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279
  
280
  synchronized long add(EffectNames eln, float x, float y, float z, Interpolator1D i, float aX, float aY, float aZ)
281
    {
282
    if( mMax[MATRIX]>mNumEffects )
283
      {
284
      mInterP[mNumEffects] = null;
285
      mInterI[mNumEffects] = i;
286
      
287
      mUniforms[NUM_UNIFORMS*mNumEffects  ] = x;
288
      mUniforms[NUM_UNIFORMS*mNumEffects+1] = y;
289
      mUniforms[NUM_UNIFORMS*mNumEffects+2] = z;
290
      
291
      mUniforms[NUM_UNIFORMS*mNumEffects+4] = aX;
292
      mUniforms[NUM_UNIFORMS*mNumEffects+5] = aY;  
293
      mUniforms[NUM_UNIFORMS*mNumEffects+6] = aZ;  
294
      
295
      return addBase(eln);
296
      }
297
      
298
    return -1;
299
    }
300

  
301
///////////////////////////////////////////////////////////////////////////////////////////////////
302
  
303
  synchronized long add(EffectNames eln, Interpolator3D p, Interpolator1D i, float aX, float aY, float aZ)
304
    {
305
    if( mMax[MATRIX]>mNumEffects )
306
      {
307
      mInterP[mNumEffects] = p;
308
      mInterI[mNumEffects] = i;
309
      
310
      mUniforms[NUM_UNIFORMS*mNumEffects+4] = aX;
311
      mUniforms[NUM_UNIFORMS*mNumEffects+5] = aY;  
312
      mUniforms[NUM_UNIFORMS*mNumEffects+6] = aZ;  
313
      
314
      return addBase(eln);
315
      }
316
      
317
    return -1;
318
    }
319
  
320
///////////////////////////////////////////////////////////////////////////////////////////////////
321
  
322
  synchronized long add(EffectNames eln, float x, float y, float z, float aA, float aX, float aY, float aZ)
323
    {
324
    if( mMax[MATRIX]>mNumEffects )
325
      {
326
      mInterP[mNumEffects] = null; 
327
      mInterI[mNumEffects] = null;
328
      
329
      mUniforms[NUM_UNIFORMS*mNumEffects  ] =  x;
330
      mUniforms[NUM_UNIFORMS*mNumEffects+1] =  y;  
331
      mUniforms[NUM_UNIFORMS*mNumEffects+2] =  z;  
332
      mUniforms[NUM_UNIFORMS*mNumEffects+3] = aA;  
333
      mUniforms[NUM_UNIFORMS*mNumEffects+4] = aX;
334
      mUniforms[NUM_UNIFORMS*mNumEffects+5] = aY;  
335
      mUniforms[NUM_UNIFORMS*mNumEffects+6] = aZ;  
336
      
337
      return addBase(eln);   
338
      }
339
      
340
    return -1;
341
    }
342

  
343
///////////////////////////////////////////////////////////////////////////////////////////////////
344
// end of VertexEffect  
345
  }
src/main/java/org/distorted/library/EffectListPostShader.java
1
package org.distorted.library;
2

  
3
///////////////////////////////////////////////////////////////////////////////////////////////////
4

  
5
import java.util.Vector;
6

  
7
/**
8
 * Do NOT base this on EffectList - this is an entirely different animal than the first 3 EffectLists.
9
 * The Effects in here will be executed after all the shaders have been executed - thus there are no
10
 * uniforms to send, no real queues to maintain.
11
 * <p>
12
 * Only 2 effects here ATM:
13
 * - save current Surface to a PNG file
14
 * - save current animation to a .MP4 file
15
 *
16
 * In contrast to the other EffectLists, only one instance of each allowed at any given moment - thus
17
 * this is not even a real EffectList, it is named so only for consistency with the others.
18
 */
19
public class EffectListPostShader
20
  {
21
  private Vector<EffectListener> mListeners =null;
22
  private int mNumListeners=0;  // ==mListeners.length(), but we only create mListeners if the first one gets added
23

  
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25

  
26
  public EffectListPostShader(DistortedObject obj)
27
    {
28

  
29
    }
30

  
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

  
33
  synchronized void send()
34
    {
35

  
36
    }
37

  
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

  
40
  synchronized void abortAll()
41
    {
42

  
43
    }
44

  
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

  
47
  void addListener(EffectListener el)
48
    {
49
    if( mListeners==null ) mListeners = new Vector<>(2,2);
50

  
51
    mListeners.add(el);
52
    mNumListeners++;
53
    }
54

  
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

  
57
  void removeListener(EffectListener el)
58
    {
59
    if( mNumListeners>0 )
60
      {
61
      mListeners.remove(el);
62
      mNumListeners--;
63
      }
64
    }
65

  
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

  
68
  synchronized boolean removeByID(long id)
69
    {
70
    //....
71

  
72
    return false;
73
    }
74

  
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

  
77
  synchronized boolean removeByType(EffectNames effect)
78
    {
79
    // ...
80

  
81
    return false;
82
    }
83

  
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

  
86
  protected boolean printByID(long id)
87
    {
88
    return false;
89
    }
90

  
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

  
93
  synchronized long add(EffectNames eln, String filename)
94
    {
95
    return 0;
96
    }
97
  }
src/main/java/org/distorted/library/EffectListPreShader.java
1
package org.distorted.library;
2

  
3
import android.opengl.GLES20;
4
import android.opengl.Matrix;
5

  
6
///////////////////////////////////////////////////////////////////////////////////////////////////
7

  
8
class EffectListPreShader extends EffectList
9
  {   
10
  private static final int NUM_UNIFORMS = 7; 
11
  private static float[] mMVPMatrix= new float[16];
12
  private static float[] mTmpMatrix= new float[16];
13
  
14
  private static int mBmpDH;      // This is a handle to half a bitmap dimensions
15
  private static int mDepthH;     // Handle to the max Depth, i.e (farplane-nearplane)/2
16
  private static int mMVPMatrixH; // pass in the transformation matrix
17
  private static int mMVMatrixH;  // pass in the modelview matrix.
18
  
19
///////////////////////////////////////////////////////////////////////////////////////////////////
20
   
21
  public EffectListPreShader(DistortedObject obj)
22
    { 
23
    super(obj,NUM_UNIFORMS, PRESHADER);
24
    }
25

  
26
///////////////////////////////////////////////////////////////////////////////////////////////////
27

  
28
  private static void multiplyByQuat(float[] matrix, float X, float Y, float Z, float W)
29
    {
30
    float xx= X * X;
31
    float xy= X * Y;
32
    float xz= X * Z;
33
    float xw= X * W;
34
    float yy= Y * Y;
35
    float yz= Y * Z;
36
    float yw= Y * W;
37
    float zz= Z * Z;
38
    float zw= Z * W;
39

  
40
    mTmpMatrix[0]  = 1 - 2 * ( yy + zz );
41
    mTmpMatrix[1]  =     2 * ( xy - zw );
42
    mTmpMatrix[2]  =     2 * ( xz + yw );
43
    mTmpMatrix[4]  =     2 * ( xy + zw );
44
    mTmpMatrix[5]  = 1 - 2 * ( xx + zz );
45
    mTmpMatrix[6]  =     2 * ( yz - xw );
46
    mTmpMatrix[8]  =     2 * ( xz - yw );
47
    mTmpMatrix[9]  =     2 * ( yz + xw );
48
    mTmpMatrix[10] = 1 - 2 * ( xx + yy );
49
    mTmpMatrix[3]  = mTmpMatrix[7] = mTmpMatrix[11] = mTmpMatrix[12] = mTmpMatrix[13] = mTmpMatrix[14] = 0;
50
    mTmpMatrix[15] = 1;
51
    
52
    Matrix.multiplyMM(mMVPMatrix, 0, matrix, 0, mTmpMatrix, 0);  
53
    for(int j=0; j<16; j++) matrix[j] = mMVPMatrix[j];   
54
    }
55
  
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57
// Only max Byte.MAX_VALUE concurrent effects per bitmap.
58
// If you want more, change type of the mNumEffects, mIDIndex and mFreeIndexes variables to shorts.
59
  
60
  static boolean setMax(int m)
61
    {
62
    if( (mCreated==false && !Distorted.isInitialized()) || m<=mMax[PRESHADER] )
63
      {
64
           if( m<0              ) m = 0;
65
      else if( m>Byte.MAX_VALUE ) m = Byte.MAX_VALUE;
66
      
67
      mMax[PRESHADER] = m;
68
      return true;
69
      }
70
   
71
    return false;
72
    }
73
 
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

  
76
  static int getMax()
77
    {
78
    return mMax[PRESHADER];
79
    }
80

  
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

  
83
  static void getUniforms(int mProgramH)
84
    {
85
    mBmpDH     = GLES20.glGetUniformLocation(mProgramH, "u_bmpD");
86
    mDepthH    = GLES20.glGetUniformLocation(mProgramH, "u_Depth");
87
    mMVPMatrixH= GLES20.glGetUniformLocation(mProgramH, "u_MVPMatrix");
88
    mMVMatrixH = GLES20.glGetUniformLocation(mProgramH, "u_MVMatrix"); 
89
    }
90

  
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92
  
93
  synchronized void compute(long currTime) 
94
    {
95
    if( currTime==mTime ) return;
96
    if( mTime==0 ) mTime = currTime;
97
    long step = (currTime-mTime);
98
   
99
    for(int i=0; i<mNumEffects; i++)
100
      {
101
      if( mInterI[i]==null ) continue;    
102
           
103
      if( mInterP[i]!=null ) 
104
        {
105
        mInterP[i].interpolateMain(mUniforms, NUM_UNIFORMS*i, mCurrentDuration[i]);
106
        }
107
        
108
      if( mInterI[i].interpolateMain(mUniforms ,NUM_UNIFORMS*i+3, mCurrentDuration[i], step) )      
109
        {   
110
        for(int j=0; j<mNumListeners; j++)   
111
          EffectMessageSender.newMessage( mListeners.elementAt(j),
112
                                          EffectMessage.EFFECT_FINISHED, 
113
                                         (mID[i]<<DistortedObject.TYPE_NUM)+Distorted.TYPE_PRE,
114
                                          mType[i], 
115
                                          mBitmapID); 
116
       
117
        if( EffectNames.isUnity(mType[i], mUniforms, NUM_UNIFORMS*i+3) )
118
          {  
119
          remove(i);
120
          i--;
121
          continue;
122
          }
123
        }
124
    
125
      mCurrentDuration[i] += step;
126
      }
127
     
128
    mTime = currTime;  
129
    }  
130

  
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

  
133
  protected void moveEffect(int index)
134
    {
135
    mUniforms[NUM_UNIFORMS*index  ] = mUniforms[NUM_UNIFORMS*(index+1)  ];
136
    mUniforms[NUM_UNIFORMS*index+1] = mUniforms[NUM_UNIFORMS*(index+1)+1];
137
    mUniforms[NUM_UNIFORMS*index+2] = mUniforms[NUM_UNIFORMS*(index+1)+2];
138
    mUniforms[NUM_UNIFORMS*index+3] = mUniforms[NUM_UNIFORMS*(index+1)+3];
139
    mUniforms[NUM_UNIFORMS*index+4] = mUniforms[NUM_UNIFORMS*(index+1)+4];
140
    mUniforms[NUM_UNIFORMS*index+5] = mUniforms[NUM_UNIFORMS*(index+1)+5];
141
    mUniforms[NUM_UNIFORMS*index+6] = mUniforms[NUM_UNIFORMS*(index+1)+6];
142
    }
143

  
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145
// here construct the ModelView Matrix
146

  
147
  synchronized void send(float[] viewMatrix, DistortedProjection dp) 
148
    {
149
    Matrix.setIdentityM(viewMatrix, 0);
150
    Matrix.translateM(viewMatrix, 0, -dp.width/2, dp.height/2, -dp.distance);
151
    
152
    float x,y,z, sx,sy,sz=1.0f;
153
   
154
    for(int i=0; i<mNumEffects; i++)
155
      {
156
      if (mType[i] == EffectNames.ROTATE.ordinal() )
157
        {
158
        x = mUniforms[NUM_UNIFORMS*i  ];
159
        y = mUniforms[NUM_UNIFORMS*i+1];
160
        z = mUniforms[NUM_UNIFORMS*i+2];
161
     
162
        Matrix.translateM(viewMatrix, 0, x,-y, z); 
163
        Matrix.rotateM( viewMatrix, 0, mUniforms[NUM_UNIFORMS*i+3], mUniforms[NUM_UNIFORMS*i+4], mUniforms[NUM_UNIFORMS*i+5], mUniforms[NUM_UNIFORMS*i+6]);  
164
        Matrix.translateM(viewMatrix, 0,-x, y,-z);  
165
        }
166
      else if(mType[i] == EffectNames.QUATERNION.ordinal() )
167
        {
168
        x = mUniforms[NUM_UNIFORMS*i  ];
169
        y = mUniforms[NUM_UNIFORMS*i+1];
170
        z = mUniforms[NUM_UNIFORMS*i+2];
171
     	
172
        Matrix.translateM(viewMatrix, 0, x,-y, z); 
173
        multiplyByQuat(viewMatrix, mUniforms[NUM_UNIFORMS*i+3], mUniforms[NUM_UNIFORMS*i+4], mUniforms[NUM_UNIFORMS*i+5], mUniforms[NUM_UNIFORMS*i+6]);
174
        Matrix.translateM(viewMatrix, 0,-x, y,-z);  
175
        }
176
      else if(mType[i] == EffectNames.MOVE.ordinal() )
177
        {
178
        sx = mUniforms[NUM_UNIFORMS*i+3];   
179
        sy = mUniforms[NUM_UNIFORMS*i+4];   
180
        sz = mUniforms[NUM_UNIFORMS*i+5];   
181
        
182
        Matrix.translateM(viewMatrix, 0, sx,-sy, sz);   
183
        }
184
      else if(mType[i] == EffectNames.SCALE.ordinal() )
185
        {
186
        sx = mUniforms[NUM_UNIFORMS*i+3];   
187
        sy = mUniforms[NUM_UNIFORMS*i+4];   
188
        sz = mUniforms[NUM_UNIFORMS*i+5];   
189

  
190
        Matrix.scaleM(viewMatrix, 0, sx, sy, sz);  
191
        }
192
      else if(mType[i] == EffectNames.SHEAR.ordinal() )
193
        {
194
        x  = mUniforms[NUM_UNIFORMS*i  ];
195
        y  = mUniforms[NUM_UNIFORMS*i+1];
196
        z  = mUniforms[NUM_UNIFORMS*i+2];
197
        
198
        sx = mUniforms[NUM_UNIFORMS*i+3];   
199
        sy = mUniforms[NUM_UNIFORMS*i+4];   
200
        sz = mUniforms[NUM_UNIFORMS*i+5];   
201
        
202
        Matrix.translateM(viewMatrix, 0, x,-y, z); 
203
      
204
        viewMatrix[4] += sx*viewMatrix[0]; // Multiply viewMatrix by 1 x 0 0 , i.e. X-shear. TODO: change this so it is symmetric w respect to all the axis.
205
        viewMatrix[5] += sx*viewMatrix[1]; //                        0 1 0 0 
206
        viewMatrix[6] += sx*viewMatrix[2]; //                        0 0 1 0
207
        viewMatrix[7] += sx*viewMatrix[3]; //                        0 0 0 1
208
      
209
        viewMatrix[0] += sy*viewMatrix[4]; // Multiply viewMatrix by 1 0 0 0 , i.e. Y-shear. TODO: change this so it is symmetric w respect to all the axis.
210
        viewMatrix[1] += sy*viewMatrix[5]; //                        y 1 0 0
211
        viewMatrix[2] += sy*viewMatrix[6]; //                        0 0 1 0
212
        viewMatrix[3] += sy*viewMatrix[7]; //                        0 0 0 1      
213
      
214
        // TODO: implement Z-shear.
215
        
216
        Matrix.translateM(viewMatrix, 0,-x, y, -z);
217
        }
218
      }
219
   
220
    Matrix.translateM(viewMatrix, 0, mObjHalfX,-mObjHalfY, -mObjHalfZ);
221
    Matrix.multiplyMM(mMVPMatrix, 0, dp.projectionMatrix, 0, viewMatrix, 0);
222
    
223
    GLES20.glUniform3f( mBmpDH , mObjHalfX, mObjHalfY, mObjHalfZ);
224
    GLES20.glUniform1f( mDepthH, dp.depth);   
225
    GLES20.glUniformMatrix4fv(mMVMatrixH , 1, false, viewMatrix, 0);
226
    GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix, 0);
227
    }
228

  
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230
// here construct the ModelView Matrix, but without any effects
231

  
232
  synchronized void sendNoEffects(DistortedProjection dp) 
233
    {
234
    Matrix.setIdentityM(mTmpMatrix, 0);
235
    Matrix.translateM(mTmpMatrix, 0, mObjHalfX-dp.width/2, dp.height/2-mObjHalfY, mObjHalfZ-dp.distance);
236
    Matrix.multiplyMM(mMVPMatrix, 0, dp.projectionMatrix, 0, mTmpMatrix, 0);
237
    
238
    GLES20.glUniform3f( mBmpDH , mObjHalfX, mObjHalfY, mObjHalfZ);
239
    GLES20.glUniform1f( mDepthH, dp.depth);  
240
    GLES20.glUniformMatrix4fv(mMVMatrixH , 1, false, mTmpMatrix, 0);
241
    GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix, 0);
242
    }
243

  
244
///////////////////////////////////////////////////////////////////////////////////////////////////
245
  
246
  synchronized long add(EffectNames eln, Interpolator3D p, Interpolator i)
247
    {
248
    if( mMax[PRESHADER]>mNumEffects )
249
      {
250
      mInterP[mNumEffects] = p;
251
      mInterI[mNumEffects] = i;
252
      
253
      return addBase(eln);
254
      }
255
      
256
    return -1;
257
    }
258

  
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260
  
261
  synchronized long add(EffectNames eln, float x, float y, float z, Interpolator i)
262
    {
263
    if( mMax[PRESHADER]>mNumEffects )
264
      {
265
      mInterP[mNumEffects] = null;
266
      mInterI[mNumEffects] = i;
267
      
268
      mUniforms[NUM_UNIFORMS*mNumEffects  ] = x;
269
      mUniforms[NUM_UNIFORMS*mNumEffects+1] = y;
270
      mUniforms[NUM_UNIFORMS*mNumEffects+2] = z;
271
            
272
      return addBase(eln);
273
      }
274
      
275
    return -1;
276
    }
277

  
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279
  
280
  synchronized long add(EffectNames eln, float x, float y, float z, Interpolator1D i, float aX, float aY, float aZ)
281
    {
282
    if( mMax[PRESHADER]>mNumEffects )
283
      {
284
      mInterP[mNumEffects] = null;
285
      mInterI[mNumEffects] = i;
286
      
287
      mUniforms[NUM_UNIFORMS*mNumEffects  ] = x;
288
      mUniforms[NUM_UNIFORMS*mNumEffects+1] = y;
289
      mUniforms[NUM_UNIFORMS*mNumEffects+2] = z;
290
      
291
      mUniforms[NUM_UNIFORMS*mNumEffects+4] = aX;
292
      mUniforms[NUM_UNIFORMS*mNumEffects+5] = aY;  
293
      mUniforms[NUM_UNIFORMS*mNumEffects+6] = aZ;  
294
      
295
      return addBase(eln);
296
      }
297
      
298
    return -1;
299
    }
300

  
301
///////////////////////////////////////////////////////////////////////////////////////////////////
302
  
303
  synchronized long add(EffectNames eln, Interpolator3D p, Interpolator1D i, float aX, float aY, float aZ)
304
    {
305
    if( mMax[PRESHADER]>mNumEffects )
306
      {
307
      mInterP[mNumEffects] = p;
308
      mInterI[mNumEffects] = i;
309
      
310
      mUniforms[NUM_UNIFORMS*mNumEffects+4] = aX;
311
      mUniforms[NUM_UNIFORMS*mNumEffects+5] = aY;  
312
      mUniforms[NUM_UNIFORMS*mNumEffects+6] = aZ;  
313
      
314
      return addBase(eln);
315
      }
316
      
317
    return -1;
318
    }
319
  
320
///////////////////////////////////////////////////////////////////////////////////////////////////
321
  
322
  synchronized long add(EffectNames eln, float x, float y, float z, float aA, float aX, float aY, float aZ)
323
    {
324
    if( mMax[PRESHADER]>mNumEffects )
325
      {
326
      mInterP[mNumEffects] = null; 
327
      mInterI[mNumEffects] = null;
328
      
329
      mUniforms[NUM_UNIFORMS*mNumEffects  ] =  x;
330
      mUniforms[NUM_UNIFORMS*mNumEffects+1] =  y;  
331
      mUniforms[NUM_UNIFORMS*mNumEffects+2] =  z;  
332
      mUniforms[NUM_UNIFORMS*mNumEffects+3] = aA;  
333
      mUniforms[NUM_UNIFORMS*mNumEffects+4] = aX;
334
      mUniforms[NUM_UNIFORMS*mNumEffects+5] = aY;  
335
      mUniforms[NUM_UNIFORMS*mNumEffects+6] = aZ;  
336
      
337
      return addBase(eln);   
338
      }
339
      
340
    return -1;
341
    }
342

  
343
///////////////////////////////////////////////////////////////////////////////////////////////////
344
  }
src/main/java/org/distorted/library/EffectListVertex.java
13 13
  
14 14
///////////////////////////////////////////////////////////////////////////////////////////////////
15 15
   
16
  public EffectListVertex(DistortedObject bmp) 
16
  public EffectListVertex(DistortedObject obj)
17 17
    { 
18
    super(bmp,NUM_UNIFORMS,VERTEX);
18
    super(obj,NUM_UNIFORMS,VERTEX);
19 19
    }
20 20
  
21 21
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/library/EffectNames.java
6 6
  {
7 7
  // EFFECT NAME /////// EFFECT TYPE ////////////// UNITY /////////////////////////
8 8
   
9
  ROTATE           ( Distorted.TYPE_MATR,   new float[] {0.0f}           ),
10
  QUATERNION       ( Distorted.TYPE_MATR,   new float[] {0.0f,0.0f,0.0f} ),      // quaternion is a unity iff its axis (x,y,z) is (0,0,0) 
11
  MOVE             ( Distorted.TYPE_MATR,   new float[] {0.0f,0.0f,0.0f} ),
12
  SCALE            ( Distorted.TYPE_MATR,   new float[] {1.0f,1.0f,1.0f} ),
13
  SHEAR            ( Distorted.TYPE_MATR,   new float[] {0.0f,0.0f,0.0f} ),
14
  // add new Matrix effects here...
9
  ROTATE           ( Distorted.TYPE_PRE ,   new float[] {0.0f}           ),
10
  QUATERNION       ( Distorted.TYPE_PRE ,   new float[] {0.0f,0.0f,0.0f} ),      // quaternion is a unity iff its axis (x,y,z) is (0,0,0)
11
  MOVE             ( Distorted.TYPE_PRE ,   new float[] {0.0f,0.0f,0.0f} ),
12
  SCALE            ( Distorted.TYPE_PRE ,   new float[] {1.0f,1.0f,1.0f} ),
13
  SHEAR            ( Distorted.TYPE_PRE ,   new float[] {0.0f,0.0f,0.0f} ),
14
  // add new PreShader effects here...
15 15
  
16 16
  DISTORT          ( Distorted.TYPE_VERT,   new float[] {0.0f,0.0f,0.0f} ),      // keep this the first VERT effect (reason: getType)
17 17
  DEFORM           ( Distorted.TYPE_VERT,   new float[] {0.0f,0.0f}      ),
......
32 32
  CONTRAST         ( Distorted.TYPE_FRAG,   new float[] {1.0f}           ),
33 33
  SMOOTH_CONTRAST  ( Distorted.TYPE_FRAG,   new float[] {1.0f}           ),
34 34
  HUE              ( Distorted.TYPE_FRAG,   new float[] {0.0f}           ),
35
  SMOOTH_HUE       ( Distorted.TYPE_FRAG,   new float[] {0.0f}           );
35
  SMOOTH_HUE       ( Distorted.TYPE_FRAG,   new float[] {0.0f}           ),
36 36
  // add new Fragment effects here...
37 37

  
38
  SAVE_PNG         ( Distorted.TYPE_POST,   null                         ),      // PostShader Effects don't have Unities.
39
  SAVE_MP4         ( Distorted.TYPE_POST,   null                         );      //
40
  // add new PostShader effects here...
41

  
38 42
///////////////////////////////////////////////////////////////////////////////////////////////////
39 43
  
40 44
  private static final int MAXDIM = 4;  // maximum supported dimension of an effect  
......
55 59
    
56 60
    for(EffectNames name: EffectNames.values())
57 61
      {
58
      dimensions[i] = name.unity.length;
62
      dimensions[i] = (name.unity==null ? 0 : name.unity.length);
59 63
      
60 64
      switch(dimensions[i])
61 65
        {
......
89 93
  
90 94
  static int getType(int ordinal)
91 95
    {
92
    if( ordinal<DISTORT.ordinal()     ) return Distorted.TYPE_MATR;
96
    if( ordinal<DISTORT.ordinal()     ) return Distorted.TYPE_PRE;
93 97
    if( ordinal<MACROBLOCK.ordinal()  ) return Distorted.TYPE_VERT;
94
   
95
    return Distorted.TYPE_FRAG;
98
    if( ordinal<SAVE_PNG.ordinal()    ) return Distorted.TYPE_FRAG;
99

  
100
    return Distorted.TYPE_POST;
96 101
    }
97 102

  
98 103
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff