TextureView与GLSurfaceView或如何使用GLSurfaceView与EGL14 [英] TextureView vs. GLSurfaceView or How to use GLSurfaceView with EGL14

查看:1470
本文介绍了TextureView与GLSurfaceView或如何使用GLSurfaceView与EGL14的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我越来越糊涂与EGL。

我的GLSurfaceView创建一个EGLContext。现在,我创建一个共享的环境。现在,我需要使用EGLExtension。

该方法我必须使用被称为(> = API18):

  EGLExt.egl presentationTimeANDROID(android.opengl.EGLDisplay显示,android.opengl.EGLSurface面,很长一段时间);
 

现在的问题是,该GLSurfaceView不只会造成javax.microedition.khronos.egl.EGLContext秒。

还告诉我,不要使用GLSurfaceView。所以,我想TextureView,略相似,你要处理你自己的EGL的东西的区别。这有利于这一目的。

但是: 该TextureView比较慢,至少它看起来像,所以我记录的方法探查了一些图:

下面的TextureView用自己的EGL处理: 顶部的线程是一个时钟唤醒在中间,这使得上TextureView线程。主线程将被调用后,对于重绘TextureView。

...这里的GLSurfaceView用自己的EGL处理 时钟在中间这段时间,它调用线程的顶部渲染我的形象变成帧缓冲区,这是我给直接进入SurfaceView(RENDERMODE_WHEN_DIRTY)和呼叫requestRender要求视图呈现。

你可以用一个简短的外观已经是看到了GLSurfaceView它看起来更清洁的方式,与TextureView。

在两个实施例I没有带有任何其他在屏幕上,它们呈现完全相同的网格具有相同的着色

要我的问题: 有没有一种方法使用GLSurfaceView与EGL14上下文?

难道我做错了什么?

解决方案

你可能想要做的是使用普通的 SurfaceView

这里的短版:

  • SurfaceView 有两部分,表面和有点假的东西了查看。该表面被直接传递到表面合成器(SurfaceFlinger),所以当你利用它用OpenGL有比较小的开销。这使得它速度快,但也使得它无法播放与景观层次非常正确的,因为表面是一个层和基于视图的UI是在不同的层
  • TextureView 也有两部分,但部分你画上生命幕后(这也正是表面纹理进来)。当帧完成后,您绘制的东西是位图混合到视图层。该GPU可以很快做到这一点,但一些工作永远比不工作的要慢。
  • GLSurfaceView SurfaceView 用做所有EGL设置和线程间的消息传递给你一个包装类

编辑:长版本可以这里

如果你能做到的GL / EGL设置和线程管理自己 - 这,如果你在一个TextureView开始运行,你可以清楚的 - 那么你应该使用一个普通的 SurfaceView

说了这么多,应该有可能使你原来的code与 GLSurfaceView 的工作。我希望你要调用 EGL presentationTimeANDROID()的EGL背景下,同在 GLSurfaceView ,不共享从内部 GLSurfaceView 本身,所以也无所谓了 GLSurfaceView 使用EGL10内部。什么事项共享的上下文是用于配置的上下文的上下文客户端版本(例如GLES2与GLES3),而不是将EGL接口版本

您可以看到这一切的例子 Grafika 工作。特别是:

  • 在显示+捕捉摄像头使用 GLSurfaceView ,摄像机,视频连接codeR。请注意,EGL环境是共享的。这个例子是错综复杂的,有点痛苦的,主要是因为它刻意使用 GLSurfaceView 和一个共享的EGL环境。
  • 在播放视频(TextureView)和基础GL在TextureView节目 TextureView 的行动。
  • 在记录GL应用程序与FBO采用的是普通的 SurfaceView

I am getting confused with EGL.

My GLSurfaceView creates an EGLContext. Now I create a shared context. Now I need to use a EGLExtension.

The Method I have to use is called (>=API18):

EGLExt.eglPresentationTimeANDROID(android.opengl.EGLDisplay display, android.opengl.EGLSurface surface, long time);

The Problem is, that the GLSurfaceView does only creates javax.microedition.khronos.egl.EGLContext s.

Which tells me, NOT to use GLSurfaceView. So I tried TextureView, which is slightly similar, with the difference that you have to handle your own EGL stuff. Which is good for that purpose.

But: The TextureView is slower, at least it looked like that, so I recorded some diagrams with the Method Profiler:

Here the TextureView with own EGL Handling: The Thread on the top is a clock that wakes the Thread in the middle, which renders onto the TextureView. The main Thread will be called after that, for redrawing the TextureView.

... and here the GLSurfaceView with their own EGL Handling The clock is in the middle this time, it calls the Thread on the top to render my image into a framebuffer, which I give directly into the SurfaceView (RENDERMODE_WHEN_DIRTY) and call requestRender to request the view to render.

As you can see with a short look already that with the GLSurfaceView it looks way cleaner that with the TextureView.

On both Examples I havn't had anything else on the screen and they rendered exactly the same Meshes with the same shader.

To my question: Is there a way to use GLSurfaceView with EGL14 Contexts?

Did I do something wrong?

解决方案

What you probably want to do is use a plain SurfaceView.

Here's the short version:

  • SurfaceView has two parts, the Surface and a bit of fake stuff in the View. The Surface gets passed directly to the surface compositor (SurfaceFlinger), so when you draw on it with OpenGL there's relatively little overhead. This makes it fast, but it also makes it not play quite right with the View hierarchy, because the Surface is on one layer and the View-based UI is on a different layer.
  • TextureView also has two parts, but the part you draw on lives behind the scenes (that's where the SurfaceTexture comes in). When the frame is complete, the stuff you drew is blitted onto the View layer. The GPU can do this quickly, but "some work" is always slower than "no work".
  • GLSurfaceView is a SurfaceView with a wrapper class that does all the EGL setup and inter-thread messaging for you.

Edit: the long version is available here.

If you can do the GL/EGL setup and thread management yourself -- which, if you're now running on a TextureView, you clearly can -- then you should probably use a plain SurfaceView.

Having said all that, it should be possible to make your original code work with GLSurfaceView. I expect you want to call eglPresentationTimeANDROID() on the EGL context that's shared with the GLSurfaceView, not from within GLSurfaceView itself, so it doesn't matter that GLSurfaceView is using EGL10 internally. What matters for sharing the context is the context client version (e.g. GLES2 vs. GLES3), not the EGL interface version used to configure the context.

You can see examples of all of this working in Grafika. In particular:

  • "Show + capture camera" uses a GLSurfaceView, the camera, and the video encoder. Note the EGL context is shared. The example is convoluted and somewhat painful, mostly because it's deliberately trying to use GLSurfaceView and a shared EGL context.
  • "Play video (TextureView)" and "Basic GL in TextureView" show TextureView in action.
  • "Record GL app with FBO" uses a plain SurfaceView.

这篇关于TextureView与GLSurfaceView或如何使用GLSurfaceView与EGL14的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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