示例#1
0
 @Override
 public void close() {
   super.close();
   program.close();
   gl.glDeleteBuffers(2, new int[] {verticesId, elementsId}, 0);
   gl.checkError("UniformQuadBatch close");
 }
示例#2
0
 @Override
 public void begin(float fbufWidth, float fbufHeight, boolean flip) {
   super.begin(fbufWidth, fbufHeight, flip);
   program.activate();
   // TODO: apparently we can avoid glUniform calls because they're part of the program state; so
   // we can cache the last set values for all these glUniform calls and only set them anew if
   // they differ...
   gl.glUniform2f(uHScreenSize, fbufWidth / 2f, fbufHeight / 2f);
   gl.glUniform1f(uFlip, flip ? -1 : 1);
   gl.glBindBuffer(GL_ARRAY_BUFFER, verticesId);
   gl.glEnableVertexAttribArray(aVertex);
   gl.glVertexAttribPointer(aVertex, VERTEX_SIZE, GL_SHORT, false, 0, 0);
   gl.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementsId);
   gl.glActiveTexture(GL_TEXTURE0);
   gl.glUniform1i(uTexture, 0);
   gl.checkError("UniformQuadBatch begin");
 }
示例#3
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");
  }