mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-08 23:25:40 +12:00
[GPU] Move texture binding into its own method
This commit is contained in:
parent
4cb7e3625b
commit
6b610a82d6
2 changed files with 37 additions and 34 deletions
|
@ -84,6 +84,7 @@ class Renderer {
|
||||||
void setupBlending();
|
void setupBlending();
|
||||||
void bindDepthBuffer();
|
void bindDepthBuffer();
|
||||||
void setupTextureEnvState();
|
void setupTextureEnvState();
|
||||||
|
void bindTexturesToSlots();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Renderer(GPU& gpu, const std::array<u32, regNum>& internalRegs) : gpu(gpu), regs(internalRegs) {}
|
Renderer(GPU& gpu, const std::array<u32, regNum>& internalRegs) : gpu(gpu), regs(internalRegs) {}
|
||||||
|
|
|
@ -511,6 +511,41 @@ void Renderer::setupTextureEnvState() {
|
||||||
glUniform1ui(textureEnvBufferColorLoc, regs[0xfd]);
|
glUniform1ui(textureEnvBufferColorLoc, regs[0xfd]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Renderer::bindTexturesToSlots() {
|
||||||
|
static constexpr std::array<u32, 3> ioBases = {
|
||||||
|
0x80, 0x90, 0x98
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
if ((regs[0x80] & (1 << i)) == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t ioBase = ioBases[i];
|
||||||
|
|
||||||
|
const u32 dim = regs[ioBase + 2];
|
||||||
|
const u32 config = regs[ioBase + 3];
|
||||||
|
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;
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0 + i);
|
||||||
|
Texture targetTex(addr, static_cast<PICA::TextureFmt>(format), width, height, config);
|
||||||
|
OpenGL::Texture tex = getTexture(targetTex);
|
||||||
|
tex.bind();
|
||||||
|
}
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
|
||||||
|
// Update the texture unit configuration uniform if it changed
|
||||||
|
const u32 texUnitConfig = regs[PICA::InternalRegs::TexUnitCfg];
|
||||||
|
if (oldTexUnitConfig != texUnitConfig) {
|
||||||
|
oldTexUnitConfig = texUnitConfig;
|
||||||
|
glUniform1ui(texUnitConfigLoc, texUnitConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Renderer::drawVertices(PICA::PrimType 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 = {
|
||||||
|
@ -570,40 +605,7 @@ void Renderer::drawVertices(PICA::PrimType primType, std::span<const Vertex> ver
|
||||||
}
|
}
|
||||||
|
|
||||||
setupTextureEnvState();
|
setupTextureEnvState();
|
||||||
|
bindTexturesToSlots();
|
||||||
// Bind textures 0 to 2
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
if ((regs[0x80] & (1 << i)) == 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr std::array<u32, 3> ioBases = {
|
|
||||||
0x80, 0x90, 0x98
|
|
||||||
};
|
|
||||||
|
|
||||||
const size_t ioBase = ioBases[i];
|
|
||||||
|
|
||||||
const u32 dim = regs[ioBase + 2];
|
|
||||||
const u32 config = regs[ioBase + 3];
|
|
||||||
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;
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0 + i);
|
|
||||||
Texture targetTex(addr, static_cast<PICA::TextureFmt>(format), width, height, config);
|
|
||||||
OpenGL::Texture tex = getTexture(targetTex);
|
|
||||||
tex.bind();
|
|
||||||
}
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
|
|
||||||
// Update the texture unit configuration uniform if it changed
|
|
||||||
const u32 texUnitConfig = regs[PICA::InternalRegs::TexUnitCfg];
|
|
||||||
if (oldTexUnitConfig != texUnitConfig) {
|
|
||||||
oldTexUnitConfig = texUnitConfig;
|
|
||||||
glUniform1ui(texUnitConfigLoc, texUnitConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Actually use this
|
// TODO: Actually use this
|
||||||
float viewportWidth = f24::fromRaw(regs[PICA::InternalRegs::ViewportWidth] & 0xffffff).toFloat32() * 2.0;
|
float viewportWidth = f24::fromRaw(regs[PICA::InternalRegs::ViewportWidth] & 0xffffff).toFloat32() * 2.0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue