Converting from GLSurfaceView to TextureView (via GLTextureView)
来源:互联网 发布:js input value 编辑:程序博客网 时间:2024/04/24 07:41
原文地址:
http://stackoverflow.com/questions/12061419/converting-from-glsurfaceview-to-textureview-via-gltextureview
Question:
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.
Answer One:
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
2) Rename constructors to GLTextureView. Remove code from init() method.
3) Organize imports. Always choose the non-GLSurfaceView option.
4) Find every instance of SurfaceHolder and change it to a SurfaceTexture
5) 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()
6) There should be one line where there is a call being made to getHolder(), change that to getSurfaceTexture()
7) 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.
Answer Two:
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.
- Converting from GLSurfaceView to TextureView (via GLTextureView)
- Android-代替GLSurfaceView的GLTextureView
- Converting string to/from integer
- Converting from String^ to BSTR
- Converting from C++ to Object Pascal/Delphi!
- SurfaceView, GLSurfaceView, SurfaceTexture和TextureView
- SurfaceTexture,TextureView, SurfaceView和GLSurfaceView的区别
- SurfaceView,GLSurfaceView,SurfaceTexture,VideoView及TextureView
- Converting a project from a waterfall to an iterative approach
- The convenient way for converting from dec to hex
- Copy file to / from server via SCP command
- Android 5.0(Lollipop)中的SurfaceTexture,TextureView, SurfaceView和GLSurfaceView
- Android 5.0(Lollipop)中的SurfaceTexture,TextureView, SurfaceView和GLSurfaceView
- Android 5.0(Lollipop)中的SurfaceTexture,TextureView, SurfaceView和GLSurfaceView
- Android 5.0(Lollipop)中的SurfaceTexture,TextureView, SurfaceView和GLSurfaceView
- Android 5.0(Lollipop)中的SurfaceTexture,TextureView, SurfaceView和GLSurfaceView
- Android 5.0(Lollipop)中的SurfaceTexture,TextureView, SurfaceView和GLSurfaceView
- Android 5.0(Lollipop)中的SurfaceTexture,TextureView, SurfaceView和GLSurfaceView
- Qt学习之自定义窗口部件
- 无插件ExtJs4简单甘特图
- 多态的成员的特点
- Android事件分发机制完全解析,带你从源码的角度彻底理解(下)
- 安装MOC————TODO
- Converting from GLSurfaceView to TextureView (via GLTextureView)
- __FILE__,__LINE__
- SQL基础之函数浅谈
- 过来人谈《去360还是留在百度?》
- Android手机平板两不误,使用Fragment实现兼容手机和平板的程序
- clob类型
- UVA 208 Firetruck
- js2dx --- 结构体、事件、动作
- 异常中的throw和throws,还有处理格式