public override void SetData <T>(T[] data, int startIndex, int elementCount) { if (_usage == VertexBufferUsage.Static) { throw new Exception("Can't update a vertex buffer created as Static"); } GL.GetError(); GL.BindBuffer(BufferTarget.ArrayBuffer, _buffer); System.Runtime.InteropServices.GCHandle handle = System.Runtime.InteropServices.GCHandle.Alloc(data, System.Runtime.InteropServices.GCHandleType.Pinned); try { IntPtr pointer = handle.AddrOfPinnedObject(); int size = System.Runtime.InteropServices.Marshal.SizeOf(typeof(T)); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(elementCount * size), Gk3Main.Utils.IncrementIntPtr(pointer, size * startIndex), (BufferUsageHint)convertUsage(_usage)); } finally { if (handle.IsAllocated) { handle.Free(); } } GlException.ThrowExceptionIfErrorExists(); }
private void setupVertexBufferPointers() { for (int i = 0; i < _vertexDeclaration.Elements.Length; i++) { GlslEffect.Attribute attrib = _currentEffect.GetAttribute(_vertexDeclaration.Elements[i].Usage, _vertexDeclaration.Elements[i].UsageIndex); if (GlslEffect.Attribute.IsValidAttribute(attrib) == false) { continue; } GL.EnableVertexAttribArray(attrib.GlHandle); GlException.ThrowExceptionIfErrorExists(); GL.VertexAttribPointer(attrib.GlHandle, (int)_vertexDeclaration.Elements[i].Format, VertexAttribPointerType.Float, false, _vertexDeclaration.Stride, Gk3Main.Utils.IncrementIntPtr(IntPtr.Zero, _vertexDeclaration.Elements[i].Offset)); GlException.ThrowExceptionIfErrorExists(); } GlException.ThrowExceptionIfErrorExists(); // disable the rest // TODO: we need to figure out what the maximum number of vertex elements is and use that! for (int i = _vertexDeclaration.Elements.Length; i < 12; i++) { // Gl.glDisableVertexAttribArray(i); } _vertexPointersNeedSetup = false; }
public void SetVertexBuffer(VertexBuffer buffer) { GL.GetError(); _vertexPointersNeedSetup = true; _vertexDeclaration = buffer.VertexElements; GlVertexBuffer glVertices = (GlVertexBuffer)buffer; glVertices.Bind(); GlException.ThrowExceptionIfErrorExists(); _currentVertexBuffer = glVertices; }
public void Bind() { GL.GetError(); GL.BindBuffer(BufferTarget.ArrayBuffer, _buffer); GlException.ThrowExceptionIfErrorExists(); }