Exemplo n.º 1
0
 private static int usableMaxUniformVectors(GL20 gl) {
   // this returns the maximum number of vec4s; then we subtract one vec2 to account for the
   // uHScreenSize uniform, and two more because some GPUs seem to need one for our vec3 attr
   int maxVecs = gl.glGetInteger(GL_MAX_VERTEX_UNIFORM_VECTORS) - 3;
   gl.checkError("glGetInteger(GL_MAX_VERTEX_UNIFORM_VECTORS)");
   return maxVecs;
 }
Exemplo n.º 2
0
  /** Creates a uniform quad batch with the supplied custom shader program builder. */
  public UniformQuadBatch(GL20 gl, Source source) {
    super(gl);
    int maxVecs = usableMaxUniformVectors(gl) - extraVec4s();
    if (maxVecs < vec4sPerQuad())
      throw new RuntimeException(
          "GL_MAX_VERTEX_UNIFORM_VECTORS too low: have "
              + maxVecs
              + ", need at least "
              + vec4sPerQuad());
    maxQuads = maxVecs / vec4sPerQuad();

    program = new GLProgram(gl, source.vertex(this), source.fragment());
    uTexture = program.getUniformLocation("u_Texture");
    uHScreenSize = program.getUniformLocation("u_HScreenSize");
    uFlip = program.getUniformLocation("u_Flip");
    uData = program.getUniformLocation("u_Data");
    aVertex = program.getAttribLocation("a_Vertex");

    // create our stock supply of unit quads and stuff them into our buffers
    short[] verts = new short[maxQuads * VERTICES_PER_QUAD * VERTEX_SIZE];
    short[] elems = new short[maxQuads * ELEMENTS_PER_QUAD];
    int vv = 0, ee = 0;
    for (short ii = 0; ii < maxQuads; ii++) {
      verts[vv++] = 0;
      verts[vv++] = 0;
      verts[vv++] = ii;
      verts[vv++] = 1;
      verts[vv++] = 0;
      verts[vv++] = ii;
      verts[vv++] = 0;
      verts[vv++] = 1;
      verts[vv++] = ii;
      verts[vv++] = 1;
      verts[vv++] = 1;
      verts[vv++] = ii;
      short base = (short) (ii * VERTICES_PER_QUAD);
      short base0 = base, base1 = ++base, base2 = ++base, base3 = ++base;
      elems[ee++] = base0;
      elems[ee++] = base1;
      elems[ee++] = base2;
      elems[ee++] = base1;
      elems[ee++] = base3;
      elems[ee++] = base2;
    }

    data = new float[maxQuads * vec4sPerQuad() * 4];

    // create our GL buffers
    int[] ids = new int[2];
    gl.glGenBuffers(2, ids, 0);
    verticesId = ids[0];
    elementsId = ids[1];

    gl.glBindBuffer(GL_ARRAY_BUFFER, verticesId);
    gl.bufs.setShortBuffer(verts, 0, verts.length);
    gl.glBufferData(GL_ARRAY_BUFFER, verts.length * 2, gl.bufs.shortBuffer, GL_STATIC_DRAW);

    gl.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementsId);
    gl.bufs.setShortBuffer(elems, 0, elems.length);
    gl.glBufferData(GL_ELEMENT_ARRAY_BUFFER, elems.length * 2, gl.bufs.shortBuffer, GL_STATIC_DRAW);

    gl.checkError("UniformQuadBatch end ctor");
  }