oh my god it compiles. A month of brainstorming comes out to a single enum
This commit is contained in:
@@ -42,7 +42,14 @@ Drawable needs a few things:
|
|||||||
|
|
||||||
The handle is queiried and then turned into a descriptor set in the draw_commands.
|
The handle is queiried and then turned into a descriptor set in the draw_commands.
|
||||||
|
|
||||||
|
* What if I pass using function params? But then how do I store???
|
||||||
|
|
||||||
|
==== Problem ====
|
||||||
|
I need to store vectors of multiple unequal types in a vec
|
||||||
|
|
||||||
|
vec<vec<T>>
|
||||||
|
|
||||||
|
Why can't I pass in
|
||||||
|
|
||||||
|
|
||||||
--------------------
|
--------------------
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::util::vertex_3d::{Vertex3D};
|
use crate::util::vertex_3d::Vertex3D;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
@@ -7,63 +7,95 @@ use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
|
|||||||
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, Handle};
|
use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, Handle};
|
||||||
use crate::canvas::managed::shader::text_shader::GlyphInstance;
|
use crate::canvas::managed::shader::text_shader::GlyphInstance;
|
||||||
use vulkano::pipeline::vertex::Vertex;
|
use vulkano::pipeline::vertex::Vertex;
|
||||||
|
use std::any::Any;
|
||||||
|
|
||||||
|
|
||||||
// I don't think this is going to work without getting into Box'ing
|
// I don't think this is going to work without getting into Box'ing
|
||||||
pub trait DrawableTest<V, H> where H: Handle{
|
pub trait DrawableTest<V, H> where H: Handle {
|
||||||
fn get_vertices(&self) -> Vec<V>;
|
fn get_vertices(&self) -> Vec<V>;
|
||||||
fn get_handle(&self) -> H;
|
fn get_handle(&self) -> H;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub struct DrawableTestee {
|
|
||||||
pub vertices: Vec<ImplVertexData>,
|
|
||||||
pub handle: Arc<CanvasTextureHandle>
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<V, H: Handle> DrawableTest<V, H> for DrawableTestee {
|
mod dynhash {
|
||||||
fn get_vertices(&self) -> Vec<V> {
|
use std::any::Any;
|
||||||
unimplemented!()
|
use std::hash::{Hash, Hasher};
|
||||||
|
|
||||||
|
pub trait DynEq: Any {
|
||||||
|
fn dyn_eq(&self, other: &dyn DynEq) -> bool;
|
||||||
|
|
||||||
|
fn as_any(&self) -> &dyn Any;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_handle(&self) -> H {
|
pub trait DynHash: DynEq {
|
||||||
unimplemented!()
|
fn dyn_hash(&self, hasher: &mut dyn Hasher);
|
||||||
|
|
||||||
|
fn as_dyn_eq(&self) -> &dyn DynEq;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<H: Eq + Any> DynEq for H {
|
||||||
|
fn dyn_eq(&self, other: &dyn DynEq) -> bool {
|
||||||
|
if let Some(other) = other.as_any().downcast_ref::<H>() {
|
||||||
|
self == other
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any(&self) -> &dyn Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<H: Hash + DynEq> DynHash for H {
|
||||||
|
fn dyn_hash(&self, mut hasher: &mut dyn Hasher) {
|
||||||
|
H::hash(self, &mut hasher)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_dyn_eq(&self) -> &dyn DynEq {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialEq for dyn DynHash {
|
||||||
|
fn eq(&self, other: &dyn DynHash) -> bool {
|
||||||
|
self.dyn_eq(other.as_dyn_eq())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Eq for dyn DynHash {}
|
||||||
|
|
||||||
|
impl Hash for dyn DynHash {
|
||||||
|
fn hash<H: Hasher>(&self, hasher: &mut H) {
|
||||||
|
self.dyn_hash(hasher)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
use crate::canvas::canvas_frame::dynhash::DynHash;
|
||||||
|
|
||||||
pub struct ImplVertexData {
|
|
||||||
pub x: i32,
|
|
||||||
pub y: i32,
|
|
||||||
}
|
|
||||||
impl VertexData for ImplVertexData {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait VertexData : Sized {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// CanvasFrameTest will be drawn to by objects implementing DrawableTest
|
// CanvasFrameTest will be drawn to by objects implementing DrawableTest
|
||||||
pub struct CanvasFrameTest<V: VertexData + Sized, H: Handle + Sized> {
|
pub struct CanvasFrameTest<VTypes> {
|
||||||
pub map: HashMap<H, Vec<V>>,
|
pub map: HashMap<Box<dyn DynHash>, Vec<VTypes>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<V: VertexData + Sized, H: Handle + Sized + Eq + Hash> CanvasFrameTest<V, H> {
|
impl<VTypes> CanvasFrameTest<VTypes> {
|
||||||
|
pub fn draw(&mut self, drawable: Vec<VTypes>) {
|
||||||
pub fn draw(&mut self, drawable: &dyn DrawableTest<V, H>) {
|
self.map.insert(Box::new(10), drawable);
|
||||||
drawable.get_vertices();
|
|
||||||
self.map.insert(drawable.get_handle(), drawable.get_vertices());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Drawable {
|
pub trait Drawable {
|
||||||
|
|
||||||
fn get_vertices(&self) -> Vec<(f32, f32, f32)>;
|
fn get_vertices(&self) -> Vec<(f32, f32, f32)>;
|
||||||
fn get_color(&self) -> (f32, f32, f32, f32);
|
fn get_color(&self) -> (f32, f32, f32, f32);
|
||||||
fn get_ti_coords(&self) -> Vec<(f32, f32)>;
|
fn get_ti_coords(&self) -> Vec<(f32, f32)>;
|
||||||
|
|
||||||
fn get_texture_handle(&self) -> Option<Arc<CanvasTextureHandle>>;
|
fn get_texture_handle(&self) -> Option<Arc<CanvasTextureHandle>>;
|
||||||
fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>>;
|
fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>>;
|
||||||
// fn get_text_handle(&self) -> Option<Arc<CanvasTextHandle>>;
|
// fn get_text_handle(&self) -> Option<Arc<CanvasTextHandle>>;
|
||||||
|
|
||||||
// These needs to return a vector of raw-ass data in addition to the definition for this data
|
// These needs to return a vector of raw-ass data in addition to the definition for this data
|
||||||
fn collect(&self) -> Vec<RuntimeVertexDef> {
|
fn collect(&self) -> Vec<RuntimeVertexDef> {
|
||||||
@@ -74,36 +106,30 @@ pub trait Drawable {
|
|||||||
// color: [color.0, color.1, color.2, color.3],
|
// color: [color.0, color.1, color.2, color.3],
|
||||||
// ti_position: [b.0, b.1],
|
// ti_position: [b.0, b.1],
|
||||||
// }).collect()
|
// }).collect()
|
||||||
// TODO
|
// TODO
|
||||||
vec![RuntimeVertexDef::from_primitive(0)]
|
vec![RuntimeVertexDef::from_primitive(0)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub trait VertexDefinitionAndData {}
|
||||||
|
|
||||||
pub trait VertexDefinitionAndData {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub struct CanvasFrame {
|
pub struct CanvasFrame {
|
||||||
pub colored_drawables: Vec<RuntimeVertexDef>,
|
pub colored_drawables: Vec<RuntimeVertexDef>,
|
||||||
pub textured_drawables: HashMap<Arc<CanvasTextureHandle>, Vec<Vec<RuntimeVertexDef>>>,
|
pub textured_drawables: HashMap<Arc<CanvasTextureHandle>, Vec<Vec<RuntimeVertexDef>>>,
|
||||||
pub image_drawables: HashMap<Arc<CanvasImageHandle>, Vec<Vec<RuntimeVertexDef>>>,
|
pub image_drawables: HashMap<Arc<CanvasImageHandle>, Vec<Vec<RuntimeVertexDef>>>,
|
||||||
pub text_drawables: HashMap<Arc<CanvasFontHandle>, Vec<GlyphInstance>>
|
pub text_drawables: HashMap<Arc<CanvasFontHandle>, Vec<GlyphInstance>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CanvasFrame {
|
impl CanvasFrame {
|
||||||
|
|
||||||
/// Creates a bare canvas frame with empty accumulators a
|
/// Creates a bare canvas frame with empty accumulators a
|
||||||
pub fn new() -> CanvasFrame {
|
pub fn new() -> CanvasFrame {
|
||||||
CanvasFrame {
|
CanvasFrame {
|
||||||
colored_drawables: vec![],
|
colored_drawables: vec![],
|
||||||
textured_drawables: Default::default(),
|
textured_drawables: Default::default(),
|
||||||
image_drawables: Default::default(),
|
image_drawables: Default::default(),
|
||||||
text_drawables: Default::default()
|
text_drawables: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ use vulkano::swapchain::Capabilities;
|
|||||||
use winit::Window;
|
use winit::Window;
|
||||||
use vulkano::pipeline::viewport::Viewport;
|
use vulkano::pipeline::viewport::Viewport;
|
||||||
use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer;
|
use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer;
|
||||||
use crate::canvas::canvas_frame::{CanvasFrame, CanvasFrameTest, VertexData};
|
use crate::canvas::canvas_frame::{CanvasFrame, CanvasFrameTest};
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use crate::util::vertex_3d::{Vertex3D, TextVertex3D};
|
use crate::util::vertex_3d::{Vertex3D, TextVertex3D};
|
||||||
use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue};
|
use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue};
|
||||||
@@ -69,6 +69,7 @@ pub struct CanvasState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl CanvasState {
|
impl CanvasState {
|
||||||
/// This method is called once during initialization, then again whenever the window is resized
|
/// This method is called once during initialization, then again whenever the window is resized
|
||||||
pub fn window_size_dependent_setup(&mut self, images: &[Arc<SwapchainImage<Window>>])
|
pub fn window_size_dependent_setup(&mut self, images: &[Arc<SwapchainImage<Window>>])
|
||||||
@@ -484,23 +485,62 @@ impl CanvasState {
|
|||||||
o
|
o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// This is taking in a canvas frame, which should be some sort of matrix of vertices of generic
|
// This is taking in a canvas frame, which should be some sort of matrix of vertices of generic
|
||||||
// types and handles
|
// types and handles
|
||||||
pub fn draw_commands_test<V: 'static + VertexData + Sized + Clone + Send + Sync, H: Handle + Sized>
|
pub fn draw_commands_test<T: 'static + Send + Sync + Clone>(&mut self,
|
||||||
(&mut self,
|
|
||||||
mut command_buffer: AutoCommandBufferBuilder,
|
mut command_buffer: AutoCommandBufferBuilder,
|
||||||
framebuffers: Vec<Arc<dyn FramebufferAbstract + Send + Sync>>,
|
framebuffers: Vec<Arc<dyn FramebufferAbstract + Send + Sync>>,
|
||||||
image_num: usize,
|
image_num: usize,
|
||||||
canvas_frame: CanvasFrameTest<V, H>) -> AutoCommandBufferBuilder {
|
canvas_frame: CanvasFrameTest<T>) -> AutoCommandBufferBuilder {
|
||||||
|
|
||||||
let v = Vec::<V>::new();
|
// Specify the color to clear the framebuffer with i.e. blue
|
||||||
|
let clear_values = vec!(
|
||||||
|
ClearValue::Float([0.0, 0.0, 1.0, 1.0]),
|
||||||
|
ClearValue::DepthStencil((1.0, 0x00)),
|
||||||
|
);
|
||||||
|
|
||||||
let x = ImmutableBuffer::from_iter(
|
self.dynamic_state = DynamicState {
|
||||||
v.iter().cloned(),
|
line_width: None,
|
||||||
BufferUsage::all(),
|
viewports: self.dynamic_state.viewports.clone(),
|
||||||
|
scissors: None,
|
||||||
|
compare_mask: None,
|
||||||
|
write_mask: None,
|
||||||
|
reference: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut command_buffer = command_buffer.begin_render_pass(
|
||||||
|
framebuffers[image_num].clone(), false, clear_values.clone(),
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
// Solid colors
|
||||||
|
let mut shader = self.shader_buffers.get(
|
||||||
|
self.get_shader_handle(String::from("color-passthrough"))
|
||||||
|
.unwrap().clone().get_handle() as usize
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (k,v) in canvas_frame.map {
|
||||||
|
|
||||||
|
let value : Vec<T> = v.iter().map(|v| v.clone()).collect();
|
||||||
|
|
||||||
|
let buffer : Arc<(dyn BufferAccess + Send + Sync)> = ImmutableBuffer::from_iter(
|
||||||
|
value.iter().cloned(),
|
||||||
|
BufferUsage::vertex_buffer(),
|
||||||
self.queue.clone(),
|
self.queue.clone(),
|
||||||
).unwrap().0;
|
).unwrap().0;
|
||||||
|
|
||||||
|
if !self.colored_vertex_buffer.is_empty() {
|
||||||
|
command_buffer = command_buffer.draw(
|
||||||
|
shader.get_pipeline().clone(),
|
||||||
|
&self.dynamic_state.clone(),
|
||||||
|
vec![buffer.clone()],
|
||||||
|
(), (),
|
||||||
|
).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
command_buffer
|
command_buffer
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
33
src/main.rs
33
src/main.rs
@@ -25,7 +25,7 @@ use crate::util::load_raw;
|
|||||||
use crate::sprite::{Poly, Text, TextHandle, TextVertex, TextInstance};
|
use crate::sprite::{Poly, Text, TextHandle, TextVertex, TextInstance};
|
||||||
use vulkano::instance::debug::DebugCallback;
|
use vulkano::instance::debug::DebugCallback;
|
||||||
use crate::compute::compu_frame::CompuFrame;
|
use crate::compute::compu_frame::CompuFrame;
|
||||||
use crate::canvas::canvas_frame::{CanvasFrame, DrawableTestee, CanvasFrameTest, ImplVertexData};
|
use crate::canvas::canvas_frame::{CanvasFrame, CanvasFrameTest};
|
||||||
use crate::compute::managed::compu_sprite::CompuSprite;
|
use crate::compute::managed::compu_sprite::CompuSprite;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use crate::canvas::managed::handles::CanvasTextureHandle;
|
use crate::canvas::managed::handles::CanvasTextureHandle;
|
||||||
@@ -55,6 +55,23 @@ pub mod compute;
|
|||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
pub struct ImplVertexData1 {
|
||||||
|
pub x: i32,
|
||||||
|
pub y: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ImplVertexData2 {
|
||||||
|
pub x: i32,
|
||||||
|
pub y: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ImplVertexData1 {}
|
||||||
|
impl ImplVertexData2 {}
|
||||||
|
|
||||||
|
enum VertexTypes {
|
||||||
|
VType1(ImplVertexData1),
|
||||||
|
VType2(ImplVertexData2),
|
||||||
|
}
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
hprof::start_frame();
|
hprof::start_frame();
|
||||||
@@ -182,12 +199,14 @@ pub fn main() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let dt = DrawableTestee{
|
// let dt = DrawableTestee{
|
||||||
vertices: vec![ImplVertexData{ x: 0, y: 0 }],
|
// vertices: vec![ImplVertexData{ x: 0, y: 0 }],
|
||||||
handle: Arc::new(Default::default())
|
// handle: Arc::new(CanvasTextureHandle{ handle: 0 })
|
||||||
};
|
// };
|
||||||
let mut cft :CanvasFrameTest<ImplVertexData, CanvasTextureHandle>= CanvasFrameTest{ map: Default::default() };
|
let mut cft : CanvasFrameTest<VertexTypes> =
|
||||||
cft.draw(&dt);
|
CanvasFrameTest{ map: Default::default() };
|
||||||
|
|
||||||
|
// cft.draw(&dt);
|
||||||
|
|
||||||
let mut compu_frame = CompuFrame::new();
|
let mut compu_frame = CompuFrame::new();
|
||||||
// compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
// compu_frame.add(compute_buffer.clone(), compute_kernel.clone());
|
||||||
|
|||||||
Reference in New Issue
Block a user