pub struct GlFramebuffer { /* private fields */ }Expand description
A framebuffer: a color attachment texture plus an optional depth (and stencil) renderbuffer.
The color attachment is always a GlTexture rather than a
renderbuffer, so the result can be sampled by a later pass or read
back without a resolve blit.
Implementations§
Source§impl GlFramebuffer
Implements framebuffer assembly, completeness checking, and
rebinding.
impl GlFramebuffer
Implements framebuffer assembly, completeness checking, and rebinding.
§Performance
The stored dimensions are what make a rebind after a window resize
cheap: a caller can compare the requested size against the stored one
and skip the whole re-assembly when they still agree, so binding a
framebuffer once per frame costs one bindFramebuffer and two integer
comparisons.
Sourcepub fn create(
context: &WebGl2RenderingContext,
width: u32,
height: u32,
color_format: GpuTextureFormat,
depth_format: Option<GpuTextureFormat>,
) -> Option<GlFramebuffer>
pub fn create( context: &WebGl2RenderingContext, width: u32, height: u32, color_format: GpuTextureFormat, depth_format: Option<GpuTextureFormat>, ) -> Option<GlFramebuffer>
Allocates a framebuffer with a color texture and, when depth is
Some, a depth renderbuffer of the same size.
The color attachment is always a GlTexture, never a
renderbuffer, so the rendered result can be sampled by a later
pass or read back without a resolve blit. The depth attachment is
a renderbuffer, which is cheaper than a depth texture and is
correct for a depth buffer that is written and tested but never
sampled.
§Arguments
&WebGl2RenderingContext- The context to allocate against.u32- The width in pixels.u32- The height in pixels.GpuTextureFormat- The color attachment’s format.Option<GpuTextureFormat>- The depth renderbuffer’s format, orNonefor a color-only target.
§Returns
Option<GlFramebuffer>- The assembled framebuffer, orNonewhen the driver refused to allocate one of its parts.
Sourcepub fn bind(&self, context: &WebGl2RenderingContext) -> GlFramebufferStatus
pub fn bind(&self, context: &WebGl2RenderingContext) -> GlFramebufferStatus
Binds the framebuffer as both the draw and read target, and checks that it is complete.
Binding both targets is deliberate: WebGL 2 separates
DRAW_FRAMEBUFFER from READ_FRAMEBUFFER, and a framebuffer
bound to only one of them makes a later readPixels silently
return the default framebuffer’s contents instead. The status
check is what turns a driver-side FRAMEBUFFER_INCOMPLETE_*,
which otherwise shows up as a frame that renders nothing at all,
into a value the caller can react to.
§Arguments
&WebGl2RenderingContext- The context to bind against.
§Returns
GlFramebufferStatus- Whether the framebuffer is renderable.
Sourcepub fn matches(&self, width: u32, height: u32) -> bool
pub fn matches(&self, width: u32, height: u32) -> bool
Reports whether the stored attachments still match width by
height.
The cheap half of a resize check: a caller that compares this
before GlFramebuffer::create can
skip re-allocating every attachment just to rebind an unchanged
render target once per frame.
§Arguments
u32- The width to test against.u32- The height to test against.
§Returns
bool-truewhen the attachments already match.