Adam Sawicki | f1a793c | 2018-03-13 15:42:22 +0100 | [diff] [blame] | 1 | #ifndef COMMON_H_
|
| 2 | #define COMMON_H_
|
| 3 |
|
Adam Sawicki | b8333fb | 2018-03-13 16:15:53 +0100 | [diff] [blame^] | 4 | #include "VmaUsage.h"
|
| 5 |
|
Adam Sawicki | f1a793c | 2018-03-13 15:42:22 +0100 | [diff] [blame] | 6 | #ifdef _WIN32
|
| 7 |
|
| 8 | #define MATHFU_COMPILE_WITHOUT_SIMD_SUPPORT
|
| 9 | #include <mathfu/glsl_mappings.h>
|
| 10 | #include <mathfu/constants.h>
|
| 11 |
|
Adam Sawicki | b8333fb | 2018-03-13 16:15:53 +0100 | [diff] [blame^] | 12 | #include <iostream>
|
Adam Sawicki | f1a793c | 2018-03-13 15:42:22 +0100 | [diff] [blame] | 13 | #include <fstream>
|
| 14 | #include <vector>
|
Adam Sawicki | f1a793c | 2018-03-13 15:42:22 +0100 | [diff] [blame] | 15 | #include <memory>
|
| 16 | #include <algorithm>
|
| 17 | #include <numeric>
|
| 18 | #include <array>
|
| 19 | #include <type_traits>
|
| 20 | #include <utility>
|
Adam Sawicki | b8333fb | 2018-03-13 16:15:53 +0100 | [diff] [blame^] | 21 | #include <chrono>
|
| 22 | #include <string>
|
Adam Sawicki | f1a793c | 2018-03-13 15:42:22 +0100 | [diff] [blame] | 23 |
|
Adam Sawicki | f1a793c | 2018-03-13 15:42:22 +0100 | [diff] [blame] | 24 | #include <cassert>
|
| 25 | #include <cstdlib>
|
| 26 | #include <cstdio>
|
Adam Sawicki | b8333fb | 2018-03-13 16:15:53 +0100 | [diff] [blame^] | 27 | #include <cstdarg>
|
| 28 |
|
| 29 | typedef std::chrono::high_resolution_clock::time_point time_point;
|
| 30 | typedef std::chrono::high_resolution_clock::duration duration;
|
Adam Sawicki | f1a793c | 2018-03-13 15:42:22 +0100 | [diff] [blame] | 31 |
|
| 32 | #define ERR_GUARD_VULKAN(Expr) do { VkResult res__ = (Expr); if (res__ < 0) assert(0); } while(0)
|
| 33 |
|
Adam Sawicki | b8333fb | 2018-03-13 16:15:53 +0100 | [diff] [blame^] | 34 | extern VkPhysicalDevice g_hPhysicalDevice;
|
| 35 | extern VkDevice g_hDevice;
|
| 36 | extern VmaAllocator g_hAllocator;
|
| 37 | extern bool g_MemoryAliasingWarningEnabled;
|
| 38 |
|
| 39 | inline float ToFloatSeconds(duration d)
|
| 40 | {
|
| 41 | return std::chrono::duration_cast<std::chrono::duration<float>>(d).count();
|
| 42 | }
|
| 43 |
|
| 44 | template <typename T>
|
| 45 | inline T ceil_div(T x, T y)
|
| 46 | {
|
| 47 | return (x+y-1) / y;
|
| 48 | }
|
| 49 |
|
| 50 | template <typename T>
|
| 51 | static inline T align_up(T val, T align)
|
| 52 | {
|
| 53 | return (val + align - 1) / align * align;
|
| 54 | }
|
| 55 |
|
| 56 | class RandomNumberGenerator
|
| 57 | {
|
| 58 | public:
|
| 59 | RandomNumberGenerator() : m_Value{GetTickCount()} {}
|
| 60 | RandomNumberGenerator(uint32_t seed) : m_Value{seed} { }
|
| 61 | void Seed(uint32_t seed) { m_Value = seed; }
|
| 62 | uint32_t Generate() { return GenerateFast() ^ (GenerateFast() >> 7); }
|
| 63 |
|
| 64 | private:
|
| 65 | uint32_t m_Value;
|
| 66 | uint32_t GenerateFast() { return m_Value = (m_Value * 196314165 + 907633515); }
|
| 67 | };
|
| 68 |
|
| 69 | void ReadFile(std::vector<char>& out, const char* fileName);
|
| 70 |
|
| 71 | enum class CONSOLE_COLOR
|
| 72 | {
|
| 73 | INFO,
|
| 74 | NORMAL,
|
| 75 | WARNING,
|
| 76 | ERROR_,
|
| 77 | COUNT
|
| 78 | };
|
| 79 |
|
| 80 | void SetConsoleColor(CONSOLE_COLOR color);
|
| 81 |
|
| 82 | void PrintMessage(CONSOLE_COLOR color, const char* msg);
|
| 83 | void PrintMessage(CONSOLE_COLOR color, const wchar_t* msg);
|
| 84 |
|
| 85 | inline void Print(const char* msg) { PrintMessage(CONSOLE_COLOR::NORMAL, msg); }
|
| 86 | inline void Print(const wchar_t* msg) { PrintMessage(CONSOLE_COLOR::NORMAL, msg); }
|
| 87 | inline void PrintWarning(const char* msg) { PrintMessage(CONSOLE_COLOR::WARNING, msg); }
|
| 88 | inline void PrintWarning(const wchar_t* msg) { PrintMessage(CONSOLE_COLOR::WARNING, msg); }
|
| 89 | inline void PrintError(const char* msg) { PrintMessage(CONSOLE_COLOR::ERROR_, msg); }
|
| 90 | inline void PrintError(const wchar_t* msg) { PrintMessage(CONSOLE_COLOR::ERROR_, msg); }
|
| 91 |
|
| 92 | void PrintMessageV(CONSOLE_COLOR color, const char* format, va_list argList);
|
| 93 | void PrintMessageV(CONSOLE_COLOR color, const wchar_t* format, va_list argList);
|
| 94 | void PrintMessageF(CONSOLE_COLOR color, const char* format, ...);
|
| 95 | void PrintMessageF(CONSOLE_COLOR color, const wchar_t* format, ...);
|
| 96 | void PrintWarningF(const char* format, ...);
|
| 97 | void PrintWarningF(const wchar_t* format, ...);
|
| 98 | void PrintErrorF(const char* format, ...);
|
| 99 | void PrintErrorF(const wchar_t* format, ...);
|
| 100 |
|
| 101 | void SaveFile(const wchar_t* filePath, const void* data, size_t dataSize);
|
| 102 |
|
Adam Sawicki | f1a793c | 2018-03-13 15:42:22 +0100 | [diff] [blame] | 103 | #endif // #ifdef _WIN32
|
| 104 |
|
| 105 | #endif
|