从GLSurfaceView转换为TextureView(通过GLTextureView) [英] Converting from GLSurfaceView to TextureView (via GLTextureView)

查看:3384
本文介绍了从GLSurfaceView转换为TextureView(通过GLTextureView)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在的Andr​​oid 4.0(冰淇淋三明治)发布之后,一个新的观点引入SDK。这种观点的TextureView。在文档中,它说,TextureView可以用来显示一个OpenGL场景内容。

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.

<一个href="https://groups.google.com/forum/?fromgroups=#!topic/android-developers/U5RXFGpAHPE">https://groups.google.com/forum/?fromgroups=#!topic/android-developers/U5RXFGpAHPE

不过,我想只是与TextureView更换GLSurfaceView,并让我的$ C $的其余C型相同,只是收到TextureView的优势。

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)先从GLSurfaceView源$ C ​​$ C,命名该文件GLTextureView.java

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

2)更改为标题: GLTextureView延伸TextureView实现SurfaceTextureListener

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

3)重命名构造函数GLTextureView。从初始化删除code()方法。

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

4)组织进口。始终选择非GLSurfaceView选项。

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

5)求SurfaceHolder的每一个实例,并将其更改为表面纹理

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

6)添加未实现的方法为SurfaceTextureListener,每个方法应该如下:

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

  • onSurfaceTextureAvailable - surfaceCreated(面)
  • onSurfaceTextureDestroyed - surfaceDestroyed(面),(返回true)
  • onSurfaceTextureSizeChanged - surfaceChanged(表面,0,宽度,高度)
  • onSurfaceTextureUpdated - requestRender()

7)应该有一条线,其中有一个叫被做getHolder(),更改为getSurfaceTexture()

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

8)在init()方法,把下面的行 setSurfaceTextureListener(本)

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

然后添加一个 OnLayoutChangeListener ,并将它称之为 surfaceChanged(getSurfaceTexture(),0,右 - 左,下 - 上)

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

使用,你应该能够与 GLTextureView 替换您的GLSurfaceView code和接收 GLTextureView 。另外,请确保您的应用程序支持硬件加速和你的渲染器扩展 GLTextureView .Renderer。

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.

这篇关于从GLSurfaceView转换为TextureView(通过GLTextureView)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆