Use resolution later

This commit is contained in:
grovesNL 2022-05-09 12:29:23 -02:30
parent a973504abd
commit ded1ba3310
2 changed files with 10 additions and 21 deletions

View file

@ -51,15 +51,7 @@ async fn run() {
}; };
surface.configure(&device, &config); surface.configure(&device, &config);
let mut text_renderer = TextRenderer::new( let mut text_renderer = TextRenderer::new(&device, &queue, swapchain_format);
&device,
&queue,
swapchain_format,
Resolution {
width: size.width,
height: size.height,
},
);
let font = include_bytes!("./Inter-Bold.ttf") as &[u8]; let font = include_bytes!("./Inter-Bold.ttf") as &[u8];
let font = Font::from_bytes(font, FontSettings::default()).unwrap(); let font = Font::from_bytes(font, FontSettings::default()).unwrap();

View file

@ -139,12 +139,7 @@ pub struct TextRenderer {
} }
impl TextRenderer { impl TextRenderer {
pub fn new( pub fn new(device: &Device, _queue: &Queue, format: TextureFormat) -> Self {
device: &Device,
_queue: &Queue,
format: TextureFormat,
screen_resolution: Resolution,
) -> Self {
let glyph_cache = HashMap::new(); let glyph_cache = HashMap::new();
let max_texture_dimension_2d = device.limits().max_texture_dimension_2d; let max_texture_dimension_2d = device.limits().max_texture_dimension_2d;
let atlas_width = max_texture_dimension_2d; let atlas_width = max_texture_dimension_2d;
@ -244,16 +239,18 @@ impl TextRenderer {
label: Some("glyphon bind group layout"), label: Some("glyphon bind group layout"),
}); });
let params = Params { screen_resolution }; let params = Params {
screen_resolution: Resolution {
let params_raw = unsafe { width: 0,
slice::from_raw_parts(&params as *const Params as *const u8, size_of::<Params>()) height: 0,
},
}; };
let params_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { let params_buffer = device.create_buffer(&BufferDescriptor {
label: Some("glyphon params"), label: Some("glyphon params"),
contents: params_raw, size: size_of::<Params>() as u64,
usage: BufferUsages::UNIFORM | BufferUsages::COPY_DST, usage: BufferUsages::UNIFORM | BufferUsages::COPY_DST,
mapped_at_creation: false,
}); });
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {