Rendering Static and Dynamic Graphics OpenGL

坚强是说给别人听的谎言 提交于 2019-12-04 19:42:27

It should be possible. The most straightforward approach is that you render your static elements to an FBO once. Then on each redraw, copy the content of the static FBO to your default framebuffer, and then draw the dynamic elements on top of it.

The feature set of ES 2.0 is kind of borderline to support this. For example, you don't have glBlitFramebuffer(), which would be a convenient way to copy the FBO content to the default framebuffer. But you can do the copy with a simple shader program that feeds through the coordinates in the vertex shader, and only uses a texture sample operation in the fragment shader. Then bind the texture you rendered the static content to, and draw a screen sized quad.

It gets more tricky if your dynamic rendering needs the depth buffer from the static rendering. That would for example be the case if dynamic content is obscured by static content. In that case, you would also need to copy the depth buffer. From quickly refreshing my memory of the specs, I don't see anything that would make this possible in ES 2.0. glBlitFramebuffer() is not there. And it looks like ES 2.0 does not support depth textures. You're entering ES 3.0 territory if you want to go there.

With all of this, you obviously want to make sure that it really helps your performance. Copying the framebuffer is not free. It only pays off if it's cheaper than rendering your static elements. Benchmarking of both approaches is definitely in order before you make a decision.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!