Revision d59f9e0c
Added by Leszek Koltunski 6 months ago
| src/main/java/org/distorted/library/effect/Effect.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2017 Leszek Koltunski leszek@koltunski.pl // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// This library is free software; you can redistribute it and/or // |
|
| 7 |
// modify it under the terms of the GNU Lesser General Public // |
|
| 8 |
// License as published by the Free Software Foundation; either // |
|
| 9 |
// version 2.1 of the License, or (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// This library is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // |
|
| 14 |
// Lesser General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU Lesser General Public // |
|
| 17 |
// License along with this library; if not, write to the Free Software // |
|
| 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
|
| 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 20 |
|
|
| 21 |
package org.distorted.library.effect; |
|
| 22 |
|
|
| 23 |
import org.distorted.library.effectqueue.EffectQueue; |
|
| 24 |
import org.distorted.library.main.DistortedLibrary; |
|
| 25 |
import org.distorted.library.main.InternalStackFrameList; |
|
| 26 |
import org.distorted.library.message.EffectListener; |
|
| 27 |
|
|
| 28 |
import java.lang.reflect.Method; |
|
| 29 |
import java.util.ArrayList; |
|
| 30 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 32 |
/** |
|
| 33 |
* Abstract Effect of any type. |
|
| 34 |
*/ |
|
| 35 |
public abstract class Effect |
|
| 36 |
{
|
|
| 37 |
private final static int MAX_UNITY_DIM = 4; |
|
| 38 |
private final static int NUM_EFFECTS = EffectName.LENGTH; |
|
| 39 |
|
|
| 40 |
private final long mID; |
|
| 41 |
private final EffectType mType; |
|
| 42 |
private final EffectName mName; |
|
| 43 |
private final int mDimension; |
|
| 44 |
private final int mRegionDim; |
|
| 45 |
private final int mCenterDim; |
|
| 46 |
|
|
| 47 |
private ArrayList<EffectListener> mListeners =null; |
|
| 48 |
private int mNumListeners=0; // ==mListeners.length(), but we only create mListeners if the first one gets added |
|
| 49 |
|
|
| 50 |
private final static float[] mUnity= new float[MAX_UNITY_DIM*NUM_EFFECTS]; |
|
| 51 |
private final static int[] mUnityDim = new int[NUM_EFFECTS]; |
|
| 52 |
|
|
| 53 |
int mAndAssociation; |
|
| 54 |
int mEquAssociation; |
|
| 55 |
|
|
| 56 |
static boolean[] mEnabled = new boolean[NUM_EFFECTS]; |
|
| 57 |
|
|
| 58 |
static |
|
| 59 |
{
|
|
| 60 |
for(int i=0; i<NUM_EFFECTS; i++) mEnabled[i] = false; |
|
| 61 |
} |
|
| 62 |
|
|
| 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 64 |
|
|
| 65 |
public abstract void addQueue(EffectQueue queue); |
|
| 66 |
public abstract void remQueue(EffectQueue queue); |
|
| 67 |
|
|
| 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 69 |
|
|
| 70 |
Effect(EffectName name) |
|
| 71 |
{
|
|
| 72 |
mName = name; |
|
| 73 |
mType = name.getType(); |
|
| 74 |
mDimension = name.getEffectDimension(); |
|
| 75 |
mCenterDim = name.getCenterDimension(); |
|
| 76 |
mRegionDim = name.getRegionDimension(); |
|
| 77 |
|
|
| 78 |
mAndAssociation = 0xffffffff; |
|
| 79 |
mEquAssociation = 0; |
|
| 80 |
|
|
| 81 |
int n = name.ordinal(); |
|
| 82 |
float[] u = name.getUnity(); |
|
| 83 |
int l = u.length; |
|
| 84 |
|
|
| 85 |
System.arraycopy(u, 0, mUnity, MAX_UNITY_DIM*n, l); |
|
| 86 |
|
|
| 87 |
mUnityDim[n] = l; |
|
| 88 |
|
|
| 89 |
mID = (InternalStackFrameList.getNextEffectID()<<EffectType.LENGTH) + mType.ordinal(); |
|
| 90 |
} |
|
| 91 |
|
|
| 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 93 |
/** |
|
| 94 |
* Only for use by the library itself. |
|
| 95 |
* |
|
| 96 |
* @y.exclude |
|
| 97 |
*/ |
|
| 98 |
public static void onPause() |
|
| 99 |
{
|
|
| 100 |
for(int i=0; i<NUM_EFFECTS; i++) mEnabled[i] = false; |
|
| 101 |
|
|
| 102 |
MatrixEffect.destroyStatics(); |
|
| 103 |
VertexEffect.destroyStatics(); |
|
| 104 |
FragmentEffect.destroyStatics(); |
|
| 105 |
PostprocessEffect.destroyStatics(); |
|
| 106 |
} |
|
| 107 |
|
|
| 108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 109 |
/** |
|
| 110 |
* Only for use by the library itself. |
|
| 111 |
* |
|
| 112 |
* @y.exclude |
|
| 113 |
*/ |
|
| 114 |
public abstract boolean compute(float[] uniforms, int index, long currentDuration, long step ); |
|
| 115 |
|
|
| 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 117 |
/** |
|
| 118 |
* Only for use by the library itself. |
|
| 119 |
* |
|
| 120 |
* @y.exclude |
|
| 121 |
*/ |
|
| 122 |
public int getNumListeners() |
|
| 123 |
{
|
|
| 124 |
return mNumListeners; |
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 128 |
/** |
|
| 129 |
* Only for use by the library itself. |
|
| 130 |
* |
|
| 131 |
* @y.exclude |
|
| 132 |
*/ |
|
| 133 |
public EffectListener removeFirstListener() |
|
| 134 |
{
|
|
| 135 |
if( mNumListeners>0 ) |
|
| 136 |
{
|
|
| 137 |
mNumListeners--; |
|
| 138 |
return mListeners.remove(0); |
|
| 139 |
} |
|
| 140 |
|
|
| 141 |
return null; |
|
| 142 |
} |
|
| 143 |
|
|
| 144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 145 |
/** |
|
| 146 |
* Only for use by the library itself. |
|
| 147 |
* |
|
| 148 |
* @y.exclude |
|
| 149 |
*/ |
|
| 150 |
public void writeAssociations(int[] intUniforms, int index1, int index2) |
|
| 151 |
{
|
|
| 152 |
intUniforms[index1] = mAndAssociation; |
|
| 153 |
intUniforms[index2] = mEquAssociation; |
|
| 154 |
} |
|
| 155 |
|
|
| 156 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 157 |
// PUBLIC API |
|
| 158 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 159 |
/** |
|
| 160 |
* Do the set of Uniforms written in buffer[index], buffer[index+1], etc represent a Unity, i.e a |
|
| 161 |
* null Effect? |
|
| 162 |
*/ |
|
| 163 |
public boolean isUnity(float[] buffer, int index) |
|
| 164 |
{
|
|
| 165 |
int name = mName.ordinal(); |
|
| 166 |
|
|
| 167 |
switch(mUnityDim[name]) |
|
| 168 |
{
|
|
| 169 |
case 0: return true; |
|
| 170 |
case 1: return buffer[index ]==mUnity[MAX_UNITY_DIM*name ]; |
|
| 171 |
case 2: return buffer[index ]==mUnity[MAX_UNITY_DIM*name ] && |
|
| 172 |
buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1]; |
|
| 173 |
case 3: return buffer[index ]==mUnity[MAX_UNITY_DIM*name ] && |
|
| 174 |
buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1] && |
|
| 175 |
buffer[index+2]==mUnity[MAX_UNITY_DIM*name+2]; |
|
| 176 |
case 4: return buffer[index ]==mUnity[MAX_UNITY_DIM*name ] && |
|
| 177 |
buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1] && |
|
| 178 |
buffer[index+2]==mUnity[MAX_UNITY_DIM*name+2] && |
|
| 179 |
buffer[index+3]==mUnity[MAX_UNITY_DIM*name+3]; |
|
| 180 |
} |
|
| 181 |
|
|
| 182 |
return false; |
|
| 183 |
} |
|
| 184 |
|
|
| 185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 186 |
// this will enable() all Fragment Effects twice (once for smooth variant, once for non-smooth) |
|
| 187 |
// but this shouldn't matter. |
|
| 188 |
/** |
|
| 189 |
* Enable all effects of a given type. |
|
| 190 |
* |
|
| 191 |
* @param type EffectType to enable. |
|
| 192 |
*/ |
|
| 193 |
public static void enableEffects(EffectType type) |
|
| 194 |
{
|
|
| 195 |
Method method; |
|
| 196 |
|
|
| 197 |
for(EffectName name: EffectName.values()) |
|
| 198 |
{
|
|
| 199 |
if( name.getType() == type ) |
|
| 200 |
{
|
|
| 201 |
Class<? extends Effect> cls = name.getEffectClass(); |
|
| 202 |
|
|
| 203 |
try |
|
| 204 |
{
|
|
| 205 |
method = cls.getMethod("enable"); // getMethod and NOT getDeclaredMethod because enable()
|
|
| 206 |
// is public |
|
| 207 |
} |
|
| 208 |
catch(NoSuchMethodException ex) |
|
| 209 |
{
|
|
| 210 |
DistortedLibrary.logMessage("Effect: exception getting method: "+ex.getMessage());
|
|
| 211 |
method = null; |
|
| 212 |
} |
|
| 213 |
|
|
| 214 |
try |
|
| 215 |
{
|
|
| 216 |
if( method!=null ) method.invoke(null); |
|
| 217 |
} |
|
| 218 |
catch(Exception ex) |
|
| 219 |
{
|
|
| 220 |
DistortedLibrary.logMessage("Effect: exception invoking method: "+ex.getMessage());
|
|
| 221 |
} |
|
| 222 |
} |
|
| 223 |
} |
|
| 224 |
} |
|
| 225 |
|
|
| 226 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 227 |
/** |
|
| 228 |
* Return the EffectType enum corresponding to this Effect. |
|
| 229 |
* |
|
| 230 |
* @see EffectType |
|
| 231 |
*/ |
|
| 232 |
public EffectType getType() |
|
| 233 |
{
|
|
| 234 |
return mType; |
|
| 235 |
} |
|
| 236 |
|
|
| 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 238 |
/** |
|
| 239 |
* Return the EffectName enum corresponding to this Effect. |
|
| 240 |
* |
|
| 241 |
* @see EffectName |
|
| 242 |
*/ |
|
| 243 |
public EffectName getName() |
|
| 244 |
{
|
|
| 245 |
return mName; |
|
| 246 |
} |
|
| 247 |
|
|
| 248 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 249 |
/** |
|
| 250 |
* Return the unique ID of this Effect. |
|
| 251 |
*/ |
|
| 252 |
public long getID() |
|
| 253 |
{
|
|
| 254 |
return mID; |
|
| 255 |
} |
|
| 256 |
|
|
| 257 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 258 |
/** |
|
| 259 |
* Return a printable name of this Effect. |
|
| 260 |
*/ |
|
| 261 |
public String getString() |
|
| 262 |
{
|
|
| 263 |
return mName.name(); |
|
| 264 |
} |
|
| 265 |
|
|
| 266 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 267 |
/** |
|
| 268 |
* Return the dimension of the Center supported by this effect (0- no center supported at all). |
|
| 269 |
*/ |
|
| 270 |
public int getCenterDimension() |
|
| 271 |
{
|
|
| 272 |
return mCenterDim; |
|
| 273 |
} |
|
| 274 |
|
|
| 275 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 276 |
/** |
|
| 277 |
* Return the dimension of the Region supported by this effect (0- no region supported at all). |
|
| 278 |
*/ |
|
| 279 |
public int getRegionDimension() |
|
| 280 |
{
|
|
| 281 |
return mRegionDim; |
|
| 282 |
} |
|
| 283 |
|
|
| 284 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 285 |
/** |
|
| 286 |
* Return the number of Uniforms needed to describe this effect. |
|
| 287 |
*/ |
|
| 288 |
public int getEffectDimension() |
|
| 289 |
{
|
|
| 290 |
return mDimension; |
|
| 291 |
} |
|
| 292 |
|
|
| 293 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 294 |
/** |
|
| 295 |
* Adds the calling class to the list of Listeners that get notified when this Effect gets 'finished' |
|
| 296 |
* i.e. when the Dynamic inside this Effect reaches its final point and stops moving. This will be sent |
|
| 297 |
* only once, on the first time the Dynamic reaches its final point. |
|
| 298 |
* |
|
| 299 |
* If there's no Dynamic, ths message will never be sent. |
|
| 300 |
* |
|
| 301 |
* @param el A class implementing the EffectListener interface that wants to get notifications. |
|
| 302 |
*/ |
|
| 303 |
public void notifyWhenFinished(EffectListener el) |
|
| 304 |
{
|
|
| 305 |
if( mListeners==null ) mListeners = new ArrayList<>(); |
|
| 306 |
|
|
| 307 |
if( !mListeners.contains(el) ) |
|
| 308 |
{
|
|
| 309 |
mListeners.add(el); |
|
| 310 |
mNumListeners++; |
|
| 311 |
} |
|
| 312 |
} |
|
| 313 |
} |
|
| src/main/java/org/distorted/library/effect/Effect.kt | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2017 Leszek Koltunski leszek@koltunski.pl // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// This library is free software; you can redistribute it and/or // |
|
| 7 |
// modify it under the terms of the GNU Lesser General Public // |
|
| 8 |
// License as published by the Free Software Foundation; either // |
|
| 9 |
// version 2.1 of the License, or (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// This library is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // |
|
| 14 |
// Lesser General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU Lesser General Public // |
|
| 17 |
// License along with this library; if not, write to the Free Software // |
|
| 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
|
| 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 20 |
|
|
| 21 |
package org.distorted.library.effect; |
|
| 22 |
|
|
| 23 |
import org.distorted.library.effectqueue.EffectQueue; |
|
| 24 |
import org.distorted.library.main.DistortedLibrary; |
|
| 25 |
import org.distorted.library.main.InternalStackFrameList; |
|
| 26 |
import org.distorted.library.message.EffectListener; |
|
| 27 |
|
|
| 28 |
import java.lang.reflect.Method; |
|
| 29 |
import java.util.ArrayList; |
|
| 30 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 32 |
/** |
|
| 33 |
* Abstract Effect of any type. |
|
| 34 |
*/ |
|
| 35 |
public abstract class Effect |
|
| 36 |
{
|
|
| 37 |
private final static int MAX_UNITY_DIM = 4; |
|
| 38 |
private final static int NUM_EFFECTS = EffectName.LENGTH; |
|
| 39 |
|
|
| 40 |
private final long mID; |
|
| 41 |
private final EffectType mType; |
|
| 42 |
private final EffectName mName; |
|
| 43 |
private final int mDimension; |
|
| 44 |
private final int mRegionDim; |
|
| 45 |
private final int mCenterDim; |
|
| 46 |
|
|
| 47 |
private ArrayList<EffectListener> mListeners =null; |
|
| 48 |
private int mNumListeners=0; // ==mListeners.length(), but we only create mListeners if the first one gets added |
|
| 49 |
|
|
| 50 |
private final static float[] mUnity= new float[MAX_UNITY_DIM*NUM_EFFECTS]; |
|
| 51 |
private final static int[] mUnityDim = new int[NUM_EFFECTS]; |
|
| 52 |
|
|
| 53 |
int mAndAssociation; |
|
| 54 |
int mEquAssociation; |
|
| 55 |
|
|
| 56 |
static boolean[] mEnabled = new boolean[NUM_EFFECTS]; |
|
| 57 |
|
|
| 58 |
static |
|
| 59 |
{
|
|
| 60 |
for(int i=0; i<NUM_EFFECTS; i++) mEnabled[i] = false; |
|
| 61 |
} |
|
| 62 |
|
|
| 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 64 |
|
|
| 65 |
public abstract void addQueue(EffectQueue queue); |
|
| 66 |
public abstract void remQueue(EffectQueue queue); |
|
| 67 |
|
|
| 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 69 |
|
|
| 70 |
Effect(EffectName name) |
|
| 71 |
{
|
|
| 72 |
mName = name; |
|
| 73 |
mType = name.getType(); |
|
| 74 |
mDimension = name.getEffectDimension(); |
|
| 75 |
mCenterDim = name.getCenterDimension(); |
|
| 76 |
mRegionDim = name.getRegionDimension(); |
|
| 77 |
|
|
| 78 |
mAndAssociation = 0xffffffff; |
|
| 79 |
mEquAssociation = 0; |
|
| 80 |
|
|
| 81 |
int n = name.ordinal(); |
|
| 82 |
float[] u = name.getUnity(); |
|
| 83 |
int l = u.length; |
|
| 84 |
|
|
| 85 |
System.arraycopy(u, 0, mUnity, MAX_UNITY_DIM*n, l); |
|
| 86 |
|
|
| 87 |
mUnityDim[n] = l; |
|
| 88 |
|
|
| 89 |
mID = (InternalStackFrameList.getNextEffectID()<<EffectType.LENGTH) + mType.ordinal(); |
|
| 90 |
} |
|
| 91 |
|
|
| 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 93 |
/** |
|
| 94 |
* Only for use by the library itself. |
|
| 95 |
* |
|
| 96 |
* @y.exclude |
|
| 97 |
*/ |
|
| 98 |
public static void onPause() |
|
| 99 |
{
|
|
| 100 |
for(int i=0; i<NUM_EFFECTS; i++) mEnabled[i] = false; |
|
| 101 |
|
|
| 102 |
MatrixEffect.destroyStatics(); |
|
| 103 |
VertexEffect.destroyStatics(); |
|
| 104 |
FragmentEffect.destroyStatics(); |
|
| 105 |
PostprocessEffect.destroyStatics(); |
|
| 106 |
} |
|
| 107 |
|
|
| 108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 109 |
/** |
|
| 110 |
* Only for use by the library itself. |
|
| 111 |
* |
|
| 112 |
* @y.exclude |
|
| 113 |
*/ |
|
| 114 |
public abstract boolean compute(float[] uniforms, int index, long currentDuration, long step ); |
|
| 115 |
|
|
| 116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 117 |
/** |
|
| 118 |
* Only for use by the library itself. |
|
| 119 |
* |
|
| 120 |
* @y.exclude |
|
| 121 |
*/ |
|
| 122 |
public int getNumListeners() |
|
| 123 |
{
|
|
| 124 |
return mNumListeners; |
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 128 |
/** |
|
| 129 |
* Only for use by the library itself. |
|
| 130 |
* |
|
| 131 |
* @y.exclude |
|
| 132 |
*/ |
|
| 133 |
public EffectListener removeFirstListener() |
|
| 134 |
{
|
|
| 135 |
if( mNumListeners>0 ) |
|
| 136 |
{
|
|
| 137 |
mNumListeners--; |
|
| 138 |
return mListeners.remove(0); |
|
| 139 |
} |
|
| 140 |
|
|
| 141 |
return null; |
|
| 142 |
} |
|
| 143 |
|
|
| 144 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 145 |
/** |
|
| 146 |
* Only for use by the library itself. |
|
| 147 |
* |
|
| 148 |
* @y.exclude |
|
| 149 |
*/ |
|
| 150 |
public void writeAssociations(int[] intUniforms, int index1, int index2) |
|
| 151 |
{
|
|
| 152 |
intUniforms[index1] = mAndAssociation; |
|
| 153 |
intUniforms[index2] = mEquAssociation; |
|
| 154 |
} |
|
| 155 |
|
|
| 156 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 157 |
// PUBLIC API |
|
| 158 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 159 |
/** |
|
| 160 |
* Do the set of Uniforms written in buffer[index], buffer[index+1], etc represent a Unity, i.e a |
|
| 161 |
* null Effect? |
|
| 162 |
*/ |
|
| 163 |
public boolean isUnity(float[] buffer, int index) |
|
| 164 |
{
|
|
| 165 |
int name = mName.ordinal(); |
|
| 166 |
|
|
| 167 |
switch(mUnityDim[name]) |
|
| 168 |
{
|
|
| 169 |
case 0: return true; |
|
| 170 |
case 1: return buffer[index ]==mUnity[MAX_UNITY_DIM*name ]; |
|
| 171 |
case 2: return buffer[index ]==mUnity[MAX_UNITY_DIM*name ] && |
|
| 172 |
buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1]; |
|
| 173 |
case 3: return buffer[index ]==mUnity[MAX_UNITY_DIM*name ] && |
|
| 174 |
buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1] && |
|
| 175 |
buffer[index+2]==mUnity[MAX_UNITY_DIM*name+2]; |
|
| 176 |
case 4: return buffer[index ]==mUnity[MAX_UNITY_DIM*name ] && |
|
| 177 |
buffer[index+1]==mUnity[MAX_UNITY_DIM*name+1] && |
|
| 178 |
buffer[index+2]==mUnity[MAX_UNITY_DIM*name+2] && |
|
| 179 |
buffer[index+3]==mUnity[MAX_UNITY_DIM*name+3]; |
|
| 180 |
} |
|
| 181 |
|
|
| 182 |
return false; |
|
| 183 |
} |
|
| 184 |
|
|
| 185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 186 |
// this will enable() all Fragment Effects twice (once for smooth variant, once for non-smooth) |
|
| 187 |
// but this shouldn't matter. |
|
| 188 |
/** |
|
| 189 |
* Enable all effects of a given type. |
|
| 190 |
* |
|
| 191 |
* @param type EffectType to enable. |
|
| 192 |
*/ |
|
| 193 |
public static void enableEffects(EffectType type) |
|
| 194 |
{
|
|
| 195 |
Method method; |
|
| 196 |
|
|
| 197 |
for(EffectName name: EffectName.values()) |
|
| 198 |
{
|
|
| 199 |
if( name.getType() == type ) |
|
| 200 |
{
|
|
| 201 |
Class<? extends Effect> cls = name.getEffectClass(); |
|
| 202 |
|
|
| 203 |
try |
|
| 204 |
{
|
|
| 205 |
method = cls.getMethod("enable"); // getMethod and NOT getDeclaredMethod because enable()
|
|
| 206 |
// is public |
|
| 207 |
} |
|
| 208 |
catch(NoSuchMethodException ex) |
|
| 209 |
{
|
|
| 210 |
DistortedLibrary.logMessage("Effect: exception getting method: "+ex.getMessage());
|
|
| 211 |
method = null; |
|
| 212 |
} |
|
| 213 |
|
|
| 214 |
try |
|
| 215 |
{
|
|
| 216 |
if( method!=null ) method.invoke(null); |
|
| 217 |
} |
|
| 218 |
catch(Exception ex) |
|
| 219 |
{
|
|
| 220 |
DistortedLibrary.logMessage("Effect: exception invoking method: "+ex.getMessage());
|
|
| 221 |
} |
|
| 222 |
} |
|
| 223 |
} |
|
| 224 |
} |
|
| 225 |
|
|
| 226 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 227 |
/** |
|
| 228 |
* Return the EffectType enum corresponding to this Effect. |
|
| 229 |
* |
|
| 230 |
* @see EffectType |
|
| 231 |
*/ |
|
| 232 |
public EffectType getType() |
|
| 233 |
{
|
|
| 234 |
return mType; |
|
| 235 |
} |
|
| 236 |
|
|
| 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 238 |
/** |
|
| 239 |
* Return the EffectName enum corresponding to this Effect. |
|
| 240 |
* |
|
| 241 |
* @see EffectName |
|
| 242 |
*/ |
|
| 243 |
public EffectName getName() |
|
| 244 |
{
|
|
| 245 |
return mName; |
|
| 246 |
} |
|
| 247 |
|
|
| 248 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 249 |
/** |
|
| 250 |
* Return the unique ID of this Effect. |
|
| 251 |
*/ |
|
| 252 |
public long getID() |
|
| 253 |
{
|
|
| 254 |
return mID; |
|
| 255 |
} |
|
| 256 |
|
|
| 257 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 258 |
/** |
|
| 259 |
* Return a printable name of this Effect. |
|
| 260 |
*/ |
|
| 261 |
public String getString() |
|
| 262 |
{
|
|
| 263 |
return mName.name(); |
|
| 264 |
} |
|
| 265 |
|
|
| 266 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 267 |
/** |
|
| 268 |
* Return the dimension of the Center supported by this effect (0- no center supported at all). |
|
| 269 |
*/ |
|
| 270 |
public int getCenterDimension() |
|
| 271 |
{
|
|
| 272 |
return mCenterDim; |
|
| 273 |
} |
|
| 274 |
|
|
| 275 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 276 |
/** |
|
| 277 |
* Return the dimension of the Region supported by this effect (0- no region supported at all). |
|
| 278 |
*/ |
|
| 279 |
public int getRegionDimension() |
|
| 280 |
{
|
|
| 281 |
return mRegionDim; |
|
| 282 |
} |
|
| 283 |
|
|
| 284 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 285 |
/** |
|
| 286 |
* Return the number of Uniforms needed to describe this effect. |
|
| 287 |
*/ |
|
| 288 |
public int getEffectDimension() |
|
| 289 |
{
|
|
| 290 |
return mDimension; |
|
| 291 |
} |
|
| 292 |
|
|
| 293 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 294 |
/** |
|
| 295 |
* Adds the calling class to the list of Listeners that get notified when this Effect gets 'finished' |
|
| 296 |
* i.e. when the Dynamic inside this Effect reaches its final point and stops moving. This will be sent |
|
| 297 |
* only once, on the first time the Dynamic reaches its final point. |
|
| 298 |
* |
|
| 299 |
* If there's no Dynamic, ths message will never be sent. |
|
| 300 |
* |
|
| 301 |
* @param el A class implementing the EffectListener interface that wants to get notifications. |
|
| 302 |
*/ |
|
| 303 |
public void notifyWhenFinished(EffectListener el) |
|
| 304 |
{
|
|
| 305 |
if( mListeners==null ) mListeners = new ArrayList<>(); |
|
| 306 |
|
|
| 307 |
if( !mListeners.contains(el) ) |
|
| 308 |
{
|
|
| 309 |
mListeners.add(el); |
|
| 310 |
mNumListeners++; |
|
| 311 |
} |
|
| 312 |
} |
|
| 313 |
} |
|
| src/main/java/org/distorted/library/effect/EffectName.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2017 Leszek Koltunski leszek@koltunski.pl // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// This library is free software; you can redistribute it and/or // |
|
| 7 |
// modify it under the terms of the GNU Lesser General Public // |
|
| 8 |
// License as published by the Free Software Foundation; either // |
|
| 9 |
// version 2.1 of the License, or (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// This library is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // |
|
| 14 |
// Lesser General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU Lesser General Public // |
|
| 17 |
// License along with this library; if not, write to the Free Software // |
|
| 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
|
| 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 20 |
|
|
| 21 |
package org.distorted.library.effect; |
|
| 22 |
|
|
| 23 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 24 |
/** |
|
| 25 |
* Names of Effects one can add to the DistortedEffects queues. |
|
| 26 |
* <p> |
|
| 27 |
* Effect's 'Type' is one of the constants defined in {@link EffectType}.
|
|
| 28 |
* </p> |
|
| 29 |
* <p> |
|
| 30 |
* Effect's 'Uniforms' are a vector of 7 (matrix effects) 12 (vertex) or 8 (fragment) floats, which |
|
| 31 |
* together form full information how to compute a given effect. |
|
| 32 |
* Typically, some of those values will be Interpolated in CPU (by one of the 'EffectQueueX.compute()' |
|
| 33 |
* methods) and the effect of such Interpolation sent to the Shaders. |
|
| 34 |
* </p> |
|
| 35 |
* <p> |
|
| 36 |
* Effect's 'Unity' is such a particular vector of its 'interpolated values' which makes the |
|
| 37 |
* effect NULL. For example, if the effect is 'MOVE' by a 3-dimensional vector, then a 'NULL |
|
| 38 |
* MOVE' is a MOVE by vector (0,0,0), thus (0,0,0) is the unity of the MOVE effect. |
|
| 39 |
* This is used by the EffectQueue classes to decide if the final form of the Effect is NULL - and |
|
| 40 |
* thus if it can safely be removed from Effect Queues without affecting the visual in any way. |
|
| 41 |
* </p> |
|
| 42 |
*/ |
|
| 43 |
|
|
| 44 |
public enum EffectName |
|
| 45 |
{
|
|
| 46 |
// EFFECT NAME /////// EFFECT TYPE ////////// EFFECT UNITY //////////// DIM REGION CENTER // CLASS |
|
| 47 |
ROTATE ( EffectType.MATRIX , new float[] {0.0f} , 4, 0, 3 , MatrixEffectRotate.class ),
|
|
| 48 |
QUATERNION ( EffectType.MATRIX , new float[] {0.0f,0.0f,0.0f} , 4, 0, 3 , MatrixEffectQuaternion.class ),
|
|
| 49 |
MOVE ( EffectType.MATRIX , new float[] {0.0f,0.0f,0.0f} , 3, 0, 0 , MatrixEffectMove.class ),
|
|
| 50 |
SCALE ( EffectType.MATRIX , new float[] {1.0f,1.0f,1.0f} , 3, 0, 0 , MatrixEffectScale.class ),
|
|
| 51 |
SHEAR ( EffectType.MATRIX , new float[] {0.0f,0.0f,0.0f} , 3, 0, 3 , MatrixEffectShear.class ),
|
|
| 52 |
|
|
| 53 |
DISTORT ( EffectType.VERTEX , new float[] {0.0f,0.0f,0.0f} , 3, 4, 3 , VertexEffectDistort.class ),
|
|
| 54 |
DEFORM ( EffectType.VERTEX , new float[] {0.0f,0.0f,0.0f} , 4, 4, 3 , VertexEffectDeform.class ),
|
|
| 55 |
SINK ( EffectType.VERTEX , new float[] {1.0f} , 1, 4, 3 , VertexEffectSink.class ),
|
|
| 56 |
PINCH ( EffectType.VERTEX , new float[] {1.0f} , 3, 4, 3 , VertexEffectPinch.class ),
|
|
| 57 |
SWIRL ( EffectType.VERTEX , new float[] {0.0f} , 1, 4, 3 , VertexEffectSwirl.class ),
|
|
| 58 |
WAVE ( EffectType.VERTEX , new float[] {0.0f} , 5, 4, 3 , VertexEffectWave.class ),
|
|
| 59 |
DISAPPEAR ( EffectType.VERTEX , new float[] {} , 0, 0, 0 , VertexEffectDisappear.class ),
|
|
| 60 |
PIPE ( EffectType.VERTEX , new float[] {1,0f} , 5, 0, 3 , VertexEffectPipe.class ),
|
|
| 61 |
|
|
| 62 |
VERTEX_MOVE ( EffectType.VERTEX , new float[] {0.0f,0.0f,0.0f} , 3, 0, 0 , VertexEffectMove.class ),
|
|
| 63 |
VERTEX_QUATERNION( EffectType.VERTEX , new float[] {0.0f,0.0f,0.0f} , 4, 0, 3 , VertexEffectQuaternion.class ),
|
|
| 64 |
VERTEX_ROTATE ( EffectType.VERTEX , new float[] {0.0f} , 4, 0, 3 , VertexEffectRotate.class ),
|
|
| 65 |
VERTEX_SCALE ( EffectType.VERTEX , new float[] {1.0f,1.0f,1.0f} , 3, 0, 0 , VertexEffectScale.class ),
|
|
| 66 |
VERTEX_SHEAR ( EffectType.VERTEX , new float[] {0.0f,0.0f,0.0f} , 3, 0, 3 , VertexEffectShear.class ),
|
|
| 67 |
|
|
| 68 |
ALPHA ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectAlpha.class ),
|
|
| 69 |
SMOOTH_ALPHA ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectAlpha.class ),
|
|
| 70 |
CHROMA ( EffectType.FRAGMENT, new float[] {0.0f} , 4, 3, 3 , FragmentEffectChroma.class ),
|
|
| 71 |
SMOOTH_CHROMA ( EffectType.FRAGMENT, new float[] {0.0f} , 4, 3, 3 , FragmentEffectChroma.class ),
|
|
| 72 |
BRIGHTNESS ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectBrightness.class ),
|
|
| 73 |
SMOOTH_BRIGHTNESS( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectBrightness.class ),
|
|
| 74 |
SATURATION ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectSaturation.class ),
|
|
| 75 |
SMOOTH_SATURATION( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectSaturation.class ),
|
|
| 76 |
CONTRAST ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectContrast.class ),
|
|
| 77 |
SMOOTH_CONTRAST ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectContrast.class ),
|
|
| 78 |
|
|
| 79 |
BLUR ( EffectType.POSTPROCESS,new float[] {0.0f} , 2, 0, 0 , PostprocessEffectBlur.class ),
|
|
| 80 |
GLOW ( EffectType.POSTPROCESS,new float[] {0.0f} , 6, 0, 0 , PostprocessEffectGlow.class ),
|
|
| 81 |
BORDER ( EffectType.POSTPROCESS,new float[] {0.0f} , 5, 0, 0 , PostprocessEffectBorder.class ),
|
|
| 82 |
; |
|
| 83 |
|
|
| 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 85 |
|
|
| 86 |
public static final int LENGTH = values().length; |
|
| 87 |
|
|
| 88 |
private final EffectType type; |
|
| 89 |
private final float[] unity; |
|
| 90 |
private final int dimension; |
|
| 91 |
private final int regionDim; |
|
| 92 |
private final int centerDim; |
|
| 93 |
private final Class<? extends Effect> effectClass; |
|
| 94 |
|
|
| 95 |
private static final int[] dimensions; |
|
| 96 |
private static final int[] regionDimension; |
|
| 97 |
private static final int[] centerDimension; |
|
| 98 |
private static final EffectName[] names; // copy the values() to a local variable so that we |
|
| 99 |
// don't have to keep recreating the array every time |
|
| 100 |
static |
|
| 101 |
{
|
|
| 102 |
int i=0; |
|
| 103 |
|
|
| 104 |
dimensions = new int[LENGTH]; |
|
| 105 |
regionDimension = new int[LENGTH]; |
|
| 106 |
centerDimension = new int[LENGTH]; |
|
| 107 |
names = new EffectName[LENGTH]; |
|
| 108 |
|
|
| 109 |
for(EffectName name: EffectName.values()) |
|
| 110 |
{
|
|
| 111 |
dimensions[i] = name.dimension; |
|
| 112 |
regionDimension[i] = name.regionDim; |
|
| 113 |
centerDimension[i] = name.centerDim; |
|
| 114 |
names[i] = name; |
|
| 115 |
|
|
| 116 |
i++; |
|
| 117 |
} |
|
| 118 |
} |
|
| 119 |
|
|
| 120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 121 |
|
|
| 122 |
float[] getUnity() |
|
| 123 |
{
|
|
| 124 |
return unity; |
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 128 |
|
|
| 129 |
EffectName(EffectType type, float[] unity, int dimension, int regionDim, |
|
| 130 |
int centerDim, Class<? extends Effect> effectClass ) |
|
| 131 |
{
|
|
| 132 |
this.type = type; |
|
| 133 |
this.unity = unity; |
|
| 134 |
this.dimension = dimension; |
|
| 135 |
this.regionDim = regionDim; |
|
| 136 |
this.centerDim = centerDim; |
|
| 137 |
this.effectClass = effectClass; |
|
| 138 |
} |
|
| 139 |
|
|
| 140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 141 |
// PUBLIC API |
|
| 142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 143 |
/** |
|
| 144 |
* Returns the Type of an individual Effect. For example, EffectName.ROTATE.getType() will |
|
| 145 |
* return EffectType.MATRIX. |
|
| 146 |
* @return type of the effect. |
|
| 147 |
*/ |
|
| 148 |
public EffectType getType() |
|
| 149 |
{
|
|
| 150 |
return type; |
|
| 151 |
} |
|
| 152 |
|
|
| 153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 154 |
/** |
|
| 155 |
* Returns the Class of an individual Effect. For example, EffectName.ROTATE.getEffectClass() |
|
| 156 |
* returns MatrixEffectRotate.class. |
|
| 157 |
* @return effect class. |
|
| 158 |
*/ |
|
| 159 |
public Class<? extends Effect> getEffectClass() |
|
| 160 |
{
|
|
| 161 |
return effectClass; |
|
| 162 |
} |
|
| 163 |
|
|
| 164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 165 |
/** |
|
| 166 |
* Returns the i-th EffectName. |
|
| 167 |
* <p> |
|
| 168 |
* If you want to loop over all possible Effects, you need this. |
|
| 169 |
*/ |
|
| 170 |
public static EffectName getName(int ordinal) |
|
| 171 |
{
|
|
| 172 |
return names[ordinal]; |
|
| 173 |
} |
|
| 174 |
|
|
| 175 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 176 |
/** |
|
| 177 |
* Returns the dimension of an Effect (in other words, the number of interpolated values). |
|
| 178 |
* @return dimension of the Effect. |
|
| 179 |
*/ |
|
| 180 |
public int getEffectDimension() { return dimensions[ordinal()]; }
|
|
| 181 |
|
|
| 182 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 183 |
/** |
|
| 184 |
* What is the dimension of the Region supported by this effect? |
|
| 185 |
* @return Dimension of the Region supported (0-region not supported at all). |
|
| 186 |
*/ |
|
| 187 |
public int getRegionDimension() { return regionDimension[ordinal()]; }
|
|
| 188 |
|
|
| 189 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 190 |
/** |
|
| 191 |
* What is the dimension of the Center supported by this effect? |
|
| 192 |
* @return Dimension of the Center supported (0-center not supported at all). |
|
| 193 |
*/ |
|
| 194 |
public int getCenterDimension() { return centerDimension[ordinal()]; }
|
|
| 195 |
} |
|
| 196 |
|
|
| src/main/java/org/distorted/library/effect/EffectName.kt | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2017 Leszek Koltunski leszek@koltunski.pl // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// This library is free software; you can redistribute it and/or // |
|
| 7 |
// modify it under the terms of the GNU Lesser General Public // |
|
| 8 |
// License as published by the Free Software Foundation; either // |
|
| 9 |
// version 2.1 of the License, or (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// This library is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // |
|
| 14 |
// Lesser General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU Lesser General Public // |
|
| 17 |
// License along with this library; if not, write to the Free Software // |
|
| 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
|
| 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 20 |
|
|
| 21 |
package org.distorted.library.effect; |
|
| 22 |
|
|
| 23 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 24 |
/** |
|
| 25 |
* Names of Effects one can add to the DistortedEffects queues. |
|
| 26 |
* <p> |
|
| 27 |
* Effect's 'Type' is one of the constants defined in {@link EffectType}.
|
|
| 28 |
* </p> |
|
| 29 |
* <p> |
|
| 30 |
* Effect's 'Uniforms' are a vector of 7 (matrix effects) 12 (vertex) or 8 (fragment) floats, which |
|
| 31 |
* together form full information how to compute a given effect. |
|
| 32 |
* Typically, some of those values will be Interpolated in CPU (by one of the 'EffectQueueX.compute()' |
|
| 33 |
* methods) and the effect of such Interpolation sent to the Shaders. |
|
| 34 |
* </p> |
|
| 35 |
* <p> |
|
| 36 |
* Effect's 'Unity' is such a particular vector of its 'interpolated values' which makes the |
|
| 37 |
* effect NULL. For example, if the effect is 'MOVE' by a 3-dimensional vector, then a 'NULL |
|
| 38 |
* MOVE' is a MOVE by vector (0,0,0), thus (0,0,0) is the unity of the MOVE effect. |
|
| 39 |
* This is used by the EffectQueue classes to decide if the final form of the Effect is NULL - and |
|
| 40 |
* thus if it can safely be removed from Effect Queues without affecting the visual in any way. |
|
| 41 |
* </p> |
|
| 42 |
*/ |
|
| 43 |
|
|
| 44 |
public enum EffectName |
|
| 45 |
{
|
|
| 46 |
// EFFECT NAME /////// EFFECT TYPE ////////// EFFECT UNITY //////////// DIM REGION CENTER // CLASS |
|
| 47 |
ROTATE ( EffectType.MATRIX , new float[] {0.0f} , 4, 0, 3 , MatrixEffectRotate.class ),
|
|
| 48 |
QUATERNION ( EffectType.MATRIX , new float[] {0.0f,0.0f,0.0f} , 4, 0, 3 , MatrixEffectQuaternion.class ),
|
|
| 49 |
MOVE ( EffectType.MATRIX , new float[] {0.0f,0.0f,0.0f} , 3, 0, 0 , MatrixEffectMove.class ),
|
|
| 50 |
SCALE ( EffectType.MATRIX , new float[] {1.0f,1.0f,1.0f} , 3, 0, 0 , MatrixEffectScale.class ),
|
|
| 51 |
SHEAR ( EffectType.MATRIX , new float[] {0.0f,0.0f,0.0f} , 3, 0, 3 , MatrixEffectShear.class ),
|
|
| 52 |
|
|
| 53 |
DISTORT ( EffectType.VERTEX , new float[] {0.0f,0.0f,0.0f} , 3, 4, 3 , VertexEffectDistort.class ),
|
|
| 54 |
DEFORM ( EffectType.VERTEX , new float[] {0.0f,0.0f,0.0f} , 4, 4, 3 , VertexEffectDeform.class ),
|
|
| 55 |
SINK ( EffectType.VERTEX , new float[] {1.0f} , 1, 4, 3 , VertexEffectSink.class ),
|
|
| 56 |
PINCH ( EffectType.VERTEX , new float[] {1.0f} , 3, 4, 3 , VertexEffectPinch.class ),
|
|
| 57 |
SWIRL ( EffectType.VERTEX , new float[] {0.0f} , 1, 4, 3 , VertexEffectSwirl.class ),
|
|
| 58 |
WAVE ( EffectType.VERTEX , new float[] {0.0f} , 5, 4, 3 , VertexEffectWave.class ),
|
|
| 59 |
DISAPPEAR ( EffectType.VERTEX , new float[] {} , 0, 0, 0 , VertexEffectDisappear.class ),
|
|
| 60 |
PIPE ( EffectType.VERTEX , new float[] {1,0f} , 5, 0, 3 , VertexEffectPipe.class ),
|
|
| 61 |
|
|
| 62 |
VERTEX_MOVE ( EffectType.VERTEX , new float[] {0.0f,0.0f,0.0f} , 3, 0, 0 , VertexEffectMove.class ),
|
|
| 63 |
VERTEX_QUATERNION( EffectType.VERTEX , new float[] {0.0f,0.0f,0.0f} , 4, 0, 3 , VertexEffectQuaternion.class ),
|
|
| 64 |
VERTEX_ROTATE ( EffectType.VERTEX , new float[] {0.0f} , 4, 0, 3 , VertexEffectRotate.class ),
|
|
| 65 |
VERTEX_SCALE ( EffectType.VERTEX , new float[] {1.0f,1.0f,1.0f} , 3, 0, 0 , VertexEffectScale.class ),
|
|
| 66 |
VERTEX_SHEAR ( EffectType.VERTEX , new float[] {0.0f,0.0f,0.0f} , 3, 0, 3 , VertexEffectShear.class ),
|
|
| 67 |
|
|
| 68 |
ALPHA ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectAlpha.class ),
|
|
| 69 |
SMOOTH_ALPHA ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectAlpha.class ),
|
|
| 70 |
CHROMA ( EffectType.FRAGMENT, new float[] {0.0f} , 4, 3, 3 , FragmentEffectChroma.class ),
|
|
| 71 |
SMOOTH_CHROMA ( EffectType.FRAGMENT, new float[] {0.0f} , 4, 3, 3 , FragmentEffectChroma.class ),
|
|
| 72 |
BRIGHTNESS ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectBrightness.class ),
|
|
| 73 |
SMOOTH_BRIGHTNESS( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectBrightness.class ),
|
|
| 74 |
SATURATION ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectSaturation.class ),
|
|
| 75 |
SMOOTH_SATURATION( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectSaturation.class ),
|
|
| 76 |
CONTRAST ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectContrast.class ),
|
|
| 77 |
SMOOTH_CONTRAST ( EffectType.FRAGMENT, new float[] {1.0f} , 1, 3, 3 , FragmentEffectContrast.class ),
|
|
| 78 |
|
|
| 79 |
BLUR ( EffectType.POSTPROCESS,new float[] {0.0f} , 2, 0, 0 , PostprocessEffectBlur.class ),
|
|
| 80 |
GLOW ( EffectType.POSTPROCESS,new float[] {0.0f} , 6, 0, 0 , PostprocessEffectGlow.class ),
|
|
| 81 |
BORDER ( EffectType.POSTPROCESS,new float[] {0.0f} , 5, 0, 0 , PostprocessEffectBorder.class ),
|
|
| 82 |
; |
|
| 83 |
|
|
| 84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 85 |
|
|
| 86 |
public static final int LENGTH = values().length; |
|
| 87 |
|
|
| 88 |
private final EffectType type; |
|
| 89 |
private final float[] unity; |
|
| 90 |
private final int dimension; |
|
| 91 |
private final int regionDim; |
|
| 92 |
private final int centerDim; |
|
| 93 |
private final Class<? extends Effect> effectClass; |
|
| 94 |
|
|
| 95 |
private static final int[] dimensions; |
|
| 96 |
private static final int[] regionDimension; |
|
| 97 |
private static final int[] centerDimension; |
|
| 98 |
private static final EffectName[] names; // copy the values() to a local variable so that we |
|
| 99 |
// don't have to keep recreating the array every time |
|
| 100 |
static |
|
| 101 |
{
|
|
| 102 |
int i=0; |
|
| 103 |
|
|
| 104 |
dimensions = new int[LENGTH]; |
|
| 105 |
regionDimension = new int[LENGTH]; |
|
| 106 |
centerDimension = new int[LENGTH]; |
|
| 107 |
names = new EffectName[LENGTH]; |
|
| 108 |
|
|
| 109 |
for(EffectName name: EffectName.values()) |
|
| 110 |
{
|
|
| 111 |
dimensions[i] = name.dimension; |
|
| 112 |
regionDimension[i] = name.regionDim; |
|
| 113 |
centerDimension[i] = name.centerDim; |
|
| 114 |
names[i] = name; |
|
| 115 |
|
|
| 116 |
i++; |
|
| 117 |
} |
|
| 118 |
} |
|
| 119 |
|
|
| 120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 121 |
|
|
| 122 |
float[] getUnity() |
|
| 123 |
{
|
|
| 124 |
return unity; |
|
| 125 |
} |
|
| 126 |
|
|
| 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 128 |
|
|
| 129 |
EffectName(EffectType type, float[] unity, int dimension, int regionDim, |
|
| 130 |
int centerDim, Class<? extends Effect> effectClass ) |
|
| 131 |
{
|
|
| 132 |
this.type = type; |
|
| 133 |
this.unity = unity; |
|
| 134 |
this.dimension = dimension; |
|
| 135 |
this.regionDim = regionDim; |
|
| 136 |
this.centerDim = centerDim; |
|
| 137 |
this.effectClass = effectClass; |
|
| 138 |
} |
|
| 139 |
|
|
| 140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 141 |
// PUBLIC API |
|
| 142 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 143 |
/** |
|
| 144 |
* Returns the Type of an individual Effect. For example, EffectName.ROTATE.getType() will |
|
| 145 |
* return EffectType.MATRIX. |
|
| 146 |
* @return type of the effect. |
|
| 147 |
*/ |
|
| 148 |
public EffectType getType() |
|
| 149 |
{
|
|
| 150 |
return type; |
|
| 151 |
} |
|
| 152 |
|
|
| 153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 154 |
/** |
|
| 155 |
* Returns the Class of an individual Effect. For example, EffectName.ROTATE.getEffectClass() |
|
| 156 |
* returns MatrixEffectRotate.class. |
|
| 157 |
* @return effect class. |
|
| 158 |
*/ |
|
| 159 |
public Class<? extends Effect> getEffectClass() |
|
| 160 |
{
|
|
| 161 |
return effectClass; |
|
| 162 |
} |
|
| 163 |
|
|
| 164 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 165 |
/** |
|
| 166 |
* Returns the i-th EffectName. |
|
| 167 |
* <p> |
|
| 168 |
* If you want to loop over all possible Effects, you need this. |
|
| 169 |
*/ |
|
| 170 |
public static EffectName getName(int ordinal) |
|
| 171 |
{
|
|
| 172 |
return names[ordinal]; |
|
| 173 |
} |
|
| 174 |
|
|
| 175 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 176 |
/** |
|
| 177 |
* Returns the dimension of an Effect (in other words, the number of interpolated values). |
|
| 178 |
* @return dimension of the Effect. |
|
| 179 |
*/ |
|
| 180 |
public int getEffectDimension() { return dimensions[ordinal()]; }
|
|
| 181 |
|
|
| 182 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 183 |
/** |
|
| 184 |
* What is the dimension of the Region supported by this effect? |
|
| 185 |
* @return Dimension of the Region supported (0-region not supported at all). |
|
| 186 |
*/ |
|
| 187 |
public int getRegionDimension() { return regionDimension[ordinal()]; }
|
|
| 188 |
|
|
| 189 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 190 |
/** |
|
| 191 |
* What is the dimension of the Center supported by this effect? |
|
| 192 |
* @return Dimension of the Center supported (0-center not supported at all). |
|
| 193 |
*/ |
|
| 194 |
public int getCenterDimension() { return centerDimension[ordinal()]; }
|
|
| 195 |
} |
|
| 196 |
|
|
| src/main/java/org/distorted/library/effect/EffectQuality.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2016 Leszek Koltunski leszek@koltunski.pl // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// This library is free software; you can redistribute it and/or // |
|
| 7 |
// modify it under the terms of the GNU Lesser General Public // |
|
| 8 |
// License as published by the Free Software Foundation; either // |
|
| 9 |
// version 2.1 of the License, or (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// This library is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // |
|
| 14 |
// Lesser General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU Lesser General Public // |
|
| 17 |
// License along with this library; if not, write to the Free Software // |
|
| 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
|
| 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 20 |
|
|
| 21 |
package org.distorted.library.effect; |
|
| 22 |
|
|
| 23 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 24 |
|
|
| 25 |
import org.distorted.library.main.DistortedEffects; |
|
| 26 |
|
|
| 27 |
/** |
|
| 28 |
* A list of quality levels. |
|
| 29 |
* <p> |
|
| 30 |
* One can set quality of a Postprocessing Effect to one of those. The lower the quality, the faster |
|
| 31 |
* the rendering will be. |
|
| 32 |
* |
|
| 33 |
* @see DistortedEffects |
|
| 34 |
*/ |
|
| 35 |
public enum EffectQuality |
|
| 36 |
{
|
|
| 37 |
HIGHEST ( 0, 1.000f ), // has to start from 0 |
|
| 38 |
HIGH ( 1, 0.500f ), |
|
| 39 |
MEDIUM ( 2, 0.250f ), |
|
| 40 |
LOW ( 3, 0.125f ); |
|
| 41 |
|
|
| 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 43 |
/** |
|
| 44 |
* Numof of possible qualities. |
|
| 45 |
*/ |
|
| 46 |
public static final int LENGTH = values().length; |
|
| 47 |
|
|
| 48 |
private final int level; |
|
| 49 |
private final float mipmap; |
|
| 50 |
|
|
| 51 |
private static final EffectQuality[] qualities; |
|
| 52 |
|
|
| 53 |
static |
|
| 54 |
{
|
|
| 55 |
int i=0; |
|
| 56 |
qualities= new EffectQuality[LENGTH]; |
|
| 57 |
for(EffectQuality q: EffectQuality.values()) qualities[i++] = q; |
|
| 58 |
} |
|
| 59 |
|
|
| 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 61 |
|
|
| 62 |
EffectQuality(int level, float mipmap) |
|
| 63 |
{
|
|
| 64 |
this.level = level; |
|
| 65 |
this.mipmap= mipmap; |
|
| 66 |
} |
|
| 67 |
|
|
| 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 69 |
/** |
|
| 70 |
* Only for use by the library itself. |
|
| 71 |
* |
|
| 72 |
* @y.exclude |
|
| 73 |
*/ |
|
| 74 |
public int getLevel() |
|
| 75 |
{
|
|
| 76 |
return level; |
|
| 77 |
} |
|
| 78 |
|
|
| 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 80 |
/** |
|
| 81 |
* Only for use by the library itself. |
|
| 82 |
* |
|
| 83 |
* @y.exclude |
|
| 84 |
*/ |
|
| 85 |
public static float getMipmap(int quality) |
|
| 86 |
{
|
|
| 87 |
return qualities[quality].mipmap; |
|
| 88 |
} |
|
| 89 |
} |
|
| 90 |
|
|
| src/main/java/org/distorted/library/effect/EffectQuality.kt | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2016 Leszek Koltunski leszek@koltunski.pl // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// This library is free software; you can redistribute it and/or // |
|
| 7 |
// modify it under the terms of the GNU Lesser General Public // |
|
| 8 |
// License as published by the Free Software Foundation; either // |
|
| 9 |
// version 2.1 of the License, or (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// This library is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // |
|
| 14 |
// Lesser General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU Lesser General Public // |
|
| 17 |
// License along with this library; if not, write to the Free Software // |
|
| 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
|
| 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 20 |
|
|
| 21 |
package org.distorted.library.effect; |
|
| 22 |
|
|
| 23 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 24 |
|
|
| 25 |
import org.distorted.library.main.DistortedEffects; |
|
| 26 |
|
|
| 27 |
/** |
|
| 28 |
* A list of quality levels. |
|
| 29 |
* <p> |
|
| 30 |
* One can set quality of a Postprocessing Effect to one of those. The lower the quality, the faster |
|
| 31 |
* the rendering will be. |
|
| 32 |
* |
|
| 33 |
* @see DistortedEffects |
|
| 34 |
*/ |
|
| 35 |
public enum EffectQuality |
|
| 36 |
{
|
|
| 37 |
HIGHEST ( 0, 1.000f ), // has to start from 0 |
|
| 38 |
HIGH ( 1, 0.500f ), |
|
| 39 |
MEDIUM ( 2, 0.250f ), |
|
| 40 |
LOW ( 3, 0.125f ); |
|
| 41 |
|
|
| 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 43 |
/** |
|
| 44 |
* Numof of possible qualities. |
|
| 45 |
*/ |
|
| 46 |
public static final int LENGTH = values().length; |
|
| 47 |
|
|
| 48 |
private final int level; |
|
| 49 |
private final float mipmap; |
|
| 50 |
|
|
| 51 |
private static final EffectQuality[] qualities; |
|
| 52 |
|
|
| 53 |
static |
|
| 54 |
{
|
|
| 55 |
int i=0; |
|
| 56 |
qualities= new EffectQuality[LENGTH]; |
|
| 57 |
for(EffectQuality q: EffectQuality.values()) qualities[i++] = q; |
|
| 58 |
} |
|
| 59 |
|
|
| 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 61 |
|
|
| 62 |
EffectQuality(int level, float mipmap) |
|
| 63 |
{
|
|
| 64 |
this.level = level; |
|
| 65 |
this.mipmap= mipmap; |
|
| 66 |
} |
|
| 67 |
|
|
| 68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 69 |
/** |
|
| 70 |
* Only for use by the library itself. |
|
| 71 |
* |
|
| 72 |
* @y.exclude |
|
| 73 |
*/ |
|
| 74 |
public int getLevel() |
|
| 75 |
{
|
|
| 76 |
return level; |
|
| 77 |
} |
|
| 78 |
|
|
| 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 80 |
/** |
|
| 81 |
* Only for use by the library itself. |
|
| 82 |
* |
|
| 83 |
* @y.exclude |
|
| 84 |
*/ |
|
| 85 |
public static float getMipmap(int quality) |
|
| 86 |
{
|
|
| 87 |
return qualities[quality].mipmap; |
|
| 88 |
} |
|
| 89 |
} |
|
| 90 |
|
|
| src/main/java/org/distorted/library/effect/EffectType.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2016 Leszek Koltunski leszek@koltunski.pl // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// This library is free software; you can redistribute it and/or // |
|
| 7 |
// modify it under the terms of the GNU Lesser General Public // |
|
| 8 |
// License as published by the Free Software Foundation; either // |
|
| 9 |
// version 2.1 of the License, or (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// This library is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // |
|
| 14 |
// Lesser General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU Lesser General Public // |
|
| 17 |
// License along with this library; if not, write to the Free Software // |
|
| 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
|
| 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 20 |
|
|
| 21 |
package org.distorted.library.effect; |
|
| 22 |
|
|
| 23 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 24 |
|
|
| 25 |
/** |
|
| 26 |
* Types of Effects one can add to the DistortedEffects queues. |
|
| 27 |
* <p> |
|
| 28 |
* Each effect type goes to an independent queue; the queues get executed one-by-one |
|
| 29 |
* and are each a class descendant from EffectQueue. |
|
| 30 |
*/ |
|
| 31 |
|
|
| 32 |
public enum EffectType |
|
| 33 |
{
|
|
| 34 |
/** |
|
| 35 |
* Effects that change the ModelView matrix: Rotations, Moves, Shears, Scales. |
|
| 36 |
*/ |
|
| 37 |
MATRIX, |
|
| 38 |
/** |
|
| 39 |
* Effects that get executed in the Vertex shader: various distortions of the vertices. |
|
| 40 |
*/ |
|
| 41 |
VERTEX, |
|
| 42 |
/** |
|
| 43 |
* Effects executed in the Fragment shader: changes of color, hue, transparency levels, etc. |
|
| 44 |
*/ |
|
| 45 |
FRAGMENT, |
|
| 46 |
/** |
|
| 47 |
* Postprocessing effects done to the texture the first stage fragment shader created |
|
| 48 |
*/ |
|
| 49 |
POSTPROCESS; |
|
| 50 |
|
|
| 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 52 |
/** |
|
| 53 |
* Number of effect types. |
|
| 54 |
* Only for use by the library itself. |
|
| 55 |
* |
|
| 56 |
* @y.exclude |
|
| 57 |
*/ |
|
| 58 |
public static final int LENGTH = values().length; |
|
| 59 |
/** |
|
| 60 |
* Needed when we do bitwise operations on Effect Types. |
|
| 61 |
* Only for use by the library itself. |
|
| 62 |
* |
|
| 63 |
* @y.exclude |
|
| 64 |
*/ |
|
| 65 |
public static final int MASK= (1<<LENGTH)-1; |
|
| 66 |
|
|
| 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 68 |
/** |
|
| 69 |
* Only for use by the library itself. |
|
| 70 |
* |
|
| 71 |
* @y.exclude |
|
| 72 |
*/ |
|
| 73 |
public static void reset(int[] maxtable) |
|
| 74 |
{
|
|
| 75 |
maxtable[0] =100; // By default, there can be a maximum 100 MATRIX effects in a single |
|
| 76 |
// EffectQueueMatrix at any given time. This can be changed with a call |
|
| 77 |
// to EffectQueueMatrix.setMax(int) |
|
| 78 |
maxtable[1] = 30; // Max 30 VERTEX Effects |
|
| 79 |
maxtable[2] = 5; // Max 5 FRAGMENT Effects |
|
| 80 |
maxtable[3] = 3; // Max 3 POSTPROCESSING Effects |
|
| 81 |
} |
|
| 82 |
|
|
| 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 84 |
/** |
|
| 85 |
* Returns the i-th EffectType. |
|
| 86 |
* <p> |
|
| 87 |
* If you want to loop over all possible effect types, you need this. |
|
| 88 |
*/ |
|
| 89 |
public static EffectType getType(int ordinal) |
|
| 90 |
{
|
|
| 91 |
return values()[ordinal]; |
|
| 92 |
} |
|
| 93 |
|
|
| 94 |
} |
|
| src/main/java/org/distorted/library/effect/EffectType.kt | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2016 Leszek Koltunski leszek@koltunski.pl // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// This library is free software; you can redistribute it and/or // |
|
| 7 |
// modify it under the terms of the GNU Lesser General Public // |
|
| 8 |
// License as published by the Free Software Foundation; either // |
|
| 9 |
// version 2.1 of the License, or (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// This library is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // |
|
| 14 |
// Lesser General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU Lesser General Public // |
|
| 17 |
// License along with this library; if not, write to the Free Software // |
|
| 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
|
| 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 20 |
|
|
| 21 |
package org.distorted.library.effect; |
|
| 22 |
|
|
| 23 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 24 |
|
|
| 25 |
/** |
|
| 26 |
* Types of Effects one can add to the DistortedEffects queues. |
|
| 27 |
* <p> |
|
| 28 |
* Each effect type goes to an independent queue; the queues get executed one-by-one |
|
| 29 |
* and are each a class descendant from EffectQueue. |
|
| 30 |
*/ |
|
| 31 |
|
|
| 32 |
public enum EffectType |
|
| 33 |
{
|
|
| 34 |
/** |
|
| 35 |
* Effects that change the ModelView matrix: Rotations, Moves, Shears, Scales. |
|
| 36 |
*/ |
|
| 37 |
MATRIX, |
|
| 38 |
/** |
|
| 39 |
* Effects that get executed in the Vertex shader: various distortions of the vertices. |
|
| 40 |
*/ |
|
| 41 |
VERTEX, |
|
| 42 |
/** |
|
| 43 |
* Effects executed in the Fragment shader: changes of color, hue, transparency levels, etc. |
|
| 44 |
*/ |
|
| 45 |
FRAGMENT, |
|
| 46 |
/** |
|
| 47 |
* Postprocessing effects done to the texture the first stage fragment shader created |
|
| 48 |
*/ |
|
| 49 |
POSTPROCESS; |
|
| 50 |
|
|
| 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 52 |
/** |
|
| 53 |
* Number of effect types. |
|
| 54 |
* Only for use by the library itself. |
|
| 55 |
* |
|
| 56 |
* @y.exclude |
|
| 57 |
*/ |
|
| 58 |
public static final int LENGTH = values().length; |
|
| 59 |
/** |
|
| 60 |
* Needed when we do bitwise operations on Effect Types. |
|
| 61 |
* Only for use by the library itself. |
|
| 62 |
* |
|
| 63 |
* @y.exclude |
|
| 64 |
*/ |
|
| 65 |
public static final int MASK= (1<<LENGTH)-1; |
|
| 66 |
|
|
| 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 68 |
/** |
|
| 69 |
* Only for use by the library itself. |
|
| 70 |
* |
|
| 71 |
* @y.exclude |
|
| 72 |
*/ |
|
| 73 |
public static void reset(int[] maxtable) |
|
| 74 |
{
|
|
| 75 |
maxtable[0] =100; // By default, there can be a maximum 100 MATRIX effects in a single |
|
| 76 |
// EffectQueueMatrix at any given time. This can be changed with a call |
|
| 77 |
// to EffectQueueMatrix.setMax(int) |
|
| 78 |
maxtable[1] = 30; // Max 30 VERTEX Effects |
|
| 79 |
maxtable[2] = 5; // Max 5 FRAGMENT Effects |
|
| 80 |
maxtable[3] = 3; // Max 3 POSTPROCESSING Effects |
|
| 81 |
} |
|
| 82 |
|
|
| 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 84 |
/** |
|
| 85 |
* Returns the i-th EffectType. |
|
| 86 |
* <p> |
|
| 87 |
* If you want to loop over all possible effect types, you need this. |
|
| 88 |
*/ |
|
| 89 |
public static EffectType getType(int ordinal) |
|
| 90 |
{
|
|
| 91 |
return values()[ordinal]; |
|
| 92 |
} |
|
| 93 |
|
|
| 94 |
} |
|
| src/main/java/org/distorted/library/effect/FragmentEffect.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2017 Leszek Koltunski leszek@koltunski.pl // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// This library is free software; you can redistribute it and/or // |
|
| 7 |
// modify it under the terms of the GNU Lesser General Public // |
|
| 8 |
// License as published by the Free Software Foundation; either // |
|
| 9 |
// version 2.1 of the License, or (at your option) any later version. // |
|
| 10 |
// // |
|
| 11 |
// This library is distributed in the hope that it will be useful, // |
|
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // |
|
| 14 |
// Lesser General Public License for more details. // |
|
| 15 |
// // |
|
| 16 |
// You should have received a copy of the GNU Lesser General Public // |
|
| 17 |
// License along with this library; if not, write to the Free Software // |
|
| 18 |
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // |
|
| 19 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 20 |
|
|
| 21 |
package org.distorted.library.effect; |
|
| 22 |
|
|
| 23 |
import org.distorted.library.effectqueue.EffectQueue; |
|
| 24 |
import org.distorted.library.type.Static3D; |
|
| 25 |
|
|
| 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 27 |
/** |
|
| 28 |
* Abstract class that represents an Effect that works by injecting certain code into the main Fragment shader. |
|
| 29 |
*/ |
|
| 30 |
public abstract class FragmentEffect extends Effect |
|
| 31 |
{
|
|
| 32 |
/** |
|
| 33 |
* 12: 4-per effect interpolated values, 3 dimensional Center (+padding), 3 dimensional Region (+padding). |
|
| 34 |
*/ |
|
| 35 |
public static final int NUM_FLOAT_UNIFORMS = 12; |
|
| 36 |
/** |
|
| 37 |
* 4: the name, unused, unused, unused |
|
| 38 |
*/ |
|
| 39 |
public static final int NUM_INT_UNIFORMS = 4; |
|
| 40 |
|
|
| 41 |
static final int CENTER_OFFSET = 5; |
|
| 42 |
static final int REGION_OFFSET = 8; |
|
| 43 |
private static String mGLSL = ""; |
|
| 44 |
private static int mNumEnabled = 0; |
|
| 45 |
|
|
| 46 |
final static Static3D MAX_REGION = new Static3D(1000000,1000000,1000000); |
|
| 47 |
|
|
| 48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 49 |
|
|
| 50 |
FragmentEffect(EffectName name) |
|
| 51 |
{
|
|
| 52 |
super(name); |
|
| 53 |
} |
|
| 54 |
|
|
| 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
Also available in: Unified diff
Rename .java to .kt