@Override public void flush() { if (vertices.position() == 0) return; ctx.checkGLError("Shader.flush"); vertices.send(GL20.GL_ARRAY_BUFFER, GL20.GL_STREAM_DRAW); int elems = elements.send(GL20.GL_ELEMENT_ARRAY_BUFFER, GL20.GL_STREAM_DRAW); ctx.checkGLError("Shader.flush BufferData"); elements.drawElements(GL20.GL_TRIANGLES, elems); ctx.checkGLError("Shader.flush DrawElements"); }
protected int beginPrimitive(int vertexCount, int elemCount) { int vertIdx = vertices.position() / VERTEX_SIZE; int verts = vertIdx + vertexCount, elems = elements.position() + elemCount; int availVerts = vertices.capacity() / VERTEX_SIZE, availElems = elements.capacity(); if ((verts > availVerts) || (elems > availElems)) { IndexedTrisShader.this.flush(); if (verts > availVerts) expandVerts(verts); if (elems > availElems) expandElems(elems); return 0; } return vertIdx; }
@Override public void addQuad( float m00, float m01, float m10, float m11, float tx, float ty, float x1, float y1, float sx1, float sy1, float x2, float y2, float sx2, float sy2, float x3, float y3, float sx3, float sy3, float x4, float y4, float sx4, float sy4) { int vertIdx = beginPrimitive(4, 6); vertices.add(m00, m01, m10, m11, tx, ty).add(x1, y1).add(sx1, sy1).add(arTint, gbTint); vertices.add(m00, m01, m10, m11, tx, ty).add(x2, y2).add(sx2, sy2).add(arTint, gbTint); vertices.add(m00, m01, m10, m11, tx, ty).add(x3, y3).add(sx3, sy3).add(arTint, gbTint); vertices.add(m00, m01, m10, m11, tx, ty).add(x4, y4).add(sx4, sy4).add(arTint, gbTint); elements.add(vertIdx + 0); elements.add(vertIdx + 1); elements.add(vertIdx + 2); elements.add(vertIdx + 1); elements.add(vertIdx + 3); elements.add(vertIdx + 2); }
@Override public void activate(int fbufWidth, int fbufHeight) { prog.bind(); uScreenSize.bind(fbufWidth, fbufHeight); vertices.bind(GL20.GL_ARRAY_BUFFER); aMatrix.bind(VERTEX_STRIDE, 0); aTranslation.bind(VERTEX_STRIDE, 16); aPosition.bind(VERTEX_STRIDE, 24); if (aTexCoord != null) aTexCoord.bind(VERTEX_STRIDE, 32); aColor.bind(VERTEX_STRIDE, 40); elements.bind(GL20.GL_ELEMENT_ARRAY_BUFFER); ctx.checkGLError("Shader.prepare bind"); }
@Override public void addTriangles( float m00, float m01, float m10, float m11, float tx, float ty, float[] xys, float tw, float th, int[] indices) { int vertIdx = beginPrimitive(xys.length / 2, indices.length); for (int ii = 0, ll = xys.length; ii < ll; ii += 2) { float x = xys[ii], y = xys[ii + 1]; vertices.add(m00, m01, m10, m11, tx, ty).add(x, y).add(x / tw, y / th).add(arTint, gbTint); } for (int ii = 0, ll = indices.length; ii < ll; ii++) elements.add(vertIdx + indices[ii]); }
private void expandElems(int elemCount) { int newElems = elements.capacity(); while (newElems < elemCount) newElems += EXPAND_ELEMS; elements.expand(newElems); }
@Override public String toString() { return "cq=" + (elements.capacity() / 6); }
@Override public void destroy() { super.destroy(); vertices.destroy(); elements.destroy(); }