Renamed VertexAttributesHandle.cs and added transformation matrix to convenience function.
This commit is contained in:
parent
72a8cc9206
commit
b806da6349
@ -1,11 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using OpenTK.Graphics.OpenGL;
|
using OpenTK.Graphics.OpenGL;
|
||||||
|
using OpenTK;
|
||||||
using RecrownedGTK.Graphics.Render.Shader;
|
using RecrownedGTK.Graphics.Render.Shader;
|
||||||
namespace RecrownedGTK.Graphics {
|
namespace RecrownedGTK.Graphics {
|
||||||
public class VertexAttributesHandle : IDisposable {
|
public class VertexAttributesArrayHandle : IDisposable {
|
||||||
private bool disposed;
|
private bool disposed;
|
||||||
private int handle;
|
private int handle;
|
||||||
public VertexAttributesHandle() {
|
public VertexAttributesArrayHandle() {
|
||||||
handle = GL.GenVertexArray();
|
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="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="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>
|
/// <param name="colorAttribName">The name of the attribute for color mixture. Default is "aColor".</param>
|
||||||
/// <returns>The built <see cref="RecrownedGTK.Graphics.VertexAttributesHandle"/>.</returns>
|
/// <returns>The built <see cref="RecrownedGTK.Graphics.VertexAttributesArrayHandle"/>.</returns>
|
||||||
public static VertexAttributesHandle CreateBasicVA(Shader shader = null, string positionAttribName = "aPosition", string textureAttribName = "aTexture", string colorAttribName = "aColor") {
|
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();
|
if (shader == null) shader = Shader.CreateBasicShader();
|
||||||
VertexAttributesHandle vertexAttribs = new VertexAttributesHandle();
|
VertexAttributesArrayHandle vertexAttribs = new VertexAttributesArrayHandle();
|
||||||
vertexAttribs.Bind();
|
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(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(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();
|
|
||||||
return vertexAttribs;
|
return vertexAttribs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +48,7 @@ namespace RecrownedGTK.Graphics {
|
|||||||
GL.DeleteVertexArray(handle);
|
GL.DeleteVertexArray(handle);
|
||||||
disposed = true;
|
disposed = true;
|
||||||
}
|
}
|
||||||
~VertexAttributesHandle() {
|
~VertexAttributesArrayHandle() {
|
||||||
Dispose(false);
|
Dispose(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user