Struct egui_glow::painter::Painter

source ·
pub struct Painter {
Show 14 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, 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.

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§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<Painter, String>

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 ) -> (u32, u32)

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 get_texture(&self, texture_id: TextureId) -> Option<Texture>

👎Deprecated: renamed ‘texture’
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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> 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 Twhere 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 Twhere 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.