sfxProvider.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 name;
  32. bool hasHardware;
  33. S32 maxBuffers;
  34. virtual ~SFXDeviceInfo() {}
  35. };
  36. typedef Vector<SFXDeviceInfo*> SFXDeviceInfoVector;
  37. class SFXProvider
  38. {
  39. friend class SFXSystem;
  40. private:
  41. /// The head of the linked list of avalible providers.
  42. static SFXProvider* smProviders;
  43. /// The next provider in the linked list of available providers.
  44. SFXProvider* mNextProvider;
  45. /// The provider name which is passed by the concrete provider
  46. /// class to the SFXProvider constructor.
  47. String mName;
  48. static Vector<SFXProvider*> sAllProviders;
  49. protected:
  50. /// The array of avaIlable devices from this provider. The
  51. /// concrete provider class will fill this on construction.
  52. SFXDeviceInfoVector mDeviceInfo;
  53. /// This registers the provider to the available provider list. It should be called
  54. /// for providers that are properly initialized and available for device enumeration and creation.
  55. /// the add and registration process is 2 steps to avoid issues when TGEA is used as a shared library (specifically on Windows)
  56. static void regProvider( SFXProvider* provider );
  57. virtual void init() = 0;
  58. SFXProvider( const String& name );
  59. ~SFXProvider();
  60. /// Look up the SFXDeviceInfo for the given device in mDeviceInfo.
  61. /// Return default device (first in list) if no other device matches (or null if device list is empty).
  62. SFXDeviceInfo* _findDeviceInfo( const String& deviceName );
  63. /// This is called from SFXSystem to create a new device. Must be implemented
  64. /// by all contrete provider classes.
  65. ///
  66. /// @param deviceName The case sensitive name of the device or NULL to create the
  67. // default device.
  68. /// @param useHardware Toggles the use of hardware processing when available.
  69. /// @param maxBuffers The maximum buffers for this device to use or -1
  70. /// for the device to pick a reasonable default for that device.
  71. ///
  72. /// @return Returns the created device or NULL for failure.
  73. ///
  74. virtual SFXDevice* createDevice( const String& deviceName, bool useHardware, S32 maxBuffers ) = 0;
  75. public:
  76. /// Returns a specific provider by searching the provider list
  77. /// for the first provider with the case sensitive name.
  78. static SFXProvider* findProvider( String providerName );
  79. /// Returns the first provider in the provider list. Use
  80. /// getNextProvider() to iterate over list.
  81. static SFXProvider* getFirstProvider() { return smProviders; }
  82. /// Returns the next provider in the provider list or NULL
  83. /// when the end of the list is reached.
  84. SFXProvider* getNextProvider() const { return mNextProvider; }
  85. /// The case sensitive name of this provider.
  86. const String& getName() const { return mName; }
  87. /// Returns a read only vector with device information for
  88. /// all creatable devices available from this provider.
  89. const SFXDeviceInfoVector& getDeviceInfo() const { return mDeviceInfo; }
  90. static void initializeAllProviders();
  91. };
  92. #endif // _SFXPROVIDER_H_