[][src]Struct pixels::PixelsBuilder

pub struct PixelsBuilder { /* fields omitted */ }

A builder to help create customized pixel buffers.

Methods

impl PixelsBuilder[src]

pub fn new(
    width: u32,
    height: u32,
    surface_texture: SurfaceTexture
) -> PixelsBuilder
[src]

Create a builder that can be finalized into a Pixels pixel buffer.

Examples

struct MyRenderPass {
    // ...
};

impl pixels::RenderPass for MyRenderPass {
    // ...
}

let mut pixels = PixelsBuilder::new(256, 240, surface_texture)
    .pixel_aspect_ratio(8.0 / 7.0)
    .add_render_pass(|device, queue, texture, texture_size| {
        // Create reources for MyRenderPass here
        Box::new(MyRenderPass {
            // ...
        })
    })
    .build()?;

Panics

Panics when width or height are 0.

pub const fn request_adapter_options(
    self,
    request_adapter_options: RequestAdapterOptions
) -> PixelsBuilder
[src]

Add options for requesting a wgpu::Adapter.

pub const fn device_descriptor(
    self,
    device_descriptor: DeviceDescriptor
) -> PixelsBuilder
[src]

Add options for requesting a wgpu::Device.

pub fn pixel_aspect_ratio(self, pixel_aspect_ratio: f64) -> PixelsBuilder[src]

Set the pixel aspect ratio to simulate non-square pixels.

This setting enables a render pass that horizontally scales the pixel buffer by the given factor.

E.g. set this to 8.0 / 7.0 for an 8:7 pixel aspect ratio.

Panics

The aspect ratio must be > 0.

pub const fn texture_format(
    self,
    texture_format: TextureFormat
) -> PixelsBuilder
[src]

Set the texture format.

The default value is [wgpu::TextureFormat::Rgba8UnormSrgb], which is 4 unsigned bytes in RGBA order using the SRGB color space. This is typically what you want when you are working with color values from popular image editing tools or web apps.

pub fn add_render_pass(
    self,
    factory: impl Fn(Device, Queue, &TextureView, &Extent3d) -> BoxedRenderPass + 'static
) -> PixelsBuilder
[src]

Add a render pass.

Render passes are executed in the order they are added.

Factory Arguments

  • device - A reference-counted wgpu::Device which allows you to create GPU resources.
  • queue - A reference-counted wgpu::Queue which can execute command buffers.
  • texture - A wgpu::TextureView reference that is used as the texture input for the render pass.
  • texture_size - A [wgpu::Extent3d] providing the input texture size.

Examples

use pixels::{BoxedRenderPass, Device, PixelsBuilder, Queue, RenderPass};
use pixels::wgpu::{Extent3d, TextureView};

struct MyRenderPass {
    device: Device,
    queue: Queue,
}

impl MyRenderPass {
    fn factory(
        device: Device,
        queue: Queue,
        texture: &TextureView,
        texture_size: &Extent3d,
    ) -> BoxedRenderPass {
        // Create a bind group, pipeline, etc. and store all of the necessary state...
        Box::new(MyRenderPass { device, queue })
    }
}

impl RenderPass for MyRenderPass {
    // ...
}

let builder = PixelsBuilder::new(320, 240, surface_texture)
    .add_render_pass(MyRenderPass::factory)
    .build()?;

pub fn build(self) -> Result<Pixels, Error>[src]

Create a pixel buffer from the options builder.

Errors

Returns an error when a wgpu::Adapter cannot be found.

Auto Trait Implementations

Blanket Implementations

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

impl<T> From<T> for 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.

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

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

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