naev 0.12.6
khrplatform.h
1// clang-format off
2#ifndef __khrplatform_h_
3#define __khrplatform_h_
4
5/*
6** Copyright (c) 2008-2018 The Khronos Group Inc.
7**
8** Permission is hereby granted, free of charge, to any person obtaining a
9** copy of this software and/or associated documentation files (the
10** "Materials"), to deal in the Materials without restriction, including
11** without limitation the rights to use, copy, modify, merge, publish,
12** distribute, sublicense, and/or sell copies of the Materials, and to
13** permit persons to whom the Materials are furnished to do so, subject to
14** the following conditions:
15**
16** The above copyright notice and this permission notice shall be included
17** in all copies or substantial portions of the Materials.
18**
19** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
26*/
27
28/* Khronos platform-specific types and definitions.
29 *
30 * The master copy of khrplatform.h is maintained in the Khronos EGL
31 * Registry repository at https://github.com/KhronosGroup/EGL-Registry
32 * The last semantic modification to khrplatform.h was at commit ID:
33 * 67a3e0864c2d75ea5287b9f3d2eb74a745936692
34 *
35 * Adopters may modify this file to suit their platform. Adopters are
36 * encouraged to submit platform specific modifications to the Khronos
37 * group so that they can be included in future versions of this file.
38 * Please submit changes by filing pull requests or issues on
39 * the EGL Registry repository linked above.
40 *
41 *
42 * See the Implementer's Guidelines for information about where this file
43 * should be located on your system and for more details of its use:
44 * http://www.khronos.org/registry/implementers_guide.pdf
45 *
46 * This file should be included as
47 * #include <KHR/khrplatform.h>
48 * by Khronos client API header files that use its types and defines.
49 *
50 * The types in khrplatform.h should only be used to define API-specific types.
51 *
52 * Types defined in khrplatform.h:
53 * khronos_int8_t signed 8 bit
54 * khronos_uint8_t unsigned 8 bit
55 * khronos_int16_t signed 16 bit
56 * khronos_uint16_t unsigned 16 bit
57 * khronos_int32_t signed 32 bit
58 * khronos_uint32_t unsigned 32 bit
59 * khronos_int64_t signed 64 bit
60 * khronos_uint64_t unsigned 64 bit
61 * khronos_intptr_t signed same number of bits as a pointer
62 * khronos_uintptr_t unsigned same number of bits as a pointer
63 * khronos_ssize_t signed size
64 * khronos_usize_t unsigned size
65 * khronos_float_t signed 32 bit floating point
66 * khronos_time_ns_t unsigned 64 bit time in nanoseconds
67 * khronos_utime_nanoseconds_t unsigned time interval or absolute time in
68 * nanoseconds
69 * khronos_stime_nanoseconds_t signed time interval in nanoseconds
70 * khronos_boolean_enum_t enumerated boolean type. This should
71 * only be used as a base type when a client API's boolean type is
72 * an enum. Client APIs which use an integer or other type for
73 * booleans cannot use this as the base type for their boolean.
74 *
75 * Tokens defined in khrplatform.h:
76 *
77 * KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
78 *
79 * KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
80 * KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
81 *
82 * Calling convention macros defined in this file:
83 * KHRONOS_APICALL
84 * KHRONOS_APIENTRY
85 * KHRONOS_APIATTRIBUTES
86 *
87 * These may be used in function prototypes as:
88 *
89 * KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
90 * int arg1,
91 * int arg2) KHRONOS_APIATTRIBUTES;
92 */
93
94#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
95# define KHRONOS_STATIC 1
96#endif
97
98/*-------------------------------------------------------------------------
99 * Definition of KHRONOS_APICALL
100 *-------------------------------------------------------------------------
101 * This precedes the return type of the function in the function prototype.
102 */
103#if defined(KHRONOS_STATIC)
104 /* If the preprocessor constant KHRONOS_STATIC is defined, make the
105 * header compatible with static linking. */
106# define KHRONOS_APICALL
107#elif defined(___WIN32__)
108# define KHRONOS_APICALL __declspec(dllimport)
109#elif defined (__SYMBIAN32__)
110# define KHRONOS_APICALL IMPORT_C
111#elif defined(__ANDROID__)
112# define KHRONOS_APICALL __attribute__((visibility("default")))
113#else
114# define KHRONOS_APICALL
115#endif
116
117/*-------------------------------------------------------------------------
118 * Definition of KHRONOS_APIENTRY
119 *-------------------------------------------------------------------------
120 * This follows the return type of the function and precedes the function
121 * name in the function prototype.
122 */
123#if defined(___WIN32__) && !defined(___WIN32___WCE) && !defined(__SCITECH_SNAP__)
124 /* Win32 but not WinCE */
125# define KHRONOS_APIENTRY __stdcall
126#else
127# define KHRONOS_APIENTRY
128#endif
129
130/*-------------------------------------------------------------------------
131 * Definition of KHRONOS_APIATTRIBUTES
132 *-------------------------------------------------------------------------
133 * This follows the closing parenthesis of the function prototype arguments.
134 */
135#if defined (__ARMCC_2__)
136#define KHRONOS_APIATTRIBUTES __softfp
137#else
138#define KHRONOS_APIATTRIBUTES
139#endif
140
141/*-------------------------------------------------------------------------
142 * basic type definitions
143 *-----------------------------------------------------------------------*/
144#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || defined(__SCO__) || defined(__USLC__)
145
146
147/*
148 * Using <stdint.h>
149 */
150#include <stdint.h>
151typedef int32_t khronos_int32_t;
152typedef uint32_t khronos_uint32_t;
153typedef int64_t khronos_int64_t;
154typedef uint64_t khronos_uint64_t;
155#define KHRONOS_SUPPORT_INT64 1
156#define KHRONOS_SUPPORT_FLOAT 1
157/*
158 * To support platform where unsigned long cannot be used interchangeably with
159 * inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
160 * Ideally, we could just use (u)intptr_t everywhere, but this could result in
161 * ABI breakage if khronos_uintptr_t is changed from unsigned long to
162 * unsigned long long or similar (this results in different C++ name mangling).
163 * To avoid changes for existing platforms, we restrict usage of intptr_t to
164 * platforms where the size of a pointer is larger than the size of long.
165 */
166#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
167#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
168#define KHRONOS_USE_INTPTR_T
169#endif
170#endif
171
172#elif defined(__VMS ) || defined(__sgi)
173
174/*
175 * Using <inttypes.h>
176 */
177#include <inttypes.h>
178typedef int32_t khronos_int32_t;
179typedef uint32_t khronos_uint32_t;
180typedef int64_t khronos_int64_t;
181typedef uint64_t khronos_uint64_t;
182#define KHRONOS_SUPPORT_INT64 1
183#define KHRONOS_SUPPORT_FLOAT 1
184
185#elif defined(___WIN32__) && !defined(__SCITECH_SNAP__)
186
187/*
188 * Win32
189 */
190typedef __int32 khronos_int32_t;
191typedef unsigned __int32 khronos_uint32_t;
192typedef __int64 khronos_int64_t;
193typedef unsigned __int64 khronos_uint64_t;
194#define KHRONOS_SUPPORT_INT64 1
195#define KHRONOS_SUPPORT_FLOAT 1
196
197#elif defined(__sun__) || defined(__digital__)
198
199/*
200 * Sun or Digital
201 */
202typedef int khronos_int32_t;
203typedef unsigned int khronos_uint32_t;
204#if defined(__arch64__) || defined(_LP64)
205typedef long int khronos_int64_t;
206typedef unsigned long int khronos_uint64_t;
207#else
208typedef long long int khronos_int64_t;
209typedef unsigned long long int khronos_uint64_t;
210#endif /* __arch64__ */
211#define KHRONOS_SUPPORT_INT64 1
212#define KHRONOS_SUPPORT_FLOAT 1
213
214#elif 0
215
216/*
217 * Hypothetical platform with no float or int64 support
218 */
219typedef int khronos_int32_t;
220typedef unsigned int khronos_uint32_t;
221#define KHRONOS_SUPPORT_INT64 0
222#define KHRONOS_SUPPORT_FLOAT 0
223
224#else
225
226/*
227 * Generic fallback
228 */
229#include <stdint.h>
230typedef int32_t khronos_int32_t;
231typedef uint32_t khronos_uint32_t;
232typedef int64_t khronos_int64_t;
233typedef uint64_t khronos_uint64_t;
234#define KHRONOS_SUPPORT_INT64 1
235#define KHRONOS_SUPPORT_FLOAT 1
236
237#endif
238
239
240/*
241 * Types that are (so far) the same on all platforms
242 */
243typedef signed char khronos_int8_t;
244typedef unsigned char khronos_uint8_t;
245typedef signed short int khronos_int16_t;
246typedef unsigned short int khronos_uint16_t;
247
248/*
249 * Types that differ between LLP64 and LP64 architectures - in LLP64,
250 * pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
251 * to be the only LLP64 architecture in current use.
252 */
253#ifdef KHRONOS_USE_INTPTR_T
254typedef intptr_t khronos_intptr_t;
255typedef uintptr_t khronos_uintptr_t;
256#elif defined(_WIN64)
257typedef signed long long int khronos_intptr_t;
258typedef unsigned long long int khronos_uintptr_t;
259#else
260typedef signed long int khronos_intptr_t;
261typedef unsigned long int khronos_uintptr_t;
262#endif
263
264#if defined(_WIN64)
265typedef signed long long int khronos_ssize_t;
266typedef unsigned long long int khronos_usize_t;
267#else
268typedef signed long int khronos_ssize_t;
269typedef unsigned long int khronos_usize_t;
270#endif
271
272#if KHRONOS_SUPPORT_FLOAT
273/*
274 * Float type
275 */
276typedef float khronos_float_t;
277#endif
278
279#if KHRONOS_SUPPORT_INT64
280/* Time types
281 *
282 * These types can be used to represent a time interval in nanoseconds or
283 * an absolute Unadjusted System Time. Unadjusted System Time is the number
284 * of nanoseconds since some arbitrary system event (e.g. since the last
285 * time the system booted). The Unadjusted System Time is an unsigned
286 * 64 bit value that wraps back to 0 every 584 years. Time intervals
287 * may be either signed or unsigned.
288 */
289typedef khronos_uint64_t khronos_utime_nanoseconds_t;
290typedef khronos_int64_t khronos_stime_nanoseconds_t;
291#endif
292
293/*
294 * Dummy value used to pad enum types to 32 bits.
295 */
296#ifndef KHRONOS_MAX_ENUM
297#define KHRONOS_MAX_ENUM 0x7FFFFFFF
298#endif
299
300/*
301 * Enumerated boolean type
302 *
303 * Values other than zero should be considered to be true. Therefore
304 * comparisons should not be made against KHRONOS_TRUE.
305 */
306typedef enum {
307 KHRONOS_FALSE = 0,
308 KHRONOS_TRUE = 1,
309 KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
310} khronos_boolean_enum_t;
311
312#endif /* __khrplatform_h_ */