Skip to content

Instantly share code, notes, and snippets.

@nyorain
Last active March 6, 2021 03:55
Show Gist options
  • Save nyorain/56000a995c7147509c1a9d6f1aecaf68 to your computer and use it in GitHub Desktop.
Save nyorain/56000a995c7147509c1a9d6f1aecaf68 to your computer and use it in GitHub Desktop.
Vulkan GL format map
constexpr struct FormatEntry {
GLInternalFormat glFormat;
u32 glPixelFormat;
u32 glPixelType;
vk::Format vkFormat;
} formatMap[] = {
// 8bit
{GL_R8, GL_RED, GL_UNSIGNED_BYTE, vk::Format::r8Unorm},
{GL_RG8, GL_RG, GL_UNSIGNED_BYTE, vk::Format::r8g8Unorm},
{GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, vk::Format::r8g8b8Unorm},
{GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, vk::Format::r8g8b8a8Unorm},
{GL_SR8, GL_RED, GL_UNSIGNED_BYTE, vk::Format::r8Srgb},
{GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE, vk::Format::r8g8b8Srgb},
{GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE, vk::Format::r8g8b8a8Srgb},
{GL_R8_SNORM, GL_RED, GL_BYTE, vk::Format::r8Snorm},
{GL_RG8_SNORM, GL_RED, GL_BYTE, vk::Format::r8g8Snorm},
{GL_RGB8_SNORM, GL_RED, GL_BYTE, vk::Format::r8g8b8Snorm},
{GL_RGBA8_SNORM, GL_RED, GL_BYTE, vk::Format::r8g8b8a8Snorm},
{GL_R8I, GL_RED_INTEGER, GL_BYTE, vk::Format::r8Sint},
{GL_RG8I, GL_RG_INTEGER, GL_BYTE, vk::Format::r8g8Sint},
{GL_RGB8I, GL_RGB_INTEGER, GL_BYTE, vk::Format::r8g8b8Sint},
{GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE, vk::Format::r8g8b8a8Sint},
{GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE, vk::Format::r8Uint},
{GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE, vk::Format::r8g8Uint},
{GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, vk::Format::r8g8b8Uint},
{GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, vk::Format::r8g8b8a8Uint},
// 16it
{GL_R16, GL_RED, GL_UNSIGNED_SHORT, vk::Format::r16Unorm},
{GL_RG16, GL_RG, GL_UNSIGNED_SHORT, vk::Format::r16g16Unorm},
{GL_RGB16, GL_RGB, GL_UNSIGNED_SHORT, vk::Format::r16g16b16Unorm},
{GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT, vk::Format::r16g16b16a16Unorm},
{GL_R16F, GL_RED, GL_HALF_FLOAT, vk::Format::r16Sfloat},
{GL_RG16F, GL_RG, GL_HALF_FLOAT, vk::Format::r16g16Sfloat},
{GL_RGB16F, GL_RGB, GL_HALF_FLOAT, vk::Format::r16g16b16Sfloat},
{GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT, vk::Format::r16g16b16a16Sfloat},
{GL_R16_SNORM, GL_RED, GL_SHORT, vk::Format::r16Snorm},
{GL_RG16_SNORM, GL_RG, GL_SHORT, vk::Format::r16g16Snorm},
{GL_RGB16_SNORM, GL_RGBA, GL_SHORT, vk::Format::r16g16b16Snorm},
{GL_R16I, GL_RED_INTEGER, GL_SHORT, vk::Format::r16Sint},
{GL_RG16I, GL_RG_INTEGER, GL_SHORT, vk::Format::r16g16Sint},
{GL_RGB16I, GL_RGB_INTEGER, GL_SHORT, vk::Format::r16g16b16Sint},
{GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT, vk::Format::r16g16b16a16Sint},
{GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT, vk::Format::r16Uint},
{GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT, vk::Format::r16g16Uint},
{GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, vk::Format::r16g16b16Uint},
{GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, vk::Format::r16g16b16a16Uint},
// 32bit
{GL_R32F, GL_RED, GL_FLOAT, vk::Format::r32Sfloat},
{GL_RG32F, GL_RG, GL_FLOAT, vk::Format::r32g32Sfloat},
{GL_RGBA32F, GL_RGBA, GL_FLOAT, vk::Format::r32g32b32a32Sfloat},
{GL_R32I, GL_RED_INTEGER, GL_INT, vk::Format::r32Sint},
{GL_RG32I, GL_RG_INTEGER, GL_INT, vk::Format::r32g32Sint},
{GL_RGB32I, GL_RGB_INTEGER, GL_INT, vk::Format::r32g32b32Sint},
{GL_RGBA32I, GL_RGBA_INTEGER, GL_INT, vk::Format::r32g32b32a32Sint},
{GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT, vk::Format::r32Uint},
{GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT, vk::Format::r32g32Uint},
{GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT, vk::Format::r32g32b32Uint},
{GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT, vk::Format::r32g32b32a32Uint},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment