[][src]Struct golem::Surface

pub struct Surface { /* fields omitted */ }

A framebuffer that allows render-to-texture

Implementations

impl Surface[src]

pub fn new(ctx: &Context, texture: Texture) -> Result<Surface, GolemError>[src]

Create a new Surface to render to, backed by the given texture

pub fn has_texture(&self) -> bool[src]

Check if a texture is attached to this Surface

Textures can be attached via Surface::put_texture and removed via Surface::take_texture.

pub fn is_bound(&self) -> bool[src]

Check if this surface is bound to be operated on

Call Surface::bind to bind the surface, which is required to render to it or to call Surface::get_pixel_data

pub fn take_texture(&mut self) -> Option<Texture>[src]

Remove the texture from the Surface to operate on it

Until another texture is added via Surface::put_texture, operations on the Surface will panic.

pub fn put_texture(&mut self, texture: Texture)[src]

Put a texture into the Surface to operate on

pub unsafe fn borrow_texture(&self) -> Option<&Texture>[src]

Borrow the texture the Surface is holding

Safety

The texture can be used and referenced while it is bound and while it is not bound. However, it is undefined behavior to form a 'texture loop.' If a Surface is actively bound, the texture cannot be used in the rendering pipeline. It is important to only ever render to the Surface or use its texture, not both.

pub fn bind(&self)[src]

Set the current render target to this surface

Also necessary for operations like Surface::get_pixel_data

pub fn unbind(ctx: &Context)[src]

Unbind the surface and set the render target to the screen

pub fn get_pixel_data(
    &self,
    x: u32,
    y: u32,
    width: u32,
    height: u32,
    format: ColorFormat,
    data: &mut [u8]
)
[src]

Get the pixel data and write it to a buffer

The surface must be bound first, see Surface::bind.

The ColorFormat determines how many bytes each pixel is: 3 bytes for RGB and 4 for RGBA. The slice needs have a length of (width - x) * (height - y) * ColorFormat size.

pub fn width(&self) -> Option<u32>[src]

Get the width of the inner texture, or None if there is no texture

pub fn height(&self) -> Option<u32>[src]

Get the height of the inner texture, or None if there is no texture

Trait Implementations

impl Drop for Surface[src]

Auto Trait Implementations

impl !RefUnwindSafe for Surface

impl !Send for Surface

impl !Sync for Surface

impl Unpin for Surface

impl !UnwindSafe for Surface

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.