From 9c83423c79551c342b3dec33e065791d631ca597 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Wed, 2 Mar 2022 14:29:43 -0800 Subject: [PATCH] add buffer creation convenience method --- src/Graphics/Resources/Buffer.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Graphics/Resources/Buffer.cs b/src/Graphics/Resources/Buffer.cs index be11ec27..e8e56210 100644 --- a/src/Graphics/Resources/Buffer.cs +++ b/src/Graphics/Resources/Buffer.cs @@ -11,6 +11,27 @@ namespace MoonWorks.Graphics { protected override Action QueueDestroyFunction => Refresh.Refresh_QueueDestroyBuffer; + /// + /// Creates a buffer of appropriate size given a type and element count. + /// + /// The type that the buffer will contain. + /// The GraphicsDevice. + /// Specifies how the buffer will be used. + /// How many elements of type T the buffer will contain. + /// + public static Buffer Create( + GraphicsDevice device, + BufferUsageFlags usageFlags, + uint elementCount + ) + { + return new Buffer( + device, + usageFlags, + (uint) Marshal.SizeOf() * elementCount + ); + } + /// /// Creates a buffer. ///