summaryrefslogtreecommitdiffstats
path: root/engine/render/vulkan/data.rs
blob: ae33116e56604fe795bc6051c95ef4c51dc744c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2020 Sergiusz 'q3k' Bazanski <q3k@q3k.org>
//
// This file is part of Abrasion.
//
// Abrasion is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 3.
//
// Abrasion is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// Abrasion.  If not, see <https://www.gnu.org/licenses/>.

use std::sync::Arc;

use vulkano::buffer as vb;
use vulkano::image as vm;
use vulkano::format::Format;

use cgmath as cgm;

#[derive(Default, Copy, Clone, Debug)]
pub struct Vertex {
    pos: [f32; 3],
    normal: [f32; 3],
    tex: [f32; 2],
}

impl Vertex {
    pub fn new(pos: [f32; 3], normal: [f32; 3], tex: [f32; 2]) -> Self {
        Self {
            pos, normal, tex,
        }
    }
}
vulkano::impl_vertex!(Vertex, pos, normal, tex);

#[derive(Default, Copy, Clone)]
pub struct Instance {
    model: [f32; 16],
}

impl Instance {
    pub fn new(model: &cgm::Matrix4<f32>) -> Self {
        let slice: &[f32; 16] = model.as_ref();
        Self { 
            model: slice.clone(),
        }
    }
}
vulkano::impl_vertex!(Instance, model);

#[derive(Copy, Clone, Debug)]
pub struct OmniLight {
    pub pos: [f32; 4],
    pub color: [f32; 4],
}

#[derive(Copy, Clone, Debug)]
pub struct PushConstantObject {
    pub view: cgm::Matrix4<f32>,
}

#[derive(Copy, Clone, Debug)]
pub struct FragmentUniformBufferObject {
    pub camera_pos: cgm::Vector4<f32>,
    pub omni_lights: [OmniLight; 4],
}

#[derive(Clone, Debug)]
pub struct Textures {
    // diffuse: RGB
    pub diffuse: Arc<vm::ImmutableImage<Format>>,
    // roughness: R
    pub roughness: Arc<vm::ImmutableImage<Format>>,
}

pub struct VertexData {
    pub vbuffer: Arc<vb::ImmutableBuffer<[Vertex]>>,
    pub ibuffer: Arc<vb::ImmutableBuffer<[u16]>>,
}

impl std::fmt::Debug for VertexData {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("VertexData").finish()
    }
}