Switched vertex type to be chosen at the shader load

This commit is contained in:
2020-02-13 23:37:41 -08:00
parent fcfa40e335
commit d1051a0ca3
9 changed files with 39 additions and 40 deletions

View File

@@ -9,22 +9,15 @@ use shade_runner::{Input, Output, Layout, Entry};
use std::ffi::CStr;
use std::marker::PhantomData;
use vulkano::pipeline::depth_stencil::{DepthStencil, Compare, DepthBounds, Stencil, StencilOp};
use vulkano::pipeline::vertex::{SingleBufferDefinition, OneVertexOneInstanceDefinition};
use vulkano::pipeline::vertex::{SingleBufferDefinition, OneVertexOneInstanceDefinition, Vertex};
use shade_runner as sr;
use crate::canvas::managed::shader::shader_common::{ShaderType, CompiledGraphicsPipelineResources, CompiledGraphicsPipeline};
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;
use crate::util::vertex::ColorVertex2D;
#[derive(Default, Debug, Clone, Copy)]
pub struct GlyphInstance {
pub screen_position: (f32, f32),
pub atlas_position: (f32, f32),
pub atlas_size: (f32, f32),
pub scale: f32,
}
vulkano::impl_vertex!(GlyphInstance, screen_position, atlas_position, atlas_size, scale);
/// CanvasShader holds the pipeline and render pass for the input shader source
#[derive(Clone)]
@@ -47,7 +40,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<V: Vertex>(filename: String,
device: Arc<Device>,
handle: Arc<CompiledShaderHandle>,
render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> TextShader {
@@ -111,8 +104,9 @@ impl CompiledGraphicsPipeline for TextShader {
TextShader {
graphics_pipeline:
Some(Arc::new(GraphicsPipeline::start()
//OneVertexOneInstanceDefinition::<Vertex3D, GlyphInstance>
.vertex_input(vertex_definition)
.vertex_input(SingleBufferDefinition::<V>::new())
//.vertex_input(vertex_definition)
.vertex_shader(vertex_entry_point.clone(), ShaderSpecializationConstants {
first_constant: 0,
@@ -160,8 +154,8 @@ impl CompiledGraphicsPipeline for TextShader {
fn get_renderpass(&self) -> Arc<dyn RenderPassAbstract + Send + Sync> {
self.renderpass.clone()
}
fn recompile(self, render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> TextShader {
TextShader::new(self.name,
fn recompile<V: Vertex>(self, render_pass: Arc<dyn RenderPassAbstract + Send + Sync>) -> TextShader {
TextShader::new::<V>(self.name,
self.device,
self.handle,
self.renderpass.clone())