Support setting uniform block indices in gfx::program
This commit is contained in:
parent
a9cb71629e
commit
a439d33b0f
2 changed files with 34 additions and 4 deletions
|
|
@ -115,9 +115,14 @@ namespace psemek::gfx
|
|||
uniform_proxy operator[] (std::string_view name) const;
|
||||
uniform_proxy operator[] (GLint location) const;
|
||||
|
||||
GLuint uniform_block_index(std::string_view name) const;
|
||||
void uniform_block_binding(std::string_view name, GLuint binding) const;
|
||||
void uniform_block_binding(GLuint index, GLuint binding) const;
|
||||
|
||||
private:
|
||||
GLuint program_;
|
||||
mutable boost::container::flat_map<std::string, GLint, std::less<>> uniforms_;
|
||||
mutable boost::container::flat_map<std::string, GLuint, std::less<>> uniform_blocks_;
|
||||
|
||||
program(std::nullptr_t)
|
||||
: program_{0}
|
||||
|
|
|
|||
|
|
@ -374,10 +374,10 @@ namespace psemek::gfx
|
|||
auto it = uniforms_.find(name);
|
||||
if (it == uniforms_.end())
|
||||
{
|
||||
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;
|
||||
std::string name_str(name);
|
||||
auto location = gl::GetUniformLocation(program_, name_str.data());
|
||||
uniforms_[std::move(name_str)] = location;
|
||||
return location;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
|
@ -392,4 +392,29 @@ namespace psemek::gfx
|
|||
return {location};
|
||||
}
|
||||
|
||||
GLuint program::uniform_block_index(std::string_view name) const
|
||||
{
|
||||
auto it = uniform_blocks_.find(name);
|
||||
if (it == uniform_blocks_.end())
|
||||
{
|
||||
std::string name_str(name);
|
||||
auto index = gl::GetUniformBlockIndex(program_, name.data());
|
||||
if (index == gl::INVALID_INDEX)
|
||||
throw std::runtime_error("Unknown uniform block: " + name_str);
|
||||
uniform_blocks_[std::move(name_str)] = index;
|
||||
return index;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void program::uniform_block_binding(std::string_view name, GLuint binding) const
|
||||
{
|
||||
gl::UniformBlockBinding(program_, uniform_block_index(name), binding);
|
||||
}
|
||||
|
||||
void program::uniform_block_binding(GLuint index, GLuint binding) const
|
||||
{
|
||||
gl::UniformBlockBinding(program_, index, binding);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue