fixed cube texture to use only one size parameter instead width+height

- width+height makes no sense for cube textures anyway because width must be equal to height, otherwise it is not a cube and pretty much any gapi will reject such textures
This commit is contained in:
Dmitry Stepanov
2025-05-31 22:00:26 +03:00
parent 93489c0e84
commit 4877afb072
6 changed files with 34 additions and 51 deletions
+10 -16
View File
@@ -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,
+2 -4
View File
@@ -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 {
+2 -3
View File
@@ -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,
+1 -4
View File
@@ -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()
})?;
+6 -3
View File
@@ -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,
+13 -21
View File
@@ -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<Vector2<u32>> {
if let Self::Cube { width, height } = self {
Some(Vector2::new(*width, *height))
pub fn cube_size(&self) -> Option<u32> {
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 {