oculus1

view libovr/Src/Kernel/OVR_Types.h @ 1:e2f9e4603129

added LibOVR and started a simple vr wrapper.
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Sep 2013 16:14:59 +0300
parents
children b069a5c27388
line source
1 /************************************************************************************
3 PublicHeader: OVR.h
4 Filename : OVR_Types.h
5 Content : Standard library defines and simple types
6 Created : September 19, 2012
7 Notes :
9 Copyright : Copyright 2012 Oculus VR, Inc. All Rights reserved.
11 Use of this software is subject to the terms of the Oculus license
12 agreement provided at the time of installation or download, or which
13 otherwise accompanies this software in either electronic or hard copy form.
15 ************************************************************************************/
17 #ifndef OVR_Types_H
18 #define OVR_Types_H
20 //-----------------------------------------------------------------------------------
21 // ****** Operating System
22 //
23 // Type definitions exist for the following operating systems: (OVR_OS_x)
24 //
25 // WIN32 - Win32 (Windows 95/98/ME and Windows NT/2000/XP)
26 // DARWIN - Darwin OS (Mac OS X)
27 // LINUX - Linux
28 // ANDROID - Android
29 // IPHONE - iPhone
31 #if (defined(__APPLE__) && (defined(__GNUC__) ||\
32 defined(__xlC__) || defined(__xlc__))) || defined(__MACOS__)
33 # if (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) || defined(__IPHONE_OS_VERSION_MIN_REQUIRED))
34 # define OVR_OS_IPHONE
35 # else
36 # define OVR_OS_DARWIN
37 # define OVR_OS_MAC
38 # endif
39 #elif (defined(WIN64) || defined(_WIN64) || defined(__WIN64__))
40 # define OVR_OS_WIN32
41 #elif (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__))
42 # define OVR_OS_WIN32
43 #elif defined(__linux__) || defined(__linux)
44 # define OVR_OS_LINUX
45 #else
46 # define OVR_OS_OTHER
47 #endif
49 #if defined(ANDROID)
50 # define OVR_OS_ANDROID
51 #endif
54 //-----------------------------------------------------------------------------------
55 // ***** CPU Architecture
56 //
57 // The following CPUs are defined: (OVR_CPU_x)
58 //
59 // X86 - x86 (IA-32)
60 // X86_64 - x86_64 (amd64)
61 // PPC - PowerPC
62 // PPC64 - PowerPC64
63 // MIPS - MIPS
64 // OTHER - CPU for which no special support is present or needed
67 #if defined(__x86_64__) || defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
68 # define OVR_CPU_X86_64
69 # define OVR_64BIT_POINTERS
70 #elif defined(__i386__) || defined(OVR_OS_WIN32)
71 # define OVR_CPU_X86
72 #elif defined(__powerpc64__)
73 # define OVR_CPU_PPC64
74 #elif defined(__ppc__)
75 # define OVR_CPU_PPC
76 #elif defined(__mips__) || defined(__MIPSEL__)
77 # define OVR_CPU_MIPS
78 #elif defined(__arm__)
79 # define OVR_CPU_ARM
80 #else
81 # define OVR_CPU_OTHER
82 #endif
84 //-----------------------------------------------------------------------------------
85 // ***** Co-Processor Architecture
86 //
87 // The following co-processors are defined: (OVR_CPU_x)
88 //
89 // SSE - Available on all modern x86 processors.
90 // Altivec - Available on all modern ppc processors.
91 // Neon - Available on some armv7+ processors.
93 #if defined(__SSE__) || defined(OVR_OS_WIN32)
94 # define OVR_CPU_SSE
95 #endif // __SSE__
97 #if defined( __ALTIVEC__ )
98 # define OVR_CPU_ALTIVEC
99 #endif // __ALTIVEC__
101 #if defined(__ARM_NEON__)
102 # define OVR_CPU_ARM_NEON
103 #endif // __ARM_NEON__
106 //-----------------------------------------------------------------------------------
107 // ***** Compiler
108 //
109 // The following compilers are defined: (OVR_CC_x)
110 //
111 // MSVC - Microsoft Visual C/C++
112 // INTEL - Intel C++ for Linux / Windows
113 // GNU - GNU C++
114 // ARM - ARM C/C++
116 #if defined(__INTEL_COMPILER)
117 // Intel 4.0 = 400
118 // Intel 5.0 = 500
119 // Intel 6.0 = 600
120 // Intel 8.0 = 800
121 // Intel 9.0 = 900
122 # define OVR_CC_INTEL __INTEL_COMPILER
124 #elif defined(_MSC_VER)
125 // MSVC 5.0 = 1100
126 // MSVC 6.0 = 1200
127 // MSVC 7.0 (VC2002) = 1300
128 // MSVC 7.1 (VC2003) = 1310
129 // MSVC 8.0 (VC2005) = 1400
130 // MSVC 9.0 (VC2008) = 1500
131 // MSVC 10.0 (VC2010) = 1600
132 # define OVR_CC_MSVC _MSC_VER
134 #elif defined(__GNUC__)
135 # define OVR_CC_GNU
137 #elif defined(__CC_ARM)
138 # define OVR_CC_ARM
140 #else
141 # error "Oculus does not support this Compiler"
142 #endif
145 //-----------------------------------------------------------------------------------
146 // ***** Compiler Warnings
148 // Disable MSVC warnings
149 #if defined(OVR_CC_MSVC)
150 # pragma warning(disable : 4127) // Inconsistent dll linkage
151 # pragma warning(disable : 4530) // Exception handling
152 # if (OVR_CC_MSVC<1300)
153 # pragma warning(disable : 4514) // Unreferenced inline function has been removed
154 # pragma warning(disable : 4710) // Function not inlined
155 # pragma warning(disable : 4714) // _force_inline not inlined
156 # pragma warning(disable : 4786) // Debug variable name longer than 255 chars
157 # endif // (OVR_CC_MSVC<1300)
158 #endif // (OVR_CC_MSVC)
162 // *** Linux Unicode - must come before Standard Includes
164 #ifdef OVR_OS_LINUX
165 // Use glibc unicode functions on linux.
166 # ifndef _GNU_SOURCE
167 # define _GNU_SOURCE
168 # endif
169 #endif
171 //-----------------------------------------------------------------------------------
172 // ***** Standard Includes
173 //
174 #include <stddef.h>
175 #include <limits.h>
176 #include <float.h>
179 // MSVC Based Memory Leak checking - for now
180 #if defined(OVR_CC_MSVC) && defined(OVR_BUILD_DEBUG)
181 # define _CRTDBG_MAP_ALLOC
182 # include <stdlib.h>
183 # include <crtdbg.h>
185 // Uncomment this to help debug memory leaks under Visual Studio in OVR apps only.
186 // This shouldn't be defined in customer releases.
187 # ifndef OVR_DEFINE_NEW
188 # define OVR_DEFINE_NEW new(__FILE__, __LINE__)
189 # define new OVR_DEFINE_NEW
190 # endif
192 #endif
195 //-----------------------------------------------------------------------------------
196 // ***** Type definitions for Common Systems
198 namespace OVR {
200 typedef char Char;
202 // Pointer-sized integer
203 typedef size_t UPInt;
204 typedef ptrdiff_t SPInt;
207 #if defined(OVR_OS_WIN32)
209 typedef char SByte; // 8 bit Integer (Byte)
210 typedef unsigned char UByte;
211 typedef short SInt16; // 16 bit Integer (Word)
212 typedef unsigned short UInt16;
213 typedef long SInt32; // 32 bit Integer
214 typedef unsigned long UInt32;
215 typedef __int64 SInt64; // 64 bit Integer (QWord)
216 typedef unsigned __int64 UInt64;
219 #elif defined(OVR_OS_MAC) || defined(OVR_OS_IPHONE) || defined(OVR_CC_GNU)
221 typedef int SByte __attribute__((__mode__ (__QI__)));
222 typedef unsigned int UByte __attribute__((__mode__ (__QI__)));
223 typedef int SInt16 __attribute__((__mode__ (__HI__)));
224 typedef unsigned int UInt16 __attribute__((__mode__ (__HI__)));
225 typedef int SInt32 __attribute__((__mode__ (__SI__)));
226 typedef unsigned int UInt32 __attribute__((__mode__ (__SI__)));
227 typedef int SInt64 __attribute__((__mode__ (__DI__)));
228 typedef unsigned int UInt64 __attribute__((__mode__ (__DI__)));
230 #else
232 #include <sys/types.h>
233 typedef int8_t SByte;
234 typedef uint8_t UByte;
235 typedef int16_t SInt16;
236 typedef uint16_t UInt16;
237 typedef int32_t SInt32;
238 typedef uint32_t UInt32;
239 typedef int64_t SInt64;
240 typedef uint64_t UInt64;
242 #endif
245 // ***** BaseTypes Namespace
247 // BaseTypes namespace is explicitly declared to allow base types to be used
248 // by customers directly without other contents of OVR namespace.
249 //
250 // Its is expected that GFx samples will declare 'using namespace OVR::BaseTypes'
251 // to allow using these directly without polluting the target scope with other
252 // OVR declarations, such as Ptr<>, String or Mutex.
253 namespace BaseTypes
254 {
255 using OVR::UPInt;
256 using OVR::SPInt;
257 using OVR::UByte;
258 using OVR::SByte;
259 using OVR::UInt16;
260 using OVR::SInt16;
261 using OVR::UInt32;
262 using OVR::SInt32;
263 using OVR::UInt64;
264 using OVR::SInt64;
265 } // OVR::BaseTypes
267 } // OVR
270 //-----------------------------------------------------------------------------------
271 // ***** Macro Definitions
272 //
273 // We define the following:
274 //
275 // OVR_BYTE_ORDER - Defined to either OVR_LITTLE_ENDIAN or OVR_BIG_ENDIAN
276 // OVR_FORCE_INLINE - Forces inline expansion of function
277 // OVR_ASM - Assembly language prefix
278 // OVR_STR - Prefixes string with L"" if building unicode
279 //
280 // OVR_STDCALL - Use stdcall calling convention (Pascal arg order)
281 // OVR_CDECL - Use cdecl calling convention (C argument order)
282 // OVR_FASTCALL - Use fastcall calling convention (registers)
283 //
285 // Byte order constants, OVR_BYTE_ORDER is defined to be one of these.
286 #define OVR_LITTLE_ENDIAN 1
287 #define OVR_BIG_ENDIAN 2
290 // Force inline substitute - goes before function declaration
291 #if defined(OVR_CC_MSVC)
292 # define OVR_FORCE_INLINE __forceinline
293 #elif defined(OVR_CC_GNU)
294 # define OVR_FORCE_INLINE __attribute__((always_inline)) inline
295 #else
296 # define OVR_FORCE_INLINE inline
297 #endif // OVR_CC_MSVC
300 #if defined(OVR_OS_WIN32)
302 // ***** Win32
304 // Byte order
305 #define OVR_BYTE_ORDER OVR_LITTLE_ENDIAN
307 // Calling convention - goes after function return type but before function name
308 #ifdef __cplusplus_cli
309 # define OVR_FASTCALL __stdcall
310 #else
311 # define OVR_FASTCALL __fastcall
312 #endif
314 #define OVR_STDCALL __stdcall
315 #define OVR_CDECL __cdecl
318 // Assembly macros
319 #if defined(OVR_CC_MSVC)
320 # define OVR_ASM _asm
321 #else
322 # define OVR_ASM asm
323 #endif // (OVR_CC_MSVC)
325 #ifdef UNICODE
326 # define OVR_STR(str) L##str
327 #else
328 # define OVR_STR(str) str
329 #endif // UNICODE
331 #else
333 // **** Standard systems
335 #if (defined(BYTE_ORDER) && (BYTE_ORDER == BIG_ENDIAN))|| \
336 (defined(_BYTE_ORDER) && (_BYTE_ORDER == _BIG_ENDIAN))
337 # define OVR_BYTE_ORDER OVR_BIG_ENDIAN
338 #elif (defined(__ARMEB__) || defined(OVR_CPU_PPC) || defined(OVR_CPU_PPC64))
339 # define OVR_BYTE_ORDER OVR_BIG_ENDIAN
340 #else
341 # define OVR_BYTE_ORDER OVR_LITTLE_ENDIAN
342 #endif
344 // Assembly macros
345 #define OVR_ASM __asm__
346 #define OVR_ASM_PROC(procname) OVR_ASM
347 #define OVR_ASM_END OVR_ASM
349 // Calling convention - goes after function return type but before function name
350 #define OVR_FASTCALL
351 #define OVR_STDCALL
352 #define OVR_CDECL
354 #endif // defined(OVR_OS_WIN32)
358 //-----------------------------------------------------------------------------------
359 // ***** OVR_DEBUG_BREAK, OVR_ASSERT
360 //
361 // If not in debug build, macros do nothing
362 #ifndef OVR_BUILD_DEBUG
364 # define OVR_DEBUG_BREAK ((void)0)
365 # define OVR_ASSERT(p) ((void)0)
367 #else
369 // Microsoft Win32 specific debugging support
370 #if defined(OVR_OS_WIN32)
371 # ifdef OVR_CPU_X86
372 # if defined(__cplusplus_cli)
373 # define OVR_DEBUG_BREAK do { __debugbreak(); } while(0)
374 # elif defined(OVR_CC_GNU)
375 # define OVR_DEBUG_BREAK do { OVR_ASM("int $3\n\t"); } while(0)
376 # else
377 # define OVR_DEBUG_BREAK do { OVR_ASM int 3 } while (0)
378 # endif
379 # else
380 # define OVR_DEBUG_BREAK do { __debugbreak(); } while(0)
381 # endif
382 // Unix specific debugging support
383 #elif defined(OVR_CPU_X86) || defined(OVR_CPU_X86_64)
384 # define OVR_DEBUG_BREAK do { OVR_ASM("int $3\n\t"); } while(0)
385 #else
386 # define OVR_DEBUG_BREAK do { *((int *) 0) = 1; } while(0)
387 #endif
389 // This will cause compiler breakpoint
390 #define OVR_ASSERT(p) do { if (!(p)) { OVR_DEBUG_BREAK; } } while(0)
392 #endif // OVR_BUILD_DEBUG
395 // Compile-time assert; produces compiler error if condition is false
396 #define OVR_COMPILER_ASSERT(x) { int zero = 0; switch(zero) {case 0: case x:;} }
400 //-----------------------------------------------------------------------------------
401 // ***** OVR_UNUSED - Unused Argument handling
403 // Macro to quiet compiler warnings about unused parameters/variables.
404 #if defined(OVR_CC_GNU)
405 # define OVR_UNUSED(a) do {__typeof__ (&a) __attribute__ ((unused)) __tmp = &a; } while(0)
406 #else
407 # define OVR_UNUSED(a) (a)
408 #endif
410 #define OVR_UNUSED1(a1) OVR_UNUSED(a1)
411 #define OVR_UNUSED2(a1,a2) OVR_UNUSED(a1); OVR_UNUSED(a2)
412 #define OVR_UNUSED3(a1,a2,a3) OVR_UNUSED2(a1,a2); OVR_UNUSED(a3)
413 #define OVR_UNUSED4(a1,a2,a3,a4) OVR_UNUSED3(a1,a2,a3); OVR_UNUSED(a4)
414 #define OVR_UNUSED5(a1,a2,a3,a4,a5) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED(a5)
415 #define OVR_UNUSED6(a1,a2,a3,a4,a5,a6) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED2(a5,a6)
416 #define OVR_UNUSED7(a1,a2,a3,a4,a5,a6,a7) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED3(a5,a6,a7)
417 #define OVR_UNUSED8(a1,a2,a3,a4,a5,a6,a7,a8) OVR_UNUSED4(a1,a2,a3,a4); OVR_UNUSED4(a5,a6,a7,a8)
418 #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)
421 //-----------------------------------------------------------------------------------
422 // ***** Configuration Macros
424 // SF Build type
425 #ifdef OVR_BUILD_DEBUG
426 # define OVR_BUILD_STRING "Debug"
427 #else
428 # define OVR_BUILD_STRING "Release"
429 #endif
432 //// Enables SF Debugging information
433 //# define OVR_BUILD_DEBUG
435 // OVR_DEBUG_STATEMENT injects a statement only in debug builds.
436 // OVR_DEBUG_SELECT injects first argument in debug builds, second argument otherwise.
437 #ifdef OVR_BUILD_DEBUG
438 #define OVR_DEBUG_STATEMENT(s) s
439 #define OVR_DEBUG_SELECT(d, nd) d
440 #else
441 #define OVR_DEBUG_STATEMENT(s)
442 #define OVR_DEBUG_SELECT(d, nd) nd
443 #endif
446 #define OVR_ENABLE_THREADS
447 //
448 // Prevents OVR from defining new within
449 // type macros, so developers can override
450 // new using the #define new new(...) trick
451 // - used with OVR_DEFINE_NEW macro
452 //# define OVR_BUILD_DEFINE_NEW
453 //
456 #endif // OVR_Types_h