pub struct Painter { /* private fields */ }
Expand description
An OpenGL painter using glow
.
This is responsible for painting egui and managing egui textures.
You can access the underlying glow::Context
with Self::gl
.
This struct must be destroyed with Painter::destroy
before dropping, to ensure OpenGL
objects have been properly deleted and are not leaked.
NOTE: all egui viewports share the same painter.
Implementations§
Source§impl Painter
impl Painter
Sourcepub fn new(
gl: Arc<Context>,
shader_prefix: &str,
shader_version: Option<ShaderVersion>,
dithering: bool,
) -> Result<Self, PainterError>
pub fn new( gl: Arc<Context>, shader_prefix: &str, shader_version: Option<ShaderVersion>, dithering: bool, ) -> Result<Self, PainterError>
Create painter.
Set pp_fb_extent
to the framebuffer size to enable sRGB
support on OpenGL ES and WebGL.
Set shader_prefix
if you want to turn on shader workaround e.g. "#define APPLY_BRIGHTENING_GAMMA\n"
(see https://github.com/emilk/egui/issues/794).
§Errors
will return Err
below cases
- failed to compile shader
- failed to create postprocess on webgl with
sRGB
support - failed to create buffer
pub fn max_texture_side(&self) -> usize
Sourcepub fn intermediate_fbo(&self) -> Option<Framebuffer>
pub fn intermediate_fbo(&self) -> Option<Framebuffer>
The framebuffer we use as an intermediate render target,
or None
if we are painting to the screen framebuffer directly.
This is the framebuffer that is bound when egui::Shape::Callback
is called,
and is where any callbacks should ultimately render onto.
So if in a egui::Shape::Callback
you need to use an offscreen FBO, you should
then restore to this afterwards with
gl.bind_framebuffer(glow::FRAMEBUFFER, painter.intermediate_fbo());
pub fn clear(&self, screen_size_in_pixels: [u32; 2], clear_color: [f32; 4])
Sourcepub fn paint_and_update_textures(
&mut self,
screen_size_px: [u32; 2],
pixels_per_point: f32,
clipped_primitives: &[ClippedPrimitive],
textures_delta: &TexturesDelta,
)
pub fn paint_and_update_textures( &mut self, screen_size_px: [u32; 2], pixels_per_point: f32, clipped_primitives: &[ClippedPrimitive], textures_delta: &TexturesDelta, )
You are expected to have cleared the color buffer before calling this.
Sourcepub fn paint_primitives(
&mut self,
screen_size_px: [u32; 2],
pixels_per_point: f32,
clipped_primitives: &[ClippedPrimitive],
)
pub fn paint_primitives( &mut self, screen_size_px: [u32; 2], pixels_per_point: f32, clipped_primitives: &[ClippedPrimitive], )
Main entry-point for painting a frame.
You should call target.clear_color(..)
before
and target.finish()
after this.
The following OpenGL features will be set:
- Scissor test will be enabled
- Cull face will be disabled
- Blend will be enabled
The scissor area and blend parameters will be changed.
As well as this, the following objects will be unset:
- Vertex Buffer
- Element Buffer
- Texture (and active texture will be set to 0)
- Program
Please be mindful of these effects when integrating into your program, and also be mindful of the effects your program might have on this code. Look at the source if in doubt.
pub fn set_texture(&mut self, tex_id: TextureId, delta: &ImageDelta)
pub fn free_texture(&mut self, tex_id: TextureId)
Sourcepub fn texture(&self, texture_id: TextureId) -> Option<Texture>
pub fn texture(&self, texture_id: TextureId) -> Option<Texture>
Get the glow::Texture
bound to a egui::TextureId
.