Revision fe6fe99a
Added by Leszek Koltunski over 8 years ago
| src/main/java/org/distorted/library/main/DistortedEffects.java | ||
|---|---|---|
| 150 | 150 |
} |
| 151 | 151 |
} |
| 152 | 152 |
|
| 153 |
mainVertHeader += ("#define NUM_VERTEX " + ( foundV ? getMaxVertex() : 0 ) + "\n");
|
|
| 154 |
mainFragHeader += ("#define NUM_FRAGMENT " + ( foundF ? getMaxFragment() : 0 ) + "\n");
|
|
| 153 |
mainVertHeader += ("#define NUM_VERTEX " + ( foundV ? getMax(EffectType.VERTEX ) : 0 ) + "\n");
|
|
| 154 |
mainFragHeader += ("#define NUM_FRAGMENT " + ( foundF ? getMax(EffectType.FRAGMENT) : 0 ) + "\n");
|
|
| 155 | 155 |
|
| 156 | 156 |
//android.util.Log.e("Effects", "vertHeader= "+mainVertHeader);
|
| 157 | 157 |
//android.util.Log.e("Effects", "fragHeader= "+mainFragHeader);
|
| ... | ... | |
| 629 | 629 |
|
| 630 | 630 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 631 | 631 |
/** |
| 632 |
* Returns the maximum number of Matrix effects.
|
|
| 632 |
* Returns the maximum number of effects of a given type.
|
|
| 633 | 633 |
* |
| 634 |
* @return The maximum number of Matrix effects |
|
| 634 |
* @param type {@link EffectType}
|
|
| 635 |
* @return The maximum number of effects of a given type. |
|
| 635 | 636 |
*/ |
| 636 | 637 |
@SuppressWarnings("unused")
|
| 637 |
public static int getMaxMatrix()
|
|
| 638 |
public static int getMax(EffectType type)
|
|
| 638 | 639 |
{
|
| 639 |
return EffectQueue.getMax(EffectType.MATRIX.ordinal());
|
|
| 640 |
return EffectQueue.getMax(type.ordinal());
|
|
| 640 | 641 |
} |
| 641 | 642 |
|
| 642 | 643 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 643 | 644 |
/** |
| 644 |
* Returns the maximum number of Vertex effects. |
|
| 645 |
* |
|
| 646 |
* @return The maximum number of Vertex effects |
|
| 647 |
*/ |
|
| 648 |
@SuppressWarnings("unused")
|
|
| 649 |
public static int getMaxVertex() |
|
| 650 |
{
|
|
| 651 |
return EffectQueue.getMax(EffectType.VERTEX.ordinal()); |
|
| 652 |
} |
|
| 653 |
|
|
| 654 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 655 |
/** |
|
| 656 |
* Returns the maximum number of Fragment effects. |
|
| 657 |
* |
|
| 658 |
* @return The maximum number of Fragment effects |
|
| 659 |
*/ |
|
| 660 |
@SuppressWarnings("unused")
|
|
| 661 |
public static int getMaxFragment() |
|
| 662 |
{
|
|
| 663 |
return EffectQueue.getMax(EffectType.FRAGMENT.ordinal()); |
|
| 664 |
} |
|
| 665 |
|
|
| 666 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 667 |
/** |
|
| 668 |
* Returns the maximum number of Postprocess effects. |
|
| 669 |
* |
|
| 670 |
* @return The maximum number of Postprocess effects |
|
| 671 |
*/ |
|
| 672 |
@SuppressWarnings("unused")
|
|
| 673 |
public static int getMaxPostprocess() |
|
| 674 |
{
|
|
| 675 |
return EffectQueue.getMax(EffectType.POSTPROCESS.ordinal()); |
|
| 676 |
} |
|
| 677 |
|
|
| 678 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 679 |
/** |
|
| 680 |
* Sets the maximum number of Matrix effects that can be stored in a single EffectQueue at one time. |
|
| 645 |
* Sets the maximum number of effects that can be stored in a single EffectQueue at one time. |
|
| 681 | 646 |
* This can fail if: |
| 682 | 647 |
* <ul> |
| 683 | 648 |
* <li>the value of 'max' is outside permitted range (0 ≤ max ≤ Byte.MAX_VALUE) |
| ... | ... | |
| 687 | 652 |
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created. |
| 688 | 653 |
* </ul> |
| 689 | 654 |
* |
| 690 |
* @param max new maximum number of simultaneous Matrix Effects. Has to be a non-negative number not greater |
|
| 691 |
* than Byte.MAX_VALUE |
|
| 692 |
* @return <code>true</code> if operation was successful, <code>false</code> otherwise. |
|
| 693 |
*/ |
|
| 694 |
@SuppressWarnings("unused")
|
|
| 695 |
public static boolean setMaxMatrix(int max) |
|
| 696 |
{
|
|
| 697 |
return EffectQueue.setMax(EffectType.MATRIX.ordinal(),max); |
|
| 698 |
} |
|
| 699 |
|
|
| 700 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 701 |
/** |
|
| 702 |
* Sets the maximum number of Vertex effects that can be stored in a single EffectQueue at one time. |
|
| 703 |
* This can fail if: |
|
| 704 |
* <ul> |
|
| 705 |
* <li>the value of 'max' is outside permitted range (0 ≤ max ≤ Byte.MAX_VALUE) |
|
| 706 |
* <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called |
|
| 707 |
* before the Vertex Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
|
|
| 708 |
* time only decreasing the value of 'max' is permitted. |
|
| 709 |
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created. |
|
| 710 |
* </ul> |
|
| 711 |
* |
|
| 712 |
* @param max new maximum number of simultaneous Vertex Effects. Has to be a non-negative number not greater |
|
| 713 |
* than Byte.MAX_VALUE |
|
| 714 |
* @return <code>true</code> if operation was successful, <code>false</code> otherwise. |
|
| 715 |
*/ |
|
| 716 |
@SuppressWarnings("unused")
|
|
| 717 |
public static boolean setMaxVertex(int max) |
|
| 718 |
{
|
|
| 719 |
return EffectQueue.setMax(EffectType.VERTEX.ordinal(),max); |
|
| 720 |
} |
|
| 721 |
|
|
| 722 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 723 |
/** |
|
| 724 |
* Sets the maximum number of Fragment effects that can be stored in a single EffectQueue at one time. |
|
| 725 |
* This can fail if: |
|
| 726 |
* <ul> |
|
| 727 |
* <li>the value of 'max' is outside permitted range (0 ≤ max ≤ Byte.MAX_VALUE) |
|
| 728 |
* <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called |
|
| 729 |
* before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
|
|
| 730 |
* time only decreasing the value of 'max' is permitted. |
|
| 731 |
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created. |
|
| 732 |
* </ul> |
|
| 733 |
* |
|
| 734 |
* @param max new maximum number of simultaneous Fragment Effects. Has to be a non-negative number not greater |
|
| 735 |
* than Byte.MAX_VALUE |
|
| 736 |
* @return <code>true</code> if operation was successful, <code>false</code> otherwise. |
|
| 737 |
*/ |
|
| 738 |
@SuppressWarnings("unused")
|
|
| 739 |
public static boolean setMaxFragment(int max) |
|
| 740 |
{
|
|
| 741 |
return EffectQueue.setMax(EffectType.FRAGMENT.ordinal(),max); |
|
| 742 |
} |
|
| 743 |
|
|
| 744 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 745 |
/** |
|
| 746 |
* Sets the maximum number of Postprocess effects that can be stored in a single EffectQueue at one time. |
|
| 747 |
* This can fail if: |
|
| 748 |
* <ul> |
|
| 749 |
* <li>the value of 'max' is outside permitted range (0 ≤ max ≤ Byte.MAX_VALUE) |
|
| 750 |
* <li>We try to increase the value of 'max' when it is too late to do so already. It needs to be called |
|
| 751 |
* before the Fragment Shader gets compiled, i.e. before the call to {@link Distorted#onCreate}. After this
|
|
| 752 |
* time only decreasing the value of 'max' is permitted. |
|
| 753 |
* <li>Furthermore, this needs to be called before any instances of the DistortedEffects class get created. |
|
| 754 |
* </ul> |
|
| 755 |
* |
|
| 756 |
* @param max new maximum number of simultaneous Postprocess Effects. Has to be a non-negative number not greater |
|
| 655 |
* @param type {@link EffectType}
|
|
| 656 |
* @param max new maximum number of simultaneous effects. Has to be a non-negative number not greater |
|
| 757 | 657 |
* than Byte.MAX_VALUE |
| 758 | 658 |
* @return <code>true</code> if operation was successful, <code>false</code> otherwise. |
| 759 | 659 |
*/ |
| 760 | 660 |
@SuppressWarnings("unused")
|
| 761 |
public static boolean setMaxPostprocess(int max)
|
|
| 661 |
public static boolean setMax(EffectType type, int max)
|
|
| 762 | 662 |
{
|
| 763 |
return EffectQueue.setMax(EffectType.POSTPROCESS.ordinal(),max);
|
|
| 663 |
return EffectQueue.setMax(type.ordinal(),max);
|
|
| 764 | 664 |
} |
| 765 | 665 |
|
| 766 | 666 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/library/main/DistortedObject.java | ||
|---|---|---|
| 91 | 91 |
object = job.object; |
| 92 | 92 |
|
| 93 | 93 |
//android.util.Log.d("Object", object.getClass().getSimpleName()+" ---> need to "
|
| 94 |
// +(job.action==JOB_CREATE ? "create":"delete")+" objectID="+object.mID ); |
|
| 94 |
// +(job.action==JOB_CREATE ? "create":"delete")+" objectID="+object.mDistortedEffectsID );
|
|
| 95 | 95 |
|
| 96 | 96 |
if( job.action==JOB_CREATE ) |
| 97 | 97 |
{
|
| src/main/java/org/distorted/library/main/EffectQueue.java | ||
|---|---|---|
| 40 | 40 |
protected static int[] mMax = new int[EffectType.LENGTH]; |
| 41 | 41 |
protected Vector<EffectListener> mListeners =null; |
| 42 | 42 |
protected int mNumListeners=0; // ==mListeners.length(), but we only create mListeners if the first one gets added |
| 43 |
protected long mID; |
|
| 43 |
protected long mDistortedEffectsID;
|
|
| 44 | 44 |
|
| 45 | 45 |
private static boolean mCreated; |
| 46 | 46 |
private int mIndex; |
| ... | ... | |
| 55 | 55 |
|
| 56 | 56 |
EffectQueue(long id, int numUniforms, int index) |
| 57 | 57 |
{
|
| 58 |
mNumEffects = 0; |
|
| 59 |
mID = id;
|
|
| 60 |
mIndex = index; |
|
| 61 |
mNumUniforms = numUniforms; |
|
| 58 |
mNumEffects = 0;
|
|
| 59 |
mDistortedEffectsID = id;
|
|
| 60 |
mIndex = index;
|
|
| 61 |
mNumUniforms = numUniforms;
|
|
| 62 | 62 |
|
| 63 | 63 |
int max = mMax[mIndex]; |
| 64 | 64 |
|
| ... | ... | |
| 208 | 208 |
if( notify ) |
| 209 | 209 |
{
|
| 210 | 210 |
for(int j=0; j<mNumListeners; j++) |
| 211 |
EffectMessageSender.newMessage( mListeners.elementAt(j), EffectMessage.EFFECT_REMOVED, mEffects[i].getID(), mID); |
|
| 211 |
EffectMessageSender.newMessage( mListeners.elementAt(j), EffectMessage.EFFECT_REMOVED, mEffects[i].getID(), mDistortedEffectsID);
|
|
| 212 | 212 |
} |
| 213 | 213 |
|
| 214 | 214 |
mEffects[i] = null; |
| ... | ... | |
| 241 | 241 |
mEffects[mNumEffects] = null; |
| 242 | 242 |
|
| 243 | 243 |
for(int i=0; i<mNumListeners; i++) |
| 244 |
EffectMessageSender.newMessage( mListeners.elementAt(i), EffectMessage.EFFECT_REMOVED, removedID, mID); |
|
| 244 |
EffectMessageSender.newMessage( mListeners.elementAt(i), EffectMessage.EFFECT_REMOVED, removedID, mDistortedEffectsID);
|
|
| 245 | 245 |
} |
| 246 | 246 |
|
| 247 | 247 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 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(), mID); |
|
| 69 |
EffectMessageSender.newMessage( mListeners.elementAt(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(), mID); |
|
| 302 |
EffectMessageSender.newMessage( mListeners.elementAt(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(), mID); |
|
| 190 |
EffectMessageSender.newMessage( mListeners.elementAt(j), EffectMessage.EFFECT_FINISHED, mEffects[i].getID(), mDistortedEffectsID);
|
|
| 191 | 191 |
|
| 192 | 192 |
if( mEffects[i].isUnity( mUniforms, NUM_UNIFORMS*i) ) |
| 193 | 193 |
{
|
| 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(), mID); |
|
| 69 |
EffectMessageSender.newMessage( mListeners.elementAt(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/program/DistortedProgram.java | ||
|---|---|---|
| 22 | 22 |
import android.opengl.GLES30; |
| 23 | 23 |
import android.os.Build; |
| 24 | 24 |
|
| 25 |
import org.distorted.library.effect.EffectType; |
|
| 25 | 26 |
import org.distorted.library.main.DistortedEffects; |
| 26 | 27 |
|
| 27 | 28 |
import java.io.BufferedReader; |
| ... | ... | |
| 201 | 202 |
int realMaxV = (maxV-11)/4; // adjust this in case of changes to the shaders... |
| 202 | 203 |
int realMaxF = (maxF- 2)/4; // |
| 203 | 204 |
|
| 204 |
if( DistortedEffects.getMaxVertex() > realMaxV )
|
|
| 205 |
if( DistortedEffects.getMax(EffectType.VERTEX) > realMaxV )
|
|
| 205 | 206 |
{
|
| 206 | 207 |
throw new VertexUniformsException("Too many effects in the vertex shader, max is "+realMaxV, realMaxV);
|
| 207 | 208 |
} |
| 208 |
if( DistortedEffects.getMaxFragment() > realMaxF )
|
|
| 209 |
if( DistortedEffects.getMax(EffectType.FRAGMENT) > realMaxF )
|
|
| 209 | 210 |
{
|
| 210 | 211 |
throw new FragmentUniformsException("Too many effects in the fragment shader, max is "+realMaxF, realMaxF);
|
| 211 | 212 |
} |
Also available in: Unified diff
Small API simplification.