Package k8.buffer.vbo

Source Code of k8.buffer.vbo.VBOIndicesBuffer

package k8.buffer.vbo;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;

import k8.buffer.IndicesBuffer;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.ARBVertexBufferObject;


public final class VBOIndicesBuffer extends IndicesBuffer {
   
    private int id;
 
    /**
     * Creates an instance of VBOIndicesBuffer.
     *
     * @param capacity
     *          Initial capacity (number of vertices)
     */
    public VBOIndicesBuffer(int capacity) {
        super(capacity);
        IntBuffer int_buffer = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
        ARBVertexBufferObject.glGenBuffersARB(int_buffer);
        id = int_buffer.get(0);
    }

    @Override
    public void destroy() {
        IntBuffer int_buffer = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
        int_buffer.put(id);
        ARBVertexBufferObject.glDeleteBuffersARB(int_buffer);
    }

    @Override
    public void glDrawElements() {
      ARBVertexBufferObject.glBindBufferARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, id);
      if ( flush ) {
        buffer.rewind();
            ARBVertexBufferObject.glBufferDataARB(ARBVertexBufferObject.GL_ELEMENT_ARRAY_BUFFER_ARB, buffer, ARBVertexBufferObject.GL_STATIC_DRAW_ARB);
            flush = false;
      }
        GL11.glDrawElements(GL11.GL_TRIANGLES, elements, GL11.GL_UNSIGNED_INT, 0);
    }
   
}
TOP

Related Classes of k8.buffer.vbo.VBOIndicesBuffer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.