/// <summary> /// Creates a new vertex buffer with a specific size /// </summary> /// <param name="elementCount"></param> protected override void CreateBuffer(int elementCount) { VertexBuffer buffer = null; switch (_bufferType) { case BufferType.Static: buffer = new VertexBuffer(_device, _vertexDeclaration, elementCount, BufferUsage.None); break; case BufferType.StaticWriteOnly: buffer = new VertexBuffer(_device, _vertexDeclaration, elementCount, BufferUsage.WriteOnly); break; case BufferType.Dynamic: buffer = new DynamicVertexBuffer(_device, _vertexDeclaration, elementCount, BufferUsage.None); break; case BufferType.DynamicWriteOnly: buffer = new DynamicVertexBuffer(_device, _vertexDeclaration, elementCount, BufferUsage.WriteOnly); break; } if(buffer == null) throw new InvalidOperationException("Failed to create a vertex buffer"); CreateWrapper(buffer); BufferAllocatedEventArgs e = new BufferAllocatedEventArgs(this, elementCount); OnVertexBufferAllocated(e); }
/// <summary> /// Raises the VertexBufferAllocated event /// </summary> /// <param name="e">Argument</param> private void OnVertexBufferAllocated(BufferAllocatedEventArgs e) { EventHandler<BufferAllocatedEventArgs> bufferAllocated = VertexBufferAllocated; if (bufferAllocated != null) bufferAllocated(this, e); }
/// <summary> /// Calls when a vertex buffer object allocate a new hardware vertex buffer /// </summary> /// <param name="sender">Sender</param> /// <param name="e">Argument</param> private void BufferAllocated(object sender, BufferAllocatedEventArgs e) { UpdateBindingArray(); }