#opengl #unsigned-int #cg #vector #vertex-attribute

vec-2-10-10-10

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.

3 releases

Uses old Rust 2015

0.1.2 Sep 2, 2017
0.1.1 Sep 2, 2017
0.1.0 Sep 2, 2017

#2251 in Data structures

Download history 37/week @ 2024-05-27 34/week @ 2024-06-03 20/week @ 2024-06-10 34/week @ 2024-06-17 31/week @ 2024-06-24 4/week @ 2024-07-08 25/week @ 2024-07-15 24/week @ 2024-07-22 66/week @ 2024-07-29 24/week @ 2024-08-05 45/week @ 2024-08-12 18/week @ 2024-08-19 15/week @ 2024-08-26 20/week @ 2024-09-02 17/week @ 2024-09-09

74 downloads per month

MIT/Apache

13KB
111 lines

A compact, 4D, 32-bit 2-10-10-10 vector

Version Build Status

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.

Example

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
}

Installation

In your Cargo.toml, add:

vec-2-10-10-10 = "0.1"

Add reference to the crate:

extern crate vec_2_10_10_10;

License

Licensed under either of

at your option.

Contribution

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.

No runtime deps