pub trait FrameBuffer: Downcast {
// Required methods
fn color_attachments(&self) -> &[Attachment];
fn depth_attachment(&self) -> Option<&Attachment>;
fn set_cubemap_face(&mut self, attachment_index: usize, face: CubeMapFace);
fn blit_to(
&self,
dest: &(dyn FrameBuffer + 'static),
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(
&mut self,
viewport: Rect<i32>,
color: Option<Color>,
depth: Option<f32>,
stencil: Option<i32>,
);
fn draw(
&mut self,
geometry: &(dyn GeometryBuffer + 'static),
viewport: Rect<i32>,
program: &(dyn GpuProgram + 'static),
params: &DrawParameters,
resources: &[ResourceBindGroup<'_>],
element_range: ElementRange,
) -> Result<DrawCallStatistics, FrameworkError>;
fn draw_instances(
&mut self,
count: usize,
geometry: &(dyn GeometryBuffer + 'static),
viewport: Rect<i32>,
program: &(dyn GpuProgram + 'static),
params: &DrawParameters,
resources: &[ResourceBindGroup<'_>],
) -> DrawCallStatistics;
}
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§
Sourcefn color_attachments(&self) -> &[Attachment]
fn color_attachments(&self) -> &[Attachment]
Returns a list of color attachments.
Sourcefn depth_attachment(&self) -> Option<&Attachment>
fn depth_attachment(&self) -> Option<&Attachment>
Returns an optional depth/stencil attachment.
Sourcefn set_cubemap_face(&mut self, attachment_index: usize, face: CubeMapFace)
fn set_cubemap_face(&mut self, attachment_index: usize, face: CubeMapFace)
Sets an active face of a cube map (only for frame buffers that using cube maps for rendering).
Sourcefn blit_to(
&self,
dest: &(dyn FrameBuffer + 'static),
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 blit_to( &self, dest: &(dyn FrameBuffer + 'static), 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
Sourcefn clear(
&mut self,
viewport: Rect<i32>,
color: Option<Color>,
depth: Option<f32>,
stencil: Option<i32>,
)
fn clear( &mut 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.
Sourcefn draw(
&mut self,
geometry: &(dyn GeometryBuffer + 'static),
viewport: Rect<i32>,
program: &(dyn GpuProgram + 'static),
params: &DrawParameters,
resources: &[ResourceBindGroup<'_>],
element_range: ElementRange,
) -> Result<DrawCallStatistics, FrameworkError>
fn draw( &mut self, geometry: &(dyn GeometryBuffer + 'static), viewport: Rect<i32>, program: &(dyn GpuProgram + 'static), 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 GeometryBuffer
, 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.
Sourcefn draw_instances(
&mut self,
count: usize,
geometry: &(dyn GeometryBuffer + 'static),
viewport: Rect<i32>,
program: &(dyn GpuProgram + 'static),
params: &DrawParameters,
resources: &[ResourceBindGroup<'_>],
) -> DrawCallStatistics
fn draw_instances( &mut self, count: usize, geometry: &(dyn GeometryBuffer + 'static), viewport: Rect<i32>, program: &(dyn GpuProgram + 'static), params: &DrawParameters, resources: &[ResourceBindGroup<'_>], ) -> DrawCallStatistics
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.