Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
740 views
in Technique[技术] by (71.8m points)

android - Converting from GLSurfaceView to TextureView (via GLTextureView)

When Android 4.0 (Ice Cream Sandwich) was released, a new view was introduced into the sdk. This View is the TextureView. In the documentation, it says that the TextureView can be used to display content for an OpenGL scene.

When you look up how to do this, you'll find this link to one example.

https://groups.google.com/forum/?fromgroups=#!topic/android-developers/U5RXFGpAHPE

However I wanted to just replace GLSurfaceView with TextureView, and keep the rest of my code the same, and just receive the advantages of the TextureView.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Answer:

1) Start with the source code of the GLSurfaceView, name the file GLTextureView.java

2) Change the header to: GLTextureView extends TextureView implements SurfaceTextureListener

3) Rename constructors to GLTextureView. Remove code from init() method.

4) Organize imports. Always choose the non-GLSurfaceView option.

5) Find every instance of SurfaceHolder and change it to a SurfaceTexture

6) Add Unimplemented methods for the SurfaceTextureListener, each method should be as follows:

  • onSurfaceTextureAvailable - surfaceCreated(surface)
  • onSurfaceTextureDestroyed - surfaceDestroyed(surface), (return true)
  • onSurfaceTextureSizeChanged - surfaceChanged(surface, 0, width, height)
  • onSurfaceTextureUpdated - requestRender()

7) There should be one line where there is a call being made to getHolder(), change that to getSurfaceTexture()

8) In the init() method, put the following line setSurfaceTextureListener(this)

Then add an OnLayoutChangeListener and have it call surfaceChanged(getSurfaceTexture(), 0, right - left, bottom - top).

With that you should be able to replace your GLSurfaceView code with GLTextureView and receive the benefits of GLTextureView. Also make sure your app supports Hardware Acceleration and that your Renderer extends GLTextureView.Renderer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...