简体   繁体   中英

Single Context. Multiple GLSurfaceView and One texture

Is it possible to create only one 3D texture in a surface view and use the same ID across different surfaceviews. Here i am creating the same texture in 3 surface views and taking up thrice the space in memory. Is possible to create a texture common to all these views somwhere and use it across these?

Yes. There are a couple of approaches.

The easiest way is to use the same EGL context for all three SurfaceViews. Use eglMakeCurrent() to change the EGLSurface when you want to draw on a different SurfaceView.

The slightly more awkward way is to use shared EGL contexts, which you configure when the second and subsequent EGL contexts are initially created. Each SurfaceView has a separate context, but they can all see the same textures (and a few other things; see the EGL spec for details).

Which you should use depends on what you need. You can see examples of both approaches in Grafika , though rather than multiple SurfaceViews it's generally using one view and one MediaCodec input surface.

This is much easier to do with plain SurfaceView than GLSurfaceView, because GLSurfaceView handles most of the EGL context housekeeping for you. The "Show + capture camera" activity in Grafika uses shared contexts with GLSurfaceView, but has to jump through a few hoops to get there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM