nxdk_pgraph_tests
A collection of tests for the Xbox nv2a graphics processor
 
Loading...
Searching...
No Matches
test_host.h
1#ifndef NXDK_PGRAPH_TESTS_TEST_HOST_H
2#define NXDK_PGRAPH_TESTS_TEST_HOST_H
3
4#include <debug_output.h>
5#include <ftp_logger.h>
6#include <pbkit/pbkit.h>
7#include <printf/printf.h>
8
9#include <cstdint>
10#include <memory>
11
12#include "nv2astate.h"
13#include "nxdk_ext.h"
14#include "pushbuffer.h"
15#include "string"
16#include "texture_format.h"
17#include "texture_stage.h"
18#include "vertex_buffer.h"
19#include "xbox_math_types.h"
20
21using namespace XboxMath;
22using namespace PBKitPlusPlus;
23
24namespace PBKitPlusPlus {
25class VertexShaderProgram;
26struct Vertex;
27class VertexBuffer;
28} // namespace PBKitPlusPlus
29
33class TestHost : public NV2AState {
34 public:
35 TestHost(std::shared_ptr<FTPLogger> ftp_logger, uint32_t framebuffer_width, uint32_t framebuffer_height,
36 uint32_t max_texture_width, uint32_t max_texture_height, uint32_t max_texture_depth = 4);
37
39 void FinishDraw(bool allow_saving, const std::string &output_directory, const std::string &suite_name,
40 const std::string &name, bool save_zbuffer = false);
41
43 [[nodiscard]] bool GetSaveResults() const { return save_results_; }
45 void SetSaveResults(bool enable = true) { save_results_ = enable; }
46
47 [[nodiscard]] std::shared_ptr<FTPLogger> GetFTPLogger() const { return ftp_logger_; }
48
50 static std::string SaveTexture(const std::string &output_directory, const std::string &name, const uint8_t *texture,
51 uint32_t width, uint32_t height, uint32_t pitch, uint32_t bits_per_pixel,
52 SDL_PixelFormatEnum format);
54 static std::string SaveRawTexture(const std::string &output_directory, const std::string &name,
55 const uint8_t *texture, uint32_t width, uint32_t height, uint32_t pitch,
56 uint32_t bits_per_pixel);
58 [[nodiscard]] std::string SaveZBuffer(const std::string &output_directory, const std::string &name) const;
59
61 static void EnsureFolderExists(const std::string &folder_path);
62
64 inline float CenterX(float item_width, bool pixel_align = true) {
65 float ret = (GetFramebufferWidthF() - item_width) * 0.5f;
66 if (pixel_align) {
67 return floorf(ret);
68 }
69
70 return ret;
71 }
72
74 inline float CenterY(float item_height, bool pixel_align = true) {
75 float ret = (GetFramebufferHeightF() - item_height) * 0.5f;
76 if (pixel_align) {
77 return floorf(ret);
78 }
79 return ret;
80 }
81
83 static std::string GetDrawPrimitiveName(DrawPrimitive primitive);
84
85 private:
86 static std::string PrepareSaveFile(std::string output_directory, const std::string &filename,
87 const std::string &ext = ".png");
88 static std::string SaveBackBuffer(const std::string &output_directory, const std::string &name);
89
90 private:
91 bool save_results_{true};
92
93 std::shared_ptr<FTPLogger> ftp_logger_;
94};
95
96#endif // NXDK_PGRAPH_TESTS_TEST_HOST_H
Definition test_host.h:33
static std::string SaveRawTexture(const std::string &output_directory, const std::string &name, const uint8_t *texture, uint32_t width, uint32_t height, uint32_t pitch, uint32_t bits_per_pixel)
Saves the given region of memory as a flat binary file.
Definition test_host.cpp:205
float CenterY(float item_height, bool pixel_align=true)
Returns a Y coordinate sufficient to center a primitive with the given height within the framebuffer.
Definition test_host.h:74
bool GetSaveResults() const
Returns the current override flag to allow/prevent artifact saving.
Definition test_host.h:43
static void EnsureFolderExists(const std::string &folder_path)
Creates the given directory if it does not already exist.
Definition test_host.cpp:75
static std::string SaveTexture(const std::string &output_directory, const std::string &name, const uint8_t *texture, uint32_t width, uint32_t height, uint32_t pitch, uint32_t bits_per_pixel, SDL_PixelFormatEnum format)
Saves the given texture to the filesystem as a PNG file.
Definition test_host.cpp:181
float CenterX(float item_width, bool pixel_align=true)
Returns an X coordinate sufficient to center a primitive with the given width within the framebuffer.
Definition test_host.h:64
void FinishDraw(bool allow_saving, const std::string &output_directory, const std::string &suite_name, const std::string &name, bool save_zbuffer=false)
Marks drawing as completed, potentially causing artifacts (framebuffer, z/stencil-buffer) to be saved...
Definition test_host.cpp:231
void SetSaveResults(bool enable=true)
Sets the override flag to prevent artifact saving during FinishDraw.
Definition test_host.h:45
std::string SaveZBuffer(const std::string &output_directory, const std::string &name) const
Saves the Z/Stencil buffer to the filesystem/.
Definition test_host.cpp:168
static std::string GetDrawPrimitiveName(DrawPrimitive primitive)
Returns a string name for the given DrawPrimitive.
Definition test_host.cpp:270