platformVideo.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 setVerticalSync( bool on ); // enable/disable vertical sync
  72. };
  73. struct Resolution
  74. {
  75. U32 w, h, bpp;
  76. Resolution( U32 _w = 0, U32 _h = 0, U32 _bpp = 0 )
  77. {
  78. w = _w;
  79. h = _h;
  80. bpp = _bpp;
  81. }
  82. bool operator==( const Resolution& otherRes ) const
  83. {
  84. return ( ( w == otherRes.w ) && ( h == otherRes.h ) && ( bpp == otherRes.bpp ) );
  85. }
  86. void operator=( const Resolution& otherRes )
  87. {
  88. w = otherRes.w;
  89. h = otherRes.h;
  90. bpp = otherRes.bpp;
  91. }
  92. };
  93. class DisplayDevice
  94. {
  95. public:
  96. const char* mDeviceName;
  97. protected:
  98. static Resolution smCurrentRes;
  99. static bool smIsFullScreen;
  100. Vector<Resolution> mResolutionList;
  101. bool mFullScreenOnly;
  102. public:
  103. DisplayDevice();
  104. virtual ~DisplayDevice() {}
  105. virtual void initDevice() = 0;
  106. virtual bool activate( U32 width, U32 height, U32 bpp, bool fullScreen ) = 0;
  107. virtual void shutdown() = 0;
  108. virtual bool setScreenMode( U32 width, U32 height, U32 bpp, bool fullScreen, bool forceIt = false, bool repaint = true ) = 0;
  109. virtual bool setResolution( U32 width, U32 height, U32 bpp );
  110. virtual bool toggleFullScreen();
  111. virtual void swapBuffers() = 0;
  112. virtual const char* getDriverInfo() = 0;
  113. virtual bool getGammaCorrection(F32 &g) = 0;
  114. virtual bool setGammaCorrection(F32 g) = 0;
  115. virtual bool setVerticalSync( bool on ) = 0;
  116. bool prevRes();
  117. bool nextRes();
  118. const char* getResolutionList();
  119. bool isFullScreenOnly() { return( mFullScreenOnly ); }
  120. static void init();
  121. static Resolution getResolution();
  122. static bool isFullScreen();
  123. };
  124. //------------------------------------------------------------------------------
  125. inline bool DisplayDevice::setResolution( U32 width, U32 height, U32 bpp )
  126. {
  127. return setScreenMode( width, height, bpp, smIsFullScreen );
  128. }
  129. //------------------------------------------------------------------------------
  130. inline bool DisplayDevice::toggleFullScreen()
  131. {
  132. return setScreenMode( smCurrentRes.w, smCurrentRes.h, smCurrentRes.bpp, !smIsFullScreen );
  133. }
  134. //------------------------------------------------------------------------------
  135. inline Resolution DisplayDevice::getResolution()
  136. {
  137. return smCurrentRes;
  138. }
  139. //------------------------------------------------------------------------------
  140. inline bool DisplayDevice::isFullScreen()
  141. {
  142. return smIsFullScreen;
  143. }
  144. #endif // _H_PLATFORMVIDEO