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