Black screen when trying to use multiple textures in Expo

Viewed 118

I'm trying to use multiple textures in expo, but for some reason whenever I try to bind more than one texture, even if the texture is unused in the shader, nothing renders to the screen.

Code that binds textures:

   gl.useProgram(program);
   gl.bindVertexArray(vao);
 
   // Set texture sampler uniform
   const TEXTURE_UNIT = 0;
   const TEXTURE_UNIT2 = 1;
   gl.uniform1i(uniformLocations.get('cameraTexture'), TEXTURE_UNIT);
   gl.uniform1i(uniformLocations.get('segmentationTexture'), TEXTURE_UNIT2);
   gl.activeTexture(gl.TEXTURE0);
   gl.bindTexture(gl.TEXTURE_2D, cameraTexture);
   gl.activeTexture(gl.TEXTURE1);
   gl.bindTexture(gl.TEXTURE_2D, segmentationTexture);

   gl.bindFramebuffer(gl.FRAMEBUFFER, null);
   gl.viewport(0, 0, dims.width, dims.height);
   gl.drawArrays(gl.TRIANGLES, 0, vertices.length / 2);
   //console.log("draws")
 
   gl.bindVertexArray(null);
   gl.bindTexture(gl.TEXTURE_2D, null);
   gl.useProgram(null);

Fragment shader:

#version 300 es
precision highp float;
uniform sampler2D cameraTexture;
uniform sampler2D segmentationTexture;
in vec2 uv;
out vec4 fragColor;
void main() {
  fragColor = texture(cameraTexture, uv); //segmentationTexture.r * 
}

Vertex Shader:

const horizontalScale = flipHorizontal ? -1 : 1;
  return `#version 300 es
precision highp float;

in vec2 position;
in vec2 texCoords;

out vec2 uv;

void main() {
  // Invert geometry to match the image orientation from the camera.
  gl_Position = vec4(position * vec2(${horizontalScale}., -1.), 0, 1);
  uv = texCoords;
}`

I have checked both textures by commenting out the code the binds the other texture, e.g.

const TEXTURE_UNIT = 0;
//const TEXTURE_UNIT2 = 1;
gl.uniform1i(uniformLocations.get('cameraTexture'), TEXTURE_UNIT);
//gl.uniform1i(uniformLocations.get('segmentationTexture'), TEXTURE_UNIT2);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, cameraTexture);
//gl.activeTexture(gl.TEXTURE1);
//gl.bindTexture(gl.TEXTURE_2D, segmentationTexture);

or

//const TEXTURE_UNIT = 0;
const TEXTURE_UNIT2 = 1;
//gl.uniform1i(uniformLocations.get('cameraTexture'), TEXTURE_UNIT);
gl.uniform1i(uniformLocations.get('segmentationTexture'), TEXTURE_UNIT2);
//gl.activeTexture(gl.TEXTURE0);
//gl.bindTexture(gl.TEXTURE_2D, cameraTexture);
gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, segmentationTexture);

and both render fine individually.

However, the act of trying to bind multiple textures, even though only one is used in frag shader, leaves me with only a black screen.

0 Answers
Related