OpenGL FrameBuffer Object 201
MRT with FBO and GLSLAt this point if we were to render it using the standard Fixed Function Pipeline (as the examples have used thus far) then both textures would get the same data in them, however using GLSL we can write a fragment shader which allows us to send different data to the textures. Normally when you write a GLSL fragment shader you would output the colour value to gl_FragColor, which would then be written to the frame buffer as normal. However there is a second way to write out colour information via the gl_FragData[] array. This special variable allows us to direct where the data is going and maps directly to the values given to glDrawBuffers(). So, in the case of the glDrawBuffers() call above the buffers would map as follows: If we were to change the above function call however the mappings would change: GLenum buffers[] = { GL_COLOR_ATTACHMENT1_EXT, GL_COLOR_ATTACHMENT0_EXT }; glDrawBuffers(2, buffers); This is highlighted because it is the order the values are supplied to the glDrawBuffers() function, which dictates how they map to the gl_FragData[] array, not their values. Lets say that for some reason we wanted to write green to one render target and blue to the other, then the GLSL code would look as follows: #version 110 void main() { gl_FragData[0] = vec4(0.0, 1.0, 0.0); gl_FragData[1] = vec4(0.0, 0.0, 1.0); } The first line says we need at least version 1.10 (OGL2.0) of the GLSL and the function body just writes green to the first buffer and blue to the second buffer. |