gfxInit.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 _GFXINIT_H_
  23. #define _GFXINIT_H_
  24. #ifndef _GFXDEVICE_H_
  25. #include "gfx/gfxDevice.h"
  26. #endif
  27. #ifndef _ENGINEOBJECT_H_
  28. #include "console/engineObject.h"
  29. #endif
  30. /// Interface for tracking GFX adapters and initializing them into devices.
  31. /// @note Implement this class per platform.
  32. /// @note This is just a class so it can be friends with GFXDevice)
  33. class GFXInit
  34. {
  35. DECLARE_STATIC_CLASS( GFXInit );
  36. public:
  37. /// Allows device to register themselves as available
  38. typedef Signal<void (Vector<GFXAdapter*>&)> RegisterDeviceSignal;
  39. static RegisterDeviceSignal& getRegisterDeviceSignal();
  40. /// Prepares the adapter list.
  41. static void init();
  42. /// Cleans out the adapter list.
  43. static void cleanup();
  44. /// Creates a GFXDevice based on an adapter from the
  45. /// enumerateAdapters method.
  46. ///
  47. /// @param adapter Graphics adapter to create device
  48. static GFXDevice *createDevice( GFXAdapter *adapter );
  49. /// Enumerate all the graphics adapters on the system
  50. static void enumerateAdapters();
  51. /// Get the enumerated adapters. Should only call this after
  52. /// a call to enumerateAdapters.
  53. static void getAdapters( Vector<GFXAdapter*> *adapters );
  54. /// Get the number of available adapters.
  55. static S32 getAdapterCount();
  56. /// Compares the adapter's output display device with the given output display device
  57. static bool compareAdapterOutputDevice(const GFXAdapter* adapter, const char* outputDevice);
  58. /// Chooses a suitable GFXAdapter, based on type, preferences, and fallbacks.
  59. /// If the requested type is omitted, we use the prefs value.
  60. /// If the requested type isn't found, we use fallbacks: OpenGL, NullDevice
  61. /// This method never returns NULL.
  62. static GFXAdapter *chooseAdapter( GFXAdapterType type, const char* outputDevice);
  63. /// Override which chooses an adapter based on an index instead
  64. static GFXAdapter *chooseAdapter( GFXAdapterType type, S32 outputDeviceIndex );
  65. /// Gets the first adapter of the requested type (and on the requested output device)
  66. /// from the list of enumerated adapters. Should only call this after a call to
  67. /// enumerateAdapters.
  68. static GFXAdapter *getAdapterOfType( GFXAdapterType type, const char* outputDevice );
  69. /// Override which gets an adapter based on an index instead
  70. static GFXAdapter *getAdapterOfType( GFXAdapterType type, S32 outputDeviceIndex );
  71. /// Converts a GFXAdapterType to a string name. Useful for writing out prefs
  72. static const char *getAdapterNameFromType( GFXAdapterType type );
  73. /// Converts a string to a GFXAdapterType. Useful for reading in prefs.
  74. static GFXAdapterType getAdapterTypeFromName( const char* name );
  75. /// Returns a GFXVideoMode that describes the current state of the main monitor.
  76. /// This should probably move to the abstract window manager
  77. static GFXVideoMode getDesktopResolution();
  78. /// Based on user preferences (or in the absence of a valid user selection,
  79. /// a heuristic), return a "best" adapter.
  80. static GFXAdapter *getBestAdapterChoice();
  81. /// Get the initial video mode based on user preferences (or a heuristic).
  82. static GFXVideoMode getInitialVideoMode();
  83. private:
  84. /// List of known adapters.
  85. static Vector<GFXAdapter*> smAdapters;
  86. static RegisterDeviceSignal* smRegisterDeviceSignal;
  87. };
  88. #endif