Module azul_glium::framebuffer

source ·
Expand description

Framebuffers allow you to customize the color, depth and stencil buffers you will draw on.

In order to draw on a texture, use a SimpleFrameBuffer. This framebuffer is compatible with shaders that write to gl_FragColor.

let framebuffer = glium::framebuffer::SimpleFrameBuffer::new(&display, &texture);
// framebuffer.draw(...);    // draws over `texture`

If, however, your shader wants to write to multiple color buffers at once, you must use a MultiOutputFrameBuffer.

let output = [ ("output1", &texture1), ("output2", &texture2) ];
let framebuffer = glium::framebuffer::MultiOutputFrameBuffer::new(&display, output.iter().cloned());
// framebuffer.draw(...);

// example shader:
//
//     out vec4 output1;
//     out vec4 output2;
//
//     void main() {
//         output1 = vec4(0.0, 0.0, 0.5, 1.0);
//         output2 = vec4(1.0, 0.7, 1.0, 1.0);
//     }

Note: depth-stencil attachments are not yet implemented.

A note on restrictions

Some restrictions apply when you use framebuffers:

  • All textures must have an internal format that is renderable. Not all formats are supported.

  • All attachments must have the same number of samples, or must all have multisampling disabled. For example you can’t create a texture with 4x multisampling, another texture with 2x multisampling, and draw on them simultaneously.

  • On old hardware all the framebuffer attachments must have the same dimensions (on more recent hardware the intersection between all the attachments is taken if all attachments don’t have the same dimensions). You can use the is_dimensions_mismatch_supported function to check what the hardware supports.

  • You will get undefined results if you try to sample to a texture mipmap attached to the framebuffer that you are using. This is not enforced by glium as it depends on your shader’s source code.

Empty framebuffers

Modern OpenGL implementations support empty framebuffers. This is handled by glium with the EmptyFrameBuffer struct.

You can check whether they are supported by calling EmptyFrameBuffer::is_supported(&display).

Layered framebuffers

Not yet supported

Structs

A framebuffer which has only one color attachment.
A render buffer is similar to a texture, but is optimized for usage as a draw target.
A render buffer is similar to a texture, but is optimized for usage as a draw target.
A framebuffer with no attachment at all.
This struct is useless for the moment.
A render buffer is similar to a texture, but is optimized for usage as a draw target.
A RenderBuffer of indeterminate type.
A framebuffer which has only one color attachment.
A render buffer is similar to a texture, but is optimized for usage as a draw target.

Enums

Describes an attachment for a color buffer.
One of the color attachments on the default framebuffer.
Describes an attachment for a depth buffer.
Describes an attachment for a depth and stencil buffer.
Error while creating a render buffer.
Describes an attachment for a stencil buffer.
An error that can happen while validating attachments.

Traits

Trait for objects that can be used as color attachments.
Trait for objects that can be used as depth attachments.
Trait for objects that can be used as depth and stencil attachments.
Trait for objects that can be used as stencil attachments.

Functions

Returns true if the backend supports attachments with varying dimensions.