Send Depthbuffer and TextureBuffer to same Fragment OpenGL3

It might be stupid and a trivial question but since i'm kinda new with OpenGL ,I don't understand how to send color buffer and depth buffer coming from a single FBO to the fragment shader.
My FBO is generated with 1 texture buffer and 1 depth buffer

   glGenTextures(1, &texture_color);
   glBindTexture(GL_TEXTURE_2D, texture_color);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);    
   glGenTextures(1, &texture_depth);
   glBindTexture(GL_TEXTURE_2D, texture_depth);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);

and I would like, in my fragment buffer to have

uniform sampler2D colorTexture;
uniform sampler2D depthTexture;

to be filled with both color and depth texture...

I can send just one or the other with GlBindtexture (and it works well), but I don't success to send the 2 at the same time. Does somebody knows how to do it?

Thanks!


Ok, I might not be giant since the solution is easy, and I was just doing wrong.

I was trying to use glActiveTexture(GL_DEPTH) followed by a binding to my Texture : (glBindTexture(GL_TEXTURE_2D, visibilityFBO.getDepthTexture());) thinking it was normal to use GL_DEPTH.

But i was wrong, and it works using :

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, visibilityFBO.getColorTexture()); 
glUniform1i(glGetUniformLocation(visibilityPassShader.Program, "positionTexture"), 0);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, visibilityFBO.getDepthTexture());
glUniform1i(glGetUniformLocation(visibilityPassShader.Program, "depthTexture"), 1);

it's the same as before, but the DEPTH is considerated as a Texture since I used glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); to produce my Depth texture. So I just have to call the next texture and bind it to be able to use it.

In the fragment, it is still :

uniform sampler2D positionTexture;
uniform sampler2D depthTexture;

In the good order.

Using OpenGL >= 4, you can use in the fragment shader

layout (binding = 0) uniform sampler2D positionTexture;
layout (binding = 1) uniform sampler2D depthTexture;

and forgive the part about glUniform1i in the source code.

Hope it can help someone!

链接地址: http://www.djcxy.com/p/6558.html

上一篇: 我如何控制Emacs如何制作备份文件?

下一篇: 将Depthbuffer和TextureBuffer发送到相同的Fragment OpenGL3