CmDebug.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "CmDebug.h"
  2. #include "CmLog.h"
  3. #include "CmException.h"
  4. #include "CmBitmapWriter.h"
  5. #include "CmFileSystem.h"
  6. #include "CmDataStream.h"
  7. #include "CmPath.h"
  8. namespace BansheeEngine
  9. {
  10. void Debug::logDebug(const String& msg)
  11. {
  12. mLog.logMsg(msg, "GlobalDebug");
  13. }
  14. void Debug::logInfo(const String& msg)
  15. {
  16. mLog.logMsg(msg, "GlobalInfo");
  17. }
  18. void Debug::logWarning(const String& msg)
  19. {
  20. mLog.logMsg(msg, "GlobalWarning");
  21. }
  22. void Debug::logError(const String& msg)
  23. {
  24. mLog.logMsg(msg, "GlobalError");
  25. }
  26. void Debug::log(const String& msg, const String& channel)
  27. {
  28. mLog.logMsg(msg, channel);
  29. }
  30. void Debug::writeAsBMP(UINT8* rawPixels, UINT32 bytesPerPixel, UINT32 width, UINT32 height, const Path& filePath, bool overwrite) const
  31. {
  32. if(FileSystem::isFile(filePath))
  33. {
  34. if(overwrite)
  35. FileSystem::remove(filePath);
  36. else
  37. CM_EXCEPT(FileNotFoundException, "File already exists at specified location: " + filePath.toString());
  38. }
  39. DataStreamPtr ds = FileSystem::createAndOpenFile(filePath);
  40. UINT32 bmpDataSize = BitmapWriter::getBMPSize(width, height, bytesPerPixel);
  41. UINT8* bmpBuffer = cm_newN<UINT8, ScratchAlloc>(bmpDataSize);
  42. BitmapWriter::rawPixelsToBMP(rawPixels, bmpBuffer, width, height, bytesPerPixel);
  43. ds->write(bmpBuffer, bmpDataSize);
  44. ds->close();
  45. cm_deleteN<ScratchAlloc>(bmpBuffer, bmpDataSize);
  46. }
  47. CM_UTILITY_EXPORT Debug& gDebug()
  48. {
  49. static Debug debug;
  50. return debug;
  51. }
  52. }