Question

I am trying to make a simple 3D application in WebGl, in which every object that is drawn has it's own shader attached. But I have a strange problem in Firefox (in Chrome this works perfectly) in which the uniform location for each matrix/sampler in each shader are not saved properly. Meaning I have to call getUniformLocation for every matrix that my shader uses each time I change the current shader, which to me seems a bit wasteful.

tmp.pMatrixUniform = this.gl.getUniformLocation(tmp, "uPMatrix"); //perpesctive
tmp.mvMatrixUniform = this.gl.getUniformLocation(tmp, "uMVMatrix");  //world transform
tmp.samplerUniform = this.gl.getUniformLocation(tmp, "uSampler"); //texture sampler

return tmp;

The above code is where I create a shader and store it for use across multiple objects. I know that the reference of the tmp shader object is stored and modified correctly, because right above these lines of code I save every attribute location in a similar manner, which doesn't need to be reset for every change of a "current shader".

Like I said, this doesn't work only in Firefox, which make me believe Firefox and Chrome store uniform locations differently. Does anyone know another way to store these values so that it works in both browsers, not having to "re-get" them for every frame?

Was it helpful?

Solution

I solved the issue. It turns out that it wasn't a problem with the function itself, but the fact that when switching to a new shader, I would always link it instead of linking the shader only on creation.

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