Struct egui_directx11::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
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 render(
&mut self,
device_context: &ID3D11DeviceContext,
render_target: &ID3D11RenderTargetView,
egui_ctx: &Context,
egui_output: RendererOutput,
scale_factor: f32
) -> Result<()>
pub fn render( &mut self, device_context: &ID3D11DeviceContext, render_target: &ID3D11RenderTargetView, egui_ctx: &Context, egui_output: RendererOutput, scale_factor: f32 ) -> Result<()>
Render the output of egui
to the provided render target using the
provided device context. The render target should use a linear color
space (e.g. DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
) for proper results.
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;
See the egui-demo
example for code examples.