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

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

问题描述

Android 4.0 (Ice Cream Sandwich) 发布时,在 sdk 中引入了一个新视图.这个 View 就是 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.

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

但是,我只想将 GLSurfaceView 替换为 TextureView,并保持我的其余代码相同,并获得 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的源代码开始,将文件命名为GLTextureView.java

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

2) 将标题更改为:GLTextureView 扩展 TextureView 实现 SurfaceTextureListener

3) 将构造函数重命名为 GLTextureView.从 init() 方法中删除代码.

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

4) 组织导入.始终选择非 GLSurfaceView 选项.

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

5) 找到 SurfaceHolder 的每个实例并将其更改为 SurfaceTexture

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(surface)
  • onSurfaceTextureDestroyed - surfaceDestroyed(surface), (return true)
  • onSurfaceTextureSizeChanged - surfaceChanged(surface, 0, width, height)
  • 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(this)

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

然后添加一个 OnLayoutChangeListener 并让它调用 surfaceChanged(getSurfaceTexture(), 0, right - left, bottom - top).

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

这样,您应该能够将您的 GLSurfaceView 代码替换为 GLTextureView 并获得 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天全站免登陆