public void Dispose() { GL.DeleteBuffer(VBO); GL.DeleteVertexArray(VAO); GLBind.VertexArray(0); GLBind.VertexBuffer(0); }
public void UnsetElementBuffer() { GLBind.VertexBuffer(VBO); GLBind.VertexArray(VAO); GL.BindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); HasElements = false; _elements = null; }
public void SetElementBuffer(ElementBuffer elems) { GLBind.VertexBuffer(VBO); GLBind.VertexArray(VAO); GL.BindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, elems.Handle); HasElements = true; _elements = elems; }
public void SetData(ushort[] data, int count) { GLBind.VertexArray(0); GLBind.VertexBuffer(0); GL.BindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, Handle); fixed(ushort *ptr = data) { ; GL.BufferSubData(GL.GL_ELEMENT_ARRAY_BUFFER, IntPtr.Zero, new IntPtr(count * 2), (IntPtr)ptr); } }
public VertexBuffer(VertexDeclaration decl, int length, bool isStream = false) { this.decl = decl; VBO = GL.GenBuffer(); var usageHint = isStream ? GL.GL_STREAM_DRAW : GL.GL_STATIC_DRAW; GL.GenVertexArrays(1, out VAO); GLBind.VertexArray(VAO); GLBind.VertexBuffer(VBO); GL.BufferData(GL.GL_ARRAY_BUFFER, (IntPtr)(length * decl.Stride), IntPtr.Zero, usageHint); decl.SetPointers(); VertexCount = length; }
public void Draw(PrimitiveTypes primitiveType, int baseVertex, int startIndex, int primitiveCount) { RenderState.Instance.Apply(); int indexElementCount = primitiveType.GetArrayLength(primitiveCount); GLBind.VertexBuffer(VBO); GLBind.VertexArray(VAO); GL.DrawElementsBaseVertex(primitiveType.GLType(), indexElementCount, GL.GL_UNSIGNED_SHORT, (IntPtr)(startIndex * 2), baseVertex); TotalDrawcalls++; }
public void SetData <T>(T[] data, int?length = null) where T : struct { if (typeof(T) != type && typeof(T) != typeof(byte)) { throw new Exception("Data must be of type " + type.FullName); } int len = length ?? data.Length; GLBind.VertexBuffer(VBO); GLBind.VertexArray(VAO); var handle = GCHandle.Alloc(data, GCHandleType.Pinned); GL.BufferSubData(GL.GL_ARRAY_BUFFER, IntPtr.Zero, (IntPtr)(len * decl.Stride), handle.AddrOfPinnedObject()); handle.Free(); }
public VertexBuffer(Type type, int length, bool isStream = false) { VBO = GL.GenBuffer(); var usageHint = isStream ? GL.GL_STREAM_DRAW : GL.GL_STATIC_DRAW; this.type = type; try { vertextype = (IVertexType)Activator.CreateInstance(type); decl = vertextype.GetVertexDeclaration(); } catch (Exception) { throw new Exception(string.Format("{0} is not a valid IVertexType", type.FullName)); } GL.GenVertexArrays(1, out VAO); GLBind.VertexArray(VAO); GLBind.VertexBuffer(VBO); GL.BufferData(GL.GL_ARRAY_BUFFER, (IntPtr)(length * decl.Stride), IntPtr.Zero, usageHint); decl.SetPointers(); VertexCount = length; }
public void Draw(PrimitiveTypes primitiveType, int start, int primitiveCount) { RenderState.Instance.Apply(); GLBind.VertexBuffer(VBO); GLBind.VertexArray(VAO); if (HasElements) { int indexElementCount = primitiveType.GetArrayLength(primitiveCount); GL.DrawElements(primitiveType.GLType(), indexElementCount, GL.GL_UNSIGNED_SHORT, (IntPtr)(2 * start) ); } else { int indexElementCount = primitiveType.GetArrayLength(primitiveCount); GL.DrawArrays(primitiveType.GLType(), start, indexElementCount ); } TotalDrawcalls++; }
public void UnbindAll() { GLBind.VertexArray(0); GLBind.VertexBuffer(0); }