mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-05-18 01:33:58 +12:00
Migrate PICA-types into PICA
namespace
Rather than prefixing these types with `PICA`, a namespace is used instead.
This commit is contained in:
parent
78a3f9fa23
commit
838d3f27f9
7 changed files with 204 additions and 201 deletions
|
@ -47,7 +47,7 @@ class GPU {
|
||||||
};
|
};
|
||||||
|
|
||||||
u64 getVertexShaderInputConfig() {
|
u64 getVertexShaderInputConfig() {
|
||||||
return u64(regs[PICAInternalRegs::VertexShaderInputCfgLow]) | (u64(regs[PICAInternalRegs::VertexShaderInputCfgHigh]) << 32);
|
return u64(regs[PICA::InternalRegs::VertexShaderInputCfgLow]) | (u64(regs[PICA::InternalRegs::VertexShaderInputCfgHigh]) << 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<AttribInfo, maxAttribCount> attributeInfo; // Info for each of the 12 attributes
|
std::array<AttribInfo, maxAttribCount> attributeInfo; // Info for each of the 12 attributes
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "helpers.hpp"
|
#include "helpers.hpp"
|
||||||
|
|
||||||
namespace PICAInternalRegs {
|
namespace PICA {
|
||||||
|
namespace InternalRegs {
|
||||||
enum : u32 {
|
enum : u32 {
|
||||||
// Rasterizer registers
|
// Rasterizer registers
|
||||||
ViewportWidth = 0x41,
|
ViewportWidth = 0x41,
|
||||||
|
@ -129,7 +130,7 @@ namespace PICAInternalRegs {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class PICAColorFmt : u32 {
|
enum class ColorFmt : u32 {
|
||||||
RGBA8 = 0,
|
RGBA8 = 0,
|
||||||
BGR8 = 1,
|
BGR8 = 1,
|
||||||
RGB5A1 = 2,
|
RGB5A1 = 2,
|
||||||
|
@ -142,7 +143,7 @@ enum class PICAColorFmt : u32 {
|
||||||
Unknown7 = 7,
|
Unknown7 = 7,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class PICADepthFmt : u32 {
|
enum class DepthFmt : u32 {
|
||||||
Depth16 = 0,
|
Depth16 = 0,
|
||||||
Unknown1 = 1, // Technically selectable, but function is unknown
|
Unknown1 = 1, // Technically selectable, but function is unknown
|
||||||
Depth24 = 2,
|
Depth24 = 2,
|
||||||
|
@ -152,26 +153,28 @@ enum class PICADepthFmt : u32 {
|
||||||
// Size occupied by each pixel in bytes
|
// Size occupied by each pixel in bytes
|
||||||
|
|
||||||
// All formats are 16BPP except for RGBA8 (32BPP) and BGR8 (24BPP)
|
// All formats are 16BPP except for RGBA8 (32BPP) and BGR8 (24BPP)
|
||||||
inline constexpr usize sizePerPixel(PICAColorFmt format) {
|
inline constexpr usize sizePerPixel(ColorFmt format) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case PICAColorFmt::BGR8: return 3;
|
case ColorFmt::BGR8: return 3;
|
||||||
case PICAColorFmt::RGBA8: return 4;
|
case ColorFmt::RGBA8: return 4;
|
||||||
default: return 2;
|
default: return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline constexpr usize sizePerPixel(PICADepthFmt format) {
|
inline constexpr usize sizePerPixel(DepthFmt format) {
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case PICADepthFmt::Depth16: return 2;
|
case DepthFmt::Depth16: return 2;
|
||||||
case PICADepthFmt::Depth24: return 3;
|
case DepthFmt::Depth24: return 3;
|
||||||
case PICADepthFmt::Depth24Stencil8: return 4;
|
case DepthFmt::Depth24Stencil8: return 4;
|
||||||
default: return 1; // Invalid format
|
default: return 1; // Invalid format
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class PICAPrimType : u32 {
|
enum class PrimType : u32 {
|
||||||
TriangleList = 0,
|
TriangleList = 0,
|
||||||
TriangleStrip = 1,
|
TriangleStrip = 1,
|
||||||
TriangleFan = 2,
|
TriangleFan = 2,
|
||||||
GeometryPrimitive = 3,
|
GeometryPrimitive = 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace PICA
|
|
@ -47,11 +47,11 @@ class Renderer {
|
||||||
OpenGL::uvec2 fbSize; // The size of the framebuffer (ie both the colour and depth buffer)'
|
OpenGL::uvec2 fbSize; // The size of the framebuffer (ie both the colour and depth buffer)'
|
||||||
|
|
||||||
u32 colourBufferLoc; // Location in 3DS VRAM for the colour buffer
|
u32 colourBufferLoc; // Location in 3DS VRAM for the colour buffer
|
||||||
PICAColorFmt colourBufferFormat; // Format of the colours stored in the colour buffer
|
PICA::ColorFmt colourBufferFormat; // Format of the colours stored in the colour buffer
|
||||||
|
|
||||||
// Same for the depth/stencil buffer
|
// Same for the depth/stencil buffer
|
||||||
u32 depthBufferLoc;
|
u32 depthBufferLoc;
|
||||||
PICADepthFmt depthBufferFormat;
|
PICA::DepthFmt depthBufferFormat;
|
||||||
|
|
||||||
// Dummy VAO/VBO for blitting the final output
|
// Dummy VAO/VBO for blitting the final output
|
||||||
OpenGL::VertexArray dummyVAO;
|
OpenGL::VertexArray dummyVAO;
|
||||||
|
@ -76,16 +76,16 @@ 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(PICAPrimType primType, std::span<const Vertex> vertices); // Draw the given vertices
|
void drawVertices(PICA::PrimType primType, std::span<const Vertex> vertices); // Draw the given vertices
|
||||||
|
|
||||||
void setFBSize(u32 width, u32 height) {
|
void setFBSize(u32 width, u32 height) {
|
||||||
fbSize.x() = width;
|
fbSize.x() = width;
|
||||||
fbSize.y() = height;
|
fbSize.y() = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setColourFormat(PICAColorFmt format) { colourBufferFormat = format; }
|
void setColourFormat(PICA::ColorFmt format) { colourBufferFormat = format; }
|
||||||
void setDepthFormat(PICADepthFmt format) {
|
void setDepthFormat(PICA::DepthFmt format) {
|
||||||
if (format == PICADepthFmt::Unknown1) {
|
if (format == PICA::DepthFmt::Unknown1) {
|
||||||
Helpers::panic("[PICA] Undocumented depth-stencil mode!");
|
Helpers::panic("[PICA] Undocumented depth-stencil mode!");
|
||||||
}
|
}
|
||||||
depthBufferFormat = format;
|
depthBufferFormat = format;
|
||||||
|
|
|
@ -9,7 +9,7 @@ using Interval = boost::icl::right_open_interval<T>;
|
||||||
|
|
||||||
struct ColourBuffer {
|
struct ColourBuffer {
|
||||||
u32 location;
|
u32 location;
|
||||||
PICAColorFmt format;
|
PICA::ColorFmt format;
|
||||||
OpenGL::uvec2 size;
|
OpenGL::uvec2 size;
|
||||||
bool valid;
|
bool valid;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ struct ColourBuffer {
|
||||||
|
|
||||||
ColourBuffer() : valid(false) {}
|
ColourBuffer() : valid(false) {}
|
||||||
|
|
||||||
ColourBuffer(u32 loc, PICAColorFmt format, u32 x, u32 y, bool valid = true)
|
ColourBuffer(u32 loc, PICA::ColorFmt format, u32 x, u32 y, bool valid = true)
|
||||||
: location(loc), format(format), size({x, y}), valid(valid) {
|
: location(loc), format(format), size({x, y}), valid(valid) {
|
||||||
|
|
||||||
u64 endLoc = (u64)loc + sizeInBytes();
|
u64 endLoc = (u64)loc + sizeInBytes();
|
||||||
|
@ -70,13 +70,13 @@ struct ColourBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t sizeInBytes() {
|
size_t sizeInBytes() {
|
||||||
return (size_t)size.x() * (size_t)size.y() * sizePerPixel(format);
|
return (size_t)size.x() * (size_t)size.y() * PICA::sizePerPixel(format);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DepthBuffer {
|
struct DepthBuffer {
|
||||||
u32 location;
|
u32 location;
|
||||||
PICADepthFmt format;
|
PICA::DepthFmt format;
|
||||||
OpenGL::uvec2 size; // Implicitly set to the size of the framebuffer
|
OpenGL::uvec2 size; // Implicitly set to the size of the framebuffer
|
||||||
bool valid;
|
bool valid;
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ struct DepthBuffer {
|
||||||
|
|
||||||
DepthBuffer() : valid(false) {}
|
DepthBuffer() : valid(false) {}
|
||||||
|
|
||||||
DepthBuffer(u32 loc, PICADepthFmt format, u32 x, u32 y, bool valid = true) :
|
DepthBuffer(u32 loc, PICA::DepthFmt format, u32 x, u32 y, bool valid = true) :
|
||||||
location(loc), format(format), size({x, y}), valid(valid) {
|
location(loc), format(format), size({x, y}), valid(valid) {
|
||||||
|
|
||||||
u64 endLoc = (u64)loc + sizeInBytes();
|
u64 endLoc = (u64)loc + sizeInBytes();
|
||||||
|
@ -96,7 +96,7 @@ struct DepthBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasStencil() {
|
bool hasStencil() {
|
||||||
return format == PICADepthFmt::Depth24Stencil8;
|
return format == PICA::DepthFmt::Depth24Stencil8;
|
||||||
}
|
}
|
||||||
|
|
||||||
void allocate() {
|
void allocate() {
|
||||||
|
@ -142,6 +142,6 @@ struct DepthBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t sizeInBytes() {
|
size_t sizeInBytes() {
|
||||||
return (size_t)size.x() * (size_t)size.y() * sizePerPixel(format);
|
return (size_t)size.x() * (size_t)size.y() * PICA::sizePerPixel(format);
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -50,45 +50,45 @@ template <bool indexed>
|
||||||
void GPU::drawArrays() {
|
void GPU::drawArrays() {
|
||||||
// Base address for vertex attributes
|
// Base address for vertex attributes
|
||||||
// The vertex base is always on a quadword boundary because the PICA does weird alignment shit any time possible
|
// The vertex base is always on a quadword boundary because the PICA does weird alignment shit any time possible
|
||||||
const u32 vertexBase = ((regs[PICAInternalRegs::VertexAttribLoc] >> 1) & 0xfffffff) * 16;
|
const u32 vertexBase = ((regs[PICA::InternalRegs::VertexAttribLoc] >> 1) & 0xfffffff) * 16;
|
||||||
const u32 vertexCount = regs[PICAInternalRegs::VertexCountReg]; // Total # of vertices to transfer
|
const u32 vertexCount = regs[PICA::InternalRegs::VertexCountReg]; // Total # of vertices to transfer
|
||||||
|
|
||||||
// Configures the type of primitive and the number of vertex shader outputs
|
// Configures the type of primitive and the number of vertex shader outputs
|
||||||
const u32 primConfig = regs[PICAInternalRegs::PrimitiveConfig];
|
const u32 primConfig = regs[PICA::InternalRegs::PrimitiveConfig];
|
||||||
const PICAPrimType primType = static_cast<PICAPrimType>(Helpers::getBits<8, 2>(primConfig));
|
const PICA::PrimType primType = static_cast<PICA::PrimType>(Helpers::getBits<8, 2>(primConfig));
|
||||||
if (primType == PICAPrimType::TriangleFan) Helpers::panic("[PICA] Tried to draw unimplemented shape %d\n", primType);
|
if (primType == PICA::PrimType::TriangleFan) Helpers::panic("[PICA] Tried to draw unimplemented shape %d\n", primType);
|
||||||
if (vertexCount > Renderer::vertexBufferSize) Helpers::panic("[PICA] vertexCount > vertexBufferSize");
|
if (vertexCount > Renderer::vertexBufferSize) Helpers::panic("[PICA] vertexCount > vertexBufferSize");
|
||||||
|
|
||||||
if ((primType == PICAPrimType::TriangleList && vertexCount % 3) ||
|
if ((primType == PICA::PrimType::TriangleList && vertexCount % 3) ||
|
||||||
(primType == PICAPrimType::TriangleStrip && vertexCount < 3)) {
|
(primType == PICA::PrimType::TriangleStrip && vertexCount < 3)) {
|
||||||
Helpers::panic("Invalid vertex count for primitive. Type: %d, vert count: %d\n", primType, vertexCount);
|
Helpers::panic("Invalid vertex count for primitive. Type: %d, vert count: %d\n", primType, vertexCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the configuration for the index buffer, used only for indexed drawing
|
// Get the configuration for the index buffer, used only for indexed drawing
|
||||||
u32 indexBufferConfig = regs[PICAInternalRegs::IndexBufferConfig];
|
u32 indexBufferConfig = regs[PICA::InternalRegs::IndexBufferConfig];
|
||||||
u32 indexBufferPointer = vertexBase + (indexBufferConfig & 0xfffffff);
|
u32 indexBufferPointer = vertexBase + (indexBufferConfig & 0xfffffff);
|
||||||
bool shortIndex = Helpers::getBit<31>(indexBufferConfig); // Indicates whether vert indices are 16-bit or 8-bit
|
bool shortIndex = Helpers::getBit<31>(indexBufferConfig); // Indicates whether vert indices are 16-bit or 8-bit
|
||||||
|
|
||||||
// Stuff the global attribute config registers in one u64 to make attr parsing easier
|
// Stuff the global attribute config registers in one u64 to make attr parsing easier
|
||||||
// TODO: Cache this when the vertex attribute format registers are written to
|
// TODO: Cache this when the vertex attribute format registers are written to
|
||||||
u64 vertexCfg = u64(regs[PICAInternalRegs::AttribFormatLow]) | (u64(regs[PICAInternalRegs::AttribFormatHigh]) << 32);
|
u64 vertexCfg = u64(regs[PICA::InternalRegs::AttribFormatLow]) | (u64(regs[PICA::InternalRegs::AttribFormatHigh]) << 32);
|
||||||
|
|
||||||
if constexpr (!indexed) {
|
if constexpr (!indexed) {
|
||||||
u32 offset = regs[PICAInternalRegs::VertexOffsetReg];
|
u32 offset = regs[PICA::InternalRegs::VertexOffsetReg];
|
||||||
log("PICA::DrawArrays(vertex count = %d, vertexOffset = %d)\n", vertexCount, offset);
|
log("PICA::DrawArrays(vertex count = %d, vertexOffset = %d)\n", vertexCount, offset);
|
||||||
} else {
|
} else {
|
||||||
log("PICA::DrawElements(vertex count = %d, index buffer config = %08X)\n", vertexCount, indexBufferConfig);
|
log("PICA::DrawElements(vertex count = %d, index buffer config = %08X)\n", vertexCount, indexBufferConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Total number of input attributes to shader. Differs between GS and VS. Currently stubbed to the VS one, as we don't have geometry shaders.
|
// Total number of input attributes to shader. Differs between GS and VS. Currently stubbed to the VS one, as we don't have geometry shaders.
|
||||||
const u32 inputAttrCount = (regs[PICAInternalRegs::VertexShaderInputBufferCfg] & 0xf) + 1;
|
const u32 inputAttrCount = (regs[PICA::InternalRegs::VertexShaderInputBufferCfg] & 0xf) + 1;
|
||||||
const u64 inputAttrCfg = getVertexShaderInputConfig();
|
const u64 inputAttrCfg = getVertexShaderInputConfig();
|
||||||
|
|
||||||
for (u32 i = 0; i < vertexCount; i++) {
|
for (u32 i = 0; i < vertexCount; i++) {
|
||||||
u32 vertexIndex; // Index of the vertex in the VBO
|
u32 vertexIndex; // Index of the vertex in the VBO
|
||||||
|
|
||||||
if constexpr (!indexed) {
|
if constexpr (!indexed) {
|
||||||
vertexIndex = i + regs[PICAInternalRegs::VertexOffsetReg];
|
vertexIndex = i + regs[PICA::InternalRegs::VertexOffsetReg];
|
||||||
} else {
|
} else {
|
||||||
if (shortIndex) {
|
if (shortIndex) {
|
||||||
auto ptr = getPointerPhys<u16>(indexBufferPointer);
|
auto ptr = getPointerPhys<u16>(indexBufferPointer);
|
||||||
|
@ -209,7 +209,7 @@ void GPU::drawArrays() {
|
||||||
|
|
||||||
Vertex GPU::getImmediateModeVertex() {
|
Vertex GPU::getImmediateModeVertex() {
|
||||||
Vertex v;
|
Vertex v;
|
||||||
const int totalAttrCount = (regs[PICAInternalRegs::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
|
||||||
for (int i = 0; i < totalAttrCount; i++) {
|
for (int i = 0; i < totalAttrCount; i++) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ u32 GPU::readInternalReg(u32 index) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPU::writeInternalReg(u32 index, u32 value, u32 mask) {
|
void GPU::writeInternalReg(u32 index, u32 value, u32 mask) {
|
||||||
using namespace PICAInternalRegs;
|
using namespace PICA::InternalRegs;
|
||||||
|
|
||||||
if (index > regNum) {
|
if (index > regNum) {
|
||||||
Helpers::panic("Tried to write to invalid GPU register. Index: %X, value: %08X\n", index, value);
|
Helpers::panic("Tried to write to invalid GPU register. Index: %X, value: %08X\n", index, value);
|
||||||
|
@ -68,7 +68,7 @@ void GPU::writeInternalReg(u32 index, u32 value, u32 mask) {
|
||||||
|
|
||||||
case ColourBufferFormat: {
|
case ColourBufferFormat: {
|
||||||
u32 format = getBits<16, 3>(value);
|
u32 format = getBits<16, 3>(value);
|
||||||
renderer.setColourFormat(static_cast<PICAColorFmt>(format));
|
renderer.setColourFormat(static_cast<PICA::ColorFmt>(format));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ void GPU::writeInternalReg(u32 index, u32 value, u32 mask) {
|
||||||
|
|
||||||
case DepthBufferFormat: {
|
case DepthBufferFormat: {
|
||||||
u32 format = value & 0x3;
|
u32 format = value & 0x3;
|
||||||
renderer.setDepthFormat(static_cast<PICADepthFmt>(format));
|
renderer.setDepthFormat(static_cast<PICA::DepthFmt>(format));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ void GPU::writeInternalReg(u32 index, u32 value, u32 mask) {
|
||||||
if (fixedAttribIndex < 12) [[likely]] {
|
if (fixedAttribIndex < 12) [[likely]] {
|
||||||
shaderUnit.vs.fixedAttributes[fixedAttribIndex++] = attr;
|
shaderUnit.vs.fixedAttributes[fixedAttribIndex++] = attr;
|
||||||
} else if (fixedAttribIndex == 15) { // Otherwise if it's 15, we're submitting an immediate mode vertex
|
} else if (fixedAttribIndex == 15) { // Otherwise if it's 15, we're submitting an immediate mode vertex
|
||||||
const uint totalAttrCount = (regs[PICAInternalRegs::VertexShaderAttrNum] & 0xf) + 1;
|
const uint totalAttrCount = (regs[PICA::InternalRegs::VertexShaderAttrNum] & 0xf) + 1;
|
||||||
if (totalAttrCount <= immediateModeAttrIndex) {
|
if (totalAttrCount <= immediateModeAttrIndex) {
|
||||||
printf("Broken state in the immediate mode vertex submission pipeline. Failing silently\n");
|
printf("Broken state in the immediate mode vertex submission pipeline. Failing silently\n");
|
||||||
immediateModeAttrIndex = 0;
|
immediateModeAttrIndex = 0;
|
||||||
|
@ -151,13 +151,13 @@ void GPU::writeInternalReg(u32 index, u32 value, u32 mask) {
|
||||||
immediateModeVertices[immediateModeVertIndex++] = v;
|
immediateModeVertices[immediateModeVertIndex++] = v;
|
||||||
|
|
||||||
// Get primitive type
|
// Get primitive type
|
||||||
const u32 primConfig = regs[PICAInternalRegs::PrimitiveConfig];
|
const u32 primConfig = regs[PICA::InternalRegs::PrimitiveConfig];
|
||||||
const u32 primType = getBits<8, 2>(primConfig);
|
const u32 primType = getBits<8, 2>(primConfig);
|
||||||
|
|
||||||
// If we've reached 3 verts, issue a draw call
|
// If we've reached 3 verts, issue a draw call
|
||||||
// Handle rendering depending on the primitive type
|
// Handle rendering depending on the primitive type
|
||||||
if (immediateModeVertIndex == 3) {
|
if (immediateModeVertIndex == 3) {
|
||||||
renderer.drawVertices(PICAPrimType::TriangleList, immediateModeVertices);
|
renderer.drawVertices(PICA::PrimType::TriangleList, immediateModeVertices);
|
||||||
|
|
||||||
switch (primType) {
|
switch (primType) {
|
||||||
// Triangle or geometry primitive. Draw a triangle and discard all vertices
|
// Triangle or geometry primitive. Draw a triangle and discard all vertices
|
||||||
|
|
|
@ -144,10 +144,10 @@ void Renderer::reset() {
|
||||||
|
|
||||||
// Init the colour/depth buffer settings to some random defaults on reset
|
// Init the colour/depth buffer settings to some random defaults on reset
|
||||||
colourBufferLoc = 0;
|
colourBufferLoc = 0;
|
||||||
colourBufferFormat = PICAColorFmt::RGBA8;
|
colourBufferFormat = PICA::ColorFmt::RGBA8;
|
||||||
|
|
||||||
depthBufferLoc = 0;
|
depthBufferLoc = 0;
|
||||||
depthBufferFormat = PICADepthFmt::Depth16;
|
depthBufferFormat = PICA::DepthFmt::Depth16;
|
||||||
|
|
||||||
if (triangleProgram.exists()) {
|
if (triangleProgram.exists()) {
|
||||||
const auto oldProgram = OpenGL::getProgram();
|
const auto oldProgram = OpenGL::getProgram();
|
||||||
|
@ -221,7 +221,7 @@ void Renderer::getGraphicsContext() {
|
||||||
|
|
||||||
// Set up the OpenGL blending context to match the emulated PICA
|
// Set up the OpenGL blending context to match the emulated PICA
|
||||||
void Renderer::setupBlending() {
|
void Renderer::setupBlending() {
|
||||||
const bool blendingEnabled = (regs[PICAInternalRegs::ColourOperation] & (1 << 8)) != 0;
|
const bool blendingEnabled = (regs[PICA::InternalRegs::ColourOperation] & (1 << 8)) != 0;
|
||||||
|
|
||||||
// Map of PICA blending equations to OpenGL blending equations. The unused blending equations are equivalent to equation 0 (add)
|
// Map of PICA blending equations to OpenGL blending equations. The unused blending equations are equivalent to equation 0 (add)
|
||||||
static constexpr std::array<GLenum, 8> blendingEquations = {
|
static constexpr std::array<GLenum, 8> blendingEquations = {
|
||||||
|
@ -241,7 +241,7 @@ void Renderer::setupBlending() {
|
||||||
OpenGL::enableBlend();
|
OpenGL::enableBlend();
|
||||||
|
|
||||||
// Get blending equations
|
// Get blending equations
|
||||||
const u32 blendControl = regs[PICAInternalRegs::BlendFunc];
|
const u32 blendControl = regs[PICA::InternalRegs::BlendFunc];
|
||||||
const u32 rgbEquation = blendControl & 0x7;
|
const u32 rgbEquation = blendControl & 0x7;
|
||||||
const u32 alphaEquation = getBits<8, 3>(blendControl);
|
const u32 alphaEquation = getBits<8, 3>(blendControl);
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ void Renderer::setupBlending() {
|
||||||
const u32 alphaSourceFunc = getBits<24, 4>(blendControl);
|
const u32 alphaSourceFunc = getBits<24, 4>(blendControl);
|
||||||
const u32 alphaDestFunc = getBits<28, 4>(blendControl);
|
const u32 alphaDestFunc = getBits<28, 4>(blendControl);
|
||||||
|
|
||||||
const u32 constantColor = regs[PICAInternalRegs::BlendColour];
|
const u32 constantColor = regs[PICA::InternalRegs::BlendColour];
|
||||||
const u32 r = constantColor & 0xff;
|
const u32 r = constantColor & 0xff;
|
||||||
const u32 g = getBits<8, 8>(constantColor);
|
const u32 g = getBits<8, 8>(constantColor);
|
||||||
const u32 b = getBits<16, 8>(constantColor);
|
const u32 b = getBits<16, 8>(constantColor);
|
||||||
|
@ -264,7 +264,7 @@ void Renderer::setupBlending() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::drawVertices(PICAPrimType primType, std::span<const Vertex> 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
|
||||||
|
@ -272,7 +272,7 @@ void Renderer::drawVertices(PICAPrimType primType, std::span<const Vertex> verti
|
||||||
const auto primitiveTopology = primTypes[static_cast<usize>(primType)];
|
const auto primitiveTopology = primTypes[static_cast<usize>(primType)];
|
||||||
|
|
||||||
// Adjust alpha test if necessary
|
// Adjust alpha test if necessary
|
||||||
const u32 alphaControl = regs[PICAInternalRegs::AlphaTestConfig];
|
const u32 alphaControl = regs[PICA::InternalRegs::AlphaTestConfig];
|
||||||
if (alphaControl != oldAlphaControl) {
|
if (alphaControl != oldAlphaControl) {
|
||||||
oldAlphaControl = alphaControl;
|
oldAlphaControl = alphaControl;
|
||||||
glUniform1ui(alphaControlLoc, alphaControl);
|
glUniform1ui(alphaControlLoc, alphaControl);
|
||||||
|
@ -282,7 +282,7 @@ void Renderer::drawVertices(PICAPrimType primType, std::span<const Vertex> verti
|
||||||
OpenGL::Framebuffer poop = getColourFBO();
|
OpenGL::Framebuffer poop = getColourFBO();
|
||||||
poop.bind(OpenGL::DrawAndReadFramebuffer);
|
poop.bind(OpenGL::DrawAndReadFramebuffer);
|
||||||
|
|
||||||
const u32 depthControl = regs[PICAInternalRegs::DepthAndColorMask];
|
const u32 depthControl = regs[PICA::InternalRegs::DepthAndColorMask];
|
||||||
const bool depthEnable = depthControl & 1;
|
const bool depthEnable = depthControl & 1;
|
||||||
const bool depthWriteEnable = getBit<12>(depthControl);
|
const bool depthWriteEnable = getBit<12>(depthControl);
|
||||||
const int depthFunc = getBits<4, 3>(depthControl);
|
const int depthFunc = getBits<4, 3>(depthControl);
|
||||||
|
@ -293,9 +293,9 @@ void Renderer::drawVertices(PICAPrimType primType, std::span<const Vertex> verti
|
||||||
GL_NEVER, GL_ALWAYS, GL_EQUAL, GL_NOTEQUAL, GL_LESS, GL_LEQUAL, GL_GREATER, GL_GEQUAL
|
GL_NEVER, GL_ALWAYS, GL_EQUAL, GL_NOTEQUAL, GL_LESS, GL_LEQUAL, GL_GREATER, GL_GEQUAL
|
||||||
};
|
};
|
||||||
|
|
||||||
const float depthScale = f24::fromRaw(regs[PICAInternalRegs::DepthScale] & 0xffffff).toFloat32();
|
const float depthScale = f24::fromRaw(regs[PICA::InternalRegs::DepthScale] & 0xffffff).toFloat32();
|
||||||
const float depthOffset = f24::fromRaw(regs[PICAInternalRegs::DepthOffset] & 0xffffff).toFloat32();
|
const float depthOffset = f24::fromRaw(regs[PICA::InternalRegs::DepthOffset] & 0xffffff).toFloat32();
|
||||||
const bool depthMapEnable = regs[PICAInternalRegs::DepthmapEnable] & 1;
|
const bool depthMapEnable = regs[PICA::InternalRegs::DepthmapEnable] & 1;
|
||||||
|
|
||||||
// Update depth uniforms
|
// Update depth uniforms
|
||||||
if (oldDepthScale != depthScale) {
|
if (oldDepthScale != depthScale) {
|
||||||
|
@ -328,15 +328,15 @@ void Renderer::drawVertices(PICAPrimType primType, std::span<const Vertex> verti
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the texture unit configuration uniform if it changed
|
// Update the texture unit configuration uniform if it changed
|
||||||
const u32 texUnitConfig = regs[PICAInternalRegs::TexUnitCfg];
|
const u32 texUnitConfig = regs[PICA::InternalRegs::TexUnitCfg];
|
||||||
if (oldTexUnitConfig != texUnitConfig) {
|
if (oldTexUnitConfig != texUnitConfig) {
|
||||||
oldTexUnitConfig = texUnitConfig;
|
oldTexUnitConfig = texUnitConfig;
|
||||||
glUniform1ui(texUnitConfigLoc, texUnitConfig);
|
glUniform1ui(texUnitConfigLoc, texUnitConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Actually use this
|
// TODO: Actually use this
|
||||||
float viewportWidth = f24::fromRaw(regs[PICAInternalRegs::ViewportWidth] & 0xffffff).toFloat32() * 2.0;
|
float viewportWidth = f24::fromRaw(regs[PICA::InternalRegs::ViewportWidth] & 0xffffff).toFloat32() * 2.0;
|
||||||
float viewportHeight = f24::fromRaw(regs[PICAInternalRegs::ViewportHeight] & 0xffffff).toFloat32() * 2.0;
|
float viewportHeight = f24::fromRaw(regs[PICA::InternalRegs::ViewportHeight] & 0xffffff).toFloat32() * 2.0;
|
||||||
OpenGL::setViewport(viewportWidth, viewportHeight);
|
OpenGL::setViewport(viewportWidth, viewportHeight);
|
||||||
|
|
||||||
// Note: The code below must execute after we've bound the colour buffer & its framebuffer
|
// Note: The code below must execute after we've bound the colour buffer & its framebuffer
|
||||||
|
@ -429,8 +429,8 @@ void Renderer::bindDepthBuffer() {
|
||||||
tex = depthBufferCache.add(sampleBuffer).texture.m_handle;
|
tex = depthBufferCache.add(sampleBuffer).texture.m_handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PICADepthFmt::Depth24Stencil8 != depthBufferFormat) Helpers::panic("TODO: Should we remove stencil attachment?");
|
if (PICA::DepthFmt::Depth24Stencil8 != depthBufferFormat) Helpers::panic("TODO: Should we remove stencil attachment?");
|
||||||
auto attachment = depthBufferFormat == PICADepthFmt::Depth24Stencil8 ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT;
|
auto attachment = depthBufferFormat == PICA::DepthFmt::Depth24Stencil8 ? GL_DEPTH_STENCIL_ATTACHMENT : GL_DEPTH_ATTACHMENT;
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, tex, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, tex, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue