pub fn new(
        device: &wgpu::Device,
        output_format: wgpu::TextureFormat,
        msaa_samples: u32,
    ) -> Self {
        let shader = wgpu::ShaderModuleDescriptor {
            label: Some("egui_shader"),
            source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("egui.wgsl"))),
        };
        let module = device.create_shader_module(&shader);

        let uniform_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
            label: Some("egui_uniform_buffer"),
            contents: bytemuck::cast_slice(&[UniformBuffer {
                screen_size_in_points: [0.0, 0.0],
            }]),
            usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
        });
        let uniform_buffer = SizedBuffer {
            buffer: uniform_buffer,
            size: std::mem::size_of::<UniformBuffer>(),
        };

        let uniform_bind_group_layout =
            device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
                label: Some("egui_uniform_bind_group_layout"),
                entries: &[wgpu::BindGroupLayoutEntry {
                    binding: 0,
                    visibility: wgpu::ShaderStages::VERTEX,
                    ty: wgpu::BindingType::Buffer {
                        has_dynamic_offset: false,
                        min_binding_size: None,
                        ty: wgpu::BufferBindingType::Uniform,
                    },
                    count: None,
                }],
            });

        let uniform_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
            label: Some("egui_uniform_bind_group"),
            layout: &uniform_bind_group_layout,
            entries: &[wgpu::BindGroupEntry {
                binding: 0,
                resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding {
                    buffer: &uniform_buffer.buffer,
                    offset: 0,
                    size: None,
                }),
            }],
        });

        let texture_bind_group_layout =
            device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
                label: Some("egui_texture_bind_group_layout"),
                entries: &[
                    wgpu::BindGroupLayoutEntry {
                        binding: 0,
                        visibility: wgpu::ShaderStages::FRAGMENT,
                        ty: wgpu::BindingType::Texture {
                            multisampled: false,
                            sample_type: wgpu::TextureSampleType::Float { filterable: true },
                            view_dimension: wgpu::TextureViewDimension::D2,
                        },
                        count: None,
                    },
                    wgpu::BindGroupLayoutEntry {
                        binding: 1,
                        visibility: wgpu::ShaderStages::FRAGMENT,
                        ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
                        count: None,
                    },
                ],
            });

        let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
            label: Some("egui_pipeline_layout"),
            bind_group_layouts: &[&uniform_bind_group_layout, &texture_bind_group_layout],
            push_constant_ranges: &[],
        });

        let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
            label: Some("egui_pipeline"),
            layout: Some(&pipeline_layout),
            vertex: wgpu::VertexState {
                entry_point: if output_format.describe().srgb {
                    "vs_main"
                } else {
                    "vs_conv_main"
                },
                module: &module,
                buffers: &[wgpu::VertexBufferLayout {
                    array_stride: 5 * 4,
                    step_mode: wgpu::VertexStepMode::Vertex,
                    // 0: vec2 position
                    // 1: vec2 texture coordinates
                    // 2: uint color
                    attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x2, 2 => Uint32],
                }],
            },
            primitive: wgpu::PrimitiveState {
                topology: wgpu::PrimitiveTopology::TriangleList,
                unclipped_depth: false,
                conservative: false,
                cull_mode: None,
                front_face: wgpu::FrontFace::default(),
                polygon_mode: wgpu::PolygonMode::default(),
                strip_index_format: None,
            },
            depth_stencil: None,
            multisample: wgpu::MultisampleState {
                alpha_to_coverage_enabled: false,
                count: msaa_samples,
                mask: !0,
            },

            fragment: Some(wgpu::FragmentState {
                module: &module,
                entry_point: "fs_main",
                targets: &[wgpu::ColorTargetState {
                    format: output_format,
                    blend: Some(wgpu::BlendState {
                        color: wgpu::BlendComponent {
                            src_factor: wgpu::BlendFactor::One,
                            dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
                            operation: wgpu::BlendOperation::Add,
                        },
                        alpha: wgpu::BlendComponent {
                            src_factor: wgpu::BlendFactor::OneMinusDstAlpha,
                            dst_factor: wgpu::BlendFactor::One,
                            operation: wgpu::BlendOperation::Add,
                        },
                    }),
                    write_mask: wgpu::ColorWrites::ALL,
                }],
            }),
            multiview: None,
        });

        Self {
            render_pipeline,
            vertex_buffers: Vec::with_capacity(64),
            index_buffers: Vec::with_capacity(64),
            uniform_buffer,
            uniform_bind_group,
            texture_bind_group_layout,
            textures: HashMap::new(),
            next_user_texture_id: 0,
        }
    }
/// Creates a new render pass to render a egui UI.
///
/// If the format passed is not a *Srgb format, the shader will automatically convert to `sRGB` colors in the shader.
Creates a new render pass to render a egui UI.
If the format passed is not a *Srgb format, the shader will automatically convert to `sRGB` colors in the shader.
Creates a new render pass to render a egui UI . If the format passed is not a * Srgb format the shader will automatically convert to ` sRGB ` colors in the shader .
pub fn new(
        device: &wgpu::Device,
        output_format: wgpu::TextureFormat,
        msaa_samples: u32,
    ) -> Self {
        let shader = wgpu::ShaderModuleDescriptor {
            label: Some("egui_shader"),
            source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("egui.wgsl"))),
        };
        let module = device.create_shader_module(&shader);
        let uniform_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
            label: Some("egui_uniform_buffer"),
            contents: bytemuck::cast_slice(&[UniformBuffer {
                screen_size_in_points: [0.0, 0.0],
            }]),
            usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
        });
        let uniform_buffer = SizedBuffer {
            buffer: uniform_buffer,
            size: std::mem::size_of::<UniformBuffer>(),
        };
        let uniform_bind_group_layout =
            device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
                label: Some("egui_uniform_bind_group_layout"),
                entries: &[wgpu::BindGroupLayoutEntry {
                    binding: 0,
                    visibility: wgpu::ShaderStages::VERTEX,
                    ty: wgpu::BindingType::Buffer {
                        has_dynamic_offset: false,
                        min_binding_size: None,
                        ty: wgpu::BufferBindingType::Uniform,
                    },
                    count: None,
                }],
            });
        let uniform_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
            label: Some("egui_uniform_bind_group"),
            layout: &uniform_bind_group_layout,
            entries: &[wgpu::BindGroupEntry {
                binding: 0,
                resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding {
                    buffer: &uniform_buffer.buffer,
                    offset: 0,
                    size: None,
                }),
            }],
        });
        let texture_bind_group_layout =
            device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
                label: Some("egui_texture_bind_group_layout"),
                entries: &[
                    wgpu::BindGroupLayoutEntry {
                        binding: 0,
                        visibility: wgpu::ShaderStages::FRAGMENT,
                        ty: wgpu::BindingType::Texture {
                            multisampled: false,
                            sample_type: wgpu::TextureSampleType::Float { filterable: true },
                            view_dimension: wgpu::TextureViewDimension::D2,
                        },
                        count: None,
                    },
                    wgpu::BindGroupLayoutEntry {
                        binding: 1,
                        visibility: wgpu::ShaderStages::FRAGMENT,
                        ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
                        count: None,
                    },
                ],
            });
        let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
            label: Some("egui_pipeline_layout"),
            bind_group_layouts: &[&uniform_bind_group_layout, &texture_bind_group_layout],
            push_constant_ranges: &[],
        });
        let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
            label: Some("egui_pipeline"),
            layout: Some(&pipeline_layout),
            vertex: wgpu::VertexState {
                entry_point: if output_format.describe().srgb {
                    "vs_main"
                } else {
                    "vs_conv_main"
                },
                module: &module,
                buffers: &[wgpu::VertexBufferLayout {
                    array_stride: 5 * 4,
                    step_mode: wgpu::VertexStepMode::Vertex,
                    // 0: vec2 position
                    // 1: vec2 texture coordinates
                    // 2: uint color
                    attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x2, 2 => Uint32],
                }],
            },
            primitive: wgpu::PrimitiveState {
                topology: wgpu::PrimitiveTopology::TriangleList,
                unclipped_depth: false,
                conservative: false,
                cull_mode: None,
                front_face: wgpu::FrontFace::default(),
                polygon_mode: wgpu::PolygonMode::default(),
                strip_index_format: None,
            },
            depth_stencil: None,
            multisample: wgpu::MultisampleState {
                alpha_to_coverage_enabled: false,
                count: msaa_samples,
                mask: !0,
            },
            fragment: Some(wgpu::FragmentState {
                module: &module,
                entry_point: "fs_main",
                targets: &[wgpu::ColorTargetState {
                    format: output_format,
                    blend: Some(wgpu::BlendState {
                        color: wgpu::BlendComponent {
                            src_factor: wgpu::BlendFactor::One,
                            dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
                            operation: wgpu::BlendOperation::Add,
                        },
                        alpha: wgpu::BlendComponent {
                            src_factor: wgpu::BlendFactor::OneMinusDstAlpha,
                            dst_factor: wgpu::BlendFactor::One,
                            operation: wgpu::BlendOperation::Add,
                        },
                    }),
                    write_mask: wgpu::ColorWrites::ALL,
                }],
            }),
            multiview: None,
        });
        Self {
            render_pipeline,
            vertex_buffers: Vec::with_capacity(64),
            index_buffers: Vec::with_capacity(64),
            uniform_buffer,
            uniform_bind_group,
            texture_bind_group_layout,
            textures: HashMap::new(),
            next_user_texture_id: 0,
        }
    }
pub fn new ( device : & wgpu :: Device , output_format : wgpu :: TextureFormat , msaa_samples : u32 , ) -> Self { let shader = wgpu :: ShaderModuleDescriptor { label : Some ( " " ) , source : wgpu :: ShaderSource :: Wgsl ( Cow :: Borrowed ( include_str ! ( " " ) ) ) , } ; let module = device . create_shader_module ( & shader ) ; let uniform_buffer = device . create_buffer_init ( & wgpu :: util :: BufferInitDescriptor { label : Some ( " " ) , contents : bytemuck :: cast_slice ( & [ UniformBuffer { screen_size_in_points : [ 0.0 , 0.0 ] , } ] ) , usage : wgpu :: BufferUsages :: UNIFORM | wgpu :: BufferUsages :: COPY_DST , } ) ; let uniform_buffer = SizedBuffer { buffer : uniform_buffer , size : std :: mem :: size_of :: < UniformBuffer > ( ) , } ; let uniform_bind_group_layout = device . create_bind_group_layout ( & wgpu :: BindGroupLayoutDescriptor { label : Some ( " " ) , entries : & [ wgpu :: BindGroupLayoutEntry { binding : 0 , visibility : wgpu :: ShaderStages :: VERTEX , ty : wgpu :: BindingType :: Buffer { has_dynamic_offset : false , min_binding_size : None , ty : wgpu :: BufferBindingType :: Uniform , } , count : None , } ] , } ) ; let uniform_bind_group = device . create_bind_group ( & wgpu :: BindGroupDescriptor { label : Some ( " " ) , layout : & uniform_bind_group_layout , entries : & [ wgpu :: BindGroupEntry { binding : 0 , resource : wgpu :: BindingResource :: Buffer ( wgpu :: BufferBinding { buffer : & uniform_buffer . buffer , offset : 0 , size : None , } ) , } ] , } ) ; let texture_bind_group_layout = device . create_bind_group_layout ( & wgpu :: BindGroupLayoutDescriptor { label : Some ( " " ) , entries : & [ wgpu :: BindGroupLayoutEntry { binding : 0 , visibility : wgpu :: ShaderStages :: FRAGMENT , ty : wgpu :: BindingType :: Texture { multisampled : false , sample_type : wgpu :: TextureSampleType :: Float { filterable : true } , view_dimension : wgpu :: TextureViewDimension :: D2 , } , count : None , } , wgpu :: BindGroupLayoutEntry { binding : 1 , visibility : wgpu :: ShaderStages :: FRAGMENT , ty : wgpu :: BindingType :: Sampler ( wgpu :: SamplerBindingType :: Filtering ) , count : None , } , ] , } ) ; let pipeline_layout = device . create_pipeline_layout ( & wgpu :: PipelineLayoutDescriptor { label : Some ( " " ) , bind_group_layouts : & [ & uniform_bind_group_layout , & texture_bind_group_layout ] , push_constant_ranges : & [ ] , } ) ; let render_pipeline = device . create_render_pipeline ( & wgpu :: RenderPipelineDescriptor { label : Some ( " " ) , layout : Some ( & pipeline_layout ) , vertex : wgpu :: VertexState { entry_point : if output_format . describe ( ) . srgb { " " } else { " " } , module : & module , buffers : & [ wgpu :: VertexBufferLayout { array_stride : 5 * 4 , step_mode : wgpu :: VertexStepMode :: Vertex , // 0: vec2 position // 1: vec2 texture coordinates // 2: uint color attributes : & wgpu :: vertex_attr_array ! [ 0 Float32x2 1 Float32x2 2 Uint32 ] , } ] , } , primitive : wgpu :: PrimitiveState { topology : wgpu :: PrimitiveTopology :: TriangleList , unclipped_depth : false , conservative : false , cull_mode : None , front_face : wgpu :: FrontFace :: default ( ) , polygon_mode : wgpu :: PolygonMode :: default ( ) , strip_index_format : None , } , depth_stencil : None , multisample : wgpu :: MultisampleState { alpha_to_coverage_enabled : false , count : msaa_samples , mask : ! 0 , } , fragment : Some ( wgpu :: FragmentState { module : & module , entry_point : " " , targets : & [ wgpu :: ColorTargetState { format : output_format , blend : Some ( wgpu :: BlendState { color : wgpu :: BlendComponent { src_factor : wgpu :: BlendFactor :: One , dst_factor : wgpu :: BlendFactor :: OneMinusSrcAlpha , operation : wgpu :: BlendOperation :: Add , } , alpha : wgpu :: BlendComponent { src_factor : wgpu :: BlendFactor :: OneMinusDstAlpha , dst_factor : wgpu :: BlendFactor :: One , operation : wgpu :: BlendOperation :: Add , } , } ) , write_mask : wgpu :: ColorWrites :: ALL , } ] , } ) , multiview : None , } ) ; Self { render_pipeline , vertex_buffers : Vec :: with_capacity ( 64 ) , index_buffers : Vec :: with_capacity ( 64 ) , uniform_buffer , uniform_bind_group , texture_bind_group_layout , textures : HashMap :: new ( ) , next_user_texture_id : 0 , } }
Creates a new render pass to render a egui UI.
Creates a new render pass to render a egui UI .
device
&wgpu::Device
output_format
wgpu::TextureFormat
msaa_samples
u32
device
&wgpu::Device
output_format
wgpu::TextureFormat
msaa_samples
u32