Init
This commit is contained in:
commit
a68b8bc000
13 changed files with 370 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
174
Cargo.lock
generated
Normal file
174
Cargo.lock
generated
Normal file
|
@ -0,0 +1,174 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69323bff1fb41c635347b8ead484a5ca6c3f11914d784170b158d8449ab07f8e"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crossbeam-channel",
|
||||
"crossbeam-deque",
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-queue",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-channel"
|
||||
version = "0.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
"maybe-uninit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-deque"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f02af974daeee82218205558e51ec8768b48cf524bd01d550abe5573a608285"
|
||||
dependencies = [
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-utils",
|
||||
"maybe-uninit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-epoch"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"cfg-if",
|
||||
"crossbeam-utils",
|
||||
"lazy_static",
|
||||
"maybe-uninit",
|
||||
"memoffset",
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-queue"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crossbeam-utils",
|
||||
"maybe-uninit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"cfg-if",
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "half"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d36fab90f82edc3c747f9d438e06cf0a491055896f2a279638bb5beed6c40177"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.80"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614"
|
||||
|
||||
[[package]]
|
||||
name = "maybe-uninit"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
|
||||
|
||||
[[package]]
|
||||
name = "memoffset"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "043175f069eda7b85febe4a74abbaeff828d9f8b448515d3151a14a3542811aa"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||
|
||||
[[package]]
|
||||
name = "shared_library"
|
||||
version = "0.1.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7acad6f34eb9e8a259d3283d1e8c1d34d7415943d4895f65cc73813c7396fc85"
|
||||
|
||||
[[package]]
|
||||
name = "tuto1"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"vulkano",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vk-sys"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae0f1a2f2bd58d3063288a278e72ff8d8504897d9a6cf37cadc806ce551bef0b"
|
||||
|
||||
[[package]]
|
||||
name = "vulkano"
|
||||
version = "0.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02729a317fca4d4420d81286ce09471c872ecd55d6d6d6b98c9409707331f925"
|
||||
dependencies = [
|
||||
"crossbeam",
|
||||
"fnv",
|
||||
"half",
|
||||
"lazy_static",
|
||||
"shared_library",
|
||||
"smallvec",
|
||||
"vk-sys",
|
||||
]
|
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "tuto1"
|
||||
version = "0.1.0"
|
||||
authors = ["Florian RICHER <florian.richer@unova.fr>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
vulkano = "0.19"
|
5
src/entities/entity.rs
Normal file
5
src/entities/entity.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
use crate::math::Transform;
|
||||
|
||||
pub trait Entity {
|
||||
fn get_transform(&mut self) -> &mut Transform;
|
||||
}
|
5
src/entities/mod.rs
Normal file
5
src/entities/mod.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
mod entity;
|
||||
mod player;
|
||||
|
||||
pub use entity::Entity;
|
||||
pub use player::Player;
|
21
src/entities/player.rs
Normal file
21
src/entities/player.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use crate::math::Transform;
|
||||
use crate::entities::Entity;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Player {
|
||||
transform: Transform,
|
||||
}
|
||||
|
||||
impl Player {
|
||||
pub fn new() -> Player {
|
||||
Player {
|
||||
transform: Transform::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Entity for Player {
|
||||
fn get_transform(&mut self) -> &mut Transform {
|
||||
&mut self.transform
|
||||
}
|
||||
}
|
16
src/main.rs
Normal file
16
src/main.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
mod render;
|
||||
mod entities;
|
||||
mod math;
|
||||
|
||||
use entities::Entity;
|
||||
use entities::Player;
|
||||
use render::debug;
|
||||
use render::vulkan::test;
|
||||
|
||||
fn main() {
|
||||
let mut player = Player::new();
|
||||
debug(&player);
|
||||
player.get_transform().translate(10.0, 20.0);
|
||||
debug(&player);
|
||||
test();
|
||||
}
|
5
src/math/mod.rs
Normal file
5
src/math/mod.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
mod tranform;
|
||||
mod vec2;
|
||||
|
||||
pub use vec2::Vec2;
|
||||
pub use tranform::Transform;
|
40
src/math/tranform.rs
Normal file
40
src/math/tranform.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
use super::Vec2;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Transform {
|
||||
position: Vec2,
|
||||
rotation: Vec2,
|
||||
scale: Vec2
|
||||
}
|
||||
|
||||
impl Transform {
|
||||
pub fn new() -> Transform {
|
||||
Transform {
|
||||
position: Vec2::new(),
|
||||
rotation: Vec2::new(),
|
||||
scale: Vec2::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_rotation(&self) -> &Vec2 {
|
||||
&self.rotation
|
||||
}
|
||||
|
||||
pub fn get_position(&self) -> &Vec2 {
|
||||
&self.position
|
||||
}
|
||||
|
||||
pub fn get_scale(&self) -> &Vec2 {
|
||||
&self.scale
|
||||
}
|
||||
|
||||
pub fn translate(&mut self, x: f64, y: f64) {
|
||||
self.position.x += x;
|
||||
self.position.y += y;
|
||||
}
|
||||
|
||||
pub fn rotate(&mut self, x: f64, y: f64) {
|
||||
self.rotation.x += x;
|
||||
self.rotation.y += y;
|
||||
}
|
||||
}
|
36
src/math/vec2.rs
Normal file
36
src/math/vec2.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
#[derive(Debug)]
|
||||
pub struct Vec2 {
|
||||
pub x: f64,
|
||||
pub y: f64
|
||||
}
|
||||
|
||||
impl Vec2 {
|
||||
pub fn new() -> Vec2 {
|
||||
Vec2 {
|
||||
x: 0.0,
|
||||
y: 0.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Add<Vec2> for Vec2 {
|
||||
type Output = Vec2;
|
||||
|
||||
fn add(self, b: Vec2) -> Vec2 {
|
||||
Vec2 {
|
||||
x: self.x + b.x,
|
||||
y: self.y + b.y
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Sub<Vec2> for Vec2 {
|
||||
type Output = Vec2;
|
||||
|
||||
fn sub(self, b: Vec2) -> Vec2 {
|
||||
Vec2 {
|
||||
x: self.x - b.x,
|
||||
y: self.y - b.y
|
||||
}
|
||||
}
|
||||
}
|
3
src/render/display.rs
Normal file
3
src/render/display.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
pub fn debug(data: &impl std::fmt::Debug) {
|
||||
println!("{:#?}", data);
|
||||
}
|
4
src/render/mod.rs
Normal file
4
src/render/mod.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
mod display;
|
||||
pub mod vulkan;
|
||||
|
||||
pub use display::debug;
|
50
src/render/vulkan/mod.rs
Normal file
50
src/render/vulkan/mod.rs
Normal file
|
@ -0,0 +1,50 @@
|
|||
use vulkano::sync::GpuFuture;
|
||||
use vulkano::command_buffer::CommandBuffer;
|
||||
use vulkano::command_buffer::AutoCommandBufferBuilder;
|
||||
use vulkano::buffer::BufferUsage;
|
||||
use vulkano::buffer::CpuAccessibleBuffer;
|
||||
use vulkano::device::DeviceExtensions;
|
||||
use vulkano::device::Features;
|
||||
use vulkano::device::Device;
|
||||
use vulkano::instance::PhysicalDevice;
|
||||
use vulkano::instance::Instance;
|
||||
use vulkano::instance::InstanceExtensions;
|
||||
|
||||
pub fn test() {
|
||||
let instance = Instance::new(None, &InstanceExtensions::none(), None)
|
||||
.expect("Failed to create instance");
|
||||
|
||||
let physical = PhysicalDevice::enumerate(&instance).next().expect("No device available");
|
||||
|
||||
let queue_family = physical.queue_families()
|
||||
.find(|&q| q.supports_graphics())
|
||||
.expect("couldn't find a graphical queue family");
|
||||
|
||||
let (device, mut queues) = {
|
||||
Device::new(physical, &Features::none(), &DeviceExtensions::none(),
|
||||
[(queue_family, 0.5)].iter().cloned()).expect("failed to create device")
|
||||
};
|
||||
|
||||
let queue = queues.next().unwrap();
|
||||
|
||||
let source_content = 0 .. 64;
|
||||
let source = CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::all(), false,
|
||||
source_content).expect("failed to create buffer");
|
||||
|
||||
let dest_content = (0 .. 64).map(|_| 0);
|
||||
let dest = CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::all(), false,
|
||||
dest_content).expect("failed to create buffer");
|
||||
|
||||
let mut builder = AutoCommandBufferBuilder::new(device.clone(), queue.family()).unwrap();
|
||||
builder.copy_buffer(source.clone(), dest.clone()).unwrap();
|
||||
let command_buffer = builder.build().unwrap();
|
||||
|
||||
let finished = command_buffer.execute(queue.clone()).unwrap();
|
||||
|
||||
finished.then_signal_fence_and_flush().unwrap()
|
||||
.wait(None).unwrap();
|
||||
|
||||
let src_content = source.read().unwrap();
|
||||
let dest_content = dest.read().unwrap();
|
||||
assert_eq!(&*src_content, &*dest_content);
|
||||
}
|
Loading…
Reference in a new issue