Html5 - bind additional uniform textures to shader

Html5 - bind additional uniform textures to shader
0
#1

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?

How to pass a uniform sampler2D (texture) to a shader program on HTML5?
#2

hi @unreal_world, how did you solved your issue? I need the same thing: passing a second texture to a shader… please share your solution. thks!

#3

Hi guys. I have made a component for Cocos Creator 1.9.3 for very similar purpose. Couldn’t set second texture for WebGL. Did you solve it?

Here is my topic: