mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 23:25:40 +12:00
PicaVertex -> PICA::Vertex
This commit is contained in:
parent
b403e9a66e
commit
a3d8f777b4
6 changed files with 43 additions and 41 deletions
|
@ -28,7 +28,7 @@ class GPU {
|
||||||
std::array<vec4f, 16> currentAttributes; // Vertex attributes before being passed to the shader
|
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<vec4f, 16> immediateModeAttributes; // Vertex attributes uploaded via immediate mode submission
|
||||||
std::array<PicaVertex, 3> immediateModeVertices;
|
std::array<PICA::Vertex, 3> immediateModeVertices;
|
||||||
uint immediateModeVertIndex;
|
uint immediateModeVertIndex;
|
||||||
uint immediateModeAttrIndex; // Index of the immediate mode attribute we're uploading
|
uint immediateModeAttrIndex; // Index of the immediate mode attribute we're uploading
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class GPU {
|
||||||
u32* cmdBuffCurr = nullptr;
|
u32* cmdBuffCurr = nullptr;
|
||||||
|
|
||||||
Renderer renderer;
|
Renderer renderer;
|
||||||
PicaVertex getImmediateModeVertex();
|
PICA::Vertex getImmediateModeVertex();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// 256 entries per LUT with each LUT as its own row forming a 2D image 256 * LUT_COUNT
|
// 256 entries per LUT with each LUT as its own row forming a 2D image 256 * LUT_COUNT
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
#include "PICA/float_types.hpp"
|
#include "PICA/float_types.hpp"
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
namespace PICA {
|
||||||
// A representation of the output vertex as it comes out of the vertex shader, with padding and all
|
// A representation of the output vertex as it comes out of the vertex shader, with padding and all
|
||||||
struct PicaVertex {
|
struct Vertex {
|
||||||
using vec2f = std::array<Floats::f24, 2>;
|
using vec2f = std::array<Floats::f24, 2>;
|
||||||
using vec3f = std::array<Floats::f24, 3>;
|
using vec3f = std::array<Floats::f24, 3>;
|
||||||
using vec4f = std::array<Floats::f24, 4>;
|
using vec4f = std::array<Floats::f24, 4>;
|
||||||
|
@ -26,11 +27,12 @@ struct PicaVertex {
|
||||||
// The software, non-accelerated vertex loader writes here and then reads specific components from the above struct
|
// The software, non-accelerated vertex loader writes here and then reads specific components from the above struct
|
||||||
Floats::f24 raw[0x20];
|
Floats::f24 raw[0x20];
|
||||||
};
|
};
|
||||||
PicaVertex() {}
|
Vertex() {}
|
||||||
};
|
};
|
||||||
|
} // 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
|
// 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(positions, 0)
|
||||||
ASSERT_POS(quaternion, 4)
|
ASSERT_POS(quaternion, 4)
|
||||||
|
|
|
@ -91,7 +91,7 @@ class Renderer {
|
||||||
void getGraphicsContext(); // Set up graphics context for rendering
|
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 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 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) {
|
void setFBSize(u32 width, u32 height) {
|
||||||
fbSize.x() = width;
|
fbSize.x() = width;
|
||||||
|
|
|
@ -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>
|
template <bool indexed, bool useShaderJIT>
|
||||||
void GPU::drawArrays() {
|
void GPU::drawArrays() {
|
||||||
|
@ -249,7 +249,7 @@ void GPU::drawArrays() {
|
||||||
shaderUnit.vs.run();
|
shaderUnit.vs.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
PicaVertex& out = vertices[i];
|
PICA::Vertex& out = vertices[i];
|
||||||
// Map shader outputs to fixed function properties
|
// Map shader outputs to fixed function properties
|
||||||
const u32 totalShaderOutputs = regs[PICA::InternalRegs::ShaderOutputCount] & 7;
|
const u32 totalShaderOutputs = regs[PICA::InternalRegs::ShaderOutputCount] & 7;
|
||||||
for (int i = 0; i < totalShaderOutputs; i++) {
|
for (int i = 0; i < totalShaderOutputs; i++) {
|
||||||
|
@ -265,8 +265,8 @@ void GPU::drawArrays() {
|
||||||
renderer.drawVertices(primType, std::span(vertices).first(vertexCount));
|
renderer.drawVertices(primType, std::span(vertices).first(vertexCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
PicaVertex GPU::getImmediateModeVertex() {
|
PICA::Vertex GPU::getImmediateModeVertex() {
|
||||||
PicaVertex v;
|
PICA::Vertex v;
|
||||||
const int totalAttrCount = (regs[PICA::InternalRegs::VertexShaderAttrNum] & 0xf) + 1;
|
const int totalAttrCount = (regs[PICA::InternalRegs::VertexShaderAttrNum] & 0xf) + 1;
|
||||||
|
|
||||||
// Copy immediate mode attributes to vertex shader unit
|
// Copy immediate mode attributes to vertex shader unit
|
||||||
|
|
|
@ -188,7 +188,7 @@ void GPU::writeInternalReg(u32 index, u32 value, u32 mask) {
|
||||||
|
|
||||||
immediateModeAttributes[immediateModeAttrIndex++] = attr;
|
immediateModeAttributes[immediateModeAttrIndex++] = attr;
|
||||||
if (immediateModeAttrIndex == totalAttrCount) {
|
if (immediateModeAttrIndex == totalAttrCount) {
|
||||||
PicaVertex v = getImmediateModeVertex();
|
PICA::Vertex v = getImmediateModeVertex();
|
||||||
immediateModeAttrIndex = 0;
|
immediateModeAttrIndex = 0;
|
||||||
immediateModeVertices[immediateModeVertIndex++] = v;
|
immediateModeVertices[immediateModeVertIndex++] = v;
|
||||||
|
|
||||||
|
|
|
@ -645,34 +645,34 @@ void Renderer::initGraphicsContext() {
|
||||||
displayProgram.use();
|
displayProgram.use();
|
||||||
glUniform1i(OpenGL::uniformLocation(displayProgram, "u_texture"), 0); // Init sampler object
|
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();
|
vbo.bind();
|
||||||
vao.create();
|
vao.create();
|
||||||
vao.bind();
|
vao.bind();
|
||||||
|
|
||||||
// Position (x, y, z, w) attributes
|
// 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);
|
vao.enableAttribute(0);
|
||||||
// Quaternion attribute
|
// 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);
|
vao.enableAttribute(1);
|
||||||
// Colour attribute
|
// 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);
|
vao.enableAttribute(2);
|
||||||
// UV 0 attribute
|
// 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);
|
vao.enableAttribute(3);
|
||||||
// UV 1 attribute
|
// 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);
|
vao.enableAttribute(4);
|
||||||
// UV 0 W-component attribute
|
// 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);
|
vao.enableAttribute(5);
|
||||||
// View
|
// 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);
|
vao.enableAttribute(6);
|
||||||
// UV 2 attribute
|
// 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);
|
vao.enableAttribute(7);
|
||||||
|
|
||||||
dummyVBO.create();
|
dummyVBO.create();
|
||||||
|
@ -842,7 +842,7 @@ void Renderer::updateLightingLUT(){
|
||||||
gpu.lightingLUTDirty = false;
|
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
|
// The fourth type is meant to be "Geometry primitive". TODO: Find out what that is
|
||||||
static constexpr std::array<OpenGL::Primitives, 4> primTypes = {
|
static constexpr std::array<OpenGL::Primitives, 4> primTypes = {
|
||||||
OpenGL::Triangle, OpenGL::TriangleStrip, OpenGL::TriangleFan, OpenGL::Triangle
|
OpenGL::Triangle, OpenGL::TriangleStrip, OpenGL::TriangleFan, OpenGL::Triangle
|
||||||
|
|
Loading…
Add table
Reference in a new issue