Converting from GLSurfaceView to TextureView (via GLTextureView)
2013-08-04 23:18
281 查看
原文地址:
http://stackoverflow.com/questions/12061419/converting-from-glsurfaceview-to-textureview-via-gltextureview
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.
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.
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:
Other than that, I was up and running in about five minutes flat! Thanks.
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.
相关文章推荐
- Passing a list of objects from view to controller via jquery ajax(Json(aspx) -> object(C#))
- 如何封装 opengl 流程 EglHelper GLThread glSurfaceView glTextureView
- Converting a project from VS.NET 2003 to VS.NET 2002
- Unable to get view server protocol version from device
- 【iOS】Illegal Configuration: The Label outlet from the ViewController to the UILabel is invalid. Outl
- Using Android's TextureView to Display Video Mirrored
- Cannot make a static reference to the non-static method setInAnimation(Animation) from the type View
- 全局拉普拉斯平滑之(1)Strucutre extraction from texture via relative total variation及稀疏矩阵求解
- How to show a Detail View via code
- Any gotchas at all with converting from MyISAM to InnoDB?
- How to Transfer Audio Output from Mac OS X to Ubuntu via a Network?
- Camera 预览之SurfaceView、TextureView、GLSurfaceView(二)
- How to upgrade from ESXi 5.x to ESXi 6.0 via CLI
- Android Dev Intro - SurfaceTexture,TextureView, SurfaceView and GLSurfaceView
- smoothScrollToPositionFromTop girdview 有时滚动到指定无效
- GLSurfaceView中GL相关资源销毁问题
- recyclerview的“Error:Error converting bytecode to dex“报错
- You may want to manually restart adb from the Devices view.
- When Not to Create a Thread-come from WINDOWS VIA C C++
- Android重写view时onAttachedToWindow () 和 onDetachedFromWindow ()