Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{
// if there is no shader here, we can use the default shader.
// and that only gets created if we actually need it..
if (!defaultShader)
{
const sampleValues = new Int32Array(16);
for (let i = 0; i < 16; i++)
{
sampleValues[i] = i;
}
const uniforms = {
tint: new Float32Array([1, 1, 1, 1]),
translationMatrix: new Matrix(),
default: UniformGroup.from({ uSamplers: sampleValues }, true),
};
// we can bbase default shader of the batch renderers program
const program = renderer.plugins.batch._shader.program;
defaultShader = new Shader(program, uniforms);
}
this.shader = defaultShader;
}
const uniforms = this.shader.uniforms;
// lets set the transfomr
uniforms.translationMatrix = this.transform.worldTransform;
export default function generateMultiTextureShader(gl, maxTextures)
{
const sampleValues = new Int32Array(maxTextures);
for (let i = 0; i < maxTextures; i++)
{
sampleValues[i] = i;
}
const uniforms = {
default: UniformGroup.from({ uSamplers: sampleValues }, true),
};
let fragmentSrc = fragTemplate;
fragmentSrc = fragmentSrc.replace(/%count%/gi, maxTextures);
fragmentSrc = fragmentSrc.replace(/%forloop%/gi, generateSampleSrc(maxTextures));
const shader = Shader.from(vertex, fragmentSrc, uniforms);
return shader;
}