gpt4 book ai didi

opengl - 尝试创建多重采样帧缓冲区时获取 FramebufferIncompleteMultisample

转载 作者:行者123 更新时间:2023-12-02 22:02:58 26 4
gpt4 key购买 nike

我使用以下代码创建纹理+帧缓冲区(在C#中使用openTK):

    public void Create(int width, int height, SurfaceFormat format)
{
bool multisample = format.Multisample > 1;
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());
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.Error("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.Error("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.Depth24Stencil8, 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.Error("Created Framebuffer: " + GL.GetError());
GL.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
}

我收到以下错误:

[ERROR]: Created Texture Parameters: InvalidEnum

[LOG]: Framebuffer status: FramebufferIncompleteMultisample

当我尝试使用多重采样创建表面时 (2)

有什么想法出了什么问题吗?该代码适用于 ms < 2 的 find。

最佳答案

触发 GL_INVALID_ENUM 错误是因为 GL_TEXTURE_2D_MULTISAMPLE 作为 TexParameter() 调用的第一个参数无效。

多重采样纹理只能在着色器中使用texelFetch()函数访问。它们不支持 mipmap、线性采样或任何其他采样属性。因此,GL_TEXTURE_2D_MULTISAMPLE 不是 glTexParameteri() 的有效目标。

关于GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE错误,这很可能是由此调用的最后一个参数引起的:

GL.TexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, samples,
format.InternalFormat, Width, Height, false);

最后一个参数是fixedsamplelocations,因此调用会禁用固定样本位置。

OpenGL 规范的帧缓冲区完整性部分包括以下错误情况:

The value of TEXTURE_FIXED_SAMPLE_LOCATIONS is the same for all attached textures; and, if the attached images are a mix of renderbuffers and textures, the value of TEXTURE_FIXED_SAMPLE_LOCATIONS must be TRUE for all attached textures. {FRAMEBUFFER_INCOMPLETE_MULTISAMPLE}

这正是你的情况。 FBO 的附件是纹理和渲染缓冲区的混合体。为了避免此错误,纹理必须使用固定的样本位置。这是通过将上面调用中的最后一个参数更改为 true 来完成的:

GL.TexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, samples,
format.InternalFormat, Width, Height, true);

关于opengl - 尝试创建多重采样帧缓冲区时获取 FramebufferIncompleteMultisample,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24727866/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com