diff --git a/fyrox-graphics-gl/src/texture.rs b/fyrox-graphics-gl/src/texture.rs index b37603c17..8fb9fe2bf 100644 --- a/fyrox-graphics-gl/src/texture.rs +++ b/fyrox-graphics-gl/src/texture.rs @@ -338,12 +338,9 @@ impl GpuTextureTrait for GlTexture { break 'mip_loop; } } - GpuTextureKind::Cube { width, height } => { - if let (Some(width), Some(height)) = ( - width.checked_shr(mip as u32), - height.checked_shr(mip as u32), - ) { - desired_byte_count += 6 * image_2d_size_bytes(pixel_kind, width, height); + GpuTextureKind::Cube { size } => { + if let Some(size) = size.checked_shr(mip as u32) { + desired_byte_count += 6 * image_2d_size_bytes(pixel_kind, size, size); } else { break 'mip_loop; } @@ -495,12 +492,9 @@ impl GpuTextureTrait for GlTexture { break 'mip_loop2; } } - GpuTextureKind::Cube { width, height } => { - if let (Some(width), Some(height)) = ( - width.checked_shr(mip as u32), - height.checked_shr(mip as u32), - ) { - let bytes_per_face = image_2d_size_bytes(pixel_kind, width, height); + GpuTextureKind::Cube { size } => { + if let Some(size) = size.checked_shr(mip as u32) { + let bytes_per_face = image_2d_size_bytes(pixel_kind, size, size); for face in 0..6 { let begin = mip_byte_offset + face * bytes_per_face; @@ -512,8 +506,8 @@ impl GpuTextureTrait for GlTexture { glow::TEXTURE_CUBE_MAP_POSITIVE_X + face as u32, mip as i32, internal_format as i32, - width as i32, - height as i32, + size as i32, + size as i32, 0, bytes_per_face as i32, face_pixels.ok_or(FrameworkError::EmptyTextureData)?, @@ -523,8 +517,8 @@ impl GpuTextureTrait for GlTexture { glow::TEXTURE_CUBE_MAP_POSITIVE_X + face as u32, mip as i32, internal_format as i32, - width as i32, - height as i32, + size as i32, + size as i32, 0, format, data_type, diff --git a/fyrox-graphics/src/gpu_texture.rs b/fyrox-graphics/src/gpu_texture.rs index 4bea46416..b88bbcde6 100644 --- a/fyrox-graphics/src/gpu_texture.rs +++ b/fyrox-graphics/src/gpu_texture.rs @@ -43,10 +43,8 @@ pub enum GpuTextureKind { }, /// Six 2D textures forming a cube. Cube { - /// Width of the texture. - width: usize, - /// Height of the texture. - height: usize, + /// Size of the texture. + size: usize, }, /// Volumetric texture that consists of `depth` textures with `width x height` size. Volume { diff --git a/fyrox-impl/src/renderer/cache/texture.rs b/fyrox-impl/src/renderer/cache/texture.rs index bb78c588d..741787d82 100644 --- a/fyrox-impl/src/renderer/cache/texture.rs +++ b/fyrox-impl/src/renderer/cache/texture.rs @@ -57,9 +57,8 @@ fn convert_texture_kind(v: TextureKind) -> GpuTextureKind { width: width as usize, height: height as usize, }, - TextureKind::Cube { width, height } => GpuTextureKind::Cube { - width: width as usize, - height: height as usize, + TextureKind::Cube { size } => GpuTextureKind::Cube { + size: size as usize, }, TextureKind::Volume { width, diff --git a/fyrox-impl/src/renderer/shadow/point.rs b/fyrox-impl/src/renderer/shadow/point.rs index 395143fdf..87b84e19a 100644 --- a/fyrox-impl/src/renderer/shadow/point.rs +++ b/fyrox-impl/src/renderer/shadow/point.rs @@ -95,10 +95,7 @@ impl PointShadowMapRenderer { )?; let cube_map = server.create_texture(GpuTextureDescriptor { - kind: GpuTextureKind::Cube { - width: size, - height: size, - }, + kind: GpuTextureKind::Cube { size }, pixel_kind: PixelKind::R16F, ..Default::default() })?; diff --git a/fyrox-impl/src/scene/camera.rs b/fyrox-impl/src/scene/camera.rs index d0a1edc9a..e6812cf4e 100644 --- a/fyrox-impl/src/scene/camera.rs +++ b/fyrox-impl/src/scene/camera.rs @@ -1507,8 +1507,11 @@ impl SkyBox { }, ); - let (width, height) = match kind { - TextureKind::Rectangle { width, height } => (width, height), + let size = match kind { + TextureKind::Rectangle { width, height } => { + assert_eq!(width, height); + width + } _ => return Err(SkyBoxError::UnsupportedTextureKind(kind)), }; @@ -1524,7 +1527,7 @@ impl SkyBox { let cubemap = TextureResource::from_bytes( Uuid::new_v4(), - TextureKind::Cube { width, height }, + TextureKind::Cube { size }, pixel_kind, data, ResourceKind::Embedded, diff --git a/fyrox-texture/src/lib.rs b/fyrox-texture/src/lib.rs index 043ffd2ee..7ef95c85f 100644 --- a/fyrox-texture/src/lib.rs +++ b/fyrox-texture/src/lib.rs @@ -95,10 +95,8 @@ pub enum TextureKind { }, /// Cube texture. Cube { - /// Width of the cube face. - width: u32, - /// Height of the cube face. - height: u32, + /// Width and height of the cube face. + size: u32, }, /// Volume texture (3D). Volume { @@ -132,11 +130,11 @@ impl TextureKind { } } - /// Tries to fetch [`TextureKind::Cube`]'s width (x) and height (y). + /// Tries to fetch [`TextureKind::Cube`]'s size. #[inline] - pub fn cube_size(&self) -> Option> { - if let Self::Cube { width, height } = self { - Some(Vector2::new(*width, *height)) + pub fn cube_size(&self) -> Option { + if let Self::Cube { size } = self { + Some(*size) } else { None } @@ -185,10 +183,7 @@ impl Visit for TextureKind { width: 0, height: 0, }, - 2 => TextureKind::Cube { - width: 0, - height: 0, - }, + 2 => TextureKind::Cube { size: 0 }, 3 => TextureKind::Volume { width: 0, height: 0, @@ -209,9 +204,9 @@ impl Visit for TextureKind { width.visit("Width", &mut region)?; height.visit("Height", &mut region)?; } - TextureKind::Cube { width, height } => { - width.visit("Width", &mut region)?; - height.visit("Height", &mut region)?; + TextureKind::Cube { size } => { + // Called `Width` for backward compatibility reasons. + size.visit("Width", &mut region)?; } TextureKind::Volume { width, @@ -1321,7 +1316,7 @@ fn bytes_in_mip_level(kind: TextureKind, pixel_kind: TexturePixelKind, mip: usiz let pixel_count = match kind { TextureKind::Line { length } => length.shr(mip), TextureKind::Rectangle { width, height } => width.shr(mip) * height.shr(mip), - TextureKind::Cube { width, height } => 6 * width.shr(mip) * height.shr(mip), + TextureKind::Cube { size } => 6 * size.shr(mip).pow(2), TextureKind::Volume { width, height, @@ -1368,9 +1363,7 @@ fn bytes_in_mip_level(kind: TextureKind, pixel_kind: TexturePixelKind, mip: usiz TextureKind::Rectangle { width, height } => { ceil_div_4(width) * ceil_div_4(height) * block_size } - TextureKind::Cube { width, height } => { - 6 * ceil_div_4(width) * ceil_div_4(height) * block_size - } + TextureKind::Cube { size } => 6 * ceil_div_4(size).pow(2) * block_size, TextureKind::Volume { width, height, @@ -1519,8 +1512,7 @@ impl Texture { bytes: bytes.into(), kind: if dds.header.caps2 & Caps2::CUBEMAP == Caps2::CUBEMAP { TextureKind::Cube { - width: dds.header.width, - height: dds.header.height, + size: dds.header.width, } } else if dds.header.caps2 & Caps2::VOLUME == Caps2::VOLUME { TextureKind::Volume {