Skip to main content

FrameBuffer

Struct FrameBuffer 

Source
pub struct FrameBuffer {
    pub data: Vec<u8>,
    pub width: u32,
    pub height: u32,
    pub dirty_region: DirtyRegion,
}
Expand description

A pixel RGBA framebuffer with configurable dimensions.

The internal buffer is a flat array of RGBA bytes in row-major order. Pixel (x, y) starts at byte offset (y * width + x) * 4.

Fields§

§data: Vec<u8>

Raw RGBA pixel data, width * height * 4 bytes.

§width: u32

Screen width in pixels.

§height: u32

Screen height in pixels.

§dirty_region: DirtyRegion

Accumulated dirty region for incremental rendering. Callers mark areas that need redrawing; render functions may skip pixels outside this region.

Implementations§

Source§

impl FrameBuffer

Source

pub fn new(config: RenderConfig, clear_color: Rgba) -> Self

Create a new framebuffer with the given render config, cleared to the given color.

Source

pub fn mark_all_dirty(&mut self)

Mark the entire framebuffer as dirty (force full redraw).

Source

pub fn mark_dirty_rect(&mut self, x: i32, y: i32, w: u32, h: u32)

Mark a rectangular region as dirty.

Source

pub fn mark_dirty_tile(&mut self, tx: i32, ty: i32)

Mark a tile as dirty given its tile coordinates (tx, ty).

Source

pub fn clear_dirty(&mut self)

Clear all dirty regions (nothing to redraw).

Source

pub fn is_dirty_pixel(&self, x: u32, y: u32) -> bool

Check whether a pixel is in a dirty region (needs redrawing). If no dirty region is present, all pixels are considered dirty.

Source

pub fn width(&self) -> u32

Returns the width of this framebuffer in pixels.

Source

pub fn height(&self) -> u32

Returns the height of this framebuffer in pixels.

Source

pub fn clear(&mut self, color: Rgba)

Clear the entire framebuffer to a single color.

Source

pub fn set_pixel(&mut self, x: u32, y: u32, color: Rgba) -> bool

Set a single pixel. Returns false if out of bounds.

Source

pub fn get_pixel(&self, x: u32, y: u32) -> Option<Rgba>

Get the color of a single pixel. Returns None if out of bounds.

Source

pub fn fill_rect( &mut self, x: u32, y: u32, rect_width: u32, rect_height: u32, color: Rgba, )

Fill a rectangular region with a color. Coordinates are clamped to screen bounds.

Source

pub fn row_slice(&self, y: u32) -> Option<&[u8]>

Get a slice of one pixel row’s RGBA data. Returns None if y is out of bounds.

Source

pub fn row_slice_mut(&mut self, y: u32) -> Option<&mut [u8]>

Get a mutable slice of one pixel row’s RGBA data. Returns None if y is out of bounds.

Source

pub fn blit_row(&mut self, x: u32, y: u32, src: &[u8], count: u32) -> bool

Copy a horizontal line of RGBA data into the framebuffer. src must be exactly count * 4 bytes. Returns false if the line goes out of bounds.

Source

pub fn save_png(&self, path: &Path) -> Result<()>

Save the framebuffer as a PNG file.

Uses the image crate to encode the raw RGBA data.

Trait Implementations§

Source§

impl Clone for FrameBuffer

Source§

fn clone(&self) -> FrameBuffer

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 FrameBuffer

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