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
impl Canvas
Sourcepub fn new(desc: &CanvasDesc) -> OpticResult<Self>
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_comparerequiresdepth_as_texture
Sourcepub fn color_tex(&self, index: usize) -> OpticResult<&Texture2D>
pub fn color_tex(&self, index: usize) -> OpticResult<&Texture2D>
Returns a reference to the colour texture at the given attachment index.
Sourcepub fn depth_tex(&self) -> Option<&Texture2D>
pub fn depth_tex(&self) -> Option<&Texture2D>
Returns a reference to the depth texture, if present.
Sourcepub fn set_size(&mut self, new_size: Size2D) -> OpticResult<()>
pub fn set_size(&mut self, new_size: Size2D) -> OpticResult<()>
Resizes the canvas by recreating the framebuffer with a new size.
Sourcepub fn resolve(&self)
pub fn resolve(&self)
Resolves MSAA colour/depth/stencil into the resolve framebuffer.
No-op if the canvas does not use MSAA.
Sourcepub fn blit_to_screen(&self, window_size: Size2D)
pub fn blit_to_screen(&self, window_size: Size2D)
Blits this canvas into the default framebuffer (screen), scaling to fit.
Sourcepub fn set_renderable_area(
&self,
x: i32,
y: i32,
size: Size2D,
) -> OpticResult<()>
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.
Sourcepub fn read_pixels(&self, index: usize) -> OpticResult<Vec<u8>>
pub fn read_pixels(&self, index: usize) -> OpticResult<Vec<u8>>
Reads pixel data from a colour attachment back to the CPU.
Sourcepub fn save_to_disk(&self, index: usize, path: &str) -> OpticResult<()>
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).
Auto Trait Implementations§
impl Freeze for Canvas
impl RefUnwindSafe for Canvas
impl Send for Canvas
impl Sync for Canvas
impl Unpin for Canvas
impl UnsafeUnpin for Canvas
impl UnwindSafe for Canvas
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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