diff --git a/src/core/texture.rs b/src/core/texture.rs index 2f0c8379..ef3a2440 100644 --- a/src/core/texture.rs +++ b/src/core/texture.rs @@ -349,12 +349,19 @@ fn set_parameters( } } -fn calculate_number_of_mip_maps( +fn calculate_number_of_mip_maps( mip_map_filter: Option, width: u32, height: u32, depth: Option, ) -> u32 { + // Cannot generate mip maps for RGB16F or RGB32F textures on web (https://registry.khronos.org/webgl/extensions/EXT_color_buffer_float/) + if (T::data_type() == crate::context::FLOAT || T::data_type() == crate::context::HALF_FLOAT) + && T::size() == 3 + { + return 1; + } + if mip_map_filter.is_some() { let max_size = width.max(height).max(depth.unwrap_or(0)); let power_of_two = max_size.next_power_of_two(); diff --git a/src/core/texture/texture2d.rs b/src/core/texture/texture2d.rs index 85e3212d..727870c5 100644 --- a/src/core/texture/texture2d.rs +++ b/src/core/texture/texture2d.rs @@ -16,6 +16,8 @@ impl Texture2D { /// /// Construcs a new texture with the given data. /// + /// **Note:** Mip maps will not be generated for RGB16F and RGB32F format, even if `mip_map_filter` is specified. + /// pub fn new(context: &Context, cpu_texture: &CpuTexture) -> Self { match cpu_texture.data { TextureData::RU8(ref data) => Self::new_with_data(context, cpu_texture, data), @@ -57,6 +59,8 @@ impl Texture2D { /// The format is determined by the generic [TextureDataType] parameter /// (for example, if [u8; 4] is specified, the format is RGBA and the data type is byte). /// + /// **Note:** Mip maps will not be generated for RGB16F and RGB32F format, even if `mip_map_filter` is specified. + /// pub fn new_empty( context: &Context, width: u32, @@ -68,7 +72,8 @@ impl Texture2D { wrap_t: Wrapping, ) -> Self { let id = generate(context); - let number_of_mip_maps = calculate_number_of_mip_maps(mip_map_filter, width, height, None); + let number_of_mip_maps = + calculate_number_of_mip_maps::(mip_map_filter, width, height, None); let texture = Self { context: context.clone(), id, diff --git a/src/core/texture/texture2d_array.rs b/src/core/texture/texture2d_array.rs index 860d8dd2..09aba98b 100644 --- a/src/core/texture/texture2d_array.rs +++ b/src/core/texture/texture2d_array.rs @@ -21,6 +21,8 @@ impl Texture2DArray { /// Creates a new texture array from the given [CpuTexture]s. /// All of the cpu textures must contain data with the same [TextureDataType] and the same width and height. /// + /// **Note:** Mip maps will not be generated for RGB16F and RGB32F format, even if `mip_map_filter` is specified. + /// pub fn new(context: &Context, cpu_textures: &[&CpuTexture]) -> Self { let cpu_texture = cpu_textures .get(0) @@ -145,6 +147,8 @@ impl Texture2DArray { /// /// Creates a new array of 2D textures. /// + /// **Note:** Mip maps will not be generated for RGB16F and RGB32F format, even if `mip_map_filter` is specified. + /// pub fn new_empty( context: &Context, width: u32, @@ -157,7 +161,8 @@ impl Texture2DArray { wrap_t: Wrapping, ) -> Self { let id = generate(context); - let number_of_mip_maps = calculate_number_of_mip_maps(mip_map_filter, width, height, None); + let number_of_mip_maps = + calculate_number_of_mip_maps::(mip_map_filter, width, height, None); let texture = Self { context: context.clone(), id, diff --git a/src/core/texture/texture3d.rs b/src/core/texture/texture3d.rs index 0d8678b6..b10ea438 100644 --- a/src/core/texture/texture3d.rs +++ b/src/core/texture/texture3d.rs @@ -16,6 +16,8 @@ impl Texture3D { /// /// Construcs a new 3D texture with the given data. /// + /// **Note:** Mip maps will not be generated for RGB16F and RGB32F format, even if `mip_map_filter` is specified. + /// pub fn new(context: &Context, cpu_texture: &CpuTexture3D) -> Self { match cpu_texture.data { TextureData::RU8(ref data) => Self::new_with_data(context, cpu_texture, data), @@ -57,6 +59,8 @@ impl Texture3D { /// /// Creates a new empty 3D color texture. /// + /// **Note:** Mip maps will not be generated for RGB16F and RGB32F format, even if `mip_map_filter` is specified. + /// pub fn new_empty( context: &Context, width: u32, @@ -71,7 +75,7 @@ impl Texture3D { ) -> Self { let id = generate(context); let number_of_mip_maps = - calculate_number_of_mip_maps(mip_map_filter, width, height, Some(depth)); + calculate_number_of_mip_maps::(mip_map_filter, width, height, Some(depth)); let texture = Self { context: context.clone(), id, diff --git a/src/core/texture/texture_cube_map.rs b/src/core/texture/texture_cube_map.rs index 38ab97b1..859fc2e9 100644 --- a/src/core/texture/texture_cube_map.rs +++ b/src/core/texture/texture_cube_map.rs @@ -118,6 +118,8 @@ impl TextureCubeMap { /// Creates a new cube map texture from the given [CpuTexture]s. /// All of the cpu textures must contain data with the same [TextureDataType]. /// + /// **Note:** Mip maps will not be generated for RGB16F and RGB32F format, even if `mip_map_filter` is specified. + /// pub fn new( context: &Context, right: &CpuTexture, @@ -299,6 +301,8 @@ impl TextureCubeMap { /// /// Creates a new texture cube map. /// + /// **Note:** Mip maps will not be generated for RGB16F and RGB32F format, even if `mip_map_filter` is specified. + /// pub fn new_empty( context: &Context, width: u32, @@ -311,7 +315,8 @@ impl TextureCubeMap { wrap_r: Wrapping, ) -> Self { let id = generate(context); - let number_of_mip_maps = calculate_number_of_mip_maps(mip_map_filter, width, height, None); + let number_of_mip_maps = + calculate_number_of_mip_maps::(mip_map_filter, width, height, None); let texture = Self { context: context.clone(), id,