Reputation: 540
I've seen that you can render stuff to a texture using OpenGL's FBOs - that is, setting a new Texture2D to GL_COLORATTACHMENT0
. However, doesn't that mean that i would need to explicitly render to this color attachment with out (location=0)
in the shader - so anything that i rendered in any other way wouldn't end up in this texture, right? Because i saw it like this on opengl-tutorials tutorial #14:
layout(location = 0) out vec3 color;
If that is true, how can i render e.g. immediate mode to texture, if that is even possible?
Upvotes: 0
Views: 226
Reputation: 45322
You are talking about four different things here: render to texture (RTT), multiple render targets (MRTs), the fixed function pipeline (rendering without shaders) and immediate mode geometry specification (glBegin/glEnd).
These features are all independent of each other in OpenGL. A framebuffer in OpenGL generally can consist of zero, one or more color buffers. And that is not only true for FBOs, but also for the window-system provided framebuffer (FBO 0): In the typical case, that one has 2 color buffers GL_BACK
and GL_FRONT
. There is probably no real use case to set up MRT for rendering into the front and back buffers simultaneously, but it is possible nonetheless. However, when you have an implementation which supports streoscopic pixel formats, you will have the 4 color buffers GL_FRONT_LEFT
, GL_FRONT_RIGHT
, GL_BACK_LEFT
and GL_BACK_RIGHT
(hence the name "quad buffering"), and rendering to left and right via MRT can actually be useful in certain situations.
The layout (location=x)
output qualifiers of the fragment shader do not map to the GL_COLOR_ATTACHMENTx
. Instead, there is another level of indirection wich is explicitely established by the glDrawBuffers()
command, which defines the actual target color buffer / attatchment for each of the color indices. And your shader may write to any (sub)set of the available indices.
If you don't use a shader, color will be written to color index zero, and you can map that to any attachment you like using glDrawBuffer()
. Without a shader, you just cannot use MRT, so there will be only one color value, which is only written to up to one color attachment of an FBO. (This is not completely true for the window-system provided framebuffer, as there are special values like GL_FRONT_AND_BACK
or GL_BACK
which means GL_BACK_LEFT
and GL_BACK_RIGHT
in a stereoscopic context, so you sometimes can write to more than one color buffer without MRT, but that replicates the same value to different bufffers).
Finally, the immediate mode has nothing to do with any of these. If you specify your primitives with glBegin()/glEnd()
or by using Vertex Arrays (client side or VAOs), or use attributeless rendering and generate them somehow directly in the shaders, is completely irrelevant. All what matters is what DrawBuffer(s) you have set up at the time of the draw call.
I hope that you are aware that immediate mode, as well as the fixed-function pipeline, are completely deprecated since almost a decade. Modern core profiles of OpenGL don't support that functionality any more.
Upvotes: 3