Struct Surface

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

A software-rendered surface that is implicitly associated with the underlying window (like glutin::RawContext).

Implementations§

Source§

impl Surface

Source

pub unsafe fn new(window: &Window, context: &Context, config: &Config) -> Self

Construct and attach a surface to the specified window.

Unsafety: The constructed Surface must be dropped before window.

Source

pub fn update_surface(&self, extent: [u32; 2], format: Format)

Update the properties of the surface.

After resizing a window, you must call this method irregardless of whether you want to change the image size or not. Also, you must call this method at least once before calling other methods.

The result of a mismatching image size is implementation-dependent. In general, you should use update_surface_to_fit.

Panics if:

  • format is not in supported_formats().
  • One of extent’s elements is zero.
  • One or more swapchain images are locked.
Source

pub fn update_surface_to_fit(&self, window: &Window, format: Format)

Update the properties of the surface. The surface size is automatically derived based on the window size.

This internally calls update_surface.

Source

pub fn supported_formats(&self) -> impl Iterator<Item = Format> + '_

Enumerate supported pixel formats.

Source

pub fn image_info(&self) -> ImageInfo

Get the ImageInfo describing the current swapchain images.

Source

pub fn num_images(&self) -> usize

Get the number of swapchain images.

This value is automatically calculated when update_surface is called.

This value does not reflect the actual number of buffers that stand between the application and the display hardware. It’s only useful when does_preserve_image() == true and the application wants to track dirty regions in each swapchain image.

Source

pub fn does_preserve_image(&self) -> bool

Get a flag indicating whether swapchain images preserve their contents when their indices are used again.

If this function returns true, the application can optimize rendering by only updating the dirty portions.

Source

pub fn poll_next_image(&self) -> Option<usize>

Get the index of the next available swapchain image.

Returns None if no image is available. In this case, the function specified via ContextBuilder::with_ready_cb will be called when one is ready. If you call poll_next_image for multiple times before the callback function is called for the next time, and all of the calls to poll_next_image returns None, then the callback function will be called only once.

The application cannot rely on image unavailability for metering the rendering speed even if Config::vsync is enabled.

update_surface may or may not cancel the deferred call to the callback.

If an image is returned, this method does not remove the image from the set of avilable images. For example, if the application calls poll_next_image repeatedly, it may return the same image index for all of the calls.

Source

pub fn lock_image(&self, i: usize) -> impl Deref<Target = [u8]> + DerefMut + '_

Lock a swapchain image at index i to access its contents.

i must be the index of a swapchain image acquired by poll_next_image.

Panics if the image is currently locked or not ready to be accessed by the application.

Given an ImageInfo, the length is calculated as: extent[1] * stride * 4.

Source

pub fn present_image(&self, i: usize)

Enqueue the presentation of a swapchain image at index i.

This method removes the swapchain image at index i from the set of available images and enqueues it for presentation.

i must be the index of a swapchain image acquired by poll_next_image. The image must not be locked by lock_image.

Trait Implementations§

Source§

impl Debug for Surface

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Surface

§

impl !RefUnwindSafe for Surface

§

impl !Send for Surface

§

impl !Sync for Surface

§

impl Unpin for Surface

§

impl !UnwindSafe for Surface

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> 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, 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> Erased for T