platformVideo.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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 _PLATFORMVIDEO_H_
  23. #define _PLATFORMVIDEO_H_
  24. #ifndef _TORQUE_TYPES_H_
  25. #include "platform/types.h"
  26. #endif
  27. #ifndef _VECTOR_H_
  28. #include "collection/vector.h"
  29. #endif
  30. #ifndef _PLATFORMASSERT_H_
  31. #include "platform/platformAssert.h"
  32. #endif
  33. enum devices
  34. {
  35. NO_DEVICE = -1,
  36. OPENGL_DEVICE,
  37. VOODOO2_DEVICE,
  38. N_DEVICES
  39. };
  40. struct Resolution;
  41. class DisplayDevice;
  42. class Video
  43. {
  44. private:
  45. static Vector<DisplayDevice *> smDeviceList;
  46. static DisplayDevice* smCurrentDevice;
  47. static bool smCritical;
  48. public:
  49. static bool smNeedResurrect;
  50. static void init();
  51. static void destroy(); // clean up and shut down
  52. static bool installDevice( DisplayDevice *dev );
  53. static bool setDevice( const char *renderName, U32 width, U32 height, U32 bpp, bool fullScreen ); // set the current display device
  54. static bool setScreenMode( U32 width, U32 height, U32 bpp, bool fullScreen );
  55. static void deactivate( bool force = false ); // deactivate current display device
  56. static void reactivate( bool force = false ); // reactivate current display device
  57. static bool setResolution( U32 width, U32 height, U32 bpp ); // set the current resolution
  58. static bool toggleFullScreen(); // toggle full screen mode
  59. static DisplayDevice* getDevice( const char* renderName );
  60. static const char* getDeviceList(); // get a tab-separated list of all the installed display devices
  61. static const char* getResolutionList(); // get a tab-separated list of all the available resolutions for the current device
  62. static const char* getDriverInfo(); // get info about the current display device driver
  63. static bool prevRes(); // switch to the next smaller available resolution with the same bit depth
  64. static bool nextRes(); // switch to the next larger available resolution with the same bit depth
  65. static Resolution getResolution(); // get the current resolution
  66. static Resolution getDesktopResolution(); // get the current desktop resolution
  67. static bool isFullScreen(); // return the current screen state
  68. static void swapBuffers(); // page flip
  69. static bool getGammaCorrection(F32 &g); // get gamma correction
  70. static bool setGammaCorrection(F32 g); // set gamma correction
  71. static bool getVerticalSync(); // get current state of vertical sync
  72. static bool setVerticalSync( bool on ); // enable/disable vertical sync
  73. };
  74. struct Resolution
  75. {
  76. U32 w, h, bpp;
  77. Resolution( U32 _w = 0, U32 _h = 0, U32 _bpp = 0 )
  78. {
  79. w = _w;
  80. h = _h;
  81. bpp = _bpp;
  82. }
  83. bool operator==( const Resolution& otherRes ) const
  84. {
  85. return ( ( w == otherRes.w ) && ( h == otherRes.h ) && ( bpp == otherRes.bpp ) );
  86. }
  87. void operator=( const Resolution& otherRes )
  88. {
  89. w = otherRes.w;
  90. h = otherRes.h;
  91. bpp = otherRes.bpp;
  92. }
  93. };
  94. class DisplayDevice
  95. {
  96. public:
  97. const char* mDeviceName;
  98. protected:
  99. static Resolution smCurrentRes;
  100. static bool smIsFullScreen;
  101. Vector<Resolution> mResolutionList;
  102. bool mFullScreenOnly;
  103. public:
  104. DisplayDevice();
  105. virtual ~DisplayDevice() {}
  106. virtual void initDevice() = 0;
  107. virtual bool activate( U32 width, U32 height, U32 bpp, bool fullScreen ) = 0;
  108. virtual void shutdown() = 0;
  109. virtual bool setScreenMode( U32 width, U32 height, U32 bpp, bool fullScreen, bool forceIt = false, bool repaint = true ) = 0;
  110. virtual bool setResolution( U32 width, U32 height, U32 bpp );
  111. virtual bool toggleFullScreen();
  112. virtual void swapBuffers() = 0;
  113. virtual const char* getDriverInfo() = 0;
  114. virtual bool getGammaCorrection(F32 &g) = 0;
  115. virtual bool setGammaCorrection(F32 g) = 0;
  116. virtual bool getVerticalSync() = 0;
  117. virtual bool setVerticalSync( bool on ) = 0;
  118. bool prevRes();
  119. bool nextRes();
  120. const char* getResolutionList();
  121. bool isFullScreenOnly() { return( mFullScreenOnly ); }
  122. static void init();
  123. static Resolution getResolution();
  124. static bool isFullScreen();
  125. };
  126. //------------------------------------------------------------------------------
  127. inline bool DisplayDevice::setResolution( U32 width, U32 height, U32 bpp )
  128. {
  129. return setScreenMode( width, height, bpp, smIsFullScreen );
  130. }
  131. //------------------------------------------------------------------------------
  132. inline bool DisplayDevice::toggleFullScreen()
  133. {
  134. return setScreenMode( smCurrentRes.w, smCurrentRes.h, smCurrentRes.bpp, !smIsFullScreen );
  135. }
  136. //------------------------------------------------------------------------------
  137. inline Resolution DisplayDevice::getResolution()
  138. {
  139. return smCurrentRes;
  140. }
  141. //------------------------------------------------------------------------------
  142. inline bool DisplayDevice::isFullScreen()
  143. {
  144. return smIsFullScreen;
  145. }
  146. #endif // _H_PLATFORMVIDEO