CmDebug.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 "CmPixelData.h"
  8. #include "CmPixelUtil.h"
  9. namespace CamelotEngine
  10. {
  11. void Debug::logDebug(std::string msg)
  12. {
  13. mLog.logMsg(msg, "GlobalDebug");
  14. }
  15. void Debug::logInfo(std::string msg)
  16. {
  17. mLog.logMsg(msg, "GlobalInfo");
  18. }
  19. void Debug::logWarning(std::string msg)
  20. {
  21. mLog.logMsg(msg, "GlobalWarning");
  22. }
  23. void Debug::logError(std::string msg)
  24. {
  25. mLog.logMsg(msg, "GlobalError");
  26. }
  27. void Debug::log(const String& msg, const String& channel)
  28. {
  29. mLog.logMsg(msg, channel);
  30. }
  31. void Debug::writeAsBMP(const PixelData& pixelData, const String& filePath, bool overwrite) const
  32. {
  33. if(FileSystem::fileExists(filePath))
  34. {
  35. if(overwrite)
  36. FileSystem::remove(filePath);
  37. else
  38. CM_EXCEPT(FileNotFoundException, "File already exists at specified location: " + filePath);
  39. }
  40. DataStreamPtr ds = FileSystem::create(filePath);
  41. UINT32 bytesPerPixel = PixelUtil::getNumElemBytes(pixelData.format);
  42. UINT32 bmpDataSize = BitmapWriter::getBMPSize(pixelData.getWidth(), pixelData.getHeight(), bytesPerPixel);
  43. UINT8* bmpBuffer = new UINT8[bmpDataSize];
  44. BitmapWriter::rawPixelsToBMP((UINT8*)pixelData.data, bmpBuffer, pixelData.getWidth(), pixelData.getHeight(), bytesPerPixel);
  45. ds->write(bmpBuffer, bmpDataSize);
  46. ds->close();
  47. delete [] bmpBuffer;
  48. }
  49. CM_UTILITY_EXPORT Debug& gDebug()
  50. {
  51. static Debug debug;
  52. return debug;
  53. }
  54. }