Basically, this topic is about recompiling shaders.
First, off, jme3’s GLRenderer.updateShaderSourceData:
public void updateShaderSourceData(ShaderSource source) {
int id = source.getId();
if (id == -1) {
...
source.setId(id);
} else { throw new RendererException("Cannot recompile shader source"); }
From this it looks like jme3 currently does not support shader recompilation.
Questions(for anyone who knows):
- Is there a reason why jme3 does not support recompiling shaders?
- Is shader recompilation supported for different graphics cards?
Here is how I currently recompile shaders:
Shader shader = ...//get from material's TechniqueDefLogic.makeCurrent;
int shaderId = shader.getId();
ShaderSource source = ... shader.getSources()[0];
int id = source.getId();
gl.glShaderSource(id, new String[]{ newCode.toString() }, newCodeLength);
gl.glCompileShader(id);
gl.glAttachShader(shaderId, id);
gl.glLinkProgram(shaderId);
for(Uniform u : shader.getUniformMap().values()) u.reset();
This work well for me so far. From https://www.opengl.org/sdk/docs/man/html/glShaderSource.xhtml
glShaderSource sets the source code in shader to the source code in the array of strings specified by string.
Any source code previously stored in the shader object is completely replaced.
This paragraph states that previously stored shader source code gets replaced, from which I assume that shader recompilation could work and it does on my pc.
Thus, if it works, can it be implemented into jme3 at some point?