@Override public void updateIndices (int targetOffset, short[] indices, int offset, int count) { isDirty = true; final int pos = byteBuffer.position(); byteBuffer.position(targetOffset * 2); BufferUtils.copy(indices, offset, byteBuffer, count); byteBuffer.position(pos); buffer.position(0); if (isBound) { Gdx.gl20.glBufferSubData(GL20.GL_ELEMENT_ARRAY_BUFFER, 0, byteBuffer.limit(), byteBuffer); isDirty = false; } }
@Override public void updateIndices (int targetOffset, short[] indices, int offset, int count) { isDirty = true; final int pos = byteBuffer.position(); byteBuffer.position(targetOffset * 2); BufferUtils.copy(indices, offset, byteBuffer, count); byteBuffer.position(pos); buffer.position(0); if (isBound) { Gdx.gl20.glBufferSubData(GL20.GL_ELEMENT_ARRAY_BUFFER, 0, byteBuffer.limit(), byteBuffer); isDirty = false; } }
@Override public void updateIndices (int targetOffset, short[] indices, int offset, int count) { isDirty = true; final int pos = byteBuffer.position(); byteBuffer.position(targetOffset * 2); BufferUtils.copy(indices, offset, byteBuffer, count); byteBuffer.position(pos); buffer.position(0); if (isBound) { Gdx.gl20.glBufferData(GL20.GL_ELEMENT_ARRAY_BUFFER, byteBuffer.limit(), byteBuffer, usage); isDirty = false; } }
@Override public void updateIndices (int targetOffset, short[] indices, int offset, int count) { isDirty = true; final int pos = byteBuffer.position(); byteBuffer.position(targetOffset * 2); BufferUtils.copy(indices, offset, byteBuffer, count); byteBuffer.position(pos); buffer.position(0); if (isBound) { Gdx.gl20.glBufferData(GL20.GL_ELEMENT_ARRAY_BUFFER, byteBuffer.limit(), byteBuffer, usage); isDirty = false; } }
/** Returns a string representing the state of this short buffer. * * @return a string representing the state of this short buffer. * @since Android 1.0 */ public String toString () { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()); sb.append(", status: capacity="); //$NON-NLS-1$ sb.append(capacity()); sb.append(" position="); //$NON-NLS-1$ sb.append(position()); sb.append(" limit="); //$NON-NLS-1$ sb.append(limit()); return sb.toString(); } }
/** Returns a string representing the state of this short buffer. * * @return a string representing the state of this short buffer. * @since Android 1.0 */ public String toString () { StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()); sb.append(", status: capacity="); //$NON-NLS-1$ sb.append(capacity()); sb.append(" position="); //$NON-NLS-1$ sb.append(position()); sb.append(" limit="); //$NON-NLS-1$ sb.append(limit()); return sb.toString(); } }
public void setIndices (ShortBuffer indices) { int pos = indices.position(); isDirty = true; buffer.clear(); buffer.put(indices); buffer.flip(); indices.position(pos); byteBuffer.position(0); byteBuffer.limit(buffer.limit() << 1); if (isBound) { Gdx.gl20.glBufferSubData(GL20.GL_ELEMENT_ARRAY_BUFFER, 0, byteBuffer.limit(), byteBuffer); isDirty = false; } }
public void setIndices (ShortBuffer indices) { int pos = indices.position(); isDirty = true; buffer.clear(); buffer.put(indices); buffer.flip(); indices.position(pos); byteBuffer.position(0); byteBuffer.limit(buffer.limit() << 1); if (isBound) { Gdx.gl20.glBufferSubData(GL20.GL_ELEMENT_ARRAY_BUFFER, 0, byteBuffer.limit(), byteBuffer); isDirty = false; } }
public void setIndices (ShortBuffer indices) { isDirty = true; int pos = indices.position(); buffer.clear(); buffer.put(indices); buffer.flip(); indices.position(pos); byteBuffer.position(0); byteBuffer.limit(buffer.limit() << 1); if (isBound) { Gdx.gl20.glBufferData(GL20.GL_ELEMENT_ARRAY_BUFFER, byteBuffer.limit(), byteBuffer, usage); isDirty = false; } }
public void setIndices (ShortBuffer indices) { isDirty = true; int pos = indices.position(); buffer.clear(); buffer.put(indices); buffer.flip(); indices.position(pos); byteBuffer.position(0); byteBuffer.limit(buffer.limit() << 1); if (isBound) { Gdx.gl20.glBufferData(GL20.GL_ELEMENT_ARRAY_BUFFER, byteBuffer.limit(), byteBuffer, usage); isDirty = false; } }
/** Copies the indices from the Mesh to the short array. The short array must be large enough to hold destOffset + count * indices. * @param srcOffset the zero-based offset of the first index to fetch * @param count the total amount of indices to copy * @param indices the array to copy the indices to * @param destOffset the offset in the indices array to start copying */ public void getIndices (int srcOffset, int count, short[] indices, int destOffset) { int max = getNumIndices(); if (count < 0) count = max - srcOffset; if (srcOffset < 0 || srcOffset >= max || srcOffset + count > max) throw new IllegalArgumentException("Invalid range specified, offset: " + srcOffset + ", count: " + count + ", max: " + max); if ((indices.length - destOffset) < count) throw new IllegalArgumentException("not enough room in indices array, has " + indices.length + " shorts, needs " + count); int pos = getIndicesBuffer().position(); getIndicesBuffer().position(srcOffset); getIndicesBuffer().get(indices, destOffset, count); getIndicesBuffer().position(pos); }
/** Copies the indices from the Mesh to the short array. The short array must be large enough to hold destOffset + count * indices. * @param srcOffset the zero-based offset of the first index to fetch * @param count the total amount of indices to copy * @param indices the array to copy the indices to * @param destOffset the offset in the indices array to start copying */ public void getIndices (int srcOffset, int count, short[] indices, int destOffset) { int max = getNumIndices(); if (count < 0) count = max - srcOffset; if (srcOffset < 0 || srcOffset >= max || srcOffset + count > max) throw new IllegalArgumentException("Invalid range specified, offset: " + srcOffset + ", count: " + count + ", max: " + max); if ((indices.length - destOffset) < count) throw new IllegalArgumentException("not enough room in indices array, has " + indices.length + " shorts, needs " + count); int pos = getIndicesBuffer().position(); getIndicesBuffer().position(srcOffset); getIndicesBuffer().get(indices, destOffset, count); getIndicesBuffer().position(pos); }
public Int16Array copy (ShortBuffer buffer) { if (GWT.isProdMode()) { return ((Int16Array)((HasArrayBufferView)buffer).getTypedArray()).subarray(buffer.position(), buffer.remaining()); } else { ensureCapacity(buffer); for (int i = buffer.position(), j = 0; i < buffer.limit(); i++, j++) { shortBuffer.set(j, buffer.get(i)); } return shortBuffer.subarray(0, buffer.remaining()); } }
public Int16Array copy (ShortBuffer buffer) { if (GWT.isProdMode()) { return ((Int16Array)((HasArrayBufferView)buffer).getTypedArray()).subarray(buffer.position(), buffer.remaining()); } else { ensureCapacity(buffer); for (int i = buffer.position(), j = 0; i < buffer.limit(); i++, j++) { shortBuffer.set(j, buffer.get(i)); } return shortBuffer.subarray(0, buffer.remaining()); } }
/** Returns the next buffer with size up to {@code sizeBytes}. */ public ByteBuffer getNextInputBuffer(int sizeBytes) { ByteBuffer inputBuffer = ByteBuffer.allocate(sizeBytes).order(ByteOrder.nativeOrder()); ShortBuffer inputBufferAsShortBuffer = inputBuffer.asShortBuffer(); int limit = buffer.limit(); buffer.limit(Math.min(buffer.position() + sizeBytes / 2, limit)); inputBufferAsShortBuffer.put(buffer); buffer.limit(limit); inputBuffer.limit(inputBufferAsShortBuffer.position() * 2); return inputBuffer; }
@Override public void flush () { if (idx == 0) return; renderCalls++; totalRenderCalls++; int spritesInBatch = idx / 20; if (spritesInBatch > maxSpritesInBatch) maxSpritesInBatch = spritesInBatch; int count = spritesInBatch * 6; lastTexture.bind(); Mesh mesh = this.mesh; mesh.setVertices(vertices, 0, idx); mesh.getIndicesBuffer().position(0); mesh.getIndicesBuffer().limit(count); if (blendingDisabled) { Gdx.gl.glDisable(GL20.GL_BLEND); } else { Gdx.gl.glEnable(GL20.GL_BLEND); if (blendSrcFunc != -1) Gdx.gl.glBlendFuncSeparate(blendSrcFunc, blendDstFunc, blendSrcFuncAlpha, blendDstFuncAlpha); } mesh.render(customShader != null ? customShader : shader, GL20.GL_TRIANGLES, 0, count); idx = 0; }
@Override public void flush () { if (idx == 0) return; renderCalls++; totalRenderCalls++; int spritesInBatch = idx / 20; if (spritesInBatch > maxSpritesInBatch) maxSpritesInBatch = spritesInBatch; int count = spritesInBatch * 6; lastTexture.bind(); Mesh mesh = this.mesh; mesh.setVertices(vertices, 0, idx); mesh.getIndicesBuffer().position(0); mesh.getIndicesBuffer().limit(count); if (blendingDisabled) { Gdx.gl.glDisable(GL20.GL_BLEND); } else { Gdx.gl.glEnable(GL20.GL_BLEND); if (blendSrcFunc != -1) Gdx.gl.glBlendFuncSeparate(blendSrcFunc, blendDstFunc, blendSrcFuncAlpha, blendDstFuncAlpha); } mesh.render(customShader != null ? customShader : shader, GL20.GL_TRIANGLES, 0, count); idx = 0; }
@Override public void render () { GL20 gl = Gdx.gl20; gl.glViewport(0, 0, Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()); Gdx.gl.glClearColor(0.7f, 0, 0, 1); gl.glClear(GL20.GL_COLOR_BUFFER_BIT); gl.glEnable(GL20.GL_TEXTURE_2D); shader.begin(); shader.setUniformi("u_texture", 0); texture.bind(); vbo.bind(shader); indices.bind(); gl.glDrawElements(GL20.GL_TRIANGLES, 3, GL20.GL_UNSIGNED_SHORT, indices.getBuffer().position()); indices.unbind(); vbo.unbind(shader); shader.end(); }