Results 1 to 7 of 7

Thread: Copy FBO to another texture? Or similar?

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2009
    Posts
    7

    Copy FBO to another texture? Or similar?

    Hi

    I need to use the FBO destination texture as a source texture for the next frame, how can I do this most efficiently? (Without reuploading the texture between CPU ad GpU every frame)

    I'm trying to implement destroyable 2d pixel terrain.
    The first frame I render the original background texture to FBO and then draw all the deformations using primitives with alpha value set to 0. It works - holes appear in the result.
    The second frame, I have to use the texture generated in the FBO last frame, as the source texture for this frame. If I used the original background texture again, my changes would be lost.

    Any help would be appreciated

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Copy FBO to another texture? Or similar?

    Sounds like standard render to texture :
    http://www.opengl.org/wiki/GL_EXT_framebuffer_object

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2009
    Posts
    7

    Re: Copy FBO to another texture? Or similar?

    I know how to render to a texture using FBO, it's working just fine.

    What I don't understand, is how to assign the destination texture of the FBO as it's source texture.

    Steps:
    First frame: Select the FBO, Draw ORIGINAL texture, Draw holes, Draw the FBO texture to screen
    Second frame: Select the FBO, Draw (first frames's)FBO texture, Draw even more holes, Draw the FBO texture to screen.
    Third frame: Select the FBO, Draw (second frames's)FBO texture, Draw some more holes, Draw the FBO texture to screen

    If I try to Draw the FBO render-target texture, while the FBO is rendering to that same texture, I get white screen.

    I need to buffer the texture, so that there are 2 copies, and no "access violation" while I do the FBO render-to-texture operation.

    Please help

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,650

    Re: Copy FBO to another texture? Or similar?

    Quote Originally Posted by gq3gq3
    I know how to render to a texture using FBO, it's working just fine.

    What I don't understand, is how to assign the destination texture of the FBO as it's source texture.
    Bind texture to a sampler/texture unit, and reference the sampler in a shader.

    I need to buffer the texture, so that there are 2 copies, and no "access violation" while I do the FBO render-to-texture operation.
    Yes. Sounds like you'll want two textures (or two layers of a texture array) to ping-ping with.

  5. #5
    Senior Member Regular Contributor DmitryM's Avatar
    Join Date
    Mar 2009
    Location
    Toronto
    Posts
    435

    Re: Copy FBO to another texture? Or similar?

    Consider applying your deformations (holes) to the original texture directly: by rendering them (optionally with some sort of blending) into it. This will not require 2 buffers to keep.

  6. #6
    Junior Member Newbie
    Join Date
    Nov 2009
    Posts
    7

    Re: Copy FBO to another texture? Or similar?


    Yes. Sounds like you'll want two textures (or two layers of a texture array) to ping-ping with.
    Could you please specify what do mean by that? Especially the ping part =)

    Quote Originally Posted by DmitryM
    Consider applying your deformations (holes) to the original texture directly: by rendering them (optionally with some sort of blending) into it. This will not require 2 buffers to keep.
    Yes, that would be perfect, but how can I render to an already existing texture? I can't use FBO for that, because can't render a texture while it's bound to FBO, right?

  7. #7
    Senior Member Regular Contributor DmitryM's Avatar
    Join Date
    Mar 2009
    Location
    Toronto
    Posts
    435

    Re: Copy FBO to another texture? Or similar?

    Could you please specify what do mean by that? Especially the ping part =)
    Have 2 textures A and B.
    First frame: A->B, using B.
    Second frame: B->A, using A.
    and so on

    Yes, that would be perfect, but how can I render to an already existing texture? I can't use FBO for that, because can't render a texture while it's bound to FBO, right?
    You can't draw to the texture and use it at the same time.
    But if you draw holes - you might not need original texture at all.
    Just try to play with different blending functions.

Similar Threads

  1. Replies: 1
    Last Post: 11-28-2018, 02:46 AM
  2. Replies: 2
    Last Post: 04-24-2014, 01:52 AM
  3. OpenGL 4.2, How to Copy a color texture into a depth texture ?
    By imported_cippyboy in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 08-26-2013, 01:17 AM
  4. texture to texture copy, running through a shader?
    By zassGL in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 07-20-2011, 03:04 PM
  5. How to copy directly one texture to another
    By pashamol in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 02-07-2004, 06:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean