PicaVertex -> PICA::Vertex

This commit is contained in:
wheremyfoodat 2023-07-04 23:37:48 +03:00
parent b403e9a66e
commit a3d8f777b4
6 changed files with 43 additions and 41 deletions

View file

@ -28,7 +28,7 @@ class GPU {
std::array<vec4f, 16> currentAttributes; // Vertex attributes before being passed to the shader
std::array<vec4f, 16> immediateModeAttributes; // Vertex attributes uploaded via immediate mode submission
std::array<PicaVertex, 3> immediateModeVertices;
std::array<PICA::Vertex, 3> immediateModeVertices;
uint immediateModeVertIndex;
uint immediateModeAttrIndex; // Index of the immediate mode attribute we're uploading
@ -68,7 +68,7 @@ class GPU {
u32* cmdBuffCurr = nullptr;
Renderer renderer;
PicaVertex getImmediateModeVertex();
PICA::Vertex getImmediateModeVertex();
public:
// 256 entries per LUT with each LUT as its own row forming a 2D image 256 * LUT_COUNT

View file

@ -2,35 +2,37 @@
#include "PICA/float_types.hpp"
#include <array>
// A representation of the output vertex as it comes out of the vertex shader, with padding and all
struct PicaVertex {
using vec2f = std::array<Floats::f24, 2>;
using vec3f = std::array<Floats::f24, 3>;
using vec4f = std::array<Floats::f24, 4>;
namespace PICA {
// A representation of the output vertex as it comes out of the vertex shader, with padding and all
struct Vertex {
using vec2f = std::array<Floats::f24, 2>;
using vec3f = std::array<Floats::f24, 3>;
using vec4f = std::array<Floats::f24, 4>;
union {
struct {
vec4f positions; // Vertex position
vec4f quaternion; // Quaternion specifying the normal/tangent frame (for fragment lighting)
vec4f colour; // Vertex color
vec2f texcoord0; // Texcoords for texture unit 0 (Only U and V, W is stored separately for 3D textures!)
vec2f texcoord1; // Texcoords for TU 1
Floats::f24 texcoord0_w; // W component for texcoord 0 if using a 3D texture
u32 padding; // Unused
union {
struct {
vec4f positions; // Vertex position
vec4f quaternion; // Quaternion specifying the normal/tangent frame (for fragment lighting)
vec4f colour; // Vertex color
vec2f texcoord0; // Texcoords for texture unit 0 (Only U and V, W is stored separately for 3D textures!)
vec2f texcoord1; // Texcoords for TU 1
Floats::f24 texcoord0_w; // W component for texcoord 0 if using a 3D texture
u32 padding; // Unused
vec3f view; // View vector (for fragment lighting)
u32 padding2; // Unused
vec2f texcoord2; // Texcoords for TU 2
} s;
vec3f view; // View vector (for fragment lighting)
u32 padding2; // Unused
vec2f texcoord2; // Texcoords for TU 2
} s;
// The software, non-accelerated vertex loader writes here and then reads specific components from the above struct
Floats::f24 raw[0x20];
// The software, non-accelerated vertex loader writes here and then reads specific components from the above struct
Floats::f24 raw[0x20];
};
Vertex() {}
};
PicaVertex() {}
};
} // namespace PICA
// Float is used here instead of Floats::f24 to ensure that Floats::f24 is properly sized for direct interpretations as a float by the render backend
#define ASSERT_POS(member, pos) static_assert(offsetof(PicaVertex, s.member) == pos * sizeof(float), "PicaVertex struct is broken!");
#define ASSERT_POS(member, pos) static_assert(offsetof(PICA::Vertex, s.member) == pos * sizeof(float), "PICA::Vertex struct is broken!");
ASSERT_POS(positions, 0)
ASSERT_POS(quaternion, 4)

View file

@ -91,7 +91,7 @@ class Renderer {
void getGraphicsContext(); // Set up graphics context for rendering
void clearBuffer(u32 startAddress, u32 endAddress, u32 value, u32 control); // Clear a GPU buffer in VRAM
void displayTransfer(u32 inputAddr, u32 outputAddr, u32 inputSize, u32 outputSize, u32 flags); // Perform display transfer
void drawVertices(PICA::PrimType primType, std::span<const PicaVertex> vertices); // Draw the given vertices
void drawVertices(PICA::PrimType primType, std::span<const PICA::Vertex> vertices); // Draw the given vertices
void setFBSize(u32 width, u32 height) {
fbSize.x() = width;

View file

@ -61,7 +61,7 @@ void GPU::drawArrays(bool indexed) {
}
}
static std::array<PicaVertex, Renderer::vertexBufferSize> vertices;
static std::array<PICA::Vertex, Renderer::vertexBufferSize> vertices;
template <bool indexed, bool useShaderJIT>
void GPU::drawArrays() {
@ -249,7 +249,7 @@ void GPU::drawArrays() {
shaderUnit.vs.run();
}
PicaVertex& out = vertices[i];
PICA::Vertex& out = vertices[i];
// Map shader outputs to fixed function properties
const u32 totalShaderOutputs = regs[PICA::InternalRegs::ShaderOutputCount] & 7;
for (int i = 0; i < totalShaderOutputs; i++) {
@ -265,8 +265,8 @@ void GPU::drawArrays() {
renderer.drawVertices(primType, std::span(vertices).first(vertexCount));
}
PicaVertex GPU::getImmediateModeVertex() {
PicaVertex v;
PICA::Vertex GPU::getImmediateModeVertex() {
PICA::Vertex v;
const int totalAttrCount = (regs[PICA::InternalRegs::VertexShaderAttrNum] & 0xf) + 1;
// Copy immediate mode attributes to vertex shader unit

View file

@ -188,7 +188,7 @@ void GPU::writeInternalReg(u32 index, u32 value, u32 mask) {
immediateModeAttributes[immediateModeAttrIndex++] = attr;
if (immediateModeAttrIndex == totalAttrCount) {
PicaVertex v = getImmediateModeVertex();
PICA::Vertex v = getImmediateModeVertex();
immediateModeAttrIndex = 0;
immediateModeVertices[immediateModeVertIndex++] = v;

View file

@ -645,34 +645,34 @@ void Renderer::initGraphicsContext() {
displayProgram.use();
glUniform1i(OpenGL::uniformLocation(displayProgram, "u_texture"), 0); // Init sampler object
vbo.createFixedSize(sizeof(PicaVertex) * vertexBufferSize, GL_STREAM_DRAW);
vbo.createFixedSize(sizeof(Vertex) * vertexBufferSize, GL_STREAM_DRAW);
vbo.bind();
vao.create();
vao.bind();
// Position (x, y, z, w) attributes
vao.setAttributeFloat<float>(0, 4, sizeof(PicaVertex), offsetof(PicaVertex, s.positions));
vao.setAttributeFloat<float>(0, 4, sizeof(Vertex), offsetof(Vertex, s.positions));
vao.enableAttribute(0);
// Quaternion attribute
vao.setAttributeFloat<float>(1, 4, sizeof(PicaVertex), offsetof(PicaVertex, s.quaternion));
vao.setAttributeFloat<float>(1, 4, sizeof(Vertex), offsetof(Vertex, s.quaternion));
vao.enableAttribute(1);
// Colour attribute
vao.setAttributeFloat<float>(2, 4, sizeof(PicaVertex), offsetof(PicaVertex, s.colour));
vao.setAttributeFloat<float>(2, 4, sizeof(Vertex), offsetof(Vertex, s.colour));
vao.enableAttribute(2);
// UV 0 attribute
vao.setAttributeFloat<float>(3, 2, sizeof(PicaVertex), offsetof(PicaVertex, s.texcoord0));
vao.setAttributeFloat<float>(3, 2, sizeof(Vertex), offsetof(Vertex, s.texcoord0));
vao.enableAttribute(3);
// UV 1 attribute
vao.setAttributeFloat<float>(4, 2, sizeof(PicaVertex), offsetof(PicaVertex, s.texcoord1));
vao.setAttributeFloat<float>(4, 2, sizeof(Vertex), offsetof(Vertex, s.texcoord1));
vao.enableAttribute(4);
// UV 0 W-component attribute
vao.setAttributeFloat<float>(5, 1, sizeof(PicaVertex), offsetof(PicaVertex, s.texcoord0_w));
vao.setAttributeFloat<float>(5, 1, sizeof(Vertex), offsetof(Vertex, s.texcoord0_w));
vao.enableAttribute(5);
// View
vao.setAttributeFloat<float>(6, 3, sizeof(PicaVertex), offsetof(PicaVertex, s.view));
vao.setAttributeFloat<float>(6, 3, sizeof(Vertex), offsetof(Vertex, s.view));
vao.enableAttribute(6);
// UV 2 attribute
vao.setAttributeFloat<float>(7, 2, sizeof(PicaVertex), offsetof(PicaVertex, s.texcoord2));
vao.setAttributeFloat<float>(7, 2, sizeof(Vertex), offsetof(Vertex, s.texcoord2));
vao.enableAttribute(7);
dummyVBO.create();
@ -842,7 +842,7 @@ void Renderer::updateLightingLUT(){
gpu.lightingLUTDirty = false;
}
void Renderer::drawVertices(PICA::PrimType primType, std::span<const PicaVertex> vertices) {
void Renderer::drawVertices(PICA::PrimType primType, std::span<const Vertex> vertices) {
// The fourth type is meant to be "Geometry primitive". TODO: Find out what that is
static constexpr std::array<OpenGL::Primitives, 4> primTypes = {
OpenGL::Triangle, OpenGL::TriangleStrip, OpenGL::TriangleFan, OpenGL::Triangle