Revision 8eccf334
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/Distorted.java | ||
---|---|---|
25 | 25 |
import android.content.res.Resources; |
26 | 26 |
import org.distorted.library.program.*; |
27 | 27 |
|
28 |
import org.distorted.library.effect.*; |
|
29 |
|
|
30 |
|
|
28 | 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
29 | 32 |
/** |
30 | 33 |
* A singleton class used to control various global settings. |
... | ... | |
80 | 83 |
|
81 | 84 |
private Distorted() |
82 | 85 |
{ |
83 |
|
|
86 |
|
|
84 | 87 |
} |
85 | 88 |
|
86 | 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
119 | 122 |
EffectQueuePostprocess.createProgram(resources); |
120 | 123 |
EffectMessageSender.startSending(); |
121 | 124 |
|
125 |
Effect.reset(); |
|
126 |
|
|
127 |
String[] classes = Effect.getClassesOfPackage(context,"org.distorted.library.effect"); |
|
128 |
int len = classes.length; |
|
129 |
|
|
130 |
android.util.Log.e("Distorted", "Number of classes found: "+len); |
|
131 |
|
|
132 |
for(int i=0; i<len; i++) |
|
133 |
{ |
|
134 |
android.util.Log.e("Distorted", "Class found: "+classes[i]); |
|
135 |
} |
|
136 |
|
|
137 |
|
|
122 | 138 |
mInitialized = true; |
123 | 139 |
} |
124 | 140 |
|
src/main/java/org/distorted/library/EffectQueueMatrix.java | ||
---|---|---|
47 | 47 |
private static float[] mViewMatrix= new float[16]; |
48 | 48 |
|
49 | 49 |
private static int mObjDH; // This is a handle to half a Object dimensions |
50 |
private static int mMVPMatrixH; // pass in the transformation matrix
|
|
51 |
private static int mMVMatrixH; // pass in the modelview matrix.
|
|
50 |
private static int mMVPMatrixH; // the transformation matrix |
|
51 |
private static int mMVMatrixH; // the modelview matrix. |
|
52 | 52 |
|
53 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
54 | 54 |
|
src/main/java/org/distorted/library/effect/Effect.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2017 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted 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 // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.library.effect; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
import android.content.Context; |
|
25 |
|
|
26 |
import java.io.File; |
|
27 |
import java.io.IOException; |
|
28 |
import java.net.URL; |
|
29 |
import java.util.ArrayList; |
|
30 |
import java.util.Enumeration; |
|
31 |
import java.util.List; |
|
32 |
|
|
33 |
import dalvik.system.DexFile; |
|
34 |
|
|
35 |
public abstract class Effect |
|
36 |
{ |
|
37 |
long mID; |
|
38 |
|
|
39 |
private static long mNextID = 0; |
|
40 |
static final int NUM_TYPES; |
|
41 |
static int[] mMax; |
|
42 |
static Class[] mDescendants; |
|
43 |
|
|
44 |
static |
|
45 |
{ |
|
46 |
try |
|
47 |
{ |
|
48 |
mDescendants = getClasses("org.distorted.library.effect"); |
|
49 |
} |
|
50 |
catch(ClassNotFoundException cnfe) |
|
51 |
{ |
|
52 |
android.util.Log.e("Effect", "ClassNotFoundException: "+cnfe.getMessage()); |
|
53 |
} |
|
54 |
catch(IOException ioe) |
|
55 |
{ |
|
56 |
android.util.Log.e("Effect", "IOException: "+ioe.getMessage()); |
|
57 |
} |
|
58 |
|
|
59 |
NUM_TYPES = mDescendants.length; |
|
60 |
mMax = new int[NUM_TYPES]; |
|
61 |
|
|
62 |
android.util.Log.e("Effect", "Found "+NUM_TYPES+" descendant classes"); |
|
63 |
} |
|
64 |
|
|
65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
66 |
|
|
67 |
public static String[] getClassesOfPackage(Context c, String packageName) |
|
68 |
{ |
|
69 |
ArrayList<String> classes = new ArrayList<>(); |
|
70 |
|
|
71 |
try |
|
72 |
{ |
|
73 |
String packageCodePath = c.getPackageCodePath(); |
|
74 |
DexFile df = new DexFile(packageCodePath); |
|
75 |
|
|
76 |
for (Enumeration<String> iter = df.entries(); iter.hasMoreElements(); ) |
|
77 |
{ |
|
78 |
String className = iter.nextElement(); |
|
79 |
if (className.contains(packageName)) |
|
80 |
{ |
|
81 |
classes.add(className.substring(className.lastIndexOf(".") + 1, className.length())); |
|
82 |
} |
|
83 |
|
|
84 |
android.util.Log.e("Distorted", "searching: "+className); |
|
85 |
} |
|
86 |
} |
|
87 |
catch (IOException e) |
|
88 |
{ |
|
89 |
e.printStackTrace(); |
|
90 |
} |
|
91 |
|
|
92 |
return classes.toArray(new String[classes.size()]); |
|
93 |
} |
|
94 |
|
|
95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
96 |
|
|
97 |
private static Class[] getClasses(String packageName) throws ClassNotFoundException, IOException |
|
98 |
{ |
|
99 |
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); |
|
100 |
assert classLoader != null; |
|
101 |
String path = packageName.replace('.', '/'); |
|
102 |
Enumeration<URL> resources = classLoader.getResources(path); |
|
103 |
|
|
104 |
android.util.Log.e("Effect", "resources: "+resources.toString()); |
|
105 |
|
|
106 |
List<File> dirs = new ArrayList<>(); |
|
107 |
|
|
108 |
while (resources.hasMoreElements()) |
|
109 |
{ |
|
110 |
URL resource = resources.nextElement(); |
|
111 |
dirs.add(new File(resource.getFile())); |
|
112 |
} |
|
113 |
|
|
114 |
android.util.Log.e("Effect", "Num of dirs: "+dirs.size()); |
|
115 |
|
|
116 |
ArrayList<Class> classes = new ArrayList<>(); |
|
117 |
|
|
118 |
for (File directory : dirs) |
|
119 |
{ |
|
120 |
android.util.Log.e("Effect", "Searching in "+directory.getName()); |
|
121 |
|
|
122 |
classes.addAll(findClasses(directory, packageName)); |
|
123 |
} |
|
124 |
|
|
125 |
return classes.toArray(new Class[classes.size()]); |
|
126 |
} |
|
127 |
|
|
128 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
129 |
|
|
130 |
private static List<Class> findClasses(File directory, String packageName) throws ClassNotFoundException |
|
131 |
{ |
|
132 |
List<Class> classes = new ArrayList<>(); |
|
133 |
|
|
134 |
if (!directory.exists()) |
|
135 |
{ |
|
136 |
return classes; |
|
137 |
} |
|
138 |
|
|
139 |
File[] files = directory.listFiles(); |
|
140 |
|
|
141 |
for (File file : files) |
|
142 |
{ |
|
143 |
if (file.isDirectory()) |
|
144 |
{ |
|
145 |
assert !file.getName().contains("."); |
|
146 |
classes.addAll(findClasses(file, packageName + "." + file.getName())); |
|
147 |
} |
|
148 |
else if (file.getName().endsWith(".class")) |
|
149 |
{ |
|
150 |
classes.add(Class.forName(packageName + '.' + file.getName().substring(0, file.getName().length() - 6))); |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
return classes; |
|
155 |
} |
|
156 |
|
|
157 |
|
|
158 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
159 |
|
|
160 |
public static void onDestroy() |
|
161 |
{ |
|
162 |
mNextID = 0; |
|
163 |
} |
|
164 |
|
|
165 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
166 |
|
|
167 |
public static void reset() |
|
168 |
{ |
|
169 |
mNextID = 1; |
|
170 |
} |
|
171 |
|
|
172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
173 |
|
|
174 |
Effect() |
|
175 |
{ |
|
176 |
mID = mNextID++; |
|
177 |
} |
|
178 |
} |
src/main/java/org/distorted/library/effect/FragmentEffect.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2017 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted 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 // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.library.effect; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
public abstract class FragmentEffect extends Effect |
|
25 |
{ |
|
26 |
|
|
27 |
} |
src/main/java/org/distorted/library/effect/MatrixEffect.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2017 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted 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 // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.library.effect; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
public abstract class MatrixEffect extends Effect |
|
25 |
{ |
|
26 |
static int mMax; |
|
27 |
|
|
28 |
|
|
29 |
} |
src/main/java/org/distorted/library/effect/PostprocessEffect.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2017 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted 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 // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.library.effect; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
public abstract class PostprocessEffect extends Effect |
|
25 |
{ |
|
26 |
|
|
27 |
} |
src/main/java/org/distorted/library/effect/VertexEffect.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2017 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted 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 // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.library.effect; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
public abstract class VertexEffect extends Effect |
|
25 |
{ |
|
26 |
|
|
27 |
} |
Also available in: Unified diff
Beginnings of support for Effect classes.