BsDebug.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "BsDebug.h"
  2. #include "BsLog.h"
  3. #include "BsException.h"
  4. #include "BsBitmapWriter.h"
  5. #include "BsFileSystem.h"
  6. #include "BsDataStream.h"
  7. #include "BsPath.h"
  8. #if BS_PLATFORM == BS_PLATFORM_WIN32 && BS_COMPILER == BS_COMPILER_MSVC
  9. #include <windows.h>
  10. void logToIDEConsole(const BansheeEngine::String& message)
  11. {
  12. OutputDebugString(message.c_str());
  13. OutputDebugString("\n");
  14. }
  15. #else
  16. void logToIDEConsole(const BansheeEngine::String& message)
  17. {
  18. // Do nothing
  19. }
  20. #endif
  21. namespace BansheeEngine
  22. {
  23. void Debug::logDebug(const String& msg)
  24. {
  25. mLog.logMsg(msg, "GlobalDebug");
  26. logToIDEConsole(msg);
  27. }
  28. void Debug::logInfo(const String& msg)
  29. {
  30. mLog.logMsg(msg, "GlobalInfo");
  31. logToIDEConsole(msg);
  32. }
  33. void Debug::logWarning(const String& msg)
  34. {
  35. mLog.logMsg(msg, "GlobalWarning");
  36. logToIDEConsole(msg);
  37. }
  38. void Debug::logError(const String& msg)
  39. {
  40. mLog.logMsg(msg, "GlobalError");
  41. logToIDEConsole(msg);
  42. }
  43. void Debug::log(const String& msg, const String& channel)
  44. {
  45. mLog.logMsg(msg, channel);
  46. logToIDEConsole(msg);
  47. }
  48. void Debug::writeAsBMP(UINT8* rawPixels, UINT32 bytesPerPixel, UINT32 width, UINT32 height, const Path& filePath, bool overwrite) const
  49. {
  50. if(FileSystem::isFile(filePath))
  51. {
  52. if(overwrite)
  53. FileSystem::remove(filePath);
  54. else
  55. BS_EXCEPT(FileNotFoundException, "File already exists at specified location: " + filePath.toString());
  56. }
  57. DataStreamPtr ds = FileSystem::createAndOpenFile(filePath);
  58. UINT32 bmpDataSize = BitmapWriter::getBMPSize(width, height, bytesPerPixel);
  59. UINT8* bmpBuffer = bs_newN<UINT8, ScratchAlloc>(bmpDataSize);
  60. BitmapWriter::rawPixelsToBMP(rawPixels, bmpBuffer, width, height, bytesPerPixel);
  61. ds->write(bmpBuffer, bmpDataSize);
  62. ds->close();
  63. bs_deleteN<ScratchAlloc>(bmpBuffer, bmpDataSize);
  64. }
  65. BS_UTILITY_EXPORT Debug& gDebug()
  66. {
  67. static Debug debug;
  68. return debug;
  69. }
  70. }