GL: Add RendererGL::getSpecializedShader

This commit is contained in:
wheremyfoodat 2024-02-29 01:28:00 +02:00
parent ddc14cea09
commit fdfb012aa1
2 changed files with 22 additions and 4 deletions

View file

@ -60,6 +60,7 @@ class RendererGL final : public Renderer {
OpenGL::Framebuffer getColourFBO();
OpenGL::Texture getTexture(Texture& tex);
OpenGL::Program getSpecializedShader();
PICA::ShaderGen::FragmentGenerator fragShaderGen;

View file

@ -393,10 +393,7 @@ void RendererGL::drawVertices(PICA::PrimType primType, std::span<const Vertex> v
std::string fs = fragShaderGen.generate(regs);
std::cout << fs << "\n\n\n";
OpenGL::Program program;
OpenGL::Shader vertShader({vs.c_str(), vs.size()}, OpenGL::Vertex);
OpenGL::Shader fragShader({fs.c_str(), fs.size()}, OpenGL::Fragment);
program.create({vertShader, fragShader});
OpenGL::Program program = getSpecializedShader();
const auto primitiveTopology = primTypes[static_cast<usize>(primType)];
gl.disableScissor();
@ -787,6 +784,26 @@ std::optional<ColourBuffer> RendererGL::getColourBuffer(u32 addr, PICA::ColorFmt
return colourBufferCache.add(sampleBuffer);
}
OpenGL::Program RendererGL::getSpecializedShader() {
OpenGL::Program program;
std::string vs = fragShaderGen.getVertexShader(regs);
std::string fs = fragShaderGen.generate(regs);
OpenGL::Shader vertShader({vs.c_str(), vs.size()}, OpenGL::Vertex);
OpenGL::Shader fragShader({fs.c_str(), fs.size()}, OpenGL::Fragment);
program.create({vertShader, fragShader});
program.use();
// Init sampler objects. Texture 0 goes in texture unit 0, texture 1 in TU 1, texture 2 in TU 2, and the light maps go in TU 3
glUniform1i(OpenGL::uniformLocation(program, "u_tex0"), 0);
glUniform1i(OpenGL::uniformLocation(program, "u_tex1"), 1);
glUniform1i(OpenGL::uniformLocation(program, "u_tex2"), 2);
glUniform1i(OpenGL::uniformLocation(program, "u_tex_lighting_lut"), 3);
return program;
}
void RendererGL::screenshot(const std::string& name) {
constexpr uint width = 400;
constexpr uint height = 2 * 240;