I'm trying to wrap my GL calls in external functions and classes. So, this brings up a question for setting uniforms for my shaders: is glGetUniformLocation a slow operation? If so, will using an std::map to store the uniform indices indexed by the names of the uniforms in strings be slower or faster? I'm trying to avoid coding in the uniforms statically (i.e. with macros or such)
Which is faster: calling glGetUniformLocation or using std::map?
Only call glGetUniformLocation
once when you compile/load the shader, and then cache the result yourself; using it in-frame will cause stalls as most drivers don't implement this as a hotpath and will wait for any queued pipeline operations to complete before executing (this goes for most glGet
functions, never call these in-frame, call them once and cache the result yourself).
Thanks. I'll probably just use a std::map and and hard-code an enum to index the map for each GLint. –
Middling
© 2022 - 2024 — McMap. All rights reserved.
glGetUniformLocation
will be be implemented as a map or hash_map lookup internally so there is no way using your own map would be slower. The question is whether it's worth it. Why do you need to do a string-based lookup more than once anyways? – Craquelure