use vulkano::descriptor::descriptor_set::PersistentDescriptorSet;
use rusttype::{Font, PositionedGlyph, Scale, Rect, point, GlyphId};
use rusttype::gpu_cache::Cache;
use vulkano::buffer::{BufferAccess, BufferUsage, ImmutableBuffer, CpuAccessibleBuffer};
use vulkano::device::{Device, Queue};
use std::sync::Arc;
use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState};
use vulkano::image::{ImmutableImage, ImageUsage, ImageLayout, Dimensions};
use vulkano::format::ClearValue;
use vulkano::format::Format::R8Unorm;
use std::fs::File;
use std::io::Read;


//pub struct Glyph {}
//
///// So currently, I'm using these as container classes which vkprocessor owns
///// I then use a CanvasFrame which accumulates lists of handles and vertices.
//pub struct CanvasFonto {
//    font: Font<'static>,
//    font_name: String,
//    allocated_font_atlas: Arc<(dyn BufferAccess + Send + Sync)>,
//}
//
//impl CanvasFonto {
//
//    pub fn parse_to_vertex_buffer(font: Font) -> Vec<TextVertex3D> {
//
//        let mut current_x = 0;
//        let mut current_y = 0;
//
//        let mut accumulator = Vec::new();
//
//        for i in (0..255) {
//
//            let glyph = font.glyph(GlyphId{ 0: 40 });
//
//            let glyph_data = glyph.get_data().unwrap();
//
//            for vertex in glyph_data.clone().shape.clone().unwrap() {
//                accumulator.push(TextVertex3D {
//                    position: [vertex.x as f32, vertex.y as f32, 0.0],
//                });
//            }
//        }
//
//        accumulator
//    }
//    /// Load the font
//    pub fn new(device: Arc<Device>, queue: Arc<Queue>, font_name: String) -> CanvasFonto {
//
//        let font = Font::from_bytes({
//            let mut f = File::open("resources/fonts/sansation.ttf").expect("Font file not found");
//            let mut font_data = Vec::new();
//            f.read_to_end(&mut font_data).expect("Dont know");
//            font_data
//        }).unwrap();
//
//        CanvasFont {
//            font: font.clone(),
//            font_name: font_name,
//            allocated_font_atlas: ImmutableBuffer::from_iter(
//                CanvasFont::parse_to_vertex_buffer(font.clone()).iter().cloned(),
//                BufferUsage::vertex_buffer(), queue).unwrap().0,
//        }
//    }
//
//    /// Generate a vertex buffer from the font
//    pub fn get_vertex_buffer(&self) -> Arc<(dyn BufferAccess + Send + Sync)> {
//        return self.allocated_font_atlas.clone();
//    }
//
//}