Question

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)

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top