mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-12 02:02:20 +00:00
detached texture-related code to separate crate
- allows to attach it to `fyrox-ui` to use textures directly without using hacky `UntypedResource` - fixed syncing bug of R coordinate for volume textures
This commit is contained in:
Generated
+1
@@ -44,6 +44,7 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/template-core/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/fyrox-graphics/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/fyrox-build-tools/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/fyrox-texture/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/examples/wasm/target" />
|
||||
</content>
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ members = [
|
||||
"project-manager",
|
||||
"fyrox-graphics",
|
||||
"fyrox-build-tools"
|
||||
]
|
||||
, "fyrox-texture"]
|
||||
resolver = "2"
|
||||
|
||||
[profile.dev]
|
||||
|
||||
@@ -23,15 +23,14 @@ fyrox-resource = { path = "../fyrox-resource", version = "0.36.0" }
|
||||
fyrox-animation = { path = "../fyrox-animation", version = "0.36.0" }
|
||||
fyrox-graph = { path = "../fyrox-graph", version = "0.36.0" }
|
||||
fyrox-graphics = { path = "../fyrox-graphics", version = "0.36.0" }
|
||||
fyrox-texture = { path = "../fyrox-texture", version = "0.36.0" }
|
||||
rapier2d = { version = "0.22", features = ["debug-render"] }
|
||||
rapier3d = { version = "0.22", features = ["debug-render"] }
|
||||
image = { version = "0.25.1", default-features = false, features = ["gif", "jpeg", "png", "tga", "tiff", "bmp"] }
|
||||
inflate = "0.4.5"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
lazy_static = "1.4.0"
|
||||
ddsfile = "0.5.0"
|
||||
rayon = "1.5.1"
|
||||
tbc = "0.3.0"
|
||||
bitflags = "2.2.1"
|
||||
walkdir = "2.3.2"
|
||||
ron = "0.8.0"
|
||||
@@ -41,7 +40,6 @@ strum_macros = "0.26.1"
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
winit = { version = "0.29.2", features = ["serde"] }
|
||||
half = { version = "2.2.1", features = ["bytemuck"] }
|
||||
fast_image_resize = "4.0.0"
|
||||
base64 = "0.22.1"
|
||||
uvgen = "0.2.0"
|
||||
lightmap = "0.2"
|
||||
|
||||
@@ -45,7 +45,6 @@ pub mod utils;
|
||||
pub use crate::core::rand;
|
||||
pub use fxhash;
|
||||
pub use lazy_static;
|
||||
pub use tbc;
|
||||
pub use walkdir;
|
||||
pub use winit::*;
|
||||
|
||||
|
||||
+109
-14
@@ -30,7 +30,13 @@ use crate::{
|
||||
},
|
||||
resource::texture::{Texture, TextureResource},
|
||||
};
|
||||
use fyrox_graphics::gpu_texture::GpuTextureDescriptor;
|
||||
use fyrox_graphics::gpu_texture::{
|
||||
GpuTextureDescriptor, GpuTextureKind, MagnificationFilter, MinificationFilter, WrapMode,
|
||||
};
|
||||
use fyrox_texture::{
|
||||
TextureKind, TextureMagnificationFilter, TextureMinificationFilter, TexturePixelKind,
|
||||
TextureWrapMode,
|
||||
};
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
pub(crate) struct TextureRenderData {
|
||||
@@ -43,20 +49,103 @@ pub struct TextureCache {
|
||||
cache: TemporaryCache<TextureRenderData>,
|
||||
}
|
||||
|
||||
fn convert_texture_kind(v: TextureKind) -> GpuTextureKind {
|
||||
match v {
|
||||
TextureKind::Line { length } => GpuTextureKind::Line {
|
||||
length: length as usize,
|
||||
},
|
||||
TextureKind::Rectangle { width, height } => GpuTextureKind::Rectangle {
|
||||
width: width as usize,
|
||||
height: height as usize,
|
||||
},
|
||||
TextureKind::Cube { width, height } => GpuTextureKind::Cube {
|
||||
width: width as usize,
|
||||
height: height as usize,
|
||||
},
|
||||
TextureKind::Volume {
|
||||
width,
|
||||
height,
|
||||
depth,
|
||||
} => GpuTextureKind::Volume {
|
||||
width: width as usize,
|
||||
height: height as usize,
|
||||
depth: depth as usize,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_pixel_kind(texture_kind: TexturePixelKind) -> PixelKind {
|
||||
match texture_kind {
|
||||
TexturePixelKind::R8 => PixelKind::R8,
|
||||
TexturePixelKind::RGB8 => PixelKind::RGB8,
|
||||
TexturePixelKind::RGBA8 => PixelKind::RGBA8,
|
||||
TexturePixelKind::RG8 => PixelKind::RG8,
|
||||
TexturePixelKind::R16 => PixelKind::R16,
|
||||
TexturePixelKind::RG16 => PixelKind::RG16,
|
||||
TexturePixelKind::BGR8 => PixelKind::BGR8,
|
||||
TexturePixelKind::BGRA8 => PixelKind::BGRA8,
|
||||
TexturePixelKind::RGB16 => PixelKind::RGB16,
|
||||
TexturePixelKind::RGBA16 => PixelKind::RGBA16,
|
||||
TexturePixelKind::RGB16F => PixelKind::RGB16F,
|
||||
TexturePixelKind::DXT1RGB => PixelKind::DXT1RGB,
|
||||
TexturePixelKind::DXT1RGBA => PixelKind::DXT1RGBA,
|
||||
TexturePixelKind::DXT3RGBA => PixelKind::DXT3RGBA,
|
||||
TexturePixelKind::DXT5RGBA => PixelKind::DXT5RGBA,
|
||||
TexturePixelKind::R8RGTC => PixelKind::R8RGTC,
|
||||
TexturePixelKind::RG8RGTC => PixelKind::RG8RGTC,
|
||||
TexturePixelKind::RGB32F => PixelKind::RGB32F,
|
||||
TexturePixelKind::RGBA32F => PixelKind::RGBA32F,
|
||||
TexturePixelKind::Luminance8 => PixelKind::L8,
|
||||
TexturePixelKind::LuminanceAlpha8 => PixelKind::LA8,
|
||||
TexturePixelKind::Luminance16 => PixelKind::L16,
|
||||
TexturePixelKind::LuminanceAlpha16 => PixelKind::LA16,
|
||||
TexturePixelKind::R32F => PixelKind::R32F,
|
||||
TexturePixelKind::R16F => PixelKind::R16F,
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_magnification_filter(v: TextureMagnificationFilter) -> MagnificationFilter {
|
||||
match v {
|
||||
TextureMagnificationFilter::Nearest => MagnificationFilter::Nearest,
|
||||
TextureMagnificationFilter::Linear => MagnificationFilter::Linear,
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_minification_filter(v: TextureMinificationFilter) -> MinificationFilter {
|
||||
match v {
|
||||
TextureMinificationFilter::Nearest => MinificationFilter::Nearest,
|
||||
TextureMinificationFilter::NearestMipMapNearest => MinificationFilter::NearestMipMapNearest,
|
||||
TextureMinificationFilter::NearestMipMapLinear => MinificationFilter::NearestMipMapLinear,
|
||||
TextureMinificationFilter::Linear => MinificationFilter::Linear,
|
||||
TextureMinificationFilter::LinearMipMapNearest => MinificationFilter::LinearMipMapNearest,
|
||||
TextureMinificationFilter::LinearMipMapLinear => MinificationFilter::LinearMipMapLinear,
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_wrap_mode(v: TextureWrapMode) -> WrapMode {
|
||||
match v {
|
||||
TextureWrapMode::Repeat => WrapMode::Repeat,
|
||||
TextureWrapMode::ClampToEdge => WrapMode::ClampToEdge,
|
||||
TextureWrapMode::ClampToBorder => WrapMode::ClampToBorder,
|
||||
TextureWrapMode::MirroredRepeat => WrapMode::MirroredRepeat,
|
||||
TextureWrapMode::MirrorClampToEdge => WrapMode::MirrorClampToEdge,
|
||||
}
|
||||
}
|
||||
|
||||
fn create_gpu_texture(
|
||||
server: &dyn GraphicsServer,
|
||||
texture: &Texture,
|
||||
) -> Result<TextureRenderData, FrameworkError> {
|
||||
server
|
||||
.create_texture(GpuTextureDescriptor {
|
||||
kind: texture.kind().into(),
|
||||
pixel_kind: PixelKind::from(texture.pixel_kind()),
|
||||
mag_filter: texture.magnification_filter().into(),
|
||||
min_filter: texture.minification_filter().into(),
|
||||
kind: convert_texture_kind(texture.kind()),
|
||||
pixel_kind: convert_pixel_kind(texture.pixel_kind()),
|
||||
mag_filter: convert_magnification_filter(texture.magnification_filter()),
|
||||
min_filter: convert_minification_filter(texture.minification_filter()),
|
||||
mip_count: texture.mip_count() as usize,
|
||||
s_wrap_mode: texture.s_wrap_mode().into(),
|
||||
t_wrap_mode: texture.t_wrap_mode().into(),
|
||||
r_wrap_mode: texture.r_wrap_mode().into(),
|
||||
s_wrap_mode: convert_wrap_mode(texture.s_wrap_mode()),
|
||||
t_wrap_mode: convert_wrap_mode(texture.t_wrap_mode()),
|
||||
r_wrap_mode: convert_wrap_mode(texture.r_wrap_mode()),
|
||||
anisotropy: texture.anisotropy_level(),
|
||||
data: Some(texture.data()),
|
||||
base_level: texture.base_level(),
|
||||
@@ -115,8 +204,8 @@ impl TextureCache {
|
||||
if entry.modifications_counter != modifications_count {
|
||||
let mut gpu_texture = entry.gpu_texture.borrow_mut();
|
||||
if let Err(e) = gpu_texture.set_data(
|
||||
texture.kind().into(),
|
||||
texture.pixel_kind().into(),
|
||||
convert_texture_kind(texture.kind()),
|
||||
convert_pixel_kind(texture.pixel_kind()),
|
||||
texture.mip_count() as usize,
|
||||
Some(texture.data()),
|
||||
) {
|
||||
@@ -131,12 +220,13 @@ impl TextureCache {
|
||||
|
||||
let mut gpu_texture = entry.gpu_texture.borrow_mut();
|
||||
|
||||
let new_mag_filter = texture.magnification_filter().into();
|
||||
let new_mag_filter =
|
||||
convert_magnification_filter(texture.magnification_filter());
|
||||
if gpu_texture.magnification_filter() != new_mag_filter {
|
||||
gpu_texture.set_magnification_filter(new_mag_filter);
|
||||
}
|
||||
|
||||
let new_min_filter = texture.minification_filter().into();
|
||||
let new_min_filter = convert_minification_filter(texture.minification_filter());
|
||||
if gpu_texture.minification_filter() != new_min_filter {
|
||||
gpu_texture.set_minification_filter(new_min_filter);
|
||||
}
|
||||
@@ -145,16 +235,21 @@ impl TextureCache {
|
||||
gpu_texture.set_anisotropy(texture.anisotropy_level());
|
||||
}
|
||||
|
||||
let new_s_wrap_mode = texture.s_wrap_mode().into();
|
||||
let new_s_wrap_mode = convert_wrap_mode(texture.s_wrap_mode());
|
||||
if gpu_texture.wrap_mode(Coordinate::S) != new_s_wrap_mode {
|
||||
gpu_texture.set_wrap(Coordinate::S, new_s_wrap_mode);
|
||||
}
|
||||
|
||||
let new_t_wrap_mode = texture.t_wrap_mode().into();
|
||||
let new_t_wrap_mode = convert_wrap_mode(texture.t_wrap_mode());
|
||||
if gpu_texture.wrap_mode(Coordinate::T) != new_t_wrap_mode {
|
||||
gpu_texture.set_wrap(Coordinate::T, new_t_wrap_mode);
|
||||
}
|
||||
|
||||
let new_r_wrap_mode = convert_wrap_mode(texture.r_wrap_mode());
|
||||
if gpu_texture.wrap_mode(Coordinate::R) != new_r_wrap_mode {
|
||||
gpu_texture.set_wrap(Coordinate::R, new_r_wrap_mode);
|
||||
}
|
||||
|
||||
return Some(&entry.gpu_texture);
|
||||
}
|
||||
Err(e) => {
|
||||
|
||||
@@ -28,112 +28,12 @@ use crate::{
|
||||
AttributeDefinition, AttributeKind, GeometryBuffer, GeometryBufferDescriptor,
|
||||
VertexBufferData, VertexBufferDescriptor,
|
||||
},
|
||||
gpu_texture::{
|
||||
GpuTextureKind, MagnificationFilter, MinificationFilter, PixelKind, WrapMode,
|
||||
},
|
||||
server::GraphicsServer,
|
||||
},
|
||||
resource::texture::{
|
||||
TextureKind, TextureMagnificationFilter, TextureMinificationFilter, TexturePixelKind,
|
||||
TextureWrapMode,
|
||||
},
|
||||
scene::mesh::{buffer::VertexAttributeDataType, surface::SurfaceData},
|
||||
};
|
||||
pub use fyrox_graphics::*;
|
||||
|
||||
impl From<TextureKind> for GpuTextureKind {
|
||||
fn from(v: TextureKind) -> Self {
|
||||
match v {
|
||||
TextureKind::Line { length } => GpuTextureKind::Line {
|
||||
length: length as usize,
|
||||
},
|
||||
TextureKind::Rectangle { width, height } => GpuTextureKind::Rectangle {
|
||||
width: width as usize,
|
||||
height: height as usize,
|
||||
},
|
||||
TextureKind::Cube { width, height } => GpuTextureKind::Cube {
|
||||
width: width as usize,
|
||||
height: height as usize,
|
||||
},
|
||||
TextureKind::Volume {
|
||||
width,
|
||||
height,
|
||||
depth,
|
||||
} => GpuTextureKind::Volume {
|
||||
width: width as usize,
|
||||
height: height as usize,
|
||||
depth: depth as usize,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TexturePixelKind> for PixelKind {
|
||||
fn from(texture_kind: TexturePixelKind) -> Self {
|
||||
match texture_kind {
|
||||
TexturePixelKind::R8 => Self::R8,
|
||||
TexturePixelKind::RGB8 => Self::RGB8,
|
||||
TexturePixelKind::RGBA8 => Self::RGBA8,
|
||||
TexturePixelKind::RG8 => Self::RG8,
|
||||
TexturePixelKind::R16 => Self::R16,
|
||||
TexturePixelKind::RG16 => Self::RG16,
|
||||
TexturePixelKind::BGR8 => Self::BGR8,
|
||||
TexturePixelKind::BGRA8 => Self::BGRA8,
|
||||
TexturePixelKind::RGB16 => Self::RGB16,
|
||||
TexturePixelKind::RGBA16 => Self::RGBA16,
|
||||
TexturePixelKind::RGB16F => Self::RGB16F,
|
||||
TexturePixelKind::DXT1RGB => Self::DXT1RGB,
|
||||
TexturePixelKind::DXT1RGBA => Self::DXT1RGBA,
|
||||
TexturePixelKind::DXT3RGBA => Self::DXT3RGBA,
|
||||
TexturePixelKind::DXT5RGBA => Self::DXT5RGBA,
|
||||
TexturePixelKind::R8RGTC => Self::R8RGTC,
|
||||
TexturePixelKind::RG8RGTC => Self::RG8RGTC,
|
||||
TexturePixelKind::RGB32F => Self::RGB32F,
|
||||
TexturePixelKind::RGBA32F => Self::RGBA32F,
|
||||
TexturePixelKind::Luminance8 => Self::L8,
|
||||
TexturePixelKind::LuminanceAlpha8 => Self::LA8,
|
||||
TexturePixelKind::Luminance16 => Self::L16,
|
||||
TexturePixelKind::LuminanceAlpha16 => Self::LA16,
|
||||
TexturePixelKind::R32F => Self::R32F,
|
||||
TexturePixelKind::R16F => Self::R16F,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TextureMagnificationFilter> for MagnificationFilter {
|
||||
fn from(v: TextureMagnificationFilter) -> Self {
|
||||
match v {
|
||||
TextureMagnificationFilter::Nearest => Self::Nearest,
|
||||
TextureMagnificationFilter::Linear => Self::Linear,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TextureMinificationFilter> for MinificationFilter {
|
||||
fn from(v: TextureMinificationFilter) -> Self {
|
||||
match v {
|
||||
TextureMinificationFilter::Nearest => Self::Nearest,
|
||||
TextureMinificationFilter::NearestMipMapNearest => Self::NearestMipMapNearest,
|
||||
TextureMinificationFilter::NearestMipMapLinear => Self::NearestMipMapLinear,
|
||||
TextureMinificationFilter::Linear => Self::Linear,
|
||||
TextureMinificationFilter::LinearMipMapNearest => Self::LinearMipMapNearest,
|
||||
TextureMinificationFilter::LinearMipMapLinear => Self::LinearMipMapLinear,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<TextureWrapMode> for WrapMode {
|
||||
fn from(v: TextureWrapMode) -> Self {
|
||||
match v {
|
||||
TextureWrapMode::Repeat => WrapMode::Repeat,
|
||||
TextureWrapMode::ClampToEdge => WrapMode::ClampToEdge,
|
||||
TextureWrapMode::ClampToBorder => WrapMode::ClampToBorder,
|
||||
TextureWrapMode::MirroredRepeat => WrapMode::MirroredRepeat,
|
||||
TextureWrapMode::MirrorClampToEdge => WrapMode::MirrorClampToEdge,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Extension trait for [`GeometryBuffer`].
|
||||
pub trait GeometryBufferExt {
|
||||
/// Creates [`GeometryBuffer`] from [`SurfaceData`].
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "fyrox-texture"
|
||||
version = "0.36.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
fyrox-core = { path = "../fyrox-core", version = "0.36.0" }
|
||||
fyrox-resource = { path = "../fyrox-resource", version = "0.36.0" }
|
||||
ddsfile = "0.5.0"
|
||||
fast_image_resize = "4.0.0"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
lazy_static = "1.4.0"
|
||||
fxhash = "0.2.1"
|
||||
strum = "0.26.1"
|
||||
strum_macros = "0.26.1"
|
||||
tbc = "0.3.0"
|
||||
image = { version = "0.25.1", default-features = false, features = ["gif", "jpeg", "png", "tga", "tiff", "bmp"] }
|
||||
|
Before Width: | Height: | Size: 310 B After Width: | Height: | Size: 310 B |
File diff suppressed because it is too large
Load Diff
@@ -20,17 +20,12 @@
|
||||
|
||||
//! Texture loader.
|
||||
|
||||
use crate::{
|
||||
asset::{
|
||||
io::ResourceIo,
|
||||
loader::{
|
||||
BoxedImportOptionsLoaderFuture, BoxedLoaderFuture, LoaderPayload, ResourceLoader,
|
||||
},
|
||||
options::{try_get_import_settings, try_get_import_settings_opaque, BaseImportOptions},
|
||||
state::LoadError,
|
||||
},
|
||||
core::{uuid::Uuid, TypeUuidProvider},
|
||||
resource::texture::{Texture, TextureImportOptions},
|
||||
use crate::{Texture, TextureImportOptions};
|
||||
use fyrox_core::{uuid::Uuid, TypeUuidProvider};
|
||||
use fyrox_resource::{
|
||||
io::ResourceIo, loader::BoxedImportOptionsLoaderFuture, loader::BoxedLoaderFuture,
|
||||
loader::LoaderPayload, loader::ResourceLoader, options::try_get_import_settings,
|
||||
options::try_get_import_settings_opaque, options::BaseImportOptions, state::LoadError,
|
||||
};
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
|
||||
Reference in New Issue
Block a user