Framebuffer Color Texture

To take control over a framebuffer, we must take responsibility for maintaining the image buffers that receive the fragments rendered to it.

One of these images will receive the RGBA color of each fragment. It is an ordinary RGBA texture, and it may have arbitrary framebufferWidth and framebufferHeight.*

gl.bindTexture(gl.TEXTURE_2D, colorTexture)
gl.texImage2D (gl.TEXTURE_2D, 0, gl.RGBA, framebufferWidth, framebufferHeight, 0, gl.RGBA, gl.UNSIGNED_BYTE, null)

By providing a null texture image, we request an empty buffer of the given size. In this circumstance, the gl.UNSIGNED_BYTE external type specification goes unused.

Like any texture, the framebuffer color texture has configurable texture parameters. These parameters do not affect how the buffer receives fragments, but they do affect how those fragments are sampled later. Once set, these settings seldom change, so it makes sense to set them when the texture is created.

gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)

A rendered image of a scene generally does not wrap, so framebuffer color textures are almost always configured to clamp.

gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)

* The maximum size of a render buffer is fairly large, usually 4096 or 8192 pixels square, circa 2015.