Renderer

Struct Renderer 

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

The core of this crate. You can set up a renderer via Renderer::new and render the output from egui with Renderer::render.

Implementations§

Source§

impl Renderer

Source

pub fn new(device: &ID3D11Device) -> Result<Self>

Create a Renderer using the provided Direct3D11 device. The Renderer holds various Direct3D11 resources and states derived from the device.

If any Direct3D resource creation fails, this function will return an error. You can create the Direct3D11 device with debug layer enabled to find out details on the error.

Source

pub fn register_user_texture( &mut self, srv: ID3D11ShaderResourceView, ) -> TextureId

Register a user-provided ID3D11ShaderResourceView and get a egui::TextureId for it.

This allows you to use your own DirectX11 textures within egui. The returned egui::TextureId can be used with egui::Image, egui::ImageButton, or any other egui widget that accepts a texture ID.

The texture will remain registered until you call Renderer::unregister_user_texture or the Renderer is dropped.

§Example
// Assuming you have a ID3D11ShaderResourceView
let texture_id = renderer.register_user_texture(my_srv);

// Use it in egui
ui.image(egui::ImageSource::Texture(egui::load::SizedTexture::new(
    texture_id,
    egui::vec2(256.0, 256.0),
)));
Source

pub fn unregister_user_texture(&mut self, tid: TextureId) -> bool

Unregister a user texture by its egui::TextureId.

Returns true if the texture was found and removed, false otherwise. Note that this only works for user-registered textures, not textures managed by egui itself.

Source

pub fn render( &mut self, device_context: &ID3D11DeviceContext, render_target: &ID3D11RenderTargetView, egui_ctx: &Context, egui_output: RendererOutput, ) -> Result<()>

Render the output of egui to the provided render_target.

As egui requires color blending in gamma space, the provided render_target MUST be in the gamma color space and viewed as non-sRGB-aware (i.e. do NOT use _SRGB format in the texture and the view).

If you have to render to a render target in linear color space or one that is sRGB-aware, you must create an intermediate render target in gamma color space and perform a blit operation afterwards.

The scale_factor should be the scale factor of your window and not confused with egui::Context::zoom_factor. If you are using winit, the scale_factor can be aquired using Window::scale_factor.

§Error Handling

If any Direct3D resource creation fails, this function will return an error. In this case you may have a incomplete or incorrect rendering result. You can create the Direct3D11 device with debug layer enabled to find out details on the error. If the device has been lost, you should drop the Renderer and create a new one.

§Pipeline State Management

This function sets up its own Direct3D11 pipeline state for rendering on the provided device context. It assumes that the hull shader, domain shader and geometry shader stages are not active on the provided device context without any further checks. It is all your responsibility to backup the current pipeline state and restore it afterwards if your rendering pipeline depends on it.

Particularly, it overrides:

  • The input layout, vertex buffer, index buffer and primitive topology in the input assembly stage;
  • The current shader in the vertex shader stage;
  • The viewport and rasterizer state in the rasterizer stage;
  • The current shader, shader resource slot 0 and sampler slot 0 in the pixel shader stage;
  • The render target(s) and blend state in the output merger stage;

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

Source§

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

Source§

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.