Optimize program uniform location cache
This commit is contained in:
parent
1cc5d28761
commit
d73ce27c32
2 changed files with 10 additions and 8 deletions
|
|
@ -8,7 +8,8 @@
|
|||
#include <psemek/geom/interval.hpp>
|
||||
#include <psemek/geom/quaternion.hpp>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <boost/container/flat_map.hpp>
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace psemek::gfx
|
||||
|
|
@ -36,7 +37,7 @@ namespace psemek::gfx
|
|||
|
||||
void reset();
|
||||
|
||||
GLint location(char const * name) const;
|
||||
GLint location(std::string_view name) const;
|
||||
|
||||
struct uniform_proxy
|
||||
{
|
||||
|
|
@ -110,11 +111,11 @@ namespace psemek::gfx
|
|||
GLint location_;
|
||||
};
|
||||
|
||||
uniform_proxy operator[] (char const * name) const;
|
||||
uniform_proxy operator[] (std::string_view name) const;
|
||||
|
||||
private:
|
||||
GLuint program_;
|
||||
mutable std::unordered_map<std::string, GLint> uniforms_;
|
||||
mutable boost::container::flat_map<std::string, GLint, std::less<>> uniforms_;
|
||||
|
||||
program(std::nullptr_t)
|
||||
: program_{0}
|
||||
|
|
|
|||
|
|
@ -364,19 +364,20 @@ namespace psemek::gfx
|
|||
program_ = 0;
|
||||
}
|
||||
|
||||
GLint program::location(char const * name) const
|
||||
GLint program::location(std::string_view name) const
|
||||
{
|
||||
auto it = uniforms_.find(name);
|
||||
if (it == uniforms_.end())
|
||||
{
|
||||
auto l = gl::GetUniformLocation(program_, name);
|
||||
uniforms_[name] = l;
|
||||
std::string name_str(name.begin(), name.end());
|
||||
auto l = gl::GetUniformLocation(program_, name_str.c_str());
|
||||
uniforms_[std::move(name_str)] = l;
|
||||
return l;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
program::uniform_proxy program::operator[] (char const * name) const
|
||||
program::uniform_proxy program::operator[] (std::string_view name) const
|
||||
{
|
||||
return {location(name)};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue