winVideo.cc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #include "winVideo.h"
  23. bool WinDisplayDevice::smCanSwitchBitDepth = false;
  24. bool WinDisplayDevice::smCanDo16Bit = false;
  25. bool WinDisplayDevice::smCanDo32Bit = false;
  26. WinDisplayDevice::WinDisplayDevice()
  27. {
  28. mRestoreGamma = false;
  29. }
  30. void WinDisplayDevice::enumerateBitDepths()
  31. {
  32. // Enumerate all available resolutions:
  33. DEVMODE devMode;
  34. U32 modeNum = 0;
  35. U32 foundDisplayMode = true;
  36. while ( foundDisplayMode )
  37. {
  38. // Clear out our display mode settings structure.
  39. dMemset( &devMode, 0, sizeof( devMode ) );
  40. devMode.dmSize = sizeof( devMode );
  41. // Check for display mode settings
  42. foundDisplayMode = EnumDisplaySettings( NULL, modeNum++, &devMode );
  43. //MIN_RESOLUTION defined in platformWin32/platformGL.h
  44. if ( devMode.dmPelsWidth >= MIN_RESOLUTION_X && devMode.dmPelsHeight >= MIN_RESOLUTION_Y && ( devMode.dmBitsPerPel == 16 || devMode.dmBitsPerPel == 32 ) )
  45. {
  46. // Note BPP for can switch bit depth.
  47. if( devMode.dmBitsPerPel == 16 )
  48. smCanDo16Bit = true;
  49. else if( devMode.dmBitsPerPel == 32 )
  50. smCanDo32Bit = true;
  51. }
  52. }
  53. // Set can switch bit depth based on found resolutions.
  54. if( smCanDo16Bit && smCanDo32Bit )
  55. smCanSwitchBitDepth = true;
  56. else
  57. smCanSwitchBitDepth = false;
  58. }
  59. void WinDisplayDevice::initDevice()
  60. {
  61. // Set some initial conditions:
  62. mResolutionList.clear();
  63. // Enumerate all available resolutions:
  64. DEVMODE devMode;
  65. U32 modeNum = 0;
  66. U32 foundDisplayMode = true;
  67. while ( foundDisplayMode )
  68. {
  69. // Clear out our display mode settings structure.
  70. dMemset( &devMode, 0, sizeof( devMode ) );
  71. devMode.dmSize = sizeof( devMode );
  72. // Check for display mode settings
  73. foundDisplayMode = EnumDisplaySettings( NULL, modeNum++, &devMode );
  74. if ( devMode.dmPelsWidth >= MIN_RESOLUTION_X && devMode.dmPelsHeight >= MIN_RESOLUTION_Y && ( devMode.dmBitsPerPel == 16 || devMode.dmBitsPerPel == 32 ) )
  75. {
  76. // Only add this resolution if it is not already in the list:
  77. bool alreadyInList = false;
  78. for ( U32 i = 0; i < (U32)mResolutionList.size(); i++ )
  79. {
  80. if ( devMode.dmPelsWidth == mResolutionList[i].w
  81. && devMode.dmPelsHeight == mResolutionList[i].h
  82. && devMode.dmBitsPerPel == mResolutionList[i].bpp )
  83. {
  84. alreadyInList = true;
  85. break;
  86. }
  87. }
  88. // If we've not already added this resolution, add it to our resolution list.
  89. if ( !alreadyInList )
  90. {
  91. Resolution newRes( devMode.dmPelsWidth, devMode.dmPelsHeight, devMode.dmBitsPerPel );
  92. mResolutionList.push_back( newRes );
  93. }
  94. }
  95. }
  96. }