debug_utils.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #include <fstream>
  5. #include <string>
  6. #include "video_core/pica.h"
  7. #include "debug_utils.h"
  8. namespace Pica {
  9. namespace DebugUtils {
  10. void GeometryDumper::AddVertex(std::array<float,3> pos, TriangleTopology topology) {
  11. vertices.push_back({pos[0], pos[1], pos[2]});
  12. int num_vertices = vertices.size();
  13. switch (topology) {
  14. case TriangleTopology::List:
  15. case TriangleTopology::ListIndexed:
  16. if (0 == (num_vertices % 3))
  17. faces.push_back({ num_vertices-3, num_vertices-2, num_vertices-1 });
  18. break;
  19. default:
  20. ERROR_LOG(GPU, "Unknown triangle topology %x", (int)topology);
  21. exit(0);
  22. break;
  23. }
  24. }
  25. void GeometryDumper::Dump() {
  26. // NOTE: Permanently enabling this just trashes hard disks for no reason.
  27. // Hence, this is currently disabled.
  28. return;
  29. static int index = 0;
  30. std::string filename = std::string("geometry_dump") + std::to_string(++index) + ".obj";
  31. std::ofstream file(filename);
  32. for (const auto& vertex : vertices) {
  33. file << "v " << vertex.pos[0]
  34. << " " << vertex.pos[1]
  35. << " " << vertex.pos[2] << std::endl;
  36. }
  37. for (const Face& face : faces) {
  38. file << "f " << 1+face.index[0]
  39. << " " << 1+face.index[1]
  40. << " " << 1+face.index[2] << std::endl;
  41. }
  42. }
  43. } // namespace
  44. } // namespace