97012950f9
Updates the requirements on [nalgebra](https://github.com/dimforge/nalgebra) to permit the latest version. <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/dimforge/nalgebra/blob/dev/CHANGELOG.md">nalgebra's changelog</a>.</em></p> <blockquote> <h2>[0.30.0] (02 Jan. 2022)</h2> <h3>Breaking changes</h3> <ul> <li>The <code>Dim</code> trait is now marked as unsafe.</li> <li>The <code>Matrix::pow</code> and <code>Matrix::pow_mut</code> methods only allow positive integer exponents now. To compute negative exponents, the user is free to invert the matrix before calling <code>pow</code> with the exponent’s absolute value.</li> </ul> <h3>Modified</h3> <ul> <li>Use more concise debug impls for matrices and geometric transformation types.</li> <li>The singular values computed by the SVD are now sorted in increasing order by default. Use <code>SVD::new_unordered</code> instead to reproduce the older behavior without the sorting overhead.</li> <li>The <code>UnitDualQuaternion::sclerp</code> method will no longer panic when given two equal rotations.</li> <li>The <code>Matrix::select_rows</code> and <code>Matrix::select_columns</code> methods no longer require the matrix components to implement the trait <code>Zero</code>.</li> <li>The <code>Matrix::pow</code> and <code>Matrix::pow_mut</code> methods will now also work with integer matrices.</li> </ul> <h3>Added</h3> <ul> <li>Added the conversion trait <code>From<Vec<T>></code> and method <code>from_vec_storage</code> for <code>RowDVector</code>.</li> <li>Added implementation of <code>From</code> and <code>Into</code> for converting between <code>nalgebra</code> types and types from <code>glam 0.18</code>. These can be enabled by enabling the <code>convert-glam018</code> cargo features.</li> <li>Added the methods <code>Matrix::product</code>, <code>::row_product</code>, <code>::row_product_tr</code>, and <code>::column_product</code> to compute the product of the components, rows, or columns, of a single matrix or vector.</li> <li>The <code>Default</code> trait is now implemented for most geometric types: <code>Point</code>, <code>Isometry</code>, <code>Rotation</code>, <code>Similarity</code>, <code>Transform</code>, <code>UnitComplex</code>, and <code>UnitQuaternion</code>.</li> <li>Added the <code>Scale</code> geometric type for representing non-uniform scaling.</li> <li>Added <code>Cholesky::new_with_substitute</code> that will replace diagonal elements by a given constant whenever <code>Cholesky</code> meets a non-definite-positiveness.</li> <li>Re-added the conversion from a vector/matrix slice to a static array.</li> <li>Added the <code>cuda</code> feature that enables the support of <a href="https://github.com/Rust-GPU/Rust-CUDA">rust-cuda</a> for using <code>nalgebra</code> features with CUDA kernels written in Rust.</li> <li>Added special-cases implementations for the 2x2 and 3x3 SVDs for better accuracy and performances.</li> <li>Added the methods <code>Matrix::polar</code>, <code>Matrix::try_polar</code>, and <code>SVD::to_polar</code> to compute the polar decomposition of a matrix, based on its SVD.</li> <li><code>nalgebra-sparse</code>: provide constructors for unsorted but otherwise valid data using the CSR format.</li> <li><code>nalgebra-sparse</code>: added reading MatrixMarked data files to a sparse <code>CooMatrix</code>.</li> </ul> <h3>Fixed</h3> <ul> <li>Fixed a potential unsoundness with <code>matrix.get(i)</code> and <code>matrix.get_mut(i)</code> where <code>i</code> is an <code>usize</code>, and <code>matrix</code> is a matrix slice with non-default strides.</li> <li>Fixed potential unsoundness with <code>vector.perp</code> where <code>vector</code> isn’t actually a 2D vector as expected.</li> <li>Fixed linkage issue with <code>nalgebra-lapack</code>: the user of <code>nalgebra-lapack</code> no longer have to add <code>extern crate lapack-src</code> to their <code>main.rs</code>.</li> <li>Fixed the <code>no-std</code> build of <code>nalgebra-glm</code>.</li> <li>Fix the <code>pow</code> and <code>pow_mut</code> functions (the result was incorrect for some exponent values).</li> </ul> <h2>[0.29.0]</h2> <h3>Breaking changes</h3> <ul> <li>We updated to the version 0.6 of <code>simba</code>. This means that the trait bounds <code>T: na::RealField</code>, <code>na::ComplexField</code>, <code>na::SimdRealField</code>, <code>na:SimdComplexField</code> no imply that <code>T: Copy</code> (they only imply that <code>T: Clone</code>). This may affect</li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href=" |
||
---|---|---|
.. | ||
bevy-crevice-derive | ||
crevice-tests | ||
src | ||
tests | ||
Cargo.toml | ||
LICENSE-APACHE | ||
LICENSE-MIT | ||
README.md | ||
README.tpl |
Bevy Crevice
This is a fork of Crevice for Bevy.
For use outside of Bevy, you should consider using Crevice directly.
It was forked to allow better integration in Bevy:
- Easier derive macro usage, without needing to depend on
Crevice
directly. - Use of unmerged features (as of the fork), like Array Support.
- Renaming of traits and macros to better match Bevy API.
Crevice
Crevice creates GLSL-compatible versions of types through the power of derive
macros. Generated structures provide an as_bytes
method to allow safely packing data into buffers for uploading.
Generated structs also implement bytemuck::Zeroable
and
bytemuck::Pod
for use with other libraries.
Crevice is similar to glsl-layout
, but supports types from many
math crates, can generate GLSL source from structs, and explicitly initializes
padding to remove one source of undefined behavior.
Crevice has support for many Rust math libraries via feature flags, and most other math libraries by use of the mint crate. Crevice currently supports:
- mint 0.5, enabled by default
- cgmath 0.18, using the
cgmath
feature - nalgebra 0.29, using the
nalgebra
feature - glam 0.20, using the
glam
feature
PRs are welcome to add or update math libraries to Crevice.
If your math library is not supported, it's possible to define structs using the types from mint and convert your math library's types into mint types. This is supported by most Rust math libraries.
Your math library may require you to turn on a feature flag to get mint support. For example, cgmath requires the "mint" feature to be enabled to allow conversions to and from mint types.
Examples
Single Value
Uploading many types can be done by deriving AsStd140
and
using as_std140
and
as_bytes
to turn the result into bytes.
uniform MAIN {
mat3 orientation;
vec3 position;
float scale;
} main;
use bevy_crevice::std140::{AsStd140, Std140};
#[derive(AsStd140)]
struct MainUniform {
orientation: mint::ColumnMatrix3<f32>,
position: mint::Vector3<f32>,
scale: f32,
}
let value = MainUniform {
orientation: [
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0],
].into(),
position: [1.0, 2.0, 3.0].into(),
scale: 4.0,
};
let value_std140 = value.as_std140();
upload_data_to_gpu(value_std140.as_bytes());
Sequential Types
More complicated data can be uploaded using the std140
Writer
type.
struct PointLight {
vec3 position;
vec3 color;
float brightness;
};
buffer POINT_LIGHTS {
uint len;
PointLight[] lights;
} point_lights;
use bevy_crevice::std140::{self, AsStd140};
#[derive(AsStd140)]
struct PointLight {
position: mint::Vector3<f32>,
color: mint::Vector3<f32>,
brightness: f32,
}
let lights = vec![
PointLight {
position: [0.0, 1.0, 0.0].into(),
color: [1.0, 0.0, 0.0].into(),
brightness: 0.6,
},
PointLight {
position: [0.0, 4.0, 3.0].into(),
color: [1.0, 1.0, 1.0].into(),
brightness: 1.0,
},
];
let target_buffer = map_gpu_buffer_for_write();
let mut writer = std140::Writer::new(target_buffer);
let light_count = lights.len() as u32;
writer.write(&light_count)?;
// Crevice will automatically insert the required padding to align the
// PointLight structure correctly. In this case, there will be 12 bytes of
// padding between the length field and the light list.
writer.write(lights.as_slice())?;
unmap_gpu_buffer();
Features
std
(default): Enablesstd::io::Write
-based structs.cgmath
: Enables support for types from cgmath.nalgebra
: Enables support for types from nalgebra.glam
: Enables support for types from glam.
Minimum Supported Rust Version (MSRV)
Crevice supports Rust 1.52.1 and newer due to use of new const fn
features.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
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.