开发者

Best way to make incremental updates to a texture? (Render to Texture)

开发者 https://www.devze.com 2023-03-12 01:08 出处:网络
I would like to rende开发者_运维问答r to a texture in OpenGL but make changes to the texture incrementally.

I would like to rende开发者_运维问答r to a texture in OpenGL but make changes to the texture incrementally.

Here's how I imagine the process:

  • Clear Color & glViewport() to texture size
  • Draw original texture (glOrtho or something), how can I copy the original with perfect quality?
  • Draw incremental changes
  • Clear again, set viewport to screen size
  • Draw scene & flip

Is there a more optimal way to do this?


You have two choices. If your hardware doesn't support FBOs, you will have to do like you've written. To draw the original texture, just draw a screen-sized quad with [0,1] texture coordinates. Make sure to use GL_NEAREST as filtering mode and GL_CLAMP_TO_EDGE as wrapping mode, to get an exact copy of the image. Then draw your incremental changes on top of it. When done, you can get the texture from the frame buffer by means of glCopyTexSubImage2D.

When your hardware supports FBOs, you can get much more efficient. In that case, attach the texture to an FBO and render into it. This way you render directly into the texture and there is no need for a copy. You also do not need to copy the original texture, just don't clear the framebuffer (texture), and render right on top of the previous data. Read some introductory material on framebuffer objects for more information.

0

精彩评论

暂无评论...
验证码 换一张
取 消