Skip to main content

Canvas

Struct Canvas 

Source
pub struct Canvas { /* private fields */ }
Expand description

An off-screen render target (framebuffer object) with optional MSAA.

Supports multiple colour attachments, depth/stencil, and MSAA resolve. Created via Canvas::new or GPU::ship_canvas.

§Example

use optic_render::handles::{Canvas, CanvasDesc};

let canvas = Canvas::new(&CanvasDesc::default())?;

Implementations§

Source§

impl Canvas

Source

pub fn new(desc: &CanvasDesc) -> OpticResult<Self>

Creates a new framebuffer from a descriptor.

Validates constraints:

  • At least one colour format or depth must be specified
  • Stencil requires depth
  • depth_compare requires depth_as_texture
Source

pub fn size(&self) -> Size2D

Returns the canvas size.

Source

pub fn color_tex(&self, index: usize) -> OpticResult<&Texture2D>

Returns a reference to the colour texture at the given attachment index.

Source

pub fn depth_tex(&self) -> Option<&Texture2D>

Returns a reference to the depth texture, if present.

Source

pub fn set_size(&mut self, new_size: Size2D) -> OpticResult<()>

Resizes the canvas by recreating the framebuffer with a new size.

Source

pub fn resolve(&self)

Resolves MSAA colour/depth/stencil into the resolve framebuffer.

No-op if the canvas does not use MSAA.

Source

pub fn blit_to_screen(&self, window_size: Size2D)

Blits this canvas into the default framebuffer (screen), scaling to fit.

Source

pub fn set_renderable_area( &self, x: i32, y: i32, size: Size2D, ) -> OpticResult<()>

Sets the viewport scissor within this canvas.

The rectangle must be within the canvas bounds.

Source

pub fn read_pixels(&self, index: usize) -> OpticResult<Vec<u8>>

Reads pixel data from a colour attachment back to the CPU.

Source

pub fn save_to_disk(&self, index: usize, path: &str) -> OpticResult<()>

Saves a colour attachment to an image file on disk.

Supported formats depend on the colour attachment format (8/16/32 bpc, 1–4 channels).

Source

pub fn delete(&mut self)

Deletes all GL resources (FBOs, RBOs, textures).

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>