Skip to main content

GlFramebuffer

Struct GlFramebuffer 

Source
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.

§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.

Source

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, or None for a color-only target.
§Returns
  • Option<GlFramebuffer> - The assembled framebuffer, or None when the driver refused to allocate one of its parts.
Source

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.
Source

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 - true when the attachments already match.
Source

pub fn delete(&mut self, context: &WebGl2RenderingContext)

Releases the framebuffer and its depth renderbuffer.

The color texture is deliberately left alone: it is a GlTexture the caller also owns, and a render target whose contents are about to be sampled must outlive its framebuffer.

§Arguments
  • &WebGl2RenderingContext - The context to release against.
Source§

impl GlFramebuffer

Source

pub fn get_framebuffer(&self) -> &WebGlFramebuffer

Source

pub fn get_mut_framebuffer(&mut self) -> &mut WebGlFramebuffer

Source

pub fn set_framebuffer(&mut self, val: WebGlFramebuffer) -> &mut Self

Source

pub fn get_depth(&self) -> Option<WebGlRenderbuffer>

Source

pub fn try_get_depth(&self) -> Option<WebGlRenderbuffer>

Source

pub fn get_mut_depth(&mut self) -> &mut Option<WebGlRenderbuffer>

Source

pub fn set_depth(&mut self, val: Option<WebGlRenderbuffer>) -> &mut Self

Source

pub fn get_color(&self) -> GlTexture

Source

pub fn get_mut_color(&mut self) -> &mut GlTexture

Source

pub fn set_color(&mut self, val: GlTexture) -> &mut Self

Source

pub fn get_width(&self) -> u32

Source

pub fn get_mut_width(&mut self) -> &mut u32

Source

pub fn set_width(&mut self, val: u32) -> &mut Self

Source

pub fn get_height(&self) -> u32

Source

pub fn get_mut_height(&mut self) -> &mut u32

Source

pub fn set_height(&mut self, val: u32) -> &mut Self

Trait Implementations§

Source§

impl Clone for GlFramebuffer

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GlFramebuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more