Hook up specialized shaders to GL renderer

This commit is contained in:
wheremyfoodat 2024-03-02 22:35:56 +02:00
parent 67fe3214fe
commit fc83d518e2

View file

@ -291,6 +291,9 @@ void RendererGL::setupStencilTest(bool stencilEnable) {
void RendererGL::setupTextureEnvState() { void RendererGL::setupTextureEnvState() {
// TODO: Only update uniforms when the TEV config changed. Use an UBO potentially. // TODO: Only update uniforms when the TEV config changed. Use an UBO potentially.
if (!usingUbershader) {
return;
}
static constexpr std::array<u32, 6> ioBases = { static constexpr std::array<u32, 6> ioBases = {
PICA::InternalRegs::TexEnv0Source, PICA::InternalRegs::TexEnv1Source, PICA::InternalRegs::TexEnv2Source, PICA::InternalRegs::TexEnv0Source, PICA::InternalRegs::TexEnv1Source, PICA::InternalRegs::TexEnv2Source,
@ -388,13 +391,17 @@ void RendererGL::drawVertices(PICA::PrimType primType, std::span<const Vertex> v
OpenGL::Triangle, OpenGL::Triangle,
}; };
OpenGL::Program& program = getSpecializedShader(); if (usingUbershader) {
gl.useProgram(triangleProgram);
} else {
OpenGL::Program& program = getSpecializedShader();
gl.useProgram(program);
}
const auto primitiveTopology = primTypes[static_cast<usize>(primType)]; const auto primitiveTopology = primTypes[static_cast<usize>(primType)];
gl.disableScissor(); gl.disableScissor();
gl.bindVBO(vbo); gl.bindVBO(vbo);
gl.bindVAO(vao); gl.bindVAO(vao);
gl.useProgram(triangleProgram);
gl.enableClipPlane(0); // Clipping plane 0 is always enabled gl.enableClipPlane(0); // Clipping plane 0 is always enabled
if (regs[PICA::InternalRegs::ClipEnable] & 1) { if (regs[PICA::InternalRegs::ClipEnable] & 1) {
@ -420,27 +427,31 @@ void RendererGL::drawVertices(PICA::PrimType primType, std::span<const Vertex> v
const bool depthMapEnable = regs[PICA::InternalRegs::DepthmapEnable] & 1; const bool depthMapEnable = regs[PICA::InternalRegs::DepthmapEnable] & 1;
// Update depth uniforms // Update depth uniforms
if (oldDepthScale != depthScale) { if (usingUbershader) {
oldDepthScale = depthScale; if (oldDepthScale != depthScale) {
glUniform1f(ubershaderData.depthScaleLoc, depthScale); oldDepthScale = depthScale;
} glUniform1f(ubershaderData.depthScaleLoc, depthScale);
}
if (oldDepthOffset != depthOffset) { if (oldDepthOffset != depthOffset) {
oldDepthOffset = depthOffset; oldDepthOffset = depthOffset;
glUniform1f(ubershaderData.depthOffsetLoc, depthOffset); glUniform1f(ubershaderData.depthOffsetLoc, depthOffset);
} }
if (oldDepthmapEnable != depthMapEnable) { if (oldDepthmapEnable != depthMapEnable) {
oldDepthmapEnable = depthMapEnable; oldDepthmapEnable = depthMapEnable;
glUniform1i(ubershaderData.depthmapEnableLoc, depthMapEnable); glUniform1i(ubershaderData.depthmapEnableLoc, depthMapEnable);
}
} }
setupTextureEnvState(); setupTextureEnvState();
bindTexturesToSlots(); bindTexturesToSlots();
// Upload PICA Registers as a single uniform. The shader needs access to the rasterizer registers (for depth, starting from index 0x48) if (usingUbershader) {
// The texturing and the fragment lighting registers. Therefore we upload them all in one go to avoid multiple slow uniform updates // Upload PICA Registers as a single uniform. The shader needs access to the rasterizer registers (for depth, starting from index 0x48)
glUniform1uiv(ubershaderData.picaRegLoc, 0x200 - 0x48, &regs[0x48]); // The texturing and the fragment lighting registers. Therefore we upload them all in one go to avoid multiple slow uniform updates
glUniform1uiv(ubershaderData.picaRegLoc, 0x200 - 0x48, &regs[0x48]);
}
if (gpu.lightingLUTDirty) { if (gpu.lightingLUTDirty) {
updateLightingLUT(); updateLightingLUT();