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
use rin_graphics::{CameraMatrices, CameraExt};
use rin_gl as gl;
use rinecs::{EntitiesThreadLocal, ResourcesThreadLocal, system_thread_local};
use crate::renderer::resources;
use crate::transformation::{Camera, CameraChanged, Viewport};

#[system_thread_local(name = "camera ubo updater")]
#[gpu_stats]
#[cond(any(resource("CameraChanged::has_changed"), resource("Viewport::has_changed")))]
#[needs("dyn CameraExt + Send", "Viewport")]
#[updates("resources::CameraUBO")]
pub fn camera_ubo_updater(_e: EntitiesThreadLocal, resources: ResourcesThreadLocal) {
    let camera = resources.as_trait::<dyn CameraExt + Send>().unwrap();
    let viewport = resources.get::<Viewport>().unwrap();
    let matrices = CameraMatrices::with_camera_viewport(&*camera, **viewport);
    let mut camera_ubo = resources.get_mut::<resources::CameraUBO>().unwrap();
    camera_ubo.load(&[matrices.data()], gl::STATIC_DRAW);
    camera_ubo.reversed_z = camera.reversed_z();
    #[cfg(not(any(feature="webgl", feature="gles")))]
    {
        camera_ubo.zero_to_one = camera.reversed_z() && camera.far_at_infinity();
    }
    #[cfg(any(feature="webgl", feature="gles"))]
    if camera.reversed_z() && camera.far_at_infinity() {
        panic!("GL One To Zero not supported, can't enable Camera reversed_z && far at infinity")
    }
    camera_ubo.clamp_depth = camera.depth_clamp();
}