public static IndexBufferData<?> convertQuadIndicesToTriangles(final int[] quadIndices, final int vertexCount) { final int qIndices = quadIndices.length; if (qIndices < 4 || (qIndices % 4) != 0) { throw new IllegalArgumentException("Quad data should have 4*N indices where N=[1,R]"); } final int quads = qIndices / 4; final int tris = 2 * quads; final int tVerts = tris * 3; final IndexBufferData<?> rVal = BufferUtils.createIndexBufferData(tVerts, vertexCount - 1); // write our new data by walking through our quads for (int q = 0; q < quads; q++) { final int offsetSrc = q * 4; // 0 1 2 rVal.put(quadIndices[offsetSrc + 0]); rVal.put(quadIndices[offsetSrc + 1]); rVal.put(quadIndices[offsetSrc + 2]); // 2 1 3 rVal.put(quadIndices[offsetSrc + 2]); rVal.put(quadIndices[offsetSrc + 1]); rVal.put(quadIndices[offsetSrc + 3]); } return rVal; } }
private void setIndexData() { final IndexBufferData<?> indices = _meshData.getIndices(); indices.getBuffer().rewind(); indices.put(4).put(0).put(2); indices.put(4).put(2).put(1); indices.put(4).put(1).put(3); indices.put(4).put(3).put(0); indices.put(5).put(2).put(0); indices.put(5).put(1).put(2); indices.put(5).put(3).put(1); indices.put(5).put(0).put(3); }
private void setIndexData() { final IndexBufferData<?> indices = BufferUtils.createIndexBufferData(6 * _meshData.getVertexCount(), _meshData.getVertexCount() - 1); for (int i = _radialSamples; i < _meshData.getVertexCount() + (_radialSamples); i++) { indices.put(i); indices.put(i - _radialSamples); indices.put(i + 1); indices.put(i + 1); indices.put(i - _radialSamples); indices.put(i - _radialSamples + 1); } for (int i = 0, len = indices.getBufferCapacity(); i < len; i++) { int ind = indices.get(i); if (ind < 0) { ind += _meshData.getVertexCount(); indices.put(i, ind); } if (ind >= _meshData.getVertexCount()) { ind -= _meshData.getVertexCount(); indices.put(i, ind); } } indices.getBuffer().rewind(); _meshData.setIndices(indices); }
/** * Create a new int[] array and populate it with the given IndexBufferData's contents. * * @param buff * the IndexBufferData to read from * @return a new int array populated from the IndexBufferData */ public static int[] getIntArray(final IndexBufferData<?> buff) { if (buff == null || buff.getBufferLimit() == 0) { return null; } buff.getBuffer().rewind(); final int[] inds = new int[buff.getBufferLimit()]; for (int x = 0; x < inds.length; x++) { inds[x] = buff.get(); } return inds; }
public static IndexBufferData<?> convertQuadIndicesToTriangles(final IndexBufferData<?> quadIndices, final int vertexCount) { final int[] indices = new int[quadIndices.getBufferLimit()]; for (int i = 0; i < indices.length; i++) { indices[i] = quadIndices.get(i); } return convertQuadIndicesToTriangles(indices, vertexCount); }
/** * Creates a new IndexBufferData with the same contents as the given IndexBufferData. The new IndexBufferData is * separate from the old one and changes are not reflected across. * * @param buf * the IndexBufferData to copy * @return the copy */ @SuppressWarnings("unchecked") public static IndexBufferData<?> clone(final IndexBufferData<?> buf) { if (buf == null) { return null; } final IndexBufferData<?> copy = createIndexBufferData(buf.getBufferLimit(), (Class<? extends IndexBufferData<?>>) buf.getClass()); if (buf.getBuffer() == null) { copy.setBuffer(null); } else { buf.getBuffer().rewind(); copy.put(buf); } return copy; }
private void setIndexData() { final IndexBufferData<?> indices = _meshData.getIndices(); indices.rewind(); indices.put(0).put(8).put(9); indices.put(0).put(9).put(4); indices.put(0).put(4).put(16); indices.put(0).put(12).put(13); indices.put(0).put(13).put(1); indices.put(0).put(1).put(8); indices.put(0).put(16).put(17); indices.put(0).put(17).put(2); indices.put(0).put(2).put(12); indices.put(8).put(1).put(18); indices.put(8).put(18).put(5); indices.put(8).put(5).put(9); indices.put(12).put(2).put(10); indices.put(12).put(10).put(3); indices.put(12).put(3).put(13); indices.put(16).put(4).put(14); indices.put(16).put(14).put(6); indices.put(16).put(6).put(17); indices.put(9).put(5).put(15); indices.put(9).put(15).put(14); indices.put(9).put(14).put(4); indices.put(6).put(11).put(10); indices.put(6).put(10).put(2); indices.put(6).put(2).put(17); indices.put(3).put(19).put(18); indices.put(3).put(18).put(1); indices.put(3).put(1).put(13);
IndexBufferData<?> dstInds = dstMeshData.getIndices(); if (dstInds != null) { dstInds.rewind(); srcInds.clear(); if (dstInds == null || dstInds.capacity() != srcInds.capacity() || dstInds.getClass() != srcInds.getClass()) { dstInds = BufferUtils.createIndexBufferData(srcInds.capacity(), srcMeshData.getVertexBuffer().capacity() - 1); dstInds.clear(); dstMeshData.setIndices(dstInds); dstInds.put(srcInds); dstInds.flip(); dstMeshData.markIndicesDirty();
/** * Gets the index buffer. * * @return the index buffer */ public Buffer getIndexBuffer() { if (_indexBuffer == null) { return null; } return _indexBuffer.getBuffer(); }
int vboID = data.getVBOID(context.getGlContextRep()); if (vboID != 0) { if (data.isNeedsRefresh()) { final Buffer dataBuffer = data.getBuffer(); dataBuffer.rewind(); JoglRendererUtil.setBoundElementVBO(rendRecord, vboID); gl.glBufferSubData(GL.GL_ELEMENT_ARRAY_BUFFER, 0, dataBuffer.limit() * data.getByteCount(), dataBuffer); data.setNeedsRefresh(false); final Buffer dataBuffer = data.getBuffer(); if (dataBuffer != null) { data.setVBOID(context.getGlContextRep(), vboID); gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, dataBuffer.limit() * data.getByteCount(), dataBuffer, getGLVBOAccessMode(data.getVboAccessMode())); } else { throw new Ardor3dException("Attempting to create a vbo id for a IndexBufferData with no Buffer value.");
@Override public void drawElements(final IndexBufferData<?> indices, final int[] indexLengths, final IndexMode[] indexModes, final int primcount) { if (indices == null || indices.getBuffer() == null) { logger.severe("Missing indices for drawElements call without VBO"); return; indices.position(0); if (indices.getBuffer() instanceof IntBuffer) { if (primcount < 0) { GL11.glDrawElements(glIndexMode, (IntBuffer) indices.getBuffer()); } else { GL31.glDrawElementsInstanced(glIndexMode, (IntBuffer) indices.getBuffer(), primcount); } else if (indices.getBuffer() instanceof ShortBuffer) { if (primcount < 0) { GL11.glDrawElements(glIndexMode, (ShortBuffer) indices.getBuffer()); } else { GL31.glDrawElementsInstanced(glIndexMode, (ShortBuffer) indices.getBuffer(), primcount); } else if (indices.getBuffer() instanceof ByteBuffer) { if (primcount < 0) { GL11.glDrawElements(glIndexMode, (ByteBuffer) indices.getBuffer()); } else { GL31.glDrawElementsInstanced(glIndexMode, (ByteBuffer) indices.getBuffer(), primcount); addStats(indexModes[0], indices.getBufferLimit()); indices.getBuffer().position(offset); indices.getBuffer().limit(offset + count);
result[i] = getIndices().get(getVertexIndex(primitiveIndex, i, section)); } else { result[i] = getVertexIndex(primitiveIndex, i, section);
gl.glDrawElements(glIndexMode, indices.getBufferLimit(), type, 0); } else { if (gl.isGL2GL3()) { gl.getGL2GL3().glDrawElementsInstanced(glIndexMode, indices.getBufferLimit(), type, indices.getBuffer(), primcount); addStats(indexModes[0], indices.getBufferLimit()); final int byteSize = indices.getByteCount(); gl.glDrawElements(glIndexMode, count, type, offset * byteSize); } else { final int previousPos = indices.getBuffer().position(); indices.getBuffer().position(offset * byteSize); if (gl.isGL2GL3()) { gl.getGL2GL3() .glDrawElementsInstanced(glIndexMode, count, type, indices.getBuffer(), primcount); indices.getBuffer().position(previousPos);
/** * Update primitive counts. */ private void updatePrimitiveCounts() { final int maxIndex = _indexBuffer != null ? _indexBuffer.getBufferLimit() : _vertexCount; final int maxSection = _indexLengths != null ? _indexLengths.length : 1; if (_primitiveCounts.length != maxSection) { _primitiveCounts = new int[maxSection]; } for (int i = 0; i < maxSection; i++) { final int size = _indexLengths != null ? _indexLengths[i] : maxIndex; final int count = IndexMode.getPrimitiveCount(getIndexMode(i), size); _primitiveCounts[i] = count; } }
GL11.glDrawElements(glIndexMode, indices.getBufferLimit(), type, 0); } else { GL31.glDrawElementsInstanced(glIndexMode, indices.getBufferLimit(), type, 0, primcount); addStats(indexModes[0], indices.getBufferLimit()); final int byteSize = indices.getByteCount();
useIndices = true; if (md.getIndices() != null) { totalIndices += md.getIndices().capacity(); } else { totalIndices += md.getVertexCount();