Compare commits
1 commit
e45e5f242d
...
30bb747e94
Author | SHA1 | Date | |
---|---|---|---|
Alex Janka | 30bb747e94 |
1003
Cargo.lock
generated
1003
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -181,6 +181,7 @@ pub(crate) use config_struct;
|
||||||
pub(crate) use config_version_set;
|
pub(crate) use config_version_set;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
#[deny(deprecated)]
|
||||||
#[deprecated = "Forward declarations for cbindgen, do not use."]
|
#[deprecated = "Forward declarations for cbindgen, do not use."]
|
||||||
mod __cbindgen_opaque_forward_declarations {
|
mod __cbindgen_opaque_forward_declarations {
|
||||||
macro_rules! typedef_struct {
|
macro_rules! typedef_struct {
|
||||||
|
@ -188,6 +189,7 @@ mod __cbindgen_opaque_forward_declarations {
|
||||||
$($(#[$($attrss)*])*
|
$($(#[$($attrss)*])*
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
#[deny(deprecated)]
|
||||||
#[deprecated]
|
#[deprecated]
|
||||||
pub struct $name;
|
pub struct $name;
|
||||||
)*
|
)*
|
||||||
|
|
|
@ -66,6 +66,7 @@
|
||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
#![feature(try_blocks)]
|
#![feature(try_blocks)]
|
||||||
#![deny(unsafe_op_in_unsafe_fn)]
|
#![deny(unsafe_op_in_unsafe_fn)]
|
||||||
|
#![deny(deprecated)]
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
|
|
|
@ -75,34 +75,28 @@ pub(crate) struct FilterCommon {
|
||||||
pub(crate) draw_quad: DrawQuad,
|
pub(crate) draw_quad: DrawQuad,
|
||||||
}
|
}
|
||||||
|
|
||||||
mod compile {
|
type ShaderPassMeta =
|
||||||
use super::*;
|
ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation, SpirvCross> + Send>;
|
||||||
pub type ShaderPassMeta =
|
fn compile_passes(
|
||||||
ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation, SpirvCross> + Send>;
|
shaders: Vec<ShaderPassConfig>,
|
||||||
|
textures: &[TextureConfig],
|
||||||
|
disable_cache: bool,
|
||||||
|
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
||||||
|
let (passes, semantics) = if !disable_cache {
|
||||||
|
HLSL::compile_preset_passes::<
|
||||||
|
CachedCompilation<SpirvCompilation>,
|
||||||
|
SpirvCross,
|
||||||
|
FilterChainError,
|
||||||
|
>(shaders, &textures)?
|
||||||
|
} else {
|
||||||
|
HLSL::compile_preset_passes::<SpirvCompilation, SpirvCross, FilterChainError>(
|
||||||
|
shaders, &textures,
|
||||||
|
)?
|
||||||
|
};
|
||||||
|
|
||||||
pub fn compile_passes(
|
Ok((passes, semantics))
|
||||||
shaders: Vec<ShaderPassConfig>,
|
|
||||||
textures: &[TextureConfig],
|
|
||||||
disable_cache: bool,
|
|
||||||
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
|
||||||
let (passes, semantics) = if !disable_cache {
|
|
||||||
HLSL::compile_preset_passes::<
|
|
||||||
CachedCompilation<SpirvCompilation>,
|
|
||||||
SpirvCross,
|
|
||||||
FilterChainError,
|
|
||||||
>(shaders, &textures)?
|
|
||||||
} else {
|
|
||||||
HLSL::compile_preset_passes::<SpirvCompilation, SpirvCross, FilterChainError>(
|
|
||||||
shaders, &textures,
|
|
||||||
)?
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok((passes, semantics))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
use compile::{compile_passes, ShaderPassMeta};
|
|
||||||
|
|
||||||
impl FilterChainD3D11 {
|
impl FilterChainD3D11 {
|
||||||
/// Load the shader preset at the given path into a filter chain.
|
/// Load the shader preset at the given path into a filter chain.
|
||||||
pub unsafe fn load_from_path(
|
pub unsafe fn load_from_path(
|
||||||
|
|
|
@ -146,56 +146,48 @@ impl Drop for FrameResiduals {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod compile {
|
type DxilShaderPassMeta =
|
||||||
use super::*;
|
ShaderPassArtifact<impl CompileReflectShader<DXIL, SpirvCompilation, SpirvCross> + Send>;
|
||||||
pub type DxilShaderPassMeta =
|
fn compile_passes_dxil(
|
||||||
ShaderPassArtifact<impl CompileReflectShader<DXIL, SpirvCompilation, SpirvCross> + Send>;
|
shaders: Vec<ShaderPassConfig>,
|
||||||
|
textures: &[TextureConfig],
|
||||||
|
disable_cache: bool,
|
||||||
|
) -> Result<(Vec<DxilShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
||||||
|
let (passes, semantics) = if !disable_cache {
|
||||||
|
DXIL::compile_preset_passes::<
|
||||||
|
CachedCompilation<SpirvCompilation>,
|
||||||
|
SpirvCross,
|
||||||
|
FilterChainError,
|
||||||
|
>(shaders, &textures)?
|
||||||
|
} else {
|
||||||
|
DXIL::compile_preset_passes::<SpirvCompilation, SpirvCross, FilterChainError>(
|
||||||
|
shaders, &textures,
|
||||||
|
)?
|
||||||
|
};
|
||||||
|
|
||||||
pub fn compile_passes_dxil(
|
Ok((passes, semantics))
|
||||||
shaders: Vec<ShaderPassConfig>,
|
|
||||||
textures: &[TextureConfig],
|
|
||||||
disable_cache: bool,
|
|
||||||
) -> Result<(Vec<DxilShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
|
||||||
let (passes, semantics) = if !disable_cache {
|
|
||||||
DXIL::compile_preset_passes::<
|
|
||||||
CachedCompilation<SpirvCompilation>,
|
|
||||||
SpirvCross,
|
|
||||||
FilterChainError,
|
|
||||||
>(shaders, &textures)?
|
|
||||||
} else {
|
|
||||||
DXIL::compile_preset_passes::<SpirvCompilation, SpirvCross, FilterChainError>(
|
|
||||||
shaders, &textures,
|
|
||||||
)?
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok((passes, semantics))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type HlslShaderPassMeta =
|
|
||||||
ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation, SpirvCross> + Send>;
|
|
||||||
|
|
||||||
pub fn compile_passes_hlsl(
|
|
||||||
shaders: Vec<ShaderPassConfig>,
|
|
||||||
textures: &[TextureConfig],
|
|
||||||
disable_cache: bool,
|
|
||||||
) -> Result<(Vec<HlslShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
|
||||||
let (passes, semantics) = if !disable_cache {
|
|
||||||
HLSL::compile_preset_passes::<
|
|
||||||
CachedCompilation<SpirvCompilation>,
|
|
||||||
SpirvCross,
|
|
||||||
FilterChainError,
|
|
||||||
>(shaders, &textures)?
|
|
||||||
} else {
|
|
||||||
HLSL::compile_preset_passes::<SpirvCompilation, SpirvCross, FilterChainError>(
|
|
||||||
shaders, &textures,
|
|
||||||
)?
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok((passes, semantics))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
type HlslShaderPassMeta =
|
||||||
|
ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation, SpirvCross> + Send>;
|
||||||
|
fn compile_passes_hlsl(
|
||||||
|
shaders: Vec<ShaderPassConfig>,
|
||||||
|
textures: &[TextureConfig],
|
||||||
|
disable_cache: bool,
|
||||||
|
) -> Result<(Vec<HlslShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
||||||
|
let (passes, semantics) = if !disable_cache {
|
||||||
|
HLSL::compile_preset_passes::<
|
||||||
|
CachedCompilation<SpirvCompilation>,
|
||||||
|
SpirvCross,
|
||||||
|
FilterChainError,
|
||||||
|
>(shaders, &textures)?
|
||||||
|
} else {
|
||||||
|
HLSL::compile_preset_passes::<SpirvCompilation, SpirvCross, FilterChainError>(
|
||||||
|
shaders, &textures,
|
||||||
|
)?
|
||||||
|
};
|
||||||
|
|
||||||
use compile::{compile_passes_dxil, compile_passes_hlsl, DxilShaderPassMeta, HlslShaderPassMeta};
|
Ok((passes, semantics))
|
||||||
|
}
|
||||||
|
|
||||||
impl FilterChainD3D12 {
|
impl FilterChainD3D12 {
|
||||||
/// Load the shader preset at the given path into a filter chain.
|
/// Load the shader preset at the given path into a filter chain.
|
||||||
|
|
|
@ -63,34 +63,29 @@ pub struct FilterChainD3D9 {
|
||||||
default_options: FrameOptionsD3D9,
|
default_options: FrameOptionsD3D9,
|
||||||
}
|
}
|
||||||
|
|
||||||
mod compile {
|
type ShaderPassMeta =
|
||||||
use super::*;
|
ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation, SpirvCross> + Send>;
|
||||||
pub type ShaderPassMeta =
|
|
||||||
ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation, SpirvCross> + Send>;
|
|
||||||
|
|
||||||
pub fn compile_passes(
|
fn compile_passes(
|
||||||
shaders: Vec<ShaderPassConfig>,
|
shaders: Vec<ShaderPassConfig>,
|
||||||
textures: &[TextureConfig],
|
textures: &[TextureConfig],
|
||||||
disable_cache: bool,
|
disable_cache: bool,
|
||||||
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
||||||
let (passes, semantics) = if !disable_cache {
|
let (passes, semantics) = if !disable_cache {
|
||||||
HLSL::compile_preset_passes::<
|
HLSL::compile_preset_passes::<
|
||||||
CachedCompilation<SpirvCompilation>,
|
CachedCompilation<SpirvCompilation>,
|
||||||
SpirvCross,
|
SpirvCross,
|
||||||
FilterChainError,
|
FilterChainError,
|
||||||
>(shaders, &textures)?
|
>(shaders, &textures)?
|
||||||
} else {
|
} else {
|
||||||
HLSL::compile_preset_passes::<SpirvCompilation, SpirvCross, FilterChainError>(
|
HLSL::compile_preset_passes::<SpirvCompilation, SpirvCross, FilterChainError>(
|
||||||
shaders, &textures,
|
shaders, &textures,
|
||||||
)?
|
)?
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((passes, semantics))
|
Ok((passes, semantics))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
use compile::{compile_passes, ShaderPassMeta};
|
|
||||||
|
|
||||||
impl FilterChainD3D9 {
|
impl FilterChainD3D9 {
|
||||||
fn init_passes(
|
fn init_passes(
|
||||||
device: &IDirect3DDevice9,
|
device: &IDirect3DDevice9,
|
||||||
|
|
|
@ -92,34 +92,28 @@ impl<T: GLInterface> FilterChainImpl<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod compile {
|
type ShaderPassMeta =
|
||||||
use super::*;
|
ShaderPassArtifact<impl CompileReflectShader<GLSL, SpirvCompilation, SpirvCross>>;
|
||||||
pub type ShaderPassMeta =
|
fn compile_passes(
|
||||||
ShaderPassArtifact<impl CompileReflectShader<GLSL, SpirvCompilation, SpirvCross>>;
|
shaders: Vec<ShaderPassConfig>,
|
||||||
|
textures: &[TextureConfig],
|
||||||
|
disable_cache: bool,
|
||||||
|
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
||||||
|
let (passes, semantics) = if !disable_cache {
|
||||||
|
GLSL::compile_preset_passes::<
|
||||||
|
CachedCompilation<SpirvCompilation>,
|
||||||
|
SpirvCross,
|
||||||
|
FilterChainError,
|
||||||
|
>(shaders, &textures)?
|
||||||
|
} else {
|
||||||
|
GLSL::compile_preset_passes::<SpirvCompilation, SpirvCross, FilterChainError>(
|
||||||
|
shaders, &textures,
|
||||||
|
)?
|
||||||
|
};
|
||||||
|
|
||||||
pub fn compile_passes(
|
Ok((passes, semantics))
|
||||||
shaders: Vec<ShaderPassConfig>,
|
|
||||||
textures: &[TextureConfig],
|
|
||||||
disable_cache: bool,
|
|
||||||
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
|
||||||
let (passes, semantics) = if !disable_cache {
|
|
||||||
GLSL::compile_preset_passes::<
|
|
||||||
CachedCompilation<SpirvCompilation>,
|
|
||||||
SpirvCross,
|
|
||||||
FilterChainError,
|
|
||||||
>(shaders, &textures)?
|
|
||||||
} else {
|
|
||||||
GLSL::compile_preset_passes::<SpirvCompilation, SpirvCross, FilterChainError>(
|
|
||||||
shaders, &textures,
|
|
||||||
)?
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok((passes, semantics))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
use compile::{compile_passes, ShaderPassMeta};
|
|
||||||
|
|
||||||
impl<T: GLInterface> FilterChainImpl<T> {
|
impl<T: GLInterface> FilterChainImpl<T> {
|
||||||
/// Load a filter chain from a pre-parsed `ShaderPreset`.
|
/// Load a filter chain from a pre-parsed `ShaderPreset`.
|
||||||
pub(crate) unsafe fn load_from_preset(
|
pub(crate) unsafe fn load_from_preset(
|
||||||
|
|
|
@ -187,4 +187,4 @@ impl FramebufferInterface for Gl46Framebuffer {
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -40,25 +40,19 @@ use std::collections::VecDeque;
|
||||||
use std::fmt::{Debug, Formatter};
|
use std::fmt::{Debug, Formatter};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
mod compile {
|
type ShaderPassMeta =
|
||||||
use super::*;
|
ShaderPassArtifact<impl CompileReflectShader<MSL, SpirvCompilation, SpirvCross> + Send>;
|
||||||
pub type ShaderPassMeta =
|
fn compile_passes(
|
||||||
ShaderPassArtifact<impl CompileReflectShader<MSL, SpirvCompilation, SpirvCross> + Send>;
|
shaders: Vec<ShaderPassConfig>,
|
||||||
|
textures: &[TextureConfig],
|
||||||
pub fn compile_passes(
|
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
||||||
shaders: Vec<ShaderPassConfig>,
|
let (passes, semantics) =
|
||||||
textures: &[TextureConfig],
|
MSL::compile_preset_passes::<SpirvCompilation, SpirvCross, FilterChainError>(
|
||||||
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
shaders, &textures,
|
||||||
let (passes, semantics) =
|
)?;
|
||||||
MSL::compile_preset_passes::<SpirvCompilation, SpirvCross, FilterChainError>(
|
Ok((passes, semantics))
|
||||||
shaders, &textures,
|
|
||||||
)?;
|
|
||||||
Ok((passes, semantics))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
use compile::{compile_passes, ShaderPassMeta};
|
|
||||||
|
|
||||||
/// A Metal filter chain.
|
/// A Metal filter chain.
|
||||||
pub struct FilterChainMetal {
|
pub struct FilterChainMetal {
|
||||||
pub(crate) common: FilterCommon,
|
pub(crate) common: FilterCommon,
|
||||||
|
|
|
@ -209,34 +209,28 @@ impl Drop for FrameResiduals {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod compile {
|
type ShaderPassMeta =
|
||||||
use super::*;
|
ShaderPassArtifact<impl CompileReflectShader<SPIRV, SpirvCompilation, SpirvCross> + Send>;
|
||||||
pub type ShaderPassMeta =
|
fn compile_passes(
|
||||||
ShaderPassArtifact<impl CompileReflectShader<SPIRV, SpirvCompilation, SpirvCross> + Send>;
|
shaders: Vec<ShaderPassConfig>,
|
||||||
|
textures: &[TextureConfig],
|
||||||
|
disable_cache: bool,
|
||||||
|
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
||||||
|
let (passes, semantics) = if !disable_cache {
|
||||||
|
SPIRV::compile_preset_passes::<
|
||||||
|
CachedCompilation<SpirvCompilation>,
|
||||||
|
SpirvCross,
|
||||||
|
FilterChainError,
|
||||||
|
>(shaders, &textures)?
|
||||||
|
} else {
|
||||||
|
SPIRV::compile_preset_passes::<SpirvCompilation, SpirvCross, FilterChainError>(
|
||||||
|
shaders, &textures,
|
||||||
|
)?
|
||||||
|
};
|
||||||
|
|
||||||
pub fn compile_passes(
|
Ok((passes, semantics))
|
||||||
shaders: Vec<ShaderPassConfig>,
|
|
||||||
textures: &[TextureConfig],
|
|
||||||
disable_cache: bool,
|
|
||||||
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
|
||||||
let (passes, semantics) = if !disable_cache {
|
|
||||||
SPIRV::compile_preset_passes::<
|
|
||||||
CachedCompilation<SpirvCompilation>,
|
|
||||||
SpirvCross,
|
|
||||||
FilterChainError,
|
|
||||||
>(shaders, &textures)?
|
|
||||||
} else {
|
|
||||||
SPIRV::compile_preset_passes::<SpirvCompilation, SpirvCross, FilterChainError>(
|
|
||||||
shaders, &textures,
|
|
||||||
)?
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok((passes, semantics))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
use compile::{compile_passes, ShaderPassMeta};
|
|
||||||
|
|
||||||
impl FilterChainVulkan {
|
impl FilterChainVulkan {
|
||||||
/// Load the shader preset at the given path into a filter chain.
|
/// Load the shader preset at the given path into a filter chain.
|
||||||
pub unsafe fn load_from_path<V, E>(
|
pub unsafe fn load_from_path<V, E>(
|
||||||
|
|
|
@ -21,7 +21,7 @@ librashader-reflect = { path = "../librashader-reflect", version = "0.2.7", feat
|
||||||
librashader-runtime = { path = "../librashader-runtime" , version = "0.2.7" }
|
librashader-runtime = { path = "../librashader-runtime" , version = "0.2.7" }
|
||||||
|
|
||||||
wgpu = { version = "0.20.0", default-features = false, features = ["wgsl"] }
|
wgpu = { version = "0.20.0", default-features = false, features = ["wgsl"] }
|
||||||
image = "0.25.1"
|
image = "0.24.7"
|
||||||
thiserror = "1.0.50"
|
thiserror = "1.0.50"
|
||||||
bytemuck = { version = "1.14.0", features = ["derive"] }
|
bytemuck = { version = "1.14.0", features = ["derive"] }
|
||||||
array-concat = "0.5.2"
|
array-concat = "0.5.2"
|
||||||
|
|
|
@ -38,25 +38,19 @@ use crate::options::{FilterChainOptionsWgpu, FrameOptionsWgpu};
|
||||||
use crate::samplers::SamplerSet;
|
use crate::samplers::SamplerSet;
|
||||||
use crate::texture::{InputImage, OwnedImage};
|
use crate::texture::{InputImage, OwnedImage};
|
||||||
|
|
||||||
mod compile {
|
type ShaderPassMeta =
|
||||||
use super::*;
|
ShaderPassArtifact<impl CompileReflectShader<WGSL, SpirvCompilation, Naga> + Send>;
|
||||||
pub type ShaderPassMeta =
|
fn compile_passes(
|
||||||
ShaderPassArtifact<impl CompileReflectShader<WGSL, SpirvCompilation, Naga> + Send>;
|
shaders: Vec<ShaderPassConfig>,
|
||||||
|
textures: &[TextureConfig],
|
||||||
pub fn compile_passes(
|
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
||||||
shaders: Vec<ShaderPassConfig>,
|
let (passes, semantics) =
|
||||||
textures: &[TextureConfig],
|
WGSL::compile_preset_passes::<SpirvCompilation, Naga, FilterChainError>(
|
||||||
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
shaders, &textures,
|
||||||
let (passes, semantics) =
|
)?;
|
||||||
WGSL::compile_preset_passes::<SpirvCompilation, Naga, FilterChainError>(
|
Ok((passes, semantics))
|
||||||
shaders, &textures,
|
|
||||||
)?;
|
|
||||||
Ok((passes, semantics))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
use compile::{compile_passes, ShaderPassMeta};
|
|
||||||
|
|
||||||
/// A wgpu filter chain.
|
/// A wgpu filter chain.
|
||||||
pub struct FilterChainWgpu {
|
pub struct FilterChainWgpu {
|
||||||
pub(crate) common: FilterCommon,
|
pub(crate) common: FilterCommon,
|
||||||
|
|
|
@ -23,7 +23,7 @@ array-concat = "0.5.2"
|
||||||
tinymap = "0.4.0"
|
tinymap = "0.4.0"
|
||||||
|
|
||||||
[dependencies.image]
|
[dependencies.image]
|
||||||
version = "0.25.1"
|
version = "0.24.5"
|
||||||
features = [
|
features = [
|
||||||
"gif", "jpeg", "png",
|
"gif", "jpeg", "png",
|
||||||
"tga", "pnm", "tiff",
|
"tga", "pnm", "tiff",
|
||||||
|
|
|
@ -5,27 +5,24 @@ use librashader_presets::{Scale2D, ScaleFactor, ScaleType, Scaling};
|
||||||
use num_traits::AsPrimitive;
|
use num_traits::AsPrimitive;
|
||||||
use std::ops::Mul;
|
use std::ops::Mul;
|
||||||
|
|
||||||
pub const MAX_TEXEL_SIZE: f32 = 16384f32;
|
|
||||||
|
|
||||||
/// Trait for size scaling relative to the viewport.
|
/// Trait for size scaling relative to the viewport.
|
||||||
pub trait ViewportSize<T>
|
pub trait ViewportSize<T>
|
||||||
where
|
where
|
||||||
T: Mul<ScaleFactor, Output = f32> + Copy + Ord + 'static,
|
T: Mul<ScaleFactor, Output = f32> + Copy + 'static,
|
||||||
f32: AsPrimitive<T>,
|
f32: AsPrimitive<T>,
|
||||||
{
|
{
|
||||||
/// Produce a `Size<T>` scaled with the input scaling options.
|
/// Produce a `Size<T>` scaled with the input scaling options.
|
||||||
/// The size will at minimum be 1x1, and at a maximum 16384x16384.
|
|
||||||
fn scale_viewport(self, scaling: Scale2D, viewport: Size<T>, original: Size<T>) -> Size<T>;
|
fn scale_viewport(self, scaling: Scale2D, viewport: Size<T>, original: Size<T>) -> Size<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> ViewportSize<T> for Size<T>
|
impl<T> ViewportSize<T> for Size<T>
|
||||||
where
|
where
|
||||||
T: Mul<ScaleFactor, Output = f32> + Copy + Ord + 'static,
|
T: Mul<ScaleFactor, Output = f32> + Copy + 'static,
|
||||||
f32: AsPrimitive<T>,
|
f32: AsPrimitive<T>,
|
||||||
{
|
{
|
||||||
fn scale_viewport(self, scaling: Scale2D, viewport: Size<T>, original: Size<T>) -> Size<T>
|
fn scale_viewport(self, scaling: Scale2D, viewport: Size<T>, original: Size<T>) -> Size<T>
|
||||||
where
|
where
|
||||||
T: Mul<ScaleFactor, Output = f32> + Copy + Ord + 'static,
|
T: Mul<ScaleFactor, Output = f32> + Copy + 'static,
|
||||||
f32: AsPrimitive<T>,
|
f32: AsPrimitive<T>,
|
||||||
{
|
{
|
||||||
scaling::scale(scaling, self, viewport, original)
|
scaling::scale(scaling, self, viewport, original)
|
||||||
|
@ -38,7 +35,6 @@ pub trait MipmapSize<T> {
|
||||||
fn calculate_miplevels(self) -> T;
|
fn calculate_miplevels(self) -> T;
|
||||||
|
|
||||||
/// Scale the size according to the given mipmap level.
|
/// Scale the size according to the given mipmap level.
|
||||||
/// The size will at minimum be 1x1, and at a maximum 16384x16384.
|
|
||||||
fn scale_mipmap(self, miplevel: T) -> Size<T>;
|
fn scale_mipmap(self, miplevel: T) -> Size<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +59,7 @@ impl MipmapSize<u32> for Size<u32> {
|
||||||
|
|
||||||
fn scale<T>(scaling: Scale2D, source: Size<T>, viewport: Size<T>, original: Size<T>) -> Size<T>
|
fn scale<T>(scaling: Scale2D, source: Size<T>, viewport: Size<T>, original: Size<T>) -> Size<T>
|
||||||
where
|
where
|
||||||
T: Mul<ScaleFactor, Output = f32> + Copy + Ord + 'static,
|
T: Mul<ScaleFactor, Output = f32> + Copy + 'static,
|
||||||
f32: AsPrimitive<T>,
|
f32: AsPrimitive<T>,
|
||||||
{
|
{
|
||||||
let width = match scaling.x {
|
let width = match scaling.x {
|
||||||
|
@ -105,14 +101,8 @@ where
|
||||||
};
|
};
|
||||||
|
|
||||||
Size {
|
Size {
|
||||||
width: std::cmp::min(
|
width: width.round().as_(),
|
||||||
std::cmp::max(width.round().as_(), 1f32.as_()),
|
height: height.round().as_(),
|
||||||
MAX_TEXEL_SIZE.as_(),
|
|
||||||
),
|
|
||||||
height: std::cmp::min(
|
|
||||||
std::cmp::max(height.round().as_(), 1f32.as_()),
|
|
||||||
MAX_TEXEL_SIZE.as_(),
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue