🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
6.3 KiB

  1. #include "config.h"
  2. #include <stddef.h>
  3. #include "AL/al.h"
  4. #include "router.h"
  5. std::atomic<DriverIface*> CurrentCtxDriver{nullptr};
  6. #define DECL_THUNK1(R,n,T1) AL_API R AL_APIENTRY n(T1 a) \
  7. { \
  8. DriverIface *iface = GetThreadDriver(); \
  9. if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
  10. return iface->n(a); \
  11. }
  12. #define DECL_THUNK2(R,n,T1,T2) AL_API R AL_APIENTRY n(T1 a, T2 b) \
  13. { \
  14. DriverIface *iface = GetThreadDriver(); \
  15. if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
  16. return iface->n(a, b); \
  17. }
  18. #define DECL_THUNK3(R,n,T1,T2,T3) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c) \
  19. { \
  20. DriverIface *iface = GetThreadDriver(); \
  21. if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
  22. return iface->n(a, b, c); \
  23. }
  24. #define DECL_THUNK4(R,n,T1,T2,T3,T4) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d) \
  25. { \
  26. DriverIface *iface = GetThreadDriver(); \
  27. if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
  28. return iface->n(a, b, c, d); \
  29. }
  30. #define DECL_THUNK5(R,n,T1,T2,T3,T4,T5) AL_API R AL_APIENTRY n(T1 a, T2 b, T3 c, T4 d, T5 e) \
  31. { \
  32. DriverIface *iface = GetThreadDriver(); \
  33. if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire); \
  34. return iface->n(a, b, c, d, e); \
  35. }
  36. /* Ugly hack for some apps calling alGetError without a current context, and
  37. * expecting it to be AL_NO_ERROR.
  38. */
  39. AL_API ALenum AL_APIENTRY alGetError(void)
  40. {
  41. DriverIface *iface = GetThreadDriver();
  42. if(!iface) iface = CurrentCtxDriver.load(std::memory_order_acquire);
  43. return iface ? iface->alGetError() : AL_NO_ERROR;
  44. }
  45. DECL_THUNK1(void, alDopplerFactor, ALfloat)
  46. DECL_THUNK1(void, alDopplerVelocity, ALfloat)
  47. DECL_THUNK1(void, alSpeedOfSound, ALfloat)
  48. DECL_THUNK1(void, alDistanceModel, ALenum)
  49. DECL_THUNK1(void, alEnable, ALenum)
  50. DECL_THUNK1(void, alDisable, ALenum)
  51. DECL_THUNK1(ALboolean, alIsEnabled, ALenum)
  52. DECL_THUNK1(const ALchar*, alGetString, ALenum)
  53. DECL_THUNK2(void, alGetBooleanv, ALenum, ALboolean*)
  54. DECL_THUNK2(void, alGetIntegerv, ALenum, ALint*)
  55. DECL_THUNK2(void, alGetFloatv, ALenum, ALfloat*)
  56. DECL_THUNK2(void, alGetDoublev, ALenum, ALdouble*)
  57. DECL_THUNK1(ALboolean, alGetBoolean, ALenum)
  58. DECL_THUNK1(ALint, alGetInteger, ALenum)
  59. DECL_THUNK1(ALfloat, alGetFloat, ALenum)
  60. DECL_THUNK1(ALdouble, alGetDouble, ALenum)
  61. DECL_THUNK1(ALboolean, alIsExtensionPresent, const ALchar*)
  62. DECL_THUNK1(void*, alGetProcAddress, const ALchar*)
  63. DECL_THUNK1(ALenum, alGetEnumValue, const ALchar*)
  64. DECL_THUNK2(void, alListenerf, ALenum, ALfloat)
  65. DECL_THUNK4(void, alListener3f, ALenum, ALfloat, ALfloat, ALfloat)
  66. DECL_THUNK2(void, alListenerfv, ALenum, const ALfloat*)
  67. DECL_THUNK2(void, alListeneri, ALenum, ALint)
  68. DECL_THUNK4(void, alListener3i, ALenum, ALint, ALint, ALint)
  69. DECL_THUNK2(void, alListeneriv, ALenum, const ALint*)
  70. DECL_THUNK2(void, alGetListenerf, ALenum, ALfloat*)
  71. DECL_THUNK4(void, alGetListener3f, ALenum, ALfloat*, ALfloat*, ALfloat*)
  72. DECL_THUNK2(void, alGetListenerfv, ALenum, ALfloat*)
  73. DECL_THUNK2(void, alGetListeneri, ALenum, ALint*)
  74. DECL_THUNK4(void, alGetListener3i, ALenum, ALint*, ALint*, ALint*)
  75. DECL_THUNK2(void, alGetListeneriv, ALenum, ALint*)
  76. DECL_THUNK2(void, alGenSources, ALsizei, ALuint*)
  77. DECL_THUNK2(void, alDeleteSources, ALsizei, const ALuint*)
  78. DECL_THUNK1(ALboolean, alIsSource, ALuint)
  79. DECL_THUNK3(void, alSourcef, ALuint, ALenum, ALfloat)
  80. DECL_THUNK5(void, alSource3f, ALuint, ALenum, ALfloat, ALfloat, ALfloat)
  81. DECL_THUNK3(void, alSourcefv, ALuint, ALenum, const ALfloat*)
  82. DECL_THUNK3(void, alSourcei, ALuint, ALenum, ALint)
  83. DECL_THUNK5(void, alSource3i, ALuint, ALenum, ALint, ALint, ALint)
  84. DECL_THUNK3(void, alSourceiv, ALuint, ALenum, const ALint*)
  85. DECL_THUNK3(void, alGetSourcef, ALuint, ALenum, ALfloat*)
  86. DECL_THUNK5(void, alGetSource3f, ALuint, ALenum, ALfloat*, ALfloat*, ALfloat*)
  87. DECL_THUNK3(void, alGetSourcefv, ALuint, ALenum, ALfloat*)
  88. DECL_THUNK3(void, alGetSourcei, ALuint, ALenum, ALint*)
  89. DECL_THUNK5(void, alGetSource3i, ALuint, ALenum, ALint*, ALint*, ALint*)
  90. DECL_THUNK3(void, alGetSourceiv, ALuint, ALenum, ALint*)
  91. DECL_THUNK2(void, alSourcePlayv, ALsizei, const ALuint*)
  92. DECL_THUNK2(void, alSourceStopv, ALsizei, const ALuint*)
  93. DECL_THUNK2(void, alSourceRewindv, ALsizei, const ALuint*)
  94. DECL_THUNK2(void, alSourcePausev, ALsizei, const ALuint*)
  95. DECL_THUNK1(void, alSourcePlay, ALuint)
  96. DECL_THUNK1(void, alSourceStop, ALuint)
  97. DECL_THUNK1(void, alSourceRewind, ALuint)
  98. DECL_THUNK1(void, alSourcePause, ALuint)
  99. DECL_THUNK3(void, alSourceQueueBuffers, ALuint, ALsizei, const ALuint*)
  100. DECL_THUNK3(void, alSourceUnqueueBuffers, ALuint, ALsizei, ALuint*)
  101. DECL_THUNK2(void, alGenBuffers, ALsizei, ALuint*)
  102. DECL_THUNK2(void, alDeleteBuffers, ALsizei, const ALuint*)
  103. DECL_THUNK1(ALboolean, alIsBuffer, ALuint)
  104. DECL_THUNK3(void, alBufferf, ALuint, ALenum, ALfloat)
  105. DECL_THUNK5(void, alBuffer3f, ALuint, ALenum, ALfloat, ALfloat, ALfloat)
  106. DECL_THUNK3(void, alBufferfv, ALuint, ALenum, const ALfloat*)
  107. DECL_THUNK3(void, alBufferi, ALuint, ALenum, ALint)
  108. DECL_THUNK5(void, alBuffer3i, ALuint, ALenum, ALint, ALint, ALint)
  109. DECL_THUNK3(void, alBufferiv, ALuint, ALenum, const ALint*)
  110. DECL_THUNK3(void, alGetBufferf, ALuint, ALenum, ALfloat*)
  111. DECL_THUNK5(void, alGetBuffer3f, ALuint, ALenum, ALfloat*, ALfloat*, ALfloat*)
  112. DECL_THUNK3(void, alGetBufferfv, ALuint, ALenum, ALfloat*)
  113. DECL_THUNK3(void, alGetBufferi, ALuint, ALenum, ALint*)
  114. DECL_THUNK5(void, alGetBuffer3i, ALuint, ALenum, ALint*, ALint*, ALint*)
  115. DECL_THUNK3(void, alGetBufferiv, ALuint, ALenum, ALint*)
  116. DECL_THUNK5(void, alBufferData, ALuint, ALenum, const ALvoid*, ALsizei, ALsizei)