Vbo.java 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package eu.tankernn.gameEngine.renderEngine;
  2. import java.nio.FloatBuffer;
  3. import java.nio.IntBuffer;
  4. import org.lwjgl.BufferUtils;
  5. import org.lwjgl.opengl.GL15;
  6. public class Vbo {
  7. private final int vboId;
  8. private final int type;
  9. private Vbo(int vboId, int type){
  10. this.vboId = vboId;
  11. this.type = type;
  12. }
  13. public static Vbo create(int type){
  14. int id = GL15.glGenBuffers();
  15. return new Vbo(id, type);
  16. }
  17. public void bind(){
  18. GL15.glBindBuffer(type, vboId);
  19. }
  20. public void unbind(){
  21. GL15.glBindBuffer(type, vboId);
  22. }
  23. public void storeData(float[] data){
  24. FloatBuffer buffer = BufferUtils.createFloatBuffer(data.length);
  25. buffer.put(data);
  26. buffer.flip();
  27. storeData(buffer);
  28. }
  29. public void storeData(FloatBuffer data){
  30. GL15.glBufferData(type, data, GL15.GL_STATIC_DRAW);
  31. }
  32. public void storeData(int[] data){
  33. IntBuffer buffer = BufferUtils.createIntBuffer(data.length);
  34. buffer.put(data);
  35. buffer.flip();
  36. storeData(buffer);
  37. }
  38. public void storeData(IntBuffer data){
  39. GL15.glBufferData(type, data, GL15.GL_STATIC_DRAW);
  40. }
  41. public void delete(){
  42. GL15.glDeleteBuffers(vboId);
  43. }
  44. }