internal bool Bind() { if (vao == null) { return(false); } vao.Bind(); GraphicsDevice.CheckError(); return(true); }
public VertexBuffer(GraphicsDevice graphicsDevice, Type vertexType, int vertexCount, BufferUsageHint usage = BufferUsageHint.StaticDraw) : this(graphicsDevice, vertexCount, usage) { IVertexType tp = Activator.CreateInstance(vertexType) as IVertexType; if (tp == null) { throw new ArgumentException("must be a vertexType"); } this.VertexDeclaration = tp.VertexDeclaration; ThreadingHelper.BlockOnUIThread(() => { vbo = GL.GenBuffer(); GL.BindBuffer(BufferTarget.ArrayBuffer, vbo); GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(vertexCount * VertexDeclaration.VertexStride), IntPtr.Zero, (OpenTK.Graphics.OpenGL4.BufferUsageHint)BufferUsage); }); ThreadingHelper.BlockOnUIThread(() => { vao = new VertexAttributes(); vao.vbo = vbo; vao.Bind(); GL.BindBuffer(BufferTarget.ArrayBuffer, vbo); VertexAttributes.ApplyAttributes(vao, VertexDeclaration); GL.BindVertexArray(0); }, true); GraphicsDevice.CheckError(); }
public static void ApplyAttributes(VertexAttributes attribs, VertexDeclaration declaration) { attribs.Bind(); foreach (var el in declaration.VertexElements) { attribs.Add(el, declaration.VertexStride, declaration.InstanceDivisor); } GL.BindVertexArray(0); }
public VertexBuffer(GraphicsDevice graphicsDevice, VertexDeclaration vertexDeclaration, int vertexCount, BufferUsageHint usage = BufferUsageHint.StaticDraw) : this(graphicsDevice, vertexCount, usage) { this.VertexDeclaration = vertexDeclaration; ThreadingHelper.BlockOnUIThread(() => { vbo = GL.GenBuffer(); GL.BindBuffer(BufferTarget.ArrayBuffer, vbo); GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(vertexCount * VertexDeclaration.VertexStride), IntPtr.Zero, (OpenTK.Graphics.OpenGL4.BufferUsageHint)BufferUsage); }); ThreadingHelper.BlockOnUIThread(() => { vao = new VertexAttributes(); vao.vbo = vbo; vao.Bind(); GL.BindBuffer(BufferTarget.ArrayBuffer, vbo); VertexAttributes.ApplyAttributes(vao, VertexDeclaration); GL.BindVertexArray(0); }, true); GraphicsDevice.CheckError(); }