Skip to main content
← PSoXide SDK guides and examples · SDK f2fec1c301f1 · All Cargo features enabled; check feature gates before use.

DoubleBuffer

Struct DoubleBuffer 

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

Two framebuffers stacked in VRAM: the GPU shows one while the other is drawn, and swap exchanges them.

The first buffer sits at VRAM line 0 and the second stride lines below it, so a 320×240 pair fits beside textures in the 1024×512 VRAM.

use psx_gpu::display::{DoubleBuffer, Resolution};
let buffers = DoubleBuffer::with_stride(Resolution::R320X240, 256);
assert_eq!(buffers.draw_origin(), (0, 0));
assert_eq!(buffers.display_origin(), (0, 256));

Implementations§

Source§

impl DoubleBuffer

Source

pub const fn new(resolution: Resolution) -> Self

Buffers of resolution, the second directly below the first.

Source

pub const fn with_stride(resolution: Resolution, stride: u16) -> Self

Buffers stride VRAM lines apart, leaving the lines between them free (palettes, say). A stride below the height is raised to it so the buffers never overlap.

§Panics

If the second buffer would end past VRAM line 512 (a 480-line resolution can’t be double-buffered this way).

Source

pub const fn size(&self) -> (u16, u16)

Width and height of each buffer, in pixels.

Source

pub const fn stride(&self) -> u16

VRAM lines between the two buffers’ top edges.

Source

pub const fn draw_origin(&self) -> (u16, u16)

Top-left VRAM corner of the buffer being drawn.

Source

pub const fn display_origin(&self) -> (u16, u16)

Top-left VRAM corner of the buffer being shown.

Source

pub fn swap(&mut self, gpu: &mut Gpu)

Show the buffer just drawn and draw into the other one from now on.

Flips at once (GP1(05h)); the hardware latches the start at the next frame. Drawing must be finished (crate::Gpu::wait_idle) first.

Source

pub fn begin_swap(&mut self, gpu: &mut Gpu) -> u32

Switch the draw side now and program its draw area and offset, and return the GP1(05h) word that shows the finished buffer, for the caller to apply at a blank edge (psx-rt’s queued flip). Drawing must be finished (crate::Gpu::wait_idle) first.

Source

pub fn begin_deferred_swap(&mut self) -> u32

Select the next draw buffer without touching the GPU, and return the GP1(05h) word that shows the finished one.

The non-blocking first half of a pipelined swap: queue the word for a VBlank edge whose handler applies it once the frame’s closing GP0(1Fh) has run (psx_rt::interrupts::queue_display_control_at_vblank, see crate::is_draw_done), wait until it has been applied, then call apply_draw_target before drawing. Safe to call while the previous frame still rasterises.

Source

pub fn apply_draw_target(&self, _gpu: &mut Gpu)

Program the draw area and draw offset for the buffer being drawn.

Source

pub fn clear(&self, gpu: &mut Gpu, color: (u8, u8, u8))

Fill the buffer being drawn with color (GP0(02h)).

Trait Implementations§

Source§

impl Clone for DoubleBuffer

Source§

fn clone(&self) -> DoubleBuffer

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DoubleBuffer

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Hash for DoubleBuffer

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given [Hasher]. Read more
1.3.0§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given [Hasher]. Read more
Source§

impl PartialEq for DoubleBuffer

Source§

fn eq(&self, other: &DoubleBuffer) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for DoubleBuffer

Source§

impl Eq for DoubleBuffer

Source§

impl StructuralPartialEq for DoubleBuffer

Auto Trait Implementations§

§

impl Freeze for DoubleBuffer

§

impl RefUnwindSafe for DoubleBuffer

§

impl Send for DoubleBuffer

§

impl Sync for DoubleBuffer

§

impl Unpin for DoubleBuffer

§

impl UnsafeUnpin for DoubleBuffer

§

impl UnwindSafe for DoubleBuffer

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.