Revision 47d838ca
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/library/Distorted.java | ||
---|---|---|
137 | 137 |
final InputStream mainVertexStream = resources.openRawResource(R.raw.main_vertex_shader); |
138 | 138 |
final InputStream mainFragmentStream = resources.openRawResource(R.raw.main_fragment_shader); |
139 | 139 |
|
140 |
DistortedProgram mainProgram = new DistortedProgram(mainVertexStream,mainFragmentStream); |
|
140 |
String mainVertexHeader= ("#version 100\n#define NUM_VERTEX " + DistortedEffects.getMaxVertex()+"\n"); |
|
141 |
|
|
142 |
for(EffectNames name: EffectNames.values() ) |
|
143 |
{ |
|
144 |
if( name.getType()== EffectTypes.VERTEX) |
|
145 |
mainVertexHeader += ("#define "+name.name()+" "+name.ordinal()+"\n"); |
|
146 |
} |
|
147 |
|
|
148 |
String mainFragmentHeader= ("#version 100\n#define NUM_FRAGMENT " + DistortedEffects.getMaxFragment()+"\n"); |
|
149 |
|
|
150 |
for(EffectNames name: EffectNames.values() ) |
|
151 |
{ |
|
152 |
if( name.getType()== EffectTypes.FRAGMENT) |
|
153 |
mainFragmentHeader += ("#define "+name.name()+" "+name.ordinal()+"\n"); |
|
154 |
} |
|
155 |
|
|
156 |
DistortedProgram mainProgram = new DistortedProgram(mainVertexStream,mainFragmentStream, mainVertexHeader, mainFragmentHeader); |
|
141 | 157 |
mainProgramH = mainProgram.getProgramHandle(); |
142 | 158 |
GLES20.glUseProgram(mainProgramH); |
143 | 159 |
mainProgram.bindAndEnableAttributes(); |
... | ... | |
158 | 174 |
final InputStream postVertexStream = resources.openRawResource(R.raw.post_vertex_shader); |
159 | 175 |
final InputStream postFragmentStream = resources.openRawResource(R.raw.post_fragment_shader); |
160 | 176 |
|
161 |
DistortedProgram postProgram = new DistortedProgram(postVertexStream,postFragmentStream); |
|
177 |
String postFragmentHeader= ("#version 100\n#define NUM_POSTPROCESS " + DistortedEffects.getMaxPostprocess()+"\n"); |
|
178 |
|
|
179 |
for(EffectNames name: EffectNames.values() ) |
|
180 |
{ |
|
181 |
if( name.getType()== EffectTypes.POSTPROCESS) |
|
182 |
postFragmentHeader += ("#define "+name.name()+" "+name.ordinal()+"\n"); |
|
183 |
} |
|
184 |
|
|
185 |
DistortedProgram postProgram = new DistortedProgram(postVertexStream,postFragmentStream, "", postFragmentHeader); |
|
162 | 186 |
postProgramH = postProgram.getProgramHandle(); |
163 | 187 |
GLES20.glUseProgram(postProgramH); |
164 | 188 |
postProgram.bindAndEnableAttributes(); |
src/main/java/org/distorted/library/program/DistortedProgram.java | ||
---|---|---|
216 | 216 |
|
217 | 217 |
if (shaderHandle != 0) |
218 | 218 |
{ |
219 |
GLES20.glShaderSource(shaderHandle, "#version 100 \n"+ generateShaderHeader(shaderType) + shaderSource);
|
|
219 |
GLES20.glShaderSource(shaderHandle, shaderSource); |
|
220 | 220 |
GLES20.glCompileShader(shaderHandle); |
221 | 221 |
final int[] compileStatus = new int[1]; |
222 | 222 |
GLES20.glGetShaderiv(shaderHandle, GLES20.GL_COMPILE_STATUS, compileStatus, 0); |
... | ... | |
243 | 243 |
return shaderHandle; |
244 | 244 |
} |
245 | 245 |
|
246 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
247 |
|
|
248 |
private static String generateShaderHeader(final int type) |
|
249 |
{ |
|
250 |
String header=""; |
|
251 |
|
|
252 |
switch(type) |
|
253 |
{ |
|
254 |
case GLES20.GL_VERTEX_SHADER : header += ("#define NUM_VERTEX " + DistortedEffects.getMaxVertex()+"\n"); |
|
255 |
|
|
256 |
for(EffectNames name: EffectNames.values() ) |
|
257 |
{ |
|
258 |
if( name.getType()== EffectTypes.VERTEX) |
|
259 |
header += ("#define "+name.name()+" "+name.ordinal()+"\n"); |
|
260 |
} |
|
261 |
break; |
|
262 |
case GLES20.GL_FRAGMENT_SHADER: header += ("#define NUM_FRAGMENT "+ DistortedEffects.getMaxFragment()+"\n"); |
|
263 |
|
|
264 |
for(EffectNames name: EffectNames.values() ) |
|
265 |
{ |
|
266 |
if( name.getType()==EffectTypes.FRAGMENT) |
|
267 |
header += ("#define "+name.name()+" "+name.ordinal()+"\n"); |
|
268 |
} |
|
269 |
break; |
|
270 |
} |
|
271 |
|
|
272 |
//android.util.Log.d("program",""+header); |
|
273 |
|
|
274 |
return header; |
|
275 |
} |
|
276 |
|
|
277 | 246 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
278 | 247 |
// PUBLIC API |
279 | 248 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
291 | 260 |
* @throws LinkingException |
292 | 261 |
*/ |
293 | 262 |
|
294 |
public DistortedProgram(final InputStream vertex, final InputStream fragment) |
|
263 |
public DistortedProgram(final InputStream vertex, final InputStream fragment, final String vertexHeader, final String fragmentHeader)
|
|
295 | 264 |
throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException |
296 | 265 |
{ |
297 | 266 |
mNumAttributes = 0; |
... | ... | |
301 | 270 |
|
302 | 271 |
sanitizeMaxValues(); |
303 | 272 |
|
304 |
final int vertexShaderHandle = compileShader(GLES20.GL_VERTEX_SHADER , vertexShader ); |
|
305 |
final int fragmentShaderHandle = compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentShader); |
|
273 |
final int vertexShaderHandle = compileShader(GLES20.GL_VERTEX_SHADER , vertexHeader + vertexShader );
|
|
274 |
final int fragmentShaderHandle = compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentHeader + fragmentShader);
|
|
306 | 275 |
|
307 | 276 |
mProgramHandle = createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, mAttributeName); |
308 | 277 |
} |
src/main/res/raw/post_fragment_shader.glsl | ||
---|---|---|
17 | 17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
18 | 18 |
////////////////////////////////////////////////////////////////////////////////////////////// |
19 | 19 |
|
20 |
#define NUM_POSTPROCESS 3 |
|
21 |
#define BLUR 0 |
|
22 |
|
|
23 | 20 |
precision lowp float; |
24 | 21 |
|
25 | 22 |
varying vec2 v_TexCoordinate; |
Also available in: Unified diff
NUM_POSTPROCESS corectly #defined now.