Converting from GLSurfaceView to TextureView (via GLTextureView)

前端 未结 4 1769
感情败类
感情败类 2020-11-30 21:49

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

相关标签:
4条回答
  • 2020-11-30 22:31

    Thanks Mr. Goodale's and Mr. Davies for answers!

    I have some extra about conversion GLSurfaceView to GLTextureView. The first is about render mode. As described there just remove the requestRender() call in onSurfaceTextureUpdated.

    The second is about
    mGLESVersion = SystemProperties.getInt("ro.opengles.version", ConfigurationInfo.GL_ES_VERSION_UNDEFINED); Just use link, but you need Context to do context.getClassLoader(); You can call reflection version of getInt from init() and save result in static field sGLESVersion = getInt(getContext(), "ro.opengles.version",ConfigurationInfo.GL_ES_VERSION_UNDEFINED);

    And the last easiest change is about EGLLogWrapper.getErrorString(error); Just copy getErrorString from EGLLogWrapper sources.

    See the final version of my conversion GLSurfaceView to GLTextureView on GitHub Gist

    0 讨论(0)
  • 2020-11-30 22:31

    If you want to copy/paste a ready-made class, I wrote one here:

    GLTextureView

    You can call setRenderer(GLSurfaceView.Renderer), like with a GLSurfaceView.

    0 讨论(0)
  • 2020-11-30 22:36

    Brilliant!

    A minor addition to Mr. Goodale's brilliant answer:

    The 4.1.1 version of GLSurfaceView seems to have been modified to avoid rendering on a zero-width/height surface, I think. And there doesn't seem to be a gratuitous onSurfaceTextureChanged notification immediately following onSurfaceTextureAvailable.

    If you start with the 4.1.1 sources, onSurfaceTextureAvailable needs to read as follows:

    public void onSurfaceTextureAvailable(SurfaceTexture surface, int width,
            int height) 
    {
        this.surfaceCreated(surface);
        this.surfaceChanged(surface, 0,width,height);
    }
    

    Other than that, I was up and running in about five minutes flat! Thanks.

    0 讨论(0)
  • 2020-11-30 22:53

    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.

    0 讨论(0)
提交回复
热议问题