diff options
Diffstat (limited to 'src/3rdparty/angle/src/common/angleutils.h')
-rw-r--r-- | src/3rdparty/angle/src/common/angleutils.h | 131 |
1 files changed, 106 insertions, 25 deletions
diff --git a/src/3rdparty/angle/src/common/angleutils.h b/src/3rdparty/angle/src/common/angleutils.h index a0178fd414..ad32a2f03a 100644 --- a/src/3rdparty/angle/src/common/angleutils.h +++ b/src/3rdparty/angle/src/common/angleutils.h @@ -23,25 +23,59 @@ namespace angle { +#if defined(ANGLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11) +using Microsoft::WRL::ComPtr; +#endif // defined(ANGLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11) + class NonCopyable { - public: + protected: NonCopyable() = default; ~NonCopyable() = default; - protected: + + private: NonCopyable(const NonCopyable&) = delete; void operator=(const NonCopyable&) = delete; }; extern const uintptr_t DirtyPointer; -} + +} // namespace angle template <typename T, size_t N> -inline size_t ArraySize(T(&)[N]) +constexpr inline size_t ArraySize(T (&)[N]) { return N; } +template <typename T> +class WrappedArray final : angle::NonCopyable +{ + public: + template <size_t N> + constexpr WrappedArray(const T (&data)[N]) : mArray(&data[0]), mSize(N) + { + } + + constexpr WrappedArray() : mArray(nullptr), mSize(0) {} + constexpr WrappedArray(const T *data, size_t size) : mArray(data), mSize(size) {} + + WrappedArray(WrappedArray &&other) : WrappedArray() + { + std::swap(mArray, other.mArray); + std::swap(mSize, other.mSize); + } + + ~WrappedArray() {} + + constexpr const T *get() const { return mArray; } + constexpr size_t size() const { return mSize; } + + private: + const T *mArray; + size_t mSize; +}; + template <typename T, unsigned int N> void SafeRelease(T (&resourceBlock)[N]) { @@ -57,15 +91,15 @@ void SafeRelease(T& resource) if (resource) { resource->Release(); - resource = NULL; + resource = nullptr; } } template <typename T> -void SafeDelete(T*& resource) +void SafeDelete(T *&resource) { delete resource; - resource = NULL; + resource = nullptr; } template <typename T> @@ -82,7 +116,7 @@ template <typename T> void SafeDeleteArray(T*& resource) { delete[] resource; - resource = NULL; + resource = nullptr; } // Provide a less-than function for comparing structs @@ -126,23 +160,11 @@ inline const char* MakeStaticString(const std::string &str) return strings.insert(str).first->c_str(); } -inline std::string ArrayString(unsigned int i) -{ - // We assume UINT_MAX and GL_INVALID_INDEX are equal - // See DynamicHLSL.cpp - if (i == UINT_MAX) - { - return ""; - } +std::string ArrayString(unsigned int i); - std::stringstream strstr; - - strstr << "["; - strstr << i; - strstr << "]"; - - return strstr.str(); -} +// Indices are stored in vectors with the outermost index in the back. In the output of the function +// the indices are reversed. +std::string ArrayIndexString(const std::vector<unsigned int> &indices); inline std::string Str(int i) { @@ -156,17 +178,76 @@ size_t FormatStringIntoVector(const char *fmt, va_list vararg, std::vector<char> std::string FormatString(const char *fmt, va_list vararg); std::string FormatString(const char *fmt, ...); +template <typename T> +std::string ToString(const T &value) +{ + std::ostringstream o; + o << value; + return o.str(); +} + // snprintf is not defined with MSVC prior to to msvc14 #if defined(_MSC_VER) && _MSC_VER < 1900 #define snprintf _snprintf #endif +#define GL_BGRX8_ANGLEX 0x6ABA +#define GL_BGR565_ANGLEX 0x6ABB #define GL_BGRA4_ANGLEX 0x6ABC #define GL_BGR5_A1_ANGLEX 0x6ABD #define GL_INT_64_ANGLEX 0x6ABE -#define GL_STRUCT_ANGLEX 0x6ABF +#define GL_UINT_64_ANGLEX 0x6ABF +#define GL_BGRA8_SRGB_ANGLEX 0x6AC0 // Hidden enum for the NULL D3D device type. #define EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE 0x6AC0 +// TODO(jmadill): Clean this up at some point. +#define EGL_PLATFORM_ANGLE_PLATFORM_METHODS_ANGLEX 0x9999 + +#define ANGLE_TRY_CHECKED_MATH(result) \ + if (!result.IsValid()) \ + { \ + return gl::InternalError() << "Integer overflow."; \ + } + +// The below inlining code lifted from V8. +#if defined(__clang__) || (defined(__GNUC__) && defined(__has_attribute)) +#define ANGLE_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline)) +#define ANGLE_HAS___FORCEINLINE 0 +#elif defined(_MSC_VER) +#define ANGLE_HAS_ATTRIBUTE_ALWAYS_INLINE 0 +#define ANGLE_HAS___FORCEINLINE 1 +#else +#define ANGLE_HAS_ATTRIBUTE_ALWAYS_INLINE 0 +#define ANGLE_HAS___FORCEINLINE 0 +#endif + +#if defined(NDEBUG) && ANGLE_HAS_ATTRIBUTE_ALWAYS_INLINE +#define ANGLE_INLINE inline __attribute__((always_inline)) +#elif defined(NDEBUG) && ANGLE_HAS___FORCEINLINE +#define ANGLE_INLINE __forceinline +#else +#define ANGLE_INLINE inline +#endif + +#ifndef ANGLE_STRINGIFY +#define ANGLE_STRINGIFY(x) #x +#endif + +#ifndef ANGLE_MACRO_STRINGIFY +#define ANGLE_MACRO_STRINGIFY(x) ANGLE_STRINGIFY(x) +#endif + +// Detect support for C++17 [[nodiscard]] +#if !defined(__has_cpp_attribute) +#define __has_cpp_attribute(name) 0 +#endif // !defined(__has_cpp_attribute) + +#if __has_cpp_attribute(nodiscard) +#define ANGLE_NO_DISCARD [[nodiscard]] +#else +#define ANGLE_NO_DISCARD +#endif // __has_cpp_attribute(nodiscard) + #endif // COMMON_ANGLEUTILS_H_ |