Revision 71887484
Added by Leszek Koltunski over 8 years ago
src/main/java/org/distorted/library/Distorted.java | ||
---|---|---|
108 | 108 |
int realMaxV = (maxV-11)/4; // adjust this in case of changes to the shaders... |
109 | 109 |
int realMaxF = (maxF- 2)/4; // |
110 | 110 |
|
111 |
if( EffectQueueVertex.getMax() > realMaxV )
|
|
111 |
if( getMaxVertex() > realMaxV )
|
|
112 | 112 |
{ |
113 | 113 |
throw new VertexUniformsException("Too many effects in the vertex shader, max is "+realMaxV, realMaxV); |
114 | 114 |
} |
115 |
if( EffectQueueFragment.getMax() > realMaxF )
|
|
115 |
if( getMaxFragment() > realMaxF )
|
|
116 | 116 |
{ |
117 | 117 |
throw new FragmentUniformsException("Too many effects in the fragment shader, max is "+realMaxF, realMaxF); |
118 | 118 |
} |
... | ... | |
204 | 204 |
|
205 | 205 |
switch(type) |
206 | 206 |
{ |
207 |
case GLES20.GL_VERTEX_SHADER : header += ("#define NUM_VERTEX " + EffectQueueVertex.getMax()+"\n");
|
|
207 |
case GLES20.GL_VERTEX_SHADER : header += ("#define NUM_VERTEX " + getMaxVertex()+"\n");
|
|
208 | 208 |
|
209 | 209 |
for(EffectNames name: EffectNames.values() ) |
210 | 210 |
{ |
... | ... | |
212 | 212 |
header += ("#define "+name.name()+" "+name.ordinal()+"\n"); |
213 | 213 |
} |
214 | 214 |
break; |
215 |
case GLES20.GL_FRAGMENT_SHADER: header += ("#define NUM_FRAGMENT "+ EffectQueueFragment.getMax()+"\n");
|
|
215 |
case GLES20.GL_FRAGMENT_SHADER: header += ("#define NUM_FRAGMENT "+ getMaxFragment()+"\n");
|
|
216 | 216 |
|
217 | 217 |
for(EffectNames name: EffectNames.values() ) |
218 | 218 |
{ |
... | ... | |
378 | 378 |
{ |
379 | 379 |
DistortedObjectList.release(); |
380 | 380 |
DistortedNode.release(); |
381 |
|
|
382 |
EffectQueueVertex.reset(); |
|
383 |
EffectQueueFragment.reset(); |
|
384 |
EffectQueueMatrix.reset(); // no need to reset Other EffectQueue |
|
385 |
|
|
381 |
EffectQueue.reset(); |
|
386 | 382 |
EffectMessageSender.stopSending(); |
387 | 383 |
|
388 | 384 |
mInitialized = false; |
... | ... | |
408 | 404 |
*/ |
409 | 405 |
public static int getMaxMatrix() |
410 | 406 |
{ |
411 |
return EffectQueueMatrix.getMax();
|
|
407 |
return EffectQueue.getMax(EffectTypes.MATRIX.ordinal());
|
|
412 | 408 |
} |
413 | 409 |
|
414 | 410 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
419 | 415 |
*/ |
420 | 416 |
public static int getMaxVertex() |
421 | 417 |
{ |
422 |
return EffectQueueVertex.getMax();
|
|
418 |
return EffectQueue.getMax(EffectTypes.VERTEX.ordinal());
|
|
423 | 419 |
} |
424 | 420 |
|
425 | 421 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
430 | 426 |
*/ |
431 | 427 |
public static int getMaxFragment() |
432 | 428 |
{ |
433 |
return EffectQueueFragment.getMax();
|
|
429 |
return EffectQueue.getMax(EffectTypes.FRAGMENT.ordinal());
|
|
434 | 430 |
} |
435 |
|
|
431 |
|
|
432 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
433 |
/** |
|
434 |
* Returns the maximum number of Other effects. |
|
435 |
* |
|
436 |
* @return The maximum number of Other effects |
|
437 |
*/ |
|
438 |
public static int getMaxOther() |
|
439 |
{ |
|
440 |
return EffectQueue.getMax(EffectTypes.OTHER.ordinal()); |
|
441 |
} |
|
442 |
|
|
436 | 443 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
437 | 444 |
/** |
438 |
* Sets the maximum number of Matrix effects that can be applied to a single DistortedBitmap at one time.
|
|
445 |
* Sets the maximum number of Matrix effects that can be applied to a single DistortedObject at one time.
|
|
439 | 446 |
* This can fail if the value of 'max' is outside permitted range. |
440 | 447 |
* |
441 | 448 |
* @param max new maximum number of simultaneous Matrix Effects. Has to be a non-negative number not greater |
... | ... | |
444 | 451 |
*/ |
445 | 452 |
public static boolean setMaxMatrix(int max) |
446 | 453 |
{ |
447 |
return EffectQueueMatrix.setMax(max);
|
|
454 |
return EffectQueue.setMax(EffectTypes.MATRIX.ordinal(),max);
|
|
448 | 455 |
} |
449 | 456 |
|
450 | 457 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
451 | 458 |
/** |
452 |
* Sets the maximum number of Vertex effects that can be applied to a single DistortedBitmap at one time.
|
|
459 |
* Sets the maximum number of Vertex effects that can be applied to a single DistortedObject at one time.
|
|
453 | 460 |
* This can fail if: |
454 | 461 |
* <ul> |
455 | 462 |
* <li>the value of 'max' is outside permitted range |
... | ... | |
464 | 471 |
*/ |
465 | 472 |
public static boolean setMaxVertex(int max) |
466 | 473 |
{ |
467 |
return EffectQueueVertex.setMax(max);
|
|
474 |
return EffectQueue.setMax(EffectTypes.VERTEX.ordinal(),max);
|
|
468 | 475 |
} |
469 | 476 |
|
470 | 477 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
471 | 478 |
/** |
472 |
* Sets the maximum number of Fragment effects that can be applied to a single DistortedBitmap at one time.
|
|
479 |
* Sets the maximum number of Fragment effects that can be applied to a single DistortedObject at one time.
|
|
473 | 480 |
* This can fail if: |
474 | 481 |
* <ul> |
475 | 482 |
* <li>the value of 'max' is outside permitted range |
... | ... | |
484 | 491 |
*/ |
485 | 492 |
public static boolean setMaxFragment(int max) |
486 | 493 |
{ |
487 |
return EffectQueueFragment.setMax(max);
|
|
494 |
return EffectQueue.setMax(EffectTypes.FRAGMENT.ordinal(),max);
|
|
488 | 495 |
} |
489 |
|
|
496 |
|
|
497 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
498 |
/** |
|
499 |
* Sets the maximum number of Other effects that can be applied to a single DistortedObject at one time. |
|
500 |
* This can fail if the value of 'max' is outside permitted range. |
|
501 |
* |
|
502 |
* @param max new maximum number of simultaneous Other Effects. Has to be a non-negative number not greater |
|
503 |
* than Byte.MAX_VALUE |
|
504 |
* @return <code>true</code> if operation was successful, <code>false</code> otherwise. |
|
505 |
*/ |
|
506 |
public static boolean setMaxOther(int max) |
|
507 |
{ |
|
508 |
return EffectQueue.setMax(EffectTypes.OTHER.ordinal(),max); |
|
509 |
} |
|
510 |
|
|
490 | 511 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
491 | 512 |
//end of file |
492 | 513 |
} |
src/main/java/org/distorted/library/EffectQueue.java | ||
---|---|---|
23 | 23 |
|
24 | 24 |
protected static int[] mMax = new int[EffectTypes.LENGTH]; |
25 | 25 |
protected int mMaxIndex; |
26 |
protected static boolean mCreated; |
|
27 |
|
|
26 |
|
|
28 | 27 |
protected Vector<EffectListener> mListeners =null; |
29 | 28 |
protected int mNumListeners=0; // ==mListeners.length(), but we only create mListeners if the first one gets added |
30 | 29 |
protected long mBitmapID; |
31 |
|
|
30 |
|
|
31 |
private static boolean mCreated; |
|
32 |
|
|
32 | 33 |
static |
33 | 34 |
{ |
34 | 35 |
reset(); |
... | ... | |
75 | 76 |
return mNumEffects; |
76 | 77 |
} |
77 | 78 |
|
79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
80 |
// Only max Byte.MAX_VALUE concurrent effects per DistortedObject. |
|
81 |
// If you want more, change type of the mNumEffects, mIDIndex and mFreeIndexes variables to shorts. |
|
82 |
|
|
83 |
static boolean setMax(int index, int m) |
|
84 |
{ |
|
85 |
if( (mCreated==false && !Distorted.isInitialized()) || m<=mMax[index] ) |
|
86 |
{ |
|
87 |
if( m<0 ) m = 0; |
|
88 |
else if( m>Byte.MAX_VALUE ) m = Byte.MAX_VALUE; |
|
89 |
|
|
90 |
mMax[index] = m; |
|
91 |
return true; |
|
92 |
} |
|
93 |
|
|
94 |
return false; |
|
95 |
} |
|
96 |
|
|
97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
98 |
|
|
99 |
static int getMax(int index) |
|
100 |
{ |
|
101 |
return mMax[index]; |
|
102 |
} |
|
103 |
|
|
78 | 104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
79 | 105 |
|
80 | 106 |
void addListener(EffectListener el) |
src/main/java/org/distorted/library/EffectQueueFragment.java | ||
---|---|---|
24 | 24 |
mBuf= new float[4*mMax[INDEX]]; |
25 | 25 |
} |
26 | 26 |
} |
27 |
|
|
28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
29 |
// Only max Byte.MAX_VALUE concurrent effects per bitmap. |
|
30 |
// If you want more, change type of the mNumEffects, mIDIndex and mFreeIndexes variables to shorts. |
|
31 |
|
|
32 |
static boolean setMax(int m) |
|
33 |
{ |
|
34 |
if( (mCreated==false && !Distorted.isInitialized()) || m<=mMax[INDEX] ) |
|
35 |
{ |
|
36 |
if( m<0 ) m = 0; |
|
37 |
else if( m>Byte.MAX_VALUE ) m = Byte.MAX_VALUE; |
|
38 |
|
|
39 |
mMax[INDEX] = m; |
|
40 |
return true; |
|
41 |
} |
|
42 |
|
|
43 |
return false; |
|
44 |
} |
|
45 |
|
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
|
48 |
static int getMax() |
|
49 |
{ |
|
50 |
return mMax[INDEX]; |
|
51 |
} |
|
52 | 27 |
|
53 | 28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
54 | 29 |
|
src/main/java/org/distorted/library/EffectQueueMatrix.java | ||
---|---|---|
53 | 53 |
Matrix.multiplyMM(mMVPMatrix, 0, matrix, 0, mTmpMatrix, 0); |
54 | 54 |
for(int j=0; j<16; j++) matrix[j] = mMVPMatrix[j]; |
55 | 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 | 56 |
|
82 | 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
83 | 58 |
|
src/main/java/org/distorted/library/EffectQueueOther.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
4 | 4 |
|
5 |
import java.util.Vector; |
|
6 |
|
|
7 |
/** |
|
8 |
* Do NOT base this on EffectQueue - 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 EffectQueue, it is named so only for consistency with the others. |
|
18 |
*/ |
|
19 |
public class EffectQueueOther |
|
5 |
class EffectQueueOther extends EffectQueue |
|
20 | 6 |
{ |
21 |
private Vector<EffectListener> mListeners =null;
|
|
22 |
private int mNumListeners=0; // ==mListeners.length(), but we only create mListeners if the first one gets added
|
|
7 |
private static final int NUM_UNIFORMS = 0;
|
|
8 |
private static final int INDEX = EffectTypes.OTHER.ordinal();
|
|
23 | 9 |
|
24 | 10 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
25 | 11 |
|
26 | 12 |
public EffectQueueOther(DistortedObject obj) |
27 | 13 |
{ |
28 |
|
|
14 |
super(obj,NUM_UNIFORMS, INDEX ); |
|
29 | 15 |
} |
30 | 16 |
|
31 | 17 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
18 |
// There are no Uniforms, nothing to move |
|
32 | 19 |
|
33 |
synchronized void send()
|
|
20 |
protected void moveEffect(int index)
|
|
34 | 21 |
{ |
35 | 22 |
|
36 | 23 |
} |
37 | 24 |
|
38 | 25 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
39 | 26 |
|
40 |
synchronized int abortAll() |
|
41 |
{ |
|
42 |
|
|
43 |
return 0; |
|
44 |
} |
|
45 |
|
|
46 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
47 |
|
|
48 |
void addListener(EffectListener el) |
|
49 |
{ |
|
50 |
if( mListeners==null ) mListeners = new Vector<>(2,2); |
|
51 |
|
|
52 |
mListeners.add(el); |
|
53 |
mNumListeners++; |
|
54 |
} |
|
55 |
|
|
56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
57 |
|
|
58 |
void removeListener(EffectListener el) |
|
59 |
{ |
|
60 |
if( mNumListeners>0 ) |
|
61 |
{ |
|
62 |
mListeners.remove(el); |
|
63 |
mNumListeners--; |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
68 |
|
|
69 |
synchronized boolean removeByID(long id) |
|
70 |
{ |
|
71 |
//.... |
|
72 |
|
|
73 |
return false; |
|
74 |
} |
|
75 |
|
|
76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
77 |
|
|
78 |
synchronized boolean removeByType(EffectNames effect) |
|
27 |
synchronized void send() |
|
79 | 28 |
{ |
80 |
// ... |
|
81 |
|
|
82 |
return false; |
|
83 |
} |
|
84 |
|
|
85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
86 | 29 |
|
87 |
protected boolean printByID(long id) |
|
88 |
{ |
|
89 |
return false; |
|
90 | 30 |
} |
91 | 31 |
|
92 | 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/EffectQueueVertex.java | ||
---|---|---|
18 | 18 |
{ |
19 | 19 |
super(obj,NUM_UNIFORMS,INDEX); |
20 | 20 |
} |
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
// Only max Byte.MAX_VALUE concurrent effects per bitmap. |
|
24 |
// If you want more, change type of the mNumEffects, mIDIndex and mFreeIndexes variables to shorts. |
|
25 |
|
|
26 |
static boolean setMax(int m) |
|
27 |
{ |
|
28 |
if( (mCreated==false && !Distorted.isInitialized()) || m<=mMax[INDEX] ) |
|
29 |
{ |
|
30 |
if( m<0 ) m = 0; |
|
31 |
else if( m>Byte.MAX_VALUE ) m = Byte.MAX_VALUE; |
|
32 |
|
|
33 |
mMax[INDEX] = m; |
|
34 |
return true; |
|
35 |
} |
|
36 |
|
|
37 |
return false; |
|
38 |
} |
|
39 |
|
|
40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
41 |
|
|
42 |
static int getMax() |
|
43 |
{ |
|
44 |
return mMax[INDEX]; |
|
45 |
} |
|
46 | 21 |
|
47 | 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
48 | 23 |
|
Also available in: Unified diff
abstract setMax and getMax to EffectQueue.