Code example for Buffer

Methods: capacity

0
     *            Mesh index buffer. Must either be an IntBuffer or a ShortBuffer. 
     */ 
    private void createIndexBufferObject(Buffer indexBuffer) {
        int sizeInBytes = 0;
        if (indexBuffer instanceof ShortBuffer) {
            sizeInBytes = indexBuffer.capacity() * 2;
            mIndexBufferType = GL_UNSIGNED_SHORT;
        } else if (indexBuffer instanceof IntBuffer) {
            sizeInBytes = indexBuffer.capacity() * 4;
            mIndexBufferType = GL_UNSIGNED_INT;
        } else { 
            throw new IllegalArgumentException(
                    "indexBuffer must either be an IntBuffer or a ShortBuffer"); 
        } 
        mIndexBufferSize = indexBuffer.capacity();
 
        // create buffer object 
        int[] buf = new int[1];
        glGenBuffers(1, buf, 0);
        mIndexBufferHandle = buf[0];
 
        // copy buffer data 
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBufferHandle);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeInBytes, indexBuffer, GL_STATIC_DRAW);
    } 
     
    /** 
     * Deletes all buffers associated with this mesh. 
     */