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 3 123 LastLast
Results 1 to 10 of 21

Thread: glBlitFramebufferEXT and AA set by the Graphics card settings

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

    glBlitFramebufferEXT and AA set by the Graphics card settings

    Hi,

    I have a viewport created with a PixelFormat without multisampling (in theory).

    Code :
     
                pfd = new PixelFormatDescriptor();
     
     
                OperatingSystem osInfo = System.Environment.OSVersion;
     
             pfd.dwFlags   = (int) (pixelFormat.DRAW_TO_WINDOW | pixelFormat.SUPPORT_OPENGL | pixelFormat.DOUBLEBUFFER);
     
     
                    if (osInfo.Version.Major >= 6)
     
     
                        pfd.dwFlags = pfd.dwFlags | (int)pixelFormat.SUPPORT_COMPOSITION;
     
     
                    pfd.PixelType = (int) pixelTypes.TYPE_RGBA;
                    pfd.ColorBits = 24;
                    pfd.AlphaBits = 8;
                    pfd.DepthBits = 24;
     
     
                    nPixelFormat = Windows.ChoosePixelFormat(theHdc, pfd);
     
                    bool valid = Windows.SetPixelFormat(theHdc, nPixelFormat, pfd);
     
                    theHrc = wglCreateContext(theHdc);                    
     
                    wglMakeCurrent(hdc, theHrc);

    I create a Multisample FBO with a number of samples defined by my application

    Code :
     
                rbColor = gl.GenRenderbuffersEXT();
                gl.BindRenderbufferEXT(gl.RENDERBUFFER_EXT, rbColor);
                gl.RenderbufferStorageMultisampleEXT(gl.RENDERBUFFER_EXT, samples, gl.RGB, Width, Height);
     
     
                rbDepth = gl.GenRenderbuffersEXT();
                gl.BindRenderbufferEXT(gl.RENDERBUFFER_EXT, rbDepth);
                gl.RenderbufferStorageMultisampleEXT(gl.RENDERBUFFER_EXT, samples, gl.DEPTH_COMPONENT, Width, Height);
     
     
                fbo = gl.GenFramebuffersEXT();
                FrameBufferObject.Enable(fbo);
                gl.FramebufferRenderbufferEXT(gl.FRAMEBUFFER_EXT, gl.COLOR_ATTACHMENT0_EXT, gl.RENDERBUFFER_EXT, rbColor);
                gl.FramebufferRenderbufferEXT(gl.FRAMEBUFFER_EXT, gl.DEPTH_ATTACHMENT_EXT, gl.RENDERBUFFER_EXT, rbDepth);
     
     
                Status = gl.CheckFramebufferStatusEXT(gl.FRAMEBUFFER_EXT);
     
     
                CheckFboStatus(Status);

    Then I draw my scene on this FBO and I copy it (only the color bits) to the Framebuffer with glBlitFramebufferEXT:

    Code :
                gl.BindFramebufferEXT(gl.READ_FRAMEBUFFER_EXT, fbo);
                gl.BindFramebufferEXT(gl.DRAW_FRAMEBUFFER_EXT, 0);
     
     
                gl.BlitFramebufferEXT(0, 0, width, height, 0, 0, width, height, gl.COLOR_BUFFER_BIT, gl.NEAREST);
     
     
                gl.BindFramebufferEXT(gl.READ_FRAMEBUFFER_EXT, 0);
                gl.BindFramebufferEXT(gl.DRAW_FRAMEBUFFER_EXT, 0);

    Now, if the user overrides the Antialiasing settings on the "Graphics Card Settings" page and sets a number of samples different from the one used by my internal FBO, I get a GL_INVALID_OPERATION after the call to glBlitFramebufferEXT.

    If instead the user sets the number of Samples equal to the one I use internally for the FBO, or if he leaves the Antialiasing settings to "Application Controlled" it works fine.

    My guess is that when the option to override the application settings is set, the Framebuffer is craeted with the number of samples specified by the graphics card settings page and copying between buffers with different samples number gives the error.

    Can anybody help?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    The solution is to detect that the default framebuffer is a multisampled framebuffer. If it is, create your FBO buffers with the same number of samples. That way, you can successfully blit between them.

    First, query `GL_SAMPLE_BUFFERS` (while the default framebuffer is bound); if it's 0, then the default framebuffer is not multisampled. If it's 1, then it is multisampled. To get the number of samples, query `GL_SAMPLES`, then use that count to create your multisampled framebuffer.

  3. #3
    Intern Contributor
    Join Date
    Nov 2010
    Posts
    81
    Yeah that works!
    Thank you very much Alfonse.

  4. #4
    Intern Contributor
    Join Date
    Nov 2010
    Posts
    81
    It seems I was wrong: the copy from my FBO created with the same number of samples as the main framebuffer gives GL_Invalid_Operation.

    I don't know why it seemed to work 2 weeks ago...

    But if I copy from my multisample FBO to a non-multisample FBO and then to the main multisample framebuffer it works.

    Is it really necessary to do this double copy, or should the Blit work directly between the two multisample FBO?

    The documentation for glBlitFrameBuffer reports:

    GL_INVALID_OPERATION is generated if mask contains GL_COLOR_BUFFER_BIT and any of the following conditions hold:
    • The read buffer contains fixed-point or floating-point values and any draw buffer contains neither fixed-point nor floating-point values.
    • The read buffer contains unsigned integer values and any draw buffer does not contain unsigned integer values.
    • The read buffer contains signed integer values and any draw buffer does not contain signed integer values.

    But I don't quite understand it: how do I know what kind of data my buffer contains?

  5. #5
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268
    If SAMPLE_BUFFERS for either the read framebuffer or draw framebuffer is
    greater than zero, no copy is performed and an INVALID_OPERATION error is
    generated if the dimensions of the source and destination rectangles provided to
    BlitFramebuffer are not identical, or if the formats of the read and draw framebuffers
    are not identical.
    This is from the spec, not ext extension, but it applies there as wel iirc. Right now you dont know what is the format of your rbo - use sized internal format.

    But I don't quite understand it: how do I know what kind of data my buffer contains?
    You know that from the format of your attachemnts.

    Also note that GL_RGB (or GL_RGB8 which would likely result from it) is not required renderbuffer format.

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

    the size of the FBO and the Renderbuffer is the same.

    My renderBuffer attached to the FBO is created with internal format GL_RGB.

  7. #7
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268
    Quote Originally Posted by Devdept2 View Post
    My renderBuffer attached to the FBO is created with internal format GL_RGB.
    No its not. RGB is not an internal format. Lots of functions take 'base internal formats' for whatever reason, but driver has to resolve this to actual internal format. (ie RGB can be either RGB8 or RGB16 or whatever)

    Last part of what i quoted is important - _default_ fbo needs to have the same format as yours (and you usually do have alpha component on it).

  8. #8
    Intern Contributor
    Join Date
    Nov 2010
    Posts
    81
    So how do I create a renderBuffer with the same internal format of the framebuffer?

  9. #9
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268
    Quote Originally Posted by Devdept2 View Post
    So how do I create a renderBuffer with the same internal format of the framebuffer?
    Funny thing is - it may not be possible If pixelformat advertises components that are shifted in a way that default framebuffer is BGRA then it cant be done, since GL doesnt expose such internal formats.

    Theory aside, try putting GL_RGBA8 in your renderbuffer storage.

  10. #10
    Intern Contributor
    Join Date
    Nov 2010
    Posts
    81
    I tried but with no success

Posting Permissions

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