pub struct Renderer { /* private fields */ }
Expand description

Vulkan renderer for imgui.

It records rendering command to the provided command buffer at each call to cmd_draw.

The renderer holds a set of vertex/index buffers per in flight frames. Vertex and index buffers are resized at each call to cmd_draw if draw data does not fit.

Implementations§

source§

impl Renderer

source

pub fn with_default_allocator( instance: &Instance, physical_device: PhysicalDevice, device: Device, queue: Queue, command_pool: CommandPool, render_pass: RenderPass, imgui: &mut Context, options: Option<Options> ) -> RendererResult<Self>

Initialize and return a new instance of the renderer.

At initialization all Vulkan resources are initialized and font texture is created and uploaded to the gpu. Vertex and index buffers are not created yet.

§Arguments
  • instance - A reference to a Vulkan instance.
  • physical_device - A Vulkan physical device.
  • device - A Vulkan device.
  • queue - A Vulkan queue. It will be used to submit commands during initialization to upload data to the gpu. The type of queue must be supported by the following commands: vkCmdCopyBufferToImage, vkCmdPipelineBarrier
  • command_pool - A Vulkan command pool used to allocate command buffers to upload textures to the gpu.
  • render_pass - without dynamic-rendering feature - The render pass used to render the gui.
  • dynamic_rendering - with dynamic-rendering feature - Dynamic rendeing parameters
  • imgui - The imgui context.
  • options - Optional parameters of the renderer.
§Errors
  • RendererError - If the number of in flight frame in incorrect.
  • RendererError - If any Vulkan or io error is encountered during initialization.
source

pub fn set_render_pass(&mut self, render_pass: RenderPass) -> RendererResult<()>

Change the render pass to render to.

Useful if you need to render to a new render pass but don’t want to rebuild the entire renderer. It will rebuild the graphics pipeline from scratch so it is an expensive operation.

§Arguments
  • render_pass - The render pass used to render the gui.
§Errors
  • RendererError - If any Vulkan error is encountered during pipeline creation.
source

pub fn textures(&mut self) -> &mut Textures<DescriptorSet>

Returns the texture mapping used by the renderer to lookup textures.

Textures are provided by the application as vk::DescriptorSets.

§Example
let descriptor_set = ...;
// Insert a vk::DescriptorSet in the renderer textures map.
// The renderer returns a generated texture id.
let texture_id = renderer.textures().insert(descriptor_set);
...
// Create an `Image` that references the texture by its id.
Image::new(texture_id, [100, 100]).build(&ui);
§Caveat

Provided vk::DescriptorSets must be created with a descriptor set layout that is compatible with the one used by the renderer. See Pipeline Layout Compatibility.

source

pub fn update_fonts_texture( &mut self, queue: Queue, command_pool: CommandPool, imgui: &mut Context ) -> RendererResult<()>

Update the fonts texture after having added new fonts to imgui.

§Arguments
  • queue - A Vulkan queue. It will be used to submit commands during initialization to upload data to the gpu. The type of queue must be supported by the following commands: vkCmdCopyBufferToImage, vkCmdPipelineBarrier
  • command_pool - A Vulkan command pool used to allocate command buffers to upload textures to the gpu.
  • imgui - The imgui context.
§Errors
  • RendererError - If any error is encountered during texture update.
source

pub fn cmd_draw( &mut self, command_buffer: CommandBuffer, draw_data: &DrawData ) -> RendererResult<()>

Record commands required to render the gui.RendererError.

§Arguments
  • command_buffer - The Vulkan command buffer that command will be recorded to.
  • draw_data - A reference to the imgui DrawData containing rendering data.
§Errors
  • RendererError - If any Vulkan error is encountered during command recording.

Trait Implementations§

source§

impl Drop for Renderer

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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>,

§

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>,

§

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.