Revision f046b159
Added by Leszek Koltunski almost 4 years ago
src/main/java/org/distorted/library/effect/VertexEffect.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import org.distorted.library.type.Static4D; |
23 | 23 |
|
24 |
import java.lang.reflect.Method; |
|
25 |
|
|
24 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
25 | 27 |
/** |
26 | 28 |
* Abstract class that represents an Effect that works by injecting certain code into the main Vertex shader. |
... | ... | |
37 | 39 |
private static String mGLSL = ""; |
38 | 40 |
private static int mNumEnabled = 0; |
39 | 41 |
|
42 |
private static String mFullGLSL = ""; |
|
43 |
private static int mFullEnabled = 0; |
|
44 |
private static boolean mFullPrepared = false; |
|
45 |
|
|
40 | 46 |
final static Static4D MAX_REGION = new Static4D(0,0,0,1000000); |
41 | 47 |
|
42 | 48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
47 | 53 |
} |
48 | 54 |
|
49 | 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
50 |
// prepare code to be injected into the 'main_vertex_shader' main() function. |
|
51 | 56 |
|
52 |
static void addEffect(EffectName name, String code)
|
|
57 |
private static String retSection(int effect, String code)
|
|
53 | 58 |
{ |
54 |
int effect = name.ordinal(); |
|
55 |
|
|
56 |
if( mEnabled[effect] ) return; |
|
57 |
|
|
58 |
mEnabled[effect] = true; |
|
59 |
mNumEnabled ++; |
|
60 |
|
|
61 |
mGLSL += |
|
59 |
return |
|
62 | 60 |
|
63 | 61 |
"if( vName[i]=="+effect+")\n" + |
64 | 62 |
"{\n" + |
... | ... | |
67 | 65 |
"else\n"; |
68 | 66 |
} |
69 | 67 |
|
68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
69 |
// prepare the code to be injected into the Full program, i.e. code of ALL vertex effects. |
|
70 |
|
|
71 |
private static void prepareFull() |
|
72 |
{ |
|
73 |
Method method; |
|
74 |
|
|
75 |
for(EffectName name: EffectName.values()) |
|
76 |
{ |
|
77 |
if( name.getType() == EffectType.VERTEX ) |
|
78 |
{ |
|
79 |
Class<? extends Effect> cls = name.getEffectClass(); |
|
80 |
|
|
81 |
try |
|
82 |
{ |
|
83 |
method = cls.getDeclaredMethod("code"); |
|
84 |
} |
|
85 |
catch(NoSuchMethodException ex) |
|
86 |
{ |
|
87 |
android.util.Log.e("Effect", "exception getting method: "+ex.getMessage()); |
|
88 |
method = null; |
|
89 |
} |
|
90 |
|
|
91 |
try |
|
92 |
{ |
|
93 |
if( method!=null ) |
|
94 |
{ |
|
95 |
Object value = method.invoke(null); |
|
96 |
String code = (String)value; |
|
97 |
mFullGLSL += retSection(name.ordinal(),code); |
|
98 |
mFullEnabled++; |
|
99 |
} |
|
100 |
} |
|
101 |
catch(Exception ex) |
|
102 |
{ |
|
103 |
android.util.Log.e("Effect", "exception invoking method: "+ex.getMessage()); |
|
104 |
} |
|
105 |
} |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
110 |
// prepare code to be injected into the 'main_vertex_shader' main() function. |
|
111 |
|
|
112 |
static void addEffect(EffectName name, String code) |
|
113 |
{ |
|
114 |
int effect = name.ordinal(); |
|
115 |
|
|
116 |
if( !mEnabled[effect] ) |
|
117 |
{ |
|
118 |
mEnabled[effect] = true; |
|
119 |
mNumEnabled ++; |
|
120 |
mGLSL += retSection(effect,code); |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
70 | 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
71 | 125 |
/** |
72 | 126 |
* Only for use by the library itself. |
... | ... | |
78 | 132 |
return mGLSL + "{}"; |
79 | 133 |
} |
80 | 134 |
|
135 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
136 |
/** |
|
137 |
* Only for use by the library itself. |
|
138 |
* |
|
139 |
* @y.exclude |
|
140 |
*/ |
|
141 |
public static String getAllGLSL() |
|
142 |
{ |
|
143 |
if( !mFullPrepared ) |
|
144 |
{ |
|
145 |
prepareFull(); |
|
146 |
mFullPrepared = true; |
|
147 |
} |
|
148 |
|
|
149 |
return mFullGLSL + "{}"; |
|
150 |
} |
|
151 |
|
|
152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
153 |
/** |
|
154 |
* Only for use by the library itself. |
|
155 |
* |
|
156 |
* @y.exclude |
|
157 |
*/ |
|
158 |
public static int getAllEnabled() |
|
159 |
{ |
|
160 |
if( !mFullPrepared ) |
|
161 |
{ |
|
162 |
prepareFull(); |
|
163 |
mFullPrepared = true; |
|
164 |
} |
|
165 |
|
|
166 |
return mFullEnabled; |
|
167 |
} |
|
168 |
|
|
81 | 169 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
82 | 170 |
|
83 | 171 |
static void destroyStatics() |
84 | 172 |
{ |
85 | 173 |
mNumEnabled = 0; |
86 | 174 |
mGLSL = ""; |
175 |
mFullEnabled= 0; |
|
176 |
mFullGLSL = ""; |
|
177 |
mFullPrepared = false; |
|
87 | 178 |
} |
88 | 179 |
|
89 | 180 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
First attempt at the MeshBase.apply(VertexEffect) API.