android - Change GlSurfaceView renderer -
i looked on net in order find out if possible change renderer of glsurfaceview on flight. reason want change opengl program, , initiate attributes , unified params vertex , fragment shader , don't want change require create brand new glsurfaceview brand new renderer.
it seems reasonable operation should doable.
note: haven't implemented following.
glsurfaceview.renderer
interface. implement 3 times. twice different opengl renderers, , 1 time attached glsurfaceview
. latter dispatches 1 of former, , allows change renderer dispatches. code must hold reference renderer, , must synchronized draw calls (though don't know).
be aware cannot switch opengles context data. shared between renderer instances.
class dispatchingrenderer implements glsurfaceview.renderer { private class renderer1 implements glsurfaceview.renderer { ... } private class renderer2 implements glsurfaceview.renderer { ... } public dispatchingrenderer() { this.r1 = new renderer1(); this.r2 = new renderer2(); this.currentrenderer = this.r1; } public void togglerenderer() { if(this.currentrenderer == this.r1) { this.currentrenderer = this.r2; } else if (this.currentrenderer == this.r2) { this.currentrenderer = this.r1; } } public void onsurfacecreated(gl10 gl, eglconfig config) { // one-time setup } public void onsurfacechanged(gl10 gl, int w, int h) { this.currentrenderer.onsurfacechanged(gl, w, h); } public void ondrawframe(gl10 gl) { this.currentrenderer.ondrawframe(gl); } }
Comments
Post a Comment