Removed state tracking from vertex attributes because GL can only bind with one at a time.

This commit is contained in:
Harrison Deng 2020-02-20 00:30:10 -05:00
parent 289799a6af
commit 7512f66cdb

View File

@ -5,20 +5,15 @@ namespace RecrownedGTK.Graphics {
public class VertexAttributesHandle : IDisposable {
private bool disposed;
private int handle;
private bool begun;
public VertexAttributesHandle() {
handle = GL.GenVertexArray();
}
public void Begin() {
if (begun) throw new InvalidOperationException("The VertexArrayHandle has already been started.");
public void Bind() {
GL.BindVertexArray(handle);
begun = true;
}
public void End() {
if (!begun) throw new InvalidOperationException("The VertexArrayHandle has never been started.");
GL.BindVertexArray(0);
begun = false;
}
/// <summary>
@ -33,16 +28,19 @@ namespace RecrownedGTK.Graphics {
public static VertexAttributesHandle CreateBasicVA(Shader shader = null, string positionAttribName = "aPosition", string textureAttribName = "aTexture", string colorAttribName = "aColor") {
if (shader == null) shader = Shader.CreateBasicShader();
VertexAttributesHandle vertexAttribs = new VertexAttributesHandle();
vertexAttribs.Bind();
GL.VertexAttribPointer(shader.GetAttribLocation(positionAttribName), 3, VertexAttribPointerType.Float, false, 9 * sizeof(float), 0);
GL.VertexAttribPointer(shader.GetAttribLocation(textureAttribName), 2, VertexAttribPointerType.Float, true, 9 * sizeof(float), 3 * sizeof(float));
GL.VertexAttribPointer(shader.GetAttribLocation(textureAttribName), 2, VertexAttribPointerType.Float, false, 9 * sizeof(float), 3 * sizeof(float));
GL.VertexAttribPointer(shader.GetAttribLocation(colorAttribName), 4, VertexAttribPointerType.Float, false, 9 * sizeof(float), 5 * sizeof(float));
vertexAttribs.End();
return vertexAttribs;
}
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing) {
if (disposed) return;
if (disposing) {