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
impl Renderer
Sourcepub fn new(device: &ID3D11Device) -> Result<Self>
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.
Sourcepub fn register_user_texture(
&mut self,
srv: ID3D11ShaderResourceView,
) -> TextureId
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),
)));Sourcepub fn unregister_user_texture(&mut self, tid: TextureId) -> bool
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.
Sourcepub fn render(
&mut self,
device_context: &ID3D11DeviceContext,
render_target: &ID3D11RenderTargetView,
egui_ctx: &Context,
egui_output: RendererOutput,
) -> Result<()>
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;