1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:58:13 +00:00

LibAccelGfx: Add cache for programs

Having programs cache shared between painters would allow us to create
more than one painter without worrying about shaders recompilation.
This commit is contained in:
Aliaksandr Kalenik 2023-11-23 15:09:40 +01:00 committed by Andreas Kling
parent d5630fedf1
commit cb90daadc7
3 changed files with 21 additions and 13 deletions

View file

@ -11,12 +11,19 @@
namespace AccelGfx {
Program Program::create(char const* vertex_shader_source, char const* fragment_shader_source)
Optional<GL::Program> programs_cache[to_underlying(Program::Name::ProgramCount)];
Program Program::create(Name name, char const* vertex_shader_source, char const* fragment_shader_source)
{
if (programs_cache[to_underlying(name)].has_value()) {
return Program { *programs_cache[to_underlying(name)] };
}
auto vertex_shader = GL::create_shader(GL::ShaderType::Vertex, vertex_shader_source);
auto fragment_shader = GL::create_shader(GL::ShaderType::Fragment, fragment_shader_source);
auto program = GL::create_program(vertex_shader, fragment_shader);
programs_cache[to_underlying(name)] = program;
return Program { program };
}
@ -36,9 +43,4 @@ GL::Uniform Program::get_uniform_location(char const* name)
return GL::get_uniform_location(m_program, name);
}
Program::~Program()
{
GL::delete_program(m_program);
}
}