This commit is contained in:
2021-08-15 22:34:29 +02:00
parent c619f945a3
commit 40aa7f635e
11 changed files with 273 additions and 56 deletions

View File

@@ -10,9 +10,9 @@ use player::Player;
use crate::{config::LogConfig, vulkan};
use crate::input::InputState;
use crate::vulkan::{Game, MeshHandle, TextureHandle, Vertex, VulkanRenderer};
use crate::vulkan::{Game, MeshHandle, TextVertex, Vertex, VulkanRenderer};
use crate::vulkan::gameobject::{GameObject, GameObjectHandle, Updatable};
use crate::vulkan::mesh::{self, CPUMesh};
use crate::vulkan::mesh::{self, CPUMesh, CPUVertex};
use crate::vulkan::pipelines::vs::ty::ObjectUniformData;
pub mod player;
@@ -119,30 +119,30 @@ impl TestGame {
let font = FontArc::try_from_slice(include_bytes!("../../models/OverpassRegular.ttf")).unwrap();
let mut glyph_brush = GlyphBrushBuilder::using_font(font).build();
glyph_brush.queue(Section::default().add_text(Text::new("rRRRRRRRRRRRRRr")));
glyph_brush.queue(Section::default().add_text(Text::new("penis lol")));
match glyph_brush.process_queued(|rect, text_data| {
renderer.upload_texture(text_data, rect.width(), rect.height(), Format::R8Srgb, renderer.device.clone());
renderer.upload_texture(text_data, rect.width(), rect.height(), Format::R8Unorm, renderer.device.clone());
self.texture_index_counter += 1;
}, |vertex_data| {
vec![
Vertex { position: [vertex_data.pixel_coords.min.x, vertex_data.pixel_coords.min.y, 0.], uv: [vertex_data.tex_coords.min.x, vertex_data.tex_coords.min.y], normal: [0., 0., 1.], ..Default::default() },
Vertex { position: [vertex_data.pixel_coords.min.x, vertex_data.pixel_coords.max.y, 0.], uv: [vertex_data.tex_coords.min.x, vertex_data.tex_coords.max.y], normal: [0., 0., 1.], ..Default::default() },
]
println!("vd: {:?}", vertex_data);
let result = vec![
TextVertex { position: [vertex_data.pixel_coords.min.x, vertex_data.pixel_coords.min.y, 0.], uv: [vertex_data.tex_coords.min.x, vertex_data.tex_coords.min.y * 256. / 10.], normal: [0., 0., 1.] },
TextVertex { position: [vertex_data.pixel_coords.min.x, vertex_data.pixel_coords.max.y, 0.], uv: [vertex_data.tex_coords.min.x, vertex_data.tex_coords.max.y * 256. / 10.], normal: [0., 0., 1.] },
TextVertex { position: [vertex_data.pixel_coords.max.x, vertex_data.pixel_coords.min.y, 0.], uv: [vertex_data.tex_coords.max.x, vertex_data.tex_coords.min.y * 256. / 10.], normal: [0., 0., 1.] },
TextVertex { position: [vertex_data.pixel_coords.max.x, vertex_data.pixel_coords.max.y, 0.], uv: [vertex_data.tex_coords.max.x, vertex_data.tex_coords.max.y * 256. / 10.], normal: [0., 0., 1.] },
];
result
}) {
Ok(BrushAction::Draw(quads)) => {
let mut final_vertices = vec![];
let mut final_indices = vec![];
let mut height = 0.2;
let mut index_offset = 2;
final_vertices.push(Vertex { position: [0., 0., 0.], uv: [0., 0.], normal: [0., 0., 1.], ..Default::default() });
final_vertices.push(Vertex { position: [0., height, 0.], uv: [0., 1.], normal: [0., 0., 1.], ..Default::default() });
let mut final_indices: Vec<u32> = vec![];
let mut index_offset = 0;
for quad in quads {
final_vertices.append(&mut quad.clone());
final_indices.append(&mut [0, 2, 3, 0, 3, 1].iter().map(|x| *x + index_offset - 2).collect());
final_vertices.append(&mut quad.iter().map(|v| CPUVertex::VertexText(v.clone())).collect());
final_indices.append(&mut [0, 2, 3, 0, 3, 1].iter().map(|x| *x + index_offset).collect());
index_offset += quad.len() as u32;
}
println!("v: {:?}", final_vertices);
println!("i: {:?}", final_indices);
let mesh = CPUMesh {
vertices: final_vertices,
indices: final_indices,
@@ -156,9 +156,10 @@ impl TestGame {
diffuse_handle: self.texture_index_counter - 1,
normal_handle: None,
original_path: None,
pipeline_index: 1
};
let mut game_object_handle = self.add_game_object(renderer, mesh_handle);
game_object_handle.get_game_object_mut(renderer).unwrap().scale = vec3(10., 10., 10.);
game_object_handle.get_game_object_mut(renderer).unwrap().scale = vec3(0.1, 0.1, 0.1);
self.game_objects.push(game_object_handle);
},
Ok(BrushAction::ReDraw) => {},
@@ -178,7 +179,7 @@ impl TestGame {
let mut mesh_handles = Vec::new();
// Load file
let (meshes, document) = mesh::load_mesh(gltf_path, self.log_config.mesh_load_info).unwrap();
let (meshes, document) = mesh::load_mesh::<Vertex>(gltf_path, self.log_config.mesh_load_info).unwrap();
for cpu_mesh in meshes.into_iter() {
// Convert file texture id to game texture id
@@ -191,7 +192,8 @@ impl TestGame {
index: mesh_id,
diffuse_handle: diffuse_id,
normal_handle: Some(normal_id),
original_path: Some(gltf_path.to_string())
original_path: Some(gltf_path.to_string()),
pipeline_index: 0
};
mesh_handles.push(mesh_handle);
}
@@ -211,7 +213,7 @@ impl TestGame {
pub fn add_game_object(&mut self, renderer: &mut VulkanRenderer, mesh: MeshHandle) -> GameObjectHandle {
let obj = GameObject::new(mesh);
let obj_handle = renderer.add_game_object(obj, 0);
let obj_handle = renderer.add_game_object(obj);
self.game_objects.push(obj_handle);
self.game_objects.last().unwrap().clone()
}