[GPU] Remove magic constants in TEV and texture binding code as much as possible

This commit is contained in:
fleroviux 2023-06-20 23:43:43 +02:00
parent 7128ae5565
commit 7ebbfbf1ef
2 changed files with 24 additions and 9 deletions

View file

@ -16,7 +16,20 @@ namespace PICA {
ShaderOutmap0 = 0x50,
DepthmapEnable = 0x6D,
// Texture registers
TexUnitCfg = 0x80,
Tex0BorderColor = 0x81,
Tex1BorderColor = 0x91,
Tex2BorderColor = 0x99,
TexEnv0Source = 0xC0,
TexEnv1Source = 0xC8,
TexEnv2Source = 0xD0,
TexEnv3Source = 0xD8,
TexEnvUpdateBuffer = 0xE0,
TexEnv4Source = 0xF0,
TexEnv5Source = 0xF8,
TexEnvBufferColor = 0xFD,
// Framebuffer registers
ColourOperation = 0x100,

View file

@ -483,7 +483,9 @@ void Renderer::setupTextureEnvState() {
// TODO: Only update uniforms when the TEV config changed. Use an UBO potentially.
static constexpr std::array<u32, 6> ioBases = {
0xc0, 0xc8, 0xd0, 0xd8, 0xf0, 0xf8
PICA::InternalRegs::TexEnv0Source, PICA::InternalRegs::TexEnv1Source,
PICA::InternalRegs::TexEnv2Source, PICA::InternalRegs::TexEnv3Source,
PICA::InternalRegs::TexEnv4Source, PICA::InternalRegs::TexEnv5Source
};
u32 textureEnvSourceRegs[6];
@ -507,28 +509,28 @@ void Renderer::setupTextureEnvState() {
glUniform1uiv(textureEnvCombinerLoc, 6, textureEnvCombinerRegs);
glUniform1uiv(textureEnvColorLoc, 6, textureEnvColourRegs);
glUniform1uiv(textureEnvScaleLoc, 6, textureEnvScaleRegs);
glUniform1ui(textureEnvUpdateBufferLoc, regs[0xe0]);
glUniform1ui(textureEnvBufferColorLoc, regs[0xfd]);
glUniform1ui(textureEnvUpdateBufferLoc, regs[PICA::InternalRegs::TexEnvUpdateBuffer]);
glUniform1ui(textureEnvBufferColorLoc, regs[PICA::InternalRegs::TexEnvBufferColor]);
}
void Renderer::bindTexturesToSlots() {
static constexpr std::array<u32, 3> ioBases = {
0x80, 0x90, 0x98
PICA::InternalRegs::Tex0BorderColor, PICA::InternalRegs::Tex1BorderColor, PICA::InternalRegs::Tex2BorderColor
};
for (int i = 0; i < 3; i++) {
if ((regs[0x80] & (1 << i)) == 0) {
if ((regs[PICA::InternalRegs::TexUnitCfg] & (1 << i)) == 0) {
continue;
}
const size_t ioBase = ioBases[i];
const u32 dim = regs[ioBase + 2];
const u32 config = regs[ioBase + 3];
const u32 dim = regs[ioBase + 1];
const u32 config = regs[ioBase + 2];
const u32 height = dim & 0x7ff;
const u32 width = getBits<16, 11>(dim);
const u32 addr = (regs[ioBase + 5] & 0x0FFFFFFF) << 3;
u32 format = regs[ioBase + (i == 0 ? 14 : 6)] & 0xF;
const u32 addr = (regs[ioBase + 4] & 0x0FFFFFFF) << 3;
u32 format = regs[ioBase + (i == 0 ? 13 : 5)] & 0xF;
glActiveTexture(GL_TEXTURE0 + i);
Texture targetTex(addr, static_cast<PICA::TextureFmt>(format), width, height, config);