Add safer_ffi changes
This commit is contained in:
parent
e14f4dac28
commit
04f6fde22f
6 changed files with 62 additions and 88 deletions
|
@ -12,7 +12,7 @@ utilities = { git = "https://gavania.de/hodasemi/utilities.git" }
|
||||||
paste = "1.0.11"
|
paste = "1.0.11"
|
||||||
assetpath = { git = "https://gavania.de/hodasemi/vulkan_lib.git" }
|
assetpath = { git = "https://gavania.de/hodasemi/vulkan_lib.git" }
|
||||||
anyhow = { version = "1.0.68", features = ["backtrace"] }
|
anyhow = { version = "1.0.68", features = ["backtrace"] }
|
||||||
cgmath = "0.18.0"
|
safer-ffi = { version = "0.0.10", features= ["proc_macros"] }
|
||||||
|
|
||||||
# optional
|
# optional
|
||||||
audio = { git = "https://gavania.de/hodasemi/audio.git", optional = true }
|
audio = { git = "https://gavania.de/hodasemi/audio.git", optional = true }
|
||||||
|
|
|
@ -588,12 +588,12 @@ impl Button {
|
||||||
let top = self.framable.top() as f32;
|
let top = self.framable.top() as f32;
|
||||||
let bottom = self.framable.bottom() as f32;
|
let bottom = self.framable.bottom() as f32;
|
||||||
|
|
||||||
frame[0] = ortho * vec4(left - offset, bottom + offset, 0.0, 1.0);
|
frame[0].position = ortho * vec4(left - offset, bottom + offset, 0.0, 1.0);
|
||||||
frame[1] = ortho * vec4(right + offset, bottom + offset, 0.0, 1.0);
|
frame[1].position = ortho * vec4(right + offset, bottom + offset, 0.0, 1.0);
|
||||||
frame[2] = ortho * vec4(right + offset, top - offset, 0.0, 1.0);
|
frame[2].position = ortho * vec4(right + offset, top - offset, 0.0, 1.0);
|
||||||
frame[3] = ortho * vec4(right + offset, top - offset, 0.0, 1.0);
|
frame[3].position = ortho * vec4(right + offset, top - offset, 0.0, 1.0);
|
||||||
frame[4] = ortho * vec4(left - offset, top - offset, 0.0, 1.0);
|
frame[4].position = ortho * vec4(left - offset, top - offset, 0.0, 1.0);
|
||||||
frame[5] = ortho * vec4(left - offset, bottom + offset, 0.0, 1.0);
|
frame[5].position = ortho * vec4(left - offset, bottom + offset, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub struct Colorable {
|
||||||
framable: Arc<Framable>,
|
framable: Arc<Framable>,
|
||||||
|
|
||||||
descriptor_set: RwLock<Arc<DescriptorSet>>,
|
descriptor_set: RwLock<Arc<DescriptorSet>>,
|
||||||
buffer: Arc<Buffer<Vector4<f32>>>,
|
buffer: Arc<Buffer<ColorableVertex>>,
|
||||||
|
|
||||||
color: RwLock<Color>,
|
color: RwLock<Color>,
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ impl Colorable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the internal vulkan buffer
|
/// Returns the internal vulkan buffer
|
||||||
pub fn buffer(&self) -> &Arc<Buffer<Vector4<f32>>> {
|
pub fn buffer(&self) -> &Arc<Buffer<ColorableVertex>> {
|
||||||
&self.buffer
|
&self.buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,33 +155,39 @@ impl Colorable {
|
||||||
let top = y_start + height * *self.top_factor.read().unwrap();
|
let top = y_start + height * *self.top_factor.read().unwrap();
|
||||||
let bottom = y_start + height * *self.bottom_factor.read().unwrap();
|
let bottom = y_start + height * *self.bottom_factor.read().unwrap();
|
||||||
|
|
||||||
frame[0] = self.framable.ortho() * vec4(left, bottom, 0.0, 1.0);
|
frame[0].position = self.framable.ortho() * vec4(left, bottom, 0.0, 1.0);
|
||||||
frame[1] = self.framable.ortho() * vec4(right, bottom, 0.0, 1.0);
|
frame[1].position = self.framable.ortho() * vec4(right, bottom, 0.0, 1.0);
|
||||||
frame[2] = self.framable.ortho() * vec4(right, top, 0.0, 1.0);
|
frame[2].position = self.framable.ortho() * vec4(right, top, 0.0, 1.0);
|
||||||
frame[3] = self.framable.ortho() * vec4(right, top, 0.0, 1.0);
|
frame[3].position = self.framable.ortho() * vec4(right, top, 0.0, 1.0);
|
||||||
frame[4] = self.framable.ortho() * vec4(left, top, 0.0, 1.0);
|
frame[4].position = self.framable.ortho() * vec4(left, top, 0.0, 1.0);
|
||||||
frame[5] = self.framable.ortho() * vec4(left, bottom, 0.0, 1.0);
|
frame[5].position = self.framable.ortho() * vec4(left, bottom, 0.0, 1.0);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn vertex_input_state() -> (
|
#[derive_ReprC]
|
||||||
Vec<VkVertexInputBindingDescription>,
|
#[repr(C)]
|
||||||
Vec<VkVertexInputAttributeDescription>,
|
#[derive(Debug, Clone, Copy)]
|
||||||
) {
|
pub struct ColorableVertex {
|
||||||
let input_bindings = vec![VkVertexInputBindingDescription {
|
pub position: Vector4<f32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl VertexInputDescription for ColorableVertex {
|
||||||
|
fn bindings() -> Vec<VkVertexInputBindingDescription> {
|
||||||
|
vec![VkVertexInputBindingDescription {
|
||||||
binding: 0,
|
binding: 0,
|
||||||
stride: std::mem::size_of::<Vector4<f32>>() as u32,
|
stride: std::mem::size_of::<Vector4<f32>>() as u32,
|
||||||
inputRate: VK_VERTEX_INPUT_RATE_VERTEX,
|
inputRate: VK_VERTEX_INPUT_RATE_VERTEX,
|
||||||
}];
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
let input_attributes = vec![VkVertexInputAttributeDescription {
|
fn attributes() -> Vec<VkVertexInputAttributeDescription> {
|
||||||
|
vec![VkVertexInputAttributeDescription {
|
||||||
location: 0,
|
location: 0,
|
||||||
binding: 0,
|
binding: 0,
|
||||||
format: VK_FORMAT_R32G32B32A32_SFLOAT,
|
format: VK_FORMAT_R32G32B32A32_SFLOAT,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
}];
|
}]
|
||||||
|
|
||||||
(input_bindings, input_attributes)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ use std::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use cgmath::Matrix4;
|
use vulkan_rs::prelude::cgmath::Matrix4;
|
||||||
|
|
||||||
/// Describes the vertical alignment for a `Framable`
|
/// Describes the vertical alignment for a `Framable`
|
||||||
#[derive(Copy, Clone, PartialEq)]
|
#[derive(Copy, Clone, PartialEq)]
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
use cgmath::prelude::Zero;
|
use safer_ffi::derive_ReprC;
|
||||||
use utilities::prelude::*;
|
|
||||||
use vulkan_rs::prelude::*;
|
use vulkan_rs::prelude::*;
|
||||||
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
|
#[derive_ReprC]
|
||||||
|
#[repr(C)]
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct TexturedVertex {
|
pub struct TexturedVertex {
|
||||||
pub position: cgmath::Vector4<f32>,
|
pub position: cgmath::Vector4<f32>,
|
||||||
pub texture_coordinates: cgmath::Vector2<f32>,
|
pub texture_coordinates: cgmath::Vector2<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TexturedVertex {
|
impl VertexInputDescription for TexturedVertex {
|
||||||
pub fn vertex_input_state() -> (
|
fn bindings() -> Vec<VkVertexInputBindingDescription> {
|
||||||
Vec<VkVertexInputBindingDescription>,
|
vec![VkVertexInputBindingDescription {
|
||||||
Vec<VkVertexInputAttributeDescription>,
|
|
||||||
) {
|
|
||||||
let input_bindings = vec![VkVertexInputBindingDescription {
|
|
||||||
binding: 0,
|
binding: 0,
|
||||||
stride: mem::size_of::<TexturedVertex>() as u32,
|
stride: mem::size_of::<TexturedVertex>() as u32,
|
||||||
inputRate: VK_VERTEX_INPUT_RATE_VERTEX,
|
inputRate: VK_VERTEX_INPUT_RATE_VERTEX,
|
||||||
}];
|
}]
|
||||||
|
}
|
||||||
|
|
||||||
let input_attributes = vec![
|
fn attributes() -> Vec<VkVertexInputAttributeDescription> {
|
||||||
|
vec![
|
||||||
VkVertexInputAttributeDescription {
|
VkVertexInputAttributeDescription {
|
||||||
location: 0,
|
location: 0,
|
||||||
binding: 0,
|
binding: 0,
|
||||||
|
@ -34,9 +34,7 @@ impl TexturedVertex {
|
||||||
format: VK_FORMAT_R32G32_SFLOAT,
|
format: VK_FORMAT_R32G32_SFLOAT,
|
||||||
offset: 16, // mem::size_of::<cgmath::Vector4<f32>>() as u32
|
offset: 16, // mem::size_of::<cgmath::Vector4<f32>>() as u32
|
||||||
},
|
},
|
||||||
];
|
]
|
||||||
|
|
||||||
(input_bindings, input_attributes)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,9 @@ use vulkan_rs::{prelude::*, render_target::sub_pass::InputAttachmentInfo};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
elements::Elements,
|
elements::Elements,
|
||||||
gui::{iconizable::IconBuilderType, texturedvertex::TexturedVertex},
|
gui::{
|
||||||
|
colorable::ColorableVertex, iconizable::IconBuilderType, texturedvertex::TexturedVertex,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
use cgmath::{ortho, vec2, vec4};
|
use cgmath::{ortho, vec2, vec4};
|
||||||
|
@ -1411,22 +1413,16 @@ impl GuiHandler {
|
||||||
let vertex_shader_text = include_bytes!("guishader/text.vert.spv");
|
let vertex_shader_text = include_bytes!("guishader/text.vert.spv");
|
||||||
let fragment_shader_text = include_bytes!("guishader/text.frag.spv");
|
let fragment_shader_text = include_bytes!("guishader/text.frag.spv");
|
||||||
|
|
||||||
let vertex_shader =
|
let vertex_shader = ShaderModule::from_slice(device.clone(), vertex_shader_text)?;
|
||||||
ShaderModule::from_slice(device.clone(), vertex_shader_text, ShaderType::Vertex)?;
|
let fragment_shader = ShaderModule::from_slice(device.clone(), fragment_shader_text)?;
|
||||||
let fragment_shader =
|
|
||||||
ShaderModule::from_slice(device.clone(), fragment_shader_text, ShaderType::Fragment)?;
|
|
||||||
|
|
||||||
let (input_bindings, input_attributes) = TexturedVertex::vertex_input_state();
|
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
render_targets.execute(|render_target| {
|
render_targets.execute(|render_target| {
|
||||||
Ok(GuiSeparator {
|
Ok(GuiSeparator {
|
||||||
_descriptor_layout: descriptor_layout.clone(),
|
_descriptor_layout: descriptor_layout.clone(),
|
||||||
|
|
||||||
pipeline: GuiHandler::init_gui_pipeline(
|
pipeline: GuiHandler::init_gui_pipeline::<TexturedVertex>(
|
||||||
device,
|
device,
|
||||||
input_bindings.clone(),
|
|
||||||
input_attributes.clone(),
|
|
||||||
render_target.read().unwrap().render_pass(),
|
render_target.read().unwrap().render_pass(),
|
||||||
&pipeline_layout,
|
&pipeline_layout,
|
||||||
vertex_shader.clone(),
|
vertex_shader.clone(),
|
||||||
|
@ -1458,27 +1454,17 @@ impl GuiHandler {
|
||||||
.build(device.clone())?;
|
.build(device.clone())?;
|
||||||
|
|
||||||
// pipeline creation
|
// pipeline creation
|
||||||
let vertex_shader = ShaderModule::from_slice(
|
let vertex_shader =
|
||||||
device.clone(),
|
ShaderModule::from_slice(device.clone(), include_bytes!("guishader/rect.vert.spv"))?;
|
||||||
include_bytes!("guishader/rect.vert.spv"),
|
let fragment_shader =
|
||||||
ShaderType::Vertex,
|
ShaderModule::from_slice(device.clone(), include_bytes!("guishader/rect.frag.spv"))?;
|
||||||
)?;
|
|
||||||
let fragment_shader = ShaderModule::from_slice(
|
|
||||||
device.clone(),
|
|
||||||
include_bytes!("guishader/rect.frag.spv"),
|
|
||||||
ShaderType::Fragment,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let (input_bindings, input_attributes) = TexturedVertex::vertex_input_state();
|
|
||||||
|
|
||||||
render_targets.execute(|render_target| {
|
render_targets.execute(|render_target| {
|
||||||
Ok(GuiSeparator {
|
Ok(GuiSeparator {
|
||||||
_descriptor_layout: descriptor_layout.clone(),
|
_descriptor_layout: descriptor_layout.clone(),
|
||||||
|
|
||||||
pipeline: GuiHandler::init_gui_pipeline(
|
pipeline: GuiHandler::init_gui_pipeline::<TexturedVertex>(
|
||||||
device,
|
device,
|
||||||
input_bindings.clone(),
|
|
||||||
input_attributes.clone(),
|
|
||||||
render_target.read().unwrap().render_pass(),
|
render_target.read().unwrap().render_pass(),
|
||||||
&pipeline_layout,
|
&pipeline_layout,
|
||||||
vertex_shader.clone(),
|
vertex_shader.clone(),
|
||||||
|
@ -1508,27 +1494,19 @@ impl GuiHandler {
|
||||||
.build(device.clone())?;
|
.build(device.clone())?;
|
||||||
|
|
||||||
// pipeline creation
|
// pipeline creation
|
||||||
let vertex_shader = ShaderModule::from_slice(
|
let vertex_shader =
|
||||||
device.clone(),
|
ShaderModule::from_slice(device.clone(), include_bytes!("guishader/rect.vert.spv"))?;
|
||||||
include_bytes!("guishader/rect.vert.spv"),
|
|
||||||
ShaderType::Vertex,
|
|
||||||
)?;
|
|
||||||
let fragment_shader = ShaderModule::from_slice(
|
let fragment_shader = ShaderModule::from_slice(
|
||||||
device.clone(),
|
device.clone(),
|
||||||
include_bytes!("guishader/input_rect.frag.spv"),
|
include_bytes!("guishader/input_rect.frag.spv"),
|
||||||
ShaderType::Fragment,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let (input_bindings, input_attributes) = TexturedVertex::vertex_input_state();
|
|
||||||
|
|
||||||
render_targets.execute(|render_target| {
|
render_targets.execute(|render_target| {
|
||||||
Ok(GuiSeparator {
|
Ok(GuiSeparator {
|
||||||
_descriptor_layout: descriptor_layout.clone(),
|
_descriptor_layout: descriptor_layout.clone(),
|
||||||
|
|
||||||
pipeline: GuiHandler::init_gui_pipeline(
|
pipeline: GuiHandler::init_gui_pipeline::<TexturedVertex>(
|
||||||
device,
|
device,
|
||||||
input_bindings.clone(),
|
|
||||||
input_attributes.clone(),
|
|
||||||
render_target.read().unwrap().render_pass(),
|
render_target.read().unwrap().render_pass(),
|
||||||
&pipeline_layout,
|
&pipeline_layout,
|
||||||
vertex_shader.clone(),
|
vertex_shader.clone(),
|
||||||
|
@ -1561,24 +1539,18 @@ impl GuiHandler {
|
||||||
let vertex_shader = ShaderModule::from_slice(
|
let vertex_shader = ShaderModule::from_slice(
|
||||||
device.clone(),
|
device.clone(),
|
||||||
include_bytes!("guishader/single_color.vert.spv"),
|
include_bytes!("guishader/single_color.vert.spv"),
|
||||||
ShaderType::Vertex,
|
|
||||||
)?;
|
)?;
|
||||||
let fragment_shader = ShaderModule::from_slice(
|
let fragment_shader = ShaderModule::from_slice(
|
||||||
device.clone(),
|
device.clone(),
|
||||||
include_bytes!("guishader/single_color.frag.spv"),
|
include_bytes!("guishader/single_color.frag.spv"),
|
||||||
ShaderType::Fragment,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let (input_bindings, input_attributes) = Colorable::vertex_input_state();
|
|
||||||
|
|
||||||
render_targets.execute(|render_target| {
|
render_targets.execute(|render_target| {
|
||||||
Ok(GuiSeparator {
|
Ok(GuiSeparator {
|
||||||
_descriptor_layout: color_layout.clone(),
|
_descriptor_layout: color_layout.clone(),
|
||||||
|
|
||||||
pipeline: GuiHandler::init_gui_pipeline(
|
pipeline: GuiHandler::init_gui_pipeline::<ColorableVertex>(
|
||||||
device,
|
device,
|
||||||
input_bindings.clone(),
|
|
||||||
input_attributes.clone(),
|
|
||||||
render_target.read().unwrap().render_pass(),
|
render_target.read().unwrap().render_pass(),
|
||||||
&pipeline_layout,
|
&pipeline_layout,
|
||||||
vertex_shader.clone(),
|
vertex_shader.clone(),
|
||||||
|
@ -1590,19 +1562,17 @@ impl GuiHandler {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_gui_pipeline(
|
fn init_gui_pipeline<T: VertexInputDescription>(
|
||||||
device: &Arc<Device>,
|
device: &Arc<Device>,
|
||||||
binding_description: Vec<VkVertexInputBindingDescription>,
|
|
||||||
attribute_description: Vec<VkVertexInputAttributeDescription>,
|
|
||||||
render_pass: &Arc<RenderPass>,
|
render_pass: &Arc<RenderPass>,
|
||||||
pipeline_layout: &Arc<PipelineLayout>,
|
pipeline_layout: &Arc<PipelineLayout>,
|
||||||
vertex_shader: Arc<ShaderModule>,
|
vertex_shader: Arc<ShaderModule<{ ShaderType::Vertex as u8 }>>,
|
||||||
fragment_shader: Arc<ShaderModule>,
|
fragment_shader: Arc<ShaderModule<{ ShaderType::Fragment as u8 }>>,
|
||||||
sample_count: VkSampleCountFlags,
|
sample_count: VkSampleCountFlags,
|
||||||
sub_pass: u32,
|
sub_pass: u32,
|
||||||
) -> Result<Arc<Pipeline>> {
|
) -> Result<Arc<Pipeline>> {
|
||||||
Pipeline::new_graphics()
|
Pipeline::new_graphics()
|
||||||
.set_vertex_shader(vertex_shader, binding_description, attribute_description)
|
.set_vertex_shader::<T>(vertex_shader)
|
||||||
.set_fragment_shader(fragment_shader)
|
.set_fragment_shader(fragment_shader)
|
||||||
.input_assembly(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, false)
|
.input_assembly(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, false)
|
||||||
.default_multisample(sample_count)
|
.default_multisample(sample_count)
|
||||||
|
|
Loading…
Reference in a new issue