diagramming out what I want to do here. CanvasFont will live with the buffers. Need to figure out how and where I'm going to query the font data for rendering
This commit is contained in:
@@ -1 +0,0 @@
|
||||
<mxfile modified="2019-09-17T05:36:48.980Z" host="www.draw.io" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/76.0.3809.100 Chrome/76.0.3809.100 Safari/537.36" etag="BK448PY-Hn1syjU6_G00" version="11.2.8" type="device" pages="1"><diagram id="eBoc7Yustm6TUbQq-vnT" name="Page-1">7Vtbc5s4FP41ntl9SMdC4MtjbafdTtOZzHhnmz4qIGM1gDxCxHZ//R7ZAgwyDmkdC3fXL0FHAsH3nZt0lB6expuPgqyWX3hAo57TDzY9POs5DvLcPvxRkq2W4PFoLwkFC7SsFMzZD6qF+sYwYwFNKwMl55Fkq6rQ50lCfVmRESH4ujpswaPqrCsS6hn7pWDuk4gaw76yQC7zt4Nf2fMXZeFSGl0xycdrQbokAV8fiPBtD08F53J/FW+mNFIA5tDs7/vQ0Fu8m6CJbHODM4nZEGfjLERPaXj3/e7jbHODvP1jnkmU6Y+eZIsFFSCb8kQSllCR9pxBBHNMHkE8CNXV7yLZESO3OeGCZ0lAFWB96F4vmaTzFfFV7xp0HGRLGUfQQnAZkUca3fOUScYTkPlABACHJ89USAZadFcbELMgUDNNSMTCo3e81x3FSM0OdNNNI++o0CYwRcpjKsUWhugb8EgroLbCG6zb61KlnbGWLQ+U2clVmWgzCotnl2oGF1rTXqN1yNC6KUmeSfo33chM0F/j5RyYjauYOSZkyDkC2eDNEHMaEPsUKx/WNbxQ3zpg+ISKTYm/tA9aER87o2TuCcy6Ypp11DqgaoMG2OYQ8VUkrYedP3wer1gEmY3KZ9TXsxWNINL+aR1dI1gg61rpmJb8hSTg9VIDLRpA+qabXMglD3lCottSOqniWY6543ylUfxOpdzqXJRkwA+eAHhi+6D7d41v6gnvvLw52+gn7ltb3TK4US94mhn4Hp4Jn7bI2SQRIZWnBg6Pcy1oRCR7rr7J+XlzL8bPAc50w+RDTgZcHxAFrZIn1dgekvZQZfRbhdDj9J6T08FVcIqHrW0RfJCsUiNoyn6Qx90ABd+Ks0Tu3tCb9LzZq/LiXe49If5TuNOYKY+42M2LF7vfKW+oV4v6TXoHi7+StxMa3eg7b0B9+iPtrVrzoR93r8A4GMIXixQUoU5YMevPc5jHzyuyy5rbdV7yu+c0zGFLw8Rjm4aJTMPc5yDWMwrkvrz8PJpQoPGbZRSOVQsotL6IMa+OTOiCBjC6isiUv6ZhAB8Eie2vWupWUKTL9tJqcw/GhlWcU1PHbTV1ZDWHMjX1ve9ncQaT/0fyqNO2AgEe5TuE28qM3U2qct07IHUmyFphYz8Eu51zPtjczjxlA1eWn14wPc1Zezk97R9XkQvtBfTN6MzjVSY7YiC17eshsm4gZl3u0pteZzOOd31IDasG4rovmMiudU8FAzhVBDu73bTdQ8PYqt38X5797cuzw6rvcYem77lwedZpKmh0pQZUr1J49osUTfsvHanP1gAbWC+aOU3r9Q7VZ3HntMxcZXSwQIu7pmt4cHVJk739Ptx6RWE1M8INK4pubPc5XucWFEeOXCm8PlORqGOb13RGoZYxFcHNHrjmwZlrXa3ZK4HnGtpxx+Oiq+MUVuCQblVW4K5newWOcVu6rRZW8ZFzhMpvziWR9uMMqsUZt60rRKM384VmjvrP073gPk1TLqwjdoPqR1XbhmZv4L0aMmiWB/z3tYbyXyXw7b8=</diagram></mxfile>
|
||||
57
notes
57
notes
@@ -1,57 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
StorageImage
|
||||
General-purpose image in device memory.
|
||||
AttachmentImage
|
||||
ImageAccess whose purpose is to be used as a framebuffer attachment
|
||||
|
||||
|
||||
|
||||
|
||||
Hello!
|
||||
|
||||
Any of you guys use the Vulkano library? There is this PersistentDescriptorSetBuilder struct
|
||||
which uses this fun chaining dynamic
|
||||
|
||||
```
|
||||
PersistentDescriptorSet::start(layout, 0)
|
||||
.add_sampled_image(sampled_image1).unwrap()
|
||||
.add_sampled_image(sampled_image2).unwrap()
|
||||
.add_sampled_image(sampled_image3).unwrap()
|
||||
.build().unwrap();
|
||||
```
|
||||
|
||||
But it modifies the return values template values so I can't store it between loops
|
||||
|
||||
```
|
||||
let mut set_builder = PersistentDescriptorSet::start(layout, 0);
|
||||
for image in images {
|
||||
set_builder = set_builder.add_sampled_image(image);
|
||||
}
|
||||
let descriptor_set = set_builder.build().unwrap();
|
||||
```
|
||||
|
||||
The gist of the error that I get is something like:
|
||||
|
||||
```
|
||||
expected:
|
||||
PersistentDescriptorSetBuilder<Arc<GraphicsPipelineAbstract>, ()>
|
||||
got:
|
||||
PersistentDescriptorSetBuilder<Arc<GraphicsPipelineAbstract>, ((), PersistentDescriptorSetImg<Arc<ImmutableImage<Format>>>)>
|
||||
```
|
||||
|
||||
So it's adding tuples of tuples of tuples of tuples of tuples each time I chain a
|
||||
.add_sampled_image() call. I really really want to be able to do this dynamically in
|
||||
a loop; I've tried this neat iter().fold() thinking that if I didn't explicitly
|
||||
overwrite the previous returned value, rust would figure it out. It didn't
|
||||
|
||||
```
|
||||
let descriptor_set = images.iter().fold(
|
||||
PersistentDescriptorSet::start(layout, 0)
|
||||
,|a, &b| a.add_image(b))
|
||||
.unwrap()).build().unwrap();
|
||||
```
|
||||
|
||||
How do I do this dynamically?
|
||||
@@ -5,9 +5,10 @@ use vulkano::format::{Format, R8Unorm};
|
||||
use vulkano::sampler::Sampler;
|
||||
use vulkano::descriptor::DescriptorSet;
|
||||
use vulkano::descriptor::descriptor_set::PersistentDescriptorSet;
|
||||
use vulkano::buffer::CpuAccessibleBuffer;
|
||||
use vulkano::buffer::{CpuAccessibleBuffer, BufferAccess};
|
||||
use vulkano::pipeline::GraphicsPipelineAbstract;
|
||||
use crate::canvas::canvas_text::CanvasFontHandle;
|
||||
use rusttype::Font;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CanvasTexture {
|
||||
@@ -52,10 +53,15 @@ impl CanvasImage {
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CanvasText {
|
||||
pub struct CanvasFont {
|
||||
pub(crate) handle: Arc<CanvasImageHandle>,
|
||||
pub(crate) buffer: Arc<(dyn BufferAccess + Send + Sync)>, // Font atlas
|
||||
pub(crate) font: Font<'static>,
|
||||
pub(crate) name: String,
|
||||
|
||||
}
|
||||
|
||||
impl CanvasText {
|
||||
impl CanvasFont {
|
||||
pub fn get_descriptor_set(pipeline: Arc<dyn GraphicsPipelineAbstract + Sync + Send>)
|
||||
-> Box<dyn DescriptorSet + Send + Sync> {
|
||||
let o: Box<dyn DescriptorSet + Send + Sync> = Box::new(
|
||||
|
||||
@@ -36,6 +36,13 @@ use crate::canvas::shader::text_shader::GlyphInstance;
|
||||
/// Provides Image and Texture handles for drawing
|
||||
/// Split out to two drawables?
|
||||
///
|
||||
|
||||
//
|
||||
pub trait DrawableTest<V, H> {
|
||||
fn get_vertices(&self) -> Vec<V>;
|
||||
fn get_handle(&self) -> Vec<H>;
|
||||
}
|
||||
|
||||
pub trait Drawable {
|
||||
fn get_vertices(&self) -> Vec<(f32, f32, f32)>;
|
||||
fn get_color(&self) -> (f32, f32, f32, f32);
|
||||
@@ -68,6 +75,12 @@ pub struct CanvasImageHandle {
|
||||
pub handle: u32
|
||||
}
|
||||
|
||||
/// Typed wrapper for a u32 font handle (index id)
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
||||
pub struct CanvasFontHandle {
|
||||
pub handle: u32
|
||||
}
|
||||
|
||||
/// Canvas state is used for storage of texture and image buffers in addition to vertex buffers
|
||||
/// Canvas state also contains logic for writing the stored buffers to the command_buffer
|
||||
#[derive(Clone)]
|
||||
@@ -77,14 +90,13 @@ pub struct CanvasState {
|
||||
/// Generated during new()
|
||||
sampler: Arc<Sampler>,
|
||||
|
||||
// hold the image, texture, and shader buffers the same was as we do CompuState
|
||||
// hold the image, texture, and Fonts the same was as we do CompuState
|
||||
image_buffers: Vec<Arc<CanvasImage>>,
|
||||
texture_buffers: Vec<Arc<CanvasTexture>>,
|
||||
shader_buffers: Vec<Arc<Box<dyn CompiledGraphicsPipeline>>>,
|
||||
|
||||
// Individually hold onto the Fonts
|
||||
font_buffers: Vec<Arc<CanvasFont>>,
|
||||
|
||||
shader_buffers: Vec<Arc<Box<dyn CompiledGraphicsPipeline>>>,
|
||||
|
||||
// Hold onto the vertices we get from the Compu and Canvas Frames
|
||||
// When the run comes around, push the vertices to the GPU
|
||||
colored_vertex_buffer: Vec<Arc<(dyn BufferAccess + Send + Sync)>>,
|
||||
|
||||
@@ -98,140 +98,4 @@ impl CanvasFont {
|
||||
return self.allocated_font_atlas.clone();
|
||||
}
|
||||
|
||||
/// postpone this until caching
|
||||
pub fn queue_text(&mut self,
|
||||
x: f32, y: f32,
|
||||
size: f32, color: [f32; 4],
|
||||
text: &str) {
|
||||
let glyphs: Vec<PositionedGlyph> = self.font.layout(text, Scale::uniform(size), point(x, y)).map(|x| x.standalone()).collect();
|
||||
// for glyph in &glyphs {
|
||||
// self.cache.queue_glyph(0, glyph.clone());
|
||||
// }
|
||||
// self.texts.push(TextData {
|
||||
// glyphs: glyphs.clone(),
|
||||
// color: color,
|
||||
// });
|
||||
}
|
||||
|
||||
pub fn draw_text(&mut self,
|
||||
command_buffer: AutoCommandBufferBuilder,
|
||||
image_num: usize,
|
||||
) -> AutoCommandBufferBuilder {
|
||||
|
||||
// let screen_width = 0;
|
||||
// let screen_height = 0;
|
||||
//
|
||||
// let cache_pixel_buffer = &mut self.cache_pixel_buffer;
|
||||
// let cache = &mut self.cache;
|
||||
//
|
||||
// // update texture cache
|
||||
// cache.cache_queued(
|
||||
// |rect, src_data| {
|
||||
// let width = (rect.max.x - rect.min.x) as usize;
|
||||
// let height = (rect.max.y - rect.min.y) as usize;
|
||||
// let mut dst_index = rect.min.y as usize * CACHE_WIDTH + rect.min.x as usize;
|
||||
// let mut src_index = 0;
|
||||
//
|
||||
// for _ in 0..height {
|
||||
// let dst_slice = &mut cache_pixel_buffer[dst_index..dst_index+width];
|
||||
// let src_slice = &src_data[src_index..src_index+width];
|
||||
// dst_slice.copy_from_slice(src_slice);
|
||||
//
|
||||
// dst_index += CACHE_WIDTH;
|
||||
// src_index += width;
|
||||
// }
|
||||
// }
|
||||
// ).unwrap();
|
||||
//
|
||||
// // need to get a hold of the cache buffer handle after I create it
|
||||
// // will then get swapped into this texture buffer
|
||||
// // Hmmm so this uninit call returns the texture and then a handle for whatever fills it up
|
||||
// let (cache_texture, cache_texture_write) = ImmutableImage::uninitialized(
|
||||
// self.device.clone(),
|
||||
// Dimensions::Dim2d { width: CACHE_WIDTH as u32, height: CACHE_HEIGHT as u32 },
|
||||
// R8Unorm,
|
||||
// 1,
|
||||
// ImageUsage {
|
||||
// sampled: true,
|
||||
// transfer_destination: true,
|
||||
// .. ImageUsage::none()
|
||||
// },
|
||||
// ImageLayout::General,
|
||||
// Some(self.queue.family())
|
||||
// ).unwrap();
|
||||
//
|
||||
//
|
||||
//
|
||||
// let set = Arc::new(
|
||||
// PersistentDescriptorSet::start(self.pipeline.clone(), 0)
|
||||
// .add_sampled_image(cache_texture.clone(), sampler).unwrap()
|
||||
// .build().unwrap()
|
||||
// );
|
||||
//
|
||||
// let mut command_buffer = command_buffer
|
||||
// .copy_buffer_to_image(
|
||||
// buffer.clone(),
|
||||
// cache_texture_write,
|
||||
// ).unwrap()
|
||||
// .begin_render_pass(self.framebuffers[image_num].clone(), false, vec!(ClearValue::None)).unwrap();
|
||||
//
|
||||
// // draw
|
||||
// for text in &mut self.texts.drain(..) {
|
||||
// let vertices: Vec<Vertex2D> = text.glyphs.iter().flat_map(|g| {
|
||||
// if let Ok(Some((uv_rect, screen_rect))) = cache.rect_for(0, g) {
|
||||
// let gl_rect = Rect {
|
||||
// min: point(
|
||||
// (screen_rect.min.x as f32 / screen_width as f32 - 0.5) * 2.0,
|
||||
// (screen_rect.min.y as f32 / screen_height as f32 - 0.5) * 2.0
|
||||
// ),
|
||||
// max: point(
|
||||
// (screen_rect.max.x as f32 / screen_width as f32 - 0.5) * 2.0,
|
||||
// (screen_rect.max.y as f32 / screen_height as f32 - 0.5) * 2.0
|
||||
// )
|
||||
// };
|
||||
// vec!(
|
||||
//// Vertex {
|
||||
//// position: [gl_rect.min.x, gl_rect.max.y],
|
||||
//// tex_position: [uv_rect.min.x, uv_rect.max.y],
|
||||
//// color: text.color,
|
||||
//// },
|
||||
//// Vertex {
|
||||
//// position: [gl_rect.min.x, gl_rect.min.y],
|
||||
//// tex_position: [uv_rect.min.x, uv_rect.min.y],
|
||||
//// color: text.color,
|
||||
//// },
|
||||
//// Vertex {
|
||||
//// position: [gl_rect.max.x, gl_rect.min.y],
|
||||
//// tex_position: [uv_rect.max.x, uv_rect.min.y],
|
||||
//// color: text.color,
|
||||
//// },
|
||||
////
|
||||
//// Vertex {
|
||||
//// position: [gl_rect.max.x, gl_rect.min.y],
|
||||
//// tex_position: [uv_rect.max.x, uv_rect.min.y],
|
||||
//// color: text.color,
|
||||
//// },
|
||||
//// Vertex {
|
||||
//// position: [gl_rect.max.x, gl_rect.max.y],
|
||||
//// tex_position: [uv_rect.max.x, uv_rect.max.y],
|
||||
//// color: text.color,
|
||||
//// },
|
||||
//// Vertex {
|
||||
//// position: [gl_rect.min.x, gl_rect.max.y],
|
||||
//// tex_position: [uv_rect.min.x, uv_rect.max.y],
|
||||
//// color: text.color,
|
||||
//// },
|
||||
// ).into_iter()
|
||||
// }
|
||||
// else {
|
||||
// vec!().into_iter()
|
||||
// }
|
||||
// }).collect();
|
||||
//
|
||||
// let vertex_buffer = CpuAccessibleBuffer::from_iter(self.device.clone(), BufferUsage::all(), vertices.into_iter()).unwrap();
|
||||
// command_buffer = command_buffer.draw(self.pipeline.clone(), &DynamicState::none(), vertex_buffer.clone(), set.clone(), ()).unwrap();
|
||||
// }
|
||||
|
||||
command_buffer//.end_render_pass().unwrap()
|
||||
}
|
||||
}
|
||||
19
src/main.rs
19
src/main.rs
@@ -97,6 +97,13 @@ pub fn main() {
|
||||
let funky_sprite = Sprite::new_with_texture((0.0, -0.5), (0.5, 0.5), 0, funky_handle.clone());
|
||||
let sfml_sprite = Sprite::new_with_texture((0.0, -0.5), (0.5, 0.5), 1, sfml_handle.clone());
|
||||
|
||||
|
||||
// ========================
|
||||
// Creating a new text... This is just something to interface with the
|
||||
// canvas_frame. So it can be mutable
|
||||
let text_sprite = TextSprite::new();
|
||||
|
||||
|
||||
let test_polygon = Poly::new_with_color((-0.5, -0.5), (0.5, 0.5), 1, (1.0,0.0,0.0,0.0));
|
||||
|
||||
drop(q2);
|
||||
@@ -156,16 +163,18 @@ pub fn main() {
|
||||
compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
||||
compu_frame.add_with_image_swap(compute_buffer.clone(), compute_kernel.clone(), &compu_sprite1);
|
||||
|
||||
if elapsed_time > (count) as f32 {
|
||||
count += 1;
|
||||
compu_frame.add_chained(compute_buffer.clone(), compute_buffer.clone(), compute_kernel.clone());
|
||||
}
|
||||
// if elapsed_time > (count) as f32 {
|
||||
// count += 1;
|
||||
// compu_frame.add_chained(compute_buffer.clone(), compute_buffer.clone(), compute_kernel.clone());
|
||||
// }
|
||||
|
||||
let mut canvas = CanvasFrame::new();
|
||||
|
||||
canvas.draw(&funky_sprite);
|
||||
canvas.draw(&test_polygon);
|
||||
|
||||
|
||||
|
||||
|
||||
{
|
||||
let g = hprof::enter("Run");
|
||||
processor.run(&surface,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::canvas::canvas_state::{Drawable, CanvasTextureHandle, CanvasImageHandle};
|
||||
use crate::canvas::canvas_state::{Drawable, CanvasTextureHandle, CanvasImageHandle, DrawableTest};
|
||||
use std::sync::Arc;
|
||||
use crate::canvas::shader::text_shader::GlyphInstance;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Sprite {
|
||||
@@ -14,6 +15,7 @@ pub struct Sprite {
|
||||
textured: bool,
|
||||
texture_handle: Option<Arc<CanvasTextureHandle>>,
|
||||
|
||||
value: GlyphInstance,
|
||||
}
|
||||
|
||||
/// Container class which implements drawable.
|
||||
@@ -52,7 +54,13 @@ impl Sprite {
|
||||
size: size,
|
||||
color: color,
|
||||
textured: false,
|
||||
texture_handle: None
|
||||
texture_handle: None,
|
||||
value: GlyphInstance {
|
||||
screen_position: (0.0, 0.0),
|
||||
atlas_position: (0.0, 0.0),
|
||||
atlas_size: (0.0, 0.0),
|
||||
scale: 0.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +101,16 @@ impl Sprite {
|
||||
|
||||
}
|
||||
|
||||
impl<V, H> DrawableTest<V, H> for Sprite {
|
||||
fn get_vertices(&self) -> Vec<V> {
|
||||
|
||||
}
|
||||
|
||||
fn get_handle(&self) -> Vec<H> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl Drawable for Sprite {
|
||||
|
||||
fn get_vertices(&self) -> Vec<(f32,f32,f32)> {
|
||||
@@ -135,6 +153,9 @@ pub struct Poly {
|
||||
textured: bool,
|
||||
texture_handle: Option<Arc<CanvasTextureHandle>>,
|
||||
|
||||
// ==================================
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// Container class which implements drawable.
|
||||
@@ -248,3 +269,77 @@ impl Drawable for Poly {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Poly {
|
||||
|
||||
pub vertices: Vec<(f32, f32, f32)>,
|
||||
pub ti_position: Vec<(f32, f32)>,
|
||||
|
||||
position: (f32, f32),
|
||||
size: (f32, f32),
|
||||
color: (f32, f32, f32, f32),
|
||||
|
||||
textured: bool,
|
||||
texture_handle: Option<Arc<CanvasTextureHandle>>,
|
||||
|
||||
// ==================================
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// Container class which implements drawable.
|
||||
impl Poly {
|
||||
|
||||
pub fn new(position: (f32, f32), size: (f32, f32)) -> Poly {
|
||||
Poly::new_with_color(position, size, 0, (0.,0.,0.,0.))
|
||||
}
|
||||
|
||||
pub fn new_with_color(position: (f32, f32),
|
||||
size: (f32, f32),
|
||||
depth: u32,
|
||||
color: (f32, f32, f32, f32)) -> Poly {
|
||||
|
||||
let normalized_depth = (depth as f32 / 255.0);
|
||||
|
||||
Poly {
|
||||
vertices: vec![],
|
||||
|
||||
position: position,
|
||||
ti_position: vec![],
|
||||
size: size,
|
||||
color: color,
|
||||
textured: false,
|
||||
texture_handle: None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drawable for Poly {
|
||||
|
||||
fn get_vertices(&self) -> Vec<(f32,f32,f32)> {
|
||||
self.vertices.to_vec()
|
||||
}
|
||||
|
||||
fn get_color(&self) -> (f32, f32, f32, f32) {
|
||||
self.color.clone()
|
||||
}
|
||||
|
||||
fn get_ti_coords(&self) -> Vec<(f32, f32)> {
|
||||
self.ti_position.to_vec()
|
||||
}
|
||||
|
||||
fn get_texture_handle(&self) -> Option<Arc<CanvasTextureHandle>> {
|
||||
match self.textured {
|
||||
true => {
|
||||
self.texture_handle.clone()
|
||||
},
|
||||
false => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user