Whats the correct way to handle OpenGL Extensions in Shader Source
Posted by Pete on Mar 18, 2016; 11:29am
URL: https://forum.jogamp.org/Whats-the-correct-way-to-handle-OpenGL-Extensions-in-Shader-Source-tp4036517.html
Hello again,
I've got a fragment shader which declares an extension at the top of the file and I'm having trouble loading it.
Fragment shader:
#extension GL_OES_EGL_image_external : require
uniform samplerExternalOES texture;
uniform ..
etc
And I load it in like so:
.. load vertex shader code ..
ShaderCode fragmentCode = ShaderCode.create( gl, GL2ES2.GL_FRAGMENT_SHADER, gl.getClass(), "/", null, filepath, true );
fragmentCode.defaultShaderCustomization( gl, false, true );
new ShaderProgram .. add code .. link & check status
When calling ShaderProgram.link I get the following exception:
(18373): Shader status invalid: 0:6: P0001: Extension directive must occur before any non-preprocessor tokens
(18373): 0:8: L0001: Typename expected, found 'samplerExternalOES'
(18373): exception encountered processing task on thread 'pool-1-thread-3'
(18373): com.jogamp.opengl.GLException: Error Linking Program: ShaderProgram[id=4, linked=false, inUse=false, program: 10,
(18373): ShaderCode[id=8, type=FRAGMENT_SHADER, valid=false, shader: 11, source]
(18373): ShaderCode[id=7, type=VERTEX_SHADER, valid=false, shader: 0, source]]
So it looks to me as if calling fragmentCode.defaultShaderCustomization( gl, false, true ); has meant that the extension definition is no longer at the top of the source code, and throws the compilation.
This particular fragment shader is only loaded on an Android device. I need to add default shader precision for Android to be happy, but most of my linux machines don't want it so I add it here dynamically if I find the device requires it.
How should I handle my extension definition in my fragment source to avoid this? Have I gone about this incorrectly?
Thanks for your time.