简体   繁体   English

深度纹理作为颜色附件

[英]Depth texture as color attachment

I d'like to attach a depth texture as a color attachment to the framebuffer. 我想将深度纹理作为颜色附件附加到帧缓冲区。 (I'm on iOS and GL_OES_depth_texture is supported) (我在iOS上,并且支持GL_OES_depth_texture)

So I setup a texture like this: 所以我设置了这样的纹理:

glGenTextures(1, &TextureName);
glBindTexture(GL_TEXTURE_2D, TextureName);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, ImageSize.Width, ImageSize.Height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0);


glGenFramebuffers(1, &ColorFrameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, ColorFrameBuffer);

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureName, 0);

But now if I check the framebuffer status I get a GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT 但是现在,如果我检查帧缓冲区状态, GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT得到GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT

What am I doing wrong here? 我在这里做错了什么?

I also tried some combinations with GL_DEPTH_COMPONENT16 , GL_DEPTH_COMPONENT24_OES , GL_DEPTH_COMPONENT32_OES but non of these worked (GL_OES_depth24 is also supported) 我还尝试了一些与GL_DEPTH_COMPONENT16GL_DEPTH_COMPONENT24_OESGL_DEPTH_COMPONENT32_OES组合,但这些组合都不起作用(也支持GL_OES_depth24)

You can't. 你不能 Textures with depth internal formats can only be attached to depth attachments. 具有深度内部格式的纹理只能附加到深度附件。 Textures with color internal formats can only be attached to color attachments. 具有内部颜色格式的纹理只能附加到颜色附件。

As previous answer mentioned, you cannot attach a texture with depth format as a color surface. 如先前的回答所述,您不能将深度格式的纹理附加为彩色表面。 Now looking at your comment, you're really after rendering to a 1-channel float format. 现在查看您的评论,您实际上是在渲染为1通道浮点格式之后。

You could look at http://www.khronos.org/registry/gles/extensions/OES/OES_texture_float.txt which allows you to have a Texture format of float format. 您可以查看http://www.khronos.org/registry/gles/extensions/OES/OES_texture_float.txt ,该文件可让您使用浮点格式的纹理格式。

You can then initialize the texture to be a Alpha map, which would only include 1 channel. 然后,您可以将纹理初始化为仅包含1个通道的Alpha贴图。

glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, ImageSize.Width, ImageSize.Height, 0, GL_ALPHA, GL_FLOAT, 0); glTexImage2D(GL_TEXTURE_2D,0,GL_ALPHA,ImageSize.Width,ImageSize.Height,0,GL_ALPHA,GL_FLOAT,0);

This may or may not work depending on what extensions supported by your device. 根据您的设备支持的扩展名,此方法可能有效也可能无效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM