diff --git a/include/PICA/gpu.hpp b/include/PICA/gpu.hpp index c2fbc1c6..5bc06c47 100644 --- a/include/PICA/gpu.hpp +++ b/include/PICA/gpu.hpp @@ -28,7 +28,7 @@ class GPU { std::array currentAttributes; // Vertex attributes before being passed to the shader std::array immediateModeAttributes; // Vertex attributes uploaded via immediate mode submission - std::array immediateModeVertices; + std::array 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 diff --git a/include/PICA/pica_vertex.hpp b/include/PICA/pica_vertex.hpp index ea90796b..800dff9a 100644 --- a/include/PICA/pica_vertex.hpp +++ b/include/PICA/pica_vertex.hpp @@ -2,35 +2,37 @@ #include "PICA/float_types.hpp" #include -// A representation of the output vertex as it comes out of the vertex shader, with padding and all -struct PicaVertex { - using vec2f = std::array; - using vec3f = std::array; - using vec4f = std::array; +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; + using vec3f = std::array; + using vec4f = std::array; - 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) diff --git a/include/renderer_gl/renderer_gl.hpp b/include/renderer_gl/renderer_gl.hpp index 0bf9b0a3..b5ac8758 100644 --- a/include/renderer_gl/renderer_gl.hpp +++ b/include/renderer_gl/renderer_gl.hpp @@ -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 vertices); // Draw the given vertices + void drawVertices(PICA::PrimType primType, std::span vertices); // Draw the given vertices void setFBSize(u32 width, u32 height) { fbSize.x() = width; diff --git a/src/core/PICA/gpu.cpp b/src/core/PICA/gpu.cpp index 43bcf674..a3163f86 100644 --- a/src/core/PICA/gpu.cpp +++ b/src/core/PICA/gpu.cpp @@ -61,7 +61,7 @@ void GPU::drawArrays(bool indexed) { } } -static std::array vertices; +static std::array vertices; template 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 diff --git a/src/core/PICA/regs.cpp b/src/core/PICA/regs.cpp index a0eb5adc..f62040dd 100644 --- a/src/core/PICA/regs.cpp +++ b/src/core/PICA/regs.cpp @@ -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; diff --git a/src/core/renderer_gl/renderer_gl.cpp b/src/core/renderer_gl/renderer_gl.cpp index 589457f5..de8a7375 100644 --- a/src/core/renderer_gl/renderer_gl.cpp +++ b/src/core/renderer_gl/renderer_gl.cpp @@ -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(0, 4, sizeof(PicaVertex), offsetof(PicaVertex, s.positions)); + vao.setAttributeFloat(0, 4, sizeof(Vertex), offsetof(Vertex, s.positions)); vao.enableAttribute(0); // Quaternion attribute - vao.setAttributeFloat(1, 4, sizeof(PicaVertex), offsetof(PicaVertex, s.quaternion)); + vao.setAttributeFloat(1, 4, sizeof(Vertex), offsetof(Vertex, s.quaternion)); vao.enableAttribute(1); // Colour attribute - vao.setAttributeFloat(2, 4, sizeof(PicaVertex), offsetof(PicaVertex, s.colour)); + vao.setAttributeFloat(2, 4, sizeof(Vertex), offsetof(Vertex, s.colour)); vao.enableAttribute(2); // UV 0 attribute - vao.setAttributeFloat(3, 2, sizeof(PicaVertex), offsetof(PicaVertex, s.texcoord0)); + vao.setAttributeFloat(3, 2, sizeof(Vertex), offsetof(Vertex, s.texcoord0)); vao.enableAttribute(3); // UV 1 attribute - vao.setAttributeFloat(4, 2, sizeof(PicaVertex), offsetof(PicaVertex, s.texcoord1)); + vao.setAttributeFloat(4, 2, sizeof(Vertex), offsetof(Vertex, s.texcoord1)); vao.enableAttribute(4); // UV 0 W-component attribute - vao.setAttributeFloat(5, 1, sizeof(PicaVertex), offsetof(PicaVertex, s.texcoord0_w)); + vao.setAttributeFloat(5, 1, sizeof(Vertex), offsetof(Vertex, s.texcoord0_w)); vao.enableAttribute(5); // View - vao.setAttributeFloat(6, 3, sizeof(PicaVertex), offsetof(PicaVertex, s.view)); + vao.setAttributeFloat(6, 3, sizeof(Vertex), offsetof(Vertex, s.view)); vao.enableAttribute(6); // UV 2 attribute - vao.setAttributeFloat(7, 2, sizeof(PicaVertex), offsetof(PicaVertex, s.texcoord2)); + vao.setAttributeFloat(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 vertices) { +void Renderer::drawVertices(PICA::PrimType primType, std::span vertices) { // The fourth type is meant to be "Geometry primitive". TODO: Find out what that is static constexpr std::array primTypes = { OpenGL::Triangle, OpenGL::TriangleStrip, OpenGL::TriangleFan, OpenGL::Triangle