Got the vertex definition into the load function. Which is something
This commit is contained in:
@@ -53,20 +53,44 @@ impl CanvasFrame {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct Pair<T> {
|
||||
x: T,
|
||||
y: T,
|
||||
}
|
||||
|
||||
impl Pair<Vertex3D> {
|
||||
fn new(x: Vertex3D, y: Vertex3D) -> Self {
|
||||
Self {
|
||||
x,
|
||||
y,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Pair<GlyphInstance> {
|
||||
fn new(x: GlyphInstance, y: GlyphInstance) -> Self {
|
||||
Self {
|
||||
x,
|
||||
y,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GenericCanvasFrame<H, V, In> {
|
||||
frame_data: HashMap<H, Vec<(Vec<V>, Vec<In>)>>
|
||||
}
|
||||
|
||||
impl<H, V, In> GenericCanvasFrame<H, V, In> {
|
||||
impl<V, In> GenericCanvasFrame<Vertex3D, V, In> {
|
||||
|
||||
/// Creates a bare canvas frame with empty accumulators
|
||||
pub fn new() -> GenericCanvasFrame<H, V, In> where H: Eq + Hash {
|
||||
pub fn new() -> GenericCanvasFrame<Vertex3D, V, In> {
|
||||
GenericCanvasFrame {
|
||||
frame_data: Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw(&mut self, drawable: &dyn DrawableTest<V, H, In>) where H: Eq + Hash + Clone {
|
||||
pub fn draw(&mut self, drawable: &dyn DrawableTest<V, Vertex3D, In>) {
|
||||
self.frame_data
|
||||
.entry(drawable.get_handle().clone())
|
||||
.or_insert(Vec::new())
|
||||
|
||||
@@ -318,16 +318,17 @@ impl CanvasState {
|
||||
|
||||
/// Load and Compile a shader with the filename at resources/shaders
|
||||
/// Takes physical and capabilities as we don't store that in Canvas
|
||||
pub fn load_shader<T: 'static>(&mut self,
|
||||
pub fn load_shader<T: 'static, V>(&mut self,
|
||||
filename: String,
|
||||
physical: PhysicalDevice,
|
||||
capabilities: Capabilities) -> Option<Arc<CompiledGraphicsPipelineHandle>>
|
||||
where T: CompiledGraphicsPipeline {
|
||||
|
||||
let handle = Arc::new(CompiledGraphicsPipelineHandle {
|
||||
handle: self.shader_buffers.len() as u32
|
||||
});
|
||||
|
||||
let shader: Box<dyn CompiledGraphicsPipeline> = Box::new(T::new(
|
||||
let shader: Box<dyn CompiledGraphicsPipeline> = Box::new(T::new::<V>(
|
||||
filename.clone(),
|
||||
self.device.clone(),
|
||||
handle.clone(),
|
||||
|
||||
@@ -103,7 +103,7 @@ pub struct CompiledGraphicsPipelineHandle {
|
||||
}
|
||||
|
||||
pub trait CompiledGraphicsPipeline {
|
||||
fn new(filename: String,
|
||||
fn new<T>(filename: String,
|
||||
device: Arc<Device>,
|
||||
handle: Arc<CompiledGraphicsPipelineHandle>,
|
||||
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> Self where Self: Sized;
|
||||
|
||||
@@ -39,7 +39,7 @@ impl CompiledGraphicsPipelineResources for GenericShader {}
|
||||
impl CompiledGraphicsPipeline for GenericShader {
|
||||
|
||||
/// This will explode when the shader does not want to compile
|
||||
fn new(filename: String,
|
||||
fn new<T>(filename: String,
|
||||
device: Arc<Device>,
|
||||
handle: Arc<CompiledGraphicsPipelineHandle>,
|
||||
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> GenericShader {
|
||||
@@ -78,7 +78,8 @@ impl CompiledGraphicsPipeline for GenericShader {
|
||||
graphics_pipeline:
|
||||
Some(Arc::new(GraphicsPipeline::start()
|
||||
|
||||
.vertex_input(SingleBufferDefinition::<Vertex3D>::new())
|
||||
//SingleBufferDefinition::<Vertex3D>
|
||||
.vertex_input(T::new())
|
||||
|
||||
.vertex_shader(vertex_entry_point.clone(), ShaderSpecializationConstants {
|
||||
first_constant: 0,
|
||||
|
||||
@@ -45,7 +45,7 @@ impl CompiledGraphicsPipelineResources for TextShader {}
|
||||
impl CompiledGraphicsPipeline for TextShader {
|
||||
|
||||
/// This will explode when the shader does not want to compile
|
||||
fn new(filename: String,
|
||||
fn new<T>(filename: String,
|
||||
device: Arc<Device>,
|
||||
handle: Arc<CompiledGraphicsPipelineHandle>,
|
||||
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> TextShader {
|
||||
@@ -107,8 +107,8 @@ impl CompiledGraphicsPipeline for TextShader {
|
||||
TextShader {
|
||||
graphics_pipeline:
|
||||
Some(Arc::new(GraphicsPipeline::start()
|
||||
|
||||
.vertex_input(OneVertexOneInstanceDefinition::<Vertex3D, GlyphInstance>::new())
|
||||
//OneVertexOneInstanceDefinition::<Vertex3D, GlyphInstance>
|
||||
.vertex_input(T::new())
|
||||
|
||||
.vertex_shader(vertex_entry_point.clone(), ShaderSpecializationConstants {
|
||||
first_constant: 0,
|
||||
|
||||
@@ -169,8 +169,8 @@ pub fn main() {
|
||||
canvas.draw(&funky_sprite);
|
||||
canvas.draw(&test_polygon);
|
||||
|
||||
let mut gencanvas = GenericCanvasFrame::new();
|
||||
gencanvas.draw(&text_sprite);
|
||||
// let mut gencanvas = GenericCanvasFrame::new();
|
||||
// gencanvas.draw(&text_sprite);
|
||||
|
||||
|
||||
{
|
||||
|
||||
@@ -97,8 +97,8 @@ impl Sprite {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V, H, In> DrawableTest<V, H, In> for Sprite {
|
||||
fn get_vertices(&self) -> Vec<V> {
|
||||
impl<H, In> DrawableTest<Vertex3D, H, In> for Sprite {
|
||||
fn get_vertices(&self) -> Vec<Vertex3D> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ pub trait TextVertex {
|
||||
fn get_vertices() -> Vec<(u32, u32, u32)>;
|
||||
}
|
||||
|
||||
impl<V: TextVertex, H: TextHandle, In: TextInstance> DrawableTest<V, H, In> for Text {
|
||||
impl<V: TextVertex, H, In: TextInstance> DrawableTest<V, H, In> for Text {
|
||||
fn get_vertices(&self) -> Vec<V> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ use std::time::Duration;
|
||||
use vulkano::pipeline::depth_stencil::{DynamicStencilValue, StencilFaceFlags};
|
||||
use crate::canvas::shader::common::CompiledGraphicsPipelineHandle;
|
||||
use crate::canvas::shader::generic_shader::GenericShader;
|
||||
use crate::canvas::shader::text_shader::TextShader;
|
||||
use crate::canvas::shader::text_shader::{TextShader, GlyphInstance};
|
||||
use vulkano::pipeline::vertex::{OneVertexOneInstanceDefinition, SingleBufferDefinition};
|
||||
use crate::util::vertex_3d::Vertex3D;
|
||||
|
||||
/// VKProcessor holds the vulkan instance information, the swapchain, and the compute and canvas states
|
||||
///
|
||||
@@ -157,10 +159,10 @@ impl<'a> VkProcessor<'a> {
|
||||
|
||||
/// A hardcoded list of shaders which can be proloaded from this function
|
||||
pub fn preload_shaders(&mut self) {
|
||||
self.canvas_state.load_shader::<GenericShader>(String::from("color-passthrough"), self.physical.clone(), self.capabilities.clone());
|
||||
self.canvas_state.load_shader::<GenericShader>(String::from("simple_texture"), self.physical.clone(), self.capabilities.clone());
|
||||
self.canvas_state.load_shader::<GenericShader>(String::from("simple_image"), self.physical.clone(), self.capabilities.clone());
|
||||
self.canvas_state.load_shader::<TextShader>(String::from("simple_text"), self.physical.clone(), self.capabilities.clone());
|
||||
self.canvas_state.load_shader::<GenericShader, SingleBufferDefinition::<Vertex3D>>(String::from("color-passthrough"), self.physical.clone(), self.capabilities.clone());
|
||||
self.canvas_state.load_shader::<GenericShader, SingleBufferDefinition::<Vertex3D>>(String::from("simple_texture"), self.physical.clone(), self.capabilities.clone());
|
||||
self.canvas_state.load_shader::<GenericShader, SingleBufferDefinition::<Vertex3D>>(String::from("simple_image"), self.physical.clone(), self.capabilities.clone());
|
||||
self.canvas_state.load_shader::<TextShader, OneVertexOneInstanceDefinition::<Vertex3D, GlyphInstance>>(String::from("simple_text"), self.physical.clone(), self.capabilities.clone());
|
||||
}
|
||||
|
||||
/// A hardcoded list of shaders which can be proloaded from this function
|
||||
|
||||
Reference in New Issue
Block a user