2014-07-20 35 views
0

這是我的代碼來創建一個「面」:多重採樣幀緩衝不完整的,我不知道爲什麼

private void Create(int width, int height, SurfaceFormat format) 
{ 
    bool multisample = format.Multisample > 1; 
    if (multisample) 
     GL.Enable(EnableCap.Multisample); 
    int samples = Math.Max(1, Math.Min(format.Multisample, 4)); 
    TextureTarget target = multisample ? TextureTarget.Texture2DMultisample : TextureTarget.Texture2D; 
    Width = width; 
    Height = height; 
    textureHandle = GL.GenTexture(); 
    //bind texture 

    GL.BindTexture(target, textureHandle); 
    Log.Error("Bound Texture: " + GL.GetError()); 
    if (!multisample) 
    { 
     GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); 
     GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); 
     GL.TexParameter(target, TextureParameterName.TextureWrapS, (int)format.WrapMode); 
     GL.TexParameter(target, TextureParameterName.TextureWrapT, (int)format.WrapMode); 
    } 

    Log.Debug("Created Texture Parameters: " + GL.GetError()); 
    if (format.Multisample < 2) 
     GL.TexImage2D(target, 0, format.InternalFormat, Width, Height, 0, format.PixelFormat, format.SourceType, format.Pixels); 
    else 
     GL.TexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, samples, format.InternalFormat, Width, Height, false); 
    Log.Debug("Created Image: " + GL.GetError()); 
    //unbind texture 
    GL.BindTexture(target, 0); 
    //create depthbuffer 
    if (format.DepthBuffer) 
    { 
     GL.GenRenderbuffers(1, out dbHandle); 
     GL.BindRenderbuffer(RenderbufferTarget.RenderbufferExt, dbHandle); 

     if(multisample) 
      GL.RenderbufferStorageMultisample(RenderbufferTarget.RenderbufferExt, samples, RenderbufferStorage.Rgba8, Width, Height); 
     else 
      GL.RenderbufferStorage(RenderbufferTarget.RenderbufferExt, RenderbufferStorage.DepthComponent24, Width, Height); 
    } 

    //create fbo 
    fboHandle = GL.GenFramebuffer(); 
    GL.BindFramebuffer(FramebufferTarget.FramebufferExt, fboHandle); 
    GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, target, textureHandle, 0); 

    if(format.DepthBuffer) 
     GL.FramebufferRenderbuffer(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, RenderbufferTarget.RenderbufferExt, dbHandle); 
    Log.Debug("Framebuffer status: " + GL.CheckFramebufferStatus(FramebufferTarget.FramebufferExt)); 
    Log.Debug("Created Framebuffer: " + GL.GetError()); 
    GL.BindFramebuffer(FramebufferTarget.FramebufferExt, 0); 

} 

現在,每當我用多重採樣大於1,我會得到一個錯誤:

[LOG]: Created Texture Parameters: NoError
[LOG]: Created Image: NoError
[LOG]: Framebuffer status: FramebufferIncompleteAttachment

當MS小於2,一切正常......

+0

對不起,我沒有看到您的編輯。儘管如此,您提出的解決方案並沒有擺脫「FramebufferIncompleteAttachment」錯誤:/ – pixartist

回答

2

您使用的是無效的格式爲您的渲染在這裏:

GL.RenderbufferStorageMultisample(RenderbufferTarget.RenderbufferExt, samples, 
     RenderbufferStorage.Rgba8, Width, Height); 

您稍後嘗試使用此緩衝區作爲深度附件。 GL_RGBA8不是深度附件的有效格式。常用的深度附件格式爲GL_DEPTH_COMPONENT16GL_DEPTH_COMPONENT24。所以電話應改爲:

GL.RenderbufferStorageMultisample(RenderbufferTarget.RenderbufferExt, samples, 
     RenderbufferStorage.DepthComponent24, Width, Height); 
相關問題