sfxProvider.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SFXPROVIDER_H_
  23. #define _SFXPROVIDER_H_
  24. #ifndef _TVECTOR_H_
  25. #include "core/util/tVector.h"
  26. #endif
  27. class SFXDevice;
  28. struct SFXDeviceInfo
  29. {
  30. String driver;
  31. String internalName;
  32. String name;
  33. bool hasHardware;
  34. S32 maxBuffers;
  35. virtual ~SFXDeviceInfo() {}
  36. };
  37. typedef Vector<SFXDeviceInfo*> SFXDeviceInfoVector;
  38. class SFXProvider
  39. {
  40. friend class SFXSystem;
  41. private:
  42. /// The head of the linked list of avalible providers.
  43. static SFXProvider* smProviders;
  44. /// The next provider in the linked list of available providers.
  45. SFXProvider* mNextProvider;
  46. /// The provider name which is passed by the concrete provider
  47. /// class to the SFXProvider constructor.
  48. String mName;
  49. static Vector<SFXProvider*> sAllProviders;
  50. protected:
  51. /// The array of avaIlable devices from this provider. The
  52. /// concrete provider class will fill this on construction.
  53. SFXDeviceInfoVector mDeviceInfo;
  54. /// This registers the provider to the available provider list. It should be called
  55. /// for providers that are properly initialized and available for device enumeration and creation.
  56. /// the add and registration process is 2 steps to avoid issues when TGEA is used as a shared library (specifically on Windows)
  57. static void regProvider( SFXProvider* provider );
  58. virtual void init() = 0;
  59. SFXProvider( const String& name );
  60. ~SFXProvider();
  61. /// Look up the SFXDeviceInfo for the given device in mDeviceInfo.
  62. /// Return default device (first in list) if no other device matches (or null if device list is empty).
  63. SFXDeviceInfo* _findDeviceInfo( const String& deviceName );
  64. /// This is called from SFXSystem to create a new device. Must be implemented
  65. /// by all contrete provider classes.
  66. ///
  67. /// @param deviceName The case sensitive name of the device or NULL to create the
  68. // default device.
  69. /// @param useHardware Toggles the use of hardware processing when available.
  70. /// @param maxBuffers The maximum buffers for this device to use or -1
  71. /// for the device to pick a reasonable default for that device.
  72. ///
  73. /// @return Returns the created device or NULL for failure.
  74. ///
  75. virtual SFXDevice* createDevice( const String& deviceName, bool useHardware, S32 maxBuffers ) = 0;
  76. public:
  77. /// Returns a specific provider by searching the provider list
  78. /// for the first provider with the case sensitive name.
  79. static SFXProvider* findProvider( String providerName );
  80. /// Returns the first provider in the provider list. Use
  81. /// getNextProvider() to iterate over list.
  82. static SFXProvider* getFirstProvider() { return smProviders; }
  83. /// Returns the next provider in the provider list or NULL
  84. /// when the end of the list is reached.
  85. SFXProvider* getNextProvider() const { return mNextProvider; }
  86. /// The case sensitive name of this provider.
  87. const String& getName() const { return mName; }
  88. /// Returns a read only vector with device information for
  89. /// all creatable devices available from this provider.
  90. const SFXDeviceInfoVector& getDeviceInfo() const { return mDeviceInfo; }
  91. static void initializeAllProviders();
  92. };
  93. #endif // _SFXPROVIDER_H_