Files
3DChess/app/src/main/java/chess/view/DDDrender/opengl/ElementBuffer.java
2025-04-28 18:23:29 +02:00

38 lines
856 B
Java

package chess.view.DDDrender.opengl;
import java.io.Closeable;
import java.io.IOException;
import org.lwjgl.opengl.GL30;
public class ElementBuffer implements Closeable {
private final int id;
private final int indiciesCount;
public ElementBuffer(int[] indicies) {
this.indiciesCount = indicies.length;
this.id = GL30.glGenBuffers();
Bind();
GL30.glBufferData(GL30.GL_ELEMENT_ARRAY_BUFFER, indicies.length * 4, GL30.GL_STATIC_DRAW);
GL30.glBufferSubData(GL30.GL_ELEMENT_ARRAY_BUFFER, 0, indicies);
Unbind();
}
public void Bind() {
GL30.glBindBuffer(GL30.GL_ELEMENT_ARRAY_BUFFER, this.id);
}
public void Unbind() {
GL30.glBindBuffer(GL30.GL_ELEMENT_ARRAY_BUFFER, 0);
}
public int GetIndiciesCount() {
return this.indiciesCount;
}
@Override
public void close() throws IOException {
GL30.glDeleteBuffers(this.id);
}
}