Ejemplo n.º 1
0
  public static void shaderSource(final GL _gl, final int shader, final CharSequence[] source) {
    final GL2ES2 gl = _gl.getGL2ES2();
    if (!isShaderCompilerAvailable(_gl)) {
      throw new GLException("No compiler is available");
    }

    final int count = (null != source) ? source.length : 0;
    if (count == 0) {
      throw new GLException("No sources specified");
    }

    final IntBuffer lengths = Buffers.newDirectIntBuffer(count);
    for (int i = 0; i < count; i++) {
      lengths.put(i, source[i].length());
    }
    if (source instanceof String[]) {
      // rare case ..
      gl.glShaderSource(shader, count, (String[]) source, lengths);
    } else {
      final String[] tmp = new String[source.length];
      for (int i = source.length - 1; i >= 0; i--) {
        final CharSequence csq = source[i];
        if (csq instanceof String) {
          // if ShaderCode.create(.. mutableStringBuilder == false )
          tmp[i] = (String) csq;
        } else {
          // if ShaderCode.create(.. mutableStringBuilder == true )
          tmp[i] = source[i].toString();
        }
      }
      gl.glShaderSource(shader, count, tmp, lengths);
    }
  }