在相机之上的 OpenGL 视图的替代方法

发布于 2024-10-11 00:48:04 字数 679 浏览 0 评论 0原文

在前面使用 OpenGL 制作相机预览背景的传统方法是采用两个 SurfaceView(一个用于相机,另一个用于 OpenGL)并将它们堆叠在一起。 问题是不鼓励堆叠 SurfaceView:

http://groups.google。 com/group/android-developers/browse_thread/thread/4850fe5c314a3dc6

那么还有什么替代方案呢?我正在考虑以下内容:

  1. 子类 GlSurfaceView,然后调用将相机预览设置到该子类的持有者上:Camera.setPreviewDisplay(mHolder);
  2. 不要使用 GLSurfaceView,而是创建您自己的 SurfaceView 子类,在其中将相机预览显示到支架上并绘制 openGL。这需要使用没有 GLSurfaceView 的 OpenGL,以前有人这样做过吗?

我不确定这是否可能或有意义,因为它意味着将相机预览显示到表面的支架上,同时在同一表面上绘制 OpenGL。 是否有其他明智的替代方案可以在不使用两个 SurfaceView 的情况下解决问题?

谢谢!

the traditional way of doing a camera preview background with OpenGL on the front is to take two SurfaceViews(one for the camera another for OpenGL) and stack them on top of each other.
The problem is that stacking SurfaceViews is discouraged:

http://groups.google.com/group/android-developers/browse_thread/thread/4850fe5c314a3dc6

So what alternatives are there? I was considering the following:

  1. Subclass GlSurfaceView, and then call set the Camera preview onto the holder of this subclass: Camera.setPreviewDisplay(mHolder);
  2. Don't use GLSurfaceView, instead create your own SurfaceView subclass where you display the Camera preview onto the holder and also draw your openGL. This would require to use OpenGL without GLSurfaceView, has anyone done this before?

I'm not sure if this even is possible or makes sense, since it implies displaying the camera preview onto the holder of the surface and at the same time drawing OpenGL on the same surface.
Is there any other sensible alternative to solving the problem without using two SurfaceViews?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

灵芸 2024-10-18 00:48:04

您可以将相机绘制到屏幕外的画布上,然后将其渲染为 opengl 中的纹理。我使用 Google 地图执行此操作,不确定相机 API 是否也可以执行此操作。

对于相机来说可能不太合理,因为绑定纹理会产生很大的开销,而且我很少这样做,每秒调用 20-30 次绑定纹理以使相机平滑,这使得堆叠表面视图听起来是一个非常好的主意。

编辑:您可以在没有 GlSurfaceView 的情况下使用 GL,但您需要使用 EGL 并手动管理曲面。

You could draw the Camera to a offscreen canvas possibly, and then render it as a texture in opengl. I do this with Google Maps, not sure if the Camera API can also do this.

Might not be as reasonable for Camera as binding the texture is a lot of overhead, and I do it rarely, having a bindtexture call 20-30 times a second to make the camera smooth makes stacking surface views sound like a very good idea.

Edit: You can use GL without GlSurfaceView, but you'll need to use EGL and manage the surfaces manually.

白日梦 2024-10-18 00:48:04

我的建议:将所有内容绘制到一个 OpenGL 表面中。 OpenGL 不是场景图,因此您不受分层中某种拓扑的限制。归根结底,就是

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
draw_bottom_layer();

glClear(GL_DEPTH_BUFFER_BIT | stencil_used_as_mask ? GL_STENCIL_BUFFER_BIT : 0 );
draw_mid_layer();

glClear(GL_DEPTH_BUFFER_BIT | stencil_used_as_mask ? GL_STENCIL_BUFFER_BIT : 0 );
draw_top_layer();

忘记“初始化”OpenGL 的投影、视口和诸如此类的东西。只要您认为合适,就可以设置它们,例如在每个draw_*_layer()函数的开头。

My suggestion: Just draw everything into a single OpenGL surface. OpenGL is not a scene graph, so you're not bounded by some kind of topology in the layering. It boils down to

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
draw_bottom_layer();

glClear(GL_DEPTH_BUFFER_BIT | stencil_used_as_mask ? GL_STENCIL_BUFFER_BIT : 0 );
draw_mid_layer();

glClear(GL_DEPTH_BUFFER_BIT | stencil_used_as_mask ? GL_STENCIL_BUFFER_BIT : 0 );
draw_top_layer();

Forget about "initializing" OpenGL's projection, viewport and that stuff. Just set those whenever you see it fit, like at the beginning of each of those draw_*_layer() functions.

金兰素衣 2024-10-18 00:48:04

我还没有使用过它,所以我对它了解不多,但你可能会发现 SurfaceTexture 很有用。

I haven't used it yet, so I don't know much about it, but you might find SurfaceTexture useful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文