[vulkan] Add a function to translate QFFormat to VkFormat

It's not great, but it does produce reasonable results for the formats
supported by QF's image system.
This commit is contained in:
Bill Currie 2022-05-04 13:57:02 +09:00
parent a77aa16318
commit 9d7cad420d
2 changed files with 32 additions and 0 deletions

View file

@ -7,6 +7,7 @@
#include <vulkan/vulkan.h>
#include "QF/darray.h"
#include "QF/image.h"
typedef struct qfv_imageset_s
DARRAY_TYPE (VkImage) qfv_imageset_t;
@ -100,4 +101,14 @@ void QFV_GenerateMipMaps (struct qfv_device_s *device, VkCommandBuffer cmd,
unsigned width, unsigned height, unsigned layers);
int QFV_MipLevels (int width, int height) __attribute__((const));
/** Convert QFFormat to VkFormat
*
* \param format The format to convert.
* \return The corresponding VkFormat.
*
* \note For tex_palette, VK_FORMAT_R8_UINT is returned. If \a format is
* not a valid QFFormat, then VK_FORMAT_R8_SRGB is returned.
*/
VkFormat QFV_ImageFormat (QFFormat format);
#endif//__QF_Vulkan_image_h

View file

@ -266,3 +266,24 @@ QFV_MipLevels (int width, int height)
{
return ilog2 (max (width, height)) + 1;
}
VkFormat
QFV_ImageFormat (QFFormat format)
{
switch (format) {
case tex_palette:
return VK_FORMAT_R8_UINT;
case tex_l:
case tex_a:
return VK_FORMAT_R8_UNORM;
case tex_la:
return VK_FORMAT_R8G8_UNORM;
case tex_rgb:
return VK_FORMAT_R8G8B8_UNORM; // SRGB?
case tex_rgba:
return VK_FORMAT_R8G8B8A8_UNORM;// SRGB?
case tex_frgba:
return VK_FORMAT_R32G32B32A32_SFLOAT;
}
return VK_FORMAT_R8_SRGB;
}