title: OpenGL Shaders. Pass array of float
body: <p>On my scene i have many objects that i want to rotate at the same time but on different angles.</p>
  
  <p>I have a shader that computes position of each object and draw the whole scene (pass vertex array into the shader with array of vertexes).</p>
  
  <pre><code>    "uniform float uRotation;" +
      ...
      "   mat4 mz = mat4(1.0);" +
      "   mz[0][0] = cos(rotation);" +
      "   mz[0][1] = sin(rotation);" +
      "   mz[1][0] = -sin(rotation);" +
      "   mz[1][1] = cos(rotation);" +
      ...
      gl_Position = uMVPMatrix * (aPosition *mz);
  </code></pre>
  
  <p>i have all my vertexes, indexes, colors etc in arrays (not 1 array for each object, but 1 array with offset for vertexes, one for colors etc.).</p>
  
  <p>I want to pass array of floats (angles for each "object") in one float[], but nothing is happinig.</p>
  
  <pre><code>    public void setRotations(float[] rotations)
      {
          GLES20.glUniform3fv(muRotation, rotations.length, rotations, 0);    
      }
  </code></pre>
  
  <p>if pass and use only one float everything is ok.</p>
  
  <p>How can i pass specific float for each object (for example i want to draw 20 rectangles (i have a vetrex array: float[20*3*4]) as i understand i must have float for each vertex: rotations: float[20*4])?</p>
  
  <p><strong>UPDATED:</strong></p>
  
  <p>I try to pass array as a texture.</p>
  
  <p>When i create resources for the scene - i try to create my array (called mask):</p>
  
  <pre><code>    mask = new float[512*512*4];
      for (int i = 0; i &lt; mask.length; i++)
      {
          mask[i] = 2f;
      }
  
      GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 1029384756);
      GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 1, GLES20.GL_RGBA, 512, 512, 0, GLES20.GL_RGBA, GLES20.GL_FLOAT, FloatBuffer.wrap(mask));
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
      GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
  </code></pre>
  
  <p>Then when i draw new item on scene i use shader and try to pass my array:</p>
  
  <pre><code>    setShaderProgram(ShaderProgram.getInstance());
  
      GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
      GLES20.glUniform1i(ShaderProgram.sUniformMask, GLES20.GL_TEXTURE1);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 1029384756);
      GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
  </code></pre>
  
  <p>But when i try to check any value from the array if it >0.5 every computation gives me <strong>false</strong></p>
  
  <p><strong>UPDATED</strong></p>
  
  <p>Fragment shader contains:</p>
  
  <pre><code>"uniform sampler2D " + ShaderProgramConstants.UNIFORM_TEXTURE_0 + ";\n" +
  "uniform sampler2D " + ShaderProgramConstants.UNIFORM_TEXTURE_1 + ";\n" +
  "varying mediump vec2 " + ShaderProgramConstants.VARYING_TEXTURECOORDINATES + ";\n" +
  
  "void main() {\n" +
  "vec4 color = texture2D(" + ShaderProgramConstants.UNIFORM_TEXTURE_0 + ", " + ShaderProgramConstants.VARYING_TEXTURECOORDINATES + ");\n" +
  "vec4 mask = texture2D(" + ShaderProgramConstants.UNIFORM_TEXTURE_1 + ", " + ShaderProgramConstants.VARYING_TEXTURECOORDINATES + ");\n" +
  "float maskVal = mask.r;\n" ...
  </code></pre>
  
  <p>color and mask textures have the same dimensions</p>