Skip to main content

blade_render/
lib.rs

1#![allow(
2    irrefutable_let_patterns,
3    clippy::new_without_default,
4    clippy::needless_borrowed_reference
5)]
6#![warn(
7    trivial_casts,
8    trivial_numeric_casts,
9    unused_extern_crates,
10    //TODO: re-enable. Currently doesn't like "mem::size_of" on newer Rust
11    //unused_qualifications,
12    // We don't match on a reference, unless required.
13    clippy::pattern_type_mismatch,
14)]
15
16mod dummy;
17mod env_map;
18pub use dummy::DummyResources;
19pub use env_map::EnvironmentMap;
20
21#[cfg(not(any(gles, target_arch = "wasm32")))]
22mod asset_hub;
23#[cfg(not(any(gles, target_arch = "wasm32")))]
24pub mod model;
25#[cfg(not(any(gles, target_arch = "wasm32")))]
26pub mod raster;
27#[cfg(not(any(gles, target_arch = "wasm32")))]
28mod render;
29#[cfg(not(any(gles, target_arch = "wasm32")))]
30pub mod shader;
31#[cfg(not(any(gles, target_arch = "wasm32")))]
32pub mod texture;
33#[cfg(not(any(gles, target_arch = "wasm32")))]
34pub mod util;
35
36#[cfg(not(any(gles, target_arch = "wasm32")))]
37pub use asset_hub::*;
38#[cfg(not(any(gles, target_arch = "wasm32")))]
39pub use model::{Model, ProceduralGeometry};
40#[cfg(not(any(gles, target_arch = "wasm32")))]
41pub use raster::{RasterConfig, Rasterizer};
42#[cfg(not(any(gles, target_arch = "wasm32")))]
43pub use render::*;
44#[cfg(not(any(gles, target_arch = "wasm32")))]
45pub use shader::Shader;
46#[cfg(not(any(gles, target_arch = "wasm32")))]
47pub use texture::Texture;
48
49// Has to match the `Vertex` in shaders
50#[repr(C)]
51#[derive(Clone, Copy, Debug, Default, bytemuck::Zeroable, bytemuck::Pod)]
52pub struct Vertex {
53    pub position: [f32; 3],
54    pub bitangent_sign: f32,
55    pub tex_coords: [f32; 2],
56    pub normal: u32,
57    pub tangent: u32,
58}
59
60/// Asymmetric field-of-view angles (in radians).
61/// All angles are positive: left/down are measured from center toward left/down.
62#[derive(Clone, Copy, Debug)]
63pub struct Fov {
64    pub left: f32,
65    pub right: f32,
66    pub up: f32,
67    pub down: f32,
68}
69
70#[derive(Clone, Copy, Debug)]
71pub struct Camera {
72    pub pos: mint::Vector3<f32>,
73    pub rot: mint::Quaternion<f32>,
74    pub fov_y: f32,
75    pub depth: f32,
76    /// Per-eye asymmetric FOV. When set, overrides `fov_y` for projection.
77    pub fov: Option<Fov>,
78}
79
80#[cfg(not(any(gles, target_arch = "wasm32")))]
81pub struct Object {
82    pub model: blade_asset::Handle<Model>,
83    pub transform: blade_graphics::Transform,
84    pub prev_transform: blade_graphics::Transform,
85    /// Per-object color tint multiplied with the material's base_color_factor.
86    /// Default: [1.0, 1.0, 1.0, 1.0] (no tint).
87    pub color_tint: [f32; 4],
88}
89
90#[cfg(not(any(gles, target_arch = "wasm32")))]
91impl From<blade_asset::Handle<Model>> for Object {
92    fn from(model: blade_asset::Handle<Model>) -> Self {
93        Self {
94            model,
95            transform: blade_graphics::IDENTITY_TRANSFORM,
96            prev_transform: blade_graphics::IDENTITY_TRANSFORM,
97            color_tint: [1.0; 4],
98        }
99    }
100}
101
102#[cfg(not(any(gles, target_arch = "wasm32")))]
103#[repr(C)]
104#[derive(Clone, Copy, Default, bytemuck::Zeroable, bytemuck::Pod)]
105struct CameraParams {
106    position: [f32; 3],
107    depth: f32,
108    orientation: [f32; 4],
109    fov: [f32; 2],
110    target_size: [u32; 2],
111}