private final void expandVerts (int vertCount) { int newVerts = vertices.length / vertexSize(); while (newVerts < vertCount) newVerts += EXPAND_VERTS; vertices = new float[newVerts*vertexSize()]; }
private final void expandVerts (int vertCount) { int newVerts = vertices.length / vertexSize(); while (newVerts < vertCount) newVerts += EXPAND_VERTS; vertices = new float[newVerts*vertexSize()]; }
protected int vertexStride () { return vertexSize() * FLOAT_SIZE_BYTES; }
protected int vertexStride () { return vertexSize() * FLOAT_SIZE_BYTES; }
protected int beginPrimitive (int vertexCount, int elemCount) { // check whether we have enough room to hold this primitive int vertIdx = vertPos / vertexSize(); int verts = vertIdx + vertexCount, elems = elemPos + elemCount; int availVerts = vertices.length / vertexSize(), availElems = elements.length; if (verts <= availVerts && elems <= availElems) return vertIdx; // otherwise, flush and expand our buffers if needed flush(); if (verts > availVerts) expandVerts(verts); if (elems > availElems) expandElems(elems); return 0; }
protected int beginPrimitive (int vertexCount, int elemCount) { // check whether we have enough room to hold this primitive int vertIdx = vertPos / vertexSize(); int verts = vertIdx + vertexCount, elems = elemPos + elemCount; int availVerts = vertices.length / vertexSize(), availElems = elements.length; if (verts <= availVerts && elems <= availElems) return vertIdx; // otherwise, flush and expand our buffers if needed flush(); if (verts > availVerts) expandVerts(verts); if (elems > availElems) expandElems(elems); return 0; }
/** Creates a triangle batch with the supplied custom shader program. */ public TriangleBatch (GL20 gl, Source source) { super(gl); delayedBinding = "Intel".equals(gl.glGetString(GL20.GL_VENDOR)); program = new GLProgram(gl, source.vertex(), source.fragment()); uTexture = program.getUniformLocation("u_Texture"); uHScreenSize = program.getUniformLocation("u_HScreenSize"); uFlip = program.getUniformLocation("u_Flip"); aMatrix = program.getAttribLocation("a_Matrix"); aTranslation = program.getAttribLocation("a_Translation"); aColor = program.getAttribLocation("a_Color"); aPosition = program.getAttribLocation("a_Position"); aTexCoord = program.getAttribLocation("a_TexCoord"); // create our vertex and index buffers stableAttrs = new float[stableAttrsSize()]; vertices = new float[START_VERTS*vertexSize()]; elements = new short[START_ELEMS]; // create our GL buffers int[] ids = new int[2]; gl.glGenBuffers(2, ids, 0); verticesId = ids[0]; elementsId = ids[1]; gl.checkError("TriangleBatch end ctor"); }
/** Creates a triangle batch with the supplied custom shader program. */ public TriangleBatch (GL20 gl, Source source) { super(gl); delayedBinding = "Intel".equals(gl.glGetString(GL20.GL_VENDOR)); program = new GLProgram(gl, source.vertex(), source.fragment()); uTexture = program.getUniformLocation("u_Texture"); uHScreenSize = program.getUniformLocation("u_HScreenSize"); uFlip = program.getUniformLocation("u_Flip"); aMatrix = program.getAttribLocation("a_Matrix"); aTranslation = program.getAttribLocation("a_Translation"); aColor = program.getAttribLocation("a_Color"); aPosition = program.getAttribLocation("a_Position"); aTexCoord = program.getAttribLocation("a_TexCoord"); // create our vertex and index buffers stableAttrs = new float[stableAttrsSize()]; vertices = new float[START_VERTS*vertexSize()]; elements = new short[START_ELEMS]; // create our GL buffers int[] ids = new int[2]; gl.glGenBuffers(2, ids, 0); verticesId = ids[0]; elementsId = ids[1]; gl.checkError("TriangleBatch end ctor"); }