Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
TextureType.h
Go to the documentation of this file.
1#pragma once
2#include <vulkan/vulkan_core.h>
3#include <cstdint>
4
5namespace Engine::Assets {
6
23
37constexpr VkFormat getVkFormat(TextureType type, int bits, int components) {
38 // For 8-bit textures, type determines SRGB vs UNORM
39 if (bits == 8) {
40 switch (components) {
41 case 1:
42 // Single channel
43 switch (type) {
47 return VK_FORMAT_R8_SRGB;
51 return VK_FORMAT_R8_UNORM;
52 }
53 break;
54 case 2:
55 // Two channels
56 switch (type) {
60 return VK_FORMAT_R8G8_SRGB;
64 return VK_FORMAT_R8G8_UNORM;
65 }
66 break;
67 case 3:
68 // Three channels (RGB)
69 switch (type) {
73 return VK_FORMAT_R8G8B8_SRGB;
77 return VK_FORMAT_R8G8B8_UNORM;
78 }
79 break;
80 case 4:
81 default:
82 // Four channels (RGBA) - most common case
83 switch (type) {
87 return VK_FORMAT_R8G8B8A8_SRGB;
91 return VK_FORMAT_R8G8B8A8_UNORM;
92 }
93 break;
94 }
95 }
96
97 // For 16-bit textures, always use SFLOAT (linear HDR data)
98 if (bits == 16) {
99 switch (components) {
100 case 1: return VK_FORMAT_R16_SFLOAT;
101 case 2: return VK_FORMAT_R16G16_SFLOAT;
102 case 3: return VK_FORMAT_R16G16B16_SFLOAT;
103 case 4:
104 default: return VK_FORMAT_R16G16B16A16_SFLOAT;
105 }
106 }
107
108 // For 32-bit textures, always use SFLOAT (linear HDR data)
109 if (bits == 32) {
110 switch (components) {
111 case 1: return VK_FORMAT_R32_SFLOAT;
112 case 2: return VK_FORMAT_R32G32_SFLOAT;
113 case 3: return VK_FORMAT_R32G32B32_SFLOAT;
114 case 4:
115 default: return VK_FORMAT_R32G32B32A32_SFLOAT;
116 }
117 }
118
119 // Fallback for unknown bit depths
120 return VK_FORMAT_R8G8B8A8_SRGB;
121}
122
129constexpr bool requiresLinearFormat(TextureType type) {
130 switch (type) {
134 return true;
138 default:
139 return false;
140 }
141}
142
143} // namespace EngineCore
constexpr VkFormat getVkFormat(TextureType type, int bits, int components)
Get the correct VkFormat based on texture type and image properties.
Definition TextureType.h:37
TextureType
Represents the semantic type of a texture, determining its Vulkan format.
Definition TextureType.h:15
@ Lightmap
HDR baked lighting data (SFLOAT format)
Definition TextureType.h:20
@ Emissive
Color data with gamma (SRGB format for 8-bit)
Definition TextureType.h:19
@ BaseColor
Color data with gamma (SRGB format for 8-bit)
Definition TextureType.h:16
@ Unknown
Fallback type, uses SRGB as default.
Definition TextureType.h:21
@ Normal
Linear data for normal maps (UNORM format for 8-bit)
Definition TextureType.h:17
@ MetallicRoughness
Linear data for PBR parameters (UNORM format for 8-bit)
Definition TextureType.h:18
constexpr bool requiresLinearFormat(TextureType type)
Check if a texture type requires linear (non-SRGB) format.