cardProfile.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #include "core/strings/stringFunctions.h"
  23. #include "console/console.h"
  24. #include "platformWin32/platformWin32.h"
  25. void initDisplayDeviceInfo()
  26. {
  27. Con::printf( "Reading Display Device information..." );
  28. U8 i = 0;
  29. DISPLAY_DEVICEA ddData;
  30. ddData.cb = sizeof( DISPLAY_DEVICEA );
  31. // Search for the primary display adapter, because that is what the rendering
  32. // context will get created on.
  33. while( EnumDisplayDevicesA( NULL, i, &ddData, 0 ) != 0 )
  34. {
  35. // If we find the primary display adapter, break out
  36. if( ddData.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE )
  37. break;
  38. i++;
  39. }
  40. Con::printf( " Primary Display Device Found:" );
  41. // Ok, now we have the primary display device. Parse the device information.
  42. char ven[9];
  43. char dev[9];
  44. ven[8] = dev[8] = '\0';
  45. // It may seem a bit silly here to cast, but there are two implimentations in Platform.h
  46. // This usage is the "const" version...
  47. char *pos = dStrstr( ddData.DeviceID, (const char *)"VEN_");
  48. dStrncpy( ven, ( pos ) ? pos : "VEN_0000", 8 );
  49. Con::printf( " Vendor Id: %s", ven );
  50. pos = dStrstr( ddData.DeviceID, (const char *)"DEV_" );
  51. dStrncpy( dev, ( pos ) ? pos : "DEV_0000", 8 );
  52. Con::printf( " Device Id: %s", dev );
  53. // We now have the information, set them to console variables so we can parse
  54. // the file etc in script using getField and so on.
  55. Con::setVariable( "$PCI_VEN", ven );
  56. Con::setVariable( "$PCI_DEV", dev );
  57. }
  58. ConsoleFunction( initDisplayDeviceInfo, void, 1, 1, "()"
  59. "@brief Initializes variables that track device and vendor information/IDs\n\n"
  60. "@ingroup Rendering")
  61. {
  62. initDisplayDeviceInfo();
  63. }