| 1 |
{ |
| 2 |
Copyright 2002-2023 Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in this distribution, for details about the copyright. |
| 8 |
|
| 9 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
---------------------------------------------------------------------------- |
| 14 |
} |
| 15 |
|
| 16 |
{ Common compiler defines and symbols. |
| 17 |
This is a central include file for Castle Game Engine. |
| 18 |
|
| 19 |
This file should be included in *all* Castle Game Engine units. |
| 20 |
It defines some symbols that are *not* always configured on FPC command-line |
| 21 |
or in LPK settings, because they cannot, e.g. "modeswitch advancedrecords". |
| 22 |
|
| 23 |
Note that some required compilation options are still set outside of this file: |
| 24 |
- For example optimization options can only be specified on the command-line |
| 25 |
(and they are important for a game engine). |
| 26 |
|
| 27 |
The proper compiler options to compile the engine are: |
| 28 |
- in the ../../castle-fpc.cfg configuration file (used also by fpmake |
| 29 |
compilation method), |
| 30 |
- and they are replicated in Lazarus packages compilation settings, |
| 31 |
- and are replicated once more in the castle-engine build tool code |
| 32 |
(toolcompile.pas). |
| 33 |
} |
| 34 |
|
| 35 |
{$ifndef CASTLE_CONF_INCLUDED} |
| 36 |
{$define CASTLE_CONF_INCLUDED} |
| 37 |
|
| 38 |
{ Compiler version check ----------------------------------------------------- } |
| 39 |
|
| 40 |
{$ifndef PASDOC} // Avoid Pasdoc warnings, as Pasdoc cannot calculate $if below |
| 41 |
{$ifdef FPC} |
| 42 |
{$if defined(VER2) or defined(VER3_0)} |
| 43 |
{$fatal You need FPC version >= 3.2.0 to compile Castle Game Engine. See https://castle-engine.io/supported_compilers.php} |
| 44 |
{$endif} |
| 45 |
{$else} |
| 46 |
// See http://delphi.wikia.com/wiki/CompilerVersion_Constant |
| 47 |
{$if CompilerVersion < 32} |
| 48 |
{$message fatal 'Use Delphi >= 10.2.1 to compile Castle Game Engine. See https://castle-engine.io/delphi'} |
| 49 |
{$endif} |
| 50 |
{$endif} |
| 51 |
{$endif} |
| 52 |
|
| 53 |
{ Configure syntax ----------------------------------------------------------- } |
| 54 |
|
| 55 |
{ Although these options are also specified by the CGE build tool |
| 56 |
on the command-line, |
| 57 |
and are in Lazarus packages too, |
| 58 |
we still need to repeat them here. |
| 59 |
|
| 60 |
That is because user can specify "<option>-Mdelphi</option>" |
| 61 |
in CastleEngineManifest.xml, to compile the application in Delphi mode. |
| 62 |
} |
| 63 |
{$ifdef FPC} |
| 64 |
{$mode objfpc} |
| 65 |
{$H+} |
| 66 |
{$macro on} |
| 67 |
{$modeswitch advancedrecords} // Note: no way to specify this by FPC command-line. |
| 68 |
{$else} |
| 69 |
{ Makes TStructList.L useful in Delphi, like "MyArray.L[100]". |
| 70 |
FPC has this by default. |
| 71 |
See https://docwiki.embarcadero.com/RADStudio/Sydney/en/Pointer_Math_(Delphi) } |
| 72 |
{$pointermath on} |
| 73 |
// For now we only support FPC or Delphi |
| 74 |
{$define DELPHI} |
| 75 |
{$endif} |
| 76 |
|
| 77 |
{$writeableconst off} // Note: no way to specify this by FPC command-line. |
| 78 |
|
| 79 |
{ CPU symbols ---------------------------------------------------------------- } |
| 80 |
|
| 81 |
{ Delphi compatibility } |
| 82 |
{$ifndef FPC} |
| 83 |
{ Define in Delphi CPU32/64, like FPC does. } |
| 84 |
{$ifdef CPUX86} {$define CPU32} {$endif} |
| 85 |
{$ifdef CPU32BITS} {$define CPU32} {$endif} |
| 86 |
{$ifdef CPUX64} {$define CPU64} {$endif} |
| 87 |
{$ifdef CPU64BITS} {$define CPU64} {$endif} |
| 88 |
|
| 89 |
{ Define platforms like FPC does. } |
| 90 |
{$ifdef CPUX64} {$define cpux86_64} {$define cpuamd64} {$endif} |
| 91 |
{$ifdef CPUX86} {$define cpu386} {$define cpui386} {$endif} |
| 92 |
{$ifdef CPUARM64} {$define CPUAARCH64} {$endif} |
| 93 |
|
| 94 |
{ Define in Delphi UNIX when LINUX, like FPC does. } |
| 95 |
{$ifdef LINUX} {$define UNIX} {$endif} |
| 96 |
{$endif} |
| 97 |
|
| 98 |
{ Traditionally, CGE defined CPUARM64 also for 64-bit iOS. |
| 99 |
For compatibility, keep it defined there. |
| 100 |
But CPUARM64 should not be used anymore: we use now CPUAARCH64, |
| 101 |
defined by FPC automatically (so it's safer to use, it will work |
| 102 |
regardless of how you compile the sources). } |
| 103 |
{$ifdef CPUAARCH64} |
| 104 |
{$define CPUARM64} |
| 105 |
{$endif} |
| 106 |
|
| 107 |
{ Endianess ------------------------------------------------------------------ } |
| 108 |
|
| 109 |
{$ifdef FPC} |
| 110 |
{$ifdef FPC_LITTLE_ENDIAN} {$define CASTLE_LITTLE_ENDIAN} {$endif} |
| 111 |
{$ifdef FPC_BIG_ENDIAN} {$define CASTLE_BIG_ENDIAN} {$endif} |
| 112 |
{$else} |
| 113 |
{ Delphi only supports little-endian it seems. } |
| 114 |
{$define CASTLE_LITTLE_ENDIAN} |
| 115 |
{$endif} |
| 116 |
|
| 117 |
{$ifndef CASTLE_LITTLE_ENDIAN} |
| 118 |
{$ifndef CASTLE_BIG_ENDIAN} |
| 119 |
{$error Neither CASTLE_LITTLE_ENDIAN or CASTLE_BIG_ENDIAN defined. Fix castleconf.inc for the current compiler/platform combination.} |
| 120 |
{$endif} |
| 121 |
{$endif} |
| 122 |
|
| 123 |
{ Define various necessary things -------------------------------------------- } |
| 124 |
|
| 125 |
(*EXTENDED_EQUALS_DOUBLE should be defined when Extended type is |
| 126 |
the same thing as Double type on this platform. |
| 127 |
|
| 128 |
One typical case when this is important is when you overload |
| 129 |
one procedure like |
| 130 |
p(single) |
| 131 |
p(double) |
| 132 |
p(extended) |
| 133 |
In such cases you must do it like this: |
| 134 |
p(single) |
| 135 |
p(double) |
| 136 |
{$ifndef EXTENDED_EQUALS_DOUBLE} p(extended) {$endif} |
| 137 |
|
| 138 |
According to FPC docs (Programmers Manual, 8.2.0: floating point types), |
| 139 |
there's no Extended (i.e. Extended = Double) for most of non-i386 architectures. |
| 140 |
Exception to the above is Linux on x86-64, that allows to use normal Extended. |
| 141 |
Maybe Darwin on x86-64 also? |
| 142 |
*) |
| 143 |
{$ifdef FPC} |
| 144 |
{$ifndef FPC_HAS_TYPE_EXTENDED} |
| 145 |
{$define EXTENDED_EQUALS_DOUBLE} |
| 146 |
{$endif} |
| 147 |
{$else} |
| 148 |
{ Following https://docwiki.embarcadero.com/RADStudio/Sydney/en/Simple_Types_(Delphi)#Real_Types } |
| 149 |
{$if defined(LINUX) and defined(CPU64)} |
| 150 |
{$define EXTENDED_EQUALS_LONG_DOUBLE} |
| 151 |
{$elseif defined(WIN32)} |
| 152 |
{ Original Pascal 10-byte Extended. } |
| 153 |
{$else} |
| 154 |
{$define EXTENDED_EQUALS_DOUBLE} |
| 155 |
{$endif} |
| 156 |
{$endif} |
| 157 |
|
| 158 |
{ When using FPC, and Extended = Double, you cannot overload |
| 159 |
for both Double and Extended as they are just equal. |
| 160 |
Extended is just alias for Double. |
| 161 |
|
| 162 |
Delphi, even when Extended = Double, still treats Extended |
| 163 |
like a different type, for choosing overloads. |
| 164 |
It even requires Extended overloads e.g. for MinVar(Extended, ...). } |
| 165 |
{$ifndef PASDOC} |
| 166 |
{$if not (defined(FPC) and defined(EXTENDED_EQUALS_DOUBLE))} |
| 167 |
{$define EXTENDED_OVERLOADS} |
| 168 |
{$endif} |
| 169 |
{$endif} |
| 170 |
|
| 171 |
{ We used to disable inline functions/methods when compiling from |
| 172 |
Lazarus package (when CASTLE_ENGINE_LAZARUS_PACKAGE), |
| 173 |
to workaround FPC bug http://bugs.freepascal.org/view.php?id=12223 . |
| 174 |
That bug is closed, but with an answer basically "it will never be fixed", |
| 175 |
which means that you cannot have units in Lazarus package having |
| 176 |
"inline". (Unless you add -Ur, which would be uncomfortable for |
| 177 |
engine development from Lazarus.) |
| 178 |
|
| 179 |
But with FPC 3.0.2 everything seems to work cool even with "inline", |
| 180 |
so let's try defining it always now. |
| 181 |
We only support FPC >= 3.0.0 now. |
| 182 |
} |
| 183 |
{$define SUPPORTS_INLINE} |
| 184 |
|
| 185 |
{ Delphi does not support "inline" with types that are not in units explicitly |
| 186 |
used on the "uses" list. |
| 187 |
Avoid flood of hints like this: |
| 188 |
"[dcc32 Hint] castlerendercontext.pas(313): H2443 Inline function 'TGenericVector4.GetItems' has not been expanded because unit 'CastleVectorsInternalSingle' is not specified in USES list" } |
| 189 |
{$if defined(FPC) and defined(SUPPORTS_INLINE)} |
| 190 |
{$define INLINE_GENERIC_VECTORS} |
| 191 |
{$endif} |
| 192 |
|
| 193 |
{$define TOBJECT_HAS_EQUALS} |
| 194 |
|
| 195 |
{ Delphi reports many hints/warnings that are known to be harmless in our case. } |
| 196 |
{$ifndef FPC} |
| 197 |
{$hints off} |
| 198 |
{$warn COMPARING_SIGNED_UNSIGNED off} |
| 199 |
{$warn COMBINING_SIGNED_UNSIGNED off} |
| 200 |
{$if CompilerVersion >= 32} {$warn COMBINING_SIGNED_UNSIGNED64 off} {$endif} // only since Delphi 10.2 |
| 201 |
{$warn IMPLICIT_STRING_CAST off} |
| 202 |
{ TODO: We'd like to unhide this. } |
| 203 |
{$warn IMPLICIT_STRING_CAST_LOSS off} |
| 204 |
{$warn GARBAGE off} |
| 205 |
{$warn WIDECHAR_REDUCED off} |
| 206 |
{ We sometimes use deprecated CGE things in CGE itself, to support other |
| 207 |
deprecated API for the time being. We actually disable warnings around with |
| 208 |
$warnings on/off... but not enough for Delphi. |
| 209 |
TODO: This should eventually by unhidden. } |
| 210 |
{$warn SYMBOL_DEPRECATED off} |
| 211 |
{$endif} |
| 212 |
|
| 213 |
{ If GENERICS_CONSTREF is defined, then various routines used with Generics.Collections |
| 214 |
(like callbacks we pass to TComparer, or OnNotify callback or Notify virtual method) |
| 215 |
should have "constref" parameter, not "const". |
| 216 |
This was the case of FPC<= 3.2.0, FPC changed it in |
| 217 |
https://gitlab.com/freepascal.org/fpc/source/-/commit/693491048bf2c6f9122a0d8b044ad0e55382354d } |
| 218 |
{$ifdef VER3_0} {$define GENERICS_CONSTREF} {$endif} |
| 219 |
{$ifdef VER3_2} {$define GENERICS_CONSTREF} {$endif} |
| 220 |
{$if defined(VER3_2_3)} |
| 221 |
{ FPC 3.2.3 (fixes_3_2 branch, as of 2023-12-23) no longer uses "constref". |
| 222 |
Confirmed on Linux/Arm32, Linux/Arm64(Aarch64), Linux/x86_64, |
| 223 |
see also sources: |
| 224 |
https://gitlab.com/freepascal.org/fpc/source/-/blob/fixes_3_2/packages/rtl-generics/src/generics.collections.pas?ref_type=heads. } |
| 225 |
{$undef GENERICS_CONSTREF} |
| 226 |
{$endif} |
| 227 |
|
| 228 |
{ Define CASTLE_IOS when appropriate ----------------------------------------- } |
| 229 |
|
| 230 |
{ Build tool defines CASTLE_IOS automatically. |
| 231 |
This include file defines CASTLE_IOS too, to have it regardless of compilation method. |
| 232 |
|
| 233 |
Note: FPC >= 3.2.2 introduced own IOS symbol. |
| 234 |
It only indicates "real" physical iOS, not iPhoneSimulator. } |
| 235 |
|
| 236 |
// FPC defines iOS as a separate OS since FPC 3.2.2. |
| 237 |
{$define HAS_SEPARATE_IOS} |
| 238 |
{$ifdef VER3_0} {$undef HAS_SEPARATE_IOS} {$endif} |
| 239 |
{$ifdef VER3_2_0} {$undef HAS_SEPARATE_IOS} {$endif} |
| 240 |
|
| 241 |
{$ifndef PASDOC} // Avoid Pasdoc warnings, as Pasdoc cannot calculate $if below |
| 242 |
{$ifdef HAS_SEPARATE_IOS} |
| 243 |
{$if defined(iPHONESIM) or defined(iOS)} |
| 244 |
{$define CASTLE_IOS} |
| 245 |
{$endif} |
| 246 |
{$else} |
| 247 |
{$if defined(iPHONESIM) or (defined(DARWIN) and (defined(CPUARM) or defined(CPUAARCH64)))} |
| 248 |
{$define CASTLE_IOS} |
| 249 |
{$endif} |
| 250 |
{$endif} |
| 251 |
{$endif} |
| 252 |
|
| 253 |
{ Define COMPILER_CASE_ANALYSIS when appropriate --------------------------- } |
| 254 |
|
| 255 |
{ Compiler automatically detects and warns when "case" doesn't cover |
| 256 |
all possibilities. This means we do not have to, and actually |
| 257 |
we should not have to (as it would cause "Warning: Unreachable code" warning), |
| 258 |
add a clause like "else raise EInternalError.Create('xxx');" |
| 259 |
to "case" statements that should always have a matching possibility. |
| 260 |
|
| 261 |
This is true for FPC >= 3.2 now. } |
| 262 |
|
| 263 |
{$ifdef FPC} |
| 264 |
{$ifndef VER3_0} |
| 265 |
{$ifndef VER3_1} |
| 266 |
{$define COMPILER_CASE_ANALYSIS} |
| 267 |
{$endif} |
| 268 |
{$endif} |
| 269 |
{$endif} |
| 270 |
|
| 271 |
{ Nintendo Switch ------------------------------------------------------------ } |
| 272 |
|
| 273 |
{ Since we use (as a hack) Aarch64/Android for Nintendo Switch, |
| 274 |
undefine ANDROID now, |
| 275 |
to not automatically use Android-specific units in |
| 276 |
android/castleandroidinternal*.pas . } |
| 277 |
{$ifdef CASTLE_NINTENDO_SWITCH} |
| 278 |
{$undef ANDROID} |
| 279 |
{$endif CASTLE_NINTENDO_SWITCH} |
| 280 |
|
| 281 |
{ Platform specific adjustments ---------------------------------------------- } |
| 282 |
|
| 283 |
{ On some Android versions, you cannot call dlopen (load dynamic libraries) |
| 284 |
from the initialization section of units. You have to wait for |
| 285 |
AndroidMain to be called by NDK, otherwise we get a crash at initialization. } |
| 286 |
{$define ALLOW_DLOPEN_FROM_UNIT_INITIALIZATION} |
| 287 |
{$ifdef ANDROID} |
| 288 |
{$undef ALLOW_DLOPEN_FROM_UNIT_INITIALIZATION} |
| 289 |
{$endif} |
| 290 |
// TODO: for now dlopen doesn't work at all on NX, so avoid it |
| 291 |
{$ifdef CASTLE_NINTENDO_SWITCH} |
| 292 |
{$undef ALLOW_DLOPEN_FROM_UNIT_INITIALIZATION} |
| 293 |
{$endif} |
| 294 |
|
| 295 |
{ OpenGL[ES] ------------------------------------------------------------------ } |
| 296 |
|
| 297 |
(*Whether we use OpenGL ES or normal OpenGL. |
| 298 |
OpenGL ES is by default used for mobile devices. |
| 299 |
For testing, you can also use OpenGL ES on normal desktop OSes |
| 300 |
(see https://castle-engine.io/android_faq#testing-mobile-opengl-es-rendering-without-an-android |
| 301 |
for instructions how to install OpenGL ES on desktop). |
| 302 |
|
| 303 |
CGE units that directly access OpenGL(ES) should use this line: |
| 304 |
|
| 305 |
{$ifdef OpenGLES} CastleGLES, {$else} CastleGL, {$endif} |
| 306 |
|
| 307 |
Applications using CGE (including CGE examples) cannot include castleconf.inc |
| 308 |
(it's internal what it defines) and usually should not need to access OpenGL(ES) |
| 309 |
API directly (to stay independent from OpenGL(ES) details or any future renderer API). |
| 310 |
But if you really have to use OpenGL(ES) API directly, you can do this: |
| 311 |
|
| 312 |
{$ifdef ANDROID} {$define OpenGLES} {$endif} |
| 313 |
{$ifdef CASTLE_IOS} {$define OpenGLES} {$endif} |
| 314 |
{$ifdef OpenGLES} CastleGLES, {$else} CastleGL, {$endif} |
| 315 |
|
| 316 |
The above code supports both FPC and Delphi, and supports both OpenGL and OpenGLES. |
| 317 |
Please note that above recommendation may change from time to time. |
| 318 |
*) |
| 319 |
{ $define OpenGLES} |
| 320 |
{$ifdef ANDROID} {$define OpenGLES} {$endif} |
| 321 |
{$ifdef CASTLE_IOS} {$define OpenGLES} {$endif} |
| 322 |
|
| 323 |
{ NX supports OpenGL and OpenGLES (that's public information, |
| 324 |
https://wccftech.com/nintendo-switch-supports-vulkan/ ). |
| 325 |
Our rendering matches better OpenGLES on NX. } |
| 326 |
{$ifdef CASTLE_NINTENDO_SWITCH} {$define OpenGLES} {$endif} |
| 327 |
|
| 328 |
{$ifdef OpenGLES} |
| 329 |
{$ifdef CASTLE_NINTENDO_SWITCH} |
| 330 |
{$define CastleGLES := CastleInternalNxGLES20} |
| 331 |
{$endif} |
| 332 |
|
| 333 |
{ This is necessary for OpenGL ES 2.0 versions that support only 16-bit indexes, |
| 334 |
which is valid for OpenGL ES 2.0 implementations. |
| 335 |
WebGL 1.0 also shares this limitation. |
| 336 |
|
| 337 |
Example observed in real-life: Android EMUI 3.1 |
| 338 |
(Renderer = "Mali-450 MP", Vendor = "ARM", Version string "OpenGL ES 2.0"). |
| 339 |
|
| 340 |
- OpenGLES 2.0 indeed does not allows 32-bit indexes in spec, |
| 341 |
i.e. you cannot pass GL_UNSIGNED_INT to glDrawElements |
| 342 |
( https://docs.gl/es2/glDrawElements ), |
| 343 |
- although OpenGL 3.0 allows them |
| 344 |
( https://docs.gl/es3/glDrawElements ) |
| 345 |
- and there's an extension to enable it for GLES 2 |
| 346 |
( https://github.com/KhronosGroup/OpenGL-Registry/blob/main/extensions/OES/OES_element_index_uint.txt ). |
| 347 |
|
| 348 |
Current solution: We render using 16-bit indexes, which may also be useful |
| 349 |
to gain a little performance, *but* it means we cannot render large shapes. |
| 350 |
|
| 351 |
TODO: The more long-term solution is: |
| 352 |
|
| 353 |
- Detect the need for 32-bit indexes at runtime, |
| 354 |
and switch between 16-bit and 32-bit indexes as needed. |
| 355 |
|
| 356 |
- This would allow performance gain on both desktops and mobiles (but I did not |
| 357 |
check whether this gain is noticeable!), while still allowing to render large |
| 358 |
shapes. |
| 359 |
For small shapes, your indexes can take 2x less memory on GPU. |
| 360 |
|
| 361 |
- Unless we need 32-bit indexes but OpenGLES doesn't support it |
| 362 |
(so we have OpenGLES 2, not 3, and without OES_element_index_uint), |
| 363 |
then we can: |
| 364 |
|
| 365 |
- refuse to render given shapes (authors that want to support older OpenGLES |
| 366 |
would have to keep this limit in mind, and design for it) |
| 367 |
- or force AllowIndexed := false in X3D renderer |
| 368 |
- or split the shapes (but this would complicate the rendering code). |
| 369 |
} |
| 370 |
{$define GLIndexesShort} |
| 371 |
{$else} |
| 372 |
{ For OpenGL (not ES), we use our own fork of dglOpenGL |
| 373 |
(with all compilers and platforms now). } |
| 374 |
{$define USE_DGL} |
| 375 |
{$endif} |
| 376 |
|
| 377 |
{ PNG ------------------------------------------------------------------------ } |
| 378 |
|
| 379 |
{ There are few ways to read/write the PNG format: |
| 380 |
|
| 381 |
1.Pascal-only solutions. |
| 382 |
|
| 383 |
These mean: |
| 384 |
- FpImage (fcl-image units) with FPC |
| 385 |
- PngImage with Delphi |
| 386 |
- Vampyre Imaging Library (both FPC and Delphi) |
| 387 |
|
| 388 |
These are used: |
| 389 |
- if neither CASTLE_PNG_DYNAMIC nor CASTLE_PNG_STATIC are defined. |
| 390 |
- or CASTLE_DISABLE_LIBPNG is defined (which forcefully undefines |
| 391 |
CASTLE_PNG_DYNAMIC and CASTLE_PNG_STATIC). |
| 392 |
- or when CASTLE_PNG_DYNAMIC is defined but libpng cannot be loaded |
| 393 |
at runtime. |
| 394 |
|
| 395 |
Pascal solutions are simplest to use, since the PNG support is completely |
| 396 |
contained in Pascal code, so you don't need to distribute anything, |
| 397 |
and it works on all platforms. |
| 398 |
|
| 399 |
The downside is that it is not optimal. |
| 400 |
In particular FpImage is extremely slow: |
| 401 |
- LibPng results in drastically faster PNG loading than FpImage |
| 402 |
- LibPng gives 4x speedup on desktops over FpImage |
| 403 |
- LibPng gives 10x speedup on Android over FpImage |
| 404 |
Vampyre PNG reading is faster, though LibPng is still ~2x faster than Vampyre. |
| 405 |
|
| 406 |
Use examples/images_videos/image_display/ to measure the speed. |
| 407 |
|
| 408 |
2.If CASTLE_PNG_DYNAMIC is defined and libpng exists, |
| 409 |
we use libpng from a dynamic library (.so or .dll). |
| 410 |
|
| 411 |
- On Linux and other desktop Unixes, libpng is almost definitely already |
| 412 |
installed system-wide, so this just works. |
| 413 |
|
| 414 |
- On Windows, the appropriate dll is available in our build tool data in |
| 415 |
../../tools/build-tool/data/external_libraries/ . |
| 416 |
|
| 417 |
It will be added to your Windows package by the build tool automatically when |
| 418 |
you run "castle-engine package ..." |
| 419 |
See https://castle-engine.io/build_tool . |
| 420 |
It will also be placed alongside your .exe when you do "castle-engine compile ...". |
| 421 |
|
| 422 |
- On macOS, see https://castle-engine.io/macos . |
| 423 |
|
| 424 |
- On Android, we have a "png" service with libpng included. |
| 425 |
See ../../tools/build-tool/data/android/integrated-services/png/README.adoc . |
| 426 |
|
| 427 |
3.If CASTLE_PNG_STATIC is defined, we statically link to libpng. |
| 428 |
The presense of static libpng library (libpng.a on Unix) is then |
| 429 |
required at compile-time. |
| 430 |
This is necessary on some platforms, e.g. iOS. The CGE build tool |
| 431 |
automatically uses this flag when necessary. |
| 432 |
} |
| 433 |
|
| 434 |
{$ifndef PASDOC} // Avoid Pasdoc warnings, as Pasdoc cannot calculate $if below |
| 435 |
|
| 436 |
{ On most platforms, try dynamic libpng (will fallback on FpImage at runtime). |
| 437 |
Except on platforms where we know it would not work. } |
| 438 |
{$if not (defined(CASTLE_IOS) or defined(CASTLE_NINTENDO_SWITCH))} |
| 439 |
{$define CASTLE_PNG_DYNAMIC} |
| 440 |
{$endif} |
| 441 |
|
| 442 |
{$if defined(CASTLE_PNG_DYNAMIC) and defined(CASTLE_PNG_STATIC)} |
| 443 |
{$error Cannot define both CASTLE_PNG_DYNAMIC and CASTLE_PNG_STATIC. Define at most one of them.} |
| 444 |
{$endif} |
| 445 |
|
| 446 |
{$if defined(CASTLE_DISABLE_LIBPNG)} |
| 447 |
{$undef CASTLE_PNG_DYNAMIC} |
| 448 |
{$undef CASTLE_PNG_STATIC} |
| 449 |
{$endif} |
| 450 |
{$endif} |
| 451 |
|
| 452 |
{ LIBPNG_CDECL is relevant only if we use libpng (dynamic or static). |
| 453 |
Determines calling convention of libpng functions and libpng callbacks. |
| 454 |
When LIBPNG_CDECL is defined, it is "cdecl", otherwise it is "stdcall". |
| 455 |
Right now, in practice it is always LIBPNG_CDECL, even on Windows |
| 456 |
(standard Windows libpng DLL libraries use cdecl, just like on Unix). } |
| 457 |
{$ifdef MSWINDOWS} |
| 458 |
{$define LIBPNG_CDECL} |
| 459 |
{$else} |
| 460 |
{$define LIBPNG_CDECL} |
| 461 |
{$endif} |
| 462 |
|
| 463 |
{ FpHttpClient --------------------------------------------------------------- } |
| 464 |
|
| 465 |
{ Keep HAS_FP_HTTP_CLIENT defined for all platforms that have |
| 466 |
FpHttpClient implemented, if you use FPC. } |
| 467 |
{$define HAS_FP_HTTP_CLIENT} |
| 468 |
{$ifdef CASTLE_NINTENDO_SWITCH} {$undef HAS_FP_HTTP_CLIENT} {$endif} |
| 469 |
{$ifdef ANDROID} {$undef HAS_FP_HTTP_CLIENT} {$endif} |
| 470 |
{$ifndef FPC} {$undef HAS_FP_HTTP_CLIENT} {$endif} |
| 471 |
|
| 472 |
{ Threading --------------------------------------------------------------- } |
| 473 |
|
| 474 |
{ Threading support, as some platforms don't have threads (implemented yet). |
| 475 |
|
| 476 |
Note: This does *not* detect the case when threads are possible on this |
| 477 |
platform, but not "compiled in". That is, when using regular Unix |
| 478 |
(like Linux) this symbol will be defined, regardless if you used CThreads or not in FPC. } |
| 479 |
{$define CASTLE_SUPPORTS_THREADING} |
| 480 |
{$ifdef CASTLE_NINTENDO_SWITCH} {$undef CASTLE_SUPPORTS_THREADING} {$endif} |
| 481 |
|
| 482 |
{ Audio ---------------------------------------------------------------------- } |
| 483 |
|
| 484 |
{ Although Tremolo is largely compatible with VorbisFile, there are small differences, |
| 485 |
e.g. ov_time_total returns Int64 with Tremolo instead of Double with VorbisFile. } |
| 486 |
{$if defined(CASTLE_IOS) or defined(ANDROID) or defined(CASTLE_NINTENDO_SWITCH)} |
| 487 |
{$define CASTLE_TREMOLO} |
| 488 |
{$endif} |
| 489 |
|
| 490 |
{ X3D ------------------------------------------------------------------------ } |
| 491 |
|
| 492 |
{ Define this if needed to optimize loading time. |
| 493 |
It removes various seldom-used fields from often-used X3D nodes, |
| 494 |
thus increasing the X3D node creation time significantly. |
| 495 |
It also makes some exposed X3D fields into non-exposed |
| 496 |
(it means you cannot define X3D ROUTEs to pass value into/out of this field). |
| 497 |
The choice "which fields are seldom used" is purely subjective, and may change! } |
| 498 |
{.$define CASTLE_SLIM_NODES} |
| 499 |
|
| 500 |
{ Vampyre Imaging ------------------------------------------------------------ } |
| 501 |
|
| 502 |
{ Use Vampyre Imaging Library to support additional image formats. |
| 503 |
See https://imaginglib.sourceforge.io/ , |
| 504 |
https://github.com/galfar/imaginglib , |
| 505 |
https://castle-engine.io/wp/2021/12/18/integration-with-vampyre-imaging-library-new-example-image_display-to-test-image-loading-speed-and-format-support/ |
| 506 |
about Vampyre. |
| 507 |
|
| 508 |
We rely on Vampyre for a number of formats. |
| 509 |
|
| 510 |
- With Delphi (where Vampyre is our only way to read some formats, |
| 511 |
like JPG, BPM, PPM). |
| 512 |
|
| 513 |
- With FPC (although with FPC we can also use FpImage. |
| 514 |
But Vampyre proved better: 2x faster at reading PNG, |
| 515 |
and more reliable at reading BMP, PPM, XPM -- we have testcase images in this |
| 516 |
repo that fail with FpImage, while work OK with Vampyre). |
| 517 |
|
| 518 |
Right now we just use Vampyre, by default, with all compilers. |
| 519 |
|
| 520 |
We bundle Vampyre Imaging sources with CGE (in src/vampyre_imaging), |
| 521 |
and so it is available automatically without any effort for all CGE devs, |
| 522 |
and so we just use it automatically. |
| 523 |
|
| 524 |
Note: To compile with Vampyre using Lazarus (from LPI, LPK): |
| 525 |
remember to register in Lazarus 2 Vampyre packages: |
| 526 |
src/vampyre_imaginglib/src/Packages/VampyreImaginePackage.lpk |
| 527 |
src/vampyre_imaginglib/src/Packages/VampyreImaginePackageExt.lpk |
| 528 |
} |
| 529 |
{$define USE_VAMPYRE_IMAGING} |
| 530 |
|
| 531 |
{ GPU texture compression ---------------------------------------------------- } |
| 532 |
|
| 533 |
{ If defined, use "astcenc" tool to compress textures to ASTC |
| 534 |
(resulting in ASTC compression in .astc file format). |
| 535 |
|
| 536 |
Advantage: astcenc is fully open-source, simple tool distributed with CGE. |
| 537 |
|
| 538 |
Disadvantage: .astc cannot express mipmaps, and we cannot autogenerate mipmaps |
| 539 |
for compressed textures. So this makes such textures bad for situations when |
| 540 |
mipmaps are desired, which is typical for textures in 3D games. } |
| 541 |
{.$define USE_ASTCENC} |
| 542 |
|
| 543 |
{ Features ------------------------------------------------------------------- } |
| 544 |
|
| 545 |
(*Generic methods are a cool idea, and we have at least one important use-case |
| 546 |
for them: node searching that filters and returns proper type. |
| 547 |
See TCastleScene.Node, TX3DRootNode.Find. |
| 548 |
|
| 549 |
Unfortunately generic methods suck now with FPC 3.2.2. |
| 550 |
- In ObjFpc you need to use "specialize" keyword, which looks excessive. |
| 551 |
Esp. that we actually need "{$ifdef FPC}specialize{$endif}". |
| 552 |
- If you forget about "specialize" keyword, |
| 553 |
sometimes you get FPC internal error, |
| 554 |
sometimes it compiles code that always results in EAccessViolation. |
| 555 |
|
| 556 |
Until this is fixed, we cannot really use them. |
| 557 |
But we have some ready code with them, you can undefine this symbol |
| 558 |
and try out the new generic TCastleScene.Node, TX3DRootNode.Find. |
| 559 |
*) |
| 560 |
{.$define GENERIC_METHODS} |
| 561 |
|
| 562 |
{ Parts of CastleScript implementation right now use Pascal generics |
| 563 |
in ways that don't compile with Delphi. |
| 564 |
Symbol CASTLE_SCRIPT_FPC is in practice equal to just FPC, |
| 565 |
but having a dedicated symbol allows to easier grep for it and eventually fix. } |
| 566 |
{$ifdef FPC} |
| 567 |
{$define CASTLE_SCRIPT_FPC} |
| 568 |
{$endif} |
| 569 |
|
| 570 |
{ Indicates units like X, XLib are available on this platform. } |
| 571 |
{$if defined(FPC) and (defined(LINUX) or defined(FREEBSD))} |
| 572 |
{$define UNIX_WITH_X} |
| 573 |
{$endif} |
| 574 |
|
| 575 |
{$endif not CASTLE_CONF_INCLUDED} |