platformVideo.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 void resetCanvas();
  55. static bool setScreenMode( U32 width, U32 height, U32 bpp, bool fullScreen );
  56. static void deactivate( bool force = false ); // deactivate current display device
  57. static void reactivate( bool force = false ); // reactivate current display device
  58. static bool setResolution( U32 width, U32 height, U32 bpp ); // set the current resolution
  59. static bool toggleFullScreen(); // toggle full screen mode
  60. static DisplayDevice* getDevice( const char* renderName );
  61. static const char* getDeviceList(); // get a tab-separated list of all the installed display devices
  62. static const char* getResolutionList(); // get a tab-separated list of all the available resolutions for the current device
  63. static const char* getDriverInfo(); // get info about the current display device driver
  64. static bool prevRes(); // switch to the next smaller available resolution with the same bit depth
  65. static bool nextRes(); // switch to the next larger available resolution with the same bit depth
  66. static Resolution getResolution(); // get the current resolution
  67. static Resolution getDesktopResolution(); // get the current desktop resolution
  68. static bool isFullScreen(); // return the current screen state
  69. static void swapBuffers(); // page flip
  70. static bool getGammaCorrection(F32 &g); // get gamma correction
  71. static bool setGammaCorrection(F32 g); // set gamma correction
  72. static bool getVerticalSync(); // get current state of vertical sync
  73. static bool setVerticalSync( bool on ); // enable/disable vertical sync
  74. };
  75. struct Resolution
  76. {
  77. U32 w, h, bpp;
  78. Resolution( U32 _w = 0, U32 _h = 0, U32 _bpp = 0 )
  79. {
  80. w = _w;
  81. h = _h;
  82. bpp = _bpp;
  83. }
  84. bool operator==( const Resolution& otherRes ) const
  85. {
  86. return ( ( w == otherRes.w ) && ( h == otherRes.h ) && ( bpp == otherRes.bpp ) );
  87. }
  88. void operator=( const Resolution& otherRes )
  89. {
  90. w = otherRes.w;
  91. h = otherRes.h;
  92. bpp = otherRes.bpp;
  93. }
  94. };
  95. class DisplayDevice
  96. {
  97. public:
  98. const char* mDeviceName;
  99. protected:
  100. static Resolution smCurrentRes;
  101. static bool smIsFullScreen;
  102. Vector<Resolution> mResolutionList;
  103. bool mFullScreenOnly;
  104. public:
  105. DisplayDevice();
  106. virtual ~DisplayDevice() {}
  107. virtual void initDevice() = 0;
  108. virtual bool activate( U32 width, U32 height, U32 bpp, bool fullScreen ) = 0;
  109. virtual void shutdown() = 0;
  110. virtual bool setScreenMode( U32 width, U32 height, U32 bpp, bool fullScreen, bool forceIt = false, bool repaint = true ) = 0;
  111. virtual bool setResolution( U32 width, U32 height, U32 bpp );
  112. virtual bool toggleFullScreen();
  113. virtual void swapBuffers() = 0;
  114. virtual const char* getDriverInfo() = 0;
  115. virtual bool getGammaCorrection(F32 &g) = 0;
  116. virtual bool setGammaCorrection(F32 g) = 0;
  117. virtual bool getVerticalSync() = 0;
  118. virtual bool setVerticalSync( bool on ) = 0;
  119. bool prevRes();
  120. bool nextRes();
  121. const char* getResolutionList();
  122. bool isFullScreenOnly() { return( mFullScreenOnly ); }
  123. static void init();
  124. static Resolution getResolution();
  125. static bool isFullScreen();
  126. };
  127. //------------------------------------------------------------------------------
  128. inline bool DisplayDevice::setResolution( U32 width, U32 height, U32 bpp )
  129. {
  130. return setScreenMode( width, height, bpp, smIsFullScreen );
  131. }
  132. //------------------------------------------------------------------------------
  133. inline bool DisplayDevice::toggleFullScreen()
  134. {
  135. return setScreenMode( smCurrentRes.w, smCurrentRes.h, smCurrentRes.bpp, !smIsFullScreen );
  136. }
  137. //------------------------------------------------------------------------------
  138. inline Resolution DisplayDevice::getResolution()
  139. {
  140. return smCurrentRes;
  141. }
  142. //------------------------------------------------------------------------------
  143. inline bool DisplayDevice::isFullScreen()
  144. {
  145. return smIsFullScreen;
  146. }
  147. #endif // _H_PLATFORMVIDEO