embree_rs/
lib.rs

1//! [![Crates.io](https://img.shields.io/crates/v/embree-rs.svg)](https://crates.io/crates/embree-rs)
2//! [![Build Status](https://travis-ci.org/Twinklebear/embree-rs.svg?branch=master)](https://travis-ci.org/Twinklebear/embree-rs)
3//! 
4//! Rust bindings to [Embree](http://embree.github.io/). These are still in
5//! development, so a range of features are in progress.
6//! 
7//! # Documentation
8//! 
9//! Rust doc can be found [here](http://www.willusher.io/embree-rs/embree-rs),
10//! Embree documentation can be found [here](https://embree.github.io/api.html).
11//! See the [examples/](https://github.com/Twinklebear/embree-rs/tree/master/examples)
12//! for some example applications using the bindings.
13
14use std::{mem, alloc};
15
16extern crate cgmath;
17
18pub mod buffer;
19pub mod device;
20pub mod geometry;
21pub mod instance;
22pub mod quad_mesh;
23pub mod ray;
24pub mod soa_ray;
25pub mod ray_packet;
26pub mod ray_stream;
27pub mod scene;
28#[allow(non_upper_case_globals)]
29#[allow(non_camel_case_types)]
30#[allow(non_snake_case)]
31pub mod sys;
32pub mod triangle_mesh;
33
34pub use buffer::{Buffer, MappedBuffer};
35pub use device::Device;
36pub use geometry::Geometry;
37pub use instance::Instance;
38pub use quad_mesh::QuadMesh;
39pub use ray::{Ray, Hit, RayHit, IntersectContext};
40pub use soa_ray::{SoARay, SoAHit, SoARayRef, SoARayRefMut,
41                    SoARayIter, SoARayIterMut, SoAHitRef,
42                    SoAHitIter, SoAHitIterMut};
43pub use ray_packet::{Ray4, Hit4, RayHit4};
44pub use ray_stream::{RayN, HitN, RayHitN};
45pub use scene::{Scene, CommittedScene};
46pub use triangle_mesh::TriangleMesh;
47
48// Pull in some cleaned up enum and bitfield types directly,
49// with prettier aliases
50pub use sys::RTCBufferType as BufferType;
51pub use sys::RTCBuildQuality as BuildQuality;
52pub use sys::RTCDeviceProperty as DeviceProperty;
53pub use sys::RTCError as Error;
54pub use sys::RTCFormat as Format;
55pub use sys::RTCGeometryType as GeometryType;
56pub use sys::RTCSubdivisionMode as SubdivisionMode;
57
58pub use sys::RTCBuildFlags as BuildFlags;
59pub use sys::RTCCurveFlags as CurveFlags;
60pub use sys::RTCIntersectContextFlags as IntersectContextFlags;
61pub use sys::RTCSceneFlags as SceneFlags;
62
63/// Utility for making specifically aligned vectors
64pub fn aligned_vector<T>(len: usize, align: usize) -> Vec<T> {
65    let t_size = mem::size_of::<T>();
66    let t_align = mem::align_of::<T>();
67    let layout =
68        if t_align >= align {
69            alloc::Layout::from_size_align(t_size * len, t_align).unwrap()
70        } else {
71            alloc::Layout::from_size_align(t_size * len, align).unwrap()
72        };
73    unsafe {
74        let mem = alloc::alloc(layout);
75        assert_eq!((mem as usize) % 16, 0);
76        Vec::<T>::from_raw_parts(mem as *mut T, len, len)
77    }
78}
79pub fn aligned_vector_init<T: Copy>(len: usize, align: usize, init: T) -> Vec<T> {
80    let mut v = aligned_vector::<T>(len, align);
81    for x in v.iter_mut() {
82        *x = init;
83    }
84    v
85}
86
87#[test]
88fn test_aligned_vector_alloc() {
89    let v = aligned_vector_init::<f32>(24, 16, 1.0);
90    for x in v.iter() {
91        assert_eq!(*x, 1.0);
92    }
93}
94