ovr_sdk

diff LibOVR/Src/Kernel/OVR_Types.h @ 0:1b39a1b46319

initial 0.4.4
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 14 Jan 2015 06:51:16 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/LibOVR/Src/Kernel/OVR_Types.h	Wed Jan 14 06:51:16 2015 +0200
     1.3 @@ -0,0 +1,909 @@
     1.4 +/************************************************************************************
     1.5 +
     1.6 +PublicHeader:   OVR_Kernel.h
     1.7 +Filename    :   OVR_Types.h
     1.8 +Content     :   Standard library defines and simple types
     1.9 +Created     :   September 19, 2012
    1.10 +Notes       : 
    1.11 +
    1.12 +Copyright   :   Copyright 2014 Oculus VR, LLC All Rights reserved.
    1.13 +
    1.14 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 
    1.15 +you may not use the Oculus VR Rift SDK except in compliance with the License, 
    1.16 +which is provided at the time of installation or download, or which 
    1.17 +otherwise accompanies this software in either electronic or hard copy form.
    1.18 +
    1.19 +You may obtain a copy of the License at
    1.20 +
    1.21 +http://www.oculusvr.com/licenses/LICENSE-3.2 
    1.22 +
    1.23 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 
    1.24 +distributed under the License is distributed on an "AS IS" BASIS,
    1.25 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.26 +See the License for the specific language governing permissions and
    1.27 +limitations under the License.
    1.28 +
    1.29 +************************************************************************************/
    1.30 +
    1.31 +#ifndef OVR_Types_H
    1.32 +#define OVR_Types_H
    1.33 +
    1.34 +#include "OVR_Compiler.h"
    1.35 +
    1.36 +
    1.37 +// Unsupported compiler configurations
    1.38 +#if _MSC_VER == 0x1600
    1.39 +#  if _MSC_FULL_VER < 160040219
    1.40 +#     error "Oculus does not support VS2010 without SP1 installed: It will crash in Release mode"
    1.41 +#  endif
    1.42 +#endif
    1.43 +
    1.44 +
    1.45 +//-----------------------------------------------------------------------------------
    1.46 +// ****** Operating system identification
    1.47 +//
    1.48 +// Try to use the most generic version of these defines as possible in order to achieve
    1.49 +// the simplest portable code. For example, instead of using #if (defined(OVR_OS_IPHONE) || defined(OVR_OS_MAC)),
    1.50 +// consider using #if defined(OVR_OS_APPLE).
    1.51 +//
    1.52 +// Type definitions exist for the following operating systems: (OVR_OS_x)
    1.53 +//
    1.54 +//    WIN32      - Win32 and Win64 (Windows XP and later) Does not include Microsoft phone and console platforms, despite that Microsoft's _WIN32 may be defined by the compiler for them.
    1.55 +//    WIN64      - Win64 (Windows XP and later)
    1.56 +//    MAC        - Mac OS X (may be defined in addition to BSD)
    1.57 +//    LINUX      - Linux
    1.58 +//    BSD        - BSD Unix
    1.59 +//    ANDROID    - Android (may be defined in addition to LINUX)
    1.60 +//    IPHONE     - iPhone
    1.61 +//    MS_MOBILE  - Microsoft mobile OS.
    1.62 +//
    1.63 +//  Meta platforms
    1.64 +//    MS        - Any OS by Microsoft (e.g. Win32, Win64, phone, console)
    1.65 +//    APPLE     - Any OS by Apple (e.g. iOS, OS X)
    1.66 +//    UNIX      - Linux, BSD, Mac OS X.
    1.67 +//    MOBILE    - iOS, Android, Microsoft phone
    1.68 +//    CONSOLE   - Console platforms
    1.69 +//
    1.70 +
    1.71 +#if (defined(__APPLE__) && (defined(__GNUC__) ||\
    1.72 +     defined(__xlC__) || defined(__xlc__))) || defined(__MACOS__)
    1.73 +#  if (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) || defined(__IPHONE_OS_VERSION_MIN_REQUIRED))
    1.74 +#    define OVR_OS_IPHONE
    1.75 +#  else
    1.76 +#    define OVR_OS_DARWIN
    1.77 +#    define OVR_OS_MAC
    1.78 +#    define OVR_OS_BSD
    1.79 +#  endif
    1.80 +#elif (defined(WIN64) || defined(_WIN64) || defined(__WIN64__))
    1.81 +#  define OVR_OS_WIN64
    1.82 +#  define OVR_OS_WIN32   // Defined for compatibility and because the Win64 API supports the Win32 API.
    1.83 +#elif (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__))
    1.84 +#  define OVR_OS_WIN32
    1.85 +#elif defined(ANDROID) || defined(__ANDROID__)
    1.86 +#  define OVR_OS_ANDROID
    1.87 +#  define OVR_OS_LINUX
    1.88 +#elif defined(__linux__) || defined(__linux)
    1.89 +#  define OVR_OS_LINUX
    1.90 +#elif defined(_BSD_) || defined(__FreeBSD__)
    1.91 +#  define OVR_OS_BSD
    1.92 +#else
    1.93 +#  define OVR_OS_OTHER
    1.94 +#endif
    1.95 +
    1.96 +#if !defined(OVR_OS_MS_MOBILE)
    1.97 +#   if (defined(_M_ARM) || defined(_M_IX86) || defined(_M_AMD64)) && !defined(OVR_OS_WIN32) && !defined(OVR_OS_CONSOLE)
    1.98 +#       define OVR_OS_MS_MOBILE
    1.99 +#   endif
   1.100 +#endif
   1.101 +
   1.102 +#if !defined(OVR_OS_MS)
   1.103 +#   if defined(OVR_OS_WIN32) || defined(OVR_OS_WIN64) || defined(OVR_OS_MS_MOBILE)
   1.104 +#       define OVR_OS_MS
   1.105 +#   endif
   1.106 +#endif
   1.107 +
   1.108 +#if !defined(OVR_OS_APPLE)
   1.109 +#   if defined(OVR_OS_MAC) || defined(OVR_OS_IPHONE)
   1.110 +#       define OVR_OS_APPLE
   1.111 +#   endif
   1.112 +#endif
   1.113 +
   1.114 +#if !defined(OVR_OS_UNIX)
   1.115 +#   if defined(OVR_OS_ANDROID) || defined(OVR_OS_BSD) || defined(OVR_OS_LINUX) || defined(OVR_OS_MAC)
   1.116 +#       define OVR_OS_UNIX
   1.117 +#   endif
   1.118 +#endif
   1.119 +
   1.120 +#if !defined(OVR_OS_MOBILE)
   1.121 +#   if defined(OVR_OS_ANDROID) || defined(OVR_OS_IPHONE) || defined(OVR_OS_MS_MOBILE)
   1.122 +#       define OVR_OS_MOBILE
   1.123 +#   endif
   1.124 +#endif
   1.125 +
   1.126 +
   1.127 +
   1.128 +
   1.129 +//-----------------------------------------------------------------------------------
   1.130 +// ***** CPU Architecture
   1.131 +//
   1.132 +// The following CPUs are defined: (OVR_CPU_x)
   1.133 +//
   1.134 +//    X86        - x86 (IA-32)
   1.135 +//    X86_64     - x86_64 (amd64)
   1.136 +//    PPC        - PowerPC
   1.137 +//    PPC64      - PowerPC64
   1.138 +//    MIPS       - MIPS
   1.139 +//    OTHER      - CPU for which no special support is present or needed
   1.140 +
   1.141 +
   1.142 +#if defined(__x86_64__) || defined(WIN64) || defined(_WIN64) || defined(__WIN64__) || defined(_M_AMD64)
   1.143 +#  define OVR_CPU_X86_64
   1.144 +#  define OVR_64BIT_POINTERS
   1.145 +#elif defined(__i386__) || defined(OVR_OS_WIN32)
   1.146 +#  define OVR_CPU_X86
   1.147 +#elif defined(__powerpc64__)
   1.148 +#  define OVR_CPU_PPC64
   1.149 +#elif defined(__ppc__)
   1.150 +#  define OVR_CPU_PPC
   1.151 +#elif defined(__mips__) || defined(__MIPSEL__)
   1.152 +#  define OVR_CPU_MIPS
   1.153 +#elif defined(__arm__)
   1.154 +#  define OVR_CPU_ARM
   1.155 +#else
   1.156 +#  define OVR_CPU_OTHER
   1.157 +#endif
   1.158 +
   1.159 +//-----------------------------------------------------------------------------------
   1.160 +// ***** Co-Processor Architecture
   1.161 +//
   1.162 +// The following co-processors are defined: (OVR_CPU_x)
   1.163 +//
   1.164 +//    SSE        - Available on all modern x86 processors.
   1.165 +//    Altivec    - Available on all modern ppc processors.
   1.166 +//    Neon       - Available on some armv7+ processors.
   1.167 +
   1.168 +#if defined(__SSE__) || defined(_M_IX86) || defined(_M_AMD64) // _M_IX86 and _M_AMD64 are Microsoft identifiers for Intel-based platforms.
   1.169 +#  define  OVR_CPU_SSE
   1.170 +#endif // __SSE__
   1.171 +
   1.172 +#if defined( __ALTIVEC__ )
   1.173 +#  define OVR_CPU_ALTIVEC
   1.174 +#endif // __ALTIVEC__
   1.175 +
   1.176 +#if defined(__ARM_NEON__)
   1.177 +#  define OVR_CPU_ARM_NEON
   1.178 +#endif // __ARM_NEON__
   1.179 +
   1.180 +
   1.181 +//-----------------------------------------------------------------------------------
   1.182 +// ***** Compiler Warnings
   1.183 +
   1.184 +// Disable MSVC warnings
   1.185 +#if defined(OVR_CC_MSVC)
   1.186 +#  pragma warning(disable : 4127)    // Inconsistent dll linkage
   1.187 +#  pragma warning(disable : 4530)    // Exception handling
   1.188 +#  if (OVR_CC_MSVC<1300)
   1.189 +#    pragma warning(disable : 4514)  // Unreferenced inline function has been removed
   1.190 +#    pragma warning(disable : 4710)  // Function not inlined
   1.191 +#    pragma warning(disable : 4714)  // _force_inline not inlined
   1.192 +#    pragma warning(disable : 4786)  // Debug variable name longer than 255 chars
   1.193 +#  endif // (OVR_CC_MSVC<1300)
   1.194 +#endif // (OVR_CC_MSVC)
   1.195 +
   1.196 +
   1.197 +
   1.198 +// *** Linux Unicode - must come before Standard Includes
   1.199 +
   1.200 +#ifdef OVR_OS_LINUX
   1.201 +// Use glibc unicode functions on linux.
   1.202 +#  ifndef  _GNU_SOURCE
   1.203 +#    define _GNU_SOURCE
   1.204 +#  endif
   1.205 +#endif
   1.206 +
   1.207 +//-----------------------------------------------------------------------------------
   1.208 +// ***** Standard Includes
   1.209 +//
   1.210 +#include    <stddef.h>
   1.211 +#include    <limits.h>
   1.212 +#include    <float.h>
   1.213 +
   1.214 +
   1.215 +// MSVC Based Memory Leak checking - for now
   1.216 +#if defined(OVR_CC_MSVC) && defined(OVR_BUILD_DEBUG)
   1.217 +#  define _CRTDBG_MAP_ALLOC
   1.218 +#  include <stdlib.h>
   1.219 +#  include <crtdbg.h>
   1.220 +#endif
   1.221 +
   1.222 +
   1.223 +//-----------------------------------------------------------------------------------
   1.224 +// ***** int8_t, int16_t, etc.
   1.225 +
   1.226 +#if defined(OVR_CC_MSVC) && (OVR_CC_VER <= 1500) // VS2008 and earlier
   1.227 +    typedef signed char        int8_t; 
   1.228 +    typedef unsigned char     uint8_t;
   1.229 +    typedef signed short      int16_t;
   1.230 +    typedef unsigned short   uint16_t;
   1.231 +    typedef signed int        int32_t;
   1.232 +    typedef unsigned int     uint32_t;
   1.233 +    typedef signed __int64    int64_t;
   1.234 +    typedef unsigned __int64 uint64_t;
   1.235 +#else
   1.236 +    #include <stdint.h>
   1.237 +#endif
   1.238 +
   1.239 +
   1.240 +//-----------------------------------------------------------------------------------
   1.241 +// ***** Type definitions for Common Systems
   1.242 +
   1.243 +namespace OVR {
   1.244 +
   1.245 +typedef char            Char;
   1.246 +
   1.247 +// Pointer-sized integer
   1.248 +typedef size_t          UPInt;
   1.249 +typedef ptrdiff_t       SPInt;
   1.250 +
   1.251 +
   1.252 +#if defined(OVR_OS_MS)
   1.253 +
   1.254 +typedef char            SByte;  // 8 bit Integer (Byte)
   1.255 +typedef unsigned char   UByte;
   1.256 +typedef short           SInt16; // 16 bit Integer (Word)
   1.257 +typedef unsigned short  UInt16;
   1.258 +typedef long            SInt32; // 32 bit Integer
   1.259 +typedef unsigned long   UInt32;
   1.260 +typedef __int64         SInt64; // 64 bit Integer (QWord)
   1.261 +typedef unsigned __int64 UInt64;
   1.262 +
   1.263 + 
   1.264 +#elif defined(OVR_OS_MAC) || defined(OVR_OS_IPHONE) || defined(OVR_CC_GNU)
   1.265 +
   1.266 +typedef int             SByte  __attribute__((__mode__ (__QI__)));
   1.267 +typedef unsigned int    UByte  __attribute__((__mode__ (__QI__)));
   1.268 +typedef int             SInt16 __attribute__((__mode__ (__HI__)));
   1.269 +typedef unsigned int    UInt16 __attribute__((__mode__ (__HI__)));
   1.270 +typedef int             SInt32 __attribute__((__mode__ (__SI__)));
   1.271 +typedef unsigned int    UInt32 __attribute__((__mode__ (__SI__)));
   1.272 +typedef int             SInt64 __attribute__((__mode__ (__DI__)));
   1.273 +typedef unsigned int    UInt64 __attribute__((__mode__ (__DI__)));
   1.274 +
   1.275 +#else
   1.276 +
   1.277 +#include <sys/types.h>
   1.278 +typedef int8_t          SByte;
   1.279 +typedef uint8_t         UByte;
   1.280 +typedef int16_t         SInt16;
   1.281 +typedef uint16_t        UInt16;
   1.282 +typedef int32_t         SInt32;
   1.283 +typedef uint32_t        UInt32;
   1.284 +typedef int64_t         SInt64;
   1.285 +typedef uint64_t        UInt64;
   1.286 +
   1.287 +#endif
   1.288 +    
   1.289 +    
   1.290 +//osx PID is a signed int32 (already defined to pid_t in OSX framework)
   1.291 +//linux PID is a signed int32 (already defined)
   1.292 +//win32 PID is an unsigned int64
   1.293 +#ifdef OVR_OS_WIN32
   1.294 +//process ID representation
   1.295 +typedef unsigned long pid_t;
   1.296 +#endif
   1.297 +
   1.298 +struct OVR_GUID
   1.299 +{
   1.300 +	uint32_t Data1;
   1.301 +	uint16_t Data2;
   1.302 +	uint16_t Data3;
   1.303 +	uint8_t  Data4[8];
   1.304 +};
   1.305 +
   1.306 +
   1.307 +
   1.308 +} // OVR
   1.309 +
   1.310 +
   1.311 +
   1.312 +//-----------------------------------------------------------------------------------
   1.313 +// ****** Standard C/C++ Library
   1.314 +//
   1.315 +// Identifies which standard library is currently being used. 
   1.316 +//
   1.317 +//    LIBSTDCPP   - GNU libstdc++, used by GCC.
   1.318 +//    LIBCPP      - LLVM libc++, typically used by clang and GCC.
   1.319 +//    DINKUMWARE  - Used by Microsoft and various non-Microsoft compilers (e.g. Sony clang).
   1.320 +
   1.321 +#if !defined(OVR_STDLIB_LIBSTDCPP)
   1.322 +    #if defined(__GLIBCXX__)
   1.323 +        #define OVR_STDLIB_LIBSTDCPP 1
   1.324 +    #endif
   1.325 +#endif
   1.326 +
   1.327 +#if !defined(OVR_STDLIB_LIBCPP)
   1.328 +    #if defined(__clang__)
   1.329 +        #if defined(__cplusplus) && __has_include(<__config>)
   1.330 +            #define OVR_STDLIB_LIBCPP 1
   1.331 +        #endif
   1.332 +    #endif 
   1.333 +#endif
   1.334 +
   1.335 +#if !defined(OVR_STDLIB_DINKUMWARE)
   1.336 +    #if defined(_YVALS) // Dinkumware globally #defines _YVALS from the #includes above.
   1.337 +        #define OVR_STDLIB_DINKUMWARE 1
   1.338 +    #endif
   1.339 +#endif
   1.340 +
   1.341 +
   1.342 +//-----------------------------------------------------------------------------------
   1.343 +// ***** Macro Definitions
   1.344 +//
   1.345 +// We define the following:
   1.346 +//
   1.347 +//  OVR_BYTE_ORDER      - Defined to either OVR_LITTLE_ENDIAN or OVR_BIG_ENDIAN
   1.348 +//  OVR_FORCE_INLINE    - Forces inline expansion of function
   1.349 +//  OVR_ASM             - Assembly language prefix
   1.350 +//  OVR_STR             - Prefixes string with L"" if building unicode
   1.351 +// 
   1.352 +//  OVR_STDCALL         - Use stdcall calling convention (Pascal arg order)
   1.353 +//  OVR_CDECL           - Use cdecl calling convention (C argument order)
   1.354 +//  OVR_FASTCALL        - Use fastcall calling convention (registers)
   1.355 +//
   1.356 +
   1.357 +// Byte order constants, OVR_BYTE_ORDER is defined to be one of these.
   1.358 +#define OVR_LITTLE_ENDIAN       1
   1.359 +#define OVR_BIG_ENDIAN          2
   1.360 +
   1.361 +
   1.362 +#if defined(OVR_OS_MS)
   1.363 +    
   1.364 +    // ***** Windows and non-desktop platforms
   1.365 +
   1.366 +    // Byte order
   1.367 +    #define OVR_BYTE_ORDER    OVR_LITTLE_ENDIAN
   1.368 +
   1.369 +    // Calling convention - goes after function return type but before function name
   1.370 +    #ifdef __cplusplus_cli
   1.371 +    #  define OVR_FASTCALL      __stdcall
   1.372 +    #else
   1.373 +    #  define OVR_FASTCALL      __fastcall
   1.374 +    #endif
   1.375 +
   1.376 +    #define OVR_STDCALL         __stdcall
   1.377 +    #define OVR_CDECL           __cdecl
   1.378 +
   1.379 +
   1.380 +    // Assembly macros
   1.381 +    #if defined(OVR_CC_MSVC)
   1.382 +    #  define OVR_ASM           _asm
   1.383 +    #else
   1.384 +    #  define OVR_ASM           asm
   1.385 +    #endif // (OVR_CC_MSVC)
   1.386 +
   1.387 +    #ifdef UNICODE
   1.388 +    #  define OVR_STR(str)      L##str
   1.389 +    #else
   1.390 +    #  define OVR_STR(str)      str
   1.391 +    #endif // UNICODE
   1.392 +
   1.393 +#else
   1.394 +
   1.395 +    // **** Standard systems
   1.396 +
   1.397 +    #if (defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN))|| \
   1.398 +        (defined(_BYTE_ORDER) && (_BYTE_ORDER == _BIG_ENDIAN))
   1.399 +    #  define OVR_BYTE_ORDER    OVR_BIG_ENDIAN
   1.400 +    #elif (defined(__ARMEB__) || defined(OVR_CPU_PPC) || defined(OVR_CPU_PPC64))
   1.401 +    #  define OVR_BYTE_ORDER    OVR_BIG_ENDIAN
   1.402 +    #else
   1.403 +    #  define OVR_BYTE_ORDER    OVR_LITTLE_ENDIAN
   1.404 +    #endif
   1.405 +    
   1.406 +    // Assembly macros
   1.407 +    #define OVR_ASM                  __asm__
   1.408 +    #define OVR_ASM_PROC(procname)   OVR_ASM
   1.409 +    #define OVR_ASM_END              OVR_ASM
   1.410 +    
   1.411 +    // Calling convention - goes after function return type but before function name
   1.412 +    #define OVR_FASTCALL
   1.413 +    #define OVR_STDCALL
   1.414 +    #define OVR_CDECL
   1.415 +
   1.416 +#endif // defined(OVR_OS_WIN32)
   1.417 +
   1.418 +
   1.419 +//-----------------------------------------------------------------------------------
   1.420 +// ***** OVR_PTR_SIZE
   1.421 +// 
   1.422 +// Specifies the byte size of pointers (same as sizeof void*).
   1.423 +
   1.424 +#if !defined(OVR_PTR_SIZE)
   1.425 +    #if defined(__WORDSIZE)
   1.426 +        #define OVR_PTR_SIZE ((__WORDSIZE) / 8)
   1.427 +    #elif defined(_WIN64) || defined(__LP64__) || defined(_LP64) || defined(_M_IA64) || defined(__ia64__) || defined(__arch64__) || defined(__64BIT__) || defined(__Ptr_Is_64)
   1.428 +        #define OVR_PTR_SIZE 8
   1.429 +    #elif defined(__CC_ARM) && (__sizeof_ptr == 8)
   1.430 +        #define OVR_PTR_SIZE 8
   1.431 +    #else
   1.432 +        #define OVR_PTR_SIZE 4
   1.433 +    #endif
   1.434 +#endif
   1.435 +
   1.436 +
   1.437 +//-----------------------------------------------------------------------------------
   1.438 +// ***** OVR_WORD_SIZE
   1.439 +// 
   1.440 +// Specifies the byte size of a machine word/register. Not necessarily the same as
   1.441 +// the size of pointers, but usually >= the size of pointers.
   1.442 +
   1.443 +#if !defined(OVR_WORD_SIZE)
   1.444 +   #define OVR_WORD_SIZE OVR_PTR_SIZE // For our currently supported platforms these are equal.
   1.445 +#endif
   1.446 +
   1.447 +
   1.448 +// ------------------------------------------------------------------------
   1.449 +// ***** OVR_FORCE_INLINE
   1.450 +//
   1.451 +// Force inline substitute - goes before function declaration
   1.452 +// Example usage:
   1.453 +//     OVR_FORCE_INLINE void Test();
   1.454 +
   1.455 +#if !defined(OVR_FORCE_INLINE)
   1.456 +    #if defined(OVR_CC_MSVC)
   1.457 +        #define OVR_FORCE_INLINE  __forceinline
   1.458 +    #elif defined(OVR_CC_GNU)
   1.459 +        #define OVR_FORCE_INLINE  __attribute__((always_inline)) inline
   1.460 +    #else
   1.461 +        #define OVR_FORCE_INLINE  inline
   1.462 +    #endif  // OVR_CC_MSVC
   1.463 +#endif
   1.464 +
   1.465 +
   1.466 +// ------------------------------------------------------------------------
   1.467 +// ***** OVR_NO_INLINE
   1.468 +//
   1.469 +// Cannot be used with inline or OVR_FORCE_INLINE.
   1.470 +// Example usage:
   1.471 +//     OVR_NO_INLINE void Test();
   1.472 +
   1.473 +#if !defined(OVR_NO_INLINE)
   1.474 +    #if defined(OVR_CC_MSVC) && (_MSC_VER >= 1500) // VS2008+
   1.475 +        #define OVR_NO_INLINE __declspec(noinline)
   1.476 +    #elif !defined(OVR_CC_MSVC)
   1.477 +        #define OVR_NO_INLINE __attribute__((noinline))
   1.478 +    #endif
   1.479 +#endif
   1.480 +
   1.481 +
   1.482 +// -----------------------------------------------------------------------------------
   1.483 +// ***** OVR_STRINGIZE
   1.484 +//
   1.485 +// Converts a preprocessor symbol to a string.
   1.486 +//
   1.487 +// Example usage:
   1.488 +//     printf("Line: %s", OVR_STRINGIZE(__LINE__));
   1.489 +//
   1.490 +#if !defined(OVR_STRINGIFY)
   1.491 +    #define OVR_STRINGIZEIMPL(x) #x
   1.492 +    #define OVR_STRINGIZE(x)     OVR_STRINGIZEIMPL(x)
   1.493 +#endif
   1.494 +
   1.495 +
   1.496 +// -----------------------------------------------------------------------------------
   1.497 +// ***** OVR_JOIN
   1.498 +//
   1.499 +// Joins two preprocessing symbols together. Supports the case when either or the
   1.500 +// the symbols are macros themselves.
   1.501 +//
   1.502 +// Example usage:
   1.503 +//    char OVR_JOIN(unique_, __LINE__);  // Results in (e.g.) char unique_123;
   1.504 +//
   1.505 +#if !defined(OVR_JOIN)
   1.506 +    #define OVR_JOIN(a, b)  OVR_JOIN1(a, b)
   1.507 +    #define OVR_JOIN1(a, b) OVR_JOIN2(a, b)
   1.508 +    #define OVR_JOIN2(a, b) a##b
   1.509 +#endif
   1.510 +
   1.511 +
   1.512 +//-----------------------------------------------------------------------------------
   1.513 +// ***** OVR_OFFSETOF
   1.514 +// 
   1.515 +// Portable implementation of offsetof for structs and classes. offsetof and GCC's 
   1.516 +// __builtin_offsetof work only with POD types (standard-layout types under C++11), 
   1.517 +// despite that it can safely work with a number of types that aren't POD. This 
   1.518 +// version works with more types without generating compiler warnings or errors.
   1.519 +// Returns the offset as a size_t, as per offsetof.
   1.520 +//
   1.521 +// Example usage:
   1.522 +//     struct Test{ int i; float f; };
   1.523 +//     size_t fPos = OVR_OFFSETOF(Test, f);
   1.524 +
   1.525 +#if defined(OVR_CC_GNU)
   1.526 +    #define OVR_OFFSETOF(class_, member_) ((size_t)(((uintptr_t)&reinterpret_cast<const volatile char&>((((class_*)65536)->member_))) - 65536))
   1.527 +#else
   1.528 +    #define OVR_OFFSETOF(class_, member_) offsetof(class_, member_)
   1.529 +#endif
   1.530 +
   1.531 +
   1.532 +//-----------------------------------------------------------------------------------
   1.533 +// ***** OVR_SIZEOF_MEMBER
   1.534 +//
   1.535 +// Implements a portable way to determine the size of struct or class data member. 
   1.536 +// C++11 allows this directly via sizeof (see OVR_CPP_NO_EXTENDED_SIZEOF), and this 
   1.537 +// macro exists to handle pre-C++11 compilers.
   1.538 +// Returns the offset as a size_t, as per sizeof.
   1.539 +//
   1.540 +// Example usage:
   1.541 +//     struct Test{ int i; float f; };
   1.542 +//     size_t fSize = OVR_SIZEOF_MEMBER(Test, f);
   1.543 +//
   1.544 +#if defined(OVR_CPP_NO_EXTENDED_SIZEOF)
   1.545 +    #define OVR_SIZEOF_MEMBER(class_, member_) (sizeof(((class_*)0)->member_))
   1.546 +#else
   1.547 +    #define OVR_SIZEOF_MEMBER(class_, member_) (sizeof(class_::member_))
   1.548 +#endif
   1.549 +
   1.550 +
   1.551 +//-----------------------------------------------------------------------------------
   1.552 +// ***** OVR_DEBUG_BREAK, OVR_DEBUG_CODE, 
   1.553 +//       OVR_ASSERT, OVR_ASSERT_M, OVR_ASSERT_AND_UNUSED
   1.554 +//
   1.555 +// Macros have effect only in debug builds.
   1.556 +//
   1.557 +// Example OVR_DEBUG_BREAK usage (note the lack of parentheses):
   1.558 +//     #define MY_ASSERT(expression) do { if (!(expression)) { OVR_DEBUG_BREAK; } } while(0)
   1.559 +//
   1.560 +// Example OVR_DEBUG_CODE usage:
   1.561 +//     OVR_DEBUG_CODE(printf("debug test\n");)
   1.562 +//       or
   1.563 +//     OVR_DEBUG_CODE(printf("debug test\n"));
   1.564 +//
   1.565 +// Example OVR_ASSERT usage:
   1.566 +//     OVR_ASSERT(count < 100);
   1.567 +//     OVR_ASSERT_M(count < 100, "count is too high");
   1.568 +//
   1.569 +#if defined(OVR_BUILD_DEBUG)
   1.570 +	// Causes a debugger breakpoint in debug builds. Has no effect in release builds.
   1.571 +	// Microsoft Win32 specific debugging support
   1.572 +	#if defined(OVR_CC_MSVC)
   1.573 +		#define OVR_DEBUG_BREAK __debugbreak()
   1.574 +	#elif defined(OVR_CC_GNU) || defined(OVR_CC_CLANG)
   1.575 +		#if defined(OVR_CPU_X86) || defined(OVR_CPU_X86_64)
   1.576 +			#define OVR_DEBUG_BREAK do { OVR_ASM("int $3\n\t"); } while(0)
   1.577 +		#else
   1.578 +			#define OVR_DEBUG_BREAK __builtin_trap()
   1.579 +		#endif
   1.580 +	#else
   1.581 +		#define OVR_DEBUG_BREAK do { *((int *) 0) = 1; } while(0)
   1.582 +	#endif
   1.583 +
   1.584 +	// The expresssion is defined only in debug builds. It is defined away in release builds.
   1.585 +	#define OVR_DEBUG_CODE(c) c
   1.586 +
   1.587 +	// In debug builds this tests the given expression; if false then executes OVR_DEBUG_BREAK,
   1.588 +	// if true then no action. Has no effect in release builds.
   1.589 +	#if defined(__clang_analyzer__) // During static analysis, make it so the analyzer thinks that failed asserts result in program exit. Reduced false positives.
   1.590 +		#include <stdlib.h>
   1.591 +		#define OVR_ASSERT_M(p, message) do { if (!(p))  { OVR_DEBUG_BREAK; exit(0); } } while(0)
   1.592 +		#define OVR_ASSERT(p)            do { if (!(p))  { OVR_DEBUG_BREAK; exit(0); } } while(0)
   1.593 +	#else
   1.594 +		// void OVR_ASSERT_M(bool expression, const char message);
   1.595 +		// Note: The expresion below is expanded into all usage of this assertion macro. 
   1.596 +		// We should try to minimize the size of the expanded code to the extent possible.
   1.597 +		#define OVR_ASSERT_M(p, message) do                                                               \
   1.598 +		{                                                                                                 \
   1.599 +			if (!(p))                                                                                     \
   1.600 +			{                                                                                             \
   1.601 +				intptr_t ovrAssertUserParam;                                                              \
   1.602 +				OVRAssertionHandler ovrAssertUserHandler = OVR::GetAssertionHandler(&ovrAssertUserParam); \
   1.603 +																							              \
   1.604 +				if(ovrAssertUserHandler && !OVRIsDebuggerPresent())                                       \
   1.605 +				{                                                                                         \
   1.606 +					ovrAssertUserHandler(ovrAssertUserParam, "Assertion failure", message);               \
   1.607 +				}                                                                                         \
   1.608 +				else                                                                                      \
   1.609 +				{                                                                                         \
   1.610 +					OVR_DEBUG_BREAK;                                                                      \
   1.611 +				}                                                                                         \
   1.612 +			}                                                                                             \
   1.613 +		} while(0)
   1.614 +
   1.615 +		// void OVR_ASSERT(bool expression);
   1.616 +		#define OVR_ASSERT(p) OVR_ASSERT_M((p), (#p))
   1.617 +	#endif
   1.618 +
   1.619 +	// Acts the same as OVR_ASSERT in debug builds. Acts the same as OVR_UNUSED in release builds.
   1.620 +	// Example usage: OVR_ASSERT_AND_UNUSED(x < 30, x);
   1.621 +	#define OVR_ASSERT_AND_UNUSED(expression, value) OVR_ASSERT(expression); OVR_UNUSED(value)
   1.622 +
   1.623 +#else 
   1.624 +
   1.625 +	// The expresssion is defined only in debug builds. It is defined away in release builds.
   1.626 +	#define OVR_DEBUG_CODE(c)
   1.627 +
   1.628 +	// Causes a debugger breakpoint in debug builds. Has no effect in release builds.
   1.629 +	#define OVR_DEBUG_BREAK  ((void)0)
   1.630 +
   1.631 +	// In debug builds this tests the given expression; if false then executes OVR_DEBUG_BREAK,
   1.632 +	// if true then no action. Has no effect in release builds.
   1.633 +	#define OVR_ASSERT(p)      ((void)0)
   1.634 +	#define OVR_ASSERT_M(p, m) ((void)0)
   1.635 +
   1.636 +	// Acts the same as OVR_ASSERT in debug builds. Acts the same as OVR_UNUSED in release builds.
   1.637 +	// Example usage: OVR_ASSERT_AND_UNUSED(x < 30, x);
   1.638 +	#define OVR_ASSERT_AND_UNUSED(expression, value) OVR_UNUSED(value)
   1.639 +
   1.640 +#endif // OVR_BUILD_DEBUG
   1.641 +
   1.642 +
   1.643 +
   1.644 +// Assert handler
   1.645 +// The user of this library can override the default assertion handler and provide their own.
   1.646 +namespace OVR
   1.647 +{
   1.648 +    // The return value meaning is reserved for future definition and currently has no effect.
   1.649 +    typedef intptr_t (*OVRAssertionHandler)(intptr_t userParameter, const char* title, const char* message);
   1.650 +
   1.651 +    // Returns the current assertion handler.
   1.652 +    OVRAssertionHandler GetAssertionHandler(intptr_t* userParameter = NULL);
   1.653 +
   1.654 +    // Sets the current assertion handler.
   1.655 +    // The default assertion handler if none is set simply issues a debug break.
   1.656 +    // Example usage:
   1.657 +    //     intptr_t CustomAssertionHandler(intptr_t /*userParameter*/, const char* title, const char* message)) { 
   1.658 +    //         MessageBox(title, message);
   1.659 +    //         OVR_DEBUG_BREAK;
   1.660 +    //     }
   1.661 +    void SetAssertionHandler(OVRAssertionHandler assertionHandler, intptr_t userParameter = 0);
   1.662 +
   1.663 +    // Implements the default assertion handler.
   1.664 +    intptr_t DefaultAssertionHandler(intptr_t userParameter, const char* title, const char* message);
   1.665 +
   1.666 +    // Currently defined in OVR_DebugHelp.cpp
   1.667 +    bool OVRIsDebuggerPresent();
   1.668 +}
   1.669 +
   1.670 +
   1.671 +// ------------------------------------------------------------------------
   1.672 +// ***** static_assert
   1.673 +//
   1.674 +// Portable support for C++11 static_assert.
   1.675 +// Acts as if the following were declared:
   1.676 +//     void static_assert(bool const_expression, const char* msg);
   1.677 +//
   1.678 +// Example usage:
   1.679 +//     static_assert(sizeof(int32_t) == 4, "int32_t expected to be 4 bytes.");
   1.680 +
   1.681 +#if defined(OVR_CPP_NO_STATIC_ASSERT) // If the compiler doesn't provide it intrinsically...
   1.682 +    #if !defined(OVR_SA_UNUSED)
   1.683 +        #if defined(OVR_CC_GNU) || defined(OVR_CC_CLANG)
   1.684 +            #define OVR_SA_UNUSED __attribute__((unused))
   1.685 +        #else
   1.686 +            #define OVR_SA_UNUSED
   1.687 +        #endif
   1.688 +        #define OVR_SA_PASTE(a,b) a##b
   1.689 +        #define OVR_SA_HELP(a,b)  OVR_SA_PASTE(a,b)
   1.690 +    #endif
   1.691 +
   1.692 +    #if defined(__COUNTER__)
   1.693 +        #define static_assert(expression, msg) typedef char OVR_SA_HELP(compileTimeAssert, __COUNTER__) [((expression) != 0) ? 1 : -1] OVR_SA_UNUSED
   1.694 +    #else
   1.695 +        #define static_assert(expression, msg) typedef char OVR_SA_HELP(compileTimeAssert, __LINE__) [((expression) != 0) ? 1 : -1] OVR_SA_UNUSED
   1.696 +    #endif
   1.697 +#endif
   1.698 +
   1.699 +
   1.700 +// ------------------------------------------------------------------------
   1.701 +// ***** OVR_COMPILER_ASSERT
   1.702 +//
   1.703 +// Compile-time assert; produces compiler error if condition is false.
   1.704 +// The expression must be a compile-time constant expression.
   1.705 +// This macro is deprecated in favor of static_assert, which provides better
   1.706 +// compiler output and works in a broader range of contexts.
   1.707 +// 
   1.708 +// Example usage:
   1.709 +//     OVR_COMPILER_ASSERT(sizeof(int32_t == 4));
   1.710 +
   1.711 +#if !defined(OVR_COMPILER_ASSERT)
   1.712 +    #define OVR_COMPILER_ASSERT(expression)        static_assert(expression, #expression)
   1.713 +    #define OVR_COMPILER_ASSERT_M(expression, msg) static_assert(expression, msg)
   1.714 +#endif
   1.715 +
   1.716 +
   1.717 +// ***** OVR_PROCESSOR_PAUSE
   1.718 +//
   1.719 +// Yields the processor for other hyperthreads, usually for the purpose of implementing spins and spin locks. 
   1.720 +//
   1.721 +// Example usage:
   1.722 +//     while(!finished())
   1.723 +//         OVR_PROCESSOR_PAUSE();
   1.724 +
   1.725 +#if defined(OVR_CPU_X86) || defined(OVR_CPU_X86_64)
   1.726 +    #if defined(OVR_CC_GNU) || defined(OVR_CC_CLANG)
   1.727 +        #define OVR_PROCESSOR_PAUSE() asm volatile("pause" ::: "memory") // Consumes 38-40 clocks on current Intel x86 and x64 hardware.
   1.728 +    #elif defined(OVR_CC_MSVC)
   1.729 +        #include <emmintrin.h>
   1.730 +        #pragma intrinsic(_mm_pause) // Maps to asm pause.
   1.731 +        #define OVR_PROCESSOR_PAUSE _mm_pause
   1.732 +    #else
   1.733 +        #define OVR_PROCESSOR_PAUSE()
   1.734 +    #endif
   1.735 +#else
   1.736 +    #define OVR_PROCESSOR_PAUSE()
   1.737 +#endif
   1.738 +
   1.739 +
   1.740 +// ------------------------------------------------------------------------
   1.741 +// ***** OVR_ARRAY_COUNT
   1.742 +//
   1.743 +// Returns the element count of a C array. 
   1.744 +//
   1.745 +// Example usage:
   1.746 +//     float itemArray[16];
   1.747 +//     for(size_t i = 0; i < OVR_ARRAY_COUNT(itemArray); i++) { ... }
   1.748 +
   1.749 +#if defined(OVR_CPP_NO_CONSTEXPR)
   1.750 +    #ifndef OVR_ARRAY_COUNT
   1.751 +        #define OVR_ARRAY_COUNT(x) (sizeof(x) / sizeof(x[0]))
   1.752 +    #endif
   1.753 +#else
   1.754 +    // Smarter C++11 version which knows the difference between arrays and pointers. 
   1.755 +    template <typename T, size_t N>
   1.756 +    char (&OVRArrayCountHelper(T (&x)[N]))[N];
   1.757 +    #define OVR_ARRAY_COUNT(x) (sizeof(OVRArrayCountHelper(x)))
   1.758 +#endif
   1.759 +
   1.760 +
   1.761 +// ------------------------------------------------------------------------
   1.762 +// ***** OVR_CURRENT_FUNCTION
   1.763 +//
   1.764 +// Portable wrapper for __PRETTY_FUNCTION__, C99 __func__, __FUNCTION__.
   1.765 +// This represents the most expressive version available.
   1.766 +// Acts as if the following were declared:
   1.767 +//     static const char OVR_CURRENT_FUNCTION[] = "function-name";
   1.768 +//
   1.769 +// Example usage:
   1.770 +//     void Test() { printf("%s", OVR_CURRENT_FUNCTION); }
   1.771 +
   1.772 +#if defined(OVR_CC_GNU) || defined(OVR_CC_CLANG) || (defined(__ICC) && (__ICC >= 600)) // GCC, clang, Intel
   1.773 +    #define OVR_CURRENT_FUNCTION __PRETTY_FUNCTION__
   1.774 +#elif defined(__FUNCSIG__) // VC++
   1.775 +    #define OVR_CURRENT_FUNCTION __FUNCSIG__
   1.776 +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) // C99 compilers
   1.777 +    #define OVR_CURRENT_FUNCTION __func__
   1.778 +#else
   1.779 +    #define OVR_CURRENT_FUNCTION __FUNCTION__
   1.780 +#endif
   1.781 +
   1.782 +
   1.783 +//-----------------------------------------------------------------------------------
   1.784 +// ***** OVR_DEPRECATED / OVR_DEPRECATED_MSG
   1.785 +// 
   1.786 +// Portably annotates a function or struct as deprecated.
   1.787 +// Note that clang supports __deprecated_enum_msg, which may be useful to support.
   1.788 +//
   1.789 +// Example usage:
   1.790 +//    OVR_DEPRECATED void Test();       // Use on the function declaration, as opposed to definition.
   1.791 +//
   1.792 +//    struct OVR_DEPRECATED Test{ ... };
   1.793 +//
   1.794 +//    OVR_DEPRECATED_MSG("Test is deprecated")
   1.795 +//    void Test();
   1.796 +
   1.797 +#if !defined(OVR_DEPRECATED)
   1.798 +    #if defined(OVR_CC_MSVC) && (OVR_CC_VERSION > 1400) // VS2005+
   1.799 +        #define OVR_DEPRECATED          __declspec(deprecated)
   1.800 +        #define OVR_DEPRECATED_MSG(msg) __declspec(deprecated(msg))
   1.801 +    #elif defined(OVR_CC_CLANG) && OVR_CC_HAS_FEATURE(attribute_deprecated_with_message)
   1.802 +        #define OVR_DEPRECATED          __declspec(deprecated)
   1.803 +        #define OVR_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
   1.804 +    #elif defined(OVR_CC_GNU) && (OVR_CC_VERSION >= 405)
   1.805 +        #define OVR_DEPRECATED          __declspec(deprecated)
   1.806 +        #define OVR_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
   1.807 +    #elif !defined(OVR_CC_MSVC)
   1.808 +        #define OVR_DEPRECATED          __attribute__((deprecated))
   1.809 +        #define OVR_DEPRECATED_MSG(msg) __attribute__((deprecated))
   1.810 +    #else
   1.811 +        #define OVR_DEPRECATED
   1.812 +        #define OVR_DEPRECATED_MSG(msg)
   1.813 +    #endif
   1.814 +#endif
   1.815 +
   1.816 +
   1.817 +//-----------------------------------------------------------------------------------
   1.818 +// ***** OVR_UNUSED - Unused Argument handling
   1.819 +// Macro to quiet compiler warnings about unused parameters/variables.
   1.820 +//
   1.821 +// Example usage:
   1.822 +//     void Test() {
   1.823 +//         int x = SomeFunction();
   1.824 +//         OVR_UNUSED(x);
   1.825 +//     }
   1.826 +//
   1.827 +
   1.828 +#if defined(OVR_CC_GNU)
   1.829 +#  define   OVR_UNUSED(a)   do {__typeof__ (&a) __attribute__ ((unused)) __tmp = &a; } while(0)
   1.830 +#else
   1.831 +#  define   OVR_UNUSED(a)   (a)
   1.832 +#endif
   1.833 +
   1.834 +#define     OVR_UNUSED1(a1) OVR_UNUSED(a1)
   1.835 +#define     OVR_UNUSED2(a1,a2) OVR_UNUSED(a1); OVR_UNUSED(a2)
   1.836 +#define     OVR_UNUSED3(a1,a2,a3) OVR_UNUSED2(a1,a2); OVR_UNUSED(a3)
   1.837 +#define     OVR_UNUSED4(a1,a2,a3,a4) OVR_UNUSED3(a1,a2,a3); OVR_UNUSED(a4)
   1.838 +#define     OVR_UNUSED5(a1,a2,a3,a4,a5) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED(a5)
   1.839 +#define     OVR_UNUSED6(a1,a2,a3,a4,a5,a6) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED2(a5,a6)
   1.840 +#define     OVR_UNUSED7(a1,a2,a3,a4,a5,a6,a7) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED3(a5,a6,a7)
   1.841 +#define     OVR_UNUSED8(a1,a2,a3,a4,a5,a6,a7,a8) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED4(a5,a6,a7,a8)
   1.842 +#define     OVR_UNUSED9(a1,a2,a3,a4,a5,a6,a7,a8,a9) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED5(a5,a6,a7,a8,a9)
   1.843 +
   1.844 +
   1.845 +//-----------------------------------------------------------------------------------
   1.846 +// ***** Configuration Macros
   1.847 +//
   1.848 +// Expands to the current build type as a const char string literal.
   1.849 +// Acts as the following declaration: const char OVR_BUILD_STRING[];
   1.850 +
   1.851 +#ifdef OVR_BUILD_DEBUG
   1.852 +#  define OVR_BUILD_STRING  "Debug"
   1.853 +#else
   1.854 +#  define OVR_BUILD_STRING  "Release"
   1.855 +#endif
   1.856 +
   1.857 +
   1.858 +//// Enables SF Debugging information
   1.859 +//# define OVR_BUILD_DEBUG
   1.860 +
   1.861 +// OVR_DEBUG_STATEMENT injects a statement only in debug builds.
   1.862 +// OVR_DEBUG_SELECT injects first argument in debug builds, second argument otherwise.
   1.863 +#ifdef OVR_BUILD_DEBUG
   1.864 +#define OVR_DEBUG_STATEMENT(s)   s
   1.865 +#define OVR_DEBUG_SELECT(d, nd)  d
   1.866 +#else
   1.867 +#define OVR_DEBUG_STATEMENT(s)
   1.868 +#define OVR_DEBUG_SELECT(d, nd)  nd
   1.869 +#endif
   1.870 +
   1.871 +
   1.872 +#define OVR_ENABLE_THREADS
   1.873 +//
   1.874 +// Prevents OVR from defining new within
   1.875 +// type macros, so developers can override
   1.876 +// new using the #define new new(...) trick
   1.877 +// - used with OVR_DEFINE_NEW macro
   1.878 +//# define OVR_BUILD_DEFINE_NEW
   1.879 +//
   1.880 +
   1.881 +
   1.882 +//-----------------------------------------------------------------------------------
   1.883 +// ***** Find normal allocations
   1.884 +//
   1.885 +// Our allocations are all supposed to go through the OVR System Allocator, so that
   1.886 +// they can be run through a game's own preferred allocator.  Occasionally we will
   1.887 +// accidentally introduce new code that doesn't adhere to this contract.  And it
   1.888 +// then becomes difficult to track down these normal allocations.  This piece of
   1.889 +// code makes it easy to check for normal allocations by asserting whenever they
   1.890 +// happen in our code.
   1.891 +
   1.892 +//#define OVR_FIND_NORMAL_ALLOCATIONS
   1.893 +#ifdef OVR_FIND_NORMAL_ALLOCATIONS
   1.894 +
   1.895 +inline void* operator new (size_t size, const char* filename, int line)
   1.896 +{
   1.897 +    void* ptr = new char[size];
   1.898 +    OVR_ASSERT(false);
   1.899 +    return ptr;
   1.900 +}
   1.901 +
   1.902 +#define new new(__FILE__, __LINE__)
   1.903 +
   1.904 +#endif // OVR_FIND_NORMAL_ALLOCATIONS
   1.905 +
   1.906 +
   1.907 +#include "OVR_Nullptr.h"
   1.908 +
   1.909 +
   1.910 +
   1.911 +
   1.912 +#endif  // OVR_Types_h