SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SL.h
Go to the documentation of this file.
1 /**
2  * \file sl/SL.h
3  * \date October 2015
4  * \authors Marcus Hudritsch
5  * \copyright http://opensource.org/licenses/GPL-3.0
6  * \remarks Please use clangformat to format the code. See more code style on
7  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
8  */
9 
10 #ifndef SL_H
11 #define SL_H
12 
13 //////////////////////////////////////////////////////////
14 // Preprocessor constant definitions used in the SLProject
15 //////////////////////////////////////////////////////////
16 
17 //-----------------------------------------------------------------------------
18 /* Determine one of the following operating systems:
19 SL_OS_MACOS :Apple Mac OSX
20 SL_OS_MACIOS :Apple iOS
21 SL_OS_WINDOWS :Microsoft desktop Windows XP, 7, 8, ...
22 SL_OS_ANDROID :Goggle Android
23 SL_OS_LINUX :Linux desktop OS
24 
25 With the OS definition the following constants are defined:
26 SL_GLES : Any version of OpenGL ES
27 SL_GLES3: Supports only OpenGL ES3
28 SL_USE_DISCARD_STEREOMODES: The discard stereo modes can be used (SLCamera)
29 */
30 
31 #ifdef __APPLE__
32 # include <TargetConditionals.h>
33 # if TARGET_OS_IOS
34 # define SL_OS_MACIOS
35 # define SL_GLES
36 # define SL_GLES3
37 # else
38 # define SL_OS_MACOS
39 # if defined(_DEBUG)
40 
41 # endif
42 # endif
43 #elif defined(ANDROID) || defined(ANDROID_NDK)
44 # define SL_OS_ANDROID
45 # define SL_GLES
46 # define SL_GLES3
47 #elif defined(_WIN32)
48 # define SL_OS_WINDOWS
49 # define SL_USE_DISCARD_STEREOMODES
50 # ifdef _DEBUG
51 # define _GLDEBUG
52 # endif
53 # define STDCALL __stdcall
54 #elif defined(linux) || defined(__linux) || defined(__linux__)
55 # define SL_OS_LINUX
56 # define SL_USE_DISCARD_STEREOMODES
57 # ifdef _DEBUG
58 # endif
59 #elif defined(__EMSCRIPTEN__)
60 # define SL_EMSCRIPTEN
61 # define SL_USE_DISCARD_STEREOMODES
62 # define SL_GLES
63 # define SL_GLES3
64 #else
65 # error "SL has not been ported to this OS"
66 #endif
67 
68 //-----------------------------------------------------------------------------
69 /* With one of the following constants the GUI system must be defined. This
70 has to be done in the project settings (pro files for QtCreator or in the
71 Visual Studio project settings):
72 
73 SL_GUI_QT :Qt on OSX, Windows, Linux or Android
74 SL_GUI_OBJC :ObjectiveC on iOS
75 SL_GUI_GLFW :GLFW on OSX, Windows or Linux
76 SL_GUI_JAVA :Java on Android (with the VS-Android project)
77 */
78 
79 //-----------------------------------------------------------------------------
80 #if defined(SL_OS_MACIOS)
81 # include <chrono>
82 # include <functional>
83 # include <random>
84 # include <sys/time.h>
85 # include <thread>
86 # include <CoreServices/CoreServices.h> // for system info
87 # include <zlib.h>
88 #elif defined(SL_OS_MACOS)
89 # include <chrono>
90 # include <functional>
91 # include <random>
92 # include <ctime>
93 # include <thread>
94 //# include <CoreServices/CoreServices.h> // for system info
95 # include <sys/sysctl.h> // for system info
96 #elif defined(SL_OS_ANDROID)
97 # include <sys/time.h>
98 # include <sys/system_properties.h>
99 # include <chrono>
100 # include <functional>
101 # include <random>
102 # include <sstream>
103 # include <thread>
104 #elif defined(SL_OS_WINDOWS)
105 # include <chrono>
106 # include <functional>
107 # include <random>
108 # include <thread>
109 # include <windows.h>
110 #elif defined(SL_OS_LINUX)
111 # include <chrono>
112 # include <functional>
113 # include <random>
114 # include <sstream>
115 # include <sys/time.h>
116 # include <thread>
117 #elif defined(SL_EMSCRIPTEN)
118 # include <random>
119 #else
120 # error "SL has not been ported to this OS"
121 #endif
122 
123 #include <Utils.h>
124 
125 //-----------------------------------------------------------------------------
126 using std::string;
127 using std::vector;
128 
129 //-----------------------------------------------------------------------------
130 // Determine compiler
131 #if defined(__GNUC__)
132 # undef _MSC_VER
133 #endif
134 
135 #if defined(_MSC_VER)
136 # define SL_COMP_MSVC
137 # define SL_STDCALL __stdcall
138 # define SL_DEPRECATED __declspec(deprecated)
139 # define _CRT_SECURE_NO_DEPRECATE // visual 8 secure crt warning
140 #elif defined(__BORLANDC__)
141 # define SL_COMP_BORLANDC
142 # define SL_STDCALL Stdcall
143 # define SL_DEPRECATED // @todo Does this compiler support deprecated attributes
144 #elif defined(__INTEL_COMPILER)
145 # define SL_COMP_INTEL
146 # define SL_STDCALL Stdcall
147 # define SL_DEPRECATED // @todo does this compiler support deprecated attributes
148 #elif defined(__GNUC__)
149 # define SL_COMP_GNUC
150 # define SL_STDCALL
151 # define SL_DEPRECATED __attribute__((deprecated))
152 #else
153 # error "SL has not been ported to this compiler"
154 #endif
155 
156 //-----------------------------------------------------------------------------
157 // Redefinition of standard types for platform independence
158 typedef string SLstring;
159 #ifndef SL_OS_ANDROID
160 typedef std::wstring SLwstring;
161 #endif
162 typedef char SLchar; // analog to GLchar (char is signed [-128 ... 127]!)
163 typedef unsigned char SLuchar; // analog to GLuchar
164 typedef signed long SLlong; // analog to GLlong
165 typedef unsigned long SLulong; // analog to GLulong
166 typedef signed char SLbyte; // analog to GLbyte
167 typedef unsigned char SLubyte; // analog to GLubyte
168 typedef short SLshort; // analog to GLshort
169 typedef unsigned short SLushort; // analog to GLushort
170 typedef int SLint; // analog to GLint
171 typedef unsigned int SLuint; // analog to GLuint
172 typedef int SLsizei; // analog to GLsizei
173 typedef float SLfloat; // analog to GLfloat
174 typedef double SLdouble; // analog to GLdouble
175 typedef bool SLbool; // analog to GLbool
176 typedef unsigned int SLenum; // analog to GLenum
177 typedef unsigned int SLbitfield; // analog to GLbitfield
178 
179 typedef int8_t SLint8;
180 typedef uint8_t SLuint8;
181 typedef int16_t SLint16;
182 typedef uint16_t SLuint16;
183 typedef int32_t SLint32;
184 typedef uint32_t SLuint32;
185 typedef int64_t SLint64;
186 typedef uint64_t SLuint64;
187 
188 // All 1D vectors begin with SLV*
189 typedef vector<SLbool> SLVbool;
190 typedef vector<SLbyte> SLVbyte;
191 typedef vector<SLubyte> SLVubyte;
192 typedef vector<SLchar> SLVchar;
193 typedef vector<SLuchar> SLVuchar;
194 typedef vector<SLshort> SLVshort;
195 typedef vector<SLushort> SLVushort;
196 typedef vector<SLint> SLVint;
197 typedef vector<SLuint> SLVuint;
198 typedef vector<SLlong> SLVlong;
199 typedef vector<SLulong> SLVulong;
200 typedef vector<SLfloat> SLVfloat;
201 typedef vector<SLstring> SLVstring;
202 typedef vector<size_t> SLVsize_t;
203 
204 // All 2D vectors begin with SLVV*
205 typedef vector<vector<SLfloat>> SLVVfloat;
206 typedef vector<vector<SLuchar>> SLVVuchar;
207 typedef vector<vector<SLushort>> SLVVushort;
208 typedef vector<vector<SLuint>> SLVVuint;
209 typedef vector<vector<SLchar>> SLVVchar;
210 typedef vector<vector<SLshort>> SLVVshort;
211 typedef vector<vector<SLint>> SLVVint;
212 
213 //-----------------------------------------------------------------------------
214 // Shortcut for size of a vector
215 template<class T>
216 inline SLuint
217 SL_sizeOfVector(const T& vector)
218 {
219  return (SLint)(vector.capacity() * sizeof(typename T::value_type));
220 }
221 //-----------------------------------------------------------------------------
222 // Bit manipulation macros for ones that forget it always
223 #define SL_GETBIT(VAR, VAL) VAR& VAL
224 #define SL_SETBIT(VAR, VAL) VAR |= VAL
225 #define SL_DELBIT(VAR, VAL) VAR &= ~VAL
226 #define SL_TOGBIT(VAR, VAL) if ((VAR) & (VAL)) (VAR) &= ~(VAL); else (VAR) |= VAL
227 //-----------------------------------------------------------------------------
228 // Prevention for warnings in XCode
229 #define UNUSED_PARAMETER(r) ((void)(x))
230 
231 //-----------------------------------------------------------------------------
232 // Some debugging and error handling macros
233 #define SL_LOG(...) Utils::log("SLProject", __VA_ARGS__)
234 #if _DEBUG
235 #define SL_LOG_DEBUG(...) Utils::log("SLProject", __VA_ARGS__)
236 #else
237 #define SL_LOG_DEBUG(...) {}
238 #endif
239 
240 #define SL_EXIT_MSG(message) Utils::exitMsg("SLProject", (message), __LINE__, __FILE__)
241 #define SL_WARN_MSG(message) Utils::warnMsg("SLProject", (message), __LINE__, __FILE__)
242 //-----------------------------------------------------------------------------
243 #endif
float SLfloat
Definition: SL.h:173
unsigned int SLenum
Definition: SL.h:176
vector< vector< SLuint > > SLVVuint
Definition: SL.h:208
vector< SLlong > SLVlong
Definition: SL.h:198
vector< SLubyte > SLVubyte
Definition: SL.h:191
unsigned int SLbitfield
Definition: SL.h:177
uint64_t SLuint64
Definition: SL.h:186
unsigned long SLulong
Definition: SL.h:165
vector< vector< SLchar > > SLVVchar
Definition: SL.h:209
vector< vector< SLshort > > SLVVshort
Definition: SL.h:210
unsigned int SLuint
Definition: SL.h:171
int8_t SLint8
Definition: SL.h:179
char SLchar
Definition: SL.h:162
vector< size_t > SLVsize_t
Definition: SL.h:202
unsigned char SLuchar
Definition: SL.h:163
double SLdouble
Definition: SL.h:174
vector< SLuchar > SLVuchar
Definition: SL.h:193
vector< SLshort > SLVshort
Definition: SL.h:194
int64_t SLint64
Definition: SL.h:185
vector< vector< SLushort > > SLVVushort
Definition: SL.h:207
int32_t SLint32
Definition: SL.h:183
vector< SLint > SLVint
Definition: SL.h:196
bool SLbool
Definition: SL.h:175
unsigned short SLushort
Definition: SL.h:169
unsigned char SLubyte
Definition: SL.h:167
vector< SLfloat > SLVfloat
Definition: SL.h:200
vector< SLstring > SLVstring
Definition: SL.h:201
uint16_t SLuint16
Definition: SL.h:182
vector< SLbool > SLVbool
Definition: SL.h:189
signed long SLlong
Definition: SL.h:164
vector< vector< SLint > > SLVVint
Definition: SL.h:211
vector< vector< SLfloat > > SLVVfloat
Definition: SL.h:205
short SLshort
Definition: SL.h:168
vector< SLulong > SLVulong
Definition: SL.h:199
signed char SLbyte
Definition: SL.h:166
int16_t SLint16
Definition: SL.h:181
vector< SLushort > SLVushort
Definition: SL.h:195
vector< SLbyte > SLVbyte
Definition: SL.h:190
uint8_t SLuint8
Definition: SL.h:180
std::wstring SLwstring
Definition: SL.h:160
int SLsizei
Definition: SL.h:172
vector< SLchar > SLVchar
Definition: SL.h:192
SLuint SL_sizeOfVector(const T &vector)
Definition: SL.h:217
vector< SLuint > SLVuint
Definition: SL.h:197
vector< vector< SLuchar > > SLVVuchar
Definition: SL.h:206
string SLstring
Definition: SL.h:158
uint32_t SLuint32
Definition: SL.h:184
int SLint
Definition: SL.h:170