pub struct Painter {Show 15 fields
gl: Arc<Context>,
max_texture_side: usize,
program: Program,
u_screen_size: UniformLocation,
u_sampler: UniformLocation,
is_webgl_1: bool,
vao: VertexArrayObject,
srgb_textures: bool,
supports_srgb_framebuffer: bool,
vbo: Buffer,
element_array_buffer: Buffer,
textures: HashMap<TextureId, Texture>,
next_native_tex_id: u64,
textures_to_destroy: Vec<Texture>,
destroyed: bool,
}
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.
Fields§
§gl: Arc<Context>
§max_texture_side: usize
§program: Program
§u_screen_size: UniformLocation
§u_sampler: UniformLocation
§is_webgl_1: bool
§vao: VertexArrayObject
§srgb_textures: bool
§supports_srgb_framebuffer: bool
§vbo: Buffer
§element_array_buffer: Buffer
§textures: HashMap<TextureId, Texture>
§next_native_tex_id: u64
§textures_to_destroy: Vec<Texture>
Stores outdated OpenGL textures that are yet to be deleted
destroyed: bool
Used to make sure we are destroyed correctly.
Implementations§
source§impl Painter
impl Painter
sourcepub fn new(
gl: Arc<Context>,
shader_prefix: &str,
shader_version: Option<ShaderVersion>,
) -> Result<Self, PainterError>
pub fn new( gl: Arc<Context>, shader_prefix: &str, shader_version: Option<ShaderVersion>, ) -> 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());
unsafe fn prepare_painting( &mut self, [width_in_pixels, height_in_pixels]: [u32; 2], pixels_per_point: f32, )
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.
fn paint_mesh(&mut self, mesh: &Mesh)
pub fn set_texture(&mut self, tex_id: TextureId, delta: &ImageDelta)
fn upload_texture_srgb( &mut self, pos: Option<[usize; 2]>, [w, h]: [usize; 2], options: TextureOptions, data: &[u8], )
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
.
pub fn register_native_texture(&mut self, native: Texture) -> TextureId
pub fn replace_native_texture(&mut self, id: TextureId, replacing: Texture)
pub fn read_screen_rgba(&self, [w, h]: [u32; 2]) -> ColorImage
pub fn read_screen_rgb(&self, [w, h]: [u32; 2]) -> Vec<u8>
unsafe fn destroy_gl(&self)
fn assert_not_destroyed(&self)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Painter
impl RefUnwindSafe for Painter
impl !Send for Painter
impl !Sync for Painter
impl Unpin for Painter
impl UnwindSafe for Painter
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more