60 lines
1.2 KiB
Java
60 lines
1.2 KiB
Java
package chess.view.DDDrender.opengl;
|
|
|
|
import java.io.Closeable;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.lwjgl.opengl.GL30;
|
|
|
|
public class VertexArray implements Closeable {
|
|
|
|
private final int id;
|
|
private final ElementBuffer elementBuffer;
|
|
private final List<VertexBuffer> vertexBuffers;
|
|
|
|
public VertexArray(ElementBuffer elementBuffer) {
|
|
this.id = GL30.glGenVertexArrays();
|
|
this.elementBuffer = elementBuffer;
|
|
this.vertexBuffers = new ArrayList<VertexBuffer>();
|
|
Bind();
|
|
BindElementArrayBuffer();
|
|
Unbind();
|
|
}
|
|
|
|
public int GetVertexCount() {
|
|
return this.elementBuffer.GetIndiciesCount();
|
|
}
|
|
|
|
public void BindVertexBuffer(VertexBuffer buffer) {
|
|
buffer.Bind();
|
|
buffer.BindVertexAttribs();
|
|
this.vertexBuffers.add(buffer);
|
|
}
|
|
|
|
public void Bind() {
|
|
GL30.glBindVertexArray(this.id);
|
|
}
|
|
|
|
public void Unbind() {
|
|
GL30.glBindVertexArray(0);
|
|
}
|
|
|
|
private void BindElementArrayBuffer() {
|
|
this.elementBuffer.Bind();
|
|
}
|
|
|
|
public List<VertexBuffer> getVertexBuffers() {
|
|
return vertexBuffers;
|
|
}
|
|
|
|
@Override
|
|
public void close() throws IOException {
|
|
GL30.glDeleteBuffers(this.id);
|
|
for (VertexBuffer vertexBuffer : vertexBuffers) {
|
|
vertexBuffer.close();
|
|
}
|
|
elementBuffer.close();
|
|
}
|
|
}
|