I need to impl a private module so I can have a private get_paths
This commit is contained in:
@@ -24,6 +24,7 @@ use crate::canvas_text::{CanvasText, CanvasTextHandle};
|
||||
use crate::canvas_shader::{CanvasShader, CanvasShaderHandle};
|
||||
use crate::canvas_buffer::{CanvasImage, CanvasTexture, CanvasTextCache};
|
||||
use crate::vertex_3d::Vertex3D;
|
||||
use vulkano::pipeline::depth_stencil::{StencilFaceFlags, DynamicStencilValue};
|
||||
|
||||
/// 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
|
||||
@@ -175,7 +176,23 @@ impl CanvasState {
|
||||
|
||||
|
||||
CanvasState {
|
||||
dynamic_state: DynamicState { line_width: None, viewports: None, scissors: None },
|
||||
dynamic_state: DynamicState {
|
||||
line_width: None,
|
||||
viewports: None,
|
||||
scissors: None,
|
||||
compare_mask: Some(DynamicStencilValue {
|
||||
face: StencilFaceFlags::StencilFrontAndBack,
|
||||
value: 0xFF,
|
||||
}),
|
||||
write_mask: Some(DynamicStencilValue {
|
||||
face: StencilFaceFlags::StencilFrontAndBack,
|
||||
value: 0xFF,
|
||||
}),
|
||||
reference: Some(DynamicStencilValue {
|
||||
face: StencilFaceFlags::StencilFrontAndBack,
|
||||
value: 0xFF,
|
||||
}),
|
||||
},
|
||||
sampler: Sampler::new(device.clone(),
|
||||
Filter::Linear, Filter::Linear,
|
||||
MipmapMode::Nearest,
|
||||
@@ -332,10 +349,12 @@ impl CanvasState {
|
||||
shader_type: ShaderType,
|
||||
physical: PhysicalDevice,
|
||||
capabilities: Capabilities) -> Option<Arc<CanvasShaderHandle>> {
|
||||
|
||||
let handle = Arc::new(CanvasShaderHandle {
|
||||
handle: self.shader_buffers.len() as u32
|
||||
});
|
||||
|
||||
// TODO : what is even going on here
|
||||
let shader = match shader_type {
|
||||
ShaderType::SOLID => {
|
||||
Arc::new(CanvasShader::new(
|
||||
@@ -478,7 +497,7 @@ impl CanvasState {
|
||||
|
||||
/// Pushes the draw commands to the command buffer. Requires the framebuffers and
|
||||
/// image number to be passed in as they are taken care of by the vkprocessor
|
||||
pub fn draw_commands(&self,
|
||||
pub fn draw_commands(&mut self,
|
||||
mut command_buffer: AutoCommandBufferBuilder,
|
||||
framebuffers: Vec<Arc<dyn FramebufferAbstract + Send + Sync>>,
|
||||
image_num: usize) -> AutoCommandBufferBuilder {
|
||||
@@ -486,9 +505,16 @@ impl CanvasState {
|
||||
// Specify the color to clear the framebuffer with i.e. blue
|
||||
let clear_values = vec!(
|
||||
ClearValue::Float([0.0, 0.0, 1.0, 1.0]),
|
||||
ClearValue::DepthStencil((1.0, 0)),
|
||||
ClearValue::DepthStencil((1.0, 0x00)),
|
||||
);
|
||||
|
||||
// self.dynamic_state = DynamicState {
|
||||
// line_width: None,
|
||||
// viewports: self.dynamic_state.viewports.clone(),
|
||||
// scissors: None,
|
||||
// compare_mask: Some(StencilMask{ face: StencilFaceFlags::StencilFaceFrontBit, mask: 0xFF }),
|
||||
// };
|
||||
|
||||
let mut command_buffer = command_buffer.begin_render_pass(
|
||||
framebuffers[image_num].clone(), false, clear_values.clone(),
|
||||
).unwrap();
|
||||
@@ -501,6 +527,7 @@ impl CanvasState {
|
||||
|
||||
// This looks a little weird as colored_vertex_buffer is a vec of GPU allocated vecs.
|
||||
// But we can pass in multiple vertex buffers
|
||||
|
||||
if !self.colored_vertex_buffer.is_empty() {
|
||||
command_buffer = command_buffer.draw(
|
||||
shader.get_pipeline().clone(),
|
||||
@@ -510,7 +537,6 @@ impl CanvasState {
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
|
||||
// Images
|
||||
let mut shader = self.shader_buffers.get(
|
||||
self.get_shader_handle(String::from("simple_image"))
|
||||
@@ -529,10 +555,10 @@ impl CanvasState {
|
||||
&self.dynamic_state.clone(), vec![vertex_buffer],
|
||||
vec![descriptor_set], (),
|
||||
).unwrap();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Textures
|
||||
let mut shader = self.shader_buffers.get(
|
||||
self.get_shader_handle(String::from("simple_texture"))
|
||||
|
||||
@@ -12,6 +12,51 @@ use crate::vertex_2d::Vertex2D;
|
||||
use vulkano::pipeline::vertex::SingleBufferDefinition;
|
||||
use crate::vertex_3d::Vertex3D;
|
||||
use vulkano::pipeline::depth_stencil::{DepthStencil, Stencil, StencilOp, Compare, DepthBounds};
|
||||
use std::collections::HashSet;
|
||||
|
||||
/// Typed wrapper for a u32 handle
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
||||
pub struct CompiledGraphicsPipelineHandle {
|
||||
pub handle: u32
|
||||
}
|
||||
|
||||
pub trait CompiledGraphicsPipeline {
|
||||
fn get_paths(&self, filename: String) -> Vec<(ShaderType, PathBuf)> {
|
||||
|
||||
let project_root =
|
||||
std::env::current_dir()
|
||||
.expect("failed to get root directory");
|
||||
|
||||
let mut shader_path = project_root.clone();
|
||||
shader_path.push(PathBuf::from("resources/shaders/"));
|
||||
|
||||
|
||||
|
||||
let mut vertex_shader_path = shader_path.clone();
|
||||
vertex_shader_path.push(PathBuf::from("resources/shaders/"));
|
||||
vertex_shader_path.push(PathBuf::from(filename.clone() + ".vertex"));
|
||||
|
||||
let mut fragment_shader_path = project_root.clone();
|
||||
fragment_shader_path.push(PathBuf::from("resources/shaders/"));
|
||||
fragment_shader_path.push(PathBuf::from(filename.clone() + ".fragment"));
|
||||
|
||||
(vertex_shader_path, fragment_shader_path)
|
||||
}
|
||||
fn new(filename: String, shaders: HashSet<ShaderType>) -> Box<dyn CompiledGraphicsPipeline>;
|
||||
fn get_name() -> String;
|
||||
fn get_handle() -> Arc<AbstractCompiledPipelineHandle>;
|
||||
fn get_pipeline() -> Arc<dyn GraphicsPipelineAbstract + Sync + Send>;
|
||||
fn recompile();
|
||||
}
|
||||
|
||||
/// Legacy ShaderType enum for single type shaders.
|
||||
#[derive(PartialEq, Eq, Hash, Clone)]
|
||||
pub enum ShaderType {
|
||||
VERTEX = 0,
|
||||
FRAGMENT = 1,
|
||||
GEOMETRY = 2,
|
||||
TESSELATION = 3,
|
||||
}
|
||||
|
||||
|
||||
/// Typed wrapper for a u32 shader handle (index id)
|
||||
@@ -31,9 +76,8 @@ pub struct CanvasShader {
|
||||
pub(crate) name: String,
|
||||
}
|
||||
|
||||
impl CanvasShader {
|
||||
/// Takes the filename of a .vertex .fragment shader combo in resources/shaders/
|
||||
/// Returns pathbuffer of that vertex and fragment shader
|
||||
impl CompiledGraphicsPipeline for CanvasShader {
|
||||
|
||||
fn get_path(filename: String) -> (PathBuf, PathBuf) {
|
||||
let project_root =
|
||||
std::env::current_dir()
|
||||
@@ -53,6 +97,30 @@ impl CanvasShader {
|
||||
(vertex_shader_path, fragment_shader_path)
|
||||
}
|
||||
|
||||
fn new(filename: String, shaders: HashSet<ShaderType>) -> Box<dyn CompiledGraphicsPipeline> {
|
||||
|
||||
}
|
||||
|
||||
fn get_name() -> String {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn get_handle() -> Arc<_> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn get_pipeline() -> Arc<dyn GraphicsPipelineAbstract> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn recompile() {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl CanvasShader {
|
||||
|
||||
|
||||
/// Clone and returns the compiled graphics pipeline
|
||||
pub fn get_pipeline(&self) -> Arc<dyn GraphicsPipelineAbstract + Sync + Send> {
|
||||
self.graphics_pipeline.clone().unwrap()
|
||||
@@ -119,16 +187,25 @@ impl CanvasShader {
|
||||
depth_bounds_test: DepthBounds::Disabled,
|
||||
stencil_front: Stencil {
|
||||
compare: Compare::Equal,
|
||||
pass_op: StencilOp::Invert,
|
||||
fail_op: StencilOp::Invert,
|
||||
pass_op: StencilOp::IncrementAndWrap,
|
||||
fail_op: StencilOp::DecrementAndClamp,
|
||||
depth_fail_op: StencilOp::Keep,
|
||||
compare_mask: Some(0x01),
|
||||
write_mask: Some(0xFF),
|
||||
reference: Some(0x01),
|
||||
compare_mask: None,
|
||||
write_mask: None,
|
||||
reference: None,
|
||||
},
|
||||
stencil_back: Stencil {
|
||||
compare: Compare::Equal,
|
||||
pass_op: StencilOp::Invert,
|
||||
fail_op: StencilOp::Zero,
|
||||
depth_fail_op: StencilOp::Zero,
|
||||
compare_mask: None,
|
||||
write_mask: None,
|
||||
reference: None,
|
||||
},
|
||||
stencil_back: Default::default()
|
||||
};
|
||||
|
||||
|
||||
CanvasShader {
|
||||
graphics_pipeline: Some(Arc::new(GraphicsPipeline::start()
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ use crate::compu_buffer::CompuBuffers;
|
||||
use crate::util::load_raw;
|
||||
use crate::canvas_frame::CanvasFrame;
|
||||
use crate::sprite::Poly;
|
||||
use vulkano::instance::debug::DebugCallback;
|
||||
|
||||
|
||||
pub mod util;
|
||||
@@ -58,6 +59,10 @@ pub fn main() {
|
||||
Instance::new(None, &extensions, None).unwrap()
|
||||
};
|
||||
|
||||
let _callback = DebugCallback::errors_and_warnings(&instance, |msg| {
|
||||
println!("Debug callback: {:?}", msg.description);
|
||||
}).ok();
|
||||
|
||||
let mut events_loop = EventsLoop::new();
|
||||
let mut surface = WindowBuilder::new()
|
||||
.with_dimensions(LogicalSize::from((800, 800)))
|
||||
@@ -106,7 +111,6 @@ pub fn main() {
|
||||
|
||||
let test_polygon = Poly::new_with_color((-0.5, -0.5), (0.5, 0.5), 1, (1.0,0.0,0.0,0.0));
|
||||
|
||||
|
||||
drop(q2);
|
||||
drop(q1);
|
||||
|
||||
@@ -186,6 +190,8 @@ pub fn main() {
|
||||
|
||||
drop(l);
|
||||
|
||||
|
||||
|
||||
hprof::end_frame();
|
||||
hprof::profiler().print_timing();
|
||||
}
|
||||
|
||||
@@ -153,32 +153,65 @@ impl Poly {
|
||||
|
||||
Poly {
|
||||
vertices: vec![
|
||||
(position.0, position.1 , normalized_depth), // top left
|
||||
(position.0, position.1 + size.1 , normalized_depth), // bottom left
|
||||
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
|
||||
(-0.5 , -0.5 , normalized_depth),
|
||||
(-1.0 , 1.0 , normalized_depth),
|
||||
(-0.25 , 0.0 , normalized_depth),
|
||||
|
||||
(position.0, position.1 , normalized_depth), // top left
|
||||
(position.0 + size.0, position.1 + size.1, normalized_depth), // bottom right
|
||||
(position.0 + size.0, position.1 , normalized_depth), // top right
|
||||
(-0.25 , 0.0 , normalized_depth),
|
||||
(-1.0 , 1.0 , normalized_depth),
|
||||
(0.0 , 0.5 , normalized_depth),
|
||||
|
||||
(position.0 - 0.1, position.1 , normalized_depth), // top left
|
||||
(position.0 - 0.1 + size.0, position.1 + size.1, normalized_depth), // bottom right
|
||||
(position.0 - 0.1 + size.0, position.1 , normalized_depth), // top right
|
||||
(0.25 , 0.0 , normalized_depth),
|
||||
(-1.0 , 1.0 , normalized_depth),
|
||||
(0.0 , 0.5 , normalized_depth),
|
||||
|
||||
(0.5 , -0.5 , normalized_depth),
|
||||
(-1.0 , 1.0 , normalized_depth),
|
||||
(0.25 , 0.0 , normalized_depth),
|
||||
|
||||
(0.25 , -0.5 , normalized_depth),
|
||||
(-1.0 , 1.0 , normalized_depth),
|
||||
(0.5 , -0.5 , normalized_depth),
|
||||
|
||||
(0.25 , -0.5 , normalized_depth),
|
||||
(-1.0 , 1.0 , normalized_depth),
|
||||
(0.0 , -0.1 , normalized_depth),
|
||||
|
||||
(-0.25 , -0.5 , normalized_depth),
|
||||
(-1.0 , 1.0 , normalized_depth),
|
||||
(0.0 , -0.1 , normalized_depth),
|
||||
|
||||
(-0.5 , -0.5 , normalized_depth),
|
||||
(-1.0 , 1.0 , normalized_depth),
|
||||
(-0.25 , -0.5 , normalized_depth),
|
||||
],
|
||||
|
||||
position: position,
|
||||
ti_position: vec![
|
||||
(-0.0, -0.0), // top left
|
||||
(-0.0, 1.0), // bottom left
|
||||
( 1.0, 1.0), // bottom right
|
||||
|
||||
(-0.0, -0.0), // top left
|
||||
( 1.0, 1.0), // bottom right
|
||||
( 1.0, -0.0), // top right
|
||||
|
||||
(-0.0, -0.0), // top left
|
||||
( 1.0, 1.0), // bottom right
|
||||
( 1.0, -0.0), // top right
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
(0.0,0.0),
|
||||
],
|
||||
size: size,
|
||||
color: color,
|
||||
|
||||
@@ -17,6 +17,7 @@ use crate::compu_kernel::{CompuKernel, CompuKernelHandle};
|
||||
use crate::compu_buffer::{CompuBuffers, CompuBufferHandle};
|
||||
use std::time::Duration;
|
||||
use crate::canvas_shader::CanvasShaderHandle;
|
||||
use vulkano::pipeline::depth_stencil::{DynamicStencilValue, StencilFaceFlags};
|
||||
|
||||
/// VKProcessor holds the vulkan instance information, the swapchain, and the compute and canvas states
|
||||
///
|
||||
@@ -27,7 +28,6 @@ pub struct VkProcessor<'a> {
|
||||
pub device: Arc<Device>,
|
||||
pub queues: QueuesIter,
|
||||
pub queue: Arc<Queue>,
|
||||
pub dynamic_state: DynamicState,
|
||||
|
||||
pub swapchain: Option<Arc<Swapchain<Window>>>,
|
||||
pub swapchain_images: Option<Vec<Arc<SwapchainImage<Window>>>>,
|
||||
@@ -72,7 +72,6 @@ impl<'a> VkProcessor<'a> {
|
||||
device: device.clone(),
|
||||
queue: queue.clone(),
|
||||
queues: queues,
|
||||
dynamic_state: DynamicState { line_width: None, viewports: None, scissors: None },
|
||||
swapchain: None,
|
||||
swapchain_images: None,
|
||||
swapchain_recreate_needed: false,
|
||||
|
||||
Reference in New Issue
Block a user