GL Studio C++ Runtime API
gls_include.h
Go to the documentation of this file.
1/// \file gls_include.h
2/// \brief A file for all GL Studio files to include.
3///
4/// \par Copyright Information
5///
6/// Copyright (c) 2017 by The DiSTI Corporation.<br>
7/// 12249 Science Drive; Suite 300<br>
8/// Orlando, Florida 32826<br>
9/// USA<br>
10/// <br>
11/// All rights reserved.<br>
12///
13/// This Software contains proprietary trade secrets of DiSTI and may not be
14/// reproduced, in whole or part, in any form, or by any means of electronic,
15/// mechanical, or otherwise, without the written permission of DiSTI. Said
16/// permission may be derived through the purchase of applicable DiSTI product
17/// licenses which detail the distribution rights of this content and any
18/// Derivative Works based on this or other copyrighted DiSTI Software.
19///
20/// NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21/// AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22/// PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23/// AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24/// IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25/// PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26///
27/// LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28/// IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29/// INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30/// DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31/// INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32/// INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBILITY
33/// OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34/// EXCEED FIVE DOLLARS (US$5.00).
35///
36/// The aforementioned terms and restrictions are governed by the laws of the
37/// State of Florida and the United States of America.
38
39#ifndef INCLUDED_GLS_INCLUDE_H
40#define INCLUDED_GLS_INCLUDE_H
41
42/// Macro denoting which functions should be visible from the runtime library.
43#if defined( WIN32 ) && ( defined( GLS_DLL ) || defined( GLS_EXPORT_LIBRARY ) || defined( GLS_IMPORT_LIBRARY ) )
44# if defined( GLS_LIBRARY ) || defined( GLS_EXPORT_LIBRARY )
45# define GLS_EXPORT __declspec( dllexport )
46# else /* GLS_DLL || GLS_IMPORT_LIBRARY */
47# define GLS_EXPORT __declspec( dllimport )
48# endif /* GLS_LIBRARY */
49#else
50# define GLS_EXPORT
51#endif /* GLS_DLL && WIN32 */
52
53/// Macro denoting which functions should be visible from the editor.
54#if defined( WIN32 ) && ( defined( GLS_EXPORT_EDITOR ) || defined( GLS_IMPORT_EDITOR ) )
55# if defined( GLS_EXPORT_EDITOR )
56# define GLS_EDITOR __declspec( dllexport )
57# else
58# define GLS_EDITOR __declspec( dllimport )
59# endif /* GLS_EXPORT_EDITOR */
60#else
61# define GLS_EDITOR
62#endif
63
64/// Macro denoting which functions should be visible from packages.
65#if defined( WIN32 ) && ( defined( GLS_EXPORT_PACKAGES ) || defined( GLS_IMPORT_PACKAGES ) )
66# if defined( GLS_EXPORT_PACKAGES )
67# define GLS_EXPORT_PACKAGE __declspec( dllexport )
68# else
69# define GLS_EXPORT_PACKAGE __declspec( dllimport )
70# endif /* GLS_EXPORT_PACKAGES */
71#else
72# define GLS_EXPORT_PACKAGE
73#endif
74
75#if defined( GLS_EXPORT_EDITOR ) || defined( GLS_IMPORT_EDITOR )
76# define GLS_EDITOR_CODE
77#endif
78
79/// Macro to wrap code that should be present on Windows only.
80#ifdef WIN32
81# define IF_WIN32( win32 ) ( win32 )
82#else
83# define IF_WIN32( win32 )
84#endif
85
86/// Macro to wrap code specific to Windows, and an alternate implementation for other platforms.
87#ifdef WIN32
88# define IF_WIN32_ELSE( win32, notWin32 ) ( win32 )
89#else
90# define IF_WIN32_ELSE( win32, notWin32 ) ( notWin32 )
91#endif
92
93/// Macro to wrap code that should be present on all platforms except Windows.
94#ifdef WIN32
95# define IF_NOT_WIN32( notWin32 )
96#else
97# define IF_NOT_WIN32( notWin32 ) ( notWin32 )
98#endif
99
100/// Macro to wrap code that should be present on macOS only.
101#ifdef __APPLE__
102# define IF_APPLE( apple ) ( apple )
103#else
104# define IF_APPLE( apple )
105#endif
106
107/// Macro to wrap code specific to macOS, and an alternate implementation for other platforms.
108#ifdef __APPLE__
109# define IF_APPLE_ELSE( apple, notApple ) ( apple )
110#else
111# define IF_APPLE_ELSE( apple, notApple ) ( notApple )
112#endif
113
114/// Macro to wrap code that should be present on all platforms except macOS.
115#ifdef __APPLE__
116# define IF_NOT_APPLE( notApple )
117#else
118# define IF_NOT_APPLE( notApple ) ( notApple )
119#endif
120
121/// Macro to wrap code that should be present on Linux only.
122#ifdef LINUX
123# define IF_LINUX( linux ) ( linux )
124#else
125# define IF_LINUX( linux )
126#endif
127
128/// Macro to wrap code specific to Linux, and an alternate implementation for other platforms.
129#ifdef LINUX
130# define IF_LINUX_ELSE( linux, notLinux ) ( linux )
131#else
132# define IF_LINUX_ELSE( linux, notLinux ) ( notLinux )
133#endif
134
135/// Macro to wrap code that should be present on all platforms except Linux.
136#ifdef LINUX
137# define IF_NOT_LINUX( notLinux )
138#else
139# define IF_NOT_LINUX( notLinux ) ( notLinux )
140#endif
141
142/// Macro to wrap code that should only be present in ES.
143/// \code{.cpp}
144/// IF_GLES( SetShader() ); // Calls this function on OpenGL ES only.
145/// \endcode
146#ifdef GLES
147# define IF_GLES( esCode ) ( esCode )
148#else
149# define IF_GLES( esCode )
150#endif
151
152/// Macro to wrap code that should not be present in ES (Desktop).
153/// \code{.cpp}
154/// IF_NOT_GLES( DesktopFileChanged() ); // Calls this function on Desktop OpenGL only.
155/// \endcode
156#ifdef GLES
157# define IF_NOT_GLES( nonEsCode )
158#else
159# define IF_NOT_GLES( nonEsCode ) ( nonEsCode )
160#endif
161
162/// Macro to wrap code specific to ES, and an alternate implementation for Desktop.
163/// \code{.cpp}
164/// auto fov = IF_GLES_ELSE( esBufferFOV, desktopFOV ); // Selects an expression to be assigned to the variable fov.
165/// \endcode
166#ifdef GLES
167# define IF_GLES_ELSE( esCode, nonEsCode ) ( esCode )
168#else
169# define IF_GLES_ELSE( esCode, nonEsCode ) ( nonEsCode )
170#endif
171
172/// Macro to wrap a parameter type specific to ES, and an alternate type for Desktop.
173/// This is like IF_GLES_ELSE, but does not add parenthesis.
174/// \code{.cpp}
175/// void MyFunc( IF_GLES_ELSE_TYPE( float, double ) ); // Selects the function parameter's type.
176/// \endcode
177#ifdef GLES
178# define IF_GLES_ELSE_TYPE( esType, nonEsType ) esType
179#else
180# define IF_GLES_ELSE_TYPE( esType, nonEsType ) nonEsType
181#endif
182
183/// Macro to wrap code that should only be present in Debug builds.
184#ifdef NDEBUG
185# define IF_DEBUG( notRelease )
186#else
187# define IF_DEBUG( notRelease ) ( notRelease )
188#endif
189
190/// Macro to wrap code that should only be present in Release builds.
191#ifdef NDEBUG
192# define IF_RELEASE( release ) ( release )
193#else
194# define IF_RELEASE( release )
195#endif
196
197/// Macro to wrap code specific to Release builds, with alternative code for Debug.
198#ifdef NDEBUG
199# define IF_RELEASE_ELSE( release, notRelease ) ( release )
200#else
201# define IF_RELEASE_ELSE( release, notRelease ) ( notRelease )
202#endif
203
204/// Macro for checking bitness (safer macros borrowed from https://www.fluentcpp.com/2019/05/28/better-macros-better-flags/)
205#define DISTI_IS_BITNESS( X ) DISTI_IS_BITNESS_PRIVATE_DEFINITION_##X()
206
207/// Can specify bitness manually when porting, or rely on the automatic checks further down.
208#if defined( DISTI_BITNESS_IS_64 )
209# define DISTI_IS_BITNESS_PRIVATE_DEFINITION_64() 1
210# define DISTI_IS_BITNESS_PRIVATE_DEFINITION_32() 0
211#elif defined( DISTI_BITNESS_IS_32 )
212# define DISTI_IS_BITNESS_PRIVATE_DEFINITION_64() 0
213# define DISTI_IS_BITNESS_PRIVATE_DEFINITION_32() 1
214#else
215/// Bitness checks borrowed from https://stackoverflow.com/a/12338526/201787
216# if _WIN64 || ( __GNUC__ && ( __x86_64__ || __aarch64__ ) )
217# define DISTI_IS_BITNESS_PRIVATE_DEFINITION_64() 1
218# define DISTI_IS_BITNESS_PRIVATE_DEFINITION_32() 0
219# elif _WIN32 || __GNUC__
220# define DISTI_IS_BITNESS_PRIVATE_DEFINITION_64() 0
221# define DISTI_IS_BITNESS_PRIVATE_DEFINITION_32() 1
222# else
223# error "Unknown bitness!"
224# endif
225#endif
226#endif