开发者

Are GL contexts "significant"?

In Android, a Renderer gets passed a GL10 object in onSurfaceCreated, onSurfaceChanged, and onDraw. Does this actual instance of GL10 really have any specific importance, or can you instantiate any instance of GL10 you want?

The reason I ask is that I have two seemingly contradictory pieces of information I've gleaned from different sources:

  1. I was looking through the source code for gl2-android, which is a set of ES 2.0 bindings. In the example, GL2Test.java, the GL10 instances that are passed are co开发者_JAVA技巧mpletely ignored. The renderer simply instantiates an AndroidGL20 instance and uses that instead.

  2. I've been working with Robert Green's code for OpenGL live wallpapers. In the many comments listed on his introductory blog post, some folks pointed out that occasionally the GL10 context that is passed to onSurfaceCreated changes to a different instance. If this happens, drawing will fail if you do not first reload your textures using the new instance. So the fix is to test at the start of onSurfaceCreated to make sure it's the same GL10 instance and deciding from there whether to reload. (You don't want to reload every time, because onSurfaceCreated gets called with each screen rotation, which must be supported by live wallpapers.)

What I'm trying to do is set up gl2-android for use with a live wallpaper. But I want to be sure I can use it in a manner that's safe from the problem described in number 2 above.


GL Contexts are objects that hold all the information of the current OpenGL instance. Whenever you create a texture, vertex buffer, a surface, a shader or change the state (blend mode, alpha and so forth) all those are stored into the context. Destroying the context will ultimately destroy the objects created within that context and reset the state of OpenGL, in that sense they are very "significant"!

OnSurfaceCreated method is called whenever a new context has been created for the first time or after a destruction of a previous one (due to returning back to the home screen, switching off the display or changing orientation) That's the reason why you will need to re-create/upload all your resources after this, since the previous one has been destroyed with all the resources attached to it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜