Skip to content

Commit 50f6715

Browse files
vitvakatukvark
authored andcommitted
Replace cgmath bindings by mint (#1301)
* Replace `cgmath-types` by `mint` User needs manually set `mint` feature in his dependencies if he wants to use mint types in constant buffers and/or uniforms for shaders. * Replace `cgmath` by mint in constant buffers. Now supports both column-major and row-major matrices. * Replace `cgmath` by `mint` in uniforms. * Fix imports & appveyor build settings
1 parent a0d9b7e commit 50f6715

File tree

9 files changed

+44
-63
lines changed

9 files changed

+44
-63
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ script:
5454
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then cargo build --features metal; else cargo build; fi
5555
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then HEADLESS_FEATURE="--features headless"; fi
5656
- cargo test --all
57-
- cargo test -p gfx -p gfx_core --features "cgmath-types serialize"
57+
- cargo test -p gfx -p gfx_core --features "mint serialize"
5858
- cargo test -p gfx_window_sdl
5959
- cargo test -p gfx_device_gl
6060
- cargo test -p gfx_window_glutin $HEADLESS_FEATURE

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ documentation = "https://docs.rs/gfx_app"
1010

1111
[features]
1212
default = []
13-
cgmath-types = ["gfx/cgmath-types", "gfx_core/cgmath-types"]
13+
mint = ["gfx/mint", "gfx_core/mint"]
1414
metal = ["gfx_device_metal", "gfx_window_metal", "gfx_device_metalll"]
1515
vulkan = ["gfx_device_vulkan", "gfx_device_vulkanll", "gfx_window_vulkan"]
1616
sdl = ["gfx_window_sdl"]

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ build_script:
1818
- cargo build --features vulkan
1919
test_script:
2020
- cargo test --all --features vulkan
21-
- cargo test -p gfx -p gfx_core --features "cgmath-types serialize"
21+
- cargo test -p gfx -p gfx_core --features "mint serialize"

src/core/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ path = "src/lib.rs"
2929

3030
[dependencies]
3131
bitflags = "0.8"
32-
cgmath = { version = "0.14", optional = true }
32+
mint = { version = "0.4.1", optional = true }
3333
derivative = "1.0"
3434
draw_state = "0.7"
3535
log = "0.3"
3636
serde = { version = "1.0", optional = true }
3737
serde_derive = { version = "1.0", optional = true }
3838

3939
[features]
40-
cgmath-types = ["cgmath"]
4140
serialize = ["serde", "serde_derive", "draw_state/serialize"]
4241
unstable = []

src/core/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ extern crate derivative;
2424
extern crate draw_state;
2525
extern crate log;
2626

27-
#[cfg(feature = "cgmath-types")]
28-
extern crate cgmath;
27+
#[cfg(feature = "mint")]
28+
extern crate mint;
2929

3030
#[cfg(feature = "serialize")]
3131
extern crate serde;
@@ -209,7 +209,7 @@ pub enum IndexType {
209209
U32,
210210
}
211211

212-
/// Different types of a specific API.
212+
/// Different types of a specific API.
213213
#[allow(missing_docs)]
214214
pub trait Resources: Clone + Hash + Debug + Eq + PartialEq + Any {
215215
type Buffer: Clone + Hash + Debug + Eq + PartialEq + Any + Send + Sync + Copy;
@@ -254,7 +254,7 @@ impl Error for SubmissionError {
254254
#[allow(missing_docs)]
255255
pub type SubmissionResult<T> = Result<T, SubmissionError>;
256256

257-
/// A `Device` is responsible for submitting `CommandBuffer`s to the GPU.
257+
/// A `Device` is responsible for submitting `CommandBuffer`s to the GPU.
258258
pub trait Device: Sized {
259259
/// Associated `Resources` type.
260260
type Resources: Resources;
@@ -285,7 +285,7 @@ pub trait Device: Sized {
285285
/// Stalls the current thread until the fence is satisfied
286286
fn wait_fence(&mut self, &handle::Fence<Self::Resources>);
287287

288-
/// Cleanup unused resources. This should be called between frames.
288+
/// Cleanup unused resources. This should be called between frames.
289289
fn cleanup(&mut self);
290290
}
291291

@@ -298,7 +298,7 @@ pub trait Adapter: Sized {
298298
/// Associated `QueueFamily` type.
299299
type QueueFamily: QueueFamily;
300300

301-
/// Enumerate all available adapters supporting this backend
301+
/// Enumerate all available adapters supporting this backend
302302
fn enumerate_adapters() -> Vec<Self>;
303303

304304
/// Create a new device and command queues.

src/core/src/shade.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use std::error::Error;
2121
use {Resources};
2222
use {AttributeSlot, ColorSlot, ConstantBufferSlot, ResourceViewSlot, SamplerSlot, UnorderedViewSlot};
2323

24-
#[cfg(feature = "cgmath-types")]
25-
use cgmath::{Deg, Matrix2, Matrix3, Matrix4, Point2, Point3, Rad, Vector2, Vector3, Vector4};
24+
#[cfg(feature = "mint")]
25+
use mint;
2626

2727
/// Number of components in a container type (vectors/matrices)
2828
pub type Dimension = u8;
@@ -252,11 +252,11 @@ macro_rules! impl_const_matrix {
252252
}
253253
}
254254

255-
#[cfg(feature = "cgmath-types")]
256-
macro_rules! impl_const_vector_cgmath {
255+
#[cfg(feature = "mint")]
256+
macro_rules! impl_const_vector_mint {
257257
( $( $name:ident = $num:expr, )* ) => {
258258
$(
259-
impl<T: BaseTyped> Formatted for $name<T> {
259+
impl<T: BaseTyped> Formatted for mint::$name<T> {
260260
fn get_format() -> ConstFormat {
261261
(T::get_base_type(), ContainerType::Vector($num))
262262
}
@@ -265,13 +265,13 @@ macro_rules! impl_const_vector_cgmath {
265265
}
266266
}
267267

268-
#[cfg(feature = "cgmath-types")]
269-
macro_rules! impl_const_matrix_cgmath {
270-
( $( $name:ident = $size:expr, )* ) => {
268+
#[cfg(feature = "mint")]
269+
macro_rules! impl_const_matrix_mint {
270+
( $( $name:ident = $format:ident $size:expr, )* ) => {
271271
$(
272-
impl<T: BaseTyped> Formatted for $name<T> {
272+
impl<T: BaseTyped> Formatted for mint::$name<T> {
273273
fn get_format() -> ConstFormat {
274-
let mf = MatrixFormat::ColumnMajor;
274+
let mf = MatrixFormat::$format;
275275
(T::get_base_type(), ContainerType::Matrix(mf, $size, $size))
276276
}
277277
}
@@ -286,12 +286,6 @@ impl_base_type! {
286286
bool = Bool,
287287
}
288288

289-
#[cfg(feature = "cgmath-types")]
290-
impl_base_type! {
291-
Deg<f32> = F32,
292-
Rad<f32> = F32,
293-
}
294-
295289
impl<T: BaseTyped> Formatted for T {
296290
fn get_format() -> ConstFormat {
297291
(T::get_base_type(), ContainerType::Single)
@@ -301,20 +295,23 @@ impl<T: BaseTyped> Formatted for T {
301295
impl_const_vector!(2, 3, 4);
302296
impl_const_matrix!([2,2], [3,3], [4,4], [4,3]);
303297

304-
#[cfg(feature = "cgmath-types")]
305-
impl_const_vector_cgmath! {
298+
#[cfg(feature = "mint")]
299+
impl_const_vector_mint! {
306300
Point2 = 2,
307301
Point3 = 3,
308302
Vector2 = 2,
309303
Vector3 = 3,
310304
Vector4 = 4,
311305
}
312306

313-
#[cfg(feature = "cgmath-types")]
314-
impl_const_matrix_cgmath! {
315-
Matrix2 = 2,
316-
Matrix3 = 3,
317-
Matrix4 = 4,
307+
#[cfg(feature = "mint")]
308+
impl_const_matrix_mint! {
309+
ColumnMatrix2 = ColumnMajor 2,
310+
ColumnMatrix3 = ColumnMajor 3,
311+
ColumnMatrix4 = ColumnMajor 4,
312+
RowMatrix2 = RowMajor 2,
313+
RowMatrix3 = RowMajor 3,
314+
RowMatrix4 = RowMajor 4,
318315
}
319316

320317
bitflags!(

src/render/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ name = "gfx"
3030
path = "src/lib.rs"
3131

3232
[features]
33-
cgmath-types = ["gfx_core/cgmath-types", "cgmath"]
3433
serialize = ["gfx_core/serialize", "draw_state/serialize"]
3534
unstable = []
3635

3736
[dependencies]
38-
cgmath = { version = "0.14", optional = true }
37+
mint = { version = "0.4.1", optional = true }
3938
derivative = "1.0"
4039
draw_state = "0.7"
4140
gfx_core = { path = "../core", version = "0.7.1" }

src/render/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
//! An efficient, low-level, bindless graphics API for Rust. See [the
1818
//! blog](http://gfx-rs.github.io/) for explanations and annotated examples.
1919
20-
#[cfg(feature = "cgmath-types")]
21-
extern crate cgmath;
20+
#[cfg(feature = "mint")]
21+
extern crate mint;
2222

2323
extern crate log;
2424
#[macro_use]

src/render/src/shade.rs

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
//! Shader parameter handling.
1616
17-
#[cfg(feature = "cgmath-types")]
18-
use cgmath::{Deg, Matrix2, Matrix3, Matrix4, Rad, Point2, Point3, Vector2, Vector3, Vector4};
17+
#[cfg(feature = "mint")]
18+
use mint;
1919

2020
use std::error::Error;
2121
use std::fmt;
@@ -52,30 +52,16 @@ impl_uniforms! {
5252
[[f32; 4]; 4] = F32Matrix4,
5353
}
5454

55-
#[cfg(feature = "cgmath-types")]
56-
impl ToUniform for Deg<f32> {
57-
fn convert(self) -> core::UniformValue {
58-
core::UniformValue::F32(self.0)
59-
}
60-
}
61-
62-
#[cfg(feature = "cgmath-types")]
63-
impl ToUniform for Rad<f32> {
64-
fn convert(self) -> core::UniformValue {
65-
core::UniformValue::F32(self.0)
66-
}
67-
}
68-
69-
#[cfg(feature = "cgmath-types")]
55+
#[cfg(feature = "mint")]
7056
impl_uniforms! {
71-
Point2<f32> = F32Vector2,
72-
Point3<f32> = F32Vector3,
73-
Vector2<f32> = F32Vector2,
74-
Vector3<f32> = F32Vector3,
75-
Vector4<f32> = F32Vector4,
76-
Matrix2<f32> = F32Matrix2,
77-
Matrix3<f32> = F32Matrix3,
78-
Matrix4<f32> = F32Matrix4,
57+
mint::Point2<f32> = F32Vector2,
58+
mint::Point3<f32> = F32Vector3,
59+
mint::Vector2<f32> = F32Vector2,
60+
mint::Vector3<f32> = F32Vector3,
61+
mint::Vector4<f32> = F32Vector4,
62+
mint::ColumnMatrix2<f32> = F32Matrix2,
63+
mint::ColumnMatrix3<f32> = F32Matrix3,
64+
mint::ColumnMatrix4<f32> = F32Matrix4,
7965
}
8066

8167
/// Program linking error

0 commit comments

Comments
 (0)