Skip to content

Commit

Permalink
Add vent-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Jul 7, 2024
1 parent 8784a5e commit 3fceeed
Show file tree
Hide file tree
Showing 168 changed files with 747 additions and 326 deletions.
34 changes: 34 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ For the current Development, look at [GitHub Projects](https://github.com/Snowii

### How to contribute?

Contributions are welcome in any way, shape, or form. See [Contributing](CONTRIBUTING) to know how you can get started:
Contributions are welcome in any way, shape, or form. See [Contributing](CONTRIBUTING) to know how you can get started.

### 🎮 Platforms

Expand Down
12 changes: 4 additions & 8 deletions crates/vent-assets/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
### Vent-Assets

Vent-Assets is a versatile assets and resource library that can load a variety of different asset types including shaders, sound files, textures, meshes, animations, and scripts. It is designed to be fast, efficient, and easy to use, and provides all the data you need about each asset.
Getting Started,
Vent-Assets aims to enhance Vent-Engine's dynamism and provide a standalone crate for others to utilize. The primary objective is to facilitate the seamless implementation of assets within applications.
This allows mod makers and designers to effortlessly modify various aspects of the game, promoting an intuitive and efficient workflow. By leveraging Vent-Assets, individuals can enjoy the flexibility of customizing the game with ease and excellence.

To use Vent-Assets in your project, simply include the Vent-Assets library in your project and start using the provided functions to load and access your assets. You can also use the built-in asset pool to manage your assets and improve performance.
**Models**
- **glTF 2.0** ✅️
- **Wavefront OBJ** ✅️

## Contributing

If you're interested in contributing to Vent-Assets, please fork the repository and submit a pull request. We welcome
contributions of all kinds, including bug fixes, new features, and documentation improvements.
See [Contributing](../../CONTRIBUTING.md)

## License

Expand Down
5 changes: 5 additions & 0 deletions crates/vent-assets/src/image.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub struct Image {}

impl Image {
pub fn new() {}
}
34 changes: 34 additions & 0 deletions crates/vent-assets/src/io/file.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::{
env,
path::{Path, PathBuf},
};

pub(crate) fn get_base_path() -> PathBuf {
if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") {
PathBuf::from(manifest_dir)
} else {
env::current_exe()
.map(|path| path.parent().map(ToOwned::to_owned).unwrap())
.unwrap()
}
}

/// I/O implementation for the local filesystem.
///
/// This asset I/O is fully featured but it's not available on `android` and `wasm` targets.
pub struct FileAssetReader {
root_path: PathBuf,
}

impl FileAssetReader {
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 }
}

pub fn root_path(&self) -> &PathBuf {
&self.root_path
}
}
3 changes: 3 additions & 0 deletions crates/vent-assets/src/io/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod file;

pub struct AssetsLoader {}
6 changes: 3 additions & 3 deletions crates/vent-assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use ash::vk;
use gltf::material::AlphaMode;
use vent_rendering::{buffer::VulkanBuffer, image::VulkanImage};

mod image;
pub mod io;
pub mod model;
pub mod pool;
pub mod shader;

pub trait Asset {}
pub trait Asset: Send + Sync + 'static {}

/// A Full Model/Scene that can be Loaded from a 3D Model File
/// This is done by Parsing all Essensial Informations like Vertices, Indices, Materials & More
Expand Down
3 changes: 2 additions & 1 deletion crates/vent-assets/src/model/gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use ash::{
use gltf::{material::AlphaMode, mesh::Mode, texture::Sampler};
use image::DynamicImage;
use vent_rendering::{
image::VulkanImage, instance::VulkanInstance, Indices, MaterialPipelineInfo, Vertex, Vertex3D,
image::VulkanImage, instance::VulkanInstance, Indices, MaterialPipelineInfo, Vertex3D,
};

use crate::{Material, Model3D, ModelPipeline};
Expand Down Expand Up @@ -399,6 +399,7 @@ impl GLTFLoader {
}

/// Converts an gltf Texture Sampler into Vulkan Sampler Info
/// TODO: Cache Samplers and reuse them
fn convert_sampler<'a>(
sampler: &'a gltf::texture::Sampler<'a>,
) -> vk::SamplerCreateInfo<'static> {
Expand Down
27 changes: 0 additions & 27 deletions crates/vent-assets/src/pool.rs

This file was deleted.

7 changes: 0 additions & 7 deletions crates/vent-assets/src/shader.rs

This file was deleted.

3 changes: 1 addition & 2 deletions crates/vent-ecs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ relationships and interactions with each other.

## Contributing

If you're interested in contributing to Vent-ECS, please fork the repository and submit a pull request. We welcome
contributions of all kinds, including bug fixes, new features, and documentation improvements.
See [Contributing](../../CONTRIBUTING.md)

## License

Expand Down
83 changes: 83 additions & 0 deletions crates/vent-math/src/vec/i32/ivec2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
use std::ops::{Mul, MulAssign};

#[repr(C)]
pub struct IVec2 {
pub x: i32,
pub y: i32,
}

impl IVec2 {
/// All zeroes.
pub const ZERO: Self = Self::splat(0);

/// All ones.
pub const ONE: Self = Self::splat(1);

/// All negative ones.
pub const NEG_ONE: Self = Self::splat(-1);

/// All `i32::MIN`.
pub const MIN: Self = Self::splat(i32::MIN);

/// All `i32::MAX`.
pub const MAX: Self = Self::splat(i32::MAX);

/// A unit vector pointing along the positive X axis.
pub const X: Self = Self::new(1, 0);

/// A unit vector pointing along the positive Y axis.
pub const Y: Self = Self::new(0, 1);

/// A unit vector pointing along the negative X axis.
pub const NEG_X: Self = Self::new(-1, 0);

/// A unit vector pointing along the negative Y axis.
pub const NEG_Y: Self = Self::new(0, -1);

/// The unit axes.
pub const AXES: [Self; 2] = [Self::X, Self::Y];

/// Creates a new vector.
#[inline(always)]
#[must_use]
pub const fn new(x: i32, y: i32) -> Self {
Self { x, y }
}

/// Creates a vector with all elements set to `v`.
#[inline]
#[must_use]
pub const fn splat(v: i32) -> Self {
Self { x: v, y: v }
}
}

impl Mul<i32> for IVec2 {
type Output = Self;
#[inline]
fn mul(self, rhs: i32) -> Self {
Self {
x: self.x.mul(rhs),
y: self.y.mul(rhs),
}
}
}

impl MulAssign<i32> for IVec2 {
#[inline]
fn mul_assign(&mut self, rhs: i32) {
self.x.mul_assign(rhs);
self.y.mul_assign(rhs);
}
}

impl Mul<IVec2> for i32 {
type Output = IVec2;
#[inline]
fn mul(self, rhs: IVec2) -> IVec2 {
IVec2 {
x: self.mul(rhs.x),
y: self.mul(rhs.y),
}
}
}
1 change: 1 addition & 0 deletions crates/vent-math/src/vec/i32/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod ivec2;
2 changes: 2 additions & 0 deletions crates/vent-math/src/vec/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod vec2;
pub mod vec3;
pub mod vec4;

pub mod i32;
60 changes: 60 additions & 0 deletions crates/vent-rendering/src/image.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::mem::size_of_val;

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

use crate::{
Expand Down Expand Up @@ -31,6 +33,64 @@ pub struct VulkanImage {
impl VulkanImage {
pub const DEFAULT_TEXTURE_FILTER: vk::Filter = vk::Filter::LINEAR;

pub fn new(
instance: &VulkanInstance,
data: &[u8],
image_size: Extent2D,
format: vk::Format,
command_pool: vk::CommandPool,
allocator: &MemoryAllocator,
submit_queue: vk::Queue,
sampler_info: Option<vk::SamplerCreateInfo>,
) -> Self {
let mut staging_buffer = VulkanBuffer::new_init(
instance,
allocator,
data.len() as vk::DeviceSize,
vk::BufferUsageFlags::TRANSFER_SRC,
&data,
vk::MemoryPropertyFlags::HOST_VISIBLE | vk::MemoryPropertyFlags::HOST_COHERENT,
None,
);

let image = Self::create_image(
&instance.device,
format,
image_size,
1,
vk::ImageUsageFlags::TRANSFER_DST
| vk::ImageUsageFlags::TRANSFER_SRC
| vk::ImageUsageFlags::SAMPLED,
);
let memory = VulkanBuffer::new_image(&instance.device, allocator, image);
Self::copy_buffer_to_image(
&instance.device,
image,
&staging_buffer,
command_pool,
submit_queue,
image_size,
1,
);
staging_buffer.destroy(&instance.device);
let image_view = Self::create_image_view(
image,
&instance.device,
format,
1,
vk::ImageAspectFlags::COLOR,
);

let sampler_info = sampler_info.unwrap_or(Self::default_sampler());
let sampler = unsafe { instance.device.create_sampler(&sampler_info, None) }.unwrap();
Self {
image,
image_view,
sampler,
memory,
}
}

pub fn from_image(
instance: &VulkanInstance,
image: image::DynamicImage,
Expand Down
18 changes: 8 additions & 10 deletions crates/vent-rendering/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,16 +584,14 @@ impl VulkanInstance {
let wanted_mode = if vsync {
vk::PresentModeKHR::FIFO
} else {
vk::PresentModeKHR::IMMEDIATE
vk::PresentModeKHR::MAILBOX
};

let present_mode = present_modes
.iter()
.find(|&mode| *mode == wanted_mode)
.unwrap_or({
log::warn!("Swapchain: Wanted mode is not supported, Using FIFO");
&vk::PresentModeKHR::FIFO
});
let mut present_mode = vk::PresentModeKHR::FIFO; // Vsync, Always supported
if present_modes.contains(&wanted_mode) {
present_mode = wanted_mode;
} else {
log::warn!("Swapchain: wanted mode is not supported, Using FIFO");
}

let swapchain_create_info = vk::SwapchainCreateInfoKHR::default()
.surface(surface)
Expand All @@ -605,7 +603,7 @@ impl VulkanInstance {
.image_sharing_mode(vk::SharingMode::EXCLUSIVE)
.pre_transform(pre_transform)
.composite_alpha(vk::CompositeAlphaFlagsKHR::OPAQUE)
.present_mode(*present_mode)
.present_mode(present_mode)
.clipped(true)
.image_array_layers(1)
.old_swapchain(old_swapchain.unwrap_or_default());
Expand Down
Loading

0 comments on commit 3fceeed

Please sign in to comment.