globals.h
cross platform rendering playgroundsrc/core/globals.h
7.48 KB#pragma once
#include <cstddef>
#include <cstdint>
typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef float f32;
typedef double f64;
typedef size_t usize;
#define static_global static
#define static_local static
#define static_internal static
// RHI STUFF, TODO: move
constexpr u32 REMAINING_MIPS = 0xFFFFFFFF;
constexpr u32 REMAINING_LAYERS = 0xFFFFFFFF;
constexpr u64 WHOLE_SIZE = ~0ull;
#define BIT(x) (1u << (x))
#define ENUM_BIT_OPS(EnumType) \
constexpr inline EnumType operator|(EnumType a, EnumType b) noexcept { \
return (EnumType)((u32)a | (u32)b); \
} \
\
constexpr inline EnumType operator&(EnumType a, EnumType b) noexcept { \
return (EnumType)((u32)a & (u32)b); \
} \
\
constexpr inline EnumType operator~(EnumType a) noexcept { \
return (EnumType)(~(u32)a); \
} \
\
constexpr inline EnumType &operator|=(EnumType &a, EnumType b) noexcept { \
a = a | b; \
return a; \
} \
\
constexpr inline EnumType &operator&=(EnumType &a, EnumType b) noexcept { \
a = a & b; \
return a; \
} \
\
constexpr inline bool Any(EnumType value, EnumType flags) noexcept { \
return ((u32)value & (u32)flags) != 0; \
} \
\
constexpr inline EnumType EnumNot(EnumType a) noexcept { \
return (EnumType)(~(u32)a); \
}
// 64‑bit version of ENUM_BIT_OPS for enums whose values exceed 32 bits.
#define ENUM_BIT_OPS_64(EnumType) \
constexpr inline EnumType operator|(EnumType a, EnumType b) noexcept { \
return (EnumType)((u64)a | (u64)b); \
} \
\
constexpr inline EnumType operator&(EnumType a, EnumType b) noexcept { \
return (EnumType)((u64)a & (u64)b); \
} \
\
constexpr inline EnumType operator~(EnumType a) noexcept { \
return (EnumType)(~(u64)a); \
} \
\
constexpr inline EnumType &operator|=(EnumType &a, EnumType b) noexcept { \
a = a | b; \
return a; \
} \
\
constexpr inline EnumType &operator&=(EnumType &a, EnumType b) noexcept { \
a = a & b; \
return a; \
} \
\
constexpr inline bool Any(EnumType value, EnumType flags) noexcept { \
return ((u64)value & (u64)flags) != 0; \
} \
\
constexpr inline EnumType EnumNot(EnumType a) noexcept { \
return (EnumType)(~(u64)a); \
}