Skip to main content

GpuFrameBufferTrait

Trait GpuFrameBufferTrait 

Source
pub trait GpuFrameBufferTrait: GpuFrameBufferAsAny {
    // Required methods
    fn color_attachments(&self) -> &[Attachment];
    fn depth_attachment(&self) -> Option<&Attachment>;
    fn set_cubemap_face(
        &self,
        attachment_index: usize,
        face: CubeMapFace,
        level: usize,
    );
    fn blit_to(
        &self,
        dest: &GpuFrameBuffer,
        src_x0: i32,
        src_y0: i32,
        src_x1: i32,
        src_y1: i32,
        dst_x0: i32,
        dst_y0: i32,
        dst_x1: i32,
        dst_y1: i32,
        copy_color: bool,
        copy_depth: bool,
        copy_stencil: bool,
    );
    fn clear(
        &self,
        viewport: Rect<i32>,
        color: Option<Color>,
        depth: Option<f32>,
        stencil: Option<i32>,
    );
    fn read_pixels(&self, read_target: ReadTarget) -> Option<Vec<u8>>;
    fn draw(
        &self,
        geometry: &GpuGeometryBuffer,
        viewport: Rect<i32>,
        program: &GpuProgram,
        params: &DrawParameters,
        resources: &[ResourceBindGroup<'_>],
        element_range: ElementRange,
    ) -> Result<DrawCallStatistics, FrameworkError>;
    fn draw_instances(
        &self,
        instance_count: usize,
        geometry: &GpuGeometryBuffer,
        viewport: Rect<i32>,
        program: &GpuProgram,
        params: &DrawParameters,
        resources: &[ResourceBindGroup<'_>],
        element_range: ElementRange,
    ) -> Result<DrawCallStatistics, FrameworkError>;
}
Expand description

Frame buffer is a set of images that is used as a storage for an image generated by a renderer. It consists of one or more color buffers and an optional depth/stencil buffer. Frame buffer is a high level abstraction that consolidates multiple images and supports drawing meshes to them with various drawing options.

Required Methods§

Source

fn color_attachments(&self) -> &[Attachment]

Returns a list of color attachments.

Source

fn depth_attachment(&self) -> Option<&Attachment>

Returns an optional depth/stencil attachment.

Source

fn set_cubemap_face( &self, attachment_index: usize, face: CubeMapFace, level: usize, )

Chooses a different face and mipmap level for the texture attached at the given index. When the texture is a cubemap texture, this allows the framebuffer to render to a different face of the cube. This method must not be called if the texture is not a cubemap.

Source

fn blit_to( &self, dest: &GpuFrameBuffer, src_x0: i32, src_y0: i32, src_x1: i32, src_y1: i32, dst_x0: i32, dst_y0: i32, dst_x1: i32, dst_y1: i32, copy_color: bool, copy_depth: bool, copy_stencil: bool, )

Performs data transfer from one frame buffer to another with scaling. It copies a region defined by src_x0, src_y0, src_x1, src_y1 coordinates from the frame buffer and “pastes” it to the other frame buffer into a region defined by dst_x0, dst_y0, dst_x1, dst_y1 coordinates. If the source rectangle does not match the destination, the image will be interpolated using nearest interpolation.

This method can copy only specific parts of the image: copy_color tells the method to copy the data from

Source

fn clear( &self, viewport: Rect<i32>, color: Option<Color>, depth: Option<f32>, stencil: Option<i32>, )

Clears the frame buffer in the given viewport with the given set of optional values. This method clears multiple attachments at once. What will be cleared defined by the provided values. If color is not None, then all the color attachments will be cleared with the given color. The same applies to depth and stencil buffers.

Source

fn read_pixels(&self, read_target: ReadTarget) -> Option<Vec<u8>>

Reads texture pixels.

Source

fn draw( &self, geometry: &GpuGeometryBuffer, viewport: Rect<i32>, program: &GpuProgram, params: &DrawParameters, resources: &[ResourceBindGroup<'_>], element_range: ElementRange, ) -> Result<DrawCallStatistics, FrameworkError>

Draws the specified geometry buffer using the given GPU program and a set of resources. This method the main method to draw anything.

geometry - defines a [GpuGeometryBuffer], that contains vertices and index buffers and essentially defines a mesh to render. viewport - defines an area on screen that will be used to draw. program - a [GpuProgram] defines a set of shaders (usually a pair of vertex + fragment) that will define how the mesh will be rendered. params - DrawParameters defines the state of graphics pipeline and essentially sets a bunch of various parameters (such as backface culling, blending mode, various tests, etc.) that will define how the rendering process is performed. resources - a set of resource bind groups, that in their turn provides a set of resources that bound to specific binding points. element_range - defines which range of elements to draw.

Source

fn draw_instances( &self, instance_count: usize, geometry: &GpuGeometryBuffer, viewport: Rect<i32>, program: &GpuProgram, params: &DrawParameters, resources: &[ResourceBindGroup<'_>], element_range: ElementRange, ) -> Result<DrawCallStatistics, FrameworkError>

Almost the same as Self::draw, but draws multiple instances at once. The caller must supply all the required data per each instance, it could be done in different ways. The data could be supplied in vertex attributes, uniform buffers, textures, etc.

Implementations§

Source§

impl dyn GpuFrameBufferTrait

Source

pub fn read_pixels_of_type<T>(&self, read_target: ReadTarget) -> Option<Vec<T>>
where T: Pod,

Reads the pixels and reinterprets them using the given type.

Implementors§