Use impl_reprc macro

This commit is contained in:
hodasemi 2023-02-01 14:42:25 +01:00
parent 04f6fde22f
commit 0878e61b3a
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"
assetpath = { git = "https://gavania.de/hodasemi/vulkan_lib.git" }
anyhow = { version = "1.0.68", features = ["backtrace"] }
safer-ffi = { version = "0.0.10", features= ["proc_macros"] }
# optional
audio = { git = "https://gavania.de/hodasemi/audio.git", optional = true }

View file

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

View file

@ -1,15 +1,16 @@
use safer_ffi::derive_ReprC;
use utilities::impl_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_reprc!(
pub struct TexturedVertex {
#[assume_reprc]
position: cgmath::Vector4<f32>,
#[assume_reprc]
texture_coordinates: cgmath::Vector2<f32>,
}
);
impl VertexInputDescription for TexturedVertex {
fn bindings() -> Vec<VkVertexInputBindingDescription> {

View file

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