public void bind(GLBuffer.Float data, int count) { data.flush(); FloatBuffer buffer = ((GL20Buffer.FloatImpl)data).buffer; buffer.position(0); gl.glUniform2fv(loc, count, buffer); } };
@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) { float dw = x2 - x1, dh = y3 - y1; float[] quadData = data.array(); int opos = data.position(), pos = opos; quadData[pos++] = m00*dw; quadData[pos++] = m01*dw; quadData[pos++] = m10*dh; quadData[pos++] = m11*dh; quadData[pos++] = tx + m00*x1 + m10*y1; quadData[pos++] = ty + m01*x1 + m11*y1; quadData[pos++] = sx1; quadData[pos++] = sy1; quadData[pos++] = sx2 - sx1; quadData[pos++] = sy3 - sy1; pos = addExtraData(quadData, pos); data.skip(pos-opos); quadCounter++; if (quadCounter >= maxQuads) QuadShader.this.flush(); }
@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) { // write our stable vertex attributes into a buffer, then copy that in four times stableAttrs[0] = m00; stableAttrs[1] = m01; stableAttrs[2] = m10; stableAttrs[3] = m11; stableAttrs[4] = tx; stableAttrs[5] = ty; addExtraStableAttrs(stableAttrs, 6); int vertIdx = beginPrimitive(4, 6), offset = vertices.position(); float[] vertData = vertices.array(); offset = addVert(vertData, offset, stableAttrs, x1, y1, sx1, sy1); offset = addVert(vertData, offset, stableAttrs, x2, y2, sx2, sy2); offset = addVert(vertData, offset, stableAttrs, x3, y3, sx3, sy3); offset = addVert(vertData, offset, stableAttrs, x4, y4, sx4, sy4); vertices.skip(offset - vertices.position()); addElems(vertIdx, QUAD_INDICES, 0, QUAD_INDICES.length, 0); }
@Override public void addTriangles(float m00, float m01, float m10, float m11, float tx, float ty, float[] xys, float[] sxys, int xysOffset, int xysLen, int[] indices, int indicesOffset, int indicesLen, int indexBase) { stableAttrs[0] = m00; stableAttrs[1] = m01; stableAttrs[2] = m10; stableAttrs[3] = m11; stableAttrs[4] = tx; stableAttrs[5] = ty; addExtraStableAttrs(stableAttrs, 6); int vertIdx = beginPrimitive(xysLen/2, indicesLen); int offset = vertices.position(); float[] vertData = vertices.array(); for (int ii = xysOffset, ll = ii+xysLen; ii < ll; ii += 2) { offset = addVert(vertData, offset, stableAttrs, xys[ii], xys[ii+1], sxys[ii], sxys[ii+1]); } vertices.skip(offset - vertices.position()); addElems(vertIdx, indices, indicesOffset, indicesLen, indexBase); }
@Override public void addTriangles(float m00, float m01, float m10, float m11, float tx, float ty, float[] xys, int xysOffset, int xysLen, float tw, float th, int[] indices, int indicesOffset, int indicesLen, int indexBase) { stableAttrs[0] = m00; stableAttrs[1] = m01; stableAttrs[2] = m10; stableAttrs[3] = m11; stableAttrs[4] = tx; stableAttrs[5] = ty; addExtraStableAttrs(stableAttrs, 6); int vertIdx = beginPrimitive(xysLen/2, indicesLen); int offset = vertices.position(); float[] vertData = vertices.array(); for (int ii = xysOffset, ll = ii+xysLen; ii < ll; ii += 2) { float x = xys[ii], y = xys[ii+1]; offset = addVert(vertData, offset, stableAttrs, x, y, x/tw, y/th); } vertices.skip(offset - vertices.position()); addElems(vertIdx, indices, indicesOffset, indicesLen, indexBase); }
@Override public void flush() { super.flush(); if (vertices.position() == 0) return; ctx.checkGLError("Shader.flush"); if (delayedBinding) { // see comments in activate() bindAttribsBufs(); ctx.checkGLError("Shader.flush bind"); } 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"); }
private void bindAttribsBufs() { vertices.bind(GL20.GL_ARRAY_BUFFER); // bind our stable attributes int stride = vertexStride(); aMatrix.bind(stride, 0); aTranslation.bind(stride, 16); aColor.bind(stride, 24); // bind our changing attributes int offset = stableAttrsSize()*FLOAT_SIZE_BYTES; aPosition.bind(stride, offset); if (aTexCoord != null) aTexCoord.bind(stride, offset+8); elements.bind(GL20.GL_ELEMENT_ARRAY_BUFFER); }
protected int beginPrimitive(int vertexCount, int elemCount) { int vertIdx = vertices.position() / vertexSize(); int verts = vertIdx + vertexCount, elems = elements.position() + elemCount; int availVerts = vertices.capacity() / vertexSize(), 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 destroy() { super.destroy(); vertices.destroy(); elements.destroy(); data.destroy(); }
public void bind(GLBuffer.Float data, int count) { data.flush(); FloatBuffer buffer = ((GL20Buffer.FloatImpl)data).buffer; buffer.position(0); gl.glUniform4fv(loc, count, buffer); } };
@Override public void destroy() { super.destroy(); vertices.destroy(); elements.destroy(); }
public void bind(GLBuffer.Float data, int count) { data.flush(); FloatBuffer buffer = ((GL20Buffer.FloatImpl)data).buffer; buffer.position(0); gl.glUniformMatrix4fv(loc, count, false, buffer); } };