Struct egui_glow::painter::Painter

source ·
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

source

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
source

pub fn gl(&self) -> &Arc<Context>

Access the shared glow context.

source

pub fn max_texture_side(&self) -> usize

source

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());

source

unsafe fn prepare_painting( &mut self, [width_in_pixels, height_in_pixels]: [u32; 2], pixels_per_point: f32, )

source

pub fn clear(&self, screen_size_in_pixels: [u32; 2], clear_color: [f32; 4])

source

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.

source

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.

source

fn paint_mesh(&mut self, mesh: &Mesh)

source

pub fn set_texture(&mut self, tex_id: TextureId, delta: &ImageDelta)

source

fn upload_texture_srgb( &mut self, pos: Option<[usize; 2]>, [w, h]: [usize; 2], options: TextureOptions, data: &[u8], )

source

pub fn free_texture(&mut self, tex_id: TextureId)

source

pub fn texture(&self, texture_id: TextureId) -> Option<Texture>

Get the glow::Texture bound to a egui::TextureId.

source

pub fn register_native_texture(&mut self, native: Texture) -> TextureId

source

pub fn replace_native_texture(&mut self, id: TextureId, replacing: Texture)

source

pub fn read_screen_rgba(&self, [w, h]: [u32; 2]) -> ColorImage

source

pub fn read_screen_rgb(&self, [w, h]: [u32; 2]) -> Vec<u8>

source

unsafe fn destroy_gl(&self)

source

pub fn destroy(&mut self)

This function must be called before Painter is dropped, as Painter has some OpenGL objects that should be deleted.

source

fn assert_not_destroyed(&self)

Trait Implementations§

source§

impl Drop for Painter

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

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

Convert 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)

Convert &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)

Convert &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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more