diff --git a/notes/CanvasContainerClasses.txt b/notes/CanvasContainerClasses.txt index 37e727a5..6afe828a 100644 --- a/notes/CanvasContainerClasses.txt +++ b/notes/CanvasContainerClasses.txt @@ -13,7 +13,6 @@ All buffers will have a coupled handle type stored in the [[/src/canvas/mod.rs|c - ===== CanvasImage ===== @@ -43,7 +42,3 @@ Container class for - - - - diff --git a/notes/CanvasFrame.txt b/notes/CanvasFrame.txt index f1ae4c3c..1a4f182a 100644 --- a/notes/CanvasFrame.txt +++ b/notes/CanvasFrame.txt @@ -32,7 +32,13 @@ I like this immediate interface for this simple style of UI and drawing. @todo finish this +Now. The CanvasFrame is closely coupled with the Drawable trait, the object which allows CanvasFrame to ingest all drawable object on a single interface +Drawable needs a few things: + Handle to the Texture or Image it is using + Vertices describing it + (vertices will be character data for text) + Instances? -------------------- diff --git a/notes/CanvasState.txt b/notes/CanvasState.txt index b3490d33..2a7d2aea 100644 --- a/notes/CanvasState.txt +++ b/notes/CanvasState.txt @@ -4,7 +4,7 @@ Creation-Date: 2020-02-03T23:30:41-08:00 ====== CanvasState ====== -[[~/source/Trac3r-rust/doc/sfml_rust/canvas/struct.CanvasState.html|Documentation]] +[[/doc/sfml_rust/canvas/canvas_state/struct.CanvasState.html|Documentation]] ===== Details ===== @@ -12,7 +12,7 @@ Creation-Date: 2020-02-03T23:30:41-08:00 **window_size_dependent_setup** is currently hosted inside this class. If a second graphics class is added I will add some shared library for this to live. - **render_pass **the render pass is created with our depth stencil data **D32Sfloat_S8Uint** and the color attachment for the render output. This is highly 2D dependent + **render_pass **the render pass is created with our depth stencil/color data **D32Sfloat_S8Uint **attachment for the render output. This is highly shader dependent. Also depends on the DynamicState ===== Interface ===== @@ -22,7 +22,9 @@ Creation-Date: 2020-02-03T23:30:41-08:00 The class then interacts with these stored items by taking and executing a list of operations to perform on them. CanvasFrame - + Going to need some interface for getting vertices. + Some interface for getting the texture or image + -------------------- diff --git a/notes/Home.txt b/notes/Home.txt index f8797b25..4e26d3b1 100644 --- a/notes/Home.txt +++ b/notes/Home.txt @@ -13,10 +13,53 @@ Main Systems: Docs [[VkProcessor]] [[~/source/Trac3r-rust/doc/sfml_rust/vkprocessor/struct.VkProcessor.html|===========]] [[CanvasState]] [[~/source/Trac3r-rust/doc/sfml_rust/canvas/canvas_state/index.html|===========]] - [[DynamicVertex]] + [[DynamicVertex]] [[CompuState]] [[~/source/Trac3r-rust/doc/sfml_rust/compute/compu_state/struct.CompuState.html|===========]] +-------------------- + +====== Warming Up ====== + +Currently I'm getting my bearings again on this project. + +=== canvas === +I made a maybe(?) good change to the heirarchy of the canvas. Hiding the construction of handles from anything outside. + +Currently, canvas is separated out to the state container itself and one API class for users to interact with, in addition to a set of 'managed' objects + +Buffers and Handles are at one level, shared with text which is unrelated. + Why do I hold the shader handles (CompiledShaderHandle) + +In Shader lie the shader compilers, pipelines, and supporting data. + +**Current Question:** + Where do I put the CompiledShaderHandles? + + I need to put them where I create them. The actual shader doesn't. + + + + + + + + +-------------------- + + + + + + + + + + + + + + ├── canvas │   ├── canvas_frame.rs │   ├── canvas_state.rs diff --git a/src/canvas/canvas_frame.rs b/src/canvas/canvas_frame.rs index fbcb720c..70050252 100644 --- a/src/canvas/canvas_frame.rs +++ b/src/canvas/canvas_frame.rs @@ -1,84 +1,77 @@ use crate::util::vertex_3d::{Vertex3D}; use std::sync::Arc; use std::collections::HashMap; -use crate::canvas::canvas_state::{Drawable}; use std::hash::Hash; use crate::canvas::*; use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef; -use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle}; +use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, Handle}; use crate::canvas::managed::shader::text_shader::GlyphInstance; - -pub struct CanvasFrame { - pub colored_drawables: Vec, - pub textured_drawables: HashMap, Vec>>, - pub image_drawables: HashMap, Vec>>, - pub text_drawables: HashMap, Vec> +// I don't think this is going to work without getting into Box'ing +pub trait DrawableTest where H: Handle{ + fn get_vertices(&self) -> Vec; + fn get_instances(&self) -> Vec; + fn get_handle(&self) -> H; } -/* -This is sort of the beginning of our interface with the user definable sprites. -Will be taking in multiple type of items - -TEXT - FontHandle - VertexDefintion - color - position - instances (string) -Textured - TextureHandle - VertexDefintion - position - coords - size - -Vertex definition is directly correlated to the compiled code. How do I bucket these +pub struct DrawableTestee { + pub vertices: Vec, + pub instances: Vec, + pub handle: Arc +} -I guess I could store them and set handles like I do textures +impl DrawableTest for DrawableTestee { + fn get_vertices(&self) -> Vec { + unimplemented!() + } -The only ent that can create these vertex handles is the vkprocessor. - So Text can only get a vertex definition by going like shader.get_definition() + fn get_instances(&self) -> Vec { + unimplemented!() + } + fn get_handle(&self) -> H { + unimplemented!() + } +} -Text - FontHandle - VertexHandle -Drawable must include - shader_handle (but how to I get this to the text? this is runtime) -Okay, no. Maybe a default shader type of setup. With a shader handle override???? +pub trait Drawable { -Type: Text - Textured - Img - Color + fn get_vertices(&self) -> Vec<(f32, f32, f32)>; + fn get_color(&self) -> (f32, f32, f32, f32); + fn get_ti_coords(&self) -> Vec<(f32, f32)>; -frame.draw(text) { + fn get_texture_handle(&self) -> Option>; + fn get_image_handle(&self) -> Option>; + // fn get_text_handle(&self) -> Option>; - text.type == TEXT { // When it matches to default text shader - text_shader.get_definition() - text_shader.get_pipeline() - } - ... - else { // When the user passes in a shader - text.shader_handle.get_definition() - text.shader_handle.get_pipeline() + // These needs to return a vector of raw-ass data in addition to the definition for this data + fn collect(&self) -> Vec { + 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)] } } -// Has default shader -let text = Text::new("asdoif"); - -let frame = CanvasFrame::new(); -frame.draw(text); +pub trait VertexDefinitionAndData { -vkprocessor.run(frame); +} -*/ +pub struct CanvasFrame { + pub colored_drawables: Vec, + pub textured_drawables: HashMap, Vec>>, + pub image_drawables: HashMap, Vec>>, + pub text_drawables: HashMap, Vec> +} impl CanvasFrame { @@ -92,6 +85,19 @@ impl CanvasFrame { } } + // +// pub fn draw_test(&mut self, drawable: &dyn DrawableTest) { +// let h = drawable.get_handle(); +// +// let v = drawable.get_vertices(); +// +// let v = v.get(0).unwrap(); +// +// // need to fill up the drawables.... +// +// +// } + // TODO: Fix this for text and fonts /// Accumulates the drawables collected Vertex2D's @@ -118,25 +124,4 @@ impl CanvasFrame { } } } -} - -pub struct GenericCanvasFrame { - frame_data: HashMap, Vec)>> -} -// -//impl GenericCanvasFrame { -// -// /// Creates a bare canvas frame with empty accumulators -// pub fn new() -> GenericCanvasFrame { -// GenericCanvasFrame { -// frame_data: Default::default() -// } -// } -// -// pub fn draw(&mut self, drawable: &dyn DrawableTest) { -// self.frame_data -// .entry(drawable.get_handle().clone()) -// .or_insert(Vec::new()) -// .push((drawable.get_vertices(), drawable.get_instances())); -// } -//} \ No newline at end of file +} \ No newline at end of file diff --git a/src/canvas/canvas_state.rs b/src/canvas/canvas_state.rs index c1239b1d..47b69a45 100644 --- a/src/canvas/canvas_state.rs +++ b/src/canvas/canvas_state.rs @@ -29,47 +29,13 @@ use std::io::Read; use rusttype::{Font, PositionedGlyph, Scale, Rect, point, GlyphId, Line, Curve, Segment}; use vulkano::pipeline::vertex::VertexDefinition; use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef; -use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, CompiledGraphicsPipelineHandle, Handle}; +use crate::canvas::managed::handles::{CanvasTextureHandle, CanvasImageHandle, CanvasFontHandle, CompiledShaderHandle, Handle}; use crate::canvas::managed::gpu_buffers::{CanvasImage, CanvasTexture, CanvasFont}; use crate::canvas::managed::shader::shader_common::CompiledGraphicsPipeline; use crate::canvas::managed::shader::generic_shader::GenericShader; -// I don't think this is going to work without getting into Box'ing -pub trait DrawableTest { - fn get_vertices(&self) -> Vec; - fn get_instances(&self) -> Vec; - fn get_handle(&self) -> H; -} - - - -/// A drawable object can be passed into a CanvasFrame to be rendered -/// Very generic implementation. (N % 2 == 0) vertices, ditto for texture coords, and rgba color -/// Provides Image and Texture handles for drawing - -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>; - fn get_image_handle(&self) -> Option>; - // fn get_text_handle(&self) -> Option>; - - fn collect(&self) -> Vec { - 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)] - } -} /// 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 @@ -308,10 +274,10 @@ impl CanvasState { pub fn load_shader(&mut self, filename: String, physical: PhysicalDevice, - capabilities: Capabilities) -> Option> + capabilities: Capabilities) -> Option> where T: CompiledGraphicsPipeline { - let handle = Arc::new(CompiledGraphicsPipelineHandle { + let handle = Arc::new(CompiledShaderHandle { handle: self.shader_buffers.len() as u32 }); @@ -396,7 +362,7 @@ impl CanvasState { /// Using the shader name, iterates through the stored shaders and matches by the name pub fn get_shader_handle(&self, shader_name: String) - -> Option> { + -> Option> { for shader in self.shader_buffers.clone() { if shader.get_name() == shader_name { return Some(shader.get_handle().clone()); diff --git a/src/canvas/managed/handles.rs b/src/canvas/managed/handles.rs index a44f0f50..d4f41628 100644 --- a/src/canvas/managed/handles.rs +++ b/src/canvas/managed/handles.rs @@ -41,23 +41,11 @@ impl Handle for CanvasImageHandle { /// Typed wrapper for a u32 handle #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] -pub struct CanvasShaderHandle { +pub struct CompiledShaderHandle { pub(in crate::canvas) handle: u32 } -impl Handle for CanvasShaderHandle { - fn get_handle(&self) -> u32 { - self.handle - } -} - -/// Typed wrapper for a u32 handle -#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] -pub struct CompiledGraphicsPipelineHandle { - pub(in crate::canvas) handle: u32 -} - -impl Handle for CompiledGraphicsPipelineHandle { +impl Handle for CompiledShaderHandle { fn get_handle(&self) -> u32 { self.handle } diff --git a/src/canvas/managed/shader/generic_shader.rs b/src/canvas/managed/shader/generic_shader.rs index 7dae70dd..730362f7 100644 --- a/src/canvas/managed/shader/generic_shader.rs +++ b/src/canvas/managed/shader/generic_shader.rs @@ -16,7 +16,7 @@ use shade_runner as sr; use vulkano::memory::pool::PotentialDedicatedAllocation::Generic; use vulkano::SafeDeref; use crate::canvas::managed::shader::shader_common::{ShaderType, CompiledGraphicsPipelineResources, CompiledGraphicsPipeline}; -use crate::canvas::managed::handles::CompiledGraphicsPipelineHandle; +use crate::canvas::managed::handles::CompiledShaderHandle; use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef; use crate::canvas::managed::ShaderSpecializationConstants; @@ -25,7 +25,7 @@ use crate::canvas::managed::ShaderSpecializationConstants; pub struct GenericShader { graphics_pipeline: Option>, - handle: Arc, + handle: Arc, name: String, device: Arc, @@ -43,9 +43,9 @@ impl CompiledGraphicsPipeline for GenericShader { /// This will explode when the shader does not want to compile fn new(filename: String, - device: Arc, - handle: Arc, - render_pass: Arc) -> GenericShader { + device: Arc, + handle: Arc, + render_pass: Arc) -> GenericShader { let compiled_vertex = GenericShader::compile( GenericShader::get_path(filename.clone(), ShaderType::VERTEX), @@ -122,7 +122,7 @@ impl CompiledGraphicsPipeline for GenericShader { self.name.clone() } - fn get_handle(&self) -> Arc { + fn get_handle(&self) -> Arc { self.handle.clone() } diff --git a/src/canvas/managed/shader/shader_common.rs b/src/canvas/managed/shader/shader_common.rs index 299e474b..fa87ecc0 100644 --- a/src/canvas/managed/shader/shader_common.rs +++ b/src/canvas/managed/shader/shader_common.rs @@ -8,7 +8,7 @@ use vulkano::pipeline::shader::{ShaderModule, GraphicsShaderType, GeometryShader use vulkano::device::Device; use shade_runner::Entry; use shaderc::ShaderKind; -use crate::canvas::managed::handles::CompiledGraphicsPipelineHandle; +use crate::canvas::managed::handles::CompiledShaderHandle; /* @@ -102,10 +102,10 @@ pub trait CompiledGraphicsPipelineResources { pub trait CompiledGraphicsPipeline { fn new(filename: String, device: Arc, - handle: Arc, + handle: Arc, render_pass: Arc) -> Self where Self: Sized; fn get_name(&self) -> String; - fn get_handle(&self) -> Arc; + fn get_handle(&self) -> Arc; fn get_pipeline(&self) -> Arc; fn get_renderpass(&self) -> Arc; fn recompile(self, render_pass: Arc) diff --git a/src/canvas/managed/shader/text_shader.rs b/src/canvas/managed/shader/text_shader.rs index 9683663e..53349852 100644 --- a/src/canvas/managed/shader/text_shader.rs +++ b/src/canvas/managed/shader/text_shader.rs @@ -13,7 +13,7 @@ use vulkano::pipeline::vertex::{SingleBufferDefinition, OneVertexOneInstanceDefi use crate::util::vertex_3d::Vertex3D; use shade_runner as sr; use crate::canvas::managed::shader::shader_common::{ShaderType, CompiledGraphicsPipelineResources, CompiledGraphicsPipeline}; -use crate::canvas::managed::handles::CompiledGraphicsPipelineHandle; +use crate::canvas::managed::handles::CompiledShaderHandle; use crate::canvas::managed::shader::generic_shader::GenericShader; use crate::canvas::managed::shader::dynamic_vertex::RuntimeVertexDef; use crate::canvas::managed::ShaderSpecializationConstants; @@ -32,7 +32,7 @@ vulkano::impl_vertex!(GlyphInstance, screen_position, atlas_position, atlas_size pub struct TextShader { graphics_pipeline: Option>, - handle: Arc, + handle: Arc, name: String, device: Arc, @@ -50,7 +50,7 @@ impl CompiledGraphicsPipeline for TextShader { /// This will explode when the shader does not want to compile fn new(filename: String, device: Arc, - handle: Arc, + handle: Arc, render_pass: Arc) -> TextShader { let compiled_vertex = GenericShader::compile( @@ -151,7 +151,7 @@ impl CompiledGraphicsPipeline for TextShader { self.name.clone() } - fn get_handle(&self) -> Arc { + fn get_handle(&self) -> Arc { self.handle.clone() } diff --git a/src/compute/compu_frame.rs b/src/compute/compu_frame.rs index 775e2d96..50f76633 100644 --- a/src/compute/compu_frame.rs +++ b/src/compute/compu_frame.rs @@ -1,8 +1,8 @@ -use crate::canvas::canvas_state::{Drawable}; 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)> diff --git a/src/compute/compu_state.rs b/src/compute/compu_state.rs index a8533982..7f6efcc8 100644 --- a/src/compute/compu_state.rs +++ b/src/compute/compu_state.rs @@ -1,7 +1,6 @@ use std::ffi::CStr; use vulkano::buffer::{CpuAccessibleBuffer, BufferUsage}; use std::sync::Arc; -use crate::canvas::canvas_state::{Drawable, CanvasState}; use vulkano::framebuffer::RenderPassAbstract; use vulkano::pipeline::{GraphicsPipelineAbstract, ComputePipeline}; use vulkano::device::Device; @@ -23,6 +22,7 @@ use crate::canvas::managed::handles::Handle; use crate::compute::managed::compu_buffer::CompuBuffers; use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle}; use crate::compute::managed::compu_kernel::CompuKernel; +use crate::canvas::canvas_state::CanvasState; /// State holding the compute buffers for computation and the kernels which will compute them diff --git a/src/compute/managed/compu_sprite.rs b/src/compute/managed/compu_sprite.rs index 7fd358d0..de3e78b0 100644 --- a/src/compute/managed/compu_sprite.rs +++ b/src/compute/managed/compu_sprite.rs @@ -1,6 +1,6 @@ -use crate::canvas::canvas_state::{Drawable}; 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], diff --git a/src/main.rs b/src/main.rs index 3d325787..7aa05c8a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,8 +25,9 @@ use crate::util::load_raw; use crate::sprite::{Poly, Text, TextHandle, TextVertex, TextInstance}; use vulkano::instance::debug::DebugCallback; use crate::compute::compu_frame::CompuFrame; -use crate::canvas::canvas_frame::{CanvasFrame, GenericCanvasFrame}; +use crate::canvas::canvas_frame::{CanvasFrame, DrawableTestee}; use crate::compute::managed::compu_sprite::CompuSprite; +use std::sync::Arc; pub mod util; @@ -86,6 +87,17 @@ pub fn main() { processor.preload_fonts(); } + let mut v = vec![]; + + let d = DrawableTestee { + vertices: vec![], + instances: vec![], + handle: Arc::new(Default::default()) + }; + + v.push(d); + + let q2 = hprof::enter("Game Objects"); let mut timer = Timer::new(); diff --git a/src/sprite.rs b/src/sprite.rs index 24cd2905..574e1a8b 100644 --- a/src/sprite.rs +++ b/src/sprite.rs @@ -3,7 +3,7 @@ use crate::util::vertex_3d::Vertex3D; use crate::canvas::*; use crate::canvas::managed::handles::{CanvasFontHandle, CanvasImageHandle, CanvasTextureHandle}; use crate::canvas::managed::shader::text_shader::GlyphInstance; -use crate::canvas::canvas_state::{DrawableTest, Drawable}; +use crate::canvas::canvas_frame::{DrawableTest, Drawable}; /// #[derive(Debug, Clone)] @@ -98,21 +98,6 @@ impl Sprite { } } } - -impl DrawableTest for Sprite { - fn get_vertices(&self) -> Vec { - unimplemented!() - } - - fn get_instances(&self) -> Vec { - unimplemented!() - } - - fn get_handle(&self) -> H { - unimplemented!() - } -} - impl Drawable for Sprite { fn get_vertices(&self) -> Vec<(f32, f32, f32)> { self.vertices.to_vec() @@ -302,17 +287,3 @@ pub trait TextInstance { pub trait TextVertex { fn get_vertices() -> Vec<(u32, u32, u32)>; } - -impl DrawableTest for Text { - fn get_vertices(&self) -> Vec { - unimplemented!() - } - - fn get_instances(&self) -> Vec { - unimplemented!() - } - - fn get_handle(&self) -> H { - unimplemented!() - } -} \ No newline at end of file diff --git a/src/vkprocessor.rs b/src/vkprocessor.rs index 49f2039e..1953b6bd 100644 --- a/src/vkprocessor.rs +++ b/src/vkprocessor.rs @@ -19,7 +19,7 @@ use crate::util::vertex_3d::Vertex3D; use crate::canvas::canvas_state::CanvasState; use crate::canvas::managed::shader::generic_shader::GenericShader; use crate::canvas::managed::shader::text_shader::TextShader; -use crate::canvas::managed::handles::{CanvasTextureHandle, CompiledGraphicsPipelineHandle, CanvasFontHandle, CanvasImageHandle}; +use crate::canvas::managed::handles::{CanvasTextureHandle, CompiledShaderHandle, CanvasFontHandle, CanvasImageHandle}; use crate::compute::managed::handles::{CompuKernelHandle, CompuBufferHandle}; @@ -190,7 +190,7 @@ impl<'a> VkProcessor<'a> { } /// O(n) Lookup for the matching shader string - pub fn get_shader_handle(&self, shader_name: String) -> Option> { + pub fn get_shader_handle(&self, shader_name: String) -> Option> { self.canvas_state.get_shader_handle(shader_name) }