/// Create a new renderer given a device and output pixel format.
Create a new renderer given a device and output pixel format.
Create a new renderer given a device and output pixel format .
pub fn new(device: &wgpu::Device, texture_format: wgpu::TextureFormat) -> Self {
        let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
            label: None,
            source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(include_str!(
                "shader.wgsl"
            ))),
        });
        let scenes = [
            Scene::new(&device),
            Scene::new(&device),
            Scene::new(&device),
        ];
        let uniform_bind_group_layout =
            device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
                entries: &[
                    wgpu::BindGroupLayoutEntry {
                        binding: 0,
                        visibility: wgpu::ShaderStages::VERTEX,
                        ty: wgpu::BindingType::Buffer {
                            ty: wgpu::BufferBindingType::Uniform,
                            has_dynamic_offset: false,
                            min_binding_size: None,
                        },
                        count: None,
                    },
                    wgpu::BindGroupLayoutEntry {
                        binding: 1,
                        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: 2,
                        visibility: wgpu::ShaderStages::FRAGMENT,
                        ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
                        count: None,
                    },
                ],
                label: Some("uniform_bind_group_layout"),
            });
        let glyph_cache = GlyphCache::new(device);
        let texture_view = glyph_cache.create_view();
        let uniforms = GPUVec::new_uniforms(device, "uniforms");
        let glyph_sampler = device.create_sampler(&wgpu::SamplerDescriptor {
            label: Some("glyph"),
            mag_filter: wgpu::FilterMode::Linear,
            min_filter: wgpu::FilterMode::Linear,
            ..Default::default()
        });
        let uniform_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
            layout: &uniform_bind_group_layout,
            entries: &[
                uniforms.bind_group_entry(0),
                wgpu::BindGroupEntry {
                    binding: 1,
                    resource: wgpu::BindingResource::TextureView(&texture_view),
                },
                wgpu::BindGroupEntry {
                    binding: 2,
                    resource: wgpu::BindingResource::Sampler(&glyph_sampler),
                },
            ],
            label: Some("vger bind group"),
        });
        let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
            label: None,
            bind_group_layouts: &[
                &Scene::bind_group_layout(&device),
                &uniform_bind_group_layout,
            ],
            push_constant_ranges: &[],
        });
        let blend_comp = wgpu::BlendComponent {
            operation: wgpu::BlendOperation::Add,
            src_factor: wgpu::BlendFactor::SrcAlpha,
            dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
        };
        let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
            label: None,
            layout: Some(&pipeline_layout),
            vertex: wgpu::VertexState {
                module: &shader,
                entry_point: "vs_main",
                buffers: &[],
            },
            fragment: Some(wgpu::FragmentState {
                module: &shader,
                entry_point: "fs_main",
                targets: &[wgpu::ColorTargetState {
                    format: texture_format,
                    blend: Some(wgpu::BlendState {
                        color: blend_comp,
                        alpha: blend_comp,
                    }),
                    write_mask: wgpu::ColorWrites::ALL,
                }],
            }),
            primitive: wgpu::PrimitiveState {
                cull_mode: None,
                topology: wgpu::PrimitiveTopology::TriangleStrip,
                ..Default::default()
            },
            depth_stencil: None,
            multisample: wgpu::MultisampleState::default(),
            multiview: None,
        });
        let layout = Layout::new(CoordinateSystem::PositiveYUp);
        Self {
            scenes,
            cur_scene: 0,
            cur_layer: 0,
            tx_stack: vec![],
            device_px_ratio: 1.0,
            screen_size: ScreenSize::new(512.0, 512.0),
            paint_count: 0,
            pipeline,
            uniforms,
            uniform_bind_group,
            xform_count: 0,
            path_scanner: PathScanner::new(),
            pen: LocalPoint::zero(),
            glyph_cache,
            layout,
        }
    }
pub fn new ( device : & wgpu :: Device , texture_format : wgpu :: TextureFormat ) -> Self { let shader = device . create_shader_module ( & wgpu :: ShaderModuleDescriptor { label : None , source : wgpu :: ShaderSource :: Wgsl ( std :: borrow :: Cow :: Borrowed ( include_str ! ( " " ) ) ) , } ) ; let scenes = [ Scene :: new ( & device ) , Scene :: new ( & device ) , Scene :: new ( & device ) , ] ; let uniform_bind_group_layout = device . create_bind_group_layout ( & wgpu :: BindGroupLayoutDescriptor { entries : & [ wgpu :: BindGroupLayoutEntry { binding : 0 , visibility : wgpu :: ShaderStages :: VERTEX , ty : wgpu :: BindingType :: Buffer { ty : wgpu :: BufferBindingType :: Uniform , has_dynamic_offset : false , min_binding_size : None , } , count : None , } , wgpu :: BindGroupLayoutEntry { binding : 1 , 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 : 2 , visibility : wgpu :: ShaderStages :: FRAGMENT , ty : wgpu :: BindingType :: Sampler ( wgpu :: SamplerBindingType :: Filtering ) , count : None , } , ] , label : Some ( " " ) , } ) ; let glyph_cache = GlyphCache :: new ( device ) ; let texture_view = glyph_cache . create_view ( ) ; let uniforms = GPUVec :: new_uniforms ( device , " " ) ; let glyph_sampler = device . create_sampler ( & wgpu :: SamplerDescriptor { label : Some ( " " ) , mag_filter : wgpu :: FilterMode :: Linear , min_filter : wgpu :: FilterMode :: Linear , .. Default :: default ( ) } ) ; let uniform_bind_group = device . create_bind_group ( & wgpu :: BindGroupDescriptor { layout : & uniform_bind_group_layout , entries : & [ uniforms . bind_group_entry ( 0 ) , wgpu :: BindGroupEntry { binding : 1 , resource : wgpu :: BindingResource :: TextureView ( & texture_view ) , } , wgpu :: BindGroupEntry { binding : 2 , resource : wgpu :: BindingResource :: Sampler ( & glyph_sampler ) , } , ] , label : Some ( " " ) , } ) ; let pipeline_layout = device . create_pipeline_layout ( & wgpu :: PipelineLayoutDescriptor { label : None , bind_group_layouts : & [ & Scene :: bind_group_layout ( & device ) , & uniform_bind_group_layout , ] , push_constant_ranges : & [ ] , } ) ; let blend_comp = wgpu :: BlendComponent { operation : wgpu :: BlendOperation :: Add , src_factor : wgpu :: BlendFactor :: SrcAlpha , dst_factor : wgpu :: BlendFactor :: OneMinusSrcAlpha , } ; let pipeline = device . create_render_pipeline ( & wgpu :: RenderPipelineDescriptor { label : None , layout : Some ( & pipeline_layout ) , vertex : wgpu :: VertexState { module : & shader , entry_point : " " , buffers : & [ ] , } , fragment : Some ( wgpu :: FragmentState { module : & shader , entry_point : " " , targets : & [ wgpu :: ColorTargetState { format : texture_format , blend : Some ( wgpu :: BlendState { color : blend_comp , alpha : blend_comp , } ) , write_mask : wgpu :: ColorWrites :: ALL , } ] , } ) , primitive : wgpu :: PrimitiveState { cull_mode : None , topology : wgpu :: PrimitiveTopology :: TriangleStrip , .. Default :: default ( ) } , depth_stencil : None , multisample : wgpu :: MultisampleState :: default ( ) , multiview : None , } ) ; let layout = Layout :: new ( CoordinateSystem :: PositiveYUp ) ; Self { scenes , cur_scene : 0 , cur_layer : 0 , tx_stack : vec ! [ ] , device_px_ratio : 1.0 , screen_size : ScreenSize :: new ( 512.0 , 512.0 ) , paint_count : 0 , pipeline , uniforms , uniform_bind_group , xform_count : 0 , path_scanner : PathScanner :: new ( ) , pen : LocalPoint :: zero ( ) , glyph_cache , layout , } }
Create a new renderer given a device and output pixel format.
Create a new renderer given a device and output pixel format .
device
&wgpu::Device
texture_format
wgpu::TextureFormat