Use impl_reprc macro

This commit is contained in:
hodasemi 2023-02-01 14:42:25 +01:00
parent e3d4f7595f
commit c5421404c2
4 changed files with 35 additions and 19 deletions

View file

@ -12,7 +12,6 @@ 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"] }
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 }

View file

@ -2,7 +2,7 @@
use crate::prelude::*; use crate::prelude::*;
use anyhow::Result; use anyhow::Result;
use utilities::prelude::*; use utilities::{impl_reprc, prelude::*};
use vulkan_rs::prelude::*; use vulkan_rs::prelude::*;
use cgmath::{vec4, Vector4}; use cgmath::{vec4, Vector4};
@ -166,12 +166,13 @@ impl Colorable {
} }
} }
#[derive_ReprC] impl_reprc!(
#[repr(C)] #[derive(Debug)]
#[derive(Debug, Clone, Copy)]
pub struct ColorableVertex { pub struct ColorableVertex {
pub position: Vector4<f32>, #[assume_reprc]
position: Vector4<f32>,
} }
);
impl VertexInputDescription for ColorableVertex { impl VertexInputDescription for ColorableVertex {
fn bindings() -> Vec<VkVertexInputBindingDescription> { fn bindings() -> Vec<VkVertexInputBindingDescription> {

View file

@ -1,15 +1,16 @@
use safer_ffi::derive_ReprC; use utilities::impl_reprc;
use vulkan_rs::prelude::*; use vulkan_rs::prelude::*;
use std::mem; use std::mem;
#[derive_ReprC] impl_reprc!(
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct TexturedVertex { pub struct TexturedVertex {
pub position: cgmath::Vector4<f32>, #[assume_reprc]
pub texture_coordinates: cgmath::Vector2<f32>, position: cgmath::Vector4<f32>,
#[assume_reprc]
texture_coordinates: cgmath::Vector2<f32>,
} }
);
impl VertexInputDescription for TexturedVertex { impl VertexInputDescription for TexturedVertex {
fn bindings() -> Vec<VkVertexInputBindingDescription> { fn bindings() -> Vec<VkVertexInputBindingDescription> {

View file

@ -2,7 +2,7 @@ use crate::prelude::*;
use anyhow::Result; use anyhow::Result;
use assetpath::AssetPath; use assetpath::AssetPath;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use utilities::prelude::*; use utilities::{impl_reprc, prelude::*};
use vulkan_rs::{prelude::*, render_target::sub_pass::InputAttachmentInfo}; use vulkan_rs::{prelude::*, render_target::sub_pass::InputAttachmentInfo};
use super::{ use super::{
@ -90,11 +90,18 @@ struct DisplayableTexture {
_texture: Arc<Image>, _texture: Arc<Image>,
} }
impl_reprc!(
struct ColorBuffer {
#[assume_reprc]
color: f32,
}
);
struct TextableColor { struct TextableColor {
_descriptor_pool: Arc<DescriptorPool>, _descriptor_pool: Arc<DescriptorPool>,
_descriptor_set: Arc<DescriptorSet>, _descriptor_set: Arc<DescriptorSet>,
_buffer: Arc<Buffer<f32>>, _buffer: Arc<Buffer<ColorBuffer>>,
} }
struct CommandBufferState { struct CommandBufferState {
@ -546,11 +553,19 @@ impl GuiHandler {
let desc_set = DescriptorPool::prepare_set(&desc_pool).allocate()?; let desc_set = DescriptorPool::prepare_set(&desc_pool).allocate()?;
let color_array: [f32; 3] = color.into(); let color_array: [f32; 3] = color.into();
let color_buffer_array: [ColorBuffer; 3] = color_array
.into_iter()
.map(|f| ColorBuffer { color: f })
.collect::<Vec<ColorBuffer>>()
.try_into()
.unwrap_or_else(|_: Vec<ColorBuffer>| {
unreachable!("create array from vec from an array")
});
let buffer = Buffer::builder() let buffer = Buffer::builder()
.set_usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) .set_usage(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)
.set_memory_usage(MemoryUsage::CpuOnly) .set_memory_usage(MemoryUsage::CpuOnly)
.set_data(&color_array) .set_data(&color_buffer_array)
.build(self.device.clone())?; .build(self.device.clone())?;
desc_set.update(&[DescriptorWrite::uniform_buffers(0, &[&buffer])])?; desc_set.update(&[DescriptorWrite::uniform_buffers(0, &[&buffer])])?;