opt.rst 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. .. default-domain:: C
  2. 🛠️ Options
  3. ===============================================================================
  4. A few options are provided via macros.
  5. Alignment Option
  6. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. As default, cglm requires types to be aligned. Alignment requirements:
  8. vec3: 8 byte
  9. vec4: 16 byte
  10. mat4: 16 byte
  11. versor: 16 byte
  12. By starting **v0.4.5** cglm provides an option to disable alignment requirement.
  13. To enable this option define **CGLM_ALL_UNALIGNED** macro before all headers.
  14. You can define it in Xcode, Visual Studio (or other IDEs) or you can also prefer
  15. to define it in build system. If you use pre-compiled versions then you
  16. have to compile cglm with **CGLM_ALL_UNALIGNED** macro.
  17. **VERY VERY IMPORTANT:** If you use cglm in multiple projects and
  18. those projects are depends on each other, then
  19. | *ALWAYS* or *NEVER USE* **CGLM_ALL_UNALIGNED** macro in linked projects
  20. if you do not know what you are doing. Because a cglm header included
  21. via 'project A' may force types to be aligned and another cglm header
  22. included via 'project B' may not require alignment. In this case
  23. cglm functions will read from and write to **INVALID MEMORY LOCATIONs**.
  24. ALWAYS USE SAME CONFIGURATION / OPTION for **cglm** if you have multiple projects.
  25. For instance if you set CGLM_ALL_UNALIGNED in a project then set it in other projects too
  26. Clipspace Option[s]
  27. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  28. By starting **v0.8.3** cglm provides options to switch between clipspace configurations.
  29. Clipspace related files are located at `include/cglm/[struct]/clipspace.h` but
  30. these are included in related files like `cam.h`. If you don't want to change your existing
  31. clipspace configuration and want to use different clipspace function like `glm_lookat_zo` or `glm_lookat_lh_zo`...
  32. then you can include individual headers or just define `CGLM_CLIPSPACE_INCLUDE_ALL` which will iclude all headers for you.
  33. 1. **CGLM_CLIPSPACE_INCLUDE_ALL**
  34. 2. **CGLM_FORCE_DEPTH_ZERO_TO_ONE**
  35. 3. **CGLM_FORCE_LEFT_HANDED**
  36. 1. **CGLM_CLIPSPACE_INCLUDE_ALL**:
  37. By defining this macro, **cglm** will include all clipspace functions for you by just using
  38. `#include cglm/cglm.h` or `#include cglm/struct.h` or `#include cglm/call.h`
  39. Otherwise you need to include header you want manually e.g. `#include cglm/clipspace/view_rh_zo.h`
  40. 2. **CGLM_FORCE_DEPTH_ZERO_TO_ONE**
  41. This is similar to **GLM**'s **GLM_FORCE_DEPTH_ZERO_TO_ONE** option.
  42. This will set clip space between 0 to 1 which makes **cglm** Vulkan, Metal friendly.
  43. You can use functions like `glm_lookat_lh_zo()` individually. By setting **CGLM_FORCE_DEPTH_ZERO_TO_ONE**
  44. functions in cam.h for instance will use `_zo` versions.
  45. 3. **CGLM_FORCE_LEFT_HANDED**
  46. Force **cglm** to use the left handed coordinate system by default, currently **cglm** uses right handed coordinate system as default,
  47. you can change this behavior with this option.
  48. **VERY VERY IMPORTANT:**
  49. Be careful if you include **cglm** in multiple projects.
  50. SSE and SSE2 Shuffle Option
  51. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  52. **_mm_shuffle_ps** generates **shufps** instruction even if registers are same.
  53. You can force it to generate **pshufd** instruction by defining
  54. **CGLM_USE_INT_DOMAIN** macro. As default it is not defined.
  55. SSE3 and SSE4 Dot Product Options
  56. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  57. You have to extra options for dot product: **CGLM_SSE4_DOT** and **CGLM_SSE3_DOT**.
  58. - If **SSE4** is enabled then you can define **CGLM_SSE4_DOT** to force cglm to use **_mm_dp_ps** instruction.
  59. - If **SSE3** is enabled then you can define **CGLM_SSE3_DOT** to force cglm to use **_mm_hadd_ps** instructions.
  60. otherwise cglm will use custom cglm's hadd functions which are optimized too.
  61. Struct API Options
  62. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  63. To configure the Struct API namespace, you can define the following macros before including the cglm/struct.h header:
  64. - **CGLM_OMIT_NS_FROM_STRUCT_API**: omits CGLM_STRUCT_API_NS (`glms_`) namespace completely if there is sub namespace e.g `mat4_`, `vec4_` ... DEFAULT is not defined
  65. - **CGLM_STRUCT_API_NS**: define name space for struct api, DEFAULT is **glms**
  66. - **CGLM_STRUCT_API_NAME_SUFFIX**: define name suffix, DEFAULT is **empty** e.g defining it as #define CGLM_STRUCT_API_NAME_SUFFIX s will add s suffix to mat4_mul -> mat4s_mul
  67. Print Options
  68. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  69. 1. **CGLM_DEFINE_PRINTS**
  70. 2. **CGLM_NO_PRINTS_NOOP** (use CGLM_DEFINE_PRINTS)
  71. Inline prints are only enabled in **DEBUG** mode or if **CGLM_DEFINE_PRINTS** is defined.
  72. **glmc_** versions will always print too.
  73. Because **cglm** tried to enable print functions in debug mode and disable them in
  74. release/production mode to eliminate printing costs when we do not need them.
  75. **cglm** checks **DEBUG** or **_DEBUG** macros to test debug mode, if these are not working for you then you can use
  76. **CGLM_DEFINE_PRINTS** to force enable, or create a PR to introduce new macro to test against debugging mode.
  77. If DEBUG mode is not enabled then print functions will be emptied to eliminate print function calls.
  78. You can disable this feature too by defining **CGLM_DEFINE_PRINTS** macro top of cglm header
  79. or in project/build settings...
  80. 3. **CGLM_PRINT_PRECISION** 5
  81. precision.
  82. 4. **CGLM_PRINT_MAX_TO_SHORT** 1e5
  83. if a number is greater than this value then %g will be used, since this is shorten print you won't be able to see high precision.
  84. 5. **CGLM_PRINT_COLOR** "\033[36m"
  85. 6. **CGLM_PRINT_COLOR_RESET** "\033[0m"
  86. You can disable colorful print output by defining **CGLM_PRINT_COLOR** and **CGLM_PRINT_COLOR_RESET** as empty macro.
  87. Because some terminals may not support colors.