Revision 1e438fc7
Added by Leszek Koltunski over 9 years ago
| src/main/java/org/distorted/library/Distorted.java | ||
|---|---|---|
| 67 | 67 |
* on the screen, with (optionally) different effects of the top-level root Bitmap. |
| 68 | 68 |
*/ |
| 69 | 69 |
public static final int CLONE_CHILDREN= 0x10; |
| 70 |
/** |
|
| 71 |
* Constant used to represent a PreShader-based effect. |
|
| 72 |
*/ |
|
| 73 |
public static final int TYPE_PRE = 0x1; |
|
| 74 |
/** |
|
| 75 |
* Constant used to represent a Vertex-based effect. |
|
| 76 |
*/ |
|
| 77 |
public static final int TYPE_VERT = 0x2; |
|
| 78 |
/** |
|
| 79 |
* Constant used to represent a Fragment-based effect. |
|
| 80 |
*/ |
|
| 81 |
public static final int TYPE_FRAG = 0x4; |
|
| 82 |
/** |
|
| 83 |
* Constant used to represent a PostShader-based effect. |
|
| 84 |
*/ |
|
| 85 |
public static final int TYPE_POST = 0x8; |
|
| 86 | 70 |
|
| 87 | 71 |
private static final String TAG = Distorted.class.getSimpleName(); |
| 88 | 72 |
private static boolean mInitialized = false; |
| ... | ... | |
| 224 | 208 |
|
| 225 | 209 |
for(EffectNames name: EffectNames.values() ) |
| 226 | 210 |
{
|
| 227 |
if( name.getType()==TYPE_VERT )
|
|
| 211 |
if( name.getType()==EffectTypes.VERTEX)
|
|
| 228 | 212 |
header += ("#define "+name.name()+" "+name.ordinal()+"\n");
|
| 229 | 213 |
} |
| 230 | 214 |
break; |
| ... | ... | |
| 232 | 216 |
|
| 233 | 217 |
for(EffectNames name: EffectNames.values() ) |
| 234 | 218 |
{
|
| 235 |
if( name.getType()==TYPE_FRAG )
|
|
| 219 |
if( name.getType()==EffectTypes.FRAGMENT)
|
|
| 236 | 220 |
header += ("#define "+name.name()+" "+name.ordinal()+"\n");
|
| 237 | 221 |
} |
| 238 | 222 |
break; |
| ... | ... | |
| 360 | 344 |
|
| 361 | 345 |
EffectListFragment.getUniforms(mProgramH); |
| 362 | 346 |
EffectListVertex.getUniforms(mProgramH); |
| 363 |
EffectListPreShader.getUniforms(mProgramH);
|
|
| 347 |
EffectListMatrix.getUniforms(mProgramH);
|
|
| 364 | 348 |
|
| 365 | 349 |
GLES20.glEnableVertexAttribArray(mPositionH); |
| 366 | 350 |
GLES20.glEnableVertexAttribArray(mColorH); |
| ... | ... | |
| 397 | 381 |
|
| 398 | 382 |
EffectListVertex.reset(); |
| 399 | 383 |
EffectListFragment.reset(); |
| 400 |
EffectListPreShader.reset(); // no need to reset PostShader stuff
|
|
| 384 |
EffectListMatrix.reset(); // no need to reset Other EffectList
|
|
| 401 | 385 |
|
| 402 | 386 |
EffectMessageSender.stopSending(); |
| 403 | 387 |
|
| ... | ... | |
| 418 | 402 |
|
| 419 | 403 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 420 | 404 |
/** |
| 421 |
* Returns the maximum number of PreShader effects.
|
|
| 405 |
* Returns the maximum number of Matrix effects.
|
|
| 422 | 406 |
* |
| 423 |
* @return The maximum number of PreShader effects
|
|
| 407 |
* @return The maximum number of Matrix effects
|
|
| 424 | 408 |
*/ |
| 425 |
public static int getMaxPreShader()
|
|
| 409 |
public static int getMaxMatrix()
|
|
| 426 | 410 |
{
|
| 427 |
return EffectListPreShader.getMax();
|
|
| 411 |
return EffectListMatrix.getMax();
|
|
| 428 | 412 |
} |
| 429 | 413 |
|
| 430 | 414 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 451 | 435 |
|
| 452 | 436 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 453 | 437 |
/** |
| 454 |
* Sets the maximum number of PreShader effects that can be applied to a single DistortedBitmap at one time.
|
|
| 438 |
* Sets the maximum number of Matrix effects that can be applied to a single DistortedBitmap at one time.
|
|
| 455 | 439 |
* This can fail if the value of 'max' is outside permitted range. |
| 456 | 440 |
* |
| 457 |
* @param max new maximum number of simultaneous PreShader Effects. Has to be a non-negative number not greater
|
|
| 441 |
* @param max new maximum number of simultaneous Matrix Effects. Has to be a non-negative number not greater
|
|
| 458 | 442 |
* than Byte.MAX_VALUE |
| 459 | 443 |
* @return <code>true</code> if operation was successful, <code>false</code> otherwise. |
| 460 | 444 |
*/ |
| 461 |
public static boolean setMaxPreShader(int max)
|
|
| 445 |
public static boolean setMaxMatrix(int max)
|
|
| 462 | 446 |
{
|
| 463 |
return EffectListPreShader.setMax(max);
|
|
| 447 |
return EffectListMatrix.setMax(max);
|
|
| 464 | 448 |
} |
| 465 | 449 |
|
| 466 | 450 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/DistortedObject.java | ||
|---|---|---|
| 9 | 9 |
* All Objects to which Distorted Graphics effects can be applied need to be extended from here. |
| 10 | 10 |
*/ |
| 11 | 11 |
public abstract class DistortedObject |
| 12 |
{
|
|
| 13 |
static final int TYPE_NUM = 4; |
|
| 14 |
private static final int TYPE_MASK= (1<<TYPE_NUM)-1; |
|
| 12 |
{
|
|
| 15 | 13 |
private static float[] mViewMatrix = new float[16]; |
| 16 | 14 |
|
| 17 |
protected EffectListPreShader mM;
|
|
| 15 |
protected EffectListMatrix mM;
|
|
| 18 | 16 |
protected EffectListFragment mF; |
| 19 | 17 |
protected EffectListVertex mV; |
| 20 |
protected EffectListPostShader mP;
|
|
| 18 |
protected EffectListOther mO;
|
|
| 21 | 19 |
|
| 22 | 20 |
protected boolean matrixCloned, vertexCloned, fragmentCloned; |
| 23 | 21 |
|
| ... | ... | |
| 62 | 60 |
} |
| 63 | 61 |
else |
| 64 | 62 |
{
|
| 65 |
mM = new EffectListPreShader(d);
|
|
| 63 |
mM = new EffectListMatrix(d);
|
|
| 66 | 64 |
matrixCloned = false; |
| 67 | 65 |
} |
| 68 | 66 |
|
| ... | ... | |
| 88 | 86 |
fragmentCloned = false; |
| 89 | 87 |
} |
| 90 | 88 |
|
| 91 |
mP = new EffectListPostShader(d); // PostShader effects are never cloned.
|
|
| 89 |
mO= new EffectListOther(d); // Other effects are never cloned.
|
|
| 92 | 90 |
} |
| 93 | 91 |
|
| 94 | 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 134 | 132 |
|
| 135 | 133 |
mGrid.draw(); |
| 136 | 134 |
|
| 137 |
mP.send();
|
|
| 135 |
mO.send();
|
|
| 138 | 136 |
} |
| 139 | 137 |
|
| 140 | 138 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 156 | 154 |
if( vertexCloned ==false) mV.abortAll(); |
| 157 | 155 |
if( fragmentCloned==false) mF.abortAll(); |
| 158 | 156 |
|
| 159 |
mP.abortAll();
|
|
| 157 |
mO.abortAll();
|
|
| 160 | 158 |
|
| 161 | 159 |
mBmp = null; |
| 162 | 160 |
mGrid = null; |
| 163 | 161 |
mM = null; |
| 164 | 162 |
mV = null; |
| 165 | 163 |
mF = null; |
| 166 |
mP = null;
|
|
| 164 |
mO = null;
|
|
| 167 | 165 |
mTextureDataH = null; |
| 168 | 166 |
} |
| 169 | 167 |
|
| ... | ... | |
| 291 | 289 |
mV.addListener(el); |
| 292 | 290 |
mF.addListener(el); |
| 293 | 291 |
mM.addListener(el); |
| 294 |
mP.addListener(el);
|
|
| 292 |
mO.addListener(el);
|
|
| 295 | 293 |
} |
| 296 | 294 |
|
| 297 | 295 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 305 | 303 |
mV.removeListener(el); |
| 306 | 304 |
mF.removeListener(el); |
| 307 | 305 |
mM.removeListener(el); |
| 308 |
mP.removeListener(el);
|
|
| 306 |
mO.removeListener(el);
|
|
| 309 | 307 |
} |
| 310 | 308 |
|
| 311 | 309 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 361 | 359 |
mM.abortAll(); |
| 362 | 360 |
mV.abortAll(); |
| 363 | 361 |
mF.abortAll(); |
| 364 |
mP.abortAll();
|
|
| 362 |
mO.abortAll();
|
|
| 365 | 363 |
} |
| 366 | 364 |
|
| 367 | 365 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 372 | 370 |
*/ |
| 373 | 371 |
public void abortAllEffects(int mask) |
| 374 | 372 |
{
|
| 375 |
if( (mask & Distorted.TYPE_PRE ) != 0 ) mM.abortAll();
|
|
| 376 |
if( (mask & Distorted.TYPE_VERT) != 0 ) mV.abortAll();
|
|
| 377 |
if( (mask & Distorted.TYPE_FRAG) != 0 ) mF.abortAll();
|
|
| 378 |
if( (mask & Distorted.TYPE_POST) != 0 ) mP.abortAll();
|
|
| 373 |
if( (mask & EffectTypes.MATRIX.type ) != 0 ) mM.abortAll();
|
|
| 374 |
if( (mask & EffectTypes.VERTEX.type ) != 0 ) mV.abortAll();
|
|
| 375 |
if( (mask & EffectTypes.FRAGMENT.type ) != 0 ) mF.abortAll();
|
|
| 376 |
if( (mask & EffectTypes.OTHER.type ) != 0 ) mO.abortAll();
|
|
| 379 | 377 |
} |
| 380 | 378 |
|
| 381 | 379 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 387 | 385 |
*/ |
| 388 | 386 |
public boolean abortEffect(long id) |
| 389 | 387 |
{
|
| 390 |
switch( (int)(id&TYPE_MASK) )
|
|
| 391 |
{
|
|
| 392 |
case Distorted.TYPE_PRE : return mM.removeByID(id>>TYPE_NUM);
|
|
| 393 |
case Distorted.TYPE_VERT: return mV.removeByID(id>>TYPE_NUM);
|
|
| 394 |
case Distorted.TYPE_FRAG: return mF.removeByID(id>>TYPE_NUM);
|
|
| 395 |
case Distorted.TYPE_POST: return mP.removeByID(id>>TYPE_NUM);
|
|
| 396 |
default : return false; |
|
| 397 |
}
|
|
| 388 |
int type = (int)(id&EffectTypes.MASK);
|
|
| 389 |
|
|
| 390 |
if( type==EffectTypes.MATRIX.type ) return mM.removeByID(id>>EffectTypes.LENGTH);
|
|
| 391 |
if( type==EffectTypes.VERTEX.type ) return mV.removeByID(id>>EffectTypes.LENGTH);
|
|
| 392 |
if( type==EffectTypes.FRAGMENT.type ) return mF.removeByID(id>>EffectTypes.LENGTH);
|
|
| 393 |
if( type==EffectTypes.OTHER.type ) return mO.removeByID(id>>EffectTypes.LENGTH);
|
|
| 394 |
|
|
| 395 |
return false;
|
|
| 398 | 396 |
} |
| 399 | 397 |
|
| 400 | 398 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 408 | 406 |
{
|
| 409 | 407 |
switch(effectType.getType()) |
| 410 | 408 |
{
|
| 411 |
case Distorted.TYPE_PRE : return mM.removeByType(effectType);
|
|
| 412 |
case Distorted.TYPE_VERT: return mV.removeByType(effectType);
|
|
| 413 |
case Distorted.TYPE_FRAG: return mF.removeByType(effectType);
|
|
| 414 |
case Distorted.TYPE_POST: return mP.removeByType(effectType);
|
|
| 415 |
default : return false;
|
|
| 409 |
case MATRIX : return mM.removeByType(effectType);
|
|
| 410 |
case VERTEX : return mV.removeByType(effectType);
|
|
| 411 |
case FRAGMENT: return mF.removeByType(effectType);
|
|
| 412 |
case OTHER : return mO.removeByType(effectType);
|
|
| 413 |
default : return false; |
|
| 416 | 414 |
} |
| 417 | 415 |
} |
| 418 | 416 |
|
| ... | ... | |
| 426 | 424 |
|
| 427 | 425 |
public boolean printEffect(long id) |
| 428 | 426 |
{
|
| 429 |
switch( (int)(id&TYPE_MASK) )
|
|
| 430 |
{
|
|
| 431 |
case Distorted.TYPE_PRE : return mM.printByID(id>>TYPE_NUM);
|
|
| 432 |
case Distorted.TYPE_VERT: return mV.printByID(id>>TYPE_NUM);
|
|
| 433 |
case Distorted.TYPE_FRAG: return mF.printByID(id>>TYPE_NUM);
|
|
| 434 |
case Distorted.TYPE_POST: return mP.printByID(id>>TYPE_NUM);
|
|
| 435 |
default : return false; |
|
| 436 |
}
|
|
| 427 |
int type = (int)(id&EffectTypes.MASK);
|
|
| 428 |
|
|
| 429 |
if( type==EffectTypes.MATRIX.type ) return mM.printByID(id>>EffectTypes.LENGTH);
|
|
| 430 |
if( type==EffectTypes.VERTEX.type ) return mV.printByID(id>>EffectTypes.LENGTH);
|
|
| 431 |
if( type==EffectTypes.FRAGMENT.type ) return mF.printByID(id>>EffectTypes.LENGTH);
|
|
| 432 |
if( type==EffectTypes.OTHER.type ) return mO.printByID(id>>EffectTypes.LENGTH);
|
|
| 433 |
|
|
| 434 |
return false;
|
|
| 437 | 435 |
} |
| 438 | 436 |
|
| 439 | 437 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/EffectList.java | ||
|---|---|---|
| 6 | 6 |
|
| 7 | 7 |
abstract class EffectList |
| 8 | 8 |
{
|
| 9 |
protected static final int DEFAULT_NUM_EFFECTS = 5; |
|
| 10 |
|
|
| 11 |
protected static final int PRESHADER =0; |
|
| 12 |
protected static final int VERTEX =1; |
|
| 13 |
protected static final int FRAGMENT =2; |
|
| 14 |
|
|
| 15 | 9 |
protected byte mNumEffects; // number of effects at the moment |
| 16 | 10 |
protected long mTotalEffects; // total number of effects ever created |
| 17 | 11 |
|
| ... | ... | |
| 27 | 21 |
protected long mTime=0; |
| 28 | 22 |
protected float mObjHalfX, mObjHalfY, mObjHalfZ; |
| 29 | 23 |
|
| 30 |
protected static int[] mMax = new int[3];
|
|
| 24 |
protected static int[] mMax = new int[EffectTypes.LENGTH];
|
|
| 31 | 25 |
protected int mMaxIndex; |
| 32 |
protected static boolean mCreated = false;
|
|
| 26 |
protected static boolean mCreated; |
|
| 33 | 27 |
|
| 34 | 28 |
protected Vector<EffectListener> mListeners =null; |
| 35 | 29 |
protected int mNumListeners=0; // ==mListeners.length(), but we only create mListeners if the first one gets added |
| ... | ... | |
| 37 | 31 |
|
| 38 | 32 |
static |
| 39 | 33 |
{
|
| 40 |
mMax[PRESHADER]= DEFAULT_NUM_EFFECTS; |
|
| 41 |
mMax[VERTEX] = DEFAULT_NUM_EFFECTS; |
|
| 42 |
mMax[FRAGMENT] = DEFAULT_NUM_EFFECTS; |
|
| 34 |
reset(); |
|
| 43 | 35 |
} |
| 44 | 36 |
|
| 45 | 37 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 49 | 41 |
mNumEffects = 0; |
| 50 | 42 |
mTotalEffects = 0; |
| 51 | 43 |
mMaxIndex = index; |
| 52 |
|
|
| 53 |
mObjHalfX = obj.getWidth() /2.0f; |
|
| 54 |
mObjHalfY = obj.getHeight()/2.0f; |
|
| 55 |
mObjHalfZ = obj.getDepth() /2.0f; |
|
| 56 | 44 |
|
| 57 |
mBitmapID = obj.getID(); |
|
| 58 |
|
|
| 45 |
if( obj!=null ) |
|
| 46 |
{
|
|
| 47 |
mObjHalfX = obj.getWidth() / 2.0f; |
|
| 48 |
mObjHalfY = obj.getHeight() / 2.0f; |
|
| 49 |
mObjHalfZ = obj.getDepth() / 2.0f; |
|
| 50 |
|
|
| 51 |
mBitmapID = obj.getID(); |
|
| 52 |
} |
|
| 53 |
|
|
| 59 | 54 |
if( mMax[mMaxIndex]>0 ) |
| 60 | 55 |
{
|
| 61 | 56 |
mType = new int[mMax[mMaxIndex]]; |
| ... | ... | |
| 105 | 100 |
|
| 106 | 101 |
static void reset() |
| 107 | 102 |
{
|
| 108 |
mMax[PRESHADER]= DEFAULT_NUM_EFFECTS; |
|
| 109 |
mMax[VERTEX] = DEFAULT_NUM_EFFECTS; |
|
| 110 |
mMax[FRAGMENT] = DEFAULT_NUM_EFFECTS; |
|
| 111 |
|
|
| 103 |
EffectTypes.reset(mMax); |
|
| 112 | 104 |
mCreated = false; |
| 113 | 105 |
} |
| 114 | 106 |
|
| ... | ... | |
| 203 | 195 |
for(int i=0; i<mNumListeners; i++) |
| 204 | 196 |
EffectMessageSender.newMessage( mListeners.elementAt(i), |
| 205 | 197 |
EffectMessage.EFFECT_REMOVED, |
| 206 |
(removedID<<DistortedObject.TYPE_NUM)+EffectNames.getType(removedType),
|
|
| 198 |
(removedID<<EffectTypes.LENGTH)+EffectNames.getType(removedType).type,
|
|
| 207 | 199 |
removedType, |
| 208 | 200 |
mBitmapID); |
| 209 | 201 |
} |
| ... | ... | |
| 223 | 215 |
mNumEffects++; |
| 224 | 216 |
mTotalEffects++; |
| 225 | 217 |
|
| 226 |
return (id<<DistortedObject.TYPE_NUM)+eln.getType();
|
|
| 218 |
return (id<<EffectTypes.LENGTH)+eln.getType().type;
|
|
| 227 | 219 |
} |
| 228 | 220 |
|
| 229 | 221 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/EffectListFragment.java | ||
|---|---|---|
| 6 | 6 |
|
| 7 | 7 |
class EffectListFragment extends EffectList |
| 8 | 8 |
{
|
| 9 |
private static final int NUM_UNIFORMS = 9; |
|
| 9 |
private static final int NUM_UNIFORMS = 9; |
|
| 10 |
private static final int INDEX = EffectTypes.FRAGMENT.ordinal(); |
|
| 10 | 11 |
private float[] mBuf; |
| 11 | 12 |
private static int mNumEffectsH; |
| 12 | 13 |
private static int mTypeH; |
| ... | ... | |
| 16 | 17 |
|
| 17 | 18 |
public EffectListFragment(DistortedObject obj) |
| 18 | 19 |
{
|
| 19 |
super(obj,NUM_UNIFORMS,FRAGMENT);
|
|
| 20 |
super(obj,NUM_UNIFORMS,INDEX);
|
|
| 20 | 21 |
|
| 21 |
if( mMax[FRAGMENT]>0 )
|
|
| 22 |
if( mMax[INDEX]>0 )
|
|
| 22 | 23 |
{
|
| 23 |
mBuf= new float[4*mMax[FRAGMENT]];
|
|
| 24 |
mBuf= new float[4*mMax[INDEX]];
|
|
| 24 | 25 |
} |
| 25 | 26 |
} |
| 26 | 27 |
|
| ... | ... | |
| 30 | 31 |
|
| 31 | 32 |
static boolean setMax(int m) |
| 32 | 33 |
{
|
| 33 |
if( (mCreated==false && !Distorted.isInitialized()) || m<=mMax[FRAGMENT] )
|
|
| 34 |
if( (mCreated==false && !Distorted.isInitialized()) || m<=mMax[INDEX] )
|
|
| 34 | 35 |
{
|
| 35 | 36 |
if( m<0 ) m = 0; |
| 36 | 37 |
else if( m>Byte.MAX_VALUE ) m = Byte.MAX_VALUE; |
| 37 | 38 |
|
| 38 |
mMax[FRAGMENT] = m;
|
|
| 39 |
mMax[INDEX] = m;
|
|
| 39 | 40 |
return true; |
| 40 | 41 |
} |
| 41 | 42 |
|
| ... | ... | |
| 46 | 47 |
|
| 47 | 48 |
static int getMax() |
| 48 | 49 |
{
|
| 49 |
return mMax[FRAGMENT];
|
|
| 50 |
return mMax[INDEX];
|
|
| 50 | 51 |
} |
| 51 | 52 |
|
| 52 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 77 | 78 |
for(int j=0; j<mNumListeners; j++) |
| 78 | 79 |
EffectMessageSender.newMessage( mListeners.elementAt(j), |
| 79 | 80 |
EffectMessage.EFFECT_FINISHED, |
| 80 |
(mID[i]<<DistortedObject.TYPE_NUM)+Distorted.TYPE_FRAG,
|
|
| 81 |
(mID[i]<<EffectTypes.LENGTH)+EffectTypes.FRAGMENT.type,
|
|
| 81 | 82 |
mType[i], |
| 82 | 83 |
mBitmapID); |
| 83 | 84 |
|
| ... | ... | |
| 167 | 168 |
|
| 168 | 169 |
synchronized long add(EffectNames eln, Interpolator inter, Float4D region, Interpolator2D point) |
| 169 | 170 |
{
|
| 170 |
if( mMax[FRAGMENT]>mNumEffects )
|
|
| 171 |
if( mMax[INDEX]>mNumEffects )
|
|
| 171 | 172 |
{
|
| 172 | 173 |
EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects); |
| 173 | 174 |
mInterI[mNumEffects] = inter; |
| ... | ... | |
| 185 | 186 |
|
| 186 | 187 |
synchronized long add(EffectNames eln, Interpolator inter, Float4D region, float x, float y) |
| 187 | 188 |
{
|
| 188 |
if( mMax[FRAGMENT]>mNumEffects )
|
|
| 189 |
if( mMax[INDEX]>mNumEffects )
|
|
| 189 | 190 |
{
|
| 190 | 191 |
EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects); |
| 191 | 192 |
mInterI[mNumEffects] = inter; |
| ... | ... | |
| 205 | 206 |
|
| 206 | 207 |
synchronized long add(EffectNames eln, Interpolator1D inter, Float3D c, Float4D region, Interpolator2D point) |
| 207 | 208 |
{
|
| 208 |
if( mMax[FRAGMENT]>mNumEffects )
|
|
| 209 |
if( mMax[INDEX]>mNumEffects )
|
|
| 209 | 210 |
{
|
| 210 | 211 |
mInterI[mNumEffects] = inter; |
| 211 | 212 |
mInterP[mNumEffects] = point; |
| ... | ... | |
| 226 | 227 |
|
| 227 | 228 |
synchronized long add(EffectNames eln, Interpolator1D inter, Float3D c, Float4D region, float x, float y) |
| 228 | 229 |
{
|
| 229 |
if( mMax[FRAGMENT]>mNumEffects )
|
|
| 230 |
if( mMax[INDEX]>mNumEffects )
|
|
| 230 | 231 |
{
|
| 231 | 232 |
mInterI[mNumEffects] = inter; |
| 232 | 233 |
mInterP[mNumEffects] = null; |
| ... | ... | |
| 249 | 250 |
|
| 250 | 251 |
synchronized long add(EffectNames eln, float t, Float3D c, Float4D region, Interpolator2D point) |
| 251 | 252 |
{
|
| 252 |
if( mMax[FRAGMENT]>mNumEffects )
|
|
| 253 |
if( mMax[INDEX]>mNumEffects )
|
|
| 253 | 254 |
{
|
| 254 | 255 |
mInterI[mNumEffects] = null; |
| 255 | 256 |
mInterP[mNumEffects] = point; |
| ... | ... | |
| 271 | 272 |
|
| 272 | 273 |
synchronized long add(EffectNames eln, float t, Float3D c, Float4D region, float x, float y) |
| 273 | 274 |
{
|
| 274 |
if( mMax[FRAGMENT]>mNumEffects )
|
|
| 275 |
if( mMax[INDEX]>mNumEffects )
|
|
| 275 | 276 |
{
|
| 276 | 277 |
mInterI[mNumEffects] = null; |
| 277 | 278 |
mInterP[mNumEffects] = null; |
| 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 final int INDEX = EffectTypes.MATRIX.ordinal(); |
|
| 12 |
private static float[] mMVPMatrix= new float[16]; |
|
| 13 |
private static float[] mTmpMatrix= new float[16]; |
|
| 14 |
|
|
| 15 |
private static int mBmpDH; // This is a handle to half a bitmap dimensions |
|
| 16 |
private static int mDepthH; // Handle to the max Depth, i.e (farplane-nearplane)/2 |
|
| 17 |
private static int mMVPMatrixH; // pass in the transformation matrix |
|
| 18 |
private static int mMVMatrixH; // pass in the modelview matrix. |
|
| 19 |
|
|
| 20 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 21 |
|
|
| 22 |
public EffectListMatrix(DistortedObject obj) |
|
| 23 |
{
|
|
| 24 |
super(obj,NUM_UNIFORMS, INDEX ); |
|
| 25 |
} |
|
| 26 |
|
|
| 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 28 |
|
|
| 29 |
private static void multiplyByQuat(float[] matrix, float X, float Y, float Z, float W) |
|
| 30 |
{
|
|
| 31 |
float xx= X * X; |
|
| 32 |
float xy= X * Y; |
|
| 33 |
float xz= X * Z; |
|
| 34 |
float xw= X * W; |
|
| 35 |
float yy= Y * Y; |
|
| 36 |
float yz= Y * Z; |
|
| 37 |
float yw= Y * W; |
|
| 38 |
float zz= Z * Z; |
|
| 39 |
float zw= Z * W; |
|
| 40 |
|
|
| 41 |
mTmpMatrix[0] = 1 - 2 * ( yy + zz ); |
|
| 42 |
mTmpMatrix[1] = 2 * ( xy - zw ); |
|
| 43 |
mTmpMatrix[2] = 2 * ( xz + yw ); |
|
| 44 |
mTmpMatrix[4] = 2 * ( xy + zw ); |
|
| 45 |
mTmpMatrix[5] = 1 - 2 * ( xx + zz ); |
|
| 46 |
mTmpMatrix[6] = 2 * ( yz - xw ); |
|
| 47 |
mTmpMatrix[8] = 2 * ( xz - yw ); |
|
| 48 |
mTmpMatrix[9] = 2 * ( yz + xw ); |
|
| 49 |
mTmpMatrix[10] = 1 - 2 * ( xx + yy ); |
|
| 50 |
mTmpMatrix[3] = mTmpMatrix[7] = mTmpMatrix[11] = mTmpMatrix[12] = mTmpMatrix[13] = mTmpMatrix[14] = 0; |
|
| 51 |
mTmpMatrix[15] = 1; |
|
| 52 |
|
|
| 53 |
Matrix.multiplyMM(mMVPMatrix, 0, matrix, 0, mTmpMatrix, 0); |
|
| 54 |
for(int j=0; j<16; j++) matrix[j] = mMVPMatrix[j]; |
|
| 55 |
} |
|
| 56 |
|
|
| 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 58 |
// Only max Byte.MAX_VALUE concurrent effects per bitmap. |
|
| 59 |
// If you want more, change type of the mNumEffects, mIDIndex and mFreeIndexes variables to shorts. |
|
| 60 |
|
|
| 61 |
static boolean setMax(int m) |
|
| 62 |
{
|
|
| 63 |
if( (mCreated==false && !Distorted.isInitialized()) || m<=mMax[INDEX] ) |
|
| 64 |
{
|
|
| 65 |
if( m<0 ) m = 0; |
|
| 66 |
else if( m>Byte.MAX_VALUE ) m = Byte.MAX_VALUE; |
|
| 67 |
|
|
| 68 |
mMax[INDEX] = m; |
|
| 69 |
return true; |
|
| 70 |
} |
|
| 71 |
|
|
| 72 |
return false; |
|
| 73 |
} |
|
| 74 |
|
|
| 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 76 |
|
|
| 77 |
static int getMax() |
|
| 78 |
{
|
|
| 79 |
return mMax[INDEX]; |
|
| 80 |
} |
|
| 81 |
|
|
| 82 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 83 |
|
|
| 84 |
static void getUniforms(int mProgramH) |
|
| 85 |
{
|
|
| 86 |
mBmpDH = GLES20.glGetUniformLocation(mProgramH, "u_bmpD"); |
|
| 87 |
mDepthH = GLES20.glGetUniformLocation(mProgramH, "u_Depth"); |
|
| 88 |
mMVPMatrixH= GLES20.glGetUniformLocation(mProgramH, "u_MVPMatrix"); |
|
| 89 |
mMVMatrixH = GLES20.glGetUniformLocation(mProgramH, "u_MVMatrix"); |
|
| 90 |
} |
|
| 91 |
|
|
| 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 93 |
|
|
| 94 |
synchronized void compute(long currTime) |
|
| 95 |
{
|
|
| 96 |
if( currTime==mTime ) return; |
|
| 97 |
if( mTime==0 ) mTime = currTime; |
|
| 98 |
long step = (currTime-mTime); |
|
| 99 |
|
|
| 100 |
for(int i=0; i<mNumEffects; i++) |
|
| 101 |
{
|
|
| 102 |
if( mInterI[i]==null ) continue; |
|
| 103 |
|
|
| 104 |
if( mInterP[i]!=null ) |
|
| 105 |
{
|
|
| 106 |
mInterP[i].interpolateMain(mUniforms, NUM_UNIFORMS*i, mCurrentDuration[i]); |
|
| 107 |
} |
|
| 108 |
|
|
| 109 |
if( mInterI[i].interpolateMain(mUniforms ,NUM_UNIFORMS*i+3, mCurrentDuration[i], step) ) |
|
| 110 |
{
|
|
| 111 |
for(int j=0; j<mNumListeners; j++) |
|
| 112 |
EffectMessageSender.newMessage( mListeners.elementAt(j), |
|
| 113 |
EffectMessage.EFFECT_FINISHED, |
|
| 114 |
(mID[i]<<EffectTypes.LENGTH)+EffectTypes.MATRIX.type, |
|
| 115 |
mType[i], |
|
| 116 |
mBitmapID); |
|
| 117 |
|
|
| 118 |
if( EffectNames.isUnity(mType[i], mUniforms, NUM_UNIFORMS*i+3) ) |
|
| 119 |
{
|
|
| 120 |
remove(i); |
|
| 121 |
i--; |
|
| 122 |
continue; |
|
| 123 |
} |
|
| 124 |
} |
|
| 125 |
|
|
| 126 |
mCurrentDuration[i] += step; |
|
| 127 |
} |
|
| 128 |
|
|
| 129 |
mTime = currTime; |
|
| 130 |
} |
|
| 131 |
|
|
| 132 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 133 |
|
|
| 134 |
protected void moveEffect(int index) |
|
| 135 |
{
|
|
| 136 |
mUniforms[NUM_UNIFORMS*index ] = mUniforms[NUM_UNIFORMS*(index+1) ]; |
|
| 137 |
mUniforms[NUM_UNIFORMS*index+1] = mUniforms[NUM_UNIFORMS*(index+1)+1]; |
|
| 138 |
mUniforms[NUM_UNIFORMS*index+2] = mUniforms[NUM_UNIFORMS*(index+1)+2]; |
|
| 139 |
mUniforms[NUM_UNIFORMS*index+3] = mUniforms[NUM_UNIFORMS*(index+1)+3]; |
|
| 140 |
mUniforms[NUM_UNIFORMS*index+4] = mUniforms[NUM_UNIFORMS*(index+1)+4]; |
|
| 141 |
mUniforms[NUM_UNIFORMS*index+5] = mUniforms[NUM_UNIFORMS*(index+1)+5]; |
|
| 142 |
mUniforms[NUM_UNIFORMS*index+6] = mUniforms[NUM_UNIFORMS*(index+1)+6]; |
|
| 143 |
} |
|
| 144 |
|
|
| 145 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 146 |
// here construct the ModelView Matrix |
|
| 147 |
|
|
| 148 |
synchronized void send(float[] viewMatrix, DistortedProjection dp) |
|
| 149 |
{
|
|
| 150 |
Matrix.setIdentityM(viewMatrix, 0); |
|
| 151 |
Matrix.translateM(viewMatrix, 0, -dp.width/2, dp.height/2, -dp.distance); |
|
| 152 |
|
|
| 153 |
float x,y,z, sx,sy,sz=1.0f; |
|
| 154 |
|
|
| 155 |
for(int i=0; i<mNumEffects; i++) |
|
| 156 |
{
|
|
| 157 |
if (mType[i] == EffectNames.ROTATE.ordinal() ) |
|
| 158 |
{
|
|
| 159 |
x = mUniforms[NUM_UNIFORMS*i ]; |
|
| 160 |
y = mUniforms[NUM_UNIFORMS*i+1]; |
|
| 161 |
z = mUniforms[NUM_UNIFORMS*i+2]; |
|
| 162 |
|
|
| 163 |
Matrix.translateM(viewMatrix, 0, x,-y, z); |
|
| 164 |
Matrix.rotateM( viewMatrix, 0, mUniforms[NUM_UNIFORMS*i+3], mUniforms[NUM_UNIFORMS*i+4], mUniforms[NUM_UNIFORMS*i+5], mUniforms[NUM_UNIFORMS*i+6]); |
|
| 165 |
Matrix.translateM(viewMatrix, 0,-x, y,-z); |
|
| 166 |
} |
|
| 167 |
else if(mType[i] == EffectNames.QUATERNION.ordinal() ) |
|
| 168 |
{
|
|
| 169 |
x = mUniforms[NUM_UNIFORMS*i ]; |
|
| 170 |
y = mUniforms[NUM_UNIFORMS*i+1]; |
|
| 171 |
z = mUniforms[NUM_UNIFORMS*i+2]; |
|
| 172 |
|
|
| 173 |
Matrix.translateM(viewMatrix, 0, x,-y, z); |
|
| 174 |
multiplyByQuat(viewMatrix, mUniforms[NUM_UNIFORMS*i+3], mUniforms[NUM_UNIFORMS*i+4], mUniforms[NUM_UNIFORMS*i+5], mUniforms[NUM_UNIFORMS*i+6]); |
|
| 175 |
Matrix.translateM(viewMatrix, 0,-x, y,-z); |
|
| 176 |
} |
|
| 177 |
else if(mType[i] == EffectNames.MOVE.ordinal() ) |
|
| 178 |
{
|
|
| 179 |
sx = mUniforms[NUM_UNIFORMS*i+3]; |
|
| 180 |
sy = mUniforms[NUM_UNIFORMS*i+4]; |
|
| 181 |
sz = mUniforms[NUM_UNIFORMS*i+5]; |
|
| 182 |
|
|
| 183 |
Matrix.translateM(viewMatrix, 0, sx,-sy, sz); |
|
| 184 |
} |
|
| 185 |
else if(mType[i] == EffectNames.SCALE.ordinal() ) |
|
| 186 |
{
|
|
| 187 |
sx = mUniforms[NUM_UNIFORMS*i+3]; |
|
| 188 |
sy = mUniforms[NUM_UNIFORMS*i+4]; |
|
| 189 |
sz = mUniforms[NUM_UNIFORMS*i+5]; |
|
| 190 |
|
|
| 191 |
Matrix.scaleM(viewMatrix, 0, sx, sy, sz); |
|
| 192 |
} |
|
| 193 |
else if(mType[i] == EffectNames.SHEAR.ordinal() ) |
|
| 194 |
{
|
|
| 195 |
x = mUniforms[NUM_UNIFORMS*i ]; |
|
| 196 |
y = mUniforms[NUM_UNIFORMS*i+1]; |
|
| 197 |
z = mUniforms[NUM_UNIFORMS*i+2]; |
|
| 198 |
|
|
| 199 |
sx = mUniforms[NUM_UNIFORMS*i+3]; |
|
| 200 |
sy = mUniforms[NUM_UNIFORMS*i+4]; |
|
| 201 |
sz = mUniforms[NUM_UNIFORMS*i+5]; |
|
| 202 |
|
|
| 203 |
Matrix.translateM(viewMatrix, 0, x,-y, z); |
|
| 204 |
|
|
| 205 |
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. |
|
| 206 |
viewMatrix[5] += sx*viewMatrix[1]; // 0 1 0 0 |
|
| 207 |
viewMatrix[6] += sx*viewMatrix[2]; // 0 0 1 0 |
|
| 208 |
viewMatrix[7] += sx*viewMatrix[3]; // 0 0 0 1 |
|
| 209 |
|
|
| 210 |
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. |
|
| 211 |
viewMatrix[1] += sy*viewMatrix[5]; // y 1 0 0 |
|
| 212 |
viewMatrix[2] += sy*viewMatrix[6]; // 0 0 1 0 |
|
| 213 |
viewMatrix[3] += sy*viewMatrix[7]; // 0 0 0 1 |
|
| 214 |
|
|
| 215 |
// TODO: implement Z-shear. |
|
| 216 |
|
|
| 217 |
Matrix.translateM(viewMatrix, 0,-x, y, -z); |
|
| 218 |
} |
|
| 219 |
} |
|
| 220 |
|
|
| 221 |
Matrix.translateM(viewMatrix, 0, mObjHalfX,-mObjHalfY, -mObjHalfZ); |
|
| 222 |
Matrix.multiplyMM(mMVPMatrix, 0, dp.projectionMatrix, 0, viewMatrix, 0); |
|
| 223 |
|
|
| 224 |
GLES20.glUniform3f( mBmpDH , mObjHalfX, mObjHalfY, mObjHalfZ); |
|
| 225 |
GLES20.glUniform1f( mDepthH, dp.depth); |
|
| 226 |
GLES20.glUniformMatrix4fv(mMVMatrixH , 1, false, viewMatrix, 0); |
|
| 227 |
GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix, 0); |
|
| 228 |
} |
|
| 229 |
|
|
| 230 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 231 |
// here construct the ModelView Matrix, but without any effects |
|
| 232 |
|
|
| 233 |
synchronized void sendNoEffects(DistortedProjection dp) |
|
| 234 |
{
|
|
| 235 |
Matrix.setIdentityM(mTmpMatrix, 0); |
|
| 236 |
Matrix.translateM(mTmpMatrix, 0, mObjHalfX-dp.width/2, dp.height/2-mObjHalfY, mObjHalfZ-dp.distance); |
|
| 237 |
Matrix.multiplyMM(mMVPMatrix, 0, dp.projectionMatrix, 0, mTmpMatrix, 0); |
|
| 238 |
|
|
| 239 |
GLES20.glUniform3f( mBmpDH , mObjHalfX, mObjHalfY, mObjHalfZ); |
|
| 240 |
GLES20.glUniform1f( mDepthH, dp.depth); |
|
| 241 |
GLES20.glUniformMatrix4fv(mMVMatrixH , 1, false, mTmpMatrix, 0); |
|
| 242 |
GLES20.glUniformMatrix4fv(mMVPMatrixH, 1, false, mMVPMatrix, 0); |
|
| 243 |
} |
|
| 244 |
|
|
| 245 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 246 |
|
|
| 247 |
synchronized long add(EffectNames eln, Interpolator3D p, Interpolator i) |
|
| 248 |
{
|
|
| 249 |
if( mMax[INDEX]>mNumEffects ) |
|
| 250 |
{
|
|
| 251 |
mInterP[mNumEffects] = p; |
|
| 252 |
mInterI[mNumEffects] = i; |
|
| 253 |
|
|
| 254 |
return addBase(eln); |
|
| 255 |
} |
|
| 256 |
|
|
| 257 |
return -1; |
|
| 258 |
} |
|
| 259 |
|
|
| 260 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 261 |
|
|
| 262 |
synchronized long add(EffectNames eln, float x, float y, float z, Interpolator i) |
|
| 263 |
{
|
|
| 264 |
if( mMax[INDEX]>mNumEffects ) |
|
| 265 |
{
|
|
| 266 |
mInterP[mNumEffects] = null; |
|
| 267 |
mInterI[mNumEffects] = i; |
|
| 268 |
|
|
| 269 |
mUniforms[NUM_UNIFORMS*mNumEffects ] = x; |
|
| 270 |
mUniforms[NUM_UNIFORMS*mNumEffects+1] = y; |
|
| 271 |
mUniforms[NUM_UNIFORMS*mNumEffects+2] = z; |
|
| 272 |
|
|
| 273 |
return addBase(eln); |
|
| 274 |
} |
|
| 275 |
|
|
| 276 |
return -1; |
|
| 277 |
} |
|
| 278 |
|
|
| 279 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 280 |
|
|
| 281 |
synchronized long add(EffectNames eln, float x, float y, float z, Interpolator1D i, float aX, float aY, float aZ) |
|
| 282 |
{
|
|
| 283 |
if( mMax[INDEX]>mNumEffects ) |
|
| 284 |
{
|
|
| 285 |
mInterP[mNumEffects] = null; |
|
| 286 |
mInterI[mNumEffects] = i; |
|
| 287 |
|
|
| 288 |
mUniforms[NUM_UNIFORMS*mNumEffects ] = x; |
|
| 289 |
mUniforms[NUM_UNIFORMS*mNumEffects+1] = y; |
|
| 290 |
mUniforms[NUM_UNIFORMS*mNumEffects+2] = z; |
|
| 291 |
|
|
| 292 |
mUniforms[NUM_UNIFORMS*mNumEffects+4] = aX; |
|
| 293 |
mUniforms[NUM_UNIFORMS*mNumEffects+5] = aY; |
|
| 294 |
mUniforms[NUM_UNIFORMS*mNumEffects+6] = aZ; |
|
| 295 |
|
|
| 296 |
return addBase(eln); |
|
| 297 |
} |
|
| 298 |
|
|
| 299 |
return -1; |
|
| 300 |
} |
|
| 301 |
|
|
| 302 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 303 |
|
|
| 304 |
synchronized long add(EffectNames eln, Interpolator3D p, Interpolator1D i, float aX, float aY, float aZ) |
|
| 305 |
{
|
|
| 306 |
if( mMax[INDEX]>mNumEffects ) |
|
| 307 |
{
|
|
| 308 |
mInterP[mNumEffects] = p; |
|
| 309 |
mInterI[mNumEffects] = i; |
|
| 310 |
|
|
| 311 |
mUniforms[NUM_UNIFORMS*mNumEffects+4] = aX; |
|
| 312 |
mUniforms[NUM_UNIFORMS*mNumEffects+5] = aY; |
|
| 313 |
mUniforms[NUM_UNIFORMS*mNumEffects+6] = aZ; |
|
| 314 |
|
|
| 315 |
return addBase(eln); |
|
| 316 |
} |
|
| 317 |
|
|
| 318 |
return -1; |
|
| 319 |
} |
|
| 320 |
|
|
| 321 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 322 |
|
|
| 323 |
synchronized long add(EffectNames eln, float x, float y, float z, float aA, float aX, float aY, float aZ) |
|
| 324 |
{
|
|
| 325 |
if( mMax[INDEX]>mNumEffects ) |
|
| 326 |
{
|
|
| 327 |
mInterP[mNumEffects] = null; |
|
| 328 |
mInterI[mNumEffects] = null; |
|
| 329 |
|
|
| 330 |
mUniforms[NUM_UNIFORMS*mNumEffects ] = x; |
|
| 331 |
mUniforms[NUM_UNIFORMS*mNumEffects+1] = y; |
|
| 332 |
mUniforms[NUM_UNIFORMS*mNumEffects+2] = z; |
|
| 333 |
mUniforms[NUM_UNIFORMS*mNumEffects+3] = aA; |
|
| 334 |
mUniforms[NUM_UNIFORMS*mNumEffects+4] = aX; |
|
| 335 |
mUniforms[NUM_UNIFORMS*mNumEffects+5] = aY; |
|
| 336 |
mUniforms[NUM_UNIFORMS*mNumEffects+6] = aZ; |
|
| 337 |
|
|
| 338 |
return addBase(eln); |
|
| 339 |
} |
|
| 340 |
|
|
| 341 |
return -1; |
|
| 342 |
} |
|
| 343 |
|
|
| 344 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 345 |
} |
|
| src/main/java/org/distorted/library/EffectListOther.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 EffectListOther |
|
| 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 EffectListOther(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/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 | ||
|---|---|---|
| 6 | 6 |
|
| 7 | 7 |
class EffectListVertex extends EffectList |
| 8 | 8 |
{
|
| 9 |
private static final int NUM_UNIFORMS = 9; |
|
| 9 |
private static final int NUM_UNIFORMS = 9; |
|
| 10 |
private static final int INDEX = EffectTypes.VERTEX.ordinal(); |
|
| 10 | 11 |
private static int mNumEffectsH; |
| 11 | 12 |
private static int mTypeH; |
| 12 | 13 |
private static int mUniformsH; |
| ... | ... | |
| 15 | 16 |
|
| 16 | 17 |
public EffectListVertex(DistortedObject obj) |
| 17 | 18 |
{
|
| 18 |
super(obj,NUM_UNIFORMS,VERTEX);
|
|
| 19 |
super(obj,NUM_UNIFORMS,INDEX);
|
|
| 19 | 20 |
} |
| 20 | 21 |
|
| 21 | 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 24 | 25 |
|
| 25 | 26 |
static boolean setMax(int m) |
| 26 | 27 |
{
|
| 27 |
if( (mCreated==false && !Distorted.isInitialized()) || m<=mMax[VERTEX] )
|
|
| 28 |
if( (mCreated==false && !Distorted.isInitialized()) || m<=mMax[INDEX] )
|
|
| 28 | 29 |
{
|
| 29 | 30 |
if( m<0 ) m = 0; |
| 30 | 31 |
else if( m>Byte.MAX_VALUE ) m = Byte.MAX_VALUE; |
| 31 | 32 |
|
| 32 |
mMax[VERTEX] = m;
|
|
| 33 |
mMax[INDEX] = m;
|
|
| 33 | 34 |
return true; |
| 34 | 35 |
} |
| 35 | 36 |
|
| ... | ... | |
| 40 | 41 |
|
| 41 | 42 |
static int getMax() |
| 42 | 43 |
{
|
| 43 |
return mMax[VERTEX];
|
|
| 44 |
return mMax[INDEX];
|
|
| 44 | 45 |
} |
| 45 | 46 |
|
| 46 | 47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 77 | 78 |
for(int j=0; j<mNumListeners; j++) |
| 78 | 79 |
EffectMessageSender.newMessage( mListeners.elementAt(j), |
| 79 | 80 |
EffectMessage.EFFECT_FINISHED, |
| 80 |
(mID[i]<<DistortedObject.TYPE_NUM)+Distorted.TYPE_VERT,
|
|
| 81 |
(mID[i]<<EffectTypes.LENGTH)+EffectTypes.VERTEX.type,
|
|
| 81 | 82 |
mType[i], |
| 82 | 83 |
mBitmapID); |
| 83 | 84 |
|
| ... | ... | |
| 154 | 155 |
|
| 155 | 156 |
synchronized long add(EffectNames eln, Interpolator inter, Float4D region, Interpolator2D point) |
| 156 | 157 |
{
|
| 157 |
if( mMax[VERTEX]>mNumEffects )
|
|
| 158 |
if( mMax[INDEX]>mNumEffects )
|
|
| 158 | 159 |
{
|
| 159 | 160 |
EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects); |
| 160 | 161 |
|
| ... | ... | |
| 171 | 172 |
|
| 172 | 173 |
synchronized long add(EffectNames eln, Interpolator inter, Float4D region, float x, float y) |
| 173 | 174 |
{
|
| 174 |
if( mMax[VERTEX]>mNumEffects )
|
|
| 175 |
if( mMax[INDEX]>mNumEffects )
|
|
| 175 | 176 |
{
|
| 176 | 177 |
EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects); |
| 177 | 178 |
|
| ... | ... | |
| 190 | 191 |
|
| 191 | 192 |
synchronized long add(EffectNames eln, float v1, float v2, float v3, Float4D region, float x, float y) |
| 192 | 193 |
{
|
| 193 |
if( mMax[VERTEX]>mNumEffects )
|
|
| 194 |
if( mMax[INDEX]>mNumEffects )
|
|
| 194 | 195 |
{
|
| 195 | 196 |
EffectNames.fillWithUnities(eln.ordinal(), mUniforms, NUM_UNIFORMS*mNumEffects); |
| 196 | 197 |
mUniforms[NUM_UNIFORMS*mNumEffects ] = v1; |
| src/main/java/org/distorted/library/EffectNames.java | ||
|---|---|---|
| 6 | 6 |
{
|
| 7 | 7 |
// EFFECT NAME /////// EFFECT TYPE ////////////// UNITY ///////////////////////// |
| 8 | 8 |
|
| 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...
|
|
| 9 |
ROTATE ( EffectTypes.MATRIX , new float[] {0.0f} ),
|
|
| 10 |
QUATERNION ( EffectTypes.MATRIX , new float[] {0.0f,0.0f,0.0f} ), // quaternion is a unity iff its axis (x,y,z) is (0,0,0)
|
|
| 11 |
MOVE ( EffectTypes.MATRIX , new float[] {0.0f,0.0f,0.0f} ),
|
|
| 12 |
SCALE ( EffectTypes.MATRIX , new float[] {1.0f,1.0f,1.0f} ),
|
|
| 13 |
SHEAR ( EffectTypes.MATRIX , new float[] {0.0f,0.0f,0.0f} ),
|
|
| 14 |
// add new Matrix effects here...
|
|
| 15 | 15 |
|
| 16 |
DISTORT ( Distorted.TYPE_VERT, new float[] {0.0f,0.0f,0.0f} ), // keep this the first VERT effect (reason: getType)
|
|
Also available in: Unified diff
Introduce ENUM EffectTypes