Which is faster: calling glGetUniformLocation or using std::map?
Asked Answered
M

1

6

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)

Middling answered 6/12, 2013 at 2:26 Comment(4)
At best, 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
I'm trying to abstract away as many details as possible. It's no big deal though, I guess I'll use macros to reference them.Middling
possible duplicate: #14724824Connective
Oops, sorry, I searched for this but I didn't see that question.Middling
H
6

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).

Hirst answered 6/12, 2013 at 6:36 Comment(1)
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.