Skip to content

Commit 67d9ec4

Browse files
committed
Add bitops macro
1 parent 1355054 commit 67d9ec4

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

include/nbl/asset/IDescriptorSetLayout.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class NBL_API IDescriptorSetLayout : public virtual core::IReferenceCounted
8686
uint32_t binding;
8787
E_DESCRIPTOR_TYPE type;
8888
uint32_t count;
89-
IShader::E_SHADER_STAGE stageFlags;
89+
IShader::E_SHADER_STAGE stageFlags; // TODO: make it bitflag
9090
// Use this if you want an immutable sampler that is baked into the DS layout itself.
9191
// If its `nullptr` then the sampler used is mutable and can be specified while writing the image descriptor to a binding while updating the DS.
9292
const core::smart_refctd_ptr<sampler_type>* samplers;

include/nbl/asset/IShader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ class NBL_API IShader : public virtual core::IReferenceCounted
7575
std::string m_filepathHint;
7676
};
7777

78+
NBL_ENUM_ADD_BITWISE_OPERATORS(IShader::E_SHADER_STAGE)
79+
7880
}
7981

8082
#endif

include/nbl/macros.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,46 @@
253253

254254
#define NBL_FOREACH(WHAT, ... ) NBL_EVAL(NBL_CONCATENATE(NBL_FOREACH_,NBL_VA_ARGS_COUNT(__VA_ARGS__))(WHAT, __VA_ARGS__))
255255

256+
#define NBL_ENUM_ADD_BITWISE_OPERATORS(EnumType) \
257+
inline constexpr EnumType operator&(const EnumType& lhs, const EnumType& rhs) noexcept \
258+
{ \
259+
using T = typename std::underlying_type_t<EnumType>; \
260+
return static_cast<EnumType>(static_cast<T>(lhs) & static_cast<T>(rhs)); \
261+
} \
262+
\
263+
inline constexpr EnumType& operator&=(EnumType& lhs, const EnumType& rhs) noexcept \
264+
{ \
265+
return lhs = lhs & rhs; \
266+
} \
267+
\
268+
inline constexpr EnumType operator|(const EnumType& lhs, const EnumType& rhs) noexcept \
269+
{ \
270+
using T = typename std::underlying_type_t<EnumType>; \
271+
return static_cast<EnumType>(static_cast<T>(lhs) | static_cast<T>(rhs)); \
272+
} \
273+
\
274+
inline constexpr EnumType& operator|=(EnumType& lhs, const EnumType& rhs) noexcept \
275+
{ \
276+
return lhs = lhs | rhs; \
277+
} \
278+
\
279+
inline constexpr EnumType operator^(const EnumType& lhs, const EnumType& rhs) noexcept \
280+
{ \
281+
using T = typename std::underlying_type_t<EnumType>; \
282+
return static_cast<EnumType>(static_cast<T>(lhs) ^ static_cast<T>(rhs)); \
283+
} \
284+
\
285+
inline constexpr EnumType& operator^=(EnumType& lhs, const EnumType& rhs) noexcept \
286+
{ \
287+
return lhs = lhs ^ rhs; \
288+
} \
289+
\
290+
inline constexpr EnumType& operator~(EnumType& e) noexcept \
291+
{ \
292+
using T = typename std::underlying_type_t<EnumType>; \
293+
return e = static_cast<EnumType>(~static_cast<T>(e)); \
294+
} \
295+
/**/
296+
256297

257298
#endif

0 commit comments

Comments
 (0)