going to save here. re-evaluating drawable now that runtimevertexdef is in

This commit is contained in:
2020-02-05 20:02:06 -08:00
parent 1fde36e42c
commit 0c1f513225
16 changed files with 166 additions and 198 deletions

View File

@@ -1,13 +1,70 @@
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;
// I don't think this is going to work without getting into Box'ing
pub trait DrawableTest<V, H, In> where H: Handle{
fn get_vertices(&self) -> Vec<V>;
fn get_instances(&self) -> Vec<In>;
fn get_handle(&self) -> H;
}
pub struct DrawableTestee {
pub vertices: Vec<u32>,
pub instances: Vec<u32>,
pub handle: Arc<CanvasTextureHandle>
}
impl<V, H: Handle, In> DrawableTest<V, H, In> for DrawableTestee {
fn get_vertices(&self) -> Vec<V> {
unimplemented!()
}
fn get_instances(&self) -> Vec<In> {
unimplemented!()
}
fn get_handle(&self) -> H {
unimplemented!()
}
}
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>,
@@ -16,70 +73,6 @@ pub struct CanvasFrame {
pub text_drawables: HashMap<Arc<CanvasFontHandle>, Vec<GlyphInstance>>
}
/*
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
I guess I could store them and set handles like I do textures
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()
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????
Type: Text
Textured
Img
Color
frame.draw(text) {
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()
}
}
// Has default shader
let text = Text::new("asdoif");
let frame = CanvasFrame::new();
frame.draw(text);
vkprocessor.run(frame);
*/
impl CanvasFrame {
/// Creates a bare canvas frame with empty accumulators a
@@ -92,6 +85,19 @@ impl CanvasFrame {
}
}
//
// pub fn draw_test<V : VertexDefinitionAndData, H: Handle, In>(&mut self, drawable: &dyn DrawableTest<V, H, In>) {
// 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<H, V, In> {
frame_data: HashMap<H, Vec<(Vec<V>, Vec<In>)>>
}
//
//impl<V, In> GenericCanvasFrame<Vertex3D, V, In> {
//
// /// Creates a bare canvas frame with empty accumulators
// pub fn new() -> GenericCanvasFrame<Vertex3D, V, In> {
// GenericCanvasFrame {
// frame_data: Default::default()
// }
// }
//
// pub fn draw(&mut self, drawable: &dyn DrawableTest<V, Vertex3D, In>) {
// self.frame_data
// .entry(drawable.get_handle().clone())
// .or_insert(Vec::new())
// .push((drawable.get_vertices(), drawable.get_instances()));
// }
//}
}

View File

@@ -29,48 +29,14 @@ 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<V, H, In> {
fn get_vertices(&self) -> Vec<V>;
fn get_instances(&self) -> Vec<In>;
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<Arc<CanvasTextureHandle>>;
fn get_image_handle(&self) -> Option<Arc<CanvasImageHandle>>;
// fn get_text_handle(&self) -> Option<Arc<CanvasTextHandle>>;
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)]
}
}
/// 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)]
@@ -308,10 +274,10 @@ impl CanvasState {
pub fn load_shader<T: 'static>(&mut self,
filename: String,
physical: PhysicalDevice,
capabilities: Capabilities) -> Option<Arc<CompiledGraphicsPipelineHandle>>
capabilities: Capabilities) -> Option<Arc<CompiledShaderHandle>>
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<Arc<CompiledGraphicsPipelineHandle>> {
-> Option<Arc<CompiledShaderHandle>> {
for shader in self.shader_buffers.clone() {
if shader.get_name() == shader_name {
return Some(shader.get_handle().clone());

View File

@@ -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
}

View File

@@ -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<Arc<dyn GraphicsPipelineAbstract + Sync + Send>>,
handle: Arc<CompiledGraphicsPipelineHandle>,
handle: Arc<CompiledShaderHandle>,
name: String,
device: Arc<Device>,
@@ -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<Device>,
handle: Arc<CompiledGraphicsPipelineHandle>,
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> GenericShader {
device: Arc<Device>,
handle: Arc<CompiledShaderHandle>,
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> 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<CompiledGraphicsPipelineHandle> {
fn get_handle(&self) -> Arc<CompiledShaderHandle> {
self.handle.clone()
}

View File

@@ -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<Device>,
handle: Arc<CompiledGraphicsPipelineHandle>,
handle: Arc<CompiledShaderHandle>,
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> Self where Self: Sized;
fn get_name(&self) -> String;
fn get_handle(&self) -> Arc<CompiledGraphicsPipelineHandle>;
fn get_handle(&self) -> Arc<CompiledShaderHandle>;
fn get_pipeline(&self) -> Arc<dyn GraphicsPipelineAbstract + Sync + Send>;
fn get_renderpass(&self) -> Arc<dyn RenderPassAbstract + Send + Sync>;
fn recompile(self, render_pass: Arc<dyn RenderPassAbstract + Send + Sync>)

View File

@@ -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<Arc<dyn GraphicsPipelineAbstract + Sync + Send>>,
handle: Arc<CompiledGraphicsPipelineHandle>,
handle: Arc<CompiledShaderHandle>,
name: String,
device: Arc<Device>,
@@ -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<Device>,
handle: Arc<CompiledGraphicsPipelineHandle>,
handle: Arc<CompiledShaderHandle>,
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> TextShader {
let compiled_vertex = GenericShader::compile(
@@ -151,7 +151,7 @@ impl CompiledGraphicsPipeline for TextShader {
self.name.clone()
}
fn get_handle(&self) -> Arc<CompiledGraphicsPipelineHandle> {
fn get_handle(&self) -> Arc<CompiledShaderHandle> {
self.handle.clone()
}

View File

@@ -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)>

View File

@@ -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

View File

@@ -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],

View File

@@ -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();

View File

@@ -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<H, In> DrawableTest<Vertex3D, H, In> for Sprite {
fn get_vertices(&self) -> Vec<Vertex3D> {
unimplemented!()
}
fn get_instances(&self) -> Vec<In> {
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<V: TextVertex, H, In: TextInstance> DrawableTest<V, H, In> for Text {
fn get_vertices(&self) -> Vec<V> {
unimplemented!()
}
fn get_instances(&self) -> Vec<In> {
unimplemented!()
}
fn get_handle(&self) -> H {
unimplemented!()
}
}

View File

@@ -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<Arc<CompiledGraphicsPipelineHandle>> {
pub fn get_shader_handle(&self, shader_name: String) -> Option<Arc<CompiledShaderHandle>> {
self.canvas_state.get_shader_handle(shader_name)
}