1 // 2 // Copyright (c) 2002-2010 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 // angleutils.h: Common ANGLE utilities. 8 9 #ifndef COMMON_ANGLEUTILS_H_ 10 #define COMMON_ANGLEUTILS_H_ 11 12 #include <stddef.h> 13 14 // A macro to disallow the copy constructor and operator= functions 15 // This must be used in the private: declarations for a class 16 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ 17 TypeName(const TypeName&); \ 18 void operator=(const TypeName&) 19 20 template <typename T, unsigned int N> 21 inline unsigned int ArraySize(T(&)[N]) 22 { 23 return N; 24 } 25 26 template <typename T, unsigned int N> 27 void SafeRelease(T (&resourceBlock)[N]) 28 { 29 for (unsigned int i = 0; i < N; i++) 30 { 31 SafeRelease(resourceBlock[i]); 32 } 33 } 34 35 template <typename T> 36 void SafeRelease(T& resource) 37 { 38 if (resource) 39 { 40 resource->Release(); 41 resource = NULL; 42 } 43 } 44 45 template <typename T> 46 void SafeDelete(T*& resource) 47 { 48 delete resource; 49 resource = NULL; 50 } 51 52 template <typename T> 53 void SafeDeleteArray(T*& resource) 54 { 55 delete[] resource; 56 resource = NULL; 57 } 58 59 // Provide a less-than function for comparing structs 60 // Note: struct memory must be initialized to zero, because of packing gaps 61 template <typename T> 62 inline bool StructLessThan(const T &a, const T &b) 63 { 64 return (memcmp(&a, &b, sizeof(T)) < 0); 65 } 66 67 // Provide a less-than function for comparing structs 68 // Note: struct memory must be initialized to zero, because of packing gaps 69 template <typename T> 70 inline bool StructEquals(const T &a, const T &b) 71 { 72 return (memcmp(&a, &b, sizeof(T)) == 0); 73 } 74 75 template <typename T> 76 inline void StructZero(T *obj) 77 { 78 memset(obj, 0, sizeof(T)); 79 } 80 81 #if defined(_MSC_VER) 82 #define snprintf _snprintf 83 #endif 84 85 #define VENDOR_ID_AMD 0x1002 86 #define VENDOR_ID_INTEL 0x8086 87 #define VENDOR_ID_NVIDIA 0x10DE 88 89 #define GL_BGRA4_ANGLEX 0x6ABC 90 #define GL_BGR5_A1_ANGLEX 0x6ABD 91 #define GL_INT_64_ANGLEX 0x6ABE 92 #define GL_STRUCT_ANGLEX 0x6ABF 93 94 #endif // COMMON_ANGLEUTILS_H_ 95