nxdk_pgraph_tests
A collection of tests for the Xbox nv2a graphics processor
 
Loading...
Searching...
No Matches
vertex_shader_program.h
1#ifndef NXDK_PGRAPH_TESTS_VERTEX_SHADER_PROGRAM_H
2#define NXDK_PGRAPH_TESTS_VERTEX_SHADER_PROGRAM_H
3
4#include <cstdint>
5#include <map>
6#include <vector>
7
8#include "xbox_math_types.h"
9
14 public:
15 // The offset into the constant table of the first user-defined constant.
16 static constexpr auto kShaderUserConstantOffset = 96;
17
18 public:
19 VertexShaderProgram() = default;
20 virtual ~VertexShaderProgram() = default;
21
22 void Activate();
23 void PrepareDraw();
24
25 // Note: It is the caller's responsibility to ensure that the shader array remains valid for the lifetime of this
26 // instance.
27 void SetShaderOverride(const uint32_t *shader, uint32_t shader_size) {
28 shader_override_ = shader;
29 shader_override_size_ = shader_size;
30 }
31
32 void SetUniform4x4F(uint32_t slot, const XboxMath::matrix4_t &value);
33 void SetUniform4F(uint32_t slot, const float *value);
34 void SetUniform4I(uint32_t slot, const uint32_t *value);
35
36 void SetUniformF(uint32_t slot, float x, float y = 0.0f, float z = 0.0f, float w = 0.0f);
37 void SetUniformI(uint32_t slot, uint32_t x, uint32_t y = 0, uint32_t z = 0, uint32_t w = 0);
38
39 protected:
41 uint32_t x, y, z, w;
42 };
43
44 protected:
45 virtual void OnActivate() {}
46 virtual void OnLoadShader() {}
47 virtual void OnLoadConstants() {};
48
49 void LoadShaderProgram(const uint32_t *shader, uint32_t shader_size) const;
50
51 void SetTransformConstantBlock(std::map<uint32_t, TransformConstant> &constants_map, uint32_t slot,
52 const uint32_t *values, uint32_t num_slots);
53
54 void SetBaseUniform4x4F(uint32_t slot, const XboxMath::matrix4_t &value);
55 void SetBaseUniform4F(uint32_t slot, const float *value);
56 void SetBaseUniform4I(uint32_t slot, const uint32_t *value);
57
58 void SetBaseUniformF(uint32_t slot, float x, float y = 0.0f, float z = 0.0f, float w = 0.0f);
59 void SetBaseUniformI(uint32_t slot, uint32_t x, uint32_t y = 0, uint32_t z = 0, uint32_t w = 0);
60
61 void UploadConstants();
62
63 protected:
66 const uint32_t *shader_override_{nullptr};
67 uint32_t shader_override_size_{0};
68
70 // Note: Use of registers before 96 is reserved as the fixed function pipeline
71 // appears to make use of them (overwriting c0-c14 at least breaks tests that
72 // use the FF pipeline).
73 std::map<uint32_t, TransformConstant> base_transform_constants_;
74
78 std::map<uint32_t, TransformConstant> uniforms_;
79
80 bool uniform_upload_required_{true};
81};
82
83#endif // NXDK_PGRAPH_TESTS_VERTEX_SHADER_PROGRAM_H
Definition vertex_shader_program.h:13
const uint32_t * shader_override_
Definition vertex_shader_program.h:66
std::map< uint32_t, TransformConstant > uniforms_
Definition vertex_shader_program.h:78
std::map< uint32_t, TransformConstant > base_transform_constants_
Map of index to constants that will be loaded starting at c[96].
Definition vertex_shader_program.h:73
Definition vertex_shader_program.h:40