working on docs
This commit is contained in:
@@ -11,12 +11,15 @@ use winit::Window;
|
||||
use crate::compu_state::CompuState;
|
||||
use vulkano::image::ImageUsage;
|
||||
use crate::compu_frame::CompuFrame;
|
||||
use crate::canvas::{CanvasState, CanvasTextureHandle, CanvasShaderHandle, CanvasImageHandle};
|
||||
use crate::canvas::{CanvasState, CanvasTextureHandle, CanvasImageHandle};
|
||||
use crate::canvas_frame::CanvasFrame;
|
||||
use crate::compu_kernel::{CompuKernel, CompuKernelHandle};
|
||||
use crate::compu_buffer::{CompuBuffers, CompuBufferHandle};
|
||||
use std::time::Duration;
|
||||
use crate::canvas_shader::CanvasShaderHandle;
|
||||
|
||||
/// VKProcessor holds the vulkan instance information, the swapchain, and the compute and canvas states
|
||||
///
|
||||
pub struct VkProcessor<'a> {
|
||||
// Vulkan state fields
|
||||
pub instance: Arc<Instance>,
|
||||
@@ -39,7 +42,11 @@ pub struct VkProcessor<'a> {
|
||||
|
||||
|
||||
impl<'a> VkProcessor<'a> {
|
||||
|
||||
/// Creates a new VkProcessor from an instance and surface
|
||||
/// This includes the physical device, queues, compute and canvas state
|
||||
pub fn new(instance: &'a Arc<Instance>, surface: &'a Arc<Surface<Window>>) -> VkProcessor<'a> {
|
||||
|
||||
let physical = PhysicalDevice::enumerate(instance).next().unwrap();
|
||||
|
||||
let queue_family = physical.queue_families().find(|&q| {
|
||||
@@ -75,6 +82,7 @@ impl<'a> VkProcessor<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Using the surface, we calculate the surface capabilities and create the swapchain and swapchain images
|
||||
pub fn create_swapchain(&mut self, surface: &'a Arc<Surface<Window>>) {
|
||||
let (mut swapchain, images) = {
|
||||
let capabilities = surface.capabilities(self.physical).unwrap();
|
||||
@@ -109,7 +117,8 @@ impl<'a> VkProcessor<'a> {
|
||||
self.swapchain = Some(swapchain);
|
||||
self.swapchain_images = Some(images);
|
||||
}
|
||||
// On resizes we have to recreate the swapchain
|
||||
|
||||
/// On screen resizes, the swapchain and images must be recreated
|
||||
pub fn recreate_swapchain(&mut self, surface: &'a Arc<Surface<Window>>) {
|
||||
let dimensions = if let Some(dimensions) = surface.window().get_inner_size() {
|
||||
let dimensions: (u32, u32) = dimensions.to_physical(surface.window().get_hidpi_factor()).into();
|
||||
@@ -130,17 +139,27 @@ impl<'a> VkProcessor<'a> {
|
||||
self.swapchain_images = Some(new_images);
|
||||
}
|
||||
|
||||
/// A hardcoded list of textures which can be preloaded from this function
|
||||
pub fn preload_textures(&mut self) {
|
||||
self.canvas.load_texture(String::from("funky-bird.jpg"));
|
||||
self.canvas.load_texture(String::from("button.png"));
|
||||
self.canvas.load_texture(String::from("background.jpg"));
|
||||
self.canvas.load_texture(String::from("test2.png"));
|
||||
}
|
||||
|
||||
/// A hardcoded list of kernels which can be preloaded from this function
|
||||
pub fn preload_kernels(&mut self) {
|
||||
self.compute_state.new_kernel(String::from("simple-homogenize.compute"), self.device.clone());
|
||||
self.compute_state.new_kernel(String::from("simple-edge.compute"), self.device.clone());
|
||||
}
|
||||
pub fn preload_shaders(&mut self) {}
|
||||
|
||||
/// A hardcoded list of shaders which can be proloaded from this function
|
||||
pub fn preload_shaders(&mut self) {
|
||||
self.canvas.load_shader(String::from("color-passthrough"), self.physical.clone(), self.capabilities.clone());
|
||||
self.canvas.load_shader(String::from("simple_texture"), self.physical.clone(), self.capabilities.clone());
|
||||
}
|
||||
|
||||
|
||||
pub fn get_texture_handle(&self, texture_name: String) -> Option<Arc<CanvasTextureHandle>> {
|
||||
self.canvas.get_texture_handle(texture_name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user