Skip to content

Replace cgmath bindings by mint #1301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ script:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then cargo build --features metal; else cargo build; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then HEADLESS_FEATURE="--features headless"; fi
- cargo test --all
- cargo test -p gfx -p gfx_core --features "cgmath-types serialize"
- cargo test -p gfx -p gfx_core --features "mint serialize"
- cargo test -p gfx_window_sdl
- cargo test -p gfx_device_gl
- cargo test -p gfx_window_glutin $HEADLESS_FEATURE
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ documentation = "https://docs.rs/gfx_app"

[features]
default = []
cgmath-types = ["gfx/cgmath-types", "gfx_core/cgmath-types"]
mint = ["gfx/mint", "gfx_core/mint"]
metal = ["gfx_device_metal", "gfx_window_metal", "gfx_device_metalll"]
vulkan = ["gfx_device_vulkan", "gfx_device_vulkanll", "gfx_window_vulkan"]
sdl = ["gfx_window_sdl"]
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ build_script:
- cargo build --features vulkan
test_script:
- cargo test --all --features vulkan
- cargo test -p gfx -p gfx_core --features "cgmath-types serialize"
- cargo test -p gfx -p gfx_core --features "mint serialize"
3 changes: 1 addition & 2 deletions src/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ path = "src/lib.rs"

[dependencies]
bitflags = "0.8"
cgmath = { version = "0.14", optional = true }
mint = { version = "0.4.1", optional = true }
derivative = "1.0"
draw_state = "0.7"
log = "0.3"
serde = { version = "1.0", optional = true }
serde_derive = { version = "1.0", optional = true }

[features]
cgmath-types = ["cgmath"]
serialize = ["serde", "serde_derive", "draw_state/serialize"]
unstable = []
12 changes: 6 additions & 6 deletions src/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ extern crate derivative;
extern crate draw_state;
extern crate log;

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

#[cfg(feature = "serialize")]
extern crate serde;
Expand Down Expand Up @@ -209,7 +209,7 @@ pub enum IndexType {
U32,
}

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

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

/// Cleanup unused resources. This should be called between frames.
/// Cleanup unused resources. This should be called between frames.
fn cleanup(&mut self);
}

Expand All @@ -298,7 +298,7 @@ pub trait Adapter: Sized {
/// Associated `QueueFamily` type.
type QueueFamily: QueueFamily;

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

/// Create a new device and command queues.
Expand Down
43 changes: 20 additions & 23 deletions src/core/src/shade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use std::error::Error;
use {Resources};
use {AttributeSlot, ColorSlot, ConstantBufferSlot, ResourceViewSlot, SamplerSlot, UnorderedViewSlot};

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

/// Number of components in a container type (vectors/matrices)
pub type Dimension = u8;
Expand Down Expand Up @@ -252,11 +252,11 @@ macro_rules! impl_const_matrix {
}
}

#[cfg(feature = "cgmath-types")]
macro_rules! impl_const_vector_cgmath {
#[cfg(feature = "mint")]
macro_rules! impl_const_vector_mint {
( $( $name:ident = $num:expr, )* ) => {
$(
impl<T: BaseTyped> Formatted for $name<T> {
impl<T: BaseTyped> Formatted for mint::$name<T> {
fn get_format() -> ConstFormat {
(T::get_base_type(), ContainerType::Vector($num))
}
Expand All @@ -265,13 +265,13 @@ macro_rules! impl_const_vector_cgmath {
}
}

#[cfg(feature = "cgmath-types")]
macro_rules! impl_const_matrix_cgmath {
( $( $name:ident = $size:expr, )* ) => {
#[cfg(feature = "mint")]
macro_rules! impl_const_matrix_mint {
( $( $name:ident = $format:ident $size:expr, )* ) => {
$(
impl<T: BaseTyped> Formatted for $name<T> {
impl<T: BaseTyped> Formatted for mint::$name<T> {
fn get_format() -> ConstFormat {
let mf = MatrixFormat::ColumnMajor;
let mf = MatrixFormat::$format;
(T::get_base_type(), ContainerType::Matrix(mf, $size, $size))
}
}
Expand All @@ -286,12 +286,6 @@ impl_base_type! {
bool = Bool,
}

#[cfg(feature = "cgmath-types")]
impl_base_type! {
Deg<f32> = F32,
Rad<f32> = F32,
}

impl<T: BaseTyped> Formatted for T {
fn get_format() -> ConstFormat {
(T::get_base_type(), ContainerType::Single)
Expand All @@ -301,20 +295,23 @@ impl<T: BaseTyped> Formatted for T {
impl_const_vector!(2, 3, 4);
impl_const_matrix!([2,2], [3,3], [4,4], [4,3]);

#[cfg(feature = "cgmath-types")]
impl_const_vector_cgmath! {
#[cfg(feature = "mint")]
impl_const_vector_mint! {
Point2 = 2,
Point3 = 3,
Vector2 = 2,
Vector3 = 3,
Vector4 = 4,
}

#[cfg(feature = "cgmath-types")]
impl_const_matrix_cgmath! {
Matrix2 = 2,
Matrix3 = 3,
Matrix4 = 4,
#[cfg(feature = "mint")]
impl_const_matrix_mint! {
ColumnMatrix2 = ColumnMajor 2,
ColumnMatrix3 = ColumnMajor 3,
ColumnMatrix4 = ColumnMajor 4,
RowMatrix2 = RowMajor 2,
RowMatrix3 = RowMajor 3,
RowMatrix4 = RowMajor 4,
}

bitflags!(
Expand Down
3 changes: 1 addition & 2 deletions src/render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ name = "gfx"
path = "src/lib.rs"

[features]
cgmath-types = ["gfx_core/cgmath-types", "cgmath"]
serialize = ["gfx_core/serialize", "draw_state/serialize"]
unstable = []

[dependencies]
cgmath = { version = "0.14", optional = true }
mint = { version = "0.4.1", optional = true }
derivative = "1.0"
draw_state = "0.7"
gfx_core = { path = "../core", version = "0.7.1" }
Expand Down
4 changes: 2 additions & 2 deletions src/render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
//! An efficient, low-level, bindless graphics API for Rust. See [the
//! blog](http://gfx-rs.github.io/) for explanations and annotated examples.

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

extern crate log;
#[macro_use]
Expand Down
36 changes: 11 additions & 25 deletions src/render/src/shade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

//! Shader parameter handling.

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

use std::error::Error;
use std::fmt;
Expand Down Expand Up @@ -52,30 +52,16 @@ impl_uniforms! {
[[f32; 4]; 4] = F32Matrix4,
}

#[cfg(feature = "cgmath-types")]
impl ToUniform for Deg<f32> {
fn convert(self) -> core::UniformValue {
core::UniformValue::F32(self.0)
}
}

#[cfg(feature = "cgmath-types")]
impl ToUniform for Rad<f32> {
fn convert(self) -> core::UniformValue {
core::UniformValue::F32(self.0)
}
}

#[cfg(feature = "cgmath-types")]
#[cfg(feature = "mint")]
impl_uniforms! {
Point2<f32> = F32Vector2,
Point3<f32> = F32Vector3,
Vector2<f32> = F32Vector2,
Vector3<f32> = F32Vector3,
Vector4<f32> = F32Vector4,
Matrix2<f32> = F32Matrix2,
Matrix3<f32> = F32Matrix3,
Matrix4<f32> = F32Matrix4,
mint::Point2<f32> = F32Vector2,
mint::Point3<f32> = F32Vector3,
mint::Vector2<f32> = F32Vector2,
mint::Vector3<f32> = F32Vector3,
mint::Vector4<f32> = F32Vector4,
mint::ColumnMatrix2<f32> = F32Matrix2,
mint::ColumnMatrix3<f32> = F32Matrix3,
mint::ColumnMatrix4<f32> = F32Matrix4,
}

/// Program linking error
Expand Down