Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support some more texture formats #224

Merged
merged 6 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions blade-graphics/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,9 @@ fn describe_texture_format(format: crate::TextureFormat) -> FormatInfo {
Tf::Bgra8Unorm => (glow::RGBA8, glow::BGRA, glow::UNSIGNED_BYTE),
Tf::Bgra8UnormSrgb => (glow::SRGB8_ALPHA8, glow::BGRA, glow::UNSIGNED_BYTE),
Tf::Rgba8Snorm => (glow::RGBA8, glow::RGBA, glow::BYTE),
Tf::R16Float => (glow::R16F, glow::RED, glow::FLOAT),
Tf::Rgba16Float => (glow::RGBA16F, glow::RGBA, glow::FLOAT),
Tf::R16Float => (glow::R16F, glow::RED, glow::HALF_FLOAT),
Tf::Rg16Float => (glow::RG16F, glow::RG, glow::HALF_FLOAT),
Tf::Rgba16Float => (glow::RGBA16F, glow::RGBA, glow::HALF_FLOAT),
Tf::R32Float => (glow::R32F, glow::RED, glow::FLOAT),
Tf::Rg32Float => (glow::RG32F, glow::RG, glow::FLOAT),
Tf::Rgba32Float => (glow::RGBA32F, glow::RGBA, glow::FLOAT),
Expand All @@ -622,6 +623,26 @@ fn describe_texture_format(format: crate::TextureFormat) -> FormatInfo {
Tf::Bc4Snorm => (glow::COMPRESSED_SIGNED_RED_RGTC1, glow::RED, 0),
Tf::Bc5Unorm => (glow::COMPRESSED_RG_RGTC2, glow::RG, 0),
Tf::Bc5Snorm => (glow::COMPRESSED_SIGNED_RG_RGTC2, glow::RG, 0),
Tf::Bc6hUfloat => (glow::COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT, glow::RGB, 0),
Tf::Bc6hFloat => (glow::COMPRESSED_RGB_BPTC_SIGNED_FLOAT, glow::RGB, 0),
Tf::Bc7Unorm => (glow::COMPRESSED_RGBA_BPTC_UNORM, glow::RGBA, 0),
Tf::Bc7UnormSrgb => (glow::COMPRESSED_SRGB_ALPHA_BPTC_UNORM, glow::RGBA, 0),
Tf::Rgb10a2Unorm => (
glow::RGB10_A2,
glow::RGBA,
glow::UNSIGNED_INT_2_10_10_10_REV,
),
Tf::Bgr10a2Unorm => (
glow::RGB10_A2, // TODO: Unsupported?
glow::BGRA,
glow::UNSIGNED_INT_2_10_10_10_REV,
),
Tf::Rg11b10Float => (
glow::R11F_G11F_B10F,
glow::RGB,
glow::UNSIGNED_INT_10F_11F_11F_REV,
),
Tf::Rgb9e5Ufloat => (glow::RGB9_E5, glow::RGB, glow::UNSIGNED_INT_5_9_9_9_REV),
};
FormatInfo {
internal,
Expand Down
10 changes: 10 additions & 0 deletions blade-graphics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ pub enum TextureFormat {
Bgra8UnormSrgb,
Rgba8Snorm,
R16Float,
Rg16Float,
Rgba16Float,
R32Float,
Rg32Float,
Expand All @@ -307,6 +308,15 @@ pub enum TextureFormat {
Bc4Snorm,
Bc5Unorm,
Bc5Snorm,
Bc6hUfloat,
Bc6hFloat,
Bc7Unorm,
Bc7UnormSrgb,
// packed 32-bit
Rgb10a2Unorm,
Bgr10a2Unorm,
EriKWDev marked this conversation as resolved.
Show resolved Hide resolved
Rg11b10Float,
Rgb9e5Ufloat,
}

#[derive(Clone, Copy, Debug)]
Expand Down
9 changes: 9 additions & 0 deletions blade-graphics/src/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ fn map_texture_format(format: crate::TextureFormat) -> metal::MTLPixelFormat {
Tf::Bgra8UnormSrgb => BGRA8Unorm_sRGB,
Tf::Rgba8Snorm => RGBA8Snorm,
Tf::R16Float => R16Float,
Tf::Rg16Float => RG16Float,
Tf::Rgba16Float => RGBA16Float,
Tf::R32Float => R32Float,
Tf::Rg32Float => RG32Float,
Expand All @@ -333,6 +334,14 @@ fn map_texture_format(format: crate::TextureFormat) -> metal::MTLPixelFormat {
Tf::Bc4Snorm => BC4_RSnorm,
Tf::Bc5Unorm => BC5_RGUnorm,
Tf::Bc5Snorm => BC5_RGSnorm,
Tf::Bc6hUfloat => BC6H_RGBUfloat,
Tf::Bc6hFloat => BC6H_RGBFloat,
Tf::Bc7Unorm => BC7_RGBAUnorm,
Tf::Bc7UnormSrgb => BC7_RGBAUnorm_sRGB,
Tf::Rgb10a2Unorm => RGB10A2Unorm,
Tf::Bgr10a2Unorm => BGR10A2Unorm,
Tf::Rg11b10Float => RG11B10Float,
Tf::Rgb9e5Ufloat => RGB9E5Float,
}
}

Expand Down
9 changes: 9 additions & 0 deletions blade-graphics/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl super::TextureFormat {
Self::Bgra8UnormSrgb => uncompressed(4),
Self::Rgba8Snorm => uncompressed(4),
Self::R16Float => uncompressed(2),
Self::Rg16Float => uncompressed(4),
Self::Rgba16Float => uncompressed(8),
Self::R32Float => uncompressed(4),
Self::Rg32Float => uncompressed(8),
Expand All @@ -83,6 +84,14 @@ impl super::TextureFormat {
Self::Bc4Snorm => cx_bc(8),
Self::Bc5Unorm => cx_bc(16),
Self::Bc5Snorm => cx_bc(16),
Self::Bc6hUfloat => cx_bc(16),
Self::Bc6hFloat => cx_bc(16),
Self::Bc7Unorm => cx_bc(16),
Self::Bc7UnormSrgb => cx_bc(16),
Self::Rgb10a2Unorm => uncompressed(4),
Self::Bgr10a2Unorm => uncompressed(4),
Self::Rg11b10Float => uncompressed(4),
Self::Rgb9e5Ufloat => uncompressed(4),
}
}

Expand Down
9 changes: 9 additions & 0 deletions blade-graphics/src/vulkan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ fn map_texture_format(format: crate::TextureFormat) -> vk::Format {
Tf::Bgra8UnormSrgb => vk::Format::B8G8R8A8_SRGB,
Tf::Rgba8Snorm => vk::Format::R8G8B8A8_SNORM,
Tf::R16Float => vk::Format::R16_SFLOAT,
Tf::Rg16Float => vk::Format::R16G16_SFLOAT,
Tf::Rgba16Float => vk::Format::R16G16B16A16_SFLOAT,
Tf::R32Float => vk::Format::R32_SFLOAT,
Tf::Rg32Float => vk::Format::R32G32_SFLOAT,
Expand All @@ -556,6 +557,14 @@ fn map_texture_format(format: crate::TextureFormat) -> vk::Format {
Tf::Bc4Snorm => vk::Format::BC4_SNORM_BLOCK,
Tf::Bc5Unorm => vk::Format::BC5_UNORM_BLOCK,
Tf::Bc5Snorm => vk::Format::BC5_SNORM_BLOCK,
Tf::Bc6hUfloat => vk::Format::BC6H_UFLOAT_BLOCK,
Tf::Bc6hFloat => vk::Format::BC6H_SFLOAT_BLOCK,
Tf::Bc7Unorm => vk::Format::BC7_UNORM_BLOCK,
Tf::Bc7UnormSrgb => vk::Format::BC7_SRGB_BLOCK,
Tf::Rgb10a2Unorm => vk::Format::A2R10G10B10_UNORM_PACK32,
kvark marked this conversation as resolved.
Show resolved Hide resolved
Tf::Bgr10a2Unorm => vk::Format::A2B10G10R10_UNORM_PACK32,
Tf::Rg11b10Float => vk::Format::B10G11R11_UFLOAT_PACK32,
Tf::Rgb9e5Ufloat => vk::Format::E5B9G9R9_UFLOAT_PACK32,
}
}

Expand Down
Loading