Hello! I have trouble passing multiple textures to my fragment shader. I create shader like this:
this.shader = new cc.GLProgram();
this.shader.initWithVertexShaderByteArray(DEFAULT_VERTEX_SHADER, MULTI_TEXTURES_FRAGMENT_SHADER);
this.shader.addAttribute(cc.ATTRIBUTE_NAME_POSITION, cc.VERTEX_ATTRIB_POSITION);
this.shader.addAttribute(cc.ATTRIBUTE_NAME_TEX_COORD, cc.VERTEX_ATTRIB_TEX_COORDS);
this.shader.link();
this.shader.updateUniforms();
In my fragment there is second sampler:
uniform sampler2D CC_Texture1;
Now Texture0 is bound to my sprite’s texture object, but how do I bind additional textures (TEXTURE1, TEXTURE2, etc)?
I can set unitform like this:
this.shader.setUniformLocationWith1i(‘CC_Texture1’, myTexture.name);
but I also need to tell webgl that it needs to bind additional textures when rendering my sprite:
gl.bindTexture(gl.TEXTURE_2D, this.tex1.getName());
, however I don’t know where I should put this line. My sprite.draw function is never called by engine.
Can you help me?