public void SetVertexArray(int VbIndex, int Stride, byte[] Buffer, GalVertexAttrib[] Attribs) { EnsureVbInitialized(VbIndex); VertexBuffers[VbIndex].PrimCount = Buffer.Length / Stride; VbInfo Vb = VertexBuffers[VbIndex]; IntPtr Length = new IntPtr(Buffer.Length); GL.BindBuffer(BufferTarget.ArrayBuffer, Vb.VboHandle); GL.BufferData(BufferTarget.ArrayBuffer, Length, Buffer, BufferUsageHint.StreamDraw); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindVertexArray(Vb.VaoHandle); for (int Attr = 0; Attr < 16; Attr++) { GL.DisableVertexAttribArray(Attr); } for (int Index = 0; Index < Attribs.Length; Index++) { GalVertexAttrib Attrib = Attribs[Index]; GL.EnableVertexAttribArray(Index); GL.BindBuffer(BufferTarget.ArrayBuffer, Vb.VboHandle); bool Unsigned = Attrib.Type == GalVertexAttribType.Unorm || Attrib.Type == GalVertexAttribType.Uint || Attrib.Type == GalVertexAttribType.Uscaled; bool Normalize = Attrib.Type == GalVertexAttribType.Snorm || Attrib.Type == GalVertexAttribType.Unorm; VertexAttribPointerType Type = 0; if (Attrib.Type == GalVertexAttribType.Float) { Type = VertexAttribPointerType.Float; } else { Type = AttribTypes[Attrib.Size] + (Unsigned ? 1 : 0); } int Size = AttribElements[Attrib.Size]; int Offset = Attrib.Offset; GL.VertexAttribPointer(Index, Size, Type, Normalize, Stride, Offset); } GL.BindVertexArray(0); }
public void DrawElements(int VbIndex, int First, GalPrimitiveType PrimType) { VbInfo Vb = VertexBuffers[VbIndex]; PrimitiveType Mode = OGLEnumConverter.GetPrimitiveType(PrimType); GL.BindVertexArray(Vb.VaoHandle); GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndexBuffer.IboHandle); GL.DrawElements(Mode, IndexBuffer.Count, IndexBuffer.Type, First); }
public void DrawArrays(int VbIndex, int First, int PrimCount, GalPrimitiveType PrimType) { if (PrimCount == 0) { return; } VbInfo Vb = VertexBuffers[VbIndex]; GL.BindVertexArray(Vb.VaoHandle); GL.DrawArrays(OGLEnumConverter.GetPrimitiveType(PrimType), First, PrimCount); }
private void EnsureVbInitialized(int VbIndex) { VbInfo Vb = VertexBuffers[VbIndex]; if (Vb.VaoHandle == 0) { Vb.VaoHandle = GL.GenVertexArray(); } if (Vb.VboHandle == 0) { Vb.VboHandle = GL.GenBuffer(); } VertexBuffers[VbIndex] = Vb; }