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