Visualizing the Stencil Buffer to a texture

有些话、适合烂在心里 提交于 2019-12-06 08:08:52

问题


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

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.

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.

EDIT: 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.


回答1:


GL_STENCIL_INDEX8

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.



来源:https://stackoverflow.com/questions/13171036/visualizing-the-stencil-buffer-to-a-texture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!