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]:创建的纹理参数:NoError
[LOG]:创建的图像:NoError
[LOG]:帧缓冲区状态:FramebufferIncompleteAttachment

当 ms 小于 2 时,一切正常...

4

1 回答 1

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);
于 2014-07-20T19:48:15.493 回答