mirror of https://git.suyu.dev/suyu/suyu
Pica: Add debug utility functions for dumping geometry data.
parent
14b24a75b3
commit
6ea003c7b5
@ -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
|
@ -0,0 +1,40 @@
|
||||
// Copyright 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
#include "video_core/pica.h"
|
||||
|
||||
namespace Pica {
|
||||
|
||||
namespace DebugUtils {
|
||||
|
||||
using TriangleTopology = Regs::TriangleTopology;
|
||||
|
||||
// Simple utility class for dumping geometry data to an OBJ file
|
||||
class GeometryDumper {
|
||||
public:
|
||||
void AddVertex(std::array<float,3> pos, TriangleTopology topology);
|
||||
|
||||
void Dump();
|
||||
|
||||
private:
|
||||
struct Vertex {
|
||||
std::array<float,3> pos;
|
||||
};
|
||||
|
||||
struct Face {
|
||||
int index[3];
|
||||
};
|
||||
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<Face> faces;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
} // namespace
|
Loading…
Reference in New Issue