Create gui handler
This commit is contained in:
parent
20ab9443e2
commit
ed5f7e24a7
7 changed files with 100 additions and 9 deletions
|
@ -10,7 +10,9 @@ crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
vulkan-rs = { git = "https://gavania.de/hodasemi/vulkan_lib.git" }
|
vulkan-rs = { git = "https://gavania.de/hodasemi/vulkan_lib.git" }
|
||||||
|
assetpath = { git = "https://gavania.de/hodasemi/vulkan_lib.git" }
|
||||||
rfactor_sm_reader = { git = "https://gavania.de/hodasemi/rfactor_sm_reader.git" }
|
rfactor_sm_reader = { git = "https://gavania.de/hodasemi/rfactor_sm_reader.git" }
|
||||||
|
ui = { git = "https://gavania.de/hodasemi/ui.git" }
|
||||||
|
|
||||||
anyhow = { version = "1.0.68", features = ["backtrace"] }
|
anyhow = { version = "1.0.68", features = ["backtrace"] }
|
||||||
cgmath = { version = "0.18.0", features = ["swizzle", "serde"] }
|
cgmath = { version = "0.18.0", features = ["swizzle", "serde"] }
|
||||||
|
|
0
src/overlay/elements/mod.rs
Normal file
0
src/overlay/elements/mod.rs
Normal file
0
src/overlay/elements/pedals.rs
Normal file
0
src/overlay/elements/pedals.rs
Normal file
0
src/overlay/elements/radar.rs
Normal file
0
src/overlay/elements/radar.rs
Normal file
|
@ -2,7 +2,7 @@ use crate::write_log;
|
||||||
|
|
||||||
use self::{
|
use self::{
|
||||||
rendering::Rendering,
|
rendering::Rendering,
|
||||||
rfactor_data::{DataConfig, RFactorData},
|
rfactor_data::{RFactorData, RadarConfig},
|
||||||
};
|
};
|
||||||
|
|
||||||
mod pipeline;
|
mod pipeline;
|
||||||
|
@ -10,20 +10,24 @@ mod rendering;
|
||||||
mod rfactor_data;
|
mod rfactor_data;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use assetpath::AssetPath;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
use ui::prelude::*;
|
||||||
use vulkan_rs::prelude::*;
|
use vulkan_rs::prelude::*;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub struct OverlayConfig {
|
pub struct OverlayConfig {
|
||||||
pub data_config: DataConfig,
|
pub radar_config: RadarConfig,
|
||||||
|
pub font_path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OverlayConfig {
|
impl OverlayConfig {
|
||||||
pub const fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
data_config: DataConfig::new(),
|
radar_config: RadarConfig::new(),
|
||||||
|
font_path: String::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +39,7 @@ pub struct Overlay {
|
||||||
device: Option<Arc<Device>>,
|
device: Option<Arc<Device>>,
|
||||||
queue: Option<Arc<Mutex<Queue>>>,
|
queue: Option<Arc<Mutex<Queue>>>,
|
||||||
rendering: Option<Rendering>,
|
rendering: Option<Rendering>,
|
||||||
|
gui_handler: Option<Arc<GuiHandler>>,
|
||||||
|
|
||||||
rfactor_data: Option<RFactorData>,
|
rfactor_data: Option<RFactorData>,
|
||||||
}
|
}
|
||||||
|
@ -48,6 +53,7 @@ impl Overlay {
|
||||||
device: None,
|
device: None,
|
||||||
queue: None,
|
queue: None,
|
||||||
rendering: None,
|
rendering: None,
|
||||||
|
gui_handler: None,
|
||||||
|
|
||||||
rfactor_data: None,
|
rfactor_data: None,
|
||||||
}
|
}
|
||||||
|
@ -98,9 +104,29 @@ impl Overlay {
|
||||||
|
|
||||||
write_log!("-> create rendering: old cleared");
|
write_log!("-> create rendering: old cleared");
|
||||||
|
|
||||||
self.rendering = Some(Rendering::new(self.device(), self.queue(), swapchain)?);
|
let rendering = Rendering::new(self.device(), self.queue(), swapchain.clone())?;
|
||||||
|
|
||||||
|
// only font is used
|
||||||
|
let mut create_info = GuiHandlerCreateInfo::default();
|
||||||
|
create_info.font_path = AssetPath::from(self.config.font_path.clone());
|
||||||
|
create_info.font_path.assume_prefix_free();
|
||||||
|
|
||||||
|
let ctx = Arc::new(ContextImpl::new(
|
||||||
|
self.device(),
|
||||||
|
self.queue(),
|
||||||
|
swapchain,
|
||||||
|
rendering.images().clone(),
|
||||||
|
));
|
||||||
|
|
||||||
|
self.gui_handler = Some(GuiHandler::new(
|
||||||
|
create_info,
|
||||||
|
&(ctx as Arc<dyn ContextInterface>),
|
||||||
|
)?);
|
||||||
|
|
||||||
|
self.rendering = Some(rendering);
|
||||||
|
|
||||||
write_log!("-> create rendering: new created");
|
write_log!("-> create rendering: new created");
|
||||||
|
|
||||||
write_log!("-> create rendering: end");
|
write_log!("-> create rendering: end");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -111,7 +137,7 @@ impl Overlay {
|
||||||
|
|
||||||
if self.rfactor_data.is_none() {
|
if self.rfactor_data.is_none() {
|
||||||
self.rfactor_data = RFactorData::new(
|
self.rfactor_data = RFactorData::new(
|
||||||
self.config.data_config,
|
self.config.radar_config,
|
||||||
self.device(),
|
self.device(),
|
||||||
self.rendering
|
self.rendering
|
||||||
.as_mut()
|
.as_mut()
|
||||||
|
@ -139,3 +165,60 @@ impl Overlay {
|
||||||
self.rendering.as_mut().unwrap().render(swapchain, &objects)
|
self.rendering.as_mut().unwrap().render(swapchain, &objects)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ContextImpl {
|
||||||
|
device: Arc<Device>,
|
||||||
|
queue: Arc<Mutex<Queue>>,
|
||||||
|
swapchain: Arc<Swapchain>,
|
||||||
|
images: Vec<Arc<Image>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ContextImpl {
|
||||||
|
fn new(
|
||||||
|
device: Arc<Device>,
|
||||||
|
queue: Arc<Mutex<Queue>>,
|
||||||
|
swapchain: Arc<Swapchain>,
|
||||||
|
images: Vec<Arc<Image>>,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
device,
|
||||||
|
queue,
|
||||||
|
swapchain,
|
||||||
|
images,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ContextInterface for ContextImpl {
|
||||||
|
fn device(&self) -> &Arc<Device> {
|
||||||
|
&self.device
|
||||||
|
}
|
||||||
|
|
||||||
|
fn queue(&self) -> &Arc<Mutex<Queue>> {
|
||||||
|
&self.queue
|
||||||
|
}
|
||||||
|
|
||||||
|
fn format(&self) -> VkFormat {
|
||||||
|
self.swapchain.format()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn image_layout(&self) -> VkImageLayout {
|
||||||
|
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
|
||||||
|
}
|
||||||
|
|
||||||
|
fn image_count(&self) -> usize {
|
||||||
|
self.images.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn images(&self) -> TargetMode<Vec<Arc<Image>>> {
|
||||||
|
TargetMode::Mono(self.images.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn width(&self) -> u32 {
|
||||||
|
self.swapchain.width()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn height(&self) -> u32 {
|
||||||
|
self.swapchain.height()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ pub struct Rendering {
|
||||||
pipeline: SingleColorPipeline,
|
pipeline: SingleColorPipeline,
|
||||||
render_target: RenderTarget,
|
render_target: RenderTarget,
|
||||||
command_buffer: Arc<CommandBuffer>,
|
command_buffer: Arc<CommandBuffer>,
|
||||||
|
images: Vec<Arc<Image>>,
|
||||||
|
|
||||||
queue: Arc<Mutex<Queue>>,
|
queue: Arc<Mutex<Queue>>,
|
||||||
}
|
}
|
||||||
|
@ -97,6 +98,7 @@ impl Rendering {
|
||||||
pipeline: SingleColorPipeline::new(device.clone(), render_target.render_pass())?,
|
pipeline: SingleColorPipeline::new(device.clone(), render_target.render_pass())?,
|
||||||
render_target,
|
render_target,
|
||||||
command_buffer: CommandBuffer::new_primary().build(device.clone(), queue.clone())?,
|
command_buffer: CommandBuffer::new_primary().build(device.clone(), queue.clone())?,
|
||||||
|
images,
|
||||||
|
|
||||||
queue,
|
queue,
|
||||||
})
|
})
|
||||||
|
@ -165,4 +167,8 @@ impl Rendering {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn images(&self) -> &Vec<Arc<Image>> {
|
||||||
|
&self.images
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub trait RenderObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Clone, Copy, Debug)]
|
#[derive(Deserialize, Serialize, Clone, Copy, Debug)]
|
||||||
pub struct DataConfig {
|
pub struct RadarConfig {
|
||||||
pub radar_scale: f32,
|
pub radar_scale: f32,
|
||||||
pub radar_center_factor: f32,
|
pub radar_center_factor: f32,
|
||||||
pub radar_transparency: f32,
|
pub radar_transparency: f32,
|
||||||
|
@ -31,7 +31,7 @@ pub struct DataConfig {
|
||||||
pub danger_color: Vector3<f32>,
|
pub danger_color: Vector3<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DataConfig {
|
impl RadarConfig {
|
||||||
pub const fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
radar_scale: 1.0,
|
radar_scale: 1.0,
|
||||||
|
@ -48,7 +48,7 @@ impl DataConfig {
|
||||||
|
|
||||||
pub struct RFactorData {
|
pub struct RFactorData {
|
||||||
// config
|
// config
|
||||||
config: DataConfig,
|
config: RadarConfig,
|
||||||
|
|
||||||
// rf2 memory mapped data
|
// rf2 memory mapped data
|
||||||
telemetry_reader: TelemetryReader,
|
telemetry_reader: TelemetryReader,
|
||||||
|
@ -82,7 +82,7 @@ pub struct RFactorData {
|
||||||
|
|
||||||
impl RFactorData {
|
impl RFactorData {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
config: DataConfig,
|
config: RadarConfig,
|
||||||
device: Arc<Device>,
|
device: Arc<Device>,
|
||||||
descriptor_layout: &Arc<DescriptorSetLayout>,
|
descriptor_layout: &Arc<DescriptorSetLayout>,
|
||||||
width: u32,
|
width: u32,
|
||||||
|
|
Loading…
Reference in a new issue