Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_platform 5 #define tools_platform 6 7 // We do not byteswap on intel (LE) (common pl 8 // We have then a better compression on these 9 // NOTE : this is the contrary to what is done 10 11 namespace tools { 12 13 inline bool is_little_endian() { 14 unsigned int i = 1; 15 unsigned char* b = (unsigned char*)&i; 16 // BE = Big Endian, LE = Little Endian. 17 // The Intels x86 are LE. 18 // Mac PPC b[3] is 1 (BE) 19 // Mac Intel b[0] is 1 (LE) 20 // Linux i386 b[0] is 1 (LE) 21 // Linux x86_64 b[0] is 1 (LE) 22 return (b[0]==1?true:false); 23 } 24 25 } 26 27 #if defined(__APPLE__) 28 #include <TargetConditionals.h> 29 #endif 30 31 namespace tools { 32 namespace device { 33 34 #if TARGET_OS_IPHONE 35 inline bool is_iOS() {return true;} 36 #else 37 inline bool is_iOS() {return false;} 38 #endif 39 40 #ifdef ANDROID 41 inline bool is_Android() {return true;} 42 #else 43 inline bool is_Android() {return false;} 44 #endif 45 46 #ifdef EMSCRIPTEN 47 inline bool is_emscripten() {return true;} 48 #else 49 inline bool is_emscripten() {return false;} 50 #endif 51 52 53 #if defined(ANDROID) || TARGET_OS_IPHONE 54 inline bool small_screen() {return true;} 55 //inline bool no_cursor() {return true; 56 inline bool stop_app_button() {return true;} 57 #elif defined(EMSCRIPTEN) 58 inline bool small_screen() {return false;} 59 //inline bool no_cursor() {return false 60 inline bool stop_app_button() {return true;} 61 #else 62 inline bool small_screen() {return false;} 63 //inline bool no_cursor() {return false 64 inline bool stop_app_button() {return false;} 65 #endif 66 #if TARGET_OS_IPHONE 67 inline bool slow_cpu() {return true;} 68 #else 69 inline bool slow_cpu() {return false;} 70 #endif 71 72 inline unsigned int tex_mem_limit() { 73 // glGet(GL_MAX_TEXTURE_SIZE) : 74 // MacBookPro : it returns 8192. 75 // SGS : it returns 2048. 76 // iPad1 : it returns 2048. 77 // iPod : it returns ? 78 // Nexus 10 : it returns ? 79 80 // 1024*1024 //*3 = 3 145 728 81 // 2048*2048 //*3 = 12 582 912 82 // 4096*4096 //*3 = 50 331 648 83 // 8192*8192 //*3 = 201 326 592 84 // 8192*4096 //*3 = 100 663 296 85 if(small_screen()) { 86 //iOS : Apple says that max 2D tex size is 87 // texture available. From doc on Pow 88 return 2048*2048*3; 89 } else { 90 //limit = 4096*4096*3; //=8192*2048 //perm 91 //permit to pass fete_science_2010/power2/ 92 return 8192*4096*3; //100663296 93 } 94 } 95 96 }} 97 98 ////////////////////////////////////////////// 99 /// backcomp : for OnX/source/Core/atat.cxx : 100 ////////////////////////////////////////////// 101 102 //NOTE : we avoid to have std includes here to 103 // that in the below ifdef things come o 104 105 namespace tools { 106 107 inline const char* os() { 108 109 #if TARGET_OS_IPHONE 110 static const char s_s[] = "iOS"; 111 #elif defined(ANDROID) 112 static const char s_s[] = "Android"; 113 #elif defined(EMSCRIPTEN) 114 static const char s_s[] = "emscripten"; 115 #elif defined(_WIN32) 116 static const char s_s[] = "Windows_NT"; 117 #elif __APPLE__ 118 static const char s_s[] = "Darwin"; 119 #elif defined(__linux) 120 static const char s_s[] = "Linux"; 121 #elif defined(__alpha) 122 static const char s_s[] = "OSF1"; 123 #elif defined(__CYGWIN__) 124 static const char s_s[] = "CYGWIN"; 125 #else 126 static const char s_s[] = "unknown"; 127 #endif 128 return s_s; 129 } 130 131 inline bool _WIN32_defined() { 132 #ifdef _WIN32 133 return true; 134 #else 135 return false; 136 #endif 137 } 138 139 inline const char* processor() { 140 141 #if defined(__GNUC__) 142 143 #if defined(__ppc__) 144 static const char s_s[] = "ppc"; 145 #elif defined(__ppc64__) 146 static const char s_s[] = "ppc64"; 147 #elif defined(__i386__) 148 static const char s_s[] = "i386"; 149 #elif defined(__x86_64__) 150 static const char s_s[] = "x86_64"; 151 #elif defined(__ia64__) 152 static const char s_s[] = "ia64"; 153 #else 154 static const char s_s[] = "unknown"; 155 #endif 156 157 #elif defined(_MSC_VER) 158 159 #if defined(_M_IX86) 160 static const char s_s[] = "ix86"; 161 #elif defined(_M_X64) 162 static const char s_s[] = "x64"; 163 #else 164 static const char s_s[] = "unknown"; 165 #endif 166 167 #elif defined(__alpha) 168 static const char s_s[] = "alpha"; 169 170 #else 171 static const char s_s[] = "unknown"; 172 #endif 173 return s_s; 174 } 175 176 inline const char* compiler_name() { 177 178 #if defined(__clang__) 179 static const char s_s[] = "clang"; 180 #elif defined(__GNUC__) 181 static const char s_s[] = "gcc"; 182 #elif defined(_MSC_VER) 183 static const char s_s[] = "cl"; 184 #elif defined(__alpha) 185 static const char s_s[] = "cxx"; 186 #else 187 static const char s_s[] = "unknown"; 188 #endif 189 return s_s; 190 } 191 192 } 193 194 #include "tosu" //does not bring any std inclu 195 196 namespace tools { 197 198 inline void compiler(char a_s[128]) { 199 char* pos = a_s; 200 unsigned int l; 201 toss(compiler_name(),pos,l);pos += l; 202 203 #if defined(__clang__) 204 *pos = '_';pos++; 205 tosu<unsigned int>(__clang_major__,pos,l);po 206 tosu<unsigned int>(__clang_minor__,pos,l);po 207 tosu<unsigned int>(__clang_patchlevel__,pos, 208 #elif defined(__GNUC__) 209 *pos = '_';pos++; 210 tosu<unsigned int>(__GNUC__,pos,l);pos += l; 211 tosu<unsigned int>(__GNUC_MINOR__,pos,l);pos 212 tosu<unsigned int>(__GNUC_PATCHLEVEL__,pos,l 213 #elif defined(_MSC_VER) 214 *pos = '_';pos++; 215 tosu<unsigned int>(_MSC_VER,pos,l);pos += l; 216 //_mfc_ 217 //tosu<unsigned int>(_MFC_VER,pos,l);pos += 218 #elif defined(__alpha) 219 #else 220 #endif 221 *pos = 0; 222 } 223 224 } 225 226 #endif 227 228 229 /* We prefer to handle endianity dynamically, 230 it would looks like (from luaconf.h) : 231 #if defined(__i386__) || defined(__i386) || \ 232 defined(__X86__) || defined (__x86_64) 233 #define TOOLS_IS_BE 0 234 #define TOOLS_IS_LE 1 235 #elif defined(__POWERPC__) || defined(__ppc__) 236 #define TOOLS_IS_BE 1 237 #define TOOLS_IS_LE 0 238 #endif 239 */