smrendererv3/SMCode/SM.OGL/Mesh/VBO.cs
Michel Fedde 9889366317 16.09.2020
~ Fixed shading import
~ Fixed "Plate" mesh
~ Move the dll files into "SMCode"
2020-09-16 19:12:53 +02:00

34 lines
No EOL
1.2 KiB
C#

using System;
using System.Collections.Generic;
using OpenTK;
using OpenTK.Graphics.OpenGL4;
namespace SM.OGL.Mesh
{
public class VBO : List<float>
{
public BufferUsageHint BufferUsageHint = BufferUsageHint.StaticDraw;
public VertexAttribPointerType PointerType = VertexAttribPointerType.Float;
public int PointerSize = 3;
public bool Normalised = false;
public int PointerStride = 0;
public int PointerOffset = 0;
public void Add(float x, float y) => AddRange(new[] {x,y});
public void Add(float x, float y, float z) => AddRange(new[] {x,y,z});
public void Add(float x, float y, float z, float w) => AddRange(new[] {x,y,z,w});
public void BindBuffer(int attribID)
{
float[] data = ToArray();
int buffer = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ArrayBuffer, buffer);
GL.BufferData(BufferTarget.ArrayBuffer, data.Length * Mesh.BufferSizeMultiplier, data, BufferUsageHint);
GL.VertexAttribPointer(attribID, PointerSize, PointerType, Normalised, PointerStride, PointerOffset);
GL.EnableVertexAttribArray(attribID);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
}
}
}