Revision 26a4e5f6
Added by Leszek Koltunski over 8 years ago
| src/main/java/org/distorted/library/main/Distorted.java | ||
|---|---|---|
| 24 | 24 |
import android.content.pm.ConfigurationInfo; |
| 25 | 25 |
import android.content.res.Resources; |
| 26 | 26 |
|
| 27 |
import org.distorted.library.effect.Effect; |
|
| 27 | 28 |
import org.distorted.library.program.*; |
| 28 | 29 |
|
| 29 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 149 | 150 |
DistortedEffects.onDestroy(); |
| 150 | 151 |
DistortedMaster.onDestroy(); |
| 151 | 152 |
EffectQueue.onDestroy(); |
| 153 |
Effect.onDestroy(); |
|
| 152 | 154 |
EffectMessageSender.stopSending(); |
| 153 | 155 |
|
| 154 | 156 |
mInitialized = false; |
| src/main/java/org/distorted/library/main/DistortedEffects.java | ||
|---|---|---|
| 284 | 284 |
|
| 285 | 285 |
long getBucket() |
| 286 | 286 |
{
|
| 287 |
return mP.getBucket();
|
|
| 287 |
return mP.getID();
|
|
| 288 | 288 |
} |
| 289 | 289 |
|
| 290 | 290 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 301 | 301 |
return mP.getHalo(); |
| 302 | 302 |
} |
| 303 | 303 |
|
| 304 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 305 |
|
|
| 306 |
void newNode(DistortedNode node) |
|
| 307 |
{
|
|
| 308 |
mM.newNode(node); |
|
| 309 |
mF.newNode(node); |
|
| 310 |
mV.newNode(node); |
|
| 311 |
mP.newNode(node); |
|
| 312 |
} |
|
| 313 |
|
|
| 304 | 314 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 305 | 315 |
/** |
| 306 | 316 |
* This is not really part of the public API. Has to be public only because it is a part of the |
| ... | ... | |
| 454 | 464 |
*/ |
| 455 | 465 |
public DistortedEffects() |
| 456 | 466 |
{
|
| 467 |
android.util.Log.e("distEffects", "constr1");
|
|
| 457 | 468 |
mID = ++mNextID; |
| 458 | 469 |
initializeEffectLists(this,0); |
| 459 | 470 |
} |
| ... | ... | |
| 470 | 481 |
*/ |
| 471 | 482 |
public DistortedEffects(DistortedEffects dc, int flags) |
| 472 | 483 |
{
|
| 484 |
android.util.Log.e("distEffects", "constr2");
|
|
| 473 | 485 |
mID = ++mNextID; |
| 474 | 486 |
initializeEffectLists(dc,flags); |
| 475 | 487 |
} |
| ... | ... | |
| 505 | 517 |
@SuppressWarnings("unused")
|
| 506 | 518 |
public void registerForMessages(EffectListener el) |
| 507 | 519 |
{
|
| 520 |
mM.registerForMessages(el); |
|
| 508 | 521 |
mV.registerForMessages(el); |
| 509 | 522 |
mF.registerForMessages(el); |
| 510 |
mM.registerForMessages(el); |
|
| 511 | 523 |
mP.registerForMessages(el); |
| 512 | 524 |
} |
| 513 | 525 |
|
| ... | ... | |
| 520 | 532 |
@SuppressWarnings("unused")
|
| 521 | 533 |
public void deregisterForMessages(EffectListener el) |
| 522 | 534 |
{
|
| 535 |
mM.deregisterForMessages(el); |
|
| 523 | 536 |
mV.deregisterForMessages(el); |
| 524 | 537 |
mF.deregisterForMessages(el); |
| 525 |
mM.deregisterForMessages(el); |
|
| 526 | 538 |
mP.deregisterForMessages(el); |
| 527 | 539 |
} |
| 528 | 540 |
|
| ... | ... | |
| 690 | 702 |
{
|
| 691 | 703 |
switch(effect.getType()) |
| 692 | 704 |
{
|
| 705 |
case MATRIX : return mM.add(effect); |
|
| 693 | 706 |
case VERTEX : return mV.add(effect); |
| 694 | 707 |
case FRAGMENT : return mF.add(effect); |
| 695 |
case MATRIX : return mM.add(effect); |
|
| 696 | 708 |
case POSTPROCESS : return mP.add(effect); |
| 697 | 709 |
} |
| 698 | 710 |
|
| src/main/java/org/distorted/library/main/DistortedNode.java | ||
|---|---|---|
| 335 | 335 |
mParent = null; |
| 336 | 336 |
} |
| 337 | 337 |
|
| 338 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 339 |
|
|
| 340 |
void sort() |
|
| 341 |
{
|
|
| 342 |
if( mParent!=null ) |
|
| 343 |
{
|
|
| 344 |
mParent.mChildren.remove(this); |
|
| 345 |
DistortedMaster.addSorted(mParent.mChildren,this); |
|
| 346 |
} |
|
| 347 |
else if( mSurfaceParent!=null ) |
|
| 348 |
{
|
|
| 349 |
ArrayList<DistortedNode> children = mSurfaceParent.getChildren(); |
|
| 350 |
children.remove(this); |
|
| 351 |
DistortedMaster.addSorted(children,this); |
|
| 352 |
} |
|
| 353 |
} |
|
| 354 |
|
|
| 338 | 355 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 339 | 356 |
// PUBLIC API |
| 340 | 357 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 376 | 393 |
mData = new NodeData(++mNextNodeID,list); |
| 377 | 394 |
mMapNodeID.put(list, mData); |
| 378 | 395 |
} |
| 396 |
|
|
| 397 |
mEffects.newNode(this); |
|
| 379 | 398 |
} |
| 380 | 399 |
|
| 381 | 400 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 456 | 475 |
mData = new NodeData(++mNextNodeID,list); |
| 457 | 476 |
mMapNodeID.put(list, mData); |
| 458 | 477 |
} |
| 478 |
|
|
| 479 |
mEffects.newNode(this); |
|
| 459 | 480 |
} |
| 460 | 481 |
|
| 461 | 482 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/main/DistortedOutputSurface.java | ||
|---|---|---|
| 317 | 317 |
|
| 318 | 318 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 319 | 319 |
|
| 320 |
void newJob(int t, DistortedNode n)
|
|
| 320 |
ArrayList<DistortedNode> getChildren()
|
|
| 321 | 321 |
{
|
| 322 |
mJobs.add(new Job(t,n));
|
|
| 322 |
return mChildren;
|
|
| 323 | 323 |
} |
| 324 | 324 |
|
| 325 | 325 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 341 | 341 |
*/ |
| 342 | 342 |
public void setDebug(int bitmask) |
| 343 | 343 |
{
|
| 344 |
mDebugLevel = bitmask; |
|
| 344 |
if( this instanceof DistortedScreen ) |
|
| 345 |
mDebugLevel = bitmask; |
|
| 345 | 346 |
} |
| 346 | 347 |
|
| 347 | 348 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 356 | 357 |
*/ |
| 357 | 358 |
public int render(long time) |
| 358 | 359 |
{
|
| 359 |
boolean showDebug = ( mDebugLevel!=0 && this instanceof DistortedScreen ); |
|
| 360 |
|
|
| 361 |
if( showDebug ) prepareDebug(time); |
|
| 360 |
if( mDebugLevel!=0 ) prepareDebug(time); |
|
| 362 | 361 |
|
| 363 | 362 |
// change tree topology (attach and detach children) |
| 364 | 363 |
/* |
| ... | ... | |
| 404 | 403 |
setAsOutput(time); |
| 405 | 404 |
numRenders += renderChildren(time,mNumChildren,mChildren); |
| 406 | 405 |
|
| 407 |
if( showDebug ) renderDebug(time);
|
|
| 406 |
if( mDebugLevel != 0 ) renderDebug(time);
|
|
| 408 | 407 |
|
| 409 | 408 |
return numRenders; |
| 410 | 409 |
} |
| src/main/java/org/distorted/library/main/DistortedScreen.java | ||
|---|---|---|
| 55 | 55 |
private long[] durations; |
| 56 | 56 |
private int currDuration; |
| 57 | 57 |
private static MatrixEffectMove mMoveEffect = new MatrixEffectMove( new Static3D(5,5,0) ); |
| 58 |
private boolean mInitialized; |
|
| 58 | 59 |
|
| 59 | 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 60 | 61 |
// here we don't manage underlying OpenGL assets ourselves |
| ... | ... | |
| 63 | 64 |
void delete() {}
|
| 64 | 65 |
void recreate() {}
|
| 65 | 66 |
|
| 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 68 |
|
|
| 69 |
private void initialize() |
|
| 70 |
{
|
|
| 71 |
fpsW = 120; |
|
| 72 |
fpsH = 70; |
|
| 73 |
|
|
| 74 |
fpsBitmap = Bitmap.createBitmap(fpsW,fpsH, Bitmap.Config.ARGB_8888); |
|
| 75 |
fpsMesh = new MeshFlat(1,1); |
|
| 76 |
fpsTexture = new DistortedTexture(fpsW,fpsH); |
|
| 77 |
fpsTexture.setTexture(fpsBitmap); |
|
| 78 |
fpsCanvas = new Canvas(fpsBitmap); |
|
| 79 |
fpsEffects = new DistortedEffects(); |
|
| 80 |
fpsEffects.apply(mMoveEffect); |
|
| 81 |
|
|
| 82 |
mPaint = new Paint(); |
|
| 83 |
mPaint.setAntiAlias(true); |
|
| 84 |
mPaint.setTextAlign(Paint.Align.CENTER); |
|
| 85 |
mPaint.setTextSize(0.7f*fpsH); |
|
| 86 |
|
|
| 87 |
durations = new long[NUM_FRAMES+1]; |
|
| 88 |
currDuration = 0; |
|
| 89 |
|
|
| 90 |
for(int i=0; i<NUM_FRAMES+1; i++) durations[i]=16; // Assume FPS will be |
|
| 91 |
durations[NUM_FRAMES] = NUM_FRAMES*16; // close to 1000/16 ~ 60 |
|
| 92 |
mInitialized=true; |
|
| 93 |
} |
|
| 94 |
|
|
| 66 | 95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 67 | 96 |
|
| 68 | 97 |
void prepareDebug(long time) |
| 69 | 98 |
{
|
| 99 |
if( !mInitialized ) initialize(); |
|
| 100 |
|
|
| 70 | 101 |
if( lastTime==0 ) lastTime = time; |
| 71 | 102 |
|
| 72 | 103 |
currDuration++; |
| ... | ... | |
| 122 | 153 |
view.setEGLContextClientVersion((configurationInfo.reqGlEsVersion >> 16) >= 3 ? 3 : 2); |
| 123 | 154 |
} |
| 124 | 155 |
|
| 125 |
/////// DEBUGGING ONLY ////////////// |
|
| 126 |
fpsW = 120; |
|
| 127 |
fpsH = 70; |
|
| 128 |
|
|
| 129 |
fpsBitmap = Bitmap.createBitmap(fpsW,fpsH, Bitmap.Config.ARGB_8888); |
|
| 130 |
fpsMesh = new MeshFlat(1,1); |
|
| 131 |
fpsTexture = new DistortedTexture(fpsW,fpsH); |
|
| 132 |
fpsTexture.setTexture(fpsBitmap); |
|
| 133 |
fpsCanvas = new Canvas(fpsBitmap); |
|
| 134 |
fpsEffects = new DistortedEffects(); |
|
| 135 |
fpsEffects.apply(mMoveEffect); |
|
| 136 |
|
|
| 137 |
mPaint = new Paint(); |
|
| 138 |
mPaint.setAntiAlias(true); |
|
| 139 |
mPaint.setTextAlign(Paint.Align.CENTER); |
|
| 140 |
mPaint.setTextSize(0.7f*fpsH); |
|
| 141 |
|
|
| 142 |
durations = new long[NUM_FRAMES+1]; |
|
| 143 |
currDuration = 0; |
|
| 144 |
|
|
| 145 |
for(int i=0; i<NUM_FRAMES+1; i++) durations[i]=16; // Assume FPS will be |
|
| 146 |
durations[NUM_FRAMES] = NUM_FRAMES*16; // close to 1000/16 ~ 60 |
|
| 156 |
mInitialized = false; |
|
| 147 | 157 |
} |
| 148 | 158 |
} |
| src/main/java/org/distorted/library/main/EffectQueue.java | ||
|---|---|---|
| 25 | 25 |
import org.distorted.library.message.EffectListener; |
| 26 | 26 |
import org.distorted.library.message.EffectMessage; |
| 27 | 27 |
|
| 28 |
import java.util.Vector;
|
|
| 28 |
import java.util.ArrayList;
|
|
| 29 | 29 |
|
| 30 | 30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 31 | 31 |
|
| 32 |
abstract class EffectQueue |
|
| 32 |
abstract class EffectQueue implements DistortedSlave
|
|
| 33 | 33 |
{
|
| 34 |
protected byte mNumEffects; |
|
| 34 |
private static final int ATTACH = 0; |
|
| 35 |
private static final int DETACH = 1; |
|
| 36 |
private static final int DETALL = 2; |
|
| 37 |
|
|
| 38 |
protected int mNumEffects; |
|
| 35 | 39 |
protected float[] mUniforms; |
| 36 | 40 |
protected long[] mCurrentDuration; |
| 37 | 41 |
protected Effect[] mEffects; |
| 38 | 42 |
protected int[] mName; |
| 39 | 43 |
protected long mTime=0; |
| 40 | 44 |
protected static int[] mMax = new int[EffectType.LENGTH]; |
| 41 |
protected Vector<EffectListener> mListeners =null;
|
|
| 45 |
protected ArrayList<EffectListener> mListeners =null;
|
|
| 42 | 46 |
protected int mNumListeners=0; // ==mListeners.length(), but we only create mListeners if the first one gets added |
| 43 | 47 |
protected long mDistortedEffectsID; |
| 44 | 48 |
|
| 49 |
private ArrayList<DistortedNode> mNodes = null; |
|
| 50 |
private long mID; |
|
| 51 |
private int mNumEffectsToBe; // this will be more than mNumEffects if doWork hasn't really added them yet |
|
| 45 | 52 |
private static boolean mCreated; |
| 46 | 53 |
private int mIndex; |
| 47 | 54 |
private int mNumUniforms; |
| 48 | 55 |
|
| 56 |
private class Job |
|
| 57 |
{
|
|
| 58 |
int type; |
|
| 59 |
int index; |
|
| 60 |
boolean notify; |
|
| 61 |
Effect effect; |
|
| 62 |
|
|
| 63 |
Job(int t, int i, boolean n, Effect e) |
|
| 64 |
{
|
|
| 65 |
type = t; |
|
| 66 |
index = i; |
|
| 67 |
notify= n; |
|
| 68 |
effect= e; |
|
| 69 |
} |
|
| 70 |
} |
|
| 71 |
|
|
| 72 |
private ArrayList<Job> mJobs = new ArrayList<>(); |
|
| 73 |
|
|
| 49 | 74 |
static |
| 50 | 75 |
{
|
| 51 | 76 |
onDestroy(); |
| ... | ... | |
| 55 | 80 |
|
| 56 | 81 |
EffectQueue(long id, int numUniforms, int index) |
| 57 | 82 |
{
|
| 83 |
mID = 0; |
|
| 58 | 84 |
mNumEffects = 0; |
| 85 |
mNumEffectsToBe = 0; |
|
| 59 | 86 |
mDistortedEffectsID = id; |
| 60 | 87 |
mIndex = index; |
| 61 | 88 |
mNumUniforms = numUniforms; |
| ... | ... | |
| 73 | 100 |
mCreated = true; |
| 74 | 101 |
} |
| 75 | 102 |
|
| 103 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 104 |
// TODO: introduce a Map to return an ID dependant on all Effects in the Queue. |
|
| 105 |
// For now this is good enough. |
|
| 106 |
|
|
| 107 |
private void regenerateID() |
|
| 108 |
{
|
|
| 109 |
mID = mNumEffects>0 ? mEffects[0].getID() : 0; |
|
| 110 |
} |
|
| 111 |
|
|
| 112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 113 |
|
|
| 114 |
void newNode(DistortedNode node) |
|
| 115 |
{
|
|
| 116 |
if( mNodes==null ) mNodes = new ArrayList<>(); |
|
| 117 |
|
|
| 118 |
mNodes.add(node); |
|
| 119 |
} |
|
| 120 |
|
|
| 76 | 121 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 77 | 122 |
|
| 78 | 123 |
@SuppressWarnings("unused")
|
| ... | ... | |
| 82 | 127 |
} |
| 83 | 128 |
|
| 84 | 129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 85 |
// Only max Byte.MAX_VALUE concurrent effects per DistortedEffects object. |
|
| 86 |
// If you want more, change type of the mNumEffects, mIDIndex and mFreeIndexes variables to shorts. |
|
| 87 |
// (although probably this many uniforms will not fit in the shaders anyway!) |
|
| 130 |
|
|
| 131 |
long getID() |
|
| 132 |
{
|
|
| 133 |
return mID; |
|
| 134 |
} |
|
| 135 |
|
|
| 136 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 88 | 137 |
|
| 89 | 138 |
static boolean setMax(int index, int m) |
| 90 | 139 |
{
|
| 91 | 140 |
if( (!mCreated && !Distorted.isInitialized()) || m<=mMax[index] ) |
| 92 | 141 |
{
|
| 93 |
if( m<0 ) m = 0; |
|
| 94 |
else if( m>Byte.MAX_VALUE ) m = Byte.MAX_VALUE; |
|
| 95 |
|
|
| 96 |
mMax[index] = m; |
|
| 142 |
mMax[index] = m<0 ? 0:m; |
|
| 97 | 143 |
return true; |
| 98 | 144 |
} |
| 99 | 145 |
|
| ... | ... | |
| 111 | 157 |
|
| 112 | 158 |
void registerForMessages(EffectListener el) |
| 113 | 159 |
{
|
| 114 |
if( mListeners==null ) mListeners = new Vector<>(2,2);
|
|
| 160 |
if( mListeners==null ) mListeners = new ArrayList<>();
|
|
| 115 | 161 |
|
| 116 | 162 |
if( !mListeners.contains(el) ) |
| 117 | 163 |
{
|
| ... | ... | |
| 139 | 185 |
} |
| 140 | 186 |
|
| 141 | 187 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 188 |
// this assumes 0<=effect<mNumEffects |
|
| 142 | 189 |
|
| 143 |
synchronized int removeByName(EffectName name)
|
|
| 190 |
protected void remove(int effect)
|
|
| 144 | 191 |
{
|
| 145 |
int ret = 0; |
|
| 192 |
mNumEffects--; |
|
| 193 |
|
|
| 194 |
long removedID = mEffects[effect].getID(); |
|
| 195 |
|
|
| 196 |
for(int j=effect; j<mNumEffects; j++ ) |
|
| 197 |
{
|
|
| 198 |
mEffects[j] = mEffects[j+1]; |
|
| 199 |
mCurrentDuration[j] = mCurrentDuration[j+1]; |
|
| 200 |
mName[j] = mName[j+1]; |
|
| 201 |
|
|
| 202 |
for(int k=0; k<mNumUniforms; k++) |
|
| 203 |
mUniforms[mNumUniforms*j+k] = mUniforms[mNumUniforms*(j+1)+k]; |
|
| 204 |
} |
|
| 205 |
|
|
| 206 |
mEffects[mNumEffects] = null; |
|
| 207 |
|
|
| 208 |
for(int i=0; i<mNumListeners; i++) |
|
| 209 |
EffectMessageSender.newMessage( mListeners.get(i), EffectMessage.EFFECT_REMOVED, removedID, mDistortedEffectsID); |
|
| 210 |
} |
|
| 146 | 211 |
|
| 212 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 213 |
|
|
| 214 |
synchronized int removeByName(EffectName name) |
|
| 215 |
{
|
|
| 147 | 216 |
for(int i=0; i<mNumEffects; i++) |
| 148 | 217 |
{
|
| 149 | 218 |
if( mEffects[i].getName() == name ) |
| 150 | 219 |
{
|
| 151 |
remove(i); |
|
| 152 |
i--; |
|
| 153 |
ret++; |
|
| 220 |
mJobs.add(new Job(DETACH,i,true,null)); |
|
| 221 |
DistortedMaster.newSlave(this); |
|
| 222 |
mNumEffectsToBe--; |
|
| 223 |
return 1; |
|
| 154 | 224 |
} |
| 155 | 225 |
} |
| 156 | 226 |
|
| 157 |
return ret;
|
|
| 227 |
return 0;
|
|
| 158 | 228 |
} |
| 159 | 229 |
|
| 160 | 230 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 161 | 231 |
|
| 162 | 232 |
synchronized int removeById(long id) |
| 163 | 233 |
{
|
| 164 |
int ret = 0; |
|
| 165 |
|
|
| 166 | 234 |
for(int i=0; i<mNumEffects; i++) |
| 167 | 235 |
{
|
| 168 | 236 |
if( mEffects[i].getID() == id ) |
| 169 | 237 |
{
|
| 170 |
remove(i); |
|
| 171 |
i--; |
|
| 172 |
ret++; |
|
| 238 |
mJobs.add(new Job(DETACH,i,true,null)); |
|
| 239 |
DistortedMaster.newSlave(this); |
|
| 240 |
mNumEffectsToBe--; |
|
| 241 |
return 1; |
|
| 173 | 242 |
} |
| 174 | 243 |
} |
| 175 | 244 |
|
| 176 |
return ret;
|
|
| 245 |
return 0;
|
|
| 177 | 246 |
} |
| 178 | 247 |
|
| 179 | 248 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 180 | 249 |
|
| 181 | 250 |
synchronized int removeEffect(Effect effect) |
| 182 | 251 |
{
|
| 183 |
int ret = 0; |
|
| 184 |
|
|
| 185 | 252 |
for(int i=0; i<mNumEffects; i++) |
| 186 | 253 |
{
|
| 187 | 254 |
if( mEffects[i]==effect ) |
| 188 | 255 |
{
|
| 189 |
remove(i); |
|
| 190 |
i--; |
|
| 191 |
ret++; |
|
| 256 |
mJobs.add(new Job(DETACH,i,true,null)); |
|
| 257 |
DistortedMaster.newSlave(this); |
|
| 258 |
mNumEffectsToBe--; |
|
| 259 |
return 1; |
|
| 192 | 260 |
} |
| 193 | 261 |
} |
| 194 | 262 |
|
| 195 |
return ret;
|
|
| 263 |
return 0;
|
|
| 196 | 264 |
} |
| 197 | 265 |
|
| 198 | 266 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 201 | 269 |
|
| 202 | 270 |
synchronized int abortAll(boolean notify) |
| 203 | 271 |
{
|
| 204 |
int ret = mNumEffects; |
|
| 272 |
mJobs.add(new Job(DETALL,0,notify,null)); |
|
| 273 |
DistortedMaster.newSlave(this); |
|
| 274 |
mNumEffectsToBe = 0; |
|
| 275 |
return mNumEffects; |
|
| 276 |
} |
|
| 205 | 277 |
|
| 206 |
for(int i=0; i<ret; i++ ) |
|
| 278 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 279 |
|
|
| 280 |
boolean add(Effect effect) |
|
| 281 |
{
|
|
| 282 |
if( mMax[mIndex]>mNumEffectsToBe ) |
|
| 207 | 283 |
{
|
| 208 |
if( notify ) |
|
| 209 |
{
|
|
| 210 |
for(int j=0; j<mNumListeners; j++) |
|
| 211 |
EffectMessageSender.newMessage( mListeners.elementAt(j), EffectMessage.EFFECT_REMOVED, mEffects[i].getID(), mDistortedEffectsID); |
|
| 212 |
} |
|
| 284 |
//android.util.Log.e("queue", "scheduling future add of "+effect.getName().name()+" to "+mNumEffectsToBe+" id="+effect.getID());
|
|
| 285 |
//android.util.Log.e("queue", "queue id="+mDistortedEffectsID);
|
|
| 213 | 286 |
|
| 214 |
mEffects[i] = null; |
|
| 287 |
mJobs.add(new Job(ATTACH,mNumEffectsToBe,false,effect)); |
|
| 288 |
DistortedMaster.newSlave(this); |
|
| 289 |
mNumEffectsToBe++; |
|
| 290 |
return true; |
|
| 215 | 291 |
} |
| 216 | 292 |
|
| 217 |
mNumEffects= 0; |
|
| 218 |
|
|
| 219 |
return ret; |
|
| 293 |
return false; |
|
| 220 | 294 |
} |
| 221 | 295 |
|
| 222 | 296 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 223 |
// this assumes 0<=effect<mNumEffects |
|
| 224 |
|
|
| 225 |
protected void remove(int effect) |
|
| 297 |
/** |
|
| 298 |
* This is not really part of the public API. Has to be public only because it is a part of the |
|
| 299 |
* DistortedSlave interface, which should really be a class that we extend here instead but |
|
| 300 |
* Java has no multiple inheritance. |
|
| 301 |
* |
|
| 302 |
* @y.exclude |
|
| 303 |
*/ |
|
| 304 |
public void doWork() |
|
| 226 | 305 |
{
|
| 227 |
mNumEffects--; |
|
| 306 |
int num = mJobs.size(); |
|
| 307 |
Job job; |
|
| 228 | 308 |
|
| 229 |
long removedID = mEffects[effect].getID(); |
|
| 230 |
|
|
| 231 |
for(int j=effect; j<mNumEffects; j++ ) |
|
| 309 |
for(int i=0; i<num; i++) |
|
| 232 | 310 |
{
|
| 233 |
mEffects[j] = mEffects[j+1]; |
|
| 234 |
mCurrentDuration[j] = mCurrentDuration[j+1]; |
|
| 235 |
mName[j] = mName[j+1]; |
|
| 311 |
job = mJobs.remove(0); |
|
| 236 | 312 |
|
| 237 |
for(int k=0; k<mNumUniforms; k++) |
|
| 238 |
mUniforms[mNumUniforms*j+k] = mUniforms[mNumUniforms*(j+1)+k]; |
|
| 313 |
switch(job.type) |
|
| 314 |
{
|
|
| 315 |
case ATTACH: android.util.Log.e("queue", "DistortedEffects ID: "+mDistortedEffectsID+" bank:"+job.index+
|
|
| 316 |
" attaching effectID="+job.effect.getID()+" ("+job.effect.getName().name()+")");
|
|
| 317 |
|
|
| 318 |
mCurrentDuration[job.index] = 0; |
|
| 319 |
mEffects[job.index] = job.effect; |
|
| 320 |
mName[job.index] = job.effect.getName().ordinal(); |
|
| 321 |
mNumEffects++; |
|
| 322 |
break; |
|
| 323 |
case DETACH: remove(job.index); |
|
| 324 |
break; |
|
| 325 |
case DETALL: for(int j=0; j<mNumEffects; j++ ) |
|
| 326 |
{
|
|
| 327 |
if( job.notify ) |
|
| 328 |
{
|
|
| 329 |
for(int k=0; k<mNumListeners; k++) |
|
| 330 |
EffectMessageSender.newMessage( mListeners.get(k), EffectMessage.EFFECT_REMOVED, mEffects[j].getID(), mDistortedEffectsID); |
|
| 331 |
} |
|
| 332 |
|
|
| 333 |
mEffects[j] = null; |
|
| 334 |
} |
|
| 335 |
|
|
| 336 |
mNumEffects= 0; |
|
| 337 |
break; |
|
| 338 |
} |
|
| 239 | 339 |
} |
| 240 |
|
|
| 241 |
mEffects[mNumEffects] = null; |
|
| 242 | 340 |
|
| 243 |
for(int i=0; i<mNumListeners; i++) |
|
| 244 |
EffectMessageSender.newMessage( mListeners.elementAt(i), EffectMessage.EFFECT_REMOVED, removedID, mDistortedEffectsID); |
|
| 245 |
} |
|
| 246 |
|
|
| 247 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 248 |
|
|
| 249 |
boolean add(Effect effect) |
|
| 250 |
{
|
|
| 251 |
if( mMax[mIndex]>mNumEffects ) |
|
| 341 |
if( num>0 ) |
|
| 252 | 342 |
{
|
| 253 |
mCurrentDuration[mNumEffects] = 0; |
|
| 254 |
mEffects[mNumEffects] = effect; |
|
| 255 |
mName[mNumEffects] = effect.getName().ordinal(); |
|
| 256 |
mNumEffects++; |
|
| 257 |
return true; |
|
| 258 |
} |
|
| 343 |
regenerateID(); |
|
| 259 | 344 |
|
| 260 |
return false; |
|
| 345 |
if( mIndex==EffectType.POSTPROCESS.ordinal() ) |
|
| 346 |
{
|
|
| 347 |
int numNodes = (mNodes==null ? 0: mNodes.size()); |
|
| 348 |
|
|
| 349 |
for(int i=0; i<numNodes; i++) |
|
| 350 |
{
|
|
| 351 |
mNodes.get(i).sort(); |
|
| 352 |
} |
|
| 353 |
} |
|
| 354 |
} |
|
| 261 | 355 |
} |
| 262 | 356 |
} |
| src/main/java/org/distorted/library/main/EffectQueueFragment.java | ||
|---|---|---|
| 66 | 66 |
if( mEffects[i].compute(mUniforms, NUM_UNIFORMS*i, mCurrentDuration[i], step) ) |
| 67 | 67 |
{
|
| 68 | 68 |
for(int j=0; j<mNumListeners; j++) |
| 69 |
EffectMessageSender.newMessage( mListeners.elementAt(j), EffectMessage.EFFECT_FINISHED, mEffects[i].getID(), mDistortedEffectsID);
|
|
| 69 |
EffectMessageSender.newMessage( mListeners.get(j), EffectMessage.EFFECT_FINISHED, mEffects[i].getID(), mDistortedEffectsID);
|
|
| 70 | 70 |
|
| 71 | 71 |
if( mEffects[i].isUnity( mUniforms, NUM_UNIFORMS*i) ) |
| 72 | 72 |
{
|
| src/main/java/org/distorted/library/main/EffectQueueMatrix.java | ||
|---|---|---|
| 299 | 299 |
if( mEffects[i].compute(mUniforms, NUM_UNIFORMS*i, mCurrentDuration[i], step) ) |
| 300 | 300 |
{
|
| 301 | 301 |
for(int j=0; j<mNumListeners; j++) |
| 302 |
EffectMessageSender.newMessage( mListeners.elementAt(j), EffectMessage.EFFECT_FINISHED, mEffects[i].getID(), mDistortedEffectsID);
|
|
| 302 |
EffectMessageSender.newMessage( mListeners.get(j), EffectMessage.EFFECT_FINISHED, mEffects[i].getID(), mDistortedEffectsID);
|
|
| 303 | 303 |
|
| 304 | 304 |
if( mEffects[i].isUnity( mUniforms, NUM_UNIFORMS*i) ) |
| 305 | 305 |
remove(i--); |
| src/main/java/org/distorted/library/main/EffectQueuePostprocess.java | ||
|---|---|---|
| 187 | 187 |
if( mEffects[i].compute(mUniforms, NUM_UNIFORMS*i, mCurrentDuration[i], step) ) |
| 188 | 188 |
{
|
| 189 | 189 |
for(int j=0; j<mNumListeners; j++) |
| 190 |
EffectMessageSender.newMessage( mListeners.elementAt(j), EffectMessage.EFFECT_FINISHED, mEffects[i].getID(), mDistortedEffectsID);
|
|
| 190 |
EffectMessageSender.newMessage( mListeners.get(j), EffectMessage.EFFECT_FINISHED, mEffects[i].getID(), mDistortedEffectsID);
|
|
| 191 | 191 |
|
| 192 | 192 |
if( mEffects[i].isUnity( mUniforms, NUM_UNIFORMS*i) ) |
| 193 | 193 |
{
|
| ... | ... | |
| 250 | 250 |
} |
| 251 | 251 |
} |
| 252 | 252 |
|
| 253 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 254 |
|
|
| 255 |
long getBucket() |
|
| 256 |
{
|
|
| 257 |
return mNumEffects>0 ? mEffects[0].getID() : 0; |
|
| 258 |
} |
|
| 259 |
|
|
| 260 | 253 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 261 | 254 |
|
| 262 | 255 |
int getHalo() |
| src/main/java/org/distorted/library/main/EffectQueueVertex.java | ||
|---|---|---|
| 66 | 66 |
if( mEffects[i].compute(mUniforms, NUM_UNIFORMS*i, mCurrentDuration[i], step) ) |
| 67 | 67 |
{
|
| 68 | 68 |
for(int j=0; j<mNumListeners; j++) |
| 69 |
EffectMessageSender.newMessage( mListeners.elementAt(j), EffectMessage.EFFECT_FINISHED, mEffects[i].getID(), mDistortedEffectsID);
|
|
| 69 |
EffectMessageSender.newMessage( mListeners.get(j), EffectMessage.EFFECT_FINISHED, mEffects[i].getID(), mDistortedEffectsID);
|
|
| 70 | 70 |
|
| 71 | 71 |
if( mEffects[i].isUnity( mUniforms, NUM_UNIFORMS*i) ) |
| 72 | 72 |
{
|
Also available in: Unified diff
Reorganize the way we add and remove all Effects (do it through DistortedMaster and is POSTPROCES - adjust Bucket and SORT Nodes).
Buggy: removing effects does not work.