Skip to content

Commit

Permalink
Merge pull request #1695 from heinezen/fix/texunit_binding
Browse files Browse the repository at this point in the history
Fix tex unit assignment to `std::optional` type
  • Loading branch information
TheJJ authored Oct 6, 2024
2 parents 02d3242 + 03c1592 commit fb88dfc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions libopenage/renderer/opengl/shader_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,11 @@ void GlShaderProgram::update_uniforms(std::shared_ptr<GlUniformInput> const &uni
glBindTexture(GL_TEXTURE_2D, tex);
// TODO: maybe call this at a more appropriate position
glUniform1i(loc, tex_unit_id);
auto &tex_value = *this->textures_per_texunits[tex_unit_id];
tex_value = tex;
ENSURE(tex_unit_id < this->textures_per_texunits.size(),
"Tried to assign texture to non-existant texture unit at index "
<< tex_unit_id
<< " (max: " << this->textures_per_texunits.size() << ").");
this->textures_per_texunits[tex_unit_id] = tex;
break;
}
default:
Expand Down
1 change: 1 addition & 0 deletions libopenage/renderer/opengl/shader_program.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class GlShaderProgram final : public ShaderProgram
std::unordered_map<std::string, GlVertexAttrib> attribs;

/// Store which texture handles are currently bound to the shader's texture units.
/// A value of std::nullopt means the texture unit is unbound (no texture assigned).
std::vector<std::optional<GLuint>> textures_per_texunits;

/// Whether this program has been validated.
Expand Down

0 comments on commit fb88dfc

Please sign in to comment.