Skip to content

Instantly share code, notes, and snippets.

@mamontov-cpp
Created April 26, 2018 11:49
Show Gist options
  • Save mamontov-cpp/0fafc012fbddc5ce359b2c1f7204f33e to your computer and use it in GitHub Desktop.
Save mamontov-cpp/0fafc012fbddc5ce359b2c1f7204f33e to your computer and use it in GitHub Desktop.
VBOUtils.java
package gl;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.ARBVertexBufferObject;
import org.lwjgl.opengl.ContextCapabilities;
import org.lwjgl.opengl.GLContext;
public class VBOUtils
{
public static int createBuffer()
{
if (supportsBuffers())
{
IntBuffer buffer = BufferUtils.createIntBuffer(1);
ARBVertexBufferObject.glGenBuffersARB(buffer);
return buffer.get(0);
}
return 0;
}
public static void storeVertexData(int bufferIndex, FloatBuffer geometryData)
{
if (supportsBuffers())
{
ARBVertexBufferObject.glBindBufferARB(34962, bufferIndex);
ARBVertexBufferObject.glBufferDataARB(34962, geometryData, 35044);
}
}
public static void storeIndexData(int bufferIndex, IntBuffer indexes)
{
if (supportsBuffers())
{
ARBVertexBufferObject.glBindBufferARB(34963, bufferIndex);
ARBVertexBufferObject.glBufferDataARB(34963, indexes, 35044);
}
}
public static void destroyBuffers(ArrayList<Integer> bufferList)
{
if (!supportsBuffers()) {
return;
}
IntBuffer bufferIDBuffer = BufferUtils.createIntBuffer(bufferList.size());
for (int i = 0; i < bufferList.size(); i++) {
bufferIDBuffer.put(((Integer)bufferList.get(i)).intValue());
}
bufferIDBuffer.rewind();
ARBVertexBufferObject.glDeleteBuffersARB(bufferIDBuffer);
}
private static boolean supportsBuffers()
{
return GLContext.getCapabilities().GL_ARB_vertex_buffer_object;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment