gx2/gx2r: improve compatibility of enum bitmask types with C++

This commit is contained in:
fincs 2021-02-11 20:17:33 +01:00
parent e4ea8bf0e4
commit a607078c5d
No known key found for this signature in database
GPG Key ID: 62C7609ADA219C60
3 changed files with 22 additions and 0 deletions

View File

@ -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,

View File

@ -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
}

View File

@ -1,5 +1,8 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdalign.h>
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<uint32_t>(lhs) | static_cast<uint32_t>(rhs)); \
} }
#else
#define WUT_ENUM_BITMASK_TYPE(_type)
#endif