Renamed VertexAttributesHandle.cs and added transformation matrix to convenience function.

This commit is contained in:
Harrison Deng 2020-02-20 16:06:37 -05:00
parent 72a8cc9206
commit b806da6349

View File

@ -1,11 +1,12 @@
using System;
using OpenTK.Graphics.OpenGL;
using OpenTK;
using RecrownedGTK.Graphics.Render.Shader;
namespace RecrownedGTK.Graphics {
public class VertexAttributesHandle : IDisposable {
public class VertexAttributesArrayHandle : IDisposable {
private bool disposed;
private int handle;
public VertexAttributesHandle() {
public VertexAttributesArrayHandle() {
handle = GL.GenVertexArray();
}
@ -21,15 +22,16 @@ namespace RecrownedGTK.Graphics {
/// <param name="positionAttribName">The name of the attribute for the vertex's position in the shader. Default is "aPosition".</param>
/// <param name="textureAttribName">The name of the attribute for the texture's coordinate. Default is "aTexture".</param>
/// <param name="colorAttribName">The name of the attribute for color mixture. Default is "aColor".</param>
/// <returns>The built <see cref="RecrownedGTK.Graphics.VertexAttributesHandle"/>.</returns>
public static VertexAttributesHandle CreateBasicVA(Shader shader = null, string positionAttribName = "aPosition", string textureAttribName = "aTexture", string colorAttribName = "aColor") {
/// <returns>The built <see cref="RecrownedGTK.Graphics.VertexAttributesArrayHandle"/>.</returns>
public static VertexAttributesArrayHandle CreateBasicVA(Shader shader = null, string positionAttribName = "aPosition", string textureAttribName = "aTexture", string colorAttribName = "aColor", string transformUnifName = "transform", Matrix4 transformMat = default(Matrix4)) {
if (shader == null) shader = Shader.CreateBasicShader();
VertexAttributesHandle vertexAttribs = new VertexAttributesHandle();
VertexAttributesArrayHandle vertexAttribs = new VertexAttributesArrayHandle();
vertexAttribs.Bind();
if (transformMat == default(Matrix4)) transformMat = Matrix4.Identity;
GL.UniformMatrix4(shader.GetAttribLocation(transformUnifName), true, ref transformMat);
GL.VertexAttribPointer(shader.GetAttribLocation(positionAttribName), 3, VertexAttribPointerType.Float, false, 9 * sizeof(float), 0);
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;
}
@ -46,7 +48,7 @@ namespace RecrownedGTK.Graphics {
GL.DeleteVertexArray(handle);
disposed = true;
}
~VertexAttributesHandle() {
~VertexAttributesArrayHandle() {
Dispose(false);
}
}