bringing docs up to date
This commit is contained in:
@@ -7,153 +7,23 @@ use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, Ca
|
||||
use crate::canvas::managed::shader::text_shader::GlyphInstance;
|
||||
use vulkano::pipeline::vertex::Vertex;
|
||||
use std::any::Any;
|
||||
|
||||
|
||||
|
||||
|
||||
pub mod dynhash {
|
||||
use std::any::Any;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
pub trait DynEq: Any {
|
||||
fn dyn_eq(&self, other: &dyn DynEq) -> bool;
|
||||
|
||||
fn as_any(&self) -> &dyn Any;
|
||||
}
|
||||
|
||||
pub trait DynHash: DynEq {
|
||||
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;
|
||||
use crate::VertexTypes;
|
||||
|
||||
|
||||
|
||||
pub trait DrawableTest {
|
||||
/// Trait which may be inherited by objects that wish to be drawn to the screen
|
||||
pub trait Drawable {
|
||||
fn get(&self) -> VertexTypes;
|
||||
}
|
||||
|
||||
/// Accumulator for Vectors of VertexTypes
|
||||
#[derive(Default)]
|
||||
pub struct CanvasFrameTest {
|
||||
pub struct CanvasFrame {
|
||||
pub map: Vec<VertexTypes>,
|
||||
}
|
||||
|
||||
impl CanvasFrameTest {
|
||||
pub fn draw(&mut self, drawable: &dyn DrawableTest) {
|
||||
impl CanvasFrame {
|
||||
|
||||
/// Push this drawable onto the back of the accumulator
|
||||
pub fn draw(&mut self, drawable: &dyn Drawable) {
|
||||
self.map.push(drawable.get());
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Drawable {
|
||||
fn get_vertices(&self) -> Vec<(f32, f32, f32)>;
|
||||
fn get_color(&self) -> (f32, f32, f32, f32);
|
||||
fn get_ti_coords(&self) -> Vec<(f32, f32)>;
|
||||
|
||||
fn get_texture_handle(&self) -> Option<Arc<CanvasTextureHandle>>;
|
||||
fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>>;
|
||||
// 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
|
||||
fn collect(&self) -> Vec<RuntimeVertexDef> {
|
||||
let color = self.get_color();
|
||||
// self.get_vertices().iter().zip(self.get_ti_coords().iter()).map(|(a, b)|
|
||||
// Vertex3D {
|
||||
// v_position: [a.0, a.1, a.2],
|
||||
// color: [color.0, color.1, color.2, color.3],
|
||||
// ti_position: [b.0, b.1],
|
||||
// }).collect()
|
||||
// TODO
|
||||
vec![RuntimeVertexDef::from_primitive(0)]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub trait VertexDefinitionAndData {}
|
||||
|
||||
|
||||
pub struct CanvasFrame {
|
||||
pub colored_drawables: Vec<RuntimeVertexDef>,
|
||||
pub textured_drawables: HashMap<Arc<CanvasTextureHandle>, Vec<Vec<RuntimeVertexDef>>>,
|
||||
pub image_drawables: HashMap<Arc<CanvasImageHandle>, Vec<Vec<RuntimeVertexDef>>>,
|
||||
pub text_drawables: HashMap<Arc<CanvasFontHandle>, Vec<GlyphInstance>>,
|
||||
}
|
||||
|
||||
impl CanvasFrame {
|
||||
/// Creates a bare canvas frame with empty accumulators a
|
||||
pub fn new() -> CanvasFrame {
|
||||
CanvasFrame {
|
||||
colored_drawables: vec![],
|
||||
textured_drawables: Default::default(),
|
||||
image_drawables: Default::default(),
|
||||
text_drawables: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: Fix this for text and fonts
|
||||
/// Accumulates the drawables collected Vertex2D's
|
||||
pub fn draw(&mut self, drawable: &dyn Drawable) {
|
||||
match drawable.get_texture_handle() {
|
||||
Some(handle) => {
|
||||
self.textured_drawables
|
||||
.entry(handle.clone())
|
||||
.or_insert(Vec::new())
|
||||
.push(drawable.collect());
|
||||
}
|
||||
None => {
|
||||
match drawable.get_image_handle() {
|
||||
Some(handle) => {
|
||||
self.image_drawables
|
||||
.entry(handle.clone())
|
||||
.or_insert(Vec::new())
|
||||
.push(drawable.collect());
|
||||
}
|
||||
None => {
|
||||
self.colored_drawables.extend(drawable.collect());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ use vulkano::swapchain::Capabilities;
|
||||
use winit::Window;
|
||||
use vulkano::pipeline::viewport::Viewport;
|
||||
use vulkano::descriptor::descriptor::DescriptorDescTy::TexelBuffer;
|
||||
use crate::canvas::canvas_frame::{CanvasFrame, CanvasFrameTest};
|
||||
use crate::canvas::canvas_frame::{CanvasFrame};
|
||||
use std::hash::Hash;
|
||||
use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue};
|
||||
use vulkano::memory::pool::PotentialDedicatedAllocation::Generic;
|
||||
@@ -45,15 +45,15 @@ pub struct CanvasState {
|
||||
/// Generated during new()
|
||||
sampler: Arc<Sampler>,
|
||||
|
||||
// hold the image, texture, and Fonts 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>>,
|
||||
font_buffers: Vec<Arc<CanvasFont>>,
|
||||
|
||||
// Compiled Graphics pipelines have a handle which self describe their position in this vector
|
||||
/// Compiled Graphics pipelines have a handle which self describe their position in this vector
|
||||
shader_buffers: Vec<Arc<Box<dyn CompiledGraphicsPipeline>>>,
|
||||
|
||||
// Looks like we gotta hold onto the queue for managing textures
|
||||
/// Looks like we gotta hold onto the queue for managing textures
|
||||
queue: Arc<Queue>,
|
||||
device: Arc<Device>,
|
||||
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>,
|
||||
@@ -260,6 +260,7 @@ impl CanvasState {
|
||||
physical: PhysicalDevice,
|
||||
capabilities: Capabilities) -> Option<Arc<CompiledShaderHandle>>
|
||||
where T: CompiledGraphicsPipeline {
|
||||
|
||||
let handle = Arc::new(CompiledShaderHandle {
|
||||
handle: self.shader_buffers.len() as u32
|
||||
});
|
||||
@@ -385,8 +386,8 @@ impl CanvasState {
|
||||
o
|
||||
}
|
||||
|
||||
/// Consume and allocated the canvas frame data to the GPU
|
||||
pub fn allocate(&mut self, canvas_frame: CanvasFrameTest) -> CanvasFrameAllocation {
|
||||
/// Consume and allocate the canvas frame data to the GPU
|
||||
pub fn allocate(&mut self, canvas_frame: CanvasFrame) -> CanvasFrameAllocation {
|
||||
|
||||
let mut colored_vertex_buffer: Vec<ColorVertex2D> = Vec::default();
|
||||
let mut textured_vertex_buffer: HashMap<Arc<CanvasTextureHandle>, Vec<TextureVertex2D>> = HashMap::new();
|
||||
|
||||
@@ -18,6 +18,7 @@ use crate::canvas::managed::shader::shader_common::{ShaderType, CompiledGraphics
|
||||
use crate::canvas::managed::handles::CompiledShaderHandle;
|
||||
use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef;
|
||||
use crate::canvas::managed::ShaderSpecializationConstants;
|
||||
use crate::util::vertex::VertexTypes;
|
||||
|
||||
/// CanvasShader holds the pipeline and render pass for the input shader source
|
||||
#[derive(Clone)]
|
||||
@@ -32,7 +33,12 @@ pub struct GenericShader {
|
||||
}
|
||||
|
||||
|
||||
impl GenericShader {}
|
||||
impl GenericShader {
|
||||
|
||||
fn get(&self) -> VertexTypes {
|
||||
VertexTypes::ImageType
|
||||
}
|
||||
}
|
||||
|
||||
/// Gives CanvasShader the resource functions
|
||||
impl CompiledGraphicsPipelineResources for GenericShader {}
|
||||
|
||||
@@ -2,7 +2,6 @@ use std::sync::Arc;
|
||||
use crate::canvas::managed::handles::{CanvasImageHandle};
|
||||
use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle};
|
||||
use crate::compute::managed::compu_sprite::CompuSprite;
|
||||
use crate::canvas::canvas_frame::Drawable;
|
||||
|
||||
pub struct CompuFrame {
|
||||
// Vec<(Buffer, Kernel)>
|
||||
@@ -52,6 +51,6 @@ impl CompuFrame {
|
||||
buffer: Arc<CompuBufferHandle>,
|
||||
kernel: Arc<CompuKernelHandle>,
|
||||
sprite: &CompuSprite) {
|
||||
self.swapped_to_image.push((buffer, sprite.get_image_handle().unwrap().clone(), kernel))
|
||||
// self.swapped_to_image.push((buffer, sprite.get_image_handle().unwrap().clone(), kernel))
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
use std::sync::Arc;
|
||||
use crate::canvas::managed::handles::{CanvasImageHandle, CanvasTextureHandle};
|
||||
use crate::canvas::canvas_frame::Drawable;
|
||||
|
||||
pub struct CompuSprite {
|
||||
pub vertices: [(f32, f32, f32); 6],
|
||||
@@ -48,24 +47,3 @@ impl CompuSprite {
|
||||
}
|
||||
}
|
||||
|
||||
impl Drawable for CompuSprite {
|
||||
fn get_vertices(&self) -> Vec<(f32, f32, f32)> {
|
||||
self.vertices.to_vec()
|
||||
}
|
||||
|
||||
fn get_color(&self) -> (f32, f32, f32, f32) {
|
||||
self.color
|
||||
}
|
||||
|
||||
fn get_ti_coords(&self) -> Vec<(f32, f32)> {
|
||||
self.ti_position.to_vec()
|
||||
}
|
||||
|
||||
fn get_texture_handle(&self) -> Option<Arc<CanvasTextureHandle>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>> {
|
||||
Some(self.image_handle.clone())
|
||||
}
|
||||
}
|
||||
@@ -24,11 +24,10 @@ use crate::util::load_raw;
|
||||
|
||||
use vulkano::instance::debug::DebugCallback;
|
||||
use crate::compute::compu_frame::CompuFrame;
|
||||
use crate::canvas::canvas_frame::{CanvasFrame, CanvasFrameTest, DrawableTest};
|
||||
use crate::canvas::canvas_frame::{CanvasFrame, Drawable};
|
||||
use crate::compute::managed::compu_sprite::CompuSprite;
|
||||
use std::sync::Arc;
|
||||
use crate::canvas::managed::handles::{CanvasTextureHandle, Handle};
|
||||
use crate::canvas::canvas_frame::dynhash::DynHash;
|
||||
use crate::util::vertex::{VertexTypes, TextureVertex2D};
|
||||
|
||||
|
||||
@@ -187,7 +186,7 @@ pub fn main() {
|
||||
|
||||
let funky_sprite = Sprite::new((0.0, -0.5), (0.5, 0.5), 0, funky_handle.clone());
|
||||
|
||||
let mut canvas_frame = CanvasFrameTest::default();
|
||||
let mut canvas_frame = CanvasFrame::default();
|
||||
canvas_frame.draw(&funky_sprite);
|
||||
canvas_frame.draw(&sfml_sprite);
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@ use std::sync::Arc;
|
||||
use crate::canvas::*;
|
||||
use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle, Handle};
|
||||
use crate::canvas::managed::shader::text_shader::GlyphInstance;
|
||||
use crate::canvas::canvas_frame::{DrawableTest, Drawable};
|
||||
use crate::canvas::canvas_frame::dynhash::DynHash;
|
||||
use crate::canvas::canvas_frame::{Drawable};
|
||||
use crate::util::vertex::{VertexTypes, TextureVertex2D, Vertex3D};
|
||||
|
||||
///
|
||||
@@ -34,7 +33,7 @@ impl Sprite {
|
||||
}
|
||||
}
|
||||
}
|
||||
impl DrawableTest for Sprite{
|
||||
impl Drawable for Sprite{
|
||||
fn get(&self) -> VertexTypes {
|
||||
self.verts.clone()
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use winit::Window;
|
||||
use crate::compute::compu_state::CompuState;
|
||||
use vulkano::image::ImageUsage;
|
||||
use crate::compute::compu_frame::CompuFrame;
|
||||
use crate::canvas::canvas_frame::{CanvasFrame, CanvasFrameTest};
|
||||
use crate::canvas::canvas_frame::{CanvasFrame};
|
||||
use std::time::Duration;
|
||||
use vulkano::pipeline::depth_stencil::{DynamicStencilValue, StencilFaceFlags};
|
||||
use vulkano::pipeline::vertex::{OneVertexOneInstanceDefinition, SingleBufferDefinition};
|
||||
@@ -226,7 +226,7 @@ impl<'a> VkProcessor<'a> {
|
||||
pub fn run(&mut self,
|
||||
surface: &'a Arc<Surface<Window>>,
|
||||
//canvas_frame: CanvasFrame,
|
||||
canvas_frame: CanvasFrameTest,
|
||||
canvas_frame: CanvasFrame,
|
||||
compute_frame: CompuFrame,
|
||||
) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user