diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/color.h | 27 | ||||
-rw-r--r-- | src/common/file_util.h | 10 |
2 files changed, 36 insertions, 1 deletions
diff --git a/src/common/color.h b/src/common/color.h index 422fdc8af..9dafdca0c 100644 --- a/src/common/color.h +++ b/src/common/color.h @@ -208,7 +208,32 @@ inline void EncodeD24(u32 value, u8* bytes) { * @param bytes Pointer where to store the encoded value */ inline void EncodeD24S8(u32 depth, u8 stencil, u8* bytes) { - *reinterpret_cast<u32_le*>(bytes) = (stencil << 24) | depth; + bytes[0] = depth & 0xFF; + bytes[1] = (depth >> 8) & 0xFF; + bytes[2] = (depth >> 16) & 0xFF; + bytes[3] = stencil; +} + +/** + * Encode a 24 bit depth value as D24X8 format (32 bits per pixel with 8 bits unused) + * @param depth 24 bit source depth value to encode + * @param bytes Pointer where to store the encoded value + * @note unused bits will not be modified + */ +inline void EncodeD24X8(u32 depth, u8* bytes) { + bytes[0] = depth & 0xFF; + bytes[1] = (depth >> 8) & 0xFF; + bytes[2] = (depth >> 16) & 0xFF; +} + +/** + * Encode an 8 bit stencil value as X24S8 format (32 bits per pixel with 24 bits unused) + * @param stencil 8 bit source stencil value to encode + * @param bytes Pointer where to store the encoded value + * @note unused bits will not be modified + */ +inline void EncodeX24S8(u8 stencil, u8* bytes) { + bytes[3] = stencil; } } // namespace diff --git a/src/common/file_util.h b/src/common/file_util.h index 8fe772aee..9637d1b85 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -181,6 +181,10 @@ public: template <typename T> size_t WriteArray(const T* data, size_t length) { + static_assert(std::is_standard_layout<T>::value, "Given array does not consist of standard layout objects"); + // TODO: gcc 4.8 does not support is_trivially_copyable, but we really should check for it here. + //static_assert(std::is_trivially_copyable<T>::value, "Given array does not consist of trivially copyable objects"); + if (!IsOpen()) { m_good = false; return -1; @@ -203,6 +207,12 @@ public: return WriteArray(reinterpret_cast<const char*>(data), length); } + template<typename T> + size_t WriteObject(const T& object) { + static_assert(!std::is_pointer<T>::value, "Given object is a pointer"); + return WriteArray(&object, 1); + } + bool IsOpen() { return nullptr != m_file; } // m_good is set to false when a read, write or other function fails |