如何在 opengl Es 2.0 中部分重绘 [英] How to redraw partially in opengl Es 2.0

查看:24
本文介绍了如何在 opengl Es 2.0 中部分重绘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的需要,我只想为每一帧重绘场景的一部分仅当更新了整个场景的某些部分时才重新绘制整个场景.

As per my need I want to redraw only some part of the scene for each frame instead of redrawing the entire scene only if some portion of it is updated.

有没有办法在 OpenGL ES 2.0 中做到这一点?请对此提出任何意见都会非常有帮助

Is there a way to do that in OpenGL ES 2.0? Please any input on this will be really helpful

推荐答案

OpenGL 并不真正支持增量渲染.每次要求重绘时都需要绘制整个框架.

OpenGL does not really support incremental rendering. You need to draw the entire frame every time you are asked to redraw.

我能想到的最接近的是您使用 FBO(帧缓冲区对象)将静态数据渲染到屏幕外帧缓冲区.如果您寻找诸如OpenGL FBO"之类的关键字,您应该能够在网上和书中找到大量示例.您将使用 glGenFramebuffers()glBindFramebuffer()glFramebufferTexture2D() 等调用.

The closest I can think of is that you render your static data to an offscreen framebuffer, using a FBO (Frame Buffer Object). You should be able to find plenty of examples online and in books if you look for keywords like "OpenGL FBO". You will be using calls like glGenFramebuffers(), glBindFramebuffer(), glFramebufferTexture2D(), etc.

将静态内容渲染到 FBO 后,您可以在每次重绘开始时将其复制到默认帧缓冲区,然后在其上渲染动态内容.如果渲染静态内容非常昂贵,这可能是一种值得的方法.否则,从 FBO 复制到默认帧缓冲区可能比每次简单地重新渲染静态内容的成本更高.

Once you rendered the static content into an FBO, you can copy it to the default framebuffer at the start of each redraw, and then render the dynamic content on top of it. This can be a worthwhile method if rendering the static content is very expensive. Otherwise, doing the copy from FBO to default framebuffer can be more expensive than simply re-rendering the static content each time.

如果静态内容在后台,动态内容完全在前面,上面的就很简单了.如果静态和动态内容重叠,它会变得更加棘手.然后,在开始呈现动态内容之前,您必须每次都恢复由于呈现静态内容而产生的深度缓冲区.我想不出在 ES 2.0 中做到这一点的好方法.相对顺利地执行此操作的功能(深度纹理,glBlitFramebuffer)仅在 ES 3.0 及更高版本中提供.

The above is pretty easy if the static content is in the background, and the dynamic content is completely in front of it. If static and dynamic content overlap, it gets trickier. You will then have to restore the depth buffer resulting from rendering the static content each time before starting to render the dynamic content. I can't think of a good way to do that in ES 2.0. The features to do this relatively smoothly (depth textures, glBlitFramebuffer) are only in ES 3.0 and later.

还有一个我认为不是很吸引人的选项,但为了完整起见,我想提一下它:EGL 定义了一个 EGL_SWAP_BEHAVIOR 属性,该属性可以设置为 EGL_BUFFER_PRESERVED.一个重要的警告是它是可选的,并非所有设备都支持.它还只保留颜色缓冲区,而不保留辅助缓冲区,如深度缓冲区.如果您仍然想阅读它,请参阅 eglSwapBufferseglSurfaceAttrib.

There is one other option that I don't think is very appealing, but I wanted to mention it for completeness sake: EGL defines a EGL_SWAP_BEHAVIOR attribute that can be set to EGL_BUFFER_PRESERVED. One big caveat is that it's optional, and not supported on all devices. It also only preserves the color buffer, and not auxiliary buffers, like the depth buffer. If you want to read up on it anyway, see eglSwapBuffers and eglSurfaceAttrib.

这篇关于如何在 opengl Es 2.0 中部分重绘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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