aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/video_core/debug_utils/debug_utils.cpp
diff options
context:
space:
mode:
authorGravatar Tony Wasserka <NeoBrainX@gmail.com>2014-08-17 14:06:58 +0200
committerGravatar Tony Wasserka <NeoBrainX@gmail.com>2014-08-25 22:03:18 +0200
commit6ea003c7b5ec97d0a754197654cdf6e7fccdba24 (patch)
treeb565322792f592bc2708a969cb395bc0679fe018 /src/video_core/debug_utils/debug_utils.cpp
parent14b24a75b37545faf49584864cb85555f22a0154 (diff)
Pica: Add debug utility functions for dumping geometry data.
Diffstat (limited to 'src/video_core/debug_utils/debug_utils.cpp')
-rw-r--r--src/video_core/debug_utils/debug_utils.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp
new file mode 100644
index 00000000..ac895ec3
--- /dev/null
+++ b/src/video_core/debug_utils/debug_utils.cpp
@@ -0,0 +1,60 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#include <fstream>
+#include <string>
+
+#include "video_core/pica.h"
+
+#include "debug_utils.h"
+
+namespace Pica {
+
+namespace DebugUtils {
+
+void GeometryDumper::AddVertex(std::array<float,3> pos, TriangleTopology topology) {
+ vertices.push_back({pos[0], pos[1], pos[2]});
+
+ int num_vertices = vertices.size();
+
+ switch (topology) {
+ case TriangleTopology::List:
+ case TriangleTopology::ListIndexed:
+ if (0 == (num_vertices % 3))
+ faces.push_back({ num_vertices-3, num_vertices-2, num_vertices-1 });
+ break;
+
+ default:
+ ERROR_LOG(GPU, "Unknown triangle topology %x", (int)topology);
+ exit(0);
+ break;
+ }
+}
+
+void GeometryDumper::Dump() {
+ // NOTE: Permanently enabling this just trashes hard disks for no reason.
+ // Hence, this is currently disabled.
+ return;
+
+ static int index = 0;
+ std::string filename = std::string("geometry_dump") + std::to_string(++index) + ".obj";
+
+ std::ofstream file(filename);
+
+ for (const auto& vertex : vertices) {
+ file << "v " << vertex.pos[0]
+ << " " << vertex.pos[1]
+ << " " << vertex.pos[2] << std::endl;
+ }
+
+ for (const Face& face : faces) {
+ file << "f " << 1+face.index[0]
+ << " " << 1+face.index[1]
+ << " " << 1+face.index[2] << std::endl;
+ }
+}
+
+} // namespace
+
+} // namespace