From a607078c5dfdc3e5fab2c9baee3a21849cf111e1 Mon Sep 17 00:00:00 2001 From: fincs Date: Thu, 11 Feb 2021 20:17:33 +0100 Subject: [PATCH] gx2/gx2r: improve compatibility of enum bitmask types with C++ --- include/gx2/enum.h | 6 ++++++ include/gx2r/resource.h | 4 ++++ include/wut_types.h | 12 ++++++++++++ 3 files changed, 22 insertions(+) diff --git a/include/gx2/enum.h b/include/gx2/enum.h index 65bf2aa..60de2c7 100644 --- a/include/gx2/enum.h +++ b/include/gx2/enum.h @@ -195,6 +195,7 @@ typedef enum GX2IndexType typedef enum GX2InvalidateMode { + GX2_INVALIDATE_MODE_NONE = 0, GX2_INVALIDATE_MODE_ATTRIBUTE_BUFFER = 1 << 0, GX2_INVALIDATE_MODE_TEXTURE = 1 << 1, GX2_INVALIDATE_MODE_UNIFORM_BLOCK = 1 << 2, @@ -209,6 +210,8 @@ typedef enum GX2InvalidateMode GX2_INVALIDATE_MODE_CPU_SHADER = GX2_INVALIDATE_MODE_CPU | GX2_INVALIDATE_MODE_SHADER, } GX2InvalidateMode; +WUT_ENUM_BITMASK_TYPE(GX2InvalidateMode) + typedef enum GX2InitAttributes { GX2_INIT_END = 0, @@ -450,6 +453,7 @@ typedef enum GX2SurfaceFormat typedef enum GX2SurfaceUse { + GX2_SURFACE_USE_NONE = 0, GX2_SURFACE_USE_TEXTURE = 1 << 0, GX2_SURFACE_USE_COLOR_BUFFER = 1 << 1, GX2_SURFACE_USE_DEPTH_BUFFER = 1 << 2, @@ -458,6 +462,8 @@ typedef enum GX2SurfaceUse GX2_SURFACE_USE_TEXTURE_COLOR_BUFFER_TV = (GX2_SURFACE_USE_TEXTURE | GX2_SURFACE_USE_COLOR_BUFFER | GX2_SURFACE_USE_TV) } GX2SurfaceUse; +WUT_ENUM_BITMASK_TYPE(GX2SurfaceUse) + typedef enum GX2TessellationMode { GX2_TESSELLATION_MODE_DISCRETE = 0, diff --git a/include/gx2r/resource.h b/include/gx2r/resource.h index 543f967..83855a9 100644 --- a/include/gx2r/resource.h +++ b/include/gx2r/resource.h @@ -13,6 +13,9 @@ extern "C" { typedef enum GX2RResourceFlags { + //! No resource flags specified + GX2R_RESOURCE_BIND_NONE = 0, + //! This resource is to be used as a texture GX2R_RESOURCE_BIND_TEXTURE = 1 << 0, @@ -86,6 +89,7 @@ typedef enum GX2RResourceFlags GX2R_RESOURCE_LOCKED = 1 << 30, } GX2RResourceFlags; +WUT_ENUM_BITMASK_TYPE(GX2RResourceFlags) #ifdef __cplusplus } diff --git a/include/wut_types.h b/include/wut_types.h index 667ef8f..878a2b5 100644 --- a/include/wut_types.h +++ b/include/wut_types.h @@ -1,5 +1,8 @@ #pragma once #include +#include +#include +#include typedef int32_t BOOL; @@ -10,3 +13,12 @@ typedef int32_t BOOL; #ifndef FALSE #define FALSE 0 #endif + +#if __cplusplus >= 201402L +#define WUT_ENUM_BITMASK_TYPE(_type) \ + extern "C++" { static constexpr inline _type operator|(_type lhs, _type rhs) { \ + return static_cast<_type>(static_cast(lhs) | static_cast(rhs)); \ + } } +#else +#define WUT_ENUM_BITMASK_TYPE(_type) +#endif