FCT
载入中...
搜索中...
未找到
Format.h
浏览该文件的文档.
1#ifndef FCT_FORMAT_H
2#define FCT_FORMAT_H
3#include "../ThirdParty.h"
4namespace FCT {
59 constexpr const char* FormatToShaderType(Format format) noexcept
60 {
61 switch (format) {
65 return "float";
66
70 return "float2";
71
74 return "float3";
75
82 return "float4";
83
84 // 整数类型
85 case Format::R8_SINT:
88 return "int";
89
93 return "int2";
94
98 return "int3";
99
103 return "int4";
104
105 // 无符号整数类型
106 case Format::R8_UINT:
107 case Format::R16_UINT:
108 case Format::R32_UINT:
109 return "uint";
110
114 return "uint2";
115
119 return "uint3";
120
124 return "uint4";
125
128 return "float";
129
132 return "float";
133
135 default:
136 return "float4";
137 }
138 }
139 constexpr size_t FormatSize(Format format) noexcept {
140 switch (format) {
141
142 case Format::R8_UNORM:
143 case Format::R8_SINT:
144 case Format::R8_UINT:
145 return 1;
146
150 return 2;
151
155 return 3;
156
163 return 4;
164
166 case Format::R16_SINT:
167 case Format::R16_UINT:
168 return 2;
169
173 return 4;
174
177 return 6;
178
182 return 8;
183
185 case Format::R32_SINT:
186 case Format::R32_UINT:
187 return 4;
188
192 return 8;
193
197 return 12;
198
202 return 16;
203
205 return 2;
207 return 4;
209 return 4;
211 return 5;
212
214 default:
215 return 0;
216 }
217 }
228#ifdef FCT_USE_VULKAN
229 inline vk::SampleCountFlagBits ToVkSampleCount(Samples samples) {
230 switch (samples) {
232 return vk::SampleCountFlagBits::e1;
234 return vk::SampleCountFlagBits::e2;
236 return vk::SampleCountFlagBits::e4;
238 return vk::SampleCountFlagBits::e8;
240 return vk::SampleCountFlagBits::e16;
242 return vk::SampleCountFlagBits::e32;
243 default:
244 return vk::SampleCountFlagBits::e1;
245 }
246 }
247
248 inline Samples FromVkSampleCount(vk::SampleCountFlagBits sampleCount) {
249 switch (sampleCount) {
250 case vk::SampleCountFlagBits::e1:
251 return Samples::sample_1;
252 case vk::SampleCountFlagBits::e2:
253 return Samples::sample_2;
254 case vk::SampleCountFlagBits::e4:
255 return Samples::sample_4;
256 case vk::SampleCountFlagBits::e8:
257 return Samples::sample_8;
258 case vk::SampleCountFlagBits::e16:
259 return Samples::sample_16;
260 case vk::SampleCountFlagBits::e32:
261 return Samples::sample_32;
262 default:
263 return Samples::sample_1;
264 }
265 }
266#endif
267#ifdef FCT_USE_VULKAN
268 inline vk::Format ToVkFormat(Format format) {
269 switch (format) {
271 return vk::Format::eUndefined;
272 case Format::R8_UNORM:
273 return vk::Format::eR8Unorm;
275 return vk::Format::eR8G8Unorm;
277 return vk::Format::eR8G8B8Unorm;
279 return vk::Format::eR8G8B8A8Unorm;
281 return vk::Format::eB8G8R8A8Unorm;
283 return vk::Format::eR8G8B8A8Srgb;
285 return vk::Format::eB8G8R8A8Srgb;
287 return vk::Format::eR16Sfloat;
289 return vk::Format::eR16G16Sfloat;
291 return vk::Format::eR16G16B16A16Sfloat;
293 return vk::Format::eR32Sfloat;
295 return vk::Format::eR32G32Sfloat;
297 return vk::Format::eR32G32B32Sfloat;
299 return vk::Format::eR32G32B32A32Sfloat;
300
301 // 有符号整数格式
302 case Format::R8_SINT:
303 return vk::Format::eR8Sint;
305 return vk::Format::eR8G8Sint;
307 return vk::Format::eR8G8B8Sint;
309 return vk::Format::eR8G8B8A8Sint;
310 case Format::R16_SINT:
311 return vk::Format::eR16Sint;
313 return vk::Format::eR16G16Sint;
315 return vk::Format::eR16G16B16Sint;
317 return vk::Format::eR16G16B16A16Sint;
318 case Format::R32_SINT:
319 return vk::Format::eR32Sint;
321 return vk::Format::eR32G32Sint;
323 return vk::Format::eR32G32B32Sint;
325 return vk::Format::eR32G32B32A32Sint;
326
327 // 无符号整数格式
328 case Format::R8_UINT:
329 return vk::Format::eR8Uint;
331 return vk::Format::eR8G8Uint;
333 return vk::Format::eR8G8B8Uint;
335 return vk::Format::eR8G8B8A8Uint;
336 case Format::R16_UINT:
337 return vk::Format::eR16Uint;
339 return vk::Format::eR16G16Uint;
341 return vk::Format::eR16G16B16Uint;
343 return vk::Format::eR16G16B16A16Uint;
344 case Format::R32_UINT:
345 return vk::Format::eR32Uint;
347 return vk::Format::eR32G32Uint;
349 return vk::Format::eR32G32B32Uint;
351 return vk::Format::eR32G32B32A32Uint;
352
354 return vk::Format::eD16Unorm;
356 return vk::Format::eD24UnormS8Uint;
358 return vk::Format::eD32Sfloat;
360 return vk::Format::eD32SfloatS8Uint;
361 default:
362 return vk::Format::eUndefined;
363 }
364 }
365 inline Format FromVkFormat(vk::Format format) {
366 switch (format) {
367 case vk::Format::eUndefined:
368 return Format::UNDEFINED;
369 case vk::Format::eR8Unorm:
370 return Format::R8_UNORM;
371 case vk::Format::eR8G8Unorm:
372 return Format::R8G8_UNORM;
373 case vk::Format::eR8G8B8Unorm:
375 case vk::Format::eR8G8B8A8Unorm:
377 case vk::Format::eB8G8R8A8Unorm:
379 case vk::Format::eR8G8B8A8Srgb:
381 case vk::Format::eB8G8R8A8Srgb:
383 case vk::Format::eR16Sfloat:
384 return Format::R16_SFLOAT;
385 case vk::Format::eR16G16Sfloat:
387 case vk::Format::eR16G16B16A16Sfloat:
389 case vk::Format::eR32Sfloat:
390 return Format::R32_SFLOAT;
391 case vk::Format::eR32G32Sfloat:
393 case vk::Format::eR32G32B32Sfloat:
395 case vk::Format::eR32G32B32A32Sfloat:
397
398 // 有符号整数格式
399 case vk::Format::eR8Sint:
400 return Format::R8_SINT;
401 case vk::Format::eR8G8Sint:
402 return Format::R8G8_SINT;
403 case vk::Format::eR8G8B8Sint:
404 return Format::R8G8B8_SINT;
405 case vk::Format::eR8G8B8A8Sint:
407 case vk::Format::eR16Sint:
408 return Format::R16_SINT;
409 case vk::Format::eR16G16Sint:
410 return Format::R16G16_SINT;
411 case vk::Format::eR16G16B16Sint:
413 case vk::Format::eR16G16B16A16Sint:
415 case vk::Format::eR32Sint:
416 return Format::R32_SINT;
417 case vk::Format::eR32G32Sint:
418 return Format::R32G32_SINT;
419 case vk::Format::eR32G32B32Sint:
421 case vk::Format::eR32G32B32A32Sint:
423
424 // 无符号整数格式
425 case vk::Format::eR8Uint:
426 return Format::R8_UINT;
427 case vk::Format::eR8G8Uint:
428 return Format::R8G8_UINT;
429 case vk::Format::eR8G8B8Uint:
430 return Format::R8G8B8_UINT;
431 case vk::Format::eR8G8B8A8Uint:
433 case vk::Format::eR16Uint:
434 return Format::R16_UINT;
435 case vk::Format::eR16G16Uint:
436 return Format::R16G16_UINT;
437 case vk::Format::eR16G16B16Uint:
439 case vk::Format::eR16G16B16A16Uint:
441 case vk::Format::eR32Uint:
442 return Format::R32_UINT;
443 case vk::Format::eR32G32Uint:
444 return Format::R32G32_UINT;
445 case vk::Format::eR32G32B32Uint:
447 case vk::Format::eR32G32B32A32Uint:
449
450 case vk::Format::eD16Unorm:
451 return Format::D16_UNORM;
452 case vk::Format::eD24UnormS8Uint:
454 case vk::Format::eD32Sfloat:
455 return Format::D32_SFLOAT;
456 case vk::Format::eD32SfloatS8Uint:
458 default:
459 return Format::UNDEFINED;
460 }
461 }
462#endif
463}
464
465
466#endif //FCT_FORMAT_H
vk::SampleCountFlagBits ToVkSampleCount(Samples samples)
constexpr const char * FormatToShaderType(Format format) noexcept
Format FromVkFormat(vk::Format format)
vk::Format ToVkFormat(Format format)
constexpr size_t FormatSize(Format format) noexcept
Samples FromVkSampleCount(vk::SampleCountFlagBits sampleCount)