Hello,
i’ve tried using the multiple GL_COLOR_ATTACHMENT in the FBO to render more than 1 texture at once (as in an MRT) but using shader version 120.
my questions are:
does it work with this version? if so how?
I’m currently using the following:
- Create 2 FBOs:
- multisampledFBO
- finalFBO (2 render buffers)
glBindFramebuffer(GL_FRAMEBUFFER, multisampledFbo);
glBindRenderbuffer(GL_RENDERBUFFER, color1RenderBuffer);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_RGBA8, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color1RenderBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, color1RenderBuffer);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_RGBA8, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_RENDERBUFFER, color2RenderBuffer);
// ATTACH TEXTURE 1
glBindFramebuffer(GL_FRAMEBUFFER, finalFbo);
glBindTexture(GL_TEXTURE_2D, textureColor);
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_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (ByteBuffer) null);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureColor, 0);
// ATTACH TEXTURE 2
glBindFramebuffer(GL_FRAMEBUFFER, finalFbo);
glBindTexture(GL_TEXTURE_2D, textureDepth);
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_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (ByteBuffer) null);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textureDepth, 0);
- Render all objects to a multisampledFBO using the frag shader #1:
varying out vec4 outColor1;
varying out vec4 outColor2;
void main (void){
...
outColor1 = vec4(1.0, 0.0, 0.0, 1.0);
outColor2 = vec4(1.0, 1.0, 0.0, 1.0);
}
- Copy multisampledFBO to a FinalFBO
glBindFramebuffer(GL_READ_FRAMEBUFFER, multisampledFbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, finalFbo);
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
- And then render everything to a quad using the frag shader #2:
uniform sampler2D texture1;
uniform sampler2D texture2;
void main (void){
vec4 color1 = texture2D(texture1, vTex);
vec4 color2 = texture2D(texture1, vTex);
gl_FragColor = color1; //This works fine
gl_FragColor = color2; //This renders out black
}
so I’m assuming I can’t render more than 1 output color channel in the shader #1.
or is there anything I am missing?
regards,
Jakes