add lots more doc comments

pull/51/head
cosmonaut 2023-09-19 13:19:41 -07:00
parent e0f05881b0
commit b026b9e81f
32 changed files with 246 additions and 30 deletions

View File

@ -4,7 +4,7 @@ using System.Runtime.InteropServices;
namespace MoonWorks.Audio
{
/// <summary>
/// Contains raw audio data in the format specified by Format.
/// Contains raw audio data in a specified Format. <br/>
/// Submit this to a SourceVoice to play audio.
/// </summary>
public class AudioBuffer : AudioResource
@ -15,6 +15,10 @@ namespace MoonWorks.Audio
public Format Format { get; }
/// <summary>
/// Create a new AudioBuffer.
/// </summary>
/// <param name="ownsBufferData">If true, the buffer data will be destroyed when this AudioBuffer is destroyed.</param>
public AudioBuffer(
AudioDevice device,
Format format,

View File

@ -58,6 +58,9 @@ namespace MoonWorks.Audio
filledLengthInBytes = sampleCount * sizeof(float);
}
/// <summary>
/// Prepares the Ogg data for streaming.
/// </summary>
public override unsafe void Load()
{
if (!Loaded)
@ -84,6 +87,9 @@ namespace MoonWorks.Audio
FAudio.stb_vorbis_seek(VorbisHandle, sampleFrame);
}
/// <summary>
/// Unloads the Ogg data, freeing resources.
/// </summary>
public override unsafe void Unload()
{
if (Loaded)
@ -96,6 +102,9 @@ namespace MoonWorks.Audio
}
}
/// <summary>
/// Loads an entire ogg file into an AudioBuffer. Useful for static audio.
/// </summary>
public unsafe static AudioBuffer CreateBuffer(AudioDevice device, string filePath)
{
var filePointer = FAudio.stb_vorbis_open_filename(filePath, out var error, IntPtr.Zero);

View File

@ -68,6 +68,9 @@ namespace MoonWorks.Audio
filledLengthInBytes = (int) (sampleCount * sizeof(short));
}
/// <summary>
/// Prepares qoa data for streaming.
/// </summary>
public override unsafe void Load()
{
if (!Loaded)
@ -93,6 +96,9 @@ namespace MoonWorks.Audio
FAudio.qoa_seek_frame(QoaHandle, (int) sampleFrame);
}
/// <summary>
/// Unloads the qoa data, freeing resources.
/// </summary>
public override unsafe void Unload()
{
if (Loaded)
@ -105,6 +111,9 @@ namespace MoonWorks.Audio
}
}
/// <summary>
/// Loads the entire qoa file into an AudioBuffer. Useful for static audio.
/// </summary>
public unsafe static AudioBuffer CreateBuffer(AudioDevice device, string filePath)
{
using var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);

View File

@ -4,6 +4,9 @@ using System.Threading;
namespace MoonWorks.Audio
{
/// <summary>
/// AudioDevice manages all audio-related concerns.
/// </summary>
public class AudioDevice : IDisposable
{
public IntPtr Handle { get; }

View File

@ -4,6 +4,9 @@ using MoonWorks.Math.Float;
namespace MoonWorks.Audio
{
/// <summary>
/// An emitter for 3D spatial audio.
/// </summary>
public class AudioEmitter : AudioResource
{
internal FAudio.F3DAUDIO_EMITTER emitterData;

View File

@ -3,6 +3,9 @@ using MoonWorks.Math.Float;
namespace MoonWorks.Audio
{
/// <summary>
/// A listener for 3D spatial audio. Usually attached to a camera.
/// </summary>
public class AudioListener : AudioResource
{
internal FAudio.F3DAUDIO_LISTENER listenerData;

View File

@ -8,6 +8,9 @@ namespace MoonWorks.Audio
IEEE_FLOAT = 3
}
/// <summary>
/// Describes the format of audio data. Usually specified in an audio file's header information.
/// </summary>
public record struct Format
{
public FormatTag Tag;

View File

@ -1,8 +1,8 @@
namespace MoonWorks.Audio
{
/// <summary>
/// TransientVoice is intended for playing one-off sound effects that don't have a long term reference.
/// It will be automatically returned to the source voice pool once it is done playing back.
/// TransientVoice is intended for playing one-off sound effects that don't have a long term reference. <br/>
/// It will be automatically returned to the AudioDevice SourceVoice pool once it is done playing back.
/// </summary>
public class TransientVoice : SourceVoice, IPoolable<TransientVoice>
{

View File

@ -4,6 +4,9 @@ using EasingFunction = System.Func<float, float>;
namespace MoonWorks.Audio
{
/// <summary>
/// Handles audio playback from audio buffer data. Can be configured with a variety of parameters.
/// </summary>
public abstract unsafe class Voice : AudioResource
{
protected IntPtr handle;

View File

@ -1,14 +1,27 @@
namespace MoonWorks
{
/// <summary>
/// The Game's frame limiter mode. Specifies a maximum rendering frames per second value.
/// </summary>
public enum FrameLimiterMode
{
/// <summary>
/// The game will render at the maximum possible framerate that the computing resources allow. <br/>
/// Note that this may lead to overheating, resource starvation, etc.
/// </summary>
Uncapped,
/// <summary>
/// The game will render no more than the specified frames per second.
/// </summary>
Capped
}
public struct FrameLimiterSettings
{
public FrameLimiterMode Mode;
/// <summary>
/// If Mode is set to Uncapped, this is the maximum frames per second that will be rendered.
/// </summary>
public int Cap;
public FrameLimiterSettings(

View File

@ -1,5 +1,8 @@
namespace MoonWorks.Graphics
{
/// <summary>
/// A buffer-offset pair to be used when binding vertex buffers.
/// </summary>
public struct BufferBinding
{
public Buffer Buffer;

View File

@ -1,7 +1,8 @@
using System;
namespace MoonWorks.Graphics
namespace MoonWorks.Graphics
{
/// <summary>
/// A texture-sampler pair to be used when binding samplers.
/// </summary>
public struct TextureSamplerBinding
{
public Texture Texture;

View File

@ -5,6 +5,9 @@ using RefreshCS;
namespace MoonWorks.Graphics
{
/// <summary>
/// GraphicsDevice manages all graphics-related concerns.
/// </summary>
public class GraphicsDevice : IDisposable
{
public IntPtr Handle { get; }
@ -21,7 +24,7 @@ namespace MoonWorks.Graphics
private readonly HashSet<WeakReference<GraphicsResource>> resources = new HashSet<WeakReference<GraphicsResource>>();
private FencePool FencePool;
public GraphicsDevice(
internal GraphicsDevice(
Backend preferredBackend,
bool debugMode
) {
@ -77,6 +80,11 @@ namespace MoonWorks.Graphics
FencePool = new FencePool(this);
}
/// <summary>
/// Prepares a window so that frames can be presented to it.
/// </summary>
/// <param name="presentMode">The desired presentation mode for the window. Roughly equivalent to V-Sync.</param>
/// <returns>True if successfully claimed.</returns>
public bool ClaimWindow(Window window, PresentMode presentMode)
{
var success = Conversions.ByteToBool(
@ -100,6 +108,9 @@ namespace MoonWorks.Graphics
return success;
}
/// <summary>
/// Unclaims a window, making it unavailable for presenting and freeing associated resources.
/// </summary>
public void UnclaimWindow(Window window)
{
Refresh.Refresh_UnclaimWindow(
@ -109,8 +120,18 @@ namespace MoonWorks.Graphics
window.Claimed = false;
}
/// <summary>
/// Changes the present mode of a claimed window. Does nothing if the window is not claimed.
/// </summary>
/// <param name="window"></param>
/// <param name="presentMode"></param>
public void SetPresentMode(Window window, PresentMode presentMode)
{
if (!window.Claimed)
{
return;
}
Refresh.Refresh_SetSwapchainPresentMode(
Handle,
window.Handle,
@ -118,6 +139,11 @@ namespace MoonWorks.Graphics
);
}
/// <summary>
/// Acquires a command buffer.
/// This is the start of your rendering process.
/// </summary>
/// <returns></returns>
public CommandBuffer AcquireCommandBuffer()
{
return new CommandBuffer(this, Refresh.Refresh_AcquireCommandBuffer(Handle));

View File

@ -1,7 +1,13 @@
namespace MoonWorks.Graphics
{
/// <summary>
/// Can be defined on your struct type to enable simplified vertex input state definition.
/// </summary>
public interface IVertexType
{
/// <summary>
/// An ordered list of the types in your vertex struct.
/// </summary>
static abstract VertexElementFormat[] Formats { get; }
}
}

View File

@ -2,11 +2,31 @@
namespace MoonWorks
{
/// <summary>
/// Presentation mode for a window.
/// </summary>
public enum PresentMode
{
/// <summary>
/// Does not wait for v-blank to update the window. Can cause visible tearing.
/// </summary>
Immediate,
/// <summary>
/// Waits for v-blank and uses a queue to hold present requests.
/// Allows for low latency while preventing tearing.
/// May not be supported on non-Vulkan non-Linux systems or older hardware.
/// </summary>
Mailbox,
/// <summary>
/// Waits for v-blank and adds present requests to a queue.
/// Will probably cause latency.
/// Required to be supported by all compliant hardware.
/// </summary>
FIFO,
/// <summary>
/// Usually waits for v-blank, but if v-blank has passed since last update will update immediately.
/// May cause visible tearing.
/// </summary>
FIFORelaxed
}
}

View File

@ -59,7 +59,7 @@ namespace MoonWorks.Graphics
/// <summary>
/// Reads data out of a buffer and into a span.
/// This operation is only guaranteed to read up-to-date data if GraphicsDevice.Wait is called first.
/// This operation is only guaranteed to read up-to-date data if GraphicsDevice.Wait or GraphicsDevice.WaitForFences is called first.
/// </summary>
/// <param name="data">The span that data will be copied to.</param>
/// <param name="dataLengthInBytes">The length of the data to read.</param>
@ -73,6 +73,11 @@ namespace MoonWorks.Graphics
{
Logger.LogWarn("Requested too many bytes from buffer!");
}
if (dataLengthInBytes > data.Length)
{
Logger.LogWarn("Data length is larger than the provided Span!");
}
#endif
fixed (T* ptr = data)
@ -88,7 +93,7 @@ namespace MoonWorks.Graphics
/// <summary>
/// Reads data out of a buffer and into an array.
/// This operation is only guaranteed to read up-to-date data if GraphicsDevice.Wait is called first.
/// This operation is only guaranteed to read up-to-date data if GraphicsDevice.Wait or GraphicsDevice.WaitForFences is called first.
/// </summary>
/// <param name="data">The span that data will be copied to.</param>
/// <param name="dataLengthInBytes">The length of the data to read.</param>
@ -102,7 +107,7 @@ namespace MoonWorks.Graphics
/// <summary>
/// Reads data out of a buffer and into a span.
/// This operation is only guaranteed to read up-to-date data if GraphicsDevice.Wait is called first.
/// This operation is only guaranteed to read up-to-date data if GraphicsDevice.Wait or GraphicsDevice.WaitForFences is called first.
/// Fills the span with as much data from the buffer as it can.
/// </summary>
/// <param name="data">The span that data will be copied to.</param>
@ -116,7 +121,7 @@ namespace MoonWorks.Graphics
/// <summary>
/// Reads data out of a buffer and into an array.
/// This operation is only guaranteed to read up-to-date data if GraphicsDevice.Wait is called first.
/// This operation is only guaranteed to read up-to-date data if GraphicsDevice.Wait or GraphicsDevice.WaitForFences is called first.
/// Fills the array with as much data from the buffer as it can.
/// </summary>
/// <param name="data">The span that data will be copied to.</param>

View File

@ -1,9 +1,11 @@
using RefreshCS;
using System;
using System.Runtime.InteropServices;
namespace MoonWorks.Graphics
{
/// <summary>
/// Compute pipelines perform arbitrary parallel processing on input data.
/// </summary>
public class ComputePipeline : GraphicsResource
{
protected override Action<IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyComputePipeline;

View File

@ -4,11 +4,10 @@ using RefreshCS;
namespace MoonWorks.Graphics
{
/// <summary>
/// Fences allow you to track the status of a submitted command buffer.
/// You should only acquire a Fence if you will need to track the command buffer.
/// You should make sure to call GraphicsDevice.ReleaseFence when done with a Fence to avoid memory growth.
///
/// The Fence object itself is basically just a wrapper for the Refresh_Fence.
/// Fences allow you to track the status of a submitted command buffer. <br/>
/// You should only acquire a Fence if you will need to track the command buffer. <br/>
/// You should make sure to call GraphicsDevice.ReleaseFence when done with a Fence to avoid memory growth. <br/>
/// The Fence object itself is basically just a wrapper for the Refresh_Fence. <br/>
/// The internal handle is replaced so that we can pool Fence objects to manage garbage.
/// </summary>
public class Fence : GraphicsResource

View File

@ -5,7 +5,7 @@ using RefreshCS;
namespace MoonWorks.Graphics
{
/// <summary>
/// Graphics pipelines encapsulate all of the render state in a single object.
/// Graphics pipelines encapsulate all of the render state in a single object. <br/>
/// These pipelines are bound before draw calls are issued.
/// </summary>
public class GraphicsPipeline : GraphicsResource

View File

@ -591,8 +591,9 @@ namespace MoonWorks.Graphics
}
/// <summary>
/// Asynchronously saves RGBA or BGRA pixel data to a file in PNG format.
/// Warning: this is expensive and will block to wait for data download from GPU!
/// Asynchronously saves RGBA or BGRA pixel data to a file in PNG format. <br/>
/// Warning: this is expensive and will block to wait for data download from GPU! <br/>
/// You can avoid blocking by calling this method from a thread.
/// </summary>
public unsafe void SavePNG(string path)
{

View File

@ -2,6 +2,9 @@
namespace MoonWorks.Graphics
{
/// <summary>
/// Defines how color blending will be performed in a GraphicsPipeline.
/// </summary>
public struct ColorAttachmentBlendState
{
/// <summary>

View File

@ -3,7 +3,7 @@ using System.Runtime.InteropServices;
namespace MoonWorks.Graphics
{
/// <summary>
/// Information that the pipeline needs about a shader.
/// Information that the compute pipeline needs about a compute shader.
/// </summary>
public struct ComputeShaderInfo
{

View File

@ -1,5 +1,8 @@
namespace MoonWorks.Graphics
{
/// <summary>
/// All of the information that is used to create a GraphicsPipeline.
/// </summary>
public struct GraphicsPipelineCreateInfo
{
public DepthStencilState DepthStencilState;

View File

@ -3,7 +3,7 @@
namespace MoonWorks.Graphics
{
/// <summary>
/// Information that the pipeline needs about a shader.
/// Information that the pipeline needs about a graphics shader.
/// </summary>
public struct GraphicsShaderInfo
{

View File

@ -2,21 +2,60 @@
namespace MoonWorks.Graphics
{
/// <summary>
/// All of the information that is used to create a sampler.
/// </summary>
public struct SamplerCreateInfo
{
/// <summary>
/// Minification filter mode. Used when the image is downscaled.
/// </summary>
public Filter MinFilter;
/// <summary>
/// Magnification filter mode. Used when the image is upscaled.
/// </summary>
public Filter MagFilter;
/// <summary>
/// Filter mode applied to mipmap lookups.
/// </summary>
public SamplerMipmapMode MipmapMode;
/// <summary>
/// Horizontal addressing mode.
/// </summary>
public SamplerAddressMode AddressModeU;
/// <summary>
/// Vertical addressing mode.
/// </summary>
public SamplerAddressMode AddressModeV;
/// <summary>
/// Depth addressing mode.
/// </summary>
public SamplerAddressMode AddressModeW;
/// <summary>
/// Bias value added to mipmap level of detail calculation.
/// </summary>
public float MipLodBias;
/// <summary>
/// Enables anisotropic filtering.
/// </summary>
public bool AnisotropyEnable;
/// <summary>
/// Maximum anisotropy value.
/// </summary>
public float MaxAnisotropy;
public bool CompareEnable;
public CompareOp CompareOp;
/// <summary>
/// Clamps the LOD value to a specified minimum.
/// </summary>
public float MinLod;
/// <summary>
/// Clamps the LOD value to a specified maximum.
/// </summary>
public float MaxLod;
/// <summary>
/// If an address mode is set to ClampToBorder, will replace color with this color when samples are outside the [0, 1) range.
/// </summary>
public BorderColor BorderColor;
public static readonly SamplerCreateInfo AnisotropicClamp = new SamplerCreateInfo

View File

@ -2,6 +2,9 @@
namespace MoonWorks.Graphics
{
/// <summary>
/// All of the information that is used to create a texture.
/// </summary>
public struct TextureCreateInfo
{
public uint Width;

View File

@ -1,7 +1,7 @@
namespace MoonWorks.Graphics
{
/// <summary>
/// Specifies how to interpet vertex data in a buffer to be passed to the vertex shader.
/// Specifies how the vertex shader will interpet vertex data in a buffer.
/// </summary>
public struct VertexInputState
{

View File

@ -1,6 +1,8 @@
namespace MoonWorks.Graphics
{
// This is a convenience structure for pairing a vertex binding with its associated attributes.
/// <summary>
/// A convenience structure for pairing a vertex binding with its associated attributes.
/// </summary>
public struct VertexBindingAndAttributes
{
public VertexBinding VertexBinding { get; }

View File

@ -25,6 +25,9 @@ namespace MoonWorks.Video
private int height;
private Dav1dfile.PixelLayout pixelLayout;
/// <summary>
/// Opens an AV1 file so it can be loaded by VideoPlayer. You must also provide a playback framerate.
/// </summary>
public VideoAV1(string filename, double framesPerSecond)
{
if (!File.Exists(filename))

View File

@ -1,12 +1,13 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using MoonWorks.Audio;
using MoonWorks.Graphics;
namespace MoonWorks.Video
{
/// <summary>
/// A structure for continuous decoding of AV1 videos and rendering them into a texture.
/// </summary>
public unsafe class VideoPlayer : IDisposable
{
public Texture RenderTexture { get; private set; } = null;
@ -44,6 +45,10 @@ namespace MoonWorks.Video
timer = new Stopwatch();
}
/// <summary>
/// Prepares a VideoAV1 for decoding and rendering.
/// </summary>
/// <param name="video"></param>
public void Load(VideoAV1 video)
{
if (Video != video)
@ -100,6 +105,9 @@ namespace MoonWorks.Video
}
}
/// <summary>
/// Starts playing back and decoding the loaded video.
/// </summary>
public void Play()
{
if (Video == null) { return; }
@ -114,6 +122,9 @@ namespace MoonWorks.Video
State = VideoState.Playing;
}
/// <summary>
/// Pauses playback and decoding of the currently playing video.
/// </summary>
public void Pause()
{
if (Video == null) { return; }
@ -128,6 +139,9 @@ namespace MoonWorks.Video
State = VideoState.Paused;
}
/// <summary>
/// Stops and resets decoding of the currently playing video.
/// </summary>
public void Stop()
{
if (Video == null) { return; }
@ -148,12 +162,18 @@ namespace MoonWorks.Video
State = VideoState.Stopped;
}
/// <summary>
/// Unloads the currently playing video.
/// </summary>
public void Unload()
{
Stop();
Video = null;
}
/// <summary>
/// Renders the video data into RenderTexture.
/// </summary>
public void Render()
{
if (Video == null || State == VideoState.Stopped)

View File

@ -6,9 +6,9 @@ using SDL2;
namespace MoonWorks
{
/// <summary>
/// Represents a window in the client operating system.
/// Every Game has a MainWindow automatically.
/// You can create dditional Windows if you desire. They must be Claimed by the GraphicsDevice to be rendered to.
/// Represents a window in the client operating system. <br/>
/// Every Game has a MainWindow automatically. <br/>
/// You can create additional Windows if you desire. They must be Claimed by the GraphicsDevice to be rendered to.
/// </summary>
public class Window : IDisposable
{
@ -69,6 +69,9 @@ namespace MoonWorks
idLookup.Add(SDL.SDL_GetWindowID(Handle), this);
}
/// <summary>
/// Changes the ScreenMode of this window.
/// </summary>
public void SetScreenMode(ScreenMode screenMode)
{
SDL.SDL_WindowFlags windowFlag = 0;
@ -93,7 +96,7 @@ namespace MoonWorks
}
/// <summary>
/// Resizes the window.
/// Resizes the window. <br/>
/// Note that you are responsible for recreating any graphics resources that need to change as a result of the size change.
/// </summary>
/// <param name="width"></param>
@ -131,6 +134,9 @@ namespace MoonWorks
}
}
/// <summary>
/// You can specify a method to run when the window size changes.
/// </summary>
public void RegisterSizeChangeCallback(System.Action<uint, uint> sizeChangeCallback)
{
SizeChangeCallback = sizeChangeCallback;

View File

@ -1,13 +1,37 @@
namespace MoonWorks
{
/// <summary>
/// All the information required for window creation.
/// </summary>
public struct WindowCreateInfo
{
/// <summary>
/// The name of the window that will be displayed in the operating system.
/// </summary>
public string WindowTitle;
/// <summary>
/// The width of the window.
/// </summary>
public uint WindowWidth;
/// <summary>
/// The height of the window.
/// </summary>
public uint WindowHeight;
/// <summary>
/// Specifies if the window will be created in windowed mode or a fullscreen mode.
/// </summary>
public ScreenMode ScreenMode;
/// <summary>
/// Specifies the presentation mode for the window. Roughly equivalent to V-Sync.
/// </summary>
public PresentMode PresentMode;
/// <summary>
/// Whether the window can be resized using the operating system's window dragging feature.
/// </summary>
public bool SystemResizable;
/// <summary>
/// Specifies if the window will open at the maximum desktop resolution.
/// </summary>
public bool StartMaximized;
public WindowCreateInfo(