简体   繁体   English

WebGL制服的返回值

[英]WebGl Uniforms return value

I am trying to make a simple 3D application in WebGl, in which every object that is drawn has it's own shader attached. 我试图在WebGl中创建一个简单的3D应用程序,其中绘制的每个对象都附加了自己的着色器。 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. 但是我在Firefox中有一个奇怪的问题(在Chrome中这很完美),其中每个着色器中每个矩阵/采样器的统一位置都没有正确保存。 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. 意思是每次我更改当前着色器时,我必须为每个我的着色器使用的矩阵调用getUniformLocation,这对我来说似乎有点浪费。

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". 我知道tmp着色器对象的引用是正确存储和修改的,因为在这些代码行的上方,我以类似的方式保存每个属性位置,对于“当前着色器”的每次更改都不需要重置。

Like I said, this doesn't work only in Firefox, which make me believe Firefox and Chrome store uniform locations differently. 就像我说的那样,这仅在Firefox中不起作用,这使我相信Firefox和Chrome浏览器存储统一位置的方式有所不同。 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? 有没有人知道另一种存储这些值的方法,以便它可以在两个浏览器中工作,而不必为每一帧“重新获取”它们?

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. 事实证明,这不是函数本身的问题,而是当切换到新的着色器时,我总是链接它而不是仅在创建时链接着色器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM