summaryrefslogtreecommitdiff
path: root/src/video_core/debug_utils
diff options
context:
space:
mode:
authorGravatar Tony Wasserka2014-08-17 14:06:58 +0200
committerGravatar Tony Wasserka2014-08-25 22:03:18 +0200
commit6ea003c7b5ec97d0a754197654cdf6e7fccdba24 (patch)
treeb565322792f592bc2708a969cb395bc0679fe018 /src/video_core/debug_utils
parentGSP: Update framebuffer information when necessary. (diff)
downloadyuzu-6ea003c7b5ec97d0a754197654cdf6e7fccdba24.tar.gz
yuzu-6ea003c7b5ec97d0a754197654cdf6e7fccdba24.tar.xz
yuzu-6ea003c7b5ec97d0a754197654cdf6e7fccdba24.zip
Pica: Add debug utility functions for dumping geometry data.
Diffstat (limited to 'src/video_core/debug_utils')
-rw-r--r--src/video_core/debug_utils/debug_utils.cpp60
-rw-r--r--src/video_core/debug_utils/debug_utils.h40
2 files changed, 100 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 000000000..ac895ec3a
--- /dev/null
+++ b/src/video_core/debug_utils/debug_utils.cpp
@@ -0,0 +1,60 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include <fstream>
6#include <string>
7
8#include "video_core/pica.h"
9
10#include "debug_utils.h"
11
12namespace Pica {
13
14namespace DebugUtils {
15
16void GeometryDumper::AddVertex(std::array<float,3> pos, TriangleTopology topology) {
17 vertices.push_back({pos[0], pos[1], pos[2]});
18
19 int num_vertices = vertices.size();
20
21 switch (topology) {
22 case TriangleTopology::List:
23 case TriangleTopology::ListIndexed:
24 if (0 == (num_vertices % 3))
25 faces.push_back({ num_vertices-3, num_vertices-2, num_vertices-1 });
26 break;
27
28 default:
29 ERROR_LOG(GPU, "Unknown triangle topology %x", (int)topology);
30 exit(0);
31 break;
32 }
33}
34
35void GeometryDumper::Dump() {
36 // NOTE: Permanently enabling this just trashes hard disks for no reason.
37 // Hence, this is currently disabled.
38 return;
39
40 static int index = 0;
41 std::string filename = std::string("geometry_dump") + std::to_string(++index) + ".obj";
42
43 std::ofstream file(filename);
44
45 for (const auto& vertex : vertices) {
46 file << "v " << vertex.pos[0]
47 << " " << vertex.pos[1]
48 << " " << vertex.pos[2] << std::endl;
49 }
50
51 for (const Face& face : faces) {
52 file << "f " << 1+face.index[0]
53 << " " << 1+face.index[1]
54 << " " << 1+face.index[2] << std::endl;
55 }
56}
57
58} // namespace
59
60} // namespace
diff --git a/src/video_core/debug_utils/debug_utils.h b/src/video_core/debug_utils/debug_utils.h
new file mode 100644
index 000000000..9b4dce539
--- /dev/null
+++ b/src/video_core/debug_utils/debug_utils.h
@@ -0,0 +1,40 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <array>
8#include <vector>
9
10#include "video_core/pica.h"
11
12namespace Pica {
13
14namespace DebugUtils {
15
16using TriangleTopology = Regs::TriangleTopology;
17
18// Simple utility class for dumping geometry data to an OBJ file
19class GeometryDumper {
20public:
21 void AddVertex(std::array<float,3> pos, TriangleTopology topology);
22
23 void Dump();
24
25private:
26 struct Vertex {
27 std::array<float,3> pos;
28 };
29
30 struct Face {
31 int index[3];
32 };
33
34 std::vector<Vertex> vertices;
35 std::vector<Face> faces;
36};
37
38} // namespace
39
40} // namespace