Revision faa3ff56
Added by Leszek Koltunski almost 7 years ago
src/main/java/org/distorted/library/program/DistortedProgram.java | ||
---|---|---|
41 | 41 |
private String[] mAttributeName; |
42 | 42 |
private String[] mUniformName; |
43 | 43 |
|
44 |
/** |
|
45 |
* List of Attributes (on OpenGL ES 3.0: 'in' variables) in the same order as declared in the shader source. |
|
46 |
*/ |
|
44 | 47 |
public final int[] mAttribute; |
48 |
/** |
|
49 |
* List of Uniforms in the same order as declared in the shader source. |
|
50 |
*/ |
|
45 | 51 |
public final int[] mUniform; |
46 | 52 |
|
47 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
342 | 348 |
} |
343 | 349 |
|
344 | 350 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
345 |
// feedback: List of 'out' variables (OpenGL ES >= 3.0 only!) that will be transferred back to CPU |
|
346 |
// using Transform Feedback. |
|
347 |
|
|
351 |
/** |
|
352 |
* Only for use by the library itself. |
|
353 |
* |
|
354 |
* @y.exclude |
|
355 |
*/ |
|
348 | 356 |
public DistortedProgram(final InputStream vertex, final InputStream fragment, final String vertexHeader, final String fragmentHeader, int glslVersion, final String[] feedback ) |
349 | 357 |
throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException |
350 | 358 |
{ |
... | ... | |
379 | 387 |
} |
380 | 388 |
|
381 | 389 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
382 |
|
|
383 |
public DistortedProgram(final String vertex, final String fragment) |
|
390 |
/** |
|
391 |
* Only for use by the library itself. |
|
392 |
* |
|
393 |
* @y.exclude |
|
394 |
*/ |
|
395 |
public DistortedProgram(final InputStream vertex, final InputStream fragment, final String vertexHeader, final String fragmentHeader, |
|
396 |
final String enabledVertex, final String enabledFragment, int glslVersion, final String[] feedback ) |
|
384 | 397 |
throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException |
385 | 398 |
{ |
386 |
init(300);
|
|
399 |
init(glslVersion);
|
|
387 | 400 |
|
388 |
doAttributes(vertex , true );
|
|
389 |
doAttributes(fragment, false);
|
|
401 |
String vertexShader = readTextFileFromRawResource(vertex , true );
|
|
402 |
String fragmentShader = readTextFileFromRawResource(fragment, false);
|
|
390 | 403 |
|
391 |
final int vertexShaderHandle = compileShader(GLES30.GL_VERTEX_SHADER , vertex );
|
|
392 |
final int fragmentShaderHandle = compileShader(GLES30.GL_FRAGMENT_SHADER, fragment);
|
|
404 |
vertexShader = insertEnabledEffects(vertexShader ,enabledVertex );
|
|
405 |
fragmentShader = insertEnabledEffects(fragmentShader,enabledFragment);
|
|
393 | 406 |
|
394 |
mProgramHandle = createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, mAttributeName, null ); |
|
407 |
final int vertexShaderHandle = compileShader(GLES30.GL_VERTEX_SHADER , vertexHeader + vertexShader ); |
|
408 |
final int fragmentShaderHandle = compileShader(GLES30.GL_FRAGMENT_SHADER, fragmentHeader + fragmentShader); |
|
409 |
|
|
410 |
mProgramHandle = createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, mAttributeName, glslVersion>= 300 ? feedback:null ); |
|
395 | 411 |
|
396 | 412 |
mAttribute = new int[mNumAttributes]; |
397 | 413 |
|
... | ... | |
414 | 430 |
} |
415 | 431 |
|
416 | 432 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
417 |
// feedback: List of 'out' variables (OpenGL ES >= 3.0 only!) that will be transferred back to CPU |
|
418 |
// using Transform Feedback. |
|
419 |
|
|
420 |
public DistortedProgram(final InputStream vertex, final InputStream fragment, final String vertexHeader, final String fragmentHeader, |
|
421 |
final String enabledVertex, final String enabledFragment, int glslVersion, final String[] feedback ) |
|
433 |
/** |
|
434 |
* Only for use by the library itself. |
|
435 |
* |
|
436 |
* @y.exclude |
|
437 |
*/ |
|
438 |
public DistortedProgram(final InputStream vertex, final InputStream fragment, final String vertexHeader, final String fragmentHeader, int glslVersion ) |
|
422 | 439 |
throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException |
423 | 440 |
{ |
424 |
init(glslVersion); |
|
441 |
this(vertex,fragment,vertexHeader,fragmentHeader,glslVersion,null); |
|
442 |
} |
|
425 | 443 |
|
426 |
String vertexShader = readTextFileFromRawResource(vertex , true ); |
|
427 |
String fragmentShader = readTextFileFromRawResource(fragment, false); |
|
444 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
445 |
// PUBLIC API |
|
446 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
447 |
/** |
|
448 |
* Create a new Shader Program from two source strings. |
|
449 |
* <p> |
|
450 |
* Needs to be called from a thread holding the OpenGL context. |
|
451 |
* Assumed to hold GLSL 'version 300 es' source. |
|
452 |
* |
|
453 |
* @param vertex Vertex shader code. |
|
454 |
* @param fragment Fragment shader code. |
|
455 |
* @throws FragmentCompilationException |
|
456 |
* @throws VertexCompilationException |
|
457 |
* @throws VertexUniformsException |
|
458 |
* @throws FragmentUniformsException |
|
459 |
* @throws LinkingException |
|
460 |
*/ |
|
461 |
public DistortedProgram(final String vertex, final String fragment) |
|
462 |
throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException |
|
463 |
{ |
|
464 |
init(300); |
|
428 | 465 |
|
429 |
vertexShader = insertEnabledEffects(vertexShader ,enabledVertex );
|
|
430 |
fragmentShader = insertEnabledEffects(fragmentShader,enabledFragment);
|
|
466 |
doAttributes(vertex , true );
|
|
467 |
doAttributes(fragment, false);
|
|
431 | 468 |
|
432 |
final int vertexShaderHandle = compileShader(GLES30.GL_VERTEX_SHADER , vertexHeader + vertexShader );
|
|
433 |
final int fragmentShaderHandle = compileShader(GLES30.GL_FRAGMENT_SHADER, fragmentHeader + fragmentShader);
|
|
469 |
final int vertexShaderHandle = compileShader(GLES30.GL_VERTEX_SHADER , vertex ); |
|
470 |
final int fragmentShaderHandle = compileShader(GLES30.GL_FRAGMENT_SHADER, fragment); |
|
434 | 471 |
|
435 |
mProgramHandle = createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, mAttributeName, glslVersion>= 300 ? feedback:null );
|
|
472 |
mProgramHandle = createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle, mAttributeName, null ); |
|
436 | 473 |
|
437 | 474 |
mAttribute = new int[mNumAttributes]; |
438 | 475 |
|
... | ... | |
454 | 491 |
else mUniform = null; |
455 | 492 |
} |
456 | 493 |
|
457 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
458 |
// PUBLIC API |
|
459 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
460 |
/** |
|
461 |
* Create a new Shader Program from source stored in resource files. |
|
462 |
* <p> |
|
463 |
* Needs to be called from a thread holding the OpenGL context. |
|
464 |
* |
|
465 |
* @param vertex InputStream containing the opened Resource file from where to read vertex shader code. |
|
466 |
* @param fragment InputStream containing the opened Resource file from where to read fragment shader code. |
|
467 |
* @throws FragmentCompilationException |
|
468 |
* @throws VertexCompilationException |
|
469 |
* @throws VertexUniformsException |
|
470 |
* @throws FragmentUniformsException |
|
471 |
* @throws LinkingException |
|
472 |
*/ |
|
473 |
|
|
474 |
public DistortedProgram(final InputStream vertex, final InputStream fragment, final String vertexHeader, final String fragmentHeader, int glslVersion ) |
|
475 |
throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException |
|
476 |
{ |
|
477 |
this(vertex,fragment,vertexHeader,fragmentHeader,glslVersion,null); |
|
478 |
} |
|
479 |
|
|
480 | 494 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
481 | 495 |
/** |
482 | 496 |
* Return the handle of the created program so that we can later, say, call glUseProgram. |
Also available in: Unified diff
Javadoc.