Crates.io | vec-2-10-10-10 |
lib.rs | vec-2-10-10-10 |
version | 0.1.2 |
source | src |
created_at | 2017-09-02 20:22:56.710584 |
updated_at | 2017-09-02 20:28:10.211158 |
description | A 32-bit vector, where 2 bits are dedicated for alpha, and 30 bits are dedicated for color. Compatible with GL_UNSIGNED_INT_2_10_10_10_REV vertex attribute format. |
homepage | |
repository | https://github.com/Nercury/vec-2-10-10-10-rs |
max_upload_size | |
id | 30293 |
size | 24,007 |
This is 32-bit 4-dimensional vector, where the first dimension has 2 bits, and the last 3 dimensions have 10 bits each. It is useful for representing color with an alpha, where the alpha does not require much precision.
It is compatible with GL_UNSIGNED_INT_2_10_10_10_REV
in OpenGL.
extern crate vec_2_10_10_10;
fn main() {
let value = vec_2_10_10_10::Vector::new(0.444, 0.555, 0.666, 0.2);
assert!(approx_equal(value.x(), 0.444));
assert!(approx_equal(value.y(), 0.555));
assert!(approx_equal(value.z(), 0.666));
// 2 bits means only possible values are 0, 0.3(3), 0.6(6) and 1.
assert!(approx_equal(value.w(), 0.333));
}
fn approx_equal(a: f32, b: f32) -> bool {
const DELTA: f32 = 0.001;
a > b - DELTA && a < b + DELTA
}
In your Cargo.toml
, add:
vec-2-10-10-10 = "0.1"
Add reference to the crate:
extern crate vec_2_10_10_10;
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.