summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/color.h27
-rw-r--r--src/common/file_util.h10
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) {
208 * @param bytes Pointer where to store the encoded value 208 * @param bytes Pointer where to store the encoded value
209 */ 209 */
210inline void EncodeD24S8(u32 depth, u8 stencil, u8* bytes) { 210inline void EncodeD24S8(u32 depth, u8 stencil, u8* bytes) {
211 *reinterpret_cast<u32_le*>(bytes) = (stencil << 24) | depth; 211 bytes[0] = depth & 0xFF;
212 bytes[1] = (depth >> 8) & 0xFF;
213 bytes[2] = (depth >> 16) & 0xFF;
214 bytes[3] = stencil;
215}
216
217/**
218 * Encode a 24 bit depth value as D24X8 format (32 bits per pixel with 8 bits unused)
219 * @param depth 24 bit source depth value to encode
220 * @param bytes Pointer where to store the encoded value
221 * @note unused bits will not be modified
222 */
223inline void EncodeD24X8(u32 depth, u8* bytes) {
224 bytes[0] = depth & 0xFF;
225 bytes[1] = (depth >> 8) & 0xFF;
226 bytes[2] = (depth >> 16) & 0xFF;
227}
228
229/**
230 * Encode an 8 bit stencil value as X24S8 format (32 bits per pixel with 24 bits unused)
231 * @param stencil 8 bit source stencil value to encode
232 * @param bytes Pointer where to store the encoded value
233 * @note unused bits will not be modified
234 */
235inline void EncodeX24S8(u8 stencil, u8* bytes) {
236 bytes[3] = stencil;
212} 237}
213 238
214} // namespace 239} // 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:
181 template <typename T> 181 template <typename T>
182 size_t WriteArray(const T* data, size_t length) 182 size_t WriteArray(const T* data, size_t length)
183 { 183 {
184 static_assert(std::is_standard_layout<T>::value, "Given array does not consist of standard layout objects");
185 // TODO: gcc 4.8 does not support is_trivially_copyable, but we really should check for it here.
186 //static_assert(std::is_trivially_copyable<T>::value, "Given array does not consist of trivially copyable objects");
187
184 if (!IsOpen()) { 188 if (!IsOpen()) {
185 m_good = false; 189 m_good = false;
186 return -1; 190 return -1;
@@ -203,6 +207,12 @@ public:
203 return WriteArray(reinterpret_cast<const char*>(data), length); 207 return WriteArray(reinterpret_cast<const char*>(data), length);
204 } 208 }
205 209
210 template<typename T>
211 size_t WriteObject(const T& object) {
212 static_assert(!std::is_pointer<T>::value, "Given object is a pointer");
213 return WriteArray(&object, 1);
214 }
215
206 bool IsOpen() { return nullptr != m_file; } 216 bool IsOpen() { return nullptr != m_file; }
207 217
208 // m_good is set to false when a read, write or other function fails 218 // m_good is set to false when a read, write or other function fails