]> git.cworth.org Git - vogl/blob - src/voglcore/vogl_core.h
Initial vogl checkin
[vogl] / src / voglcore / vogl_core.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
5  * All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23  * THE SOFTWARE.
24  *
25  **************************************************************************/
26
27 // File: vogl_core.h
28 #ifndef VOGL_CORE_H
29 #define VOGL_CORE_H
30 #pragma once
31
32 #include <inttypes.h>
33
34 #if defined(WIN32) && defined(_MSC_VER)
35 #pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union
36 #pragma warning(disable : 4127) // conditional expression is constant
37 #pragma warning(disable : 4793) // function compiled as native
38 #pragma warning(disable : 4324) // structure was padded due to __declspec(align())
39 #pragma warning(disable : 4100) // unreferenced formal parameter
40 #endif
41
42 #if defined(WIN32) && !defined(VOGL_ANSI_CPLUSPLUS)
43 #define VOGL_PLATFORM_PC 1
44 #define VOGL_USE_WIN32_API 1
45
46 // MSVC or MinGW, x86 or x64, Win32 API's for threading and Win32 Interlocked API's or GCC built-ins for atomic ops.
47 #ifdef NDEBUG
48 // Ensure checked iterators are disabled. Note: Be sure anything else that links against this lib also #define's this stuff, or remove this crap!
49 #define _SECURE_SCL 0
50 #define _HAS_ITERATOR_DEBUGGING 0
51 #endif
52 #ifndef _DLL
53 // If we're using the DLL form of the run-time libs, we're also going to be enabling exceptions because we'll be building CLR apps.
54 // Otherwise, we disable exceptions for a small speed boost.
55 #define _HAS_EXCEPTIONS 0
56 #endif
57 #define NOMINMAX
58
59 #if defined(__MINGW32__) || defined(__MINGW64__)
60 #define VOGL_USE_GCC_ATOMIC_BUILTINS 1
61 #else
62 #define VOGL_USE_WIN32_ATOMIC_FUNCTIONS 1
63 #endif
64
65 #if defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__)
66 #define VOGL_PLATFORM_PC_X64 1
67 #define VOGL_64BIT_POINTERS 1
68 #define VOGL_CPU_HAS_64BIT_REGISTERS 1
69 #define VOGL_LITTLE_ENDIAN_CPU 1
70 #else
71 #define VOGL_PLATFORM_PC_X86 1
72 #define VOGL_64BIT_POINTERS 0
73 #define VOGL_CPU_HAS_64BIT_REGISTERS 0
74 #define VOGL_LITTLE_ENDIAN_CPU 1
75 #endif
76
77 #define VOGL_USE_UNALIGNED_INT_LOADS 1
78 #define VOGL_RESTRICT __restrict
79 #define VOGL_FORCE_INLINE __forceinline
80 #define VOGL_SELECT_ANY __declspec(selectany)
81
82 #if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
83 #define VOGL_USE_MSVC_INTRINSICS 1
84 #endif
85
86 #define VOGL_STDCALL __stdcall
87 #define VOGL_MEMORY_IMPORT_BARRIER
88 #define VOGL_MEMORY_EXPORT_BARRIER
89
90 #define VOGL_FUNCTION_NAME __FUNCTION__
91
92 // for gcc/clang: string_index is the param index of the format string, 1 is the first param for static funcs, 2 for member funcs
93 // first_index is the first param to check, specify 0 to just check the format string for consistency
94 #define VOGL_ATTRIBUTE_PRINTF(string_index, first_index)
95
96 #define VOGL_NOTE_UNUSED(x) (void) x
97
98 #elif defined(__GNUC__) && !defined(VOGL_ANSI_CPLUSPLUS)
99 // GCC x86 or x64, pthreads for threading and GCC built-ins for atomic ops.
100 #define VOGL_PLATFORM_PC 1
101 #ifdef __linux
102 #define VOGL_USE_LINUX_API 1
103 #endif
104
105 #if defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__)
106 #define VOGL_PLATFORM_PC_X64 1
107 #define VOGL_64BIT_POINTERS 1
108 #define VOGL_CPU_HAS_64BIT_REGISTERS 1
109 #else
110 #define VOGL_PLATFORM_PC_X86 1
111 #define VOGL_64BIT_POINTERS 0
112 #define VOGL_CPU_HAS_64BIT_REGISTERS 0
113 #endif
114
115 #define VOGL_USE_UNALIGNED_INT_LOADS 1
116
117 #define VOGL_LITTLE_ENDIAN_CPU 1
118
119 #define VOGL_USE_PTHREADS_API 1
120 #define VOGL_USE_GCC_ATOMIC_BUILTINS 1
121
122 #define VOGL_RESTRICT
123
124 #ifdef __clang__
125 #include "../extlib/clang_warnings/clang_warnings.h"
126 // FIXME - clang interprets forceinline in a subtly different way vs. gcc/MSVS, which causes multiple func definitions
127 #define VOGL_FORCE_INLINE inline
128 #else
129 #define VOGL_FORCE_INLINE inline __attribute__((__always_inline__, __gnu_inline__))
130 #endif
131
132 #define VOGL_SELECT_ANY
133
134 #define VOGL_STDCALL
135 #define VOGL_MEMORY_IMPORT_BARRIER
136 #define VOGL_MEMORY_EXPORT_BARRIER
137
138 #define VOGL_FUNCTION_NAME __FUNCTION__
139
140 #define VOGL_ATTRIBUTE_PRINTF(string_index, first_index) __attribute__((format(printf, string_index, first_index)))
141
142 #define VOGL_NOTE_UNUSED(x) (void) x
143
144 #ifndef _LARGEFILE64_SOURCE
145 #define _LARGEFILE64_SOURCE 1
146 #endif
147
148 #ifndef D_FILE_OFFSET_BITS
149 #define _FILE_OFFSET_BITS 64
150 #endif
151 #else
152 // Vanilla ANSI-C/C++
153 // No threading support, unaligned loads are NOT okay.
154 #if defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__)
155 #define VOGL_64BIT_POINTERS 1
156 #define VOGL_CPU_HAS_64BIT_REGISTERS 1
157 #else
158 #define VOGL_64BIT_POINTERS 0
159 #define VOGL_CPU_HAS_64BIT_REGISTERS 0
160 #endif
161
162 #define VOGL_USE_UNALIGNED_INT_LOADS 0
163
164 #if __BIG_ENDIAN__
165 #define VOGL_BIG_ENDIAN_CPU 1
166 #else
167 #define VOGL_LITTLE_ENDIAN_CPU 1
168 #endif
169
170 #define VOGL_USE_GCC_ATOMIC_BUILTINS 0
171 #define VOGL_USE_WIN32_ATOMIC_FUNCTIONS 0
172
173 #define VOGL_RESTRICT
174 #define VOGL_FORCE_INLINE inline
175 #define VOGL_SELECT_ANY
176
177 #define VOGL_STDCALL
178 #define VOGL_MEMORY_IMPORT_BARRIER
179 #define VOGL_MEMORY_EXPORT_BARRIER
180
181 #define VOGL_FUNCTION_NAME __FUNCTION__
182
183 #define VOGL_ATTRIBUTE_PRINTF(string_index, first_index)
184
185 #define VOGL_NOTE_UNUSED(x) (void) x
186 #endif
187
188 #ifndef VOGL_ENABLE_ASSERTIONS_IN_ALL_BUILDS
189 #define VOGL_ENABLE_ASSERTIONS_IN_ALL_BUILDS 0
190 #endif
191
192 #include <stdlib.h>
193 #include <stdio.h>
194 #include <limits.h>
195 #include <math.h>
196 #include <stdarg.h>
197 #include <string.h>
198 #include <memory.h>
199 #include <limits.h>
200 #include <errno.h>
201 #include <stdint.h>
202
203 #include <locale>
204 #include <algorithm>
205 #include <limits>
206 #include <typeinfo>
207 #include <functional>
208 #include <iterator>
209
210 #ifdef min
211 #undef min
212 #endif
213
214 #ifdef max
215 #undef max
216 #endif
217
218 #define VOGL_FALSE (0)
219 #define VOGL_TRUE (1)
220 #define VOGL_MAX_PATH (260)
221
222 #define VOGL_NAMESPACE_BEGIN(x) \
223     namespace x                   \
224     {
225 #define VOGL_NAMESPACE_END(x) }
226
227 #if defined(_DEBUG) || defined(DEBUG)
228 #define VOGL_BUILD_DEBUG
229
230 #if defined(NDEBUG)
231 #error NDEBUG cannot be defined in VOGL_BUILD_DEBUG
232 #endif
233 #else
234 #define VOGL_BUILD_RELEASE
235
236 #ifndef NDEBUG
237 #define NDEBUG
238 #endif
239
240 #if defined(DEBUG) || defined(_DEBUG)
241 #error DEBUG and _DEBUG cannot be defined in VOGL_BUILD_RELEASE
242 #endif
243 #endif
244
245 #include "vogl_types.h"
246 #include "vogl_assert.h"
247 #include "vogl_platform.h"
248 #include "vogl_helpers.h"
249 #include "vogl_traits.h"
250 #include "vogl_mem.h"
251 #include "vogl_math.h"
252 #include "vogl_utils.h"
253 #include "vogl_hash.h"
254 #include "vogl_rand.h"
255 #include "vogl_introsort.h"
256 #include "vogl_vector.h"
257 #include "vogl_fixed_string.h"
258 #include "vogl_dynamic_string.h"
259 #include "vogl_timer.h"
260
261 #endif // VOGL_CORE_H