This commit is contained in:
@@ -1,33 +0,0 @@
|
|||||||
package chess.view.DDDrender;
|
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL30;
|
|
||||||
|
|
||||||
public class ElementBuffer {
|
|
||||||
private int id;
|
|
||||||
private 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 Destroy() {
|
|
||||||
GL30.glDeleteBuffers(this.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package chess.view.DDDrender;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL30;
|
|
||||||
|
|
||||||
public class VertexArray {
|
|
||||||
private int id;
|
|
||||||
private ElementBuffer elementBuffer;
|
|
||||||
private List<VertexBuffer> vertexBuffers;
|
|
||||||
|
|
||||||
public VertexArray(ElementBuffer elementBuffer) {
|
|
||||||
this.id = GL30.glGenVertexArrays();
|
|
||||||
this.elementBuffer = elementBuffer;
|
|
||||||
this.vertexBuffers = new ArrayList<VertexBuffer>();
|
|
||||||
Bind();
|
|
||||||
BindElementArrayBuffer();
|
|
||||||
Unbind();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Destroy() {
|
|
||||||
GL30.glDeleteBuffers(this.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package chess.view.DDDrender;
|
|
||||||
|
|
||||||
public record VertexAttribPointer(int index, int size, int offset) {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
package chess.view.DDDrender;
|
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.GL_FLOAT;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL30;
|
|
||||||
|
|
||||||
public class VertexBuffer {
|
|
||||||
private int id;
|
|
||||||
private int dataStride;
|
|
||||||
List<VertexAttribPointer> vertexAttribs;
|
|
||||||
|
|
||||||
public VertexBuffer(float[] data, int stride) {
|
|
||||||
this.id = GL30.glGenBuffers();
|
|
||||||
this.dataStride = stride;
|
|
||||||
this.vertexAttribs = new ArrayList<VertexAttribPointer>();
|
|
||||||
Bind();
|
|
||||||
GL30.glBufferData(GL30.GL_ARRAY_BUFFER, data.length * 4, GL30.GL_STATIC_DRAW);
|
|
||||||
GL30.glBufferSubData(GL30.GL_ARRAY_BUFFER, 0, data);
|
|
||||||
Unbind();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Destroy() {
|
|
||||||
GL30.glDeleteBuffers(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Bind() {
|
|
||||||
GL30.glBindBuffer(GL30.GL_ARRAY_BUFFER, this.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Unbind() {
|
|
||||||
GL30.glBindBuffer(GL30.GL_ARRAY_BUFFER, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void AddVertexAttribPointer(int index, int coordinateSize, int offset) {
|
|
||||||
VertexAttribPointer pointer = new VertexAttribPointer(index, coordinateSize, offset);
|
|
||||||
this.vertexAttribs.add(pointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void BindVertexAttribs() {
|
|
||||||
for (VertexAttribPointer vertexAttribPointer : vertexAttribs) {
|
|
||||||
GL30.glEnableVertexAttribArray(vertexAttribPointer.index());
|
|
||||||
GL30.glVertexAttribPointer(vertexAttribPointer.index(), vertexAttribPointer.size(), GL_FLOAT, false,
|
|
||||||
this.dataStride * 4, vertexAttribPointer.offset());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user