将模板缓冲区可视化为纹理 [英] Visualizing the Stencil Buffer to a texture

查看:134
本文介绍了将模板缓冲区可视化为纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将模板缓冲区放入纹理中,以便在延迟渲染器中使用.

I'm trying to put the stencil buffer into a texture for use in a deferred renderer.

我正在使用glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[color1], 0);获取其他颜色和深度附件,结果是正确的.

I'm getting other Color and Depth Attachments with glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[color1], 0); and the result is correct.

但是,当我尝试使用 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT ,GL_TEXTURE_2D, textures[stencil], 0);将模板缓冲区附加到纹理时,会得到乱码,好像FBO没有清除其缓冲区一样.

However when I try to attach my stencil buffer to a texture with glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT ,GL_TEXTURE_2D, textures[stencil], 0); I get a garbled result, as if the FBO isn't clearing its buffers.

我不知道问题是什么.我怀疑这是设置模具纹理的问题...

I don't know what the problem is. My suspicion is that it is an issue with setting up the stencil texture ...

//Stencil Texture Initialization

glBindTexture(GL_TEXTURE_2D, textures[stencil]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

glTexImage2D( GL_TEXTURE_2D, 0, GL_STENCIL_INDEX8, 512, 512, 0, GL_STENCIL_INDEX, GL_BYTE, 0);

我的安装程序中没有任何错误代码,所以我不知道是什么问题.

I don't get any error codes in my setup so I am at a loss of what the issue is.

也许我没有正确执行此操作.如果有人知道如何将模板缓冲区写入纹理,那么我真的不在乎是否编写不同的鳕鱼.我只需要一种有效的方法.

Maybe I'm not doing this correctly. If anyone knows how to write the stencil buffer to a texture, I don't really care if I write different cod. I just need a method that works.

推荐答案

GL_STENCIL_INDEX8

从不使用此功能.如果需要模板位,请始终使用压缩的深度/模板图像,例如GL_DEPTH24_STENCIL8.您应该将此附加到GL_DEPTH_STENCIL_ATTACHMENT点.

Never use this. If you need stencil bits, always use a packed depth/stencil image, like GL_DEPTH24_STENCIL8. You should attach this to the GL_DEPTH_STENCIL_ATTACHMENT point.

这篇关于将模板缓冲区可视化为纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆