@@ -16,7 +16,7 @@ namespace openage::renderer::opengl {
1616
1717GlUniformBuffer::GlUniformBuffer (const std::shared_ptr<GlContext> &context,
1818 size_t size,
19- std::unordered_map<std::string, GlInBlockUniform> uniforms,
19+ std::vector< GlInBlockUniform> uniforms,
2020 GLuint binding_point,
2121 GLenum usage) :
2222 GlSimpleObject (context,
@@ -35,7 +35,7 @@ GlUniformBuffer::GlUniformBuffer(const std::shared_ptr<GlContext> &context,
3535
3636 uniform_id_t unif_id = 0 ;
3737 for (auto &uniform : uniforms) {
38- this ->uniforms_by_name .insert (std::make_pair (uniform.first , unif_id));
38+ this ->uniforms_by_name .insert (std::make_pair (uniform.name , unif_id));
3939 unif_id += 1 ;
4040 }
4141
@@ -62,25 +62,30 @@ void GlUniformBuffer::update_uniforms(std::shared_ptr<UniformBufferInput> const
6262 this ->bind ();
6363
6464 const auto &update_offs = glunif_in->update_offs ;
65+ const auto &used_uniforms = glunif_in->used_uniforms ;
66+ const auto &uniforms = this ->uniforms ;
6567 uint8_t const *data = glunif_in->update_data .data ();
66- for (auto const &pair : this ->uniforms_by_name ) {
67- auto id = pair.second ;
68- auto offset = update_offs[id];
68+
69+ size_t unif_count = used_uniforms.size ();
70+ for (size_t i = 0 ; i < unif_count; ++i) {
71+ uniform_id_t unif_id = used_uniforms[i];
72+ auto offset = update_offs[unif_id];
73+
6974 uint8_t const *ptr = data + offset.offset ;
70- auto unif_def = this -> uniforms . find (pair. first )-> second ;
71- auto loc = unif_def .offset ;
72- auto size = unif_def .size ;
75+ auto &unif = uniforms[unif_id] ;
76+ auto loc = unif .offset ;
77+ auto size = unif .size ;
7378
7479 glBufferSubData (GL_UNIFORM_BUFFER, loc, size, ptr);
7580 }
7681}
7782
78- const std::unordered_map<std::string, GlInBlockUniform> &GlUniformBuffer::get_uniforms () const {
83+ const std::vector< GlInBlockUniform> &GlUniformBuffer::get_uniforms () const {
7984 return this ->uniforms ;
8085}
8186
82- bool GlUniformBuffer::has_uniform (const char *unif ) {
83- return this ->uniforms . count (unif) != 0 ;
87+ bool GlUniformBuffer::has_uniform (const char *name ) {
88+ return this ->uniforms_by_name . contains (name) ;
8489}
8590
8691void GlUniformBuffer::bind () const {
@@ -100,11 +105,7 @@ void GlUniformBuffer::set_unif(UniformBufferInput &in, const char *unif, void co
100105 ENSURE (unif_id < this ->uniforms .size (),
101106 " Tried to set uniform with invalid ID " << unif_id);
102107
103- auto uniform = this ->uniforms .find (unif);
104- ENSURE (uniform != std::end (this ->uniforms ),
105- " Tried to set uniform " << unif << " that does not exist in the shader program." );
106-
107- auto const &unif_data = uniform->second ;
108+ auto const &unif_data = this ->uniforms [unif_id];
108109
109110 ENSURE (type == unif_data.type ,
110111 " Tried to set uniform " << unif << " to a value of the wrong type." );
0 commit comments