Skip to content

Commit

Permalink
Load Path at Runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Sep 28, 2024
1 parent d15be1e commit 4fffac2
Show file tree
Hide file tree
Showing 17 changed files with 241 additions and 223 deletions.
31 changes: 16 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions crates/vent-assets/src/io/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ pub(crate) fn get_base_path() -> PathBuf {
///
/// This asset I/O is fully featured but it's not available on `android` and `wasm` targets.
#[allow(dead_code)]
pub struct FileAssetReader {
pub struct FileAsset {
root_path: PathBuf,
}
#[allow(dead_code)]
impl FileAssetReader {
impl FileAsset {
pub fn new<P: AsRef<Path>>(path: P) -> Self {
let root_path = get_base_path().join(path.as_ref());
// try create root
std::fs::create_dir_all(&root_path).expect("Failed to create root dirs");
Self { root_path }
}

Expand Down
2 changes: 1 addition & 1 deletion crates/vent-assets/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use crate::image::Image;

mod file;
pub mod file;

pub struct AssetsLoader {
_image_cache: HashMap<String, Image>,
Expand Down
14 changes: 8 additions & 6 deletions crates/vent-rendering/src/image.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::PathBuf;

use ash::vk::{self, Extent2D};

use crate::{
Expand All @@ -24,12 +26,12 @@ impl DepthImage {
}

pub struct SkyBoxImages {
pub right: String,
pub left: String,
pub top: String,
pub bottom: String,
pub front: String,
pub back: String,
pub right: PathBuf,
pub left: PathBuf,
pub top: PathBuf,
pub bottom: PathBuf,
pub front: PathBuf,
pub back: PathBuf,
}

pub struct VulkanImage {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 5 additions & 10 deletions crates/vent-runtime/src/render/d3/light_renderer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ash::vk;
use vent_assets::io::file::FileAsset;
use vent_math::vec::vec3::Vec3;
use vent_rendering::{
instance::VulkanInstance, mesh::Mesh3D, pipeline::VulkanPipeline, vertex::Vertex3D,
Expand All @@ -18,14 +19,8 @@ pub struct LightRenderer {
#[allow(dead_code)]
impl LightRenderer {
pub fn new(instance: &VulkanInstance) -> Self {
let vertex_shader = concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/shaders/app/3D/light.vert.spv"
);
let fragment_shader = concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/shaders/app/3D/light.frag.spv"
);
let vertex_shader = FileAsset::new("assets/shaders/app/3D/light.vert.spv");
let fragment_shader = FileAsset::new("assets/shaders/app/3D/light.frag.spv");

let desc_layout_bindings = [
vk::DescriptorSetLayoutBinding {
Expand All @@ -46,8 +41,8 @@ impl LightRenderer {

let pipeline = VulkanPipeline::create_simple_pipeline(
instance,
vertex_shader.as_ref(),
fragment_shader.as_ref(),
vertex_shader.root_path(),
fragment_shader.root_path(),
&[Vertex3D::binding_description()],
&Vertex3D::input_descriptions(),
instance.surface_resolution,
Expand Down
70 changes: 25 additions & 45 deletions crates/vent-runtime/src/render/d3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ash::vk;
use pollster::FutureExt;

use skybox_renderer::SkyBoxRenderer;
use vent_assets::io::file::FileAsset;
use vent_ecs::world::World;
use vent_math::{
scalar::mat4::Mat4,
Expand Down Expand Up @@ -69,36 +70,24 @@ impl Renderer for Renderer3D {
let skybox_renderer = SkyBoxRenderer::new(
instance,
SkyBoxImages {
right: concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/textures/skybox/right.jpg"
)
.into(),
left: concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/textures/skybox/left.jpg"
)
.into(),
top: concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/textures/skybox/top.jpg"
)
.into(),
bottom: concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/textures/skybox/bottom.jpg"
)
.into(),
front: concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/textures/skybox/front.jpg"
)
.into(),
back: concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/textures/skybox/back.jpg"
)
.into(),
right: FileAsset::new("assets/textures/skybox/right.jpg")
.root_path()
.clone(),
left: FileAsset::new("assets/textures/skybox/left.jpg")
.root_path()
.clone(),
top: FileAsset::new("assets/textures/skybox/top.jpg")
.root_path()
.clone(),
bottom: FileAsset::new("assets/textures/skybox/bottom.jpg")
.root_path()
.clone(),
front: FileAsset::new("assets/textures/skybox/front.jpg")
.root_path()
.clone(),
back: FileAsset::new("assets/textures/skybox/back.jpg")
.root_path()
.clone(),
},
);

Expand Down Expand Up @@ -143,33 +132,24 @@ impl Renderer for Renderer3D {
// // -------------- DEMO -------------------
let mut world = World::new();

let model = concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/models/test/Sponza-GLTF/Sponza.gltf"
);
let model = FileAsset::new("assets/models/test/Sponza-GLTF/Sponza.gltf");

// Sponza-GLTF/Sponza.gltf
// bistro_outside.glb

let mut material_ubos = vec![];
let light_ubos = vec![];

let vertex_shader = concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/shaders/app/3D/shader.vert.spv"
);
let fragment_shader = concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/shaders/app/3D/shader.frag.spv"
);
let vertex_shader = FileAsset::new("assets/shaders/app/3D/shader.vert.spv");
let fragment_shader = FileAsset::new("assets/shaders/app/3D/shader.frag.spv");

let mut mesh = Entity3D::new(
vent_assets::Model3D::load(
instance,
vertex_shader,
fragment_shader,
vertex_shader.root_path(),
fragment_shader.root_path(),
pipeline_layout,
model,
model.root_path(),
)
.block_on(),
);
Expand Down
15 changes: 5 additions & 10 deletions crates/vent-runtime/src/render/d3/skybox_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::mem::size_of;

use ash::vk;
use image::GenericImageView;
use vent_assets::io::file::FileAsset;
use vent_math::scalar::mat4::Mat4;
use vent_rendering::{
any_as_u8_slice,
Expand Down Expand Up @@ -33,14 +34,8 @@ pub struct SkyBoxUBO {
impl SkyBoxRenderer {
pub fn new(instance: &VulkanInstance, images: SkyBoxImages) -> Self {
log::debug!("Creating skybox");
let vertex_shader = concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/shaders/app/3D/skybox.vert.spv"
);
let fragment_shader = concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/shaders/app/3D/skybox.frag.spv"
);
let vertex_shader = FileAsset::new("assets/shaders/app/3D/skybox.vert.spv");
let fragment_shader = FileAsset::new("assets/shaders/app/3D/skybox.frag.spv");

let desc_layout_bindings = [vk::DescriptorSetLayoutBinding {
binding: 0,
Expand All @@ -56,8 +51,8 @@ impl SkyBoxRenderer {

let pipeline = VulkanPipeline::create_simple_pipeline(
instance,
vertex_shader.as_ref(),
fragment_shader.as_ref(),
vertex_shader.root_path(),
fragment_shader.root_path(),
&[VertexPos3D::binding_description()],
&VertexPos3D::input_descriptions(),
instance.surface_resolution,
Expand Down
1 change: 1 addition & 0 deletions crates/vent-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version.workspace = true
edition.workspace = true

[dependencies]
vent-assets = { path = "../vent-assets"}
vent-rendering = { path = "../vent-rendering"}
vent-math = { path = "../vent-math"}
ash = { version= "0.38", default-features = false }
Expand Down
Loading

0 comments on commit 4fffac2

Please sign in to comment.