Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Reading a texture from multisample back-buffer

  1. #1
    Intern Contributor
    Join Date
    Nov 2010
    Posts
    81

    Reading a texture from multisample back-buffer

    Hi,

    I have a multisample OpenGL viewport (when creating the viewport I ask for a pixel format with multisample to wglChoosePixelFormatARB) and my geometry is displayed antialised.

    Now, I read the backbuffer inside a texture that I later use use for a quick repaint of my scene in some situations.

    The texture is createad with NEAREST min and mag filters and has the same size of the viewport, so no magnification and minification is involved.

    On ATI cards the texture is exactly equal to the scene on screen (so when I use it for the repaint I don't notice any change on screen), but on NVidia cards they are not the same: the lines colors become a bit more intense in the texture.

    What could be the problem and how could I fix it?

    If I use a pixel format without multsampling there's no difference from the image on screen in both ATI and NVidia.

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: Reading a texture from multisample back-buffer

    Perhaps some screen images might help others see your problem?

  3. #3
    Intern Contributor
    Join Date
    Nov 2010
    Posts
    81

    Re: Reading a texture from multisample back-buffer

    This is the screen capture of the rendering of the lines:



    and this is the screen capture of the texture generated reading the back buffer


  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882

    Re: Reading a texture from multisample back-buffer

    Quote Originally Posted by Devdept2
    I have a multisample OpenGL viewport...Now, I read the backbuffer inside a texture that I later use use for a quick repaint of my scene in some situations....but on NVidia cards they are not the same: the lines colors become a bit more intense in the texture.

    What could be the problem and how could I fix it?
    Have noticed this. Seems that the NVidia driver isn't using the same downsample filter as the GPU for the ReadPixels path vs. the SwapBuffer path.

    You could try doing a manual resolve/downsample via glBlitFramebuffer to a single sample texture (which should ideally happen on the GPU), and read back the texels from that. That might produce the desired results.

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

    Re: Reading a texture from multisample back-buffer

    It *looks* like only a difference in gamma-correction.

  6. #6
    Intern Contributor
    Join Date
    Nov 2010
    Posts
    81

    Re: Reading a texture from multisample back-buffer

    I'm currently using

    glCopyTexSubImage2D

    to copy the BackBuffer to texture.

    I'll give it a try using glBlitFramebuffer...

  7. #7
    Intern Contributor
    Join Date
    Nov 2010
    Posts
    81
    Hi,

    I tried to use the glBlitFramebuffer but I still get the difference between the texture and the rendered image on NVidia cards.

    Maybe I'm not using it the right way?

    Here's my code.

    // Draw the scene on the backbuffer
    ...

    //Generate the FBO
    rb = gl.GenRenderbuffersEXT();
    gl.BindRenderbufferEXT(gl.RENDERBUFFER_EXT, rb);
    gl.RenderbufferStorageEXT(gl.RENDERBUFFER_EXT, gl.RGB, width, height);


    rbDepth = gl.GenRenderbuffersEXT();
    gl.BindRenderbufferEXT(gl.RENDERBUFFER_EXT, rbDepth);
    gl.RenderbufferStorageEXT(gl.RENDERBUFFER_EXT, gl.DEPTH_COMPONENT, width, height);


    fbo = gl.GenFramebuffersEXT();

    gl.BindFramebufferEXT(gl.FRAMEBUFFER_EXT, fbo);


    gl.FramebufferRenderbufferEXT(gl.FRAMEBUFFER_EXT, gl.COLOR_ATTACHMENT0_EXT, gl.RENDERBUFFER_EXT, rb);
    gl.FramebufferRenderbufferEXT(gl.FRAMEBUFFER_EXT, gl.DEPTH_ATTACHMENT_EXT, gl.RENDERBUFFER_EXT, rbDepth);

    int status = gl.CheckFramebufferStatusEXT(gl.FRAMEBUFFER_EXT);


    CheckFboStatus(status);

    // Copy the Back Buffer to the FBO
    gl.BindFramebufferEXT(gl.READ_FRAMEBUFFER_EXT, 0); // IS IT RIGHT???????????????
    gl.BindFramebufferEXT(gl.DRAW_FRAMEBUFFER_EXT, fbo);
    gl.BlitFramebufferEXT(0, 0, Width, Height, 0, 0, Width, Height, gl.COLOR_BUFFER_BIT, gl.NEAREST);

    // Read the FBO image in 9 textures (3x3 grid)

    for (int j = 0; j < 3; j++)


    for (int i = 0; i < 3; i++)
    {


    gl.BindTexture(gl.TEXTURE_2D, texName[i + j * 3]);


    // Debug.WriteLine("Grabbing tex " + texName[i + j * 2] + " at " + (texSize * i) + " , " + (texSize * j));
    gl.CopyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, texSize * i, texSize * j, texSize, texSize);
    }
    Last edited by Devdept2; 05-02-2012 at 01:48 AM.

  8. #8
    Intern Contributor
    Join Date
    Nov 2010
    Posts
    81
    Anybody could help, please?

  9. #9
    Advanced Member Frequent Contributor
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    723
    Just a thought,
    why use RenderbufferStorage. Render to an offscreen texture buffer that you can blit any time you like to the back buffer. Now even if there is a difference between AMD and nVidia versions, at least it is consistent on a card whether it is the first render or the "fake" blit.

  10. #10
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882
    Please use \[code\] blocks to mark code.

    Quote Originally Posted by Devdept2 View Post
    Code :
    // Copy the Back Buffer to the FBO
    gl.BindFramebufferEXT(gl.READ_FRAMEBUFFER_EXT, 0);  // IS IT RIGHT???????????????
    gl.BindFramebufferEXT(gl.DRAW_FRAMEBUFFER_EXT, fbo);
    gl.BlitFramebufferEXT(0, 0, Width, Height, 0, 0, Width, Height, gl.COLOR_BUFFER_BIT, gl.NEAREST);
     
    ...
     
    gl.CopyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, texSize * i, texSize * j, texSize, texSize);
    glCopyTexSubImage2D reads from the READ_BUFFER of the READ_FRAMEBUFFER. It doesn't look like you're reading from the framebuffer I think you intended to (see glBindFramebuffer() and glReadBuffer()). Looks like you're copying from the MSAA framebuffer as before here.

    And agree with tonyo_au. Just blit to an FBO bound to a texture. Then you don't need the CopyTexSubImage to get it into another texture.

    Also yes, binding FBO 0 reverts to the system framebuffer. I'm presuming that's the one you've got that's multisampled.

    If you still have issues, you could see if the same happens when rendering to an off-screen MSAA FBO. There may be something about your system framebuffer that's "special".

    I'm assuming you're not using sRGB framebuffers.
    Last edited by Dark Photon; 05-11-2012 at 02:09 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •