Guest User

Untitled

a guest
Jul 10th, 2024
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. let face = self.library.new_face(path, 0).unwrap();
  2. face.set_pixel_sizes(0, 48).unwrap();
  3. let mut characters = Vec::with_capacity(CHARACTERS_SIZE);
  4. for char in 33..CHARACTERS_SIZE {
  5. face.load_char(char, freetype::face::LoadFlag::RENDER)
  6. .unwrap();
  7. let glyph = face.glyph();
  8. let bitmap = glyph.bitmap();
  9.  
  10. let image_size = Extent2D {
  11. width: bitmap.width() as u32,
  12. height: bitmap.rows() as u32,
  13. };
  14.  
  15. // Reusing the sampler
  16. let texture = VulkanImage::new(
  17. instance,
  18. bitmap.buffer(),
  19. image_size,
  20. vk::Format::R8G8B8A8_UNORM,
  21. Some(SamplerInfo::default()),
  22. );
  23.  
  24. // TODO: store everything in an Texture Atlas
  25. let descriptor_sets = VulkanInstance::allocate_descriptor_sets(
  26. &instance.device,
  27. instance.descriptor_pool, // TODO: use own descriptor_pool
  28. descriptor_set_layout,
  29. instance.swapchain_images.len(),
  30. );
  31.  
  32. for &descriptor_set in descriptor_sets.iter() {
  33. let image_info = vk::DescriptorImageInfo::default()
  34. .image_layout(vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL)
  35. .image_view(texture.image_view)
  36. .sampler(texture.sampler);
  37.  
  38. let desc_sets = [vk::WriteDescriptorSet {
  39. dst_set: descriptor_set,
  40. dst_binding: 0, // From DescriptorSetLayoutBinding
  41. descriptor_count: 1,
  42. descriptor_type: vk::DescriptorType::COMBINED_IMAGE_SAMPLER,
  43. p_image_info: &image_info,
  44. ..Default::default()
  45. }];
  46. unsafe {
  47. instance.device.update_descriptor_sets(&desc_sets, &[]);
  48. }
  49. }
  50.  
  51. let character = Character {
  52. descriptor_sets,
  53. size: IVec2::new(bitmap.width(), bitmap.rows()),
  54. bearing: IVec2::new(glyph.bitmap_left(), glyph.bitmap_top()),
  55. advance: glyph.advance().x as u32,
  56. };
  57. characters.push(character);
  58. }
  59. Font {
  60. characters,
  61. buffer_cache: HashMap::new(),
  62. }
Advertisement
Add Comment
Please, Sign In to add comment