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: u32Screen width in pixels.
height: u32Screen height in pixels.
dirty_region: DirtyRegionAccumulated dirty region for incremental rendering. Callers mark areas that need redrawing; render functions may skip pixels outside this region.
Implementations§
Source§impl FrameBuffer
impl FrameBuffer
Sourcepub fn new(config: RenderConfig, clear_color: Rgba) -> Self
pub fn new(config: RenderConfig, clear_color: Rgba) -> Self
Create a new framebuffer with the given render config, cleared to the given color.
Sourcepub fn mark_all_dirty(&mut self)
pub fn mark_all_dirty(&mut self)
Mark the entire framebuffer as dirty (force full redraw).
Sourcepub fn mark_dirty_rect(&mut self, x: i32, y: i32, w: u32, h: u32)
pub fn mark_dirty_rect(&mut self, x: i32, y: i32, w: u32, h: u32)
Mark a rectangular region as dirty.
Sourcepub fn mark_dirty_tile(&mut self, tx: i32, ty: i32)
pub fn mark_dirty_tile(&mut self, tx: i32, ty: i32)
Mark a tile as dirty given its tile coordinates (tx, ty).
Sourcepub fn clear_dirty(&mut self)
pub fn clear_dirty(&mut self)
Clear all dirty regions (nothing to redraw).
Sourcepub fn is_dirty_pixel(&self, x: u32, y: u32) -> bool
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.
Sourcepub fn set_pixel(&mut self, x: u32, y: u32, color: Rgba) -> bool
pub fn set_pixel(&mut self, x: u32, y: u32, color: Rgba) -> bool
Set a single pixel. Returns false if out of bounds.
Sourcepub fn get_pixel(&self, x: u32, y: u32) -> Option<Rgba>
pub fn get_pixel(&self, x: u32, y: u32) -> Option<Rgba>
Get the color of a single pixel. Returns None if out of bounds.
Sourcepub fn fill_rect(
&mut self,
x: u32,
y: u32,
rect_width: u32,
rect_height: u32,
color: Rgba,
)
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.
Sourcepub fn row_slice(&self, y: u32) -> Option<&[u8]>
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.
Sourcepub fn row_slice_mut(&mut self, y: u32) -> Option<&mut [u8]>
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.
Trait Implementations§
Source§impl Clone for FrameBuffer
impl Clone for FrameBuffer
Source§fn clone(&self) -> FrameBuffer
fn clone(&self) -> FrameBuffer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more