I use Rajawali in android (3d opengl library).
I am trying to reload material (start to use different shaders dynamicly) - but when I set new material (at runtime) to the object it disappear (after on\off screen by power button this object it appears again with new material).
After setting new material I'm trying to reload objects' attributes (function reload), but it doesn't help (and if i call reload()
on other objects - they dissappear too =) ).
Function reload()
in materials (shaders
class) is:
public void reload() {
setShaders(mUntouchedVertexShader, mUntouchedFragmentShader);
for(int i=0; i<mNumTextures; i++) {
addTexture(mTextureInfoList.get(i), true, true);
}
}
I can't understand why they disappear and why they appear again after restart with new shaders.
The problem is that you're trying to add an object in the middle of a render cycle. When the material tries to create the shader an error is returned.
Work is currently being done to the API to make this more user-friendly. In the meantime you can do something similar to this:
This example is for onTouch() events but it shouldn't be a big effort to rewrite it to suit your needs. Basically you just queue the set shader event until the next render cycle happens.
Not the prettiest solution but it'll do until the next framework update ;-)