Formatting pass
parent
a0c57c7a59
commit
8973b3e658
|
@ -0,0 +1,14 @@
|
|||
# EditorConfig is awesome: https://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
indent_style = tab
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.cs]
|
||||
csharp_space_after_cast = true
|
||||
charset = utf-8-bom
|
||||
max_line_length = 100
|
|
@ -1,277 +1,277 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace MoonWorks.Audio
|
||||
{
|
||||
public class AudioDevice : IDisposable
|
||||
{
|
||||
public IntPtr Handle { get; }
|
||||
public byte[] Handle3D { get; }
|
||||
public IntPtr MasteringVoice { get; }
|
||||
public FAudio.FAudioDeviceDetails DeviceDetails { get; }
|
||||
public IntPtr ReverbVoice { get; }
|
||||
public class AudioDevice : IDisposable
|
||||
{
|
||||
public IntPtr Handle { get; }
|
||||
public byte[] Handle3D { get; }
|
||||
public IntPtr MasteringVoice { get; }
|
||||
public FAudio.FAudioDeviceDetails DeviceDetails { get; }
|
||||
public IntPtr ReverbVoice { get; }
|
||||
|
||||
public float CurveDistanceScalar = 1f;
|
||||
public float DopplerScale = 1f;
|
||||
public float SpeedOfSound = 343.5f;
|
||||
public float CurveDistanceScalar = 1f;
|
||||
public float DopplerScale = 1f;
|
||||
public float SpeedOfSound = 343.5f;
|
||||
|
||||
internal FAudio.FAudioVoiceSends ReverbSends;
|
||||
internal FAudio.FAudioVoiceSends ReverbSends;
|
||||
|
||||
private readonly List<WeakReference<AudioResource>> resources = new List<WeakReference<AudioResource>>();
|
||||
private readonly List<WeakReference<StreamingSound>> streamingSounds = new List<WeakReference<StreamingSound>>();
|
||||
private readonly List<WeakReference<AudioResource>> resources = new List<WeakReference<AudioResource>>();
|
||||
private readonly List<WeakReference<StreamingSound>> streamingSounds = new List<WeakReference<StreamingSound>>();
|
||||
|
||||
private bool IsDisposed;
|
||||
private bool IsDisposed;
|
||||
|
||||
public unsafe AudioDevice()
|
||||
{
|
||||
FAudio.FAudioCreate(out var handle, 0, 0);
|
||||
Handle = handle;
|
||||
public unsafe AudioDevice()
|
||||
{
|
||||
FAudio.FAudioCreate(out var handle, 0, 0);
|
||||
Handle = handle;
|
||||
|
||||
/* Find a suitable device */
|
||||
/* Find a suitable device */
|
||||
|
||||
FAudio.FAudio_GetDeviceCount(Handle, out var devices);
|
||||
FAudio.FAudio_GetDeviceCount(Handle, out var devices);
|
||||
|
||||
if (devices == 0)
|
||||
{
|
||||
Logger.LogError("No audio devices found!");
|
||||
Handle = IntPtr.Zero;
|
||||
FAudio.FAudio_Release(Handle);
|
||||
return;
|
||||
}
|
||||
if (devices == 0)
|
||||
{
|
||||
Logger.LogError("No audio devices found!");
|
||||
Handle = IntPtr.Zero;
|
||||
FAudio.FAudio_Release(Handle);
|
||||
return;
|
||||
}
|
||||
|
||||
FAudio.FAudioDeviceDetails deviceDetails;
|
||||
FAudio.FAudioDeviceDetails deviceDetails;
|
||||
|
||||
uint i = 0;
|
||||
for (i = 0; i < devices; i++)
|
||||
{
|
||||
FAudio.FAudio_GetDeviceDetails(
|
||||
Handle,
|
||||
i,
|
||||
out deviceDetails
|
||||
);
|
||||
if ((deviceDetails.Role & FAudio.FAudioDeviceRole.FAudioDefaultGameDevice) == FAudio.FAudioDeviceRole.FAudioDefaultGameDevice)
|
||||
{
|
||||
DeviceDetails = deviceDetails;
|
||||
break;
|
||||
}
|
||||
}
|
||||
uint i = 0;
|
||||
for (i = 0; i < devices; i++)
|
||||
{
|
||||
FAudio.FAudio_GetDeviceDetails(
|
||||
Handle,
|
||||
i,
|
||||
out deviceDetails
|
||||
);
|
||||
if ((deviceDetails.Role & FAudio.FAudioDeviceRole.FAudioDefaultGameDevice) == FAudio.FAudioDeviceRole.FAudioDefaultGameDevice)
|
||||
{
|
||||
DeviceDetails = deviceDetails;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == devices)
|
||||
{
|
||||
i = 0; /* whatever we'll just use the first one I guess */
|
||||
FAudio.FAudio_GetDeviceDetails(
|
||||
Handle,
|
||||
i,
|
||||
out deviceDetails
|
||||
);
|
||||
DeviceDetails = deviceDetails;
|
||||
}
|
||||
if (i == devices)
|
||||
{
|
||||
i = 0; /* whatever we'll just use the first one I guess */
|
||||
FAudio.FAudio_GetDeviceDetails(
|
||||
Handle,
|
||||
i,
|
||||
out deviceDetails
|
||||
);
|
||||
DeviceDetails = deviceDetails;
|
||||
}
|
||||
|
||||
/* Init Mastering Voice */
|
||||
IntPtr masteringVoice;
|
||||
/* Init Mastering Voice */
|
||||
IntPtr masteringVoice;
|
||||
|
||||
if (FAudio.FAudio_CreateMasteringVoice(
|
||||
Handle,
|
||||
out masteringVoice,
|
||||
FAudio.FAUDIO_DEFAULT_CHANNELS,
|
||||
FAudio.FAUDIO_DEFAULT_SAMPLERATE,
|
||||
0,
|
||||
i,
|
||||
IntPtr.Zero
|
||||
) != 0)
|
||||
{
|
||||
Logger.LogError("No mastering voice found!");
|
||||
Handle = IntPtr.Zero;
|
||||
FAudio.FAudio_Release(Handle);
|
||||
return;
|
||||
}
|
||||
if (FAudio.FAudio_CreateMasteringVoice(
|
||||
Handle,
|
||||
out masteringVoice,
|
||||
FAudio.FAUDIO_DEFAULT_CHANNELS,
|
||||
FAudio.FAUDIO_DEFAULT_SAMPLERATE,
|
||||
0,
|
||||
i,
|
||||
IntPtr.Zero
|
||||
) != 0)
|
||||
{
|
||||
Logger.LogError("No mastering voice found!");
|
||||
Handle = IntPtr.Zero;
|
||||
FAudio.FAudio_Release(Handle);
|
||||
return;
|
||||
}
|
||||
|
||||
MasteringVoice = masteringVoice;
|
||||
MasteringVoice = masteringVoice;
|
||||
|
||||
/* Init 3D Audio */
|
||||
/* Init 3D Audio */
|
||||
|
||||
Handle3D = new byte[FAudio.F3DAUDIO_HANDLE_BYTESIZE];
|
||||
FAudio.F3DAudioInitialize(
|
||||
DeviceDetails.OutputFormat.dwChannelMask,
|
||||
SpeedOfSound,
|
||||
Handle3D
|
||||
);
|
||||
Handle3D = new byte[FAudio.F3DAUDIO_HANDLE_BYTESIZE];
|
||||
FAudio.F3DAudioInitialize(
|
||||
DeviceDetails.OutputFormat.dwChannelMask,
|
||||
SpeedOfSound,
|
||||
Handle3D
|
||||
);
|
||||
|
||||
/* Init reverb */
|
||||
/* Init reverb */
|
||||
|
||||
IntPtr reverbVoice;
|
||||
IntPtr reverbVoice;
|
||||
|
||||
IntPtr reverb;
|
||||
FAudio.FAudioCreateReverb(out reverb, 0);
|
||||
IntPtr reverb;
|
||||
FAudio.FAudioCreateReverb(out reverb, 0);
|
||||
|
||||
IntPtr chainPtr;
|
||||
chainPtr = Marshal.AllocHGlobal(
|
||||
Marshal.SizeOf<FAudio.FAudioEffectChain>()
|
||||
);
|
||||
IntPtr chainPtr;
|
||||
chainPtr = Marshal.AllocHGlobal(
|
||||
Marshal.SizeOf<FAudio.FAudioEffectChain>()
|
||||
);
|
||||
|
||||
FAudio.FAudioEffectChain* reverbChain = (FAudio.FAudioEffectChain*) chainPtr;
|
||||
reverbChain->EffectCount = 1;
|
||||
reverbChain->pEffectDescriptors = Marshal.AllocHGlobal(
|
||||
Marshal.SizeOf<FAudio.FAudioEffectDescriptor>()
|
||||
);
|
||||
FAudio.FAudioEffectChain* reverbChain = (FAudio.FAudioEffectChain*) chainPtr;
|
||||
reverbChain->EffectCount = 1;
|
||||
reverbChain->pEffectDescriptors = Marshal.AllocHGlobal(
|
||||
Marshal.SizeOf<FAudio.FAudioEffectDescriptor>()
|
||||
);
|
||||
|
||||
FAudio.FAudioEffectDescriptor* reverbDescriptor =
|
||||
(FAudio.FAudioEffectDescriptor*) reverbChain->pEffectDescriptors;
|
||||
FAudio.FAudioEffectDescriptor* reverbDescriptor =
|
||||
(FAudio.FAudioEffectDescriptor*) reverbChain->pEffectDescriptors;
|
||||
|
||||
reverbDescriptor->InitialState = 1;
|
||||
reverbDescriptor->OutputChannels = (uint) (
|
||||
(DeviceDetails.OutputFormat.Format.nChannels == 6) ? 6 : 1
|
||||
);
|
||||
reverbDescriptor->pEffect = reverb;
|
||||
reverbDescriptor->InitialState = 1;
|
||||
reverbDescriptor->OutputChannels = (uint) (
|
||||
(DeviceDetails.OutputFormat.Format.nChannels == 6) ? 6 : 1
|
||||
);
|
||||
reverbDescriptor->pEffect = reverb;
|
||||
|
||||
FAudio.FAudio_CreateSubmixVoice(
|
||||
Handle,
|
||||
out reverbVoice,
|
||||
1, /* omnidirectional reverb */
|
||||
DeviceDetails.OutputFormat.Format.nSamplesPerSec,
|
||||
0,
|
||||
0,
|
||||
IntPtr.Zero,
|
||||
chainPtr
|
||||
);
|
||||
FAudio.FAPOBase_Release(reverb);
|
||||
FAudio.FAudio_CreateSubmixVoice(
|
||||
Handle,
|
||||
out reverbVoice,
|
||||
1, /* omnidirectional reverb */
|
||||
DeviceDetails.OutputFormat.Format.nSamplesPerSec,
|
||||
0,
|
||||
0,
|
||||
IntPtr.Zero,
|
||||
chainPtr
|
||||
);
|
||||
FAudio.FAPOBase_Release(reverb);
|
||||
|
||||
Marshal.FreeHGlobal(reverbChain->pEffectDescriptors);
|
||||
Marshal.FreeHGlobal(chainPtr);
|
||||
Marshal.FreeHGlobal(reverbChain->pEffectDescriptors);
|
||||
Marshal.FreeHGlobal(chainPtr);
|
||||
|
||||
ReverbVoice = reverbVoice;
|
||||
ReverbVoice = reverbVoice;
|
||||
|
||||
/* Init reverb params */
|
||||
// Defaults based on FAUDIOFX_I3DL2_PRESET_GENERIC
|
||||
/* Init reverb params */
|
||||
// Defaults based on FAUDIOFX_I3DL2_PRESET_GENERIC
|
||||
|
||||
IntPtr reverbParamsPtr = Marshal.AllocHGlobal(
|
||||
Marshal.SizeOf<FAudio.FAudioFXReverbParameters>()
|
||||
);
|
||||
IntPtr reverbParamsPtr = Marshal.AllocHGlobal(
|
||||
Marshal.SizeOf<FAudio.FAudioFXReverbParameters>()
|
||||
);
|
||||
|
||||
FAudio.FAudioFXReverbParameters* reverbParams = (FAudio.FAudioFXReverbParameters*) reverbParamsPtr;
|
||||
reverbParams->WetDryMix = 100.0f;
|
||||
reverbParams->ReflectionsDelay = 7;
|
||||
reverbParams->ReverbDelay = 11;
|
||||
reverbParams->RearDelay = FAudio.FAUDIOFX_REVERB_DEFAULT_REAR_DELAY;
|
||||
reverbParams->PositionLeft = FAudio.FAUDIOFX_REVERB_DEFAULT_POSITION;
|
||||
reverbParams->PositionRight = FAudio.FAUDIOFX_REVERB_DEFAULT_POSITION;
|
||||
reverbParams->PositionMatrixLeft = FAudio.FAUDIOFX_REVERB_DEFAULT_POSITION_MATRIX;
|
||||
reverbParams->PositionMatrixRight = FAudio.FAUDIOFX_REVERB_DEFAULT_POSITION_MATRIX;
|
||||
reverbParams->EarlyDiffusion = 15;
|
||||
reverbParams->LateDiffusion = 15;
|
||||
reverbParams->LowEQGain = 8;
|
||||
reverbParams->LowEQCutoff = 4;
|
||||
reverbParams->HighEQGain = 8;
|
||||
reverbParams->HighEQCutoff = 6;
|
||||
reverbParams->RoomFilterFreq = 5000f;
|
||||
reverbParams->RoomFilterMain = -10f;
|
||||
reverbParams->RoomFilterHF = -1f;
|
||||
reverbParams->ReflectionsGain = -26.0200005f;
|
||||
reverbParams->ReverbGain = 10.0f;
|
||||
reverbParams->DecayTime = 1.49000001f;
|
||||
reverbParams->Density = 100.0f;
|
||||
reverbParams->RoomSize = FAudio.FAUDIOFX_REVERB_DEFAULT_ROOM_SIZE;
|
||||
FAudio.FAudioVoice_SetEffectParameters(
|
||||
ReverbVoice,
|
||||
0,
|
||||
reverbParamsPtr,
|
||||
(uint) Marshal.SizeOf<FAudio.FAudioFXReverbParameters>(),
|
||||
0
|
||||
);
|
||||
Marshal.FreeHGlobal(reverbParamsPtr);
|
||||
FAudio.FAudioFXReverbParameters* reverbParams = (FAudio.FAudioFXReverbParameters*) reverbParamsPtr;
|
||||
reverbParams->WetDryMix = 100.0f;
|
||||
reverbParams->ReflectionsDelay = 7;
|
||||
reverbParams->ReverbDelay = 11;
|
||||
reverbParams->RearDelay = FAudio.FAUDIOFX_REVERB_DEFAULT_REAR_DELAY;
|
||||
reverbParams->PositionLeft = FAudio.FAUDIOFX_REVERB_DEFAULT_POSITION;
|
||||
reverbParams->PositionRight = FAudio.FAUDIOFX_REVERB_DEFAULT_POSITION;
|
||||
reverbParams->PositionMatrixLeft = FAudio.FAUDIOFX_REVERB_DEFAULT_POSITION_MATRIX;
|
||||
reverbParams->PositionMatrixRight = FAudio.FAUDIOFX_REVERB_DEFAULT_POSITION_MATRIX;
|
||||
reverbParams->EarlyDiffusion = 15;
|
||||
reverbParams->LateDiffusion = 15;
|
||||
reverbParams->LowEQGain = 8;
|
||||
reverbParams->LowEQCutoff = 4;
|
||||
reverbParams->HighEQGain = 8;
|
||||
reverbParams->HighEQCutoff = 6;
|
||||
reverbParams->RoomFilterFreq = 5000f;
|
||||
reverbParams->RoomFilterMain = -10f;
|
||||
reverbParams->RoomFilterHF = -1f;
|
||||
reverbParams->ReflectionsGain = -26.0200005f;
|
||||
reverbParams->ReverbGain = 10.0f;
|
||||
reverbParams->DecayTime = 1.49000001f;
|
||||
reverbParams->Density = 100.0f;
|
||||
reverbParams->RoomSize = FAudio.FAUDIOFX_REVERB_DEFAULT_ROOM_SIZE;
|
||||
FAudio.FAudioVoice_SetEffectParameters(
|
||||
ReverbVoice,
|
||||
0,
|
||||
reverbParamsPtr,
|
||||
(uint) Marshal.SizeOf<FAudio.FAudioFXReverbParameters>(),
|
||||
0
|
||||
);
|
||||
Marshal.FreeHGlobal(reverbParamsPtr);
|
||||
|
||||
/* Init reverb sends */
|
||||
/* Init reverb sends */
|
||||
|
||||
ReverbSends = new FAudio.FAudioVoiceSends
|
||||
{
|
||||
SendCount = 2,
|
||||
pSends = Marshal.AllocHGlobal(
|
||||
2 * Marshal.SizeOf<FAudio.FAudioSendDescriptor>()
|
||||
)
|
||||
};
|
||||
FAudio.FAudioSendDescriptor* sendDesc = (FAudio.FAudioSendDescriptor*) ReverbSends.pSends;
|
||||
sendDesc[0].Flags = 0;
|
||||
sendDesc[0].pOutputVoice = MasteringVoice;
|
||||
sendDesc[1].Flags = 0;
|
||||
sendDesc[1].pOutputVoice = ReverbVoice;
|
||||
}
|
||||
ReverbSends = new FAudio.FAudioVoiceSends
|
||||
{
|
||||
SendCount = 2,
|
||||
pSends = Marshal.AllocHGlobal(
|
||||
2 * Marshal.SizeOf<FAudio.FAudioSendDescriptor>()
|
||||
)
|
||||
};
|
||||
FAudio.FAudioSendDescriptor* sendDesc = (FAudio.FAudioSendDescriptor*) ReverbSends.pSends;
|
||||
sendDesc[0].Flags = 0;
|
||||
sendDesc[0].pOutputVoice = MasteringVoice;
|
||||
sendDesc[1].Flags = 0;
|
||||
sendDesc[1].pOutputVoice = ReverbVoice;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
for (var i = streamingSounds.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var weakReference = streamingSounds[i];
|
||||
if (weakReference.TryGetTarget(out var streamingSound))
|
||||
{
|
||||
streamingSound.Update();
|
||||
}
|
||||
else
|
||||
{
|
||||
streamingSounds.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Update()
|
||||
{
|
||||
for (var i = streamingSounds.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var weakReference = streamingSounds[i];
|
||||
if (weakReference.TryGetTarget(out var streamingSound))
|
||||
{
|
||||
streamingSound.Update();
|
||||
}
|
||||
else
|
||||
{
|
||||
streamingSounds.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void AddDynamicSoundInstance(StreamingSound instance)
|
||||
{
|
||||
streamingSounds.Add(new WeakReference<StreamingSound>(instance));
|
||||
}
|
||||
internal void AddDynamicSoundInstance(StreamingSound instance)
|
||||
{
|
||||
streamingSounds.Add(new WeakReference<StreamingSound>(instance));
|
||||
}
|
||||
|
||||
internal void AddResourceReference(WeakReference<AudioResource> resourceReference)
|
||||
{
|
||||
lock (resources)
|
||||
{
|
||||
resources.Add(resourceReference);
|
||||
}
|
||||
}
|
||||
internal void AddResourceReference(WeakReference<AudioResource> resourceReference)
|
||||
{
|
||||
lock (resources)
|
||||
{
|
||||
resources.Add(resourceReference);
|
||||
}
|
||||
}
|
||||
|
||||
internal void RemoveResourceReference(WeakReference<AudioResource> resourceReference)
|
||||
{
|
||||
lock (resources)
|
||||
{
|
||||
resources.Remove(resourceReference);
|
||||
}
|
||||
}
|
||||
internal void RemoveResourceReference(WeakReference<AudioResource> resourceReference)
|
||||
{
|
||||
lock (resources)
|
||||
{
|
||||
resources.Remove(resourceReference);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
for (var i = streamingSounds.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var weakReference = streamingSounds[i];
|
||||
|
||||
if (weakReference.TryGetTarget(out var streamingSound))
|
||||
{
|
||||
streamingSound.Dispose();
|
||||
}
|
||||
{
|
||||
streamingSound.Dispose();
|
||||
}
|
||||
}
|
||||
streamingSounds.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
FAudio.FAudioVoice_DestroyVoice(ReverbVoice);
|
||||
FAudio.FAudioVoice_DestroyVoice(MasteringVoice);
|
||||
FAudio.FAudio_Release(Handle);
|
||||
FAudio.FAudio_Release(Handle);
|
||||
|
||||
IsDisposed = true;
|
||||
}
|
||||
}
|
||||
IsDisposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
|
||||
~AudioDevice()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
// TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
|
||||
~AudioDevice()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using MoonWorks.Math;
|
||||
|
||||
namespace MoonWorks.Audio
|
||||
{
|
||||
public class AudioEmitter : AudioResource
|
||||
{
|
||||
internal FAudio.F3DAUDIO_EMITTER emitterData;
|
||||
public class AudioEmitter : AudioResource
|
||||
{
|
||||
internal FAudio.F3DAUDIO_EMITTER emitterData;
|
||||
|
||||
public float DopplerScale
|
||||
{
|
||||
|
@ -107,17 +107,17 @@ namespace MoonWorks.Audio
|
|||
GCHandleType.Pinned
|
||||
);
|
||||
|
||||
public AudioEmitter(AudioDevice device) : base(device)
|
||||
{
|
||||
emitterData = new FAudio.F3DAUDIO_EMITTER();
|
||||
public AudioEmitter(AudioDevice device) : base(device)
|
||||
{
|
||||
emitterData = new FAudio.F3DAUDIO_EMITTER();
|
||||
|
||||
DopplerScale = 1f;
|
||||
Forward = Vector3.Forward;
|
||||
Position = Vector3.Zero;
|
||||
Up = Vector3.Up;
|
||||
Velocity = Vector3.Zero;
|
||||
DopplerScale = 1f;
|
||||
Forward = Vector3.Forward;
|
||||
Position = Vector3.Zero;
|
||||
Up = Vector3.Up;
|
||||
Velocity = Vector3.Zero;
|
||||
|
||||
/* Unexposed variables, defaults based on XNA behavior */
|
||||
/* Unexposed variables, defaults based on XNA behavior */
|
||||
emitterData.pCone = IntPtr.Zero;
|
||||
emitterData.ChannelCount = 1;
|
||||
emitterData.ChannelRadius = 1.0f;
|
||||
|
@ -128,8 +128,8 @@ namespace MoonWorks.Audio
|
|||
emitterData.pLPFReverbCurve = IntPtr.Zero;
|
||||
emitterData.pReverbCurve = IntPtr.Zero;
|
||||
emitterData.CurveDistanceScaler = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Destroy() { }
|
||||
}
|
||||
protected override void Destroy() { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
using System;
|
||||
using System;
|
||||
using MoonWorks.Math;
|
||||
|
||||
namespace MoonWorks.Audio
|
||||
{
|
||||
public class AudioListener : AudioResource
|
||||
{
|
||||
internal FAudio.F3DAUDIO_LISTENER listenerData;
|
||||
public class AudioListener : AudioResource
|
||||
{
|
||||
internal FAudio.F3DAUDIO_LISTENER listenerData;
|
||||
|
||||
public Vector3 Forward
|
||||
{
|
||||
|
@ -80,18 +80,18 @@ namespace MoonWorks.Audio
|
|||
}
|
||||
}
|
||||
|
||||
public AudioListener(AudioDevice device) : base(device)
|
||||
{
|
||||
listenerData = new FAudio.F3DAUDIO_LISTENER();
|
||||
Forward = Vector3.Forward;
|
||||
Position = Vector3.Zero;
|
||||
Up = Vector3.Up;
|
||||
Velocity = Vector3.Zero;
|
||||
public AudioListener(AudioDevice device) : base(device)
|
||||
{
|
||||
listenerData = new FAudio.F3DAUDIO_LISTENER();
|
||||
Forward = Vector3.Forward;
|
||||
Position = Vector3.Zero;
|
||||
Up = Vector3.Up;
|
||||
Velocity = Vector3.Zero;
|
||||
|
||||
/* Unexposed variables, defaults based on XNA behavior */
|
||||
/* Unexposed variables, defaults based on XNA behavior */
|
||||
listenerData.pCone = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Destroy() { }
|
||||
}
|
||||
protected override void Destroy() { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,52 +1,52 @@
|
|||
using System;
|
||||
using System;
|
||||
|
||||
namespace MoonWorks.Audio
|
||||
{
|
||||
public abstract class AudioResource : IDisposable
|
||||
{
|
||||
public AudioDevice Device { get; }
|
||||
public abstract class AudioResource : IDisposable
|
||||
{
|
||||
public AudioDevice Device { get; }
|
||||
|
||||
public bool IsDisposed { get; private set; }
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
private WeakReference<AudioResource> selfReference;
|
||||
private WeakReference<AudioResource> selfReference;
|
||||
|
||||
public AudioResource(AudioDevice device)
|
||||
{
|
||||
Device = device;
|
||||
public AudioResource(AudioDevice device)
|
||||
{
|
||||
Device = device;
|
||||
|
||||
selfReference = new WeakReference<AudioResource>(this);
|
||||
Device.AddResourceReference(selfReference);
|
||||
}
|
||||
selfReference = new WeakReference<AudioResource>(this);
|
||||
Device.AddResourceReference(selfReference);
|
||||
}
|
||||
|
||||
protected abstract void Destroy();
|
||||
protected abstract void Destroy();
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
Destroy();
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
Destroy();
|
||||
|
||||
if (selfReference != null)
|
||||
{
|
||||
Device.RemoveResourceReference(selfReference);
|
||||
selfReference = null;
|
||||
}
|
||||
if (selfReference != null)
|
||||
{
|
||||
Device.RemoveResourceReference(selfReference);
|
||||
selfReference = null;
|
||||
}
|
||||
|
||||
IsDisposed = true;
|
||||
}
|
||||
}
|
||||
IsDisposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
~AudioResource()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
~AudioResource()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,271 +1,271 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using MoonWorks.Math;
|
||||
|
||||
namespace MoonWorks.Audio
|
||||
{
|
||||
public abstract class SoundInstance : AudioResource
|
||||
{
|
||||
internal IntPtr Handle { get; }
|
||||
internal FAudio.FAudioWaveFormatEx Format { get; }
|
||||
public bool Loop { get; }
|
||||
public abstract class SoundInstance : AudioResource
|
||||
{
|
||||
internal IntPtr Handle { get; }
|
||||
internal FAudio.FAudioWaveFormatEx Format { get; }
|
||||
public bool Loop { get; }
|
||||
|
||||
protected FAudio.F3DAUDIO_DSP_SETTINGS dspSettings;
|
||||
protected FAudio.F3DAUDIO_DSP_SETTINGS dspSettings;
|
||||
|
||||
protected bool is3D;
|
||||
protected bool is3D;
|
||||
|
||||
public abstract SoundState State { get; protected set; }
|
||||
public abstract SoundState State { get; protected set; }
|
||||
|
||||
private float _pan = 0;
|
||||
public float Pan
|
||||
{
|
||||
get => _pan;
|
||||
set
|
||||
{
|
||||
_pan = value;
|
||||
private float _pan = 0;
|
||||
public float Pan
|
||||
{
|
||||
get => _pan;
|
||||
set
|
||||
{
|
||||
_pan = value;
|
||||
|
||||
if (_pan < -1f)
|
||||
{
|
||||
_pan = -1f;
|
||||
}
|
||||
if (_pan > 1f)
|
||||
{
|
||||
_pan = 1f;
|
||||
}
|
||||
if (_pan < -1f)
|
||||
{
|
||||
_pan = -1f;
|
||||
}
|
||||
if (_pan > 1f)
|
||||
{
|
||||
_pan = 1f;
|
||||
}
|
||||
|
||||
if (is3D) { return; }
|
||||
if (is3D) { return; }
|
||||
|
||||
SetPanMatrixCoefficients();
|
||||
FAudio.FAudioVoice_SetOutputMatrix(
|
||||
Handle,
|
||||
Device.MasteringVoice,
|
||||
dspSettings.SrcChannelCount,
|
||||
dspSettings.DstChannelCount,
|
||||
dspSettings.pMatrixCoefficients,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
SetPanMatrixCoefficients();
|
||||
FAudio.FAudioVoice_SetOutputMatrix(
|
||||
Handle,
|
||||
Device.MasteringVoice,
|
||||
dspSettings.SrcChannelCount,
|
||||
dspSettings.DstChannelCount,
|
||||
dspSettings.pMatrixCoefficients,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private float _pitch = 1;
|
||||
public float Pitch
|
||||
{
|
||||
get => _pitch;
|
||||
set
|
||||
{
|
||||
_pitch = MathHelper.Clamp(value, -1f, 1f);
|
||||
UpdatePitch();
|
||||
}
|
||||
}
|
||||
private float _pitch = 1;
|
||||
public float Pitch
|
||||
{
|
||||
get => _pitch;
|
||||
set
|
||||
{
|
||||
_pitch = MathHelper.Clamp(value, -1f, 1f);
|
||||
UpdatePitch();
|
||||
}
|
||||
}
|
||||
|
||||
private float _volume = 1;
|
||||
public float Volume
|
||||
{
|
||||
get => _volume;
|
||||
set
|
||||
{
|
||||
_volume = value;
|
||||
FAudio.FAudioVoice_SetVolume(Handle, _volume, 0);
|
||||
}
|
||||
}
|
||||
private float _volume = 1;
|
||||
public float Volume
|
||||
{
|
||||
get => _volume;
|
||||
set
|
||||
{
|
||||
_volume = value;
|
||||
FAudio.FAudioVoice_SetVolume(Handle, _volume, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private float _reverb;
|
||||
public unsafe float Reverb
|
||||
{
|
||||
get => _reverb;
|
||||
set
|
||||
{
|
||||
_reverb = value;
|
||||
private float _reverb;
|
||||
public unsafe float Reverb
|
||||
{
|
||||
get => _reverb;
|
||||
set
|
||||
{
|
||||
_reverb = value;
|
||||
|
||||
float* outputMatrix = (float*) dspSettings.pMatrixCoefficients;
|
||||
outputMatrix[0] = _reverb;
|
||||
if (dspSettings.SrcChannelCount == 2)
|
||||
{
|
||||
outputMatrix[1] = _reverb;
|
||||
}
|
||||
float* outputMatrix = (float*) dspSettings.pMatrixCoefficients;
|
||||
outputMatrix[0] = _reverb;
|
||||
if (dspSettings.SrcChannelCount == 2)
|
||||
{
|
||||
outputMatrix[1] = _reverb;
|
||||
}
|
||||
|
||||
FAudio.FAudioVoice_SetOutputMatrix(
|
||||
Handle,
|
||||
Device.ReverbVoice,
|
||||
dspSettings.SrcChannelCount,
|
||||
1,
|
||||
dspSettings.pMatrixCoefficients,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
FAudio.FAudioVoice_SetOutputMatrix(
|
||||
Handle,
|
||||
Device.ReverbVoice,
|
||||
dspSettings.SrcChannelCount,
|
||||
1,
|
||||
dspSettings.pMatrixCoefficients,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private float _lowPassFilter;
|
||||
public float LowPassFilter
|
||||
{
|
||||
get => _lowPassFilter;
|
||||
set
|
||||
{
|
||||
_lowPassFilter = value;
|
||||
private float _lowPassFilter;
|
||||
public float LowPassFilter
|
||||
{
|
||||
get => _lowPassFilter;
|
||||
set
|
||||
{
|
||||
_lowPassFilter = value;
|
||||
|
||||
FAudio.FAudioFilterParameters p = new FAudio.FAudioFilterParameters
|
||||
{
|
||||
Type = FAudio.FAudioFilterType.FAudioLowPassFilter,
|
||||
Frequency = _lowPassFilter,
|
||||
OneOverQ = 1f
|
||||
};
|
||||
FAudio.FAudioVoice_SetFilterParameters(
|
||||
Handle,
|
||||
ref p,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
FAudio.FAudioFilterParameters p = new FAudio.FAudioFilterParameters
|
||||
{
|
||||
Type = FAudio.FAudioFilterType.FAudioLowPassFilter,
|
||||
Frequency = _lowPassFilter,
|
||||
OneOverQ = 1f
|
||||
};
|
||||
FAudio.FAudioVoice_SetFilterParameters(
|
||||
Handle,
|
||||
ref p,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private float _highPassFilter;
|
||||
public float HighPassFilter
|
||||
{
|
||||
get => _highPassFilter;
|
||||
set
|
||||
{
|
||||
_highPassFilter = value;
|
||||
private float _highPassFilter;
|
||||
public float HighPassFilter
|
||||
{
|
||||
get => _highPassFilter;
|
||||
set
|
||||
{
|
||||
_highPassFilter = value;
|
||||
|
||||
FAudio.FAudioFilterParameters p = new FAudio.FAudioFilterParameters
|
||||
{
|
||||
Type = FAudio.FAudioFilterType.FAudioHighPassFilter,
|
||||
Frequency = _highPassFilter,
|
||||
OneOverQ = 1f
|
||||
};
|
||||
FAudio.FAudioVoice_SetFilterParameters(
|
||||
Handle,
|
||||
ref p,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
FAudio.FAudioFilterParameters p = new FAudio.FAudioFilterParameters
|
||||
{
|
||||
Type = FAudio.FAudioFilterType.FAudioHighPassFilter,
|
||||
Frequency = _highPassFilter,
|
||||
OneOverQ = 1f
|
||||
};
|
||||
FAudio.FAudioVoice_SetFilterParameters(
|
||||
Handle,
|
||||
ref p,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private float _bandPassFilter;
|
||||
public float BandPassFilter
|
||||
{
|
||||
get => _bandPassFilter;
|
||||
set
|
||||
{
|
||||
_bandPassFilter = value;
|
||||
private float _bandPassFilter;
|
||||
public float BandPassFilter
|
||||
{
|
||||
get => _bandPassFilter;
|
||||
set
|
||||
{
|
||||
_bandPassFilter = value;
|
||||
|
||||
FAudio.FAudioFilterParameters p = new FAudio.FAudioFilterParameters
|
||||
{
|
||||
Type = FAudio.FAudioFilterType.FAudioBandPassFilter,
|
||||
Frequency = _bandPassFilter,
|
||||
OneOverQ = 1f
|
||||
};
|
||||
FAudio.FAudioVoice_SetFilterParameters(
|
||||
Handle,
|
||||
ref p,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
FAudio.FAudioFilterParameters p = new FAudio.FAudioFilterParameters
|
||||
{
|
||||
Type = FAudio.FAudioFilterType.FAudioBandPassFilter,
|
||||
Frequency = _bandPassFilter,
|
||||
OneOverQ = 1f
|
||||
};
|
||||
FAudio.FAudioVoice_SetFilterParameters(
|
||||
Handle,
|
||||
ref p,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public SoundInstance(
|
||||
AudioDevice device,
|
||||
ushort channels,
|
||||
uint samplesPerSecond,
|
||||
bool is3D,
|
||||
bool loop
|
||||
) : base(device)
|
||||
{
|
||||
var blockAlign = (ushort)(4 * channels);
|
||||
var format = new FAudio.FAudioWaveFormatEx
|
||||
{
|
||||
wFormatTag = 3,
|
||||
wBitsPerSample = 32,
|
||||
nChannels = channels,
|
||||
nBlockAlign = blockAlign,
|
||||
nSamplesPerSec = samplesPerSecond,
|
||||
nAvgBytesPerSec = blockAlign * samplesPerSecond
|
||||
};
|
||||
public SoundInstance(
|
||||
AudioDevice device,
|
||||
ushort channels,
|
||||
uint samplesPerSecond,
|
||||
bool is3D,
|
||||
bool loop
|
||||
) : base(device)
|
||||
{
|
||||
var blockAlign = (ushort) (4 * channels);
|
||||
var format = new FAudio.FAudioWaveFormatEx
|
||||
{
|
||||
wFormatTag = 3,
|
||||
wBitsPerSample = 32,
|
||||
nChannels = channels,
|
||||
nBlockAlign = blockAlign,
|
||||
nSamplesPerSec = samplesPerSecond,
|
||||
nAvgBytesPerSec = blockAlign * samplesPerSecond
|
||||
};
|
||||
|
||||
Format = format;
|
||||
Format = format;
|
||||
|
||||
FAudio.FAudio_CreateSourceVoice(
|
||||
Device.Handle,
|
||||
out var handle,
|
||||
ref format,
|
||||
FAudio.FAUDIO_VOICE_USEFILTER,
|
||||
FAudio.FAUDIO_DEFAULT_FREQ_RATIO,
|
||||
IntPtr.Zero,
|
||||
IntPtr.Zero,
|
||||
IntPtr.Zero
|
||||
);
|
||||
FAudio.FAudio_CreateSourceVoice(
|
||||
Device.Handle,
|
||||
out var handle,
|
||||
ref format,
|
||||
FAudio.FAUDIO_VOICE_USEFILTER,
|
||||
FAudio.FAUDIO_DEFAULT_FREQ_RATIO,
|
||||
IntPtr.Zero,
|
||||
IntPtr.Zero,
|
||||
IntPtr.Zero
|
||||
);
|
||||
|
||||
if (handle == IntPtr.Zero)
|
||||
{
|
||||
Logger.LogError("SoundInstance failed to initialize!");
|
||||
return;
|
||||
}
|
||||
if (handle == IntPtr.Zero)
|
||||
{
|
||||
Logger.LogError("SoundInstance failed to initialize!");
|
||||
return;
|
||||
}
|
||||
|
||||
Handle = handle;
|
||||
this.is3D = is3D;
|
||||
InitDSPSettings(Format.nChannels);
|
||||
Handle = handle;
|
||||
this.is3D = is3D;
|
||||
InitDSPSettings(Format.nChannels);
|
||||
|
||||
FAudio.FAudioVoice_SetOutputVoices(
|
||||
handle,
|
||||
ref Device.ReverbSends
|
||||
);
|
||||
FAudio.FAudioVoice_SetOutputVoices(
|
||||
handle,
|
||||
ref Device.ReverbSends
|
||||
);
|
||||
|
||||
Loop = loop;
|
||||
State = SoundState.Stopped;
|
||||
}
|
||||
Loop = loop;
|
||||
State = SoundState.Stopped;
|
||||
}
|
||||
|
||||
public void Apply3D(AudioListener listener, AudioEmitter emitter)
|
||||
{
|
||||
is3D = true;
|
||||
public void Apply3D(AudioListener listener, AudioEmitter emitter)
|
||||
{
|
||||
is3D = true;
|
||||
|
||||
emitter.emitterData.CurveDistanceScaler = Device.CurveDistanceScalar;
|
||||
emitter.emitterData.ChannelCount = dspSettings.SrcChannelCount;
|
||||
emitter.emitterData.CurveDistanceScaler = Device.CurveDistanceScalar;
|
||||
emitter.emitterData.ChannelCount = dspSettings.SrcChannelCount;
|
||||
|
||||
FAudio.F3DAudioCalculate(
|
||||
Device.Handle3D,
|
||||
ref listener.listenerData,
|
||||
ref emitter.emitterData,
|
||||
FAudio.F3DAUDIO_CALCULATE_MATRIX | FAudio.F3DAUDIO_CALCULATE_DOPPLER,
|
||||
ref dspSettings
|
||||
);
|
||||
FAudio.F3DAudioCalculate(
|
||||
Device.Handle3D,
|
||||
ref listener.listenerData,
|
||||
ref emitter.emitterData,
|
||||
FAudio.F3DAUDIO_CALCULATE_MATRIX | FAudio.F3DAUDIO_CALCULATE_DOPPLER,
|
||||
ref dspSettings
|
||||
);
|
||||
|
||||
UpdatePitch();
|
||||
FAudio.FAudioVoice_SetOutputMatrix(
|
||||
Handle,
|
||||
Device.MasteringVoice,
|
||||
dspSettings.SrcChannelCount,
|
||||
dspSettings.DstChannelCount,
|
||||
dspSettings.pMatrixCoefficients,
|
||||
0
|
||||
);
|
||||
}
|
||||
UpdatePitch();
|
||||
FAudio.FAudioVoice_SetOutputMatrix(
|
||||
Handle,
|
||||
Device.MasteringVoice,
|
||||
dspSettings.SrcChannelCount,
|
||||
dspSettings.DstChannelCount,
|
||||
dspSettings.pMatrixCoefficients,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
public abstract void Play();
|
||||
public abstract void Pause();
|
||||
public abstract void Stop(bool immediate);
|
||||
public abstract void Play();
|
||||
public abstract void Pause();
|
||||
public abstract void Stop(bool immediate);
|
||||
|
||||
private void InitDSPSettings(uint srcChannels)
|
||||
{
|
||||
dspSettings = new FAudio.F3DAUDIO_DSP_SETTINGS();
|
||||
dspSettings.DopplerFactor = 1f;
|
||||
dspSettings.SrcChannelCount = srcChannels;
|
||||
dspSettings.DstChannelCount = Device.DeviceDetails.OutputFormat.Format.nChannels;
|
||||
private void InitDSPSettings(uint srcChannels)
|
||||
{
|
||||
dspSettings = new FAudio.F3DAUDIO_DSP_SETTINGS();
|
||||
dspSettings.DopplerFactor = 1f;
|
||||
dspSettings.SrcChannelCount = srcChannels;
|
||||
dspSettings.DstChannelCount = Device.DeviceDetails.OutputFormat.Format.nChannels;
|
||||
|
||||
int memsize = (
|
||||
4 *
|
||||
(int) dspSettings.SrcChannelCount *
|
||||
(int) dspSettings.DstChannelCount
|
||||
);
|
||||
int memsize = (
|
||||
4 *
|
||||
(int) dspSettings.SrcChannelCount *
|
||||
(int) dspSettings.DstChannelCount
|
||||
);
|
||||
|
||||
dspSettings.pMatrixCoefficients = Marshal.AllocHGlobal(memsize);
|
||||
unsafe
|
||||
{
|
||||
byte* memPtr = (byte*) dspSettings.pMatrixCoefficients;
|
||||
for (int i = 0; i < memsize; i += 1)
|
||||
{
|
||||
memPtr[i] = 0;
|
||||
}
|
||||
}
|
||||
SetPanMatrixCoefficients();
|
||||
}
|
||||
dspSettings.pMatrixCoefficients = Marshal.AllocHGlobal(memsize);
|
||||
unsafe
|
||||
{
|
||||
byte* memPtr = (byte*) dspSettings.pMatrixCoefficients;
|
||||
for (int i = 0; i < memsize; i += 1)
|
||||
{
|
||||
memPtr[i] = 0;
|
||||
}
|
||||
}
|
||||
SetPanMatrixCoefficients();
|
||||
}
|
||||
|
||||
private void UpdatePitch()
|
||||
{
|
||||
|
@ -287,10 +287,10 @@ namespace MoonWorks.Audio
|
|||
);
|
||||
}
|
||||
|
||||
// Taken from https://github.com/FNA-XNA/FNA/blob/master/src/Audio/SoundEffectInstance.cs
|
||||
private unsafe void SetPanMatrixCoefficients()
|
||||
{
|
||||
/* Two major things to notice:
|
||||
// Taken from https://github.com/FNA-XNA/FNA/blob/master/src/Audio/SoundEffectInstance.cs
|
||||
private unsafe void SetPanMatrixCoefficients()
|
||||
{
|
||||
/* Two major things to notice:
|
||||
* 1. The spec assumes any speaker count >= 2 has Front Left/Right.
|
||||
* 2. Stereo panning is WAY more complicated than you think.
|
||||
* The main thing is that hard panning does NOT eliminate an
|
||||
|
@ -307,7 +307,7 @@ namespace MoonWorks.Audio
|
|||
else
|
||||
{
|
||||
outputMatrix[0] = (_pan > 0.0f) ? (1.0f - _pan) : 1.0f;
|
||||
outputMatrix[1] = (_pan < 0.0f) ? (1.0f + _pan) : 1.0f;
|
||||
outputMatrix[1] = (_pan < 0.0f) ? (1.0f + _pan) : 1.0f;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -339,14 +339,14 @@ namespace MoonWorks.Audio
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Destroy()
|
||||
{
|
||||
Stop(true);
|
||||
protected override void Destroy()
|
||||
{
|
||||
Stop(true);
|
||||
|
||||
FAudio.FAudioVoice_DestroyVoice(Handle);
|
||||
Marshal.FreeHGlobal(dspSettings.pMatrixCoefficients);
|
||||
}
|
||||
}
|
||||
FAudio.FAudioVoice_DestroyVoice(Handle);
|
||||
Marshal.FreeHGlobal(dspSettings.pMatrixCoefficients);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
namespace MoonWorks.Audio
|
||||
namespace MoonWorks.Audio
|
||||
{
|
||||
public enum SoundState
|
||||
{
|
||||
Playing,
|
||||
Paused,
|
||||
Stopped
|
||||
}
|
||||
public enum SoundState
|
||||
{
|
||||
Playing,
|
||||
Paused,
|
||||
Stopped
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,82 +1,82 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace MoonWorks.Audio
|
||||
{
|
||||
public class StaticSound : AudioResource
|
||||
{
|
||||
internal FAudio.FAudioBuffer Handle;
|
||||
public ushort Channels { get; }
|
||||
public uint SamplesPerSecond { get; }
|
||||
public class StaticSound : AudioResource
|
||||
{
|
||||
internal FAudio.FAudioBuffer Handle;
|
||||
public ushort Channels { get; }
|
||||
public uint SamplesPerSecond { get; }
|
||||
|
||||
public uint LoopStart { get; set; } = 0;
|
||||
public uint LoopLength { get; set; } = 0;
|
||||
public uint LoopStart { get; set; } = 0;
|
||||
public uint LoopLength { get; set; } = 0;
|
||||
|
||||
public static StaticSound LoadOgg(AudioDevice device, string filePath)
|
||||
{
|
||||
var filePointer = FAudio.stb_vorbis_open_filename(filePath, out var error, IntPtr.Zero);
|
||||
public static StaticSound LoadOgg(AudioDevice device, string filePath)
|
||||
{
|
||||
var filePointer = FAudio.stb_vorbis_open_filename(filePath, out var error, IntPtr.Zero);
|
||||
|
||||
if (error != 0)
|
||||
{
|
||||
throw new AudioLoadException("Error loading file!");
|
||||
}
|
||||
var info = FAudio.stb_vorbis_get_info(filePointer);
|
||||
var bufferSize = FAudio.stb_vorbis_stream_length_in_samples(filePointer) * info.channels;
|
||||
var buffer = new float[bufferSize];
|
||||
if (error != 0)
|
||||
{
|
||||
throw new AudioLoadException("Error loading file!");
|
||||
}
|
||||
var info = FAudio.stb_vorbis_get_info(filePointer);
|
||||
var bufferSize = FAudio.stb_vorbis_stream_length_in_samples(filePointer) * info.channels;
|
||||
var buffer = new float[bufferSize];
|
||||
|
||||
FAudio.stb_vorbis_get_samples_float_interleaved(
|
||||
filePointer,
|
||||
info.channels,
|
||||
buffer,
|
||||
(int) bufferSize
|
||||
);
|
||||
FAudio.stb_vorbis_get_samples_float_interleaved(
|
||||
filePointer,
|
||||
info.channels,
|
||||
buffer,
|
||||
(int) bufferSize
|
||||
);
|
||||
|
||||
FAudio.stb_vorbis_close(filePointer);
|
||||
FAudio.stb_vorbis_close(filePointer);
|
||||
|
||||
return new StaticSound(
|
||||
device,
|
||||
(ushort) info.channels,
|
||||
info.sample_rate,
|
||||
buffer,
|
||||
0,
|
||||
(uint) buffer.Length
|
||||
);
|
||||
}
|
||||
return new StaticSound(
|
||||
device,
|
||||
(ushort) info.channels,
|
||||
info.sample_rate,
|
||||
buffer,
|
||||
0,
|
||||
(uint) buffer.Length
|
||||
);
|
||||
}
|
||||
|
||||
public StaticSound(
|
||||
AudioDevice device,
|
||||
ushort channels,
|
||||
uint samplesPerSecond,
|
||||
float[] buffer,
|
||||
uint bufferOffset, /* in floats */
|
||||
uint bufferLength /* in floats */
|
||||
) : base(device)
|
||||
{
|
||||
Channels = channels;
|
||||
SamplesPerSecond = samplesPerSecond;
|
||||
public StaticSound(
|
||||
AudioDevice device,
|
||||
ushort channels,
|
||||
uint samplesPerSecond,
|
||||
float[] buffer,
|
||||
uint bufferOffset, /* in floats */
|
||||
uint bufferLength /* in floats */
|
||||
) : base(device)
|
||||
{
|
||||
Channels = channels;
|
||||
SamplesPerSecond = samplesPerSecond;
|
||||
|
||||
var bufferLengthInBytes = (int) (bufferLength * sizeof(float));
|
||||
Handle = new FAudio.FAudioBuffer();
|
||||
Handle.Flags = FAudio.FAUDIO_END_OF_STREAM;
|
||||
Handle.pContext = IntPtr.Zero;
|
||||
Handle.AudioBytes = (uint) bufferLengthInBytes;
|
||||
Handle.pAudioData = Marshal.AllocHGlobal(bufferLengthInBytes);
|
||||
Marshal.Copy(buffer, (int) bufferOffset, Handle.pAudioData, (int) bufferLength);
|
||||
Handle.PlayBegin = 0;
|
||||
Handle.PlayLength = 0;
|
||||
var bufferLengthInBytes = (int) (bufferLength * sizeof(float));
|
||||
Handle = new FAudio.FAudioBuffer();
|
||||
Handle.Flags = FAudio.FAUDIO_END_OF_STREAM;
|
||||
Handle.pContext = IntPtr.Zero;
|
||||
Handle.AudioBytes = (uint) bufferLengthInBytes;
|
||||
Handle.pAudioData = Marshal.AllocHGlobal(bufferLengthInBytes);
|
||||
Marshal.Copy(buffer, (int) bufferOffset, Handle.pAudioData, (int) bufferLength);
|
||||
Handle.PlayBegin = 0;
|
||||
Handle.PlayLength = 0;
|
||||
|
||||
LoopStart = 0;
|
||||
LoopLength = 0;
|
||||
}
|
||||
LoopStart = 0;
|
||||
LoopLength = 0;
|
||||
}
|
||||
|
||||
public StaticSoundInstance CreateInstance(bool loop = false)
|
||||
{
|
||||
return new StaticSoundInstance(Device, this, false, loop);
|
||||
}
|
||||
public StaticSoundInstance CreateInstance(bool loop = false)
|
||||
{
|
||||
return new StaticSoundInstance(Device, this, false, loop);
|
||||
}
|
||||
|
||||
protected override void Destroy()
|
||||
{
|
||||
Marshal.FreeHGlobal(Handle.pAudioData);
|
||||
}
|
||||
}
|
||||
protected override void Destroy()
|
||||
{
|
||||
Marshal.FreeHGlobal(Handle.pAudioData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,96 +1,96 @@
|
|||
using System;
|
||||
using System;
|
||||
|
||||
namespace MoonWorks.Audio
|
||||
{
|
||||
public class StaticSoundInstance : SoundInstance
|
||||
{
|
||||
public StaticSound Parent { get; }
|
||||
public class StaticSoundInstance : SoundInstance
|
||||
{
|
||||
public StaticSound Parent { get; }
|
||||
|
||||
private SoundState _state = SoundState.Stopped;
|
||||
public override SoundState State
|
||||
{
|
||||
get
|
||||
{
|
||||
FAudio.FAudioSourceVoice_GetState(
|
||||
Handle,
|
||||
out var state,
|
||||
FAudio.FAUDIO_VOICE_NOSAMPLESPLAYED
|
||||
);
|
||||
if (state.BuffersQueued == 0)
|
||||
{
|
||||
Stop(true);
|
||||
}
|
||||
private SoundState _state = SoundState.Stopped;
|
||||
public override SoundState State
|
||||
{
|
||||
get
|
||||
{
|
||||
FAudio.FAudioSourceVoice_GetState(
|
||||
Handle,
|
||||
out var state,
|
||||
FAudio.FAUDIO_VOICE_NOSAMPLESPLAYED
|
||||
);
|
||||
if (state.BuffersQueued == 0)
|
||||
{
|
||||
Stop(true);
|
||||
}
|
||||
|
||||
return _state;
|
||||
}
|
||||
return _state;
|
||||
}
|
||||
|
||||
protected set
|
||||
{
|
||||
_state = value;
|
||||
}
|
||||
}
|
||||
protected set
|
||||
{
|
||||
_state = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal StaticSoundInstance(
|
||||
AudioDevice device,
|
||||
StaticSound parent,
|
||||
bool is3D,
|
||||
bool loop
|
||||
) : base(device, parent.Channels, parent.SamplesPerSecond, is3D, loop)
|
||||
{
|
||||
Parent = parent;
|
||||
}
|
||||
internal StaticSoundInstance(
|
||||
AudioDevice device,
|
||||
StaticSound parent,
|
||||
bool is3D,
|
||||
bool loop
|
||||
) : base(device, parent.Channels, parent.SamplesPerSecond, is3D, loop)
|
||||
{
|
||||
Parent = parent;
|
||||
}
|
||||
|
||||
public override void Play()
|
||||
{
|
||||
if (State == SoundState.Playing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
public override void Play()
|
||||
{
|
||||
if (State == SoundState.Playing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Loop)
|
||||
{
|
||||
Parent.Handle.LoopCount = 255;
|
||||
Parent.Handle.LoopBegin = Parent.LoopStart;
|
||||
Parent.Handle.LoopLength = Parent.LoopLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
Parent.Handle.LoopCount = 0;
|
||||
Parent.Handle.LoopBegin = 0;
|
||||
Parent.Handle.LoopLength = 0;
|
||||
}
|
||||
if (Loop)
|
||||
{
|
||||
Parent.Handle.LoopCount = 255;
|
||||
Parent.Handle.LoopBegin = Parent.LoopStart;
|
||||
Parent.Handle.LoopLength = Parent.LoopLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
Parent.Handle.LoopCount = 0;
|
||||
Parent.Handle.LoopBegin = 0;
|
||||
Parent.Handle.LoopLength = 0;
|
||||
}
|
||||
|
||||
FAudio.FAudioSourceVoice_SubmitSourceBuffer(
|
||||
Handle,
|
||||
ref Parent.Handle,
|
||||
IntPtr.Zero
|
||||
);
|
||||
FAudio.FAudioSourceVoice_SubmitSourceBuffer(
|
||||
Handle,
|
||||
ref Parent.Handle,
|
||||
IntPtr.Zero
|
||||
);
|
||||
|
||||
FAudio.FAudioSourceVoice_Start(Handle, 0, 0);
|
||||
State = SoundState.Playing;
|
||||
}
|
||||
FAudio.FAudioSourceVoice_Start(Handle, 0, 0);
|
||||
State = SoundState.Playing;
|
||||
}
|
||||
|
||||
public override void Pause()
|
||||
{
|
||||
if (State == SoundState.Paused)
|
||||
{
|
||||
FAudio.FAudioSourceVoice_Stop(Handle, 0, 0);
|
||||
State = SoundState.Paused;
|
||||
}
|
||||
}
|
||||
public override void Pause()
|
||||
{
|
||||
if (State == SoundState.Paused)
|
||||
{
|
||||
FAudio.FAudioSourceVoice_Stop(Handle, 0, 0);
|
||||
State = SoundState.Paused;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Stop(bool immediate = true)
|
||||
{
|
||||
if (immediate)
|
||||
{
|
||||
FAudio.FAudioSourceVoice_Stop(Handle, 0, 0);
|
||||
FAudio.FAudioSourceVoice_FlushSourceBuffers(Handle);
|
||||
State = SoundState.Stopped;
|
||||
}
|
||||
else
|
||||
{
|
||||
FAudio.FAudioSourceVoice_ExitLoop(Handle, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
public override void Stop(bool immediate = true)
|
||||
{
|
||||
if (immediate)
|
||||
{
|
||||
FAudio.FAudioSourceVoice_Stop(Handle, 0, 0);
|
||||
FAudio.FAudioSourceVoice_FlushSourceBuffers(Handle);
|
||||
State = SoundState.Stopped;
|
||||
}
|
||||
else
|
||||
{
|
||||
FAudio.FAudioSourceVoice_ExitLoop(Handle, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,178 +1,178 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace MoonWorks.Audio
|
||||
{
|
||||
/// <summary>
|
||||
/// For streaming long playback.
|
||||
/// Can be extended to support custom decoders.
|
||||
/// </summary>
|
||||
public abstract class StreamingSound : SoundInstance
|
||||
{
|
||||
private readonly List<IntPtr> queuedBuffers = new List<IntPtr>();
|
||||
private readonly List<uint> queuedSizes = new List<uint>();
|
||||
private const int MINIMUM_BUFFER_CHECK = 3;
|
||||
/// <summary>
|
||||
/// For streaming long playback.
|
||||
/// Can be extended to support custom decoders.
|
||||
/// </summary>
|
||||
public abstract class StreamingSound : SoundInstance
|
||||
{
|
||||
private readonly List<IntPtr> queuedBuffers = new List<IntPtr>();
|
||||
private readonly List<uint> queuedSizes = new List<uint>();
|
||||
private const int MINIMUM_BUFFER_CHECK = 3;
|
||||
|
||||
public int PendingBufferCount => queuedBuffers.Count;
|
||||
public int PendingBufferCount => queuedBuffers.Count;
|
||||
|
||||
public StreamingSound(
|
||||
AudioDevice device,
|
||||
ushort channels,
|
||||
uint samplesPerSecond,
|
||||
bool is3D,
|
||||
bool loop
|
||||
) : base(device, channels, samplesPerSecond, is3D, loop) { }
|
||||
public StreamingSound(
|
||||
AudioDevice device,
|
||||
ushort channels,
|
||||
uint samplesPerSecond,
|
||||
bool is3D,
|
||||
bool loop
|
||||
) : base(device, channels, samplesPerSecond, is3D, loop) { }
|
||||
|
||||
public override void Play()
|
||||
{
|
||||
if (State == SoundState.Playing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
public override void Play()
|
||||
{
|
||||
if (State == SoundState.Playing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
State = SoundState.Playing;
|
||||
Update();
|
||||
FAudio.FAudioSourceVoice_Start(Handle, 0, 0);
|
||||
}
|
||||
State = SoundState.Playing;
|
||||
Update();
|
||||
FAudio.FAudioSourceVoice_Start(Handle, 0, 0);
|
||||
}
|
||||
|
||||
public override void Pause()
|
||||
{
|
||||
if (State == SoundState.Playing)
|
||||
{
|
||||
FAudio.FAudioSourceVoice_Stop(Handle, 0, 0);
|
||||
State = SoundState.Paused;
|
||||
}
|
||||
}
|
||||
public override void Pause()
|
||||
{
|
||||
if (State == SoundState.Playing)
|
||||
{
|
||||
FAudio.FAudioSourceVoice_Stop(Handle, 0, 0);
|
||||
State = SoundState.Paused;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Stop(bool immediate = true)
|
||||
{
|
||||
if (immediate)
|
||||
{
|
||||
FAudio.FAudioSourceVoice_Stop(Handle, 0, 0);
|
||||
FAudio.FAudioSourceVoice_FlushSourceBuffers(Handle);
|
||||
ClearBuffers();
|
||||
}
|
||||
public override void Stop(bool immediate = true)
|
||||
{
|
||||
if (immediate)
|
||||
{
|
||||
FAudio.FAudioSourceVoice_Stop(Handle, 0, 0);
|
||||
FAudio.FAudioSourceVoice_FlushSourceBuffers(Handle);
|
||||
ClearBuffers();
|
||||
}
|
||||
|
||||
State = SoundState.Stopped;
|
||||
}
|
||||
State = SoundState.Stopped;
|
||||
}
|
||||
|
||||
internal void Update()
|
||||
{
|
||||
if (State != SoundState.Playing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
internal void Update()
|
||||
{
|
||||
if (State != SoundState.Playing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FAudio.FAudioSourceVoice_GetState(
|
||||
Handle,
|
||||
out var state,
|
||||
FAudio.FAUDIO_VOICE_NOSAMPLESPLAYED
|
||||
);
|
||||
FAudio.FAudioSourceVoice_GetState(
|
||||
Handle,
|
||||
out var state,
|
||||
FAudio.FAUDIO_VOICE_NOSAMPLESPLAYED
|
||||
);
|
||||
|
||||
while (PendingBufferCount > state.BuffersQueued)
|
||||
lock (queuedBuffers)
|
||||
{
|
||||
Marshal.FreeHGlobal(queuedBuffers[0]);
|
||||
queuedBuffers.RemoveAt(0);
|
||||
}
|
||||
while (PendingBufferCount > state.BuffersQueued)
|
||||
lock (queuedBuffers)
|
||||
{
|
||||
Marshal.FreeHGlobal(queuedBuffers[0]);
|
||||
queuedBuffers.RemoveAt(0);
|
||||
}
|
||||
|
||||
QueueBuffers();
|
||||
}
|
||||
QueueBuffers();
|
||||
}
|
||||
|
||||
protected void QueueBuffers()
|
||||
{
|
||||
for (
|
||||
int i = MINIMUM_BUFFER_CHECK - PendingBufferCount;
|
||||
i > 0;
|
||||
i -= 1
|
||||
)
|
||||
{
|
||||
AddBuffer();
|
||||
}
|
||||
}
|
||||
protected void QueueBuffers()
|
||||
{
|
||||
for (
|
||||
int i = MINIMUM_BUFFER_CHECK - PendingBufferCount;
|
||||
i > 0;
|
||||
i -= 1
|
||||
)
|
||||
{
|
||||
AddBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
protected void ClearBuffers()
|
||||
{
|
||||
lock (queuedBuffers)
|
||||
{
|
||||
foreach (IntPtr buf in queuedBuffers)
|
||||
{
|
||||
Marshal.FreeHGlobal(buf);
|
||||
}
|
||||
queuedBuffers.Clear();
|
||||
queuedSizes.Clear();
|
||||
}
|
||||
}
|
||||
protected void ClearBuffers()
|
||||
{
|
||||
lock (queuedBuffers)
|
||||
{
|
||||
foreach (IntPtr buf in queuedBuffers)
|
||||
{
|
||||
Marshal.FreeHGlobal(buf);
|
||||
}
|
||||
queuedBuffers.Clear();
|
||||
queuedSizes.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
protected void AddBuffer()
|
||||
{
|
||||
AddBuffer(
|
||||
out var buffer,
|
||||
out var bufferOffset,
|
||||
out var bufferLength,
|
||||
out var reachedEnd
|
||||
);
|
||||
protected void AddBuffer()
|
||||
{
|
||||
AddBuffer(
|
||||
out var buffer,
|
||||
out var bufferOffset,
|
||||
out var bufferLength,
|
||||
out var reachedEnd
|
||||
);
|
||||
|
||||
var lengthInBytes = bufferLength * sizeof(float);
|
||||
var lengthInBytes = bufferLength * sizeof(float);
|
||||
|
||||
IntPtr next = Marshal.AllocHGlobal((int) lengthInBytes);
|
||||
Marshal.Copy(buffer, (int) bufferOffset, next, (int) bufferLength);
|
||||
IntPtr next = Marshal.AllocHGlobal((int) lengthInBytes);
|
||||
Marshal.Copy(buffer, (int) bufferOffset, next, (int) bufferLength);
|
||||
|
||||
lock (queuedBuffers)
|
||||
{
|
||||
queuedBuffers.Add(next);
|
||||
if (State != SoundState.Stopped)
|
||||
{
|
||||
FAudio.FAudioBuffer buf = new FAudio.FAudioBuffer
|
||||
{
|
||||
AudioBytes = lengthInBytes,
|
||||
pAudioData = next,
|
||||
PlayLength = (
|
||||
lengthInBytes /
|
||||
Format.nChannels /
|
||||
(uint)(Format.wBitsPerSample / 8)
|
||||
)
|
||||
};
|
||||
lock (queuedBuffers)
|
||||
{
|
||||
queuedBuffers.Add(next);
|
||||
if (State != SoundState.Stopped)
|
||||
{
|
||||
FAudio.FAudioBuffer buf = new FAudio.FAudioBuffer
|
||||
{
|
||||
AudioBytes = lengthInBytes,
|
||||
pAudioData = next,
|
||||
PlayLength = (
|
||||
lengthInBytes /
|
||||
Format.nChannels /
|
||||
(uint) (Format.wBitsPerSample / 8)
|
||||
)
|
||||
};
|
||||
|
||||
FAudio.FAudioSourceVoice_SubmitSourceBuffer(
|
||||
Handle,
|
||||
ref buf,
|
||||
IntPtr.Zero
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
queuedSizes.Add(lengthInBytes);
|
||||
}
|
||||
}
|
||||
FAudio.FAudioSourceVoice_SubmitSourceBuffer(
|
||||
Handle,
|
||||
ref buf,
|
||||
IntPtr.Zero
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
queuedSizes.Add(lengthInBytes);
|
||||
}
|
||||
}
|
||||
|
||||
/* We have reached the end of the file, what do we do? */
|
||||
if (reachedEnd)
|
||||
{
|
||||
if (Loop)
|
||||
{
|
||||
SeekStart();
|
||||
}
|
||||
else
|
||||
{
|
||||
Stop(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* We have reached the end of the file, what do we do? */
|
||||
if (reachedEnd)
|
||||
{
|
||||
if (Loop)
|
||||
{
|
||||
SeekStart();
|
||||
}
|
||||
else
|
||||
{
|
||||
Stop(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void AddBuffer(
|
||||
out float[] buffer,
|
||||
out uint bufferOffset, /* in floats */
|
||||
out uint bufferLength, /* in floats */
|
||||
out bool reachedEnd
|
||||
);
|
||||
protected abstract void AddBuffer(
|
||||
out float[] buffer,
|
||||
out uint bufferOffset, /* in floats */
|
||||
out uint bufferLength, /* in floats */
|
||||
out bool reachedEnd
|
||||
);
|
||||
|
||||
protected abstract void SeekStart();
|
||||
protected abstract void SeekStart();
|
||||
|
||||
protected override void Destroy()
|
||||
{
|
||||
Stop(true);
|
||||
}
|
||||
}
|
||||
protected override void Destroy()
|
||||
{
|
||||
Stop(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,89 +1,91 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace MoonWorks.Audio
|
||||
{
|
||||
public class StreamingSoundOgg : StreamingSound
|
||||
{
|
||||
// FIXME: what should this value be?
|
||||
public const int BUFFER_SIZE = 1024 * 128;
|
||||
public class StreamingSoundOgg : StreamingSound
|
||||
{
|
||||
// FIXME: what should this value be?
|
||||
public const int BUFFER_SIZE = 1024 * 128;
|
||||
|
||||
internal IntPtr FileHandle { get; }
|
||||
internal FAudio.stb_vorbis_info Info { get; }
|
||||
internal IntPtr FileHandle { get; }
|
||||
internal FAudio.stb_vorbis_info Info { get; }
|
||||
|
||||
private readonly float[] buffer;
|
||||
private readonly float[] buffer;
|
||||
|
||||
public override SoundState State { get; protected set; }
|
||||
public override SoundState State { get; protected set; }
|
||||
|
||||
public static StreamingSoundOgg Load(
|
||||
AudioDevice device,
|
||||
string filePath,
|
||||
bool is3D = false,
|
||||
bool loop = false
|
||||
) {
|
||||
var fileHandle = FAudio.stb_vorbis_open_filename(filePath, out var error, IntPtr.Zero);
|
||||
if (error != 0)
|
||||
{
|
||||
Logger.LogError("Error opening OGG file!");
|
||||
throw new AudioLoadException("Error opening OGG file!");
|
||||
}
|
||||
public static StreamingSoundOgg Load(
|
||||
AudioDevice device,
|
||||
string filePath,
|
||||
bool is3D = false,
|
||||
bool loop = false
|
||||
)
|
||||
{
|
||||
var fileHandle = FAudio.stb_vorbis_open_filename(filePath, out var error, IntPtr.Zero);
|
||||
if (error != 0)
|
||||
{
|
||||
Logger.LogError("Error opening OGG file!");
|
||||
throw new AudioLoadException("Error opening OGG file!");
|
||||
}
|
||||
|
||||
var info = FAudio.stb_vorbis_get_info(fileHandle);
|
||||
var info = FAudio.stb_vorbis_get_info(fileHandle);
|
||||
|
||||
return new StreamingSoundOgg(
|
||||
device,
|
||||
fileHandle,
|
||||
info,
|
||||
is3D,
|
||||
loop
|
||||
);
|
||||
}
|
||||
return new StreamingSoundOgg(
|
||||
device,
|
||||
fileHandle,
|
||||
info,
|
||||
is3D,
|
||||
loop
|
||||
);
|
||||
}
|
||||
|
||||
internal StreamingSoundOgg(
|
||||
AudioDevice device,
|
||||
IntPtr fileHandle,
|
||||
FAudio.stb_vorbis_info info,
|
||||
bool is3D,
|
||||
bool loop
|
||||
) : base(device, (ushort) info.channels, info.sample_rate, is3D, loop)
|
||||
{
|
||||
FileHandle = fileHandle;
|
||||
Info = info;
|
||||
buffer = new float[BUFFER_SIZE];
|
||||
internal StreamingSoundOgg(
|
||||
AudioDevice device,
|
||||
IntPtr fileHandle,
|
||||
FAudio.stb_vorbis_info info,
|
||||
bool is3D,
|
||||
bool loop
|
||||
) : base(device, (ushort) info.channels, info.sample_rate, is3D, loop)
|
||||
{
|
||||
FileHandle = fileHandle;
|
||||
Info = info;
|
||||
buffer = new float[BUFFER_SIZE];
|
||||
|
||||
device.AddDynamicSoundInstance(this);
|
||||
}
|
||||
device.AddDynamicSoundInstance(this);
|
||||
}
|
||||
|
||||
protected override void AddBuffer(
|
||||
out float[] buffer,
|
||||
out uint bufferOffset,
|
||||
out uint bufferLength,
|
||||
out bool reachedEnd
|
||||
) {
|
||||
buffer = this.buffer;
|
||||
protected override void AddBuffer(
|
||||
out float[] buffer,
|
||||
out uint bufferOffset,
|
||||
out uint bufferLength,
|
||||
out bool reachedEnd
|
||||
)
|
||||
{
|
||||
buffer = this.buffer;
|
||||
|
||||
/* NOTE: this function returns samples per channel, not total samples */
|
||||
var samples = FAudio.stb_vorbis_get_samples_float_interleaved(
|
||||
FileHandle,
|
||||
Info.channels,
|
||||
buffer,
|
||||
buffer.Length
|
||||
);
|
||||
/* NOTE: this function returns samples per channel, not total samples */
|
||||
var samples = FAudio.stb_vorbis_get_samples_float_interleaved(
|
||||
FileHandle,
|
||||
Info.channels,
|
||||
buffer,
|
||||
buffer.Length
|
||||
);
|
||||
|
||||
var sampleCount = samples * Info.channels;
|
||||
bufferOffset = 0;
|
||||
bufferLength = (uint) sampleCount;
|
||||
reachedEnd = sampleCount < buffer.Length;
|
||||
}
|
||||
var sampleCount = samples * Info.channels;
|
||||
bufferOffset = 0;
|
||||
bufferLength = (uint) sampleCount;
|
||||
reachedEnd = sampleCount < buffer.Length;
|
||||
}
|
||||
|
||||
protected override void SeekStart()
|
||||
{
|
||||
FAudio.stb_vorbis_seek_start(FileHandle);
|
||||
}
|
||||
protected override void SeekStart()
|
||||
{
|
||||
FAudio.stb_vorbis_seek_start(FileHandle);
|
||||
}
|
||||
|
||||
protected override void Destroy()
|
||||
{
|
||||
FAudio.stb_vorbis_close(FileHandle);
|
||||
}
|
||||
}
|
||||
protected override void Destroy()
|
||||
{
|
||||
FAudio.stb_vorbis_close(FileHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
using System;
|
||||
using System;
|
||||
|
||||
namespace MoonWorks
|
||||
{
|
||||
public class AudioLoadException : Exception
|
||||
{
|
||||
public AudioLoadException(string message) : base(message)
|
||||
{
|
||||
public class AudioLoadException : Exception
|
||||
{
|
||||
public AudioLoadException(string message) : base(message)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
219
src/Game.cs
219
src/Game.cs
|
@ -10,17 +10,17 @@ using System.Diagnostics;
|
|||
|
||||
namespace MoonWorks
|
||||
{
|
||||
public abstract class Game
|
||||
{
|
||||
public TimeSpan MAX_DELTA_TIME = TimeSpan.FromMilliseconds(100);
|
||||
public abstract class Game
|
||||
{
|
||||
public TimeSpan MAX_DELTA_TIME = TimeSpan.FromMilliseconds(100);
|
||||
|
||||
private bool quit = false;
|
||||
bool debugMode;
|
||||
private bool quit = false;
|
||||
bool debugMode;
|
||||
|
||||
private Stopwatch gameTimer;
|
||||
private TimeSpan timestep;
|
||||
private TimeSpan timestep;
|
||||
private long previousTicks = 0;
|
||||
TimeSpan accumulatedElapsedTime = TimeSpan.Zero;
|
||||
TimeSpan accumulatedElapsedTime = TimeSpan.Zero;
|
||||
// must be a power of 2 so we can do a bitmask optimization when checking worst case
|
||||
private const int PREVIOUS_SLEEP_TIME_COUNT = 128;
|
||||
private const int SLEEP_TIME_MASK = PREVIOUS_SLEEP_TIME_COUNT - 1;
|
||||
|
@ -28,26 +28,27 @@ namespace MoonWorks
|
|||
private int sleepTimeIndex = 0;
|
||||
private TimeSpan worstCaseSleepPrecision = TimeSpan.FromMilliseconds(1);
|
||||
|
||||
public OSWindow Window { get; }
|
||||
public GraphicsDevice GraphicsDevice { get; }
|
||||
public AudioDevice AudioDevice { get; }
|
||||
public Inputs Inputs { get; }
|
||||
public OSWindow Window { get; }
|
||||
public GraphicsDevice GraphicsDevice { get; }
|
||||
public AudioDevice AudioDevice { get; }
|
||||
public Inputs Inputs { get; }
|
||||
|
||||
private Dictionary<PresentMode, RefreshCS.Refresh.PresentMode> moonWorksToRefreshPresentMode = new Dictionary<PresentMode, RefreshCS.Refresh.PresentMode>
|
||||
{
|
||||
{ PresentMode.Immediate, RefreshCS.Refresh.PresentMode.Immediate },
|
||||
{ PresentMode.Mailbox, RefreshCS.Refresh.PresentMode.Mailbox },
|
||||
{ PresentMode.FIFO, RefreshCS.Refresh.PresentMode.FIFO },
|
||||
{ PresentMode.FIFORelaxed, RefreshCS.Refresh.PresentMode.FIFORelaxed }
|
||||
};
|
||||
private Dictionary<PresentMode, RefreshCS.Refresh.PresentMode> moonWorksToRefreshPresentMode = new Dictionary<PresentMode, RefreshCS.Refresh.PresentMode>
|
||||
{
|
||||
{ PresentMode.Immediate, RefreshCS.Refresh.PresentMode.Immediate },
|
||||
{ PresentMode.Mailbox, RefreshCS.Refresh.PresentMode.Mailbox },
|
||||
{ PresentMode.FIFO, RefreshCS.Refresh.PresentMode.FIFO },
|
||||
{ PresentMode.FIFORelaxed, RefreshCS.Refresh.PresentMode.FIFORelaxed }
|
||||
};
|
||||
|
||||
public Game(
|
||||
WindowCreateInfo windowCreateInfo,
|
||||
PresentMode presentMode,
|
||||
int targetTimestep = 60,
|
||||
bool debugMode = false
|
||||
) {
|
||||
timestep = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / targetTimestep);
|
||||
public Game(
|
||||
WindowCreateInfo windowCreateInfo,
|
||||
PresentMode presentMode,
|
||||
int targetTimestep = 60,
|
||||
bool debugMode = false
|
||||
)
|
||||
{
|
||||
timestep = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / targetTimestep);
|
||||
gameTimer = Stopwatch.StartNew();
|
||||
|
||||
for (int i = 0; i < previousSleepTimes.Length; i += 1)
|
||||
|
@ -55,33 +56,33 @@ namespace MoonWorks
|
|||
previousSleepTimes[i] = TimeSpan.FromMilliseconds(1);
|
||||
}
|
||||
|
||||
if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_TIMER | SDL.SDL_INIT_GAMECONTROLLER) < 0)
|
||||
{
|
||||
System.Console.WriteLine("Failed to initialize SDL!");
|
||||
return;
|
||||
}
|
||||
if (SDL.SDL_Init(SDL.SDL_INIT_VIDEO | SDL.SDL_INIT_TIMER | SDL.SDL_INIT_GAMECONTROLLER) < 0)
|
||||
{
|
||||
System.Console.WriteLine("Failed to initialize SDL!");
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.Initialize();
|
||||
Logger.Initialize();
|
||||
|
||||
Inputs = new Inputs();
|
||||
Inputs = new Inputs();
|
||||
|
||||
Window = new OSWindow(windowCreateInfo);
|
||||
Window = new OSWindow(windowCreateInfo);
|
||||
|
||||
GraphicsDevice = new GraphicsDevice(
|
||||
Window.Handle,
|
||||
moonWorksToRefreshPresentMode[presentMode],
|
||||
debugMode
|
||||
);
|
||||
GraphicsDevice = new GraphicsDevice(
|
||||
Window.Handle,
|
||||
moonWorksToRefreshPresentMode[presentMode],
|
||||
debugMode
|
||||
);
|
||||
|
||||
AudioDevice = new AudioDevice();
|
||||
AudioDevice = new AudioDevice();
|
||||
|
||||
this.debugMode = debugMode;
|
||||
}
|
||||
this.debugMode = debugMode;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
while (!quit)
|
||||
{
|
||||
public void Run()
|
||||
{
|
||||
while (!quit)
|
||||
{
|
||||
AdvanceElapsedTime();
|
||||
|
||||
/* We want to wait until the next frame,
|
||||
|
@ -111,33 +112,33 @@ namespace MoonWorks
|
|||
HandleSDLEvents();
|
||||
|
||||
// Do not let any step take longer than our maximum.
|
||||
if (accumulatedElapsedTime > MAX_DELTA_TIME)
|
||||
{
|
||||
accumulatedElapsedTime = MAX_DELTA_TIME;
|
||||
}
|
||||
if (accumulatedElapsedTime > MAX_DELTA_TIME)
|
||||
{
|
||||
accumulatedElapsedTime = MAX_DELTA_TIME;
|
||||
}
|
||||
|
||||
if (!quit)
|
||||
{
|
||||
while (accumulatedElapsedTime >= timestep)
|
||||
{
|
||||
Inputs.Mouse.Wheel = 0;
|
||||
if (!quit)
|
||||
{
|
||||
while (accumulatedElapsedTime >= timestep)
|
||||
{
|
||||
Inputs.Mouse.Wheel = 0;
|
||||
|
||||
Inputs.Update();
|
||||
AudioDevice.Update();
|
||||
Inputs.Update();
|
||||
AudioDevice.Update();
|
||||
|
||||
Update(timestep);
|
||||
Update(timestep);
|
||||
|
||||
accumulatedElapsedTime -= timestep;
|
||||
}
|
||||
accumulatedElapsedTime -= timestep;
|
||||
}
|
||||
|
||||
var alpha = accumulatedElapsedTime / timestep;
|
||||
var alpha = accumulatedElapsedTime / timestep;
|
||||
|
||||
Draw(timestep, alpha);
|
||||
Draw(timestep, alpha);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
GraphicsDevice.SubmitDestroyCommandBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
OnDestroy();
|
||||
|
||||
|
@ -146,64 +147,64 @@ namespace MoonWorks
|
|||
Window.Dispose();
|
||||
|
||||
SDL.SDL_Quit();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleSDLEvents()
|
||||
{
|
||||
while (SDL.SDL_PollEvent(out var _event) == 1)
|
||||
{
|
||||
switch (_event.type)
|
||||
{
|
||||
case SDL.SDL_EventType.SDL_QUIT:
|
||||
quit = true;
|
||||
break;
|
||||
private void HandleSDLEvents()
|
||||
{
|
||||
while (SDL.SDL_PollEvent(out var _event) == 1)
|
||||
{
|
||||
switch (_event.type)
|
||||
{
|
||||
case SDL.SDL_EventType.SDL_QUIT:
|
||||
quit = true;
|
||||
break;
|
||||
|
||||
case SDL.SDL_EventType.SDL_TEXTINPUT:
|
||||
HandleTextInput(_event);
|
||||
break;
|
||||
case SDL.SDL_EventType.SDL_TEXTINPUT:
|
||||
HandleTextInput(_event);
|
||||
break;
|
||||
|
||||
case SDL.SDL_EventType.SDL_MOUSEWHEEL:
|
||||
Inputs.Mouse.Wheel += _event.wheel.y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
case SDL.SDL_EventType.SDL_MOUSEWHEEL:
|
||||
Inputs.Mouse.Wheel += _event.wheel.y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void Update(TimeSpan dt);
|
||||
protected abstract void Update(TimeSpan dt);
|
||||
|
||||
// alpha refers to a percentage value between the current and next state
|
||||
protected abstract void Draw(TimeSpan dt, double alpha);
|
||||
protected abstract void Draw(TimeSpan dt, double alpha);
|
||||
|
||||
// Clean up any objects you created in this function
|
||||
protected abstract void OnDestroy();
|
||||
|
||||
private void HandleTextInput(SDL2.SDL.SDL_Event evt)
|
||||
{
|
||||
// Based on the SDL2# LPUtf8StrMarshaler
|
||||
unsafe
|
||||
{
|
||||
int bytes = MeasureStringLength(evt.text.text);
|
||||
if (bytes > 0)
|
||||
{
|
||||
/* UTF8 will never encode more characters
|
||||
private void HandleTextInput(SDL2.SDL.SDL_Event evt)
|
||||
{
|
||||
// Based on the SDL2# LPUtf8StrMarshaler
|
||||
unsafe
|
||||
{
|
||||
int bytes = MeasureStringLength(evt.text.text);
|
||||
if (bytes > 0)
|
||||
{
|
||||
/* UTF8 will never encode more characters
|
||||
* than bytes in a string, so bytes is a
|
||||
* suitable upper estimate of size needed
|
||||
*/
|
||||
char* charsBuffer = stackalloc char[bytes];
|
||||
int chars = Encoding.UTF8.GetChars(
|
||||
evt.text.text,
|
||||
bytes,
|
||||
charsBuffer,
|
||||
bytes
|
||||
);
|
||||
char* charsBuffer = stackalloc char[bytes];
|
||||
int chars = Encoding.UTF8.GetChars(
|
||||
evt.text.text,
|
||||
bytes,
|
||||
charsBuffer,
|
||||
bytes
|
||||
);
|
||||
|
||||
for (int i = 0; i < chars; i += 1)
|
||||
{
|
||||
Inputs.OnTextInput(charsBuffer[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < chars; i += 1)
|
||||
{
|
||||
Inputs.OnTextInput(charsBuffer[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TimeSpan AdvanceElapsedTime()
|
||||
{
|
||||
|
@ -259,8 +260,8 @@ namespace MoonWorks
|
|||
private unsafe static int MeasureStringLength(byte* ptr)
|
||||
{
|
||||
int bytes;
|
||||
for (bytes = 0; *ptr != 0; ptr += 1, bytes += 1);
|
||||
for (bytes = 0; *ptr != 0; ptr += 1, bytes += 1) ;
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
namespace MoonWorks.Graphics
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
public struct BufferBinding
|
||||
{
|
||||
public Buffer Buffer;
|
||||
public ulong Offset;
|
||||
public struct BufferBinding
|
||||
{
|
||||
public Buffer Buffer;
|
||||
public ulong Offset;
|
||||
|
||||
public BufferBinding(Buffer buffer, ulong offset)
|
||||
{
|
||||
Buffer = buffer;
|
||||
Offset = offset;
|
||||
}
|
||||
}
|
||||
public BufferBinding(Buffer buffer, ulong offset)
|
||||
{
|
||||
Buffer = buffer;
|
||||
Offset = offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
namespace MoonWorks.Graphics
|
||||
{
|
||||
public struct TextureSamplerBinding
|
||||
{
|
||||
public Texture Texture;
|
||||
public Sampler Sampler;
|
||||
public struct TextureSamplerBinding
|
||||
{
|
||||
public Texture Texture;
|
||||
public Sampler Sampler;
|
||||
|
||||
public TextureSamplerBinding(Texture texture, Sampler sampler)
|
||||
{
|
||||
Texture = texture;
|
||||
Sampler = sampler;
|
||||
}
|
||||
}
|
||||
public TextureSamplerBinding(Texture texture, Sampler sampler)
|
||||
{
|
||||
Texture = texture;
|
||||
Sampler = sampler;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
@ -41,7 +41,7 @@ namespace MoonWorks.Graphics
|
|||
{
|
||||
unchecked
|
||||
{
|
||||
return (byte)(this.packedValue);
|
||||
return (byte) (this.packedValue);
|
||||
}
|
||||
}
|
||||
set
|
||||
|
@ -59,12 +59,12 @@ namespace MoonWorks.Graphics
|
|||
{
|
||||
unchecked
|
||||
{
|
||||
return (byte)(this.packedValue >> 8);
|
||||
return (byte) (this.packedValue >> 8);
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
this.packedValue = (this.packedValue & 0xffff00ff) | ((uint)value << 8);
|
||||
this.packedValue = (this.packedValue & 0xffff00ff) | ((uint) value << 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1538,27 +1538,27 @@ namespace MoonWorks.Graphics
|
|||
RosyBrown = new Color(0xff8f8fbc);
|
||||
RoyalBlue = new Color(0xffe16941);
|
||||
SaddleBrown = new Color(0xff13458b);
|
||||
Salmon= new Color(0xff7280fa);
|
||||
Salmon = new Color(0xff7280fa);
|
||||
SandyBrown = new Color(0xff60a4f4);
|
||||
SeaGreen = new Color(0xff578b2e);
|
||||
SeaShell = new Color(0xffeef5ff);
|
||||
Sienna = new Color(0xff2d52a0);
|
||||
Silver = new Color(0xffc0c0c0);
|
||||
SkyBlue = new Color(0xffebce87);
|
||||
SlateBlue= new Color(0xffcd5a6a);
|
||||
SlateGray= new Color(0xff908070);
|
||||
Snow= new Color(0xfffafaff);
|
||||
SpringGreen= new Color(0xff7fff00);
|
||||
SteelBlue= new Color(0xffb48246);
|
||||
Tan= new Color(0xff8cb4d2);
|
||||
Teal= new Color(0xff808000);
|
||||
Thistle= new Color(0xffd8bfd8);
|
||||
Tomato= new Color(0xff4763ff);
|
||||
Turquoise= new Color(0xffd0e040);
|
||||
Violet= new Color(0xffee82ee);
|
||||
Wheat= new Color(0xffb3def5);
|
||||
White= new Color(uint.MaxValue);
|
||||
WhiteSmoke= new Color(0xfff5f5f5);
|
||||
SlateBlue = new Color(0xffcd5a6a);
|
||||
SlateGray = new Color(0xff908070);
|
||||
Snow = new Color(0xfffafaff);
|
||||
SpringGreen = new Color(0xff7fff00);
|
||||
SteelBlue = new Color(0xffb48246);
|
||||
Tan = new Color(0xff8cb4d2);
|
||||
Teal = new Color(0xff808000);
|
||||
Thistle = new Color(0xffd8bfd8);
|
||||
Tomato = new Color(0xff4763ff);
|
||||
Turquoise = new Color(0xffd0e040);
|
||||
Violet = new Color(0xffee82ee);
|
||||
Wheat = new Color(0xffb3def5);
|
||||
White = new Color(uint.MaxValue);
|
||||
WhiteSmoke = new Color(0xfff5f5f5);
|
||||
Yellow = new Color(0xff00ffff);
|
||||
YellowGreen = new Color(0xff32cd9a);
|
||||
}
|
||||
|
@ -1623,7 +1623,7 @@ namespace MoonWorks.Graphics
|
|||
R = (byte) MathHelper.Clamp(r, Byte.MinValue, Byte.MaxValue);
|
||||
G = (byte) MathHelper.Clamp(g, Byte.MinValue, Byte.MaxValue);
|
||||
B = (byte) MathHelper.Clamp(b, Byte.MinValue, Byte.MaxValue);
|
||||
A = (byte)255;
|
||||
A = (byte) 255;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1769,10 +1769,10 @@ namespace MoonWorks.Graphics
|
|||
/// <returns><c>True</c> if the instances are equal; <c>false</c> otherwise.</returns>
|
||||
public static bool operator ==(Color a, Color b)
|
||||
{
|
||||
return ( a.A == b.A &&
|
||||
return (a.A == b.A &&
|
||||
a.R == b.R &&
|
||||
a.G == b.G &&
|
||||
a.B == b.B );
|
||||
a.B == b.B);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -4,58 +4,59 @@ using RefreshCS;
|
|||
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
public class GraphicsDevice : IDisposable
|
||||
{
|
||||
public IntPtr Handle { get; }
|
||||
public class GraphicsDevice : IDisposable
|
||||
{
|
||||
public IntPtr Handle { get; }
|
||||
|
||||
public bool IsDisposed { get; private set; }
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
private readonly List<WeakReference<GraphicsResource>> resources = new List<WeakReference<GraphicsResource>>();
|
||||
private readonly List<WeakReference<GraphicsResource>> resources = new List<WeakReference<GraphicsResource>>();
|
||||
private Dictionary<IntPtr, Action<IntPtr, IntPtr, IntPtr>> resourcesToDestroy = new Dictionary<IntPtr, Action<IntPtr, IntPtr, IntPtr>>();
|
||||
|
||||
public GraphicsDevice(
|
||||
IntPtr deviceWindowHandle,
|
||||
Refresh.PresentMode presentMode,
|
||||
bool debugMode,
|
||||
int initialCommandBufferPoolSize = 4
|
||||
) {
|
||||
var presentationParameters = new Refresh.PresentationParameters
|
||||
{
|
||||
deviceWindowHandle = deviceWindowHandle,
|
||||
presentMode = presentMode
|
||||
};
|
||||
public GraphicsDevice(
|
||||
IntPtr deviceWindowHandle,
|
||||
Refresh.PresentMode presentMode,
|
||||
bool debugMode,
|
||||
int initialCommandBufferPoolSize = 4
|
||||
)
|
||||
{
|
||||
var presentationParameters = new Refresh.PresentationParameters
|
||||
{
|
||||
deviceWindowHandle = deviceWindowHandle,
|
||||
presentMode = presentMode
|
||||
};
|
||||
|
||||
Handle = Refresh.Refresh_CreateDevice(
|
||||
presentationParameters,
|
||||
Conversions.BoolToByte(debugMode)
|
||||
);
|
||||
}
|
||||
Handle = Refresh.Refresh_CreateDevice(
|
||||
presentationParameters,
|
||||
Conversions.BoolToByte(debugMode)
|
||||
);
|
||||
}
|
||||
|
||||
public CommandBuffer AcquireCommandBuffer()
|
||||
{
|
||||
return new CommandBuffer(this, Refresh.Refresh_AcquireCommandBuffer(Handle, 0));
|
||||
}
|
||||
public CommandBuffer AcquireCommandBuffer()
|
||||
{
|
||||
return new CommandBuffer(this, Refresh.Refresh_AcquireCommandBuffer(Handle, 0));
|
||||
}
|
||||
|
||||
public unsafe void Submit(params CommandBuffer[] commandBuffers)
|
||||
{
|
||||
var commandBufferPtrs = stackalloc IntPtr[commandBuffers.Length];
|
||||
public unsafe void Submit(params CommandBuffer[] commandBuffers)
|
||||
{
|
||||
var commandBufferPtrs = stackalloc IntPtr[commandBuffers.Length];
|
||||
|
||||
for (var i = 0; i < commandBuffers.Length; i += 1)
|
||||
{
|
||||
commandBufferPtrs[i] = commandBuffers[i].Handle;
|
||||
}
|
||||
for (var i = 0; i < commandBuffers.Length; i += 1)
|
||||
{
|
||||
commandBufferPtrs[i] = commandBuffers[i].Handle;
|
||||
}
|
||||
|
||||
Refresh.Refresh_Submit(
|
||||
Handle,
|
||||
(uint) commandBuffers.Length,
|
||||
(IntPtr) commandBufferPtrs
|
||||
);
|
||||
}
|
||||
Refresh.Refresh_Submit(
|
||||
Handle,
|
||||
(uint) commandBuffers.Length,
|
||||
(IntPtr) commandBufferPtrs
|
||||
);
|
||||
}
|
||||
|
||||
public void Wait()
|
||||
{
|
||||
Refresh.Refresh_Wait(Handle);
|
||||
}
|
||||
public void Wait()
|
||||
{
|
||||
Refresh.Refresh_Wait(Handle);
|
||||
}
|
||||
|
||||
internal void SubmitDestroyCommandBuffer()
|
||||
{
|
||||
|
@ -77,60 +78,60 @@ namespace MoonWorks.Graphics
|
|||
resourcesToDestroy.Add(resource.Handle, destroyFunction);
|
||||
}
|
||||
|
||||
internal void AddResourceReference(WeakReference<GraphicsResource> resourceReference)
|
||||
{
|
||||
lock (resources)
|
||||
{
|
||||
resources.Add(resourceReference);
|
||||
}
|
||||
}
|
||||
internal void AddResourceReference(WeakReference<GraphicsResource> resourceReference)
|
||||
{
|
||||
lock (resources)
|
||||
{
|
||||
resources.Add(resourceReference);
|
||||
}
|
||||
}
|
||||
|
||||
internal void RemoveResourceReference(WeakReference<GraphicsResource> resourceReference)
|
||||
{
|
||||
lock (resources)
|
||||
{
|
||||
resources.Remove(resourceReference);
|
||||
}
|
||||
}
|
||||
internal void RemoveResourceReference(WeakReference<GraphicsResource> resourceReference)
|
||||
{
|
||||
lock (resources)
|
||||
{
|
||||
resources.Remove(resourceReference);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
lock (resources)
|
||||
{
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
lock (resources)
|
||||
{
|
||||
for (var i = resources.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var resource = resources[i];
|
||||
if (resource.TryGetTarget(out var target))
|
||||
{
|
||||
target.Dispose();
|
||||
}
|
||||
{
|
||||
target.Dispose();
|
||||
}
|
||||
}
|
||||
resources.Clear();
|
||||
}
|
||||
resources.Clear();
|
||||
}
|
||||
|
||||
SubmitDestroyCommandBuffer();
|
||||
Refresh.Refresh_DestroyDevice(Handle);
|
||||
}
|
||||
Refresh.Refresh_DestroyDevice(Handle);
|
||||
}
|
||||
|
||||
IsDisposed = true;
|
||||
}
|
||||
}
|
||||
IsDisposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
~GraphicsDevice()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
~GraphicsDevice()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,51 +2,51 @@
|
|||
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
public abstract class GraphicsResource : IDisposable
|
||||
{
|
||||
public GraphicsDevice Device { get; }
|
||||
public IntPtr Handle { get; protected set; }
|
||||
public abstract class GraphicsResource : IDisposable
|
||||
{
|
||||
public GraphicsDevice Device { get; }
|
||||
public IntPtr Handle { get; protected set; }
|
||||
|
||||
public bool IsDisposed { get; private set; }
|
||||
protected abstract Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction { get; }
|
||||
public bool IsDisposed { get; private set; }
|
||||
protected abstract Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction { get; }
|
||||
|
||||
private WeakReference<GraphicsResource> selfReference;
|
||||
private WeakReference<GraphicsResource> selfReference;
|
||||
|
||||
public GraphicsResource(GraphicsDevice device)
|
||||
{
|
||||
Device = device;
|
||||
public GraphicsResource(GraphicsDevice device)
|
||||
{
|
||||
Device = device;
|
||||
|
||||
selfReference = new WeakReference<GraphicsResource>(this);
|
||||
Device.AddResourceReference(selfReference);
|
||||
}
|
||||
selfReference = new WeakReference<GraphicsResource>(this);
|
||||
Device.AddResourceReference(selfReference);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
Device.PrepareDestroyResource(this, QueueDestroyFunction);
|
||||
|
||||
if (selfReference != null)
|
||||
{
|
||||
Device.RemoveResourceReference(selfReference);
|
||||
selfReference = null;
|
||||
}
|
||||
if (selfReference != null)
|
||||
{
|
||||
Device.RemoveResourceReference(selfReference);
|
||||
selfReference = null;
|
||||
}
|
||||
|
||||
IsDisposed = true;
|
||||
}
|
||||
}
|
||||
IsDisposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
~GraphicsResource()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
~GraphicsResource()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
@ -104,7 +104,7 @@ namespace MoonWorks.Graphics
|
|||
internal static float Convert(ushort value)
|
||||
{
|
||||
uint rst;
|
||||
uint mantissa = (uint)(value & 1023);
|
||||
uint mantissa = (uint) (value & 1023);
|
||||
uint exp = 0xfffffff2;
|
||||
|
||||
if ((value & -33792) == 0)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
@ -192,7 +192,7 @@ namespace MoonWorks.Graphics
|
|||
static ulong Pack(float x, float y, float z, float w)
|
||||
{
|
||||
return (ulong) (
|
||||
((long) System.Math.Round(MathHelper.Clamp(x, -32768, 32767)) & 0xFFFF ) |
|
||||
((long) System.Math.Round(MathHelper.Clamp(x, -32768, 32767)) & 0xFFFF) |
|
||||
(((long) System.Math.Round(MathHelper.Clamp(y, -32768, 32767)) << 16) & 0xFFFF0000) |
|
||||
(((long) System.Math.Round(MathHelper.Clamp(z, -32768, 32767)) << 32) & 0xFFFF00000000) |
|
||||
((long) System.Math.Round(MathHelper.Clamp(w, -32768, 32767)) << 48)
|
||||
|
|
|
@ -5,298 +5,298 @@
|
|||
*/
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
public enum PresentMode
|
||||
{
|
||||
Immediate,
|
||||
Mailbox,
|
||||
FIFO,
|
||||
FIFORelaxed
|
||||
}
|
||||
public enum PresentMode
|
||||
{
|
||||
Immediate,
|
||||
Mailbox,
|
||||
FIFO,
|
||||
FIFORelaxed
|
||||
}
|
||||
|
||||
public enum PrimitiveType
|
||||
{
|
||||
PointList,
|
||||
LineList,
|
||||
LineStrip,
|
||||
TriangleList,
|
||||
TriangleStrip
|
||||
}
|
||||
public enum PrimitiveType
|
||||
{
|
||||
PointList,
|
||||
LineList,
|
||||
LineStrip,
|
||||
TriangleList,
|
||||
TriangleStrip
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Describes the operation that a render pass will use when loading a render target.
|
||||
/// </summary>
|
||||
public enum LoadOp
|
||||
{
|
||||
Load,
|
||||
Clear,
|
||||
DontCare
|
||||
}
|
||||
/// <summary>
|
||||
/// Describes the operation that a render pass will use when loading a render target.
|
||||
/// </summary>
|
||||
public enum LoadOp
|
||||
{
|
||||
Load,
|
||||
Clear,
|
||||
DontCare
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Describes the operation that a render pass will use when storing a render target.
|
||||
/// </summary>
|
||||
public enum StoreOp
|
||||
{
|
||||
Store,
|
||||
DontCare
|
||||
}
|
||||
/// <summary>
|
||||
/// Describes the operation that a render pass will use when storing a render target.
|
||||
/// </summary>
|
||||
public enum StoreOp
|
||||
{
|
||||
Store,
|
||||
DontCare
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum ClearOptionsFlags : uint
|
||||
{
|
||||
Color = 1,
|
||||
Depth = 2,
|
||||
Stencil = 4,
|
||||
DepthStencil = Depth | Stencil,
|
||||
All = Color | Depth | Stencil
|
||||
}
|
||||
[Flags]
|
||||
public enum ClearOptionsFlags : uint
|
||||
{
|
||||
Color = 1,
|
||||
Depth = 2,
|
||||
Stencil = 4,
|
||||
DepthStencil = Depth | Stencil,
|
||||
All = Color | Depth | Stencil
|
||||
}
|
||||
|
||||
public enum IndexElementSize
|
||||
{
|
||||
Sixteen,
|
||||
ThirtyTwo
|
||||
}
|
||||
public enum IndexElementSize
|
||||
{
|
||||
Sixteen,
|
||||
ThirtyTwo
|
||||
}
|
||||
|
||||
public enum TextureFormat
|
||||
{
|
||||
R8G8B8A8,
|
||||
R5G6B5,
|
||||
A1R5G5B5,
|
||||
B4G4R4A4,
|
||||
BC1,
|
||||
BC2,
|
||||
BC3,
|
||||
R8G8_SNORM,
|
||||
R8G8B8A8_SNORM,
|
||||
A2R10G10B10,
|
||||
R16G16,
|
||||
R16G16B16A16,
|
||||
R8,
|
||||
R32_SFLOAT,
|
||||
R32G32_SFLOAT,
|
||||
R32G32B32A32_SFLOAT,
|
||||
R16_SFLOAT,
|
||||
R16G16_SFLOAT,
|
||||
R16G16B16A16_SFLOAT,
|
||||
D16,
|
||||
D32,
|
||||
D16S8,
|
||||
D32S8
|
||||
}
|
||||
public enum TextureFormat
|
||||
{
|
||||
R8G8B8A8,
|
||||
R5G6B5,
|
||||
A1R5G5B5,
|
||||
B4G4R4A4,
|
||||
BC1,
|
||||
BC2,
|
||||
BC3,
|
||||
R8G8_SNORM,
|
||||
R8G8B8A8_SNORM,
|
||||
A2R10G10B10,
|
||||
R16G16,
|
||||
R16G16B16A16,
|
||||
R8,
|
||||
R32_SFLOAT,
|
||||
R32G32_SFLOAT,
|
||||
R32G32B32A32_SFLOAT,
|
||||
R16_SFLOAT,
|
||||
R16G16_SFLOAT,
|
||||
R16G16B16A16_SFLOAT,
|
||||
D16,
|
||||
D32,
|
||||
D16S8,
|
||||
D32S8
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum TextureUsageFlags : uint
|
||||
{
|
||||
Sampler = 1,
|
||||
ColorTarget = 2,
|
||||
DepthStencilTarget = 4
|
||||
}
|
||||
[Flags]
|
||||
public enum TextureUsageFlags : uint
|
||||
{
|
||||
Sampler = 1,
|
||||
ColorTarget = 2,
|
||||
DepthStencilTarget = 4
|
||||
}
|
||||
|
||||
public enum SampleCount
|
||||
{
|
||||
One,
|
||||
Two,
|
||||
Four,
|
||||
Eight,
|
||||
Sixteen,
|
||||
ThirtyTwo,
|
||||
SixtyFour
|
||||
}
|
||||
public enum SampleCount
|
||||
{
|
||||
One,
|
||||
Two,
|
||||
Four,
|
||||
Eight,
|
||||
Sixteen,
|
||||
ThirtyTwo,
|
||||
SixtyFour
|
||||
}
|
||||
|
||||
public enum CubeMapFace : uint
|
||||
{
|
||||
PositiveX,
|
||||
NegativeX,
|
||||
PositiveY,
|
||||
NegativeY,
|
||||
PositiveZ,
|
||||
NegativeZ
|
||||
}
|
||||
public enum CubeMapFace : uint
|
||||
{
|
||||
PositiveX,
|
||||
NegativeX,
|
||||
PositiveY,
|
||||
NegativeY,
|
||||
PositiveZ,
|
||||
NegativeZ
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum BufferUsageFlags : uint
|
||||
{
|
||||
Vertex = 1,
|
||||
Index = 2,
|
||||
Compute = 4
|
||||
}
|
||||
[Flags]
|
||||
public enum BufferUsageFlags : uint
|
||||
{
|
||||
Vertex = 1,
|
||||
Index = 2,
|
||||
Compute = 4
|
||||
}
|
||||
|
||||
public enum VertexElementFormat
|
||||
{
|
||||
Single,
|
||||
Vector2,
|
||||
Vector3,
|
||||
Vector4,
|
||||
Color,
|
||||
Byte4,
|
||||
Short2,
|
||||
Short4,
|
||||
NormalizedShort2,
|
||||
NormalizedShort4,
|
||||
HalfVector2,
|
||||
HalfVector4
|
||||
}
|
||||
public enum VertexElementFormat
|
||||
{
|
||||
Single,
|
||||
Vector2,
|
||||
Vector3,
|
||||
Vector4,
|
||||
Color,
|
||||
Byte4,
|
||||
Short2,
|
||||
Short4,
|
||||
NormalizedShort2,
|
||||
NormalizedShort4,
|
||||
HalfVector2,
|
||||
HalfVector4
|
||||
}
|
||||
|
||||
public enum VertexInputRate
|
||||
{
|
||||
Vertex,
|
||||
Instance
|
||||
}
|
||||
public enum VertexInputRate
|
||||
{
|
||||
Vertex,
|
||||
Instance
|
||||
}
|
||||
|
||||
public enum FillMode
|
||||
{
|
||||
Fill,
|
||||
Line,
|
||||
Point
|
||||
}
|
||||
public enum FillMode
|
||||
{
|
||||
Fill,
|
||||
Line,
|
||||
Point
|
||||
}
|
||||
|
||||
public enum CullMode
|
||||
{
|
||||
None,
|
||||
Front,
|
||||
Back,
|
||||
FrontAndBack
|
||||
}
|
||||
public enum CullMode
|
||||
{
|
||||
None,
|
||||
Front,
|
||||
Back,
|
||||
FrontAndBack
|
||||
}
|
||||
|
||||
public enum FrontFace
|
||||
{
|
||||
CounterClockwise,
|
||||
Clockwise
|
||||
}
|
||||
public enum FrontFace
|
||||
{
|
||||
CounterClockwise,
|
||||
Clockwise
|
||||
}
|
||||
|
||||
public enum CompareOp
|
||||
{
|
||||
Never,
|
||||
Less,
|
||||
Equal,
|
||||
LessOrEqual,
|
||||
Greater,
|
||||
NotEqual,
|
||||
GreaterOrEqual,
|
||||
Always
|
||||
}
|
||||
public enum CompareOp
|
||||
{
|
||||
Never,
|
||||
Less,
|
||||
Equal,
|
||||
LessOrEqual,
|
||||
Greater,
|
||||
NotEqual,
|
||||
GreaterOrEqual,
|
||||
Always
|
||||
}
|
||||
|
||||
public enum StencilOp
|
||||
{
|
||||
Keep,
|
||||
Zero,
|
||||
Replace,
|
||||
IncrementAndClamp,
|
||||
DecrementAndClamp,
|
||||
Invert,
|
||||
IncrementAndWrap,
|
||||
DecrementAndWrap
|
||||
}
|
||||
public enum StencilOp
|
||||
{
|
||||
Keep,
|
||||
Zero,
|
||||
Replace,
|
||||
IncrementAndClamp,
|
||||
DecrementAndClamp,
|
||||
Invert,
|
||||
IncrementAndWrap,
|
||||
DecrementAndWrap
|
||||
}
|
||||
|
||||
public enum BlendOp
|
||||
{
|
||||
Add,
|
||||
Subtract,
|
||||
ReverseSubtract,
|
||||
Min,
|
||||
Max
|
||||
}
|
||||
public enum BlendOp
|
||||
{
|
||||
Add,
|
||||
Subtract,
|
||||
ReverseSubtract,
|
||||
Min,
|
||||
Max
|
||||
}
|
||||
|
||||
public enum LogicOp
|
||||
{
|
||||
Clear,
|
||||
And,
|
||||
AndReverse,
|
||||
Copy,
|
||||
AndInverted,
|
||||
NoOp,
|
||||
Xor,
|
||||
Or,
|
||||
Nor,
|
||||
Equivalent,
|
||||
Invert,
|
||||
OrReverse,
|
||||
CopyInverted,
|
||||
OrInverted,
|
||||
Nand,
|
||||
Set
|
||||
}
|
||||
public enum LogicOp
|
||||
{
|
||||
Clear,
|
||||
And,
|
||||
AndReverse,
|
||||
Copy,
|
||||
AndInverted,
|
||||
NoOp,
|
||||
Xor,
|
||||
Or,
|
||||
Nor,
|
||||
Equivalent,
|
||||
Invert,
|
||||
OrReverse,
|
||||
CopyInverted,
|
||||
OrInverted,
|
||||
Nand,
|
||||
Set
|
||||
}
|
||||
|
||||
public enum BlendFactor
|
||||
{
|
||||
Zero,
|
||||
One,
|
||||
SourceColor,
|
||||
OneMinusSourceColor,
|
||||
DestinationColor,
|
||||
OneMinusDestinationColor,
|
||||
SourceAlpha,
|
||||
OneMinusSourceAlpha,
|
||||
DestinationAlpha,
|
||||
OneMinusDestinationAlpha,
|
||||
ConstantColor,
|
||||
OneMinusConstantColor,
|
||||
ConstantAlpha,
|
||||
OneMinusConstantAlpha,
|
||||
SourceAlphaSaturate,
|
||||
SourceOneColor,
|
||||
OneMinusSourceOneColor,
|
||||
SourceOneAlpha,
|
||||
OneMinusSourceOneAlpha
|
||||
}
|
||||
public enum BlendFactor
|
||||
{
|
||||
Zero,
|
||||
One,
|
||||
SourceColor,
|
||||
OneMinusSourceColor,
|
||||
DestinationColor,
|
||||
OneMinusDestinationColor,
|
||||
SourceAlpha,
|
||||
OneMinusSourceAlpha,
|
||||
DestinationAlpha,
|
||||
OneMinusDestinationAlpha,
|
||||
ConstantColor,
|
||||
OneMinusConstantColor,
|
||||
ConstantAlpha,
|
||||
OneMinusConstantAlpha,
|
||||
SourceAlphaSaturate,
|
||||
SourceOneColor,
|
||||
OneMinusSourceOneColor,
|
||||
SourceOneAlpha,
|
||||
OneMinusSourceOneAlpha
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum ColorComponentFlags : uint
|
||||
{
|
||||
R = 1,
|
||||
G = 2,
|
||||
B = 4,
|
||||
A = 8,
|
||||
[Flags]
|
||||
public enum ColorComponentFlags : uint
|
||||
{
|
||||
R = 1,
|
||||
G = 2,
|
||||
B = 4,
|
||||
A = 8,
|
||||
|
||||
RG = R | G,
|
||||
RB = R | B,
|
||||
RA = R | A,
|
||||
GB = G | B,
|
||||
GA = G | A,
|
||||
BA = B | A,
|
||||
RG = R | G,
|
||||
RB = R | B,
|
||||
RA = R | A,
|
||||
GB = G | B,
|
||||
GA = G | A,
|
||||
BA = B | A,
|
||||
|
||||
RGB = R | G | B,
|
||||
RGA = R | G | A,
|
||||
GBA = G | B | A,
|
||||
RGB = R | G | B,
|
||||
RGA = R | G | A,
|
||||
GBA = G | B | A,
|
||||
|
||||
RGBA = R | G | B | A,
|
||||
None = 0
|
||||
}
|
||||
RGBA = R | G | B | A,
|
||||
None = 0
|
||||
}
|
||||
|
||||
public enum ShaderStageType
|
||||
{
|
||||
Vertex,
|
||||
Fragment
|
||||
}
|
||||
public enum ShaderStageType
|
||||
{
|
||||
Vertex,
|
||||
Fragment
|
||||
}
|
||||
|
||||
public enum Filter
|
||||
{
|
||||
Nearest,
|
||||
Linear,
|
||||
Cubic
|
||||
}
|
||||
public enum Filter
|
||||
{
|
||||
Nearest,
|
||||
Linear,
|
||||
Cubic
|
||||
}
|
||||
|
||||
public enum SamplerMipmapMode
|
||||
{
|
||||
Nearest,
|
||||
Linear
|
||||
}
|
||||
public enum SamplerMipmapMode
|
||||
{
|
||||
Nearest,
|
||||
Linear
|
||||
}
|
||||
|
||||
public enum SamplerAddressMode
|
||||
{
|
||||
Repeat,
|
||||
MirroredRepeat,
|
||||
ClampToEdge,
|
||||
ClampToBorder
|
||||
}
|
||||
public enum SamplerAddressMode
|
||||
{
|
||||
Repeat,
|
||||
MirroredRepeat,
|
||||
ClampToEdge,
|
||||
ClampToBorder
|
||||
}
|
||||
|
||||
public enum BorderColor
|
||||
{
|
||||
FloatTransparentBlack,
|
||||
IntTransparentBlack,
|
||||
FloatOpaqueBlack,
|
||||
IntOpaqueBlack,
|
||||
FloatOpaqueWhite,
|
||||
IntOpaqueWhite
|
||||
}
|
||||
public enum BorderColor
|
||||
{
|
||||
FloatTransparentBlack,
|
||||
IntTransparentBlack,
|
||||
FloatOpaqueBlack,
|
||||
IntOpaqueBlack,
|
||||
FloatOpaqueWhite,
|
||||
IntOpaqueWhite
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,115 +6,115 @@ using System.Runtime.InteropServices;
|
|||
*/
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct DepthStencilValue
|
||||
{
|
||||
public float Depth;
|
||||
public uint Stencil;
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct DepthStencilValue
|
||||
{
|
||||
public float Depth;
|
||||
public uint Stencil;
|
||||
|
||||
// FIXME: can we do an unsafe cast somehow?
|
||||
public Refresh.DepthStencilValue ToRefresh()
|
||||
{
|
||||
return new Refresh.DepthStencilValue
|
||||
{
|
||||
depth = Depth,
|
||||
stencil = Stencil
|
||||
};
|
||||
}
|
||||
}
|
||||
// FIXME: can we do an unsafe cast somehow?
|
||||
public Refresh.DepthStencilValue ToRefresh()
|
||||
{
|
||||
return new Refresh.DepthStencilValue
|
||||
{
|
||||
depth = Depth,
|
||||
stencil = Stencil
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Rect
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
public int W;
|
||||
public int H;
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Rect
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
public int W;
|
||||
public int H;
|
||||
|
||||
// FIXME: can we do an unsafe cast somehow?
|
||||
public Refresh.Rect ToRefresh()
|
||||
{
|
||||
return new Refresh.Rect
|
||||
{
|
||||
x = X,
|
||||
y = Y,
|
||||
w = W,
|
||||
h = H
|
||||
};
|
||||
}
|
||||
}
|
||||
// FIXME: can we do an unsafe cast somehow?
|
||||
public Refresh.Rect ToRefresh()
|
||||
{
|
||||
return new Refresh.Rect
|
||||
{
|
||||
x = X,
|
||||
y = Y,
|
||||
w = W,
|
||||
h = H
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Viewport
|
||||
{
|
||||
public float X;
|
||||
public float Y;
|
||||
public float W;
|
||||
public float H;
|
||||
public float MinDepth;
|
||||
public float MaxDepth;
|
||||
}
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Viewport
|
||||
{
|
||||
public float X;
|
||||
public float Y;
|
||||
public float W;
|
||||
public float H;
|
||||
public float MinDepth;
|
||||
public float MaxDepth;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct VertexBinding
|
||||
{
|
||||
public uint Binding;
|
||||
public uint Stride;
|
||||
public VertexInputRate InputRate;
|
||||
}
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct VertexBinding
|
||||
{
|
||||
public uint Binding;
|
||||
public uint Stride;
|
||||
public VertexInputRate InputRate;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct VertexAttribute
|
||||
{
|
||||
public uint Location;
|
||||
public uint Binding;
|
||||
public VertexElementFormat Format;
|
||||
public uint Offset;
|
||||
}
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct VertexAttribute
|
||||
{
|
||||
public uint Location;
|
||||
public uint Binding;
|
||||
public VertexElementFormat Format;
|
||||
public uint Offset;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct ColorTargetDescription
|
||||
{
|
||||
public TextureFormat Format;
|
||||
public SampleCount MultisampleCount;
|
||||
public LoadOp LoadOp;
|
||||
public StoreOp StoreOp;
|
||||
}
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct ColorTargetDescription
|
||||
{
|
||||
public TextureFormat Format;
|
||||
public SampleCount MultisampleCount;
|
||||
public LoadOp LoadOp;
|
||||
public StoreOp StoreOp;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct DepthStencilTargetDescription
|
||||
{
|
||||
public TextureFormat Format;
|
||||
public LoadOp LoadOp;
|
||||
public StoreOp StoreOp;
|
||||
public LoadOp StencilLoadOp;
|
||||
public StoreOp StencilStoreOp;
|
||||
}
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct DepthStencilTargetDescription
|
||||
{
|
||||
public TextureFormat Format;
|
||||
public LoadOp LoadOp;
|
||||
public StoreOp StoreOp;
|
||||
public LoadOp StencilLoadOp;
|
||||
public StoreOp StencilStoreOp;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct StencilOpState
|
||||
{
|
||||
public StencilOp FailOp;
|
||||
public StencilOp PassOp;
|
||||
public StencilOp DepthFailOp;
|
||||
public CompareOp CompareOp;
|
||||
public uint CompareMask;
|
||||
public uint WriteMask;
|
||||
public uint Reference;
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct StencilOpState
|
||||
{
|
||||
public StencilOp FailOp;
|
||||
public StencilOp PassOp;
|
||||
public StencilOp DepthFailOp;
|
||||
public CompareOp CompareOp;
|
||||
public uint CompareMask;
|
||||
public uint WriteMask;
|
||||
public uint Reference;
|
||||
|
||||
// FIXME: can we do an explicit cast here?
|
||||
public Refresh.StencilOpState ToRefresh()
|
||||
{
|
||||
return new Refresh.StencilOpState
|
||||
{
|
||||
failOp = (Refresh.StencilOp)FailOp,
|
||||
passOp = (Refresh.StencilOp)PassOp,
|
||||
depthFailOp = (Refresh.StencilOp)DepthFailOp,
|
||||
compareOp = (Refresh.CompareOp)CompareOp,
|
||||
compareMask = CompareMask,
|
||||
writeMask = WriteMask,
|
||||
reference = Reference
|
||||
};
|
||||
}
|
||||
}
|
||||
// FIXME: can we do an explicit cast here?
|
||||
public Refresh.StencilOpState ToRefresh()
|
||||
{
|
||||
return new Refresh.StencilOpState
|
||||
{
|
||||
failOp = (Refresh.StencilOp) FailOp,
|
||||
passOp = (Refresh.StencilOp) PassOp,
|
||||
depthFailOp = (Refresh.StencilOp) DepthFailOp,
|
||||
compareOp = (Refresh.CompareOp) CompareOp,
|
||||
compareMask = CompareMask,
|
||||
writeMask = WriteMask,
|
||||
reference = Reference
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,55 +1,55 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using RefreshCS;
|
||||
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Buffers are generic data containers that can be used by the GPU.
|
||||
/// </summary>
|
||||
public class Buffer : GraphicsResource
|
||||
{
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyBuffer;
|
||||
/// <summary>
|
||||
/// Buffers are generic data containers that can be used by the GPU.
|
||||
/// </summary>
|
||||
public class Buffer : GraphicsResource
|
||||
{
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyBuffer;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a buffer.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="usageFlags">Specifies how the buffer will be used.</param>
|
||||
/// <param name="sizeInBytes">The length of the array. Cannot be resized.</param>
|
||||
public Buffer(
|
||||
GraphicsDevice device,
|
||||
BufferUsageFlags usageFlags,
|
||||
uint sizeInBytes
|
||||
) : base(device)
|
||||
{
|
||||
Handle = Refresh.Refresh_CreateBuffer(
|
||||
device.Handle,
|
||||
(Refresh.BufferUsageFlags) usageFlags,
|
||||
sizeInBytes
|
||||
);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a buffer.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="usageFlags">Specifies how the buffer will be used.</param>
|
||||
/// <param name="sizeInBytes">The length of the array. Cannot be resized.</param>
|
||||
public Buffer(
|
||||
GraphicsDevice device,
|
||||
BufferUsageFlags usageFlags,
|
||||
uint sizeInBytes
|
||||
) : base(device)
|
||||
{
|
||||
Handle = Refresh.Refresh_CreateBuffer(
|
||||
device.Handle,
|
||||
(Refresh.BufferUsageFlags) usageFlags,
|
||||
sizeInBytes
|
||||
);
|
||||
}
|
||||
|
||||
/// <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.
|
||||
/// </summary>
|
||||
/// <param name="data">The array that data will be copied to.</param>
|
||||
/// <param name="dataLengthInBytes">The length of the data to read.</param>
|
||||
public unsafe void GetData<T>(
|
||||
T[] data,
|
||||
uint dataLengthInBytes
|
||||
) where T : unmanaged
|
||||
{
|
||||
fixed (T* ptr = &data[0])
|
||||
{
|
||||
Refresh.Refresh_GetBufferData(
|
||||
Device.Handle,
|
||||
Handle,
|
||||
(IntPtr)ptr,
|
||||
dataLengthInBytes
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <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.
|
||||
/// </summary>
|
||||
/// <param name="data">The array that data will be copied to.</param>
|
||||
/// <param name="dataLengthInBytes">The length of the data to read.</param>
|
||||
public unsafe void GetData<T>(
|
||||
T[] data,
|
||||
uint dataLengthInBytes
|
||||
) where T : unmanaged
|
||||
{
|
||||
fixed (T* ptr = &data[0])
|
||||
{
|
||||
Refresh.Refresh_GetBufferData(
|
||||
Device.Handle,
|
||||
Handle,
|
||||
(IntPtr) ptr,
|
||||
dataLengthInBytes
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,41 +4,42 @@ using System.Runtime.InteropServices;
|
|||
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
public class ComputePipeline : GraphicsResource
|
||||
{
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyComputePipeline;
|
||||
public class ComputePipeline : GraphicsResource
|
||||
{
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyComputePipeline;
|
||||
|
||||
public ShaderStageState ComputeShaderState { get; }
|
||||
public ShaderStageState ComputeShaderState { get; }
|
||||
|
||||
public unsafe ComputePipeline(
|
||||
GraphicsDevice device,
|
||||
ShaderStageState computeShaderState,
|
||||
uint bufferBindingCount,
|
||||
uint imageBindingCount
|
||||
) : base(device) {
|
||||
var computePipelineLayoutCreateInfo = new Refresh.ComputePipelineLayoutCreateInfo
|
||||
{
|
||||
bufferBindingCount = bufferBindingCount,
|
||||
imageBindingCount = imageBindingCount
|
||||
};
|
||||
public unsafe ComputePipeline(
|
||||
GraphicsDevice device,
|
||||
ShaderStageState computeShaderState,
|
||||
uint bufferBindingCount,
|
||||
uint imageBindingCount
|
||||
) : base(device)
|
||||
{
|
||||
var computePipelineLayoutCreateInfo = new Refresh.ComputePipelineLayoutCreateInfo
|
||||
{
|
||||
bufferBindingCount = bufferBindingCount,
|
||||
imageBindingCount = imageBindingCount
|
||||
};
|
||||
|
||||
var computePipelineCreateInfo = new Refresh.ComputePipelineCreateInfo
|
||||
{
|
||||
pipelineLayoutCreateInfo = computePipelineLayoutCreateInfo,
|
||||
computeShaderState = new Refresh.ShaderStageState
|
||||
{
|
||||
entryPointName = computeShaderState.EntryPointName,
|
||||
shaderModule = computeShaderState.ShaderModule.Handle,
|
||||
uniformBufferSize = computeShaderState.UniformBufferSize
|
||||
}
|
||||
};
|
||||
var computePipelineCreateInfo = new Refresh.ComputePipelineCreateInfo
|
||||
{
|
||||
pipelineLayoutCreateInfo = computePipelineLayoutCreateInfo,
|
||||
computeShaderState = new Refresh.ShaderStageState
|
||||
{
|
||||
entryPointName = computeShaderState.EntryPointName,
|
||||
shaderModule = computeShaderState.ShaderModule.Handle,
|
||||
uniformBufferSize = computeShaderState.UniformBufferSize
|
||||
}
|
||||
};
|
||||
|
||||
Handle = Refresh.Refresh_CreateComputePipeline(
|
||||
device.Handle,
|
||||
computePipelineCreateInfo
|
||||
);
|
||||
Handle = Refresh.Refresh_CreateComputePipeline(
|
||||
device.Handle,
|
||||
computePipelineCreateInfo
|
||||
);
|
||||
|
||||
ComputeShaderState = computeShaderState;
|
||||
}
|
||||
}
|
||||
ComputeShaderState = computeShaderState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,81 +1,81 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RefreshCS;
|
||||
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// A framebuffer is a collection of render targets that is rendered to during a render pass.
|
||||
/// </summary>
|
||||
public class Framebuffer : GraphicsResource
|
||||
{
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyFramebuffer;
|
||||
/// <summary>
|
||||
/// A framebuffer is a collection of render targets that is rendered to during a render pass.
|
||||
/// </summary>
|
||||
public class Framebuffer : GraphicsResource
|
||||
{
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyFramebuffer;
|
||||
|
||||
public RenderTarget DepthStencilTarget { get; }
|
||||
public RenderTarget DepthStencilTarget { get; }
|
||||
|
||||
private RenderTarget[] colorTargets { get; }
|
||||
public IEnumerable<RenderTarget> ColorTargets => colorTargets;
|
||||
private RenderTarget[] colorTargets { get; }
|
||||
public IEnumerable<RenderTarget> ColorTargets => colorTargets;
|
||||
|
||||
public RenderPass RenderPass { get; }
|
||||
public RenderPass RenderPass { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a framebuffer.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="width">The width of the framebuffer.</param>
|
||||
/// <param name="height">The height of the framebuffer.</param>
|
||||
/// <param name="renderPass">The reference render pass for the framebuffer.</param>
|
||||
/// <param name="depthStencilTarget">The depth stencil target. Can be null.</param>
|
||||
/// <param name="colorTargets">Anywhere from 0-4 color targets can be provided.</param>
|
||||
public unsafe Framebuffer(
|
||||
GraphicsDevice device,
|
||||
uint width,
|
||||
uint height,
|
||||
RenderPass renderPass,
|
||||
RenderTarget depthStencilTarget,
|
||||
params RenderTarget[] colorTargets
|
||||
) : base(device)
|
||||
{
|
||||
IntPtr[] colorTargetHandles = new IntPtr[colorTargets.Length];
|
||||
for (var i = 0; i < colorTargets.Length; i += 1)
|
||||
{
|
||||
colorTargetHandles[i] = colorTargets[i].Handle;
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a framebuffer.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="width">The width of the framebuffer.</param>
|
||||
/// <param name="height">The height of the framebuffer.</param>
|
||||
/// <param name="renderPass">The reference render pass for the framebuffer.</param>
|
||||
/// <param name="depthStencilTarget">The depth stencil target. Can be null.</param>
|
||||
/// <param name="colorTargets">Anywhere from 0-4 color targets can be provided.</param>
|
||||
public unsafe Framebuffer(
|
||||
GraphicsDevice device,
|
||||
uint width,
|
||||
uint height,
|
||||
RenderPass renderPass,
|
||||
RenderTarget depthStencilTarget,
|
||||
params RenderTarget[] colorTargets
|
||||
) : base(device)
|
||||
{
|
||||
IntPtr[] colorTargetHandles = new IntPtr[colorTargets.Length];
|
||||
for (var i = 0; i < colorTargets.Length; i += 1)
|
||||
{
|
||||
colorTargetHandles[i] = colorTargets[i].Handle;
|
||||
}
|
||||
|
||||
IntPtr depthStencilTargetHandle;
|
||||
if (depthStencilTarget == null)
|
||||
{
|
||||
depthStencilTargetHandle = IntPtr.Zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
depthStencilTargetHandle = depthStencilTarget.Handle;
|
||||
}
|
||||
IntPtr depthStencilTargetHandle;
|
||||
if (depthStencilTarget == null)
|
||||
{
|
||||
depthStencilTargetHandle = IntPtr.Zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
depthStencilTargetHandle = depthStencilTarget.Handle;
|
||||
}
|
||||
|
||||
fixed (IntPtr* colorTargetHandlesPtr = colorTargetHandles)
|
||||
{
|
||||
Refresh.FramebufferCreateInfo framebufferCreateInfo = new Refresh.FramebufferCreateInfo
|
||||
{
|
||||
width = width,
|
||||
height = height,
|
||||
colorTargetCount = (uint) colorTargets.Length,
|
||||
pColorTargets = (IntPtr) colorTargetHandlesPtr,
|
||||
depthStencilTarget = depthStencilTargetHandle,
|
||||
renderPass = renderPass.Handle
|
||||
};
|
||||
fixed (IntPtr* colorTargetHandlesPtr = colorTargetHandles)
|
||||
{
|
||||
Refresh.FramebufferCreateInfo framebufferCreateInfo = new Refresh.FramebufferCreateInfo
|
||||
{
|
||||
width = width,
|
||||
height = height,
|
||||
colorTargetCount = (uint) colorTargets.Length,
|
||||
pColorTargets = (IntPtr) colorTargetHandlesPtr,
|
||||
depthStencilTarget = depthStencilTargetHandle,
|
||||
renderPass = renderPass.Handle
|
||||
};
|
||||
|
||||
Handle = Refresh.Refresh_CreateFramebuffer(device.Handle, framebufferCreateInfo);
|
||||
}
|
||||
Handle = Refresh.Refresh_CreateFramebuffer(device.Handle, framebufferCreateInfo);
|
||||
}
|
||||
|
||||
DepthStencilTarget = depthStencilTarget;
|
||||
DepthStencilTarget = depthStencilTarget;
|
||||
|
||||
this.colorTargets = new RenderTarget[colorTargets.Length];
|
||||
for (var i = 0; i < colorTargets.Length; i++)
|
||||
{
|
||||
this.colorTargets[i] = colorTargets[i];
|
||||
}
|
||||
this.colorTargets = new RenderTarget[colorTargets.Length];
|
||||
for (var i = 0; i < colorTargets.Length; i++)
|
||||
{
|
||||
this.colorTargets[i] = colorTargets[i];
|
||||
}
|
||||
|
||||
RenderPass = renderPass;
|
||||
}
|
||||
}
|
||||
RenderPass = renderPass;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,132 +1,132 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using RefreshCS;
|
||||
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Graphics pipelines encapsulate all of the render state in a single object.
|
||||
/// These pipelines are bound before draw calls are issued.
|
||||
/// </summary>
|
||||
public class GraphicsPipeline : GraphicsResource
|
||||
{
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyGraphicsPipeline;
|
||||
/// <summary>
|
||||
/// Graphics pipelines encapsulate all of the render state in a single object.
|
||||
/// These pipelines are bound before draw calls are issued.
|
||||
/// </summary>
|
||||
public class GraphicsPipeline : GraphicsResource
|
||||
{
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyGraphicsPipeline;
|
||||
|
||||
public ShaderStageState VertexShaderState { get; }
|
||||
public ShaderStageState FragmentShaderState { get; }
|
||||
public RenderPass RenderPass { get; }
|
||||
public ShaderStageState VertexShaderState { get; }
|
||||
public ShaderStageState FragmentShaderState { get; }
|
||||
public RenderPass RenderPass { get; }
|
||||
|
||||
public unsafe GraphicsPipeline(
|
||||
GraphicsDevice device,
|
||||
in GraphicsPipelineCreateInfo graphicsPipelineCreateInfo
|
||||
) : base(device)
|
||||
{
|
||||
ColorBlendState colorBlendState = graphicsPipelineCreateInfo.ColorBlendState;
|
||||
DepthStencilState depthStencilState = graphicsPipelineCreateInfo.DepthStencilState;
|
||||
ShaderStageState vertexShaderState = graphicsPipelineCreateInfo.VertexShaderState;
|
||||
ShaderStageState fragmentShaderState = graphicsPipelineCreateInfo.FragmentShaderState;
|
||||
MultisampleState multisampleState = graphicsPipelineCreateInfo.MultisampleState;
|
||||
GraphicsPipelineLayoutInfo pipelineLayoutInfo = graphicsPipelineCreateInfo.PipelineLayoutInfo;
|
||||
RasterizerState rasterizerState = graphicsPipelineCreateInfo.RasterizerState;
|
||||
PrimitiveType primitiveType = graphicsPipelineCreateInfo.PrimitiveType;
|
||||
VertexInputState vertexInputState = graphicsPipelineCreateInfo.VertexInputState;
|
||||
ViewportState viewportState = graphicsPipelineCreateInfo.ViewportState;
|
||||
RenderPass renderPass = graphicsPipelineCreateInfo.RenderPass;
|
||||
public unsafe GraphicsPipeline(
|
||||
GraphicsDevice device,
|
||||
in GraphicsPipelineCreateInfo graphicsPipelineCreateInfo
|
||||
) : base(device)
|
||||
{
|
||||
ColorBlendState colorBlendState = graphicsPipelineCreateInfo.ColorBlendState;
|
||||
DepthStencilState depthStencilState = graphicsPipelineCreateInfo.DepthStencilState;
|
||||
ShaderStageState vertexShaderState = graphicsPipelineCreateInfo.VertexShaderState;
|
||||
ShaderStageState fragmentShaderState = graphicsPipelineCreateInfo.FragmentShaderState;
|
||||
MultisampleState multisampleState = graphicsPipelineCreateInfo.MultisampleState;
|
||||
GraphicsPipelineLayoutInfo pipelineLayoutInfo = graphicsPipelineCreateInfo.PipelineLayoutInfo;
|
||||
RasterizerState rasterizerState = graphicsPipelineCreateInfo.RasterizerState;
|
||||
PrimitiveType primitiveType = graphicsPipelineCreateInfo.PrimitiveType;
|
||||
VertexInputState vertexInputState = graphicsPipelineCreateInfo.VertexInputState;
|
||||
ViewportState viewportState = graphicsPipelineCreateInfo.ViewportState;
|
||||
RenderPass renderPass = graphicsPipelineCreateInfo.RenderPass;
|
||||
|
||||
var vertexAttributesHandle = GCHandle.Alloc(
|
||||
vertexInputState.VertexAttributes,
|
||||
GCHandleType.Pinned
|
||||
);
|
||||
var vertexBindingsHandle = GCHandle.Alloc(
|
||||
vertexInputState.VertexBindings,
|
||||
GCHandleType.Pinned
|
||||
);
|
||||
var viewportHandle = GCHandle.Alloc(
|
||||
viewportState.Viewports,
|
||||
GCHandleType.Pinned
|
||||
);
|
||||
var scissorHandle = GCHandle.Alloc(
|
||||
viewportState.Scissors,
|
||||
GCHandleType.Pinned
|
||||
);
|
||||
var vertexAttributesHandle = GCHandle.Alloc(
|
||||
vertexInputState.VertexAttributes,
|
||||
GCHandleType.Pinned
|
||||
);
|
||||
var vertexBindingsHandle = GCHandle.Alloc(
|
||||
vertexInputState.VertexBindings,
|
||||
GCHandleType.Pinned
|
||||
);
|
||||
var viewportHandle = GCHandle.Alloc(
|
||||
viewportState.Viewports,
|
||||
GCHandleType.Pinned
|
||||
);
|
||||
var scissorHandle = GCHandle.Alloc(
|
||||
viewportState.Scissors,
|
||||
GCHandleType.Pinned
|
||||
);
|
||||
|
||||
var colorTargetBlendStates = stackalloc Refresh.ColorTargetBlendState[
|
||||
colorBlendState.ColorTargetBlendStates.Length
|
||||
];
|
||||
var colorTargetBlendStates = stackalloc Refresh.ColorTargetBlendState[
|
||||
colorBlendState.ColorTargetBlendStates.Length
|
||||
];
|
||||
|
||||
for (var i = 0; i < colorBlendState.ColorTargetBlendStates.Length; i += 1)
|
||||
{
|
||||
colorTargetBlendStates[i] = colorBlendState.ColorTargetBlendStates[i].ToRefreshColorTargetBlendState();
|
||||
}
|
||||
for (var i = 0; i < colorBlendState.ColorTargetBlendStates.Length; i += 1)
|
||||
{
|
||||
colorTargetBlendStates[i] = colorBlendState.ColorTargetBlendStates[i].ToRefreshColorTargetBlendState();
|
||||
}
|
||||
|
||||
Refresh.GraphicsPipelineCreateInfo refreshGraphicsPipelineCreateInfo;
|
||||
Refresh.GraphicsPipelineCreateInfo refreshGraphicsPipelineCreateInfo;
|
||||
|
||||
refreshGraphicsPipelineCreateInfo.colorBlendState.logicOpEnable = Conversions.BoolToByte(colorBlendState.LogicOpEnable);
|
||||
refreshGraphicsPipelineCreateInfo.colorBlendState.logicOp = (Refresh.LogicOp) colorBlendState.LogicOp;
|
||||
refreshGraphicsPipelineCreateInfo.colorBlendState.blendStates = (IntPtr) colorTargetBlendStates;
|
||||
refreshGraphicsPipelineCreateInfo.colorBlendState.blendStateCount = (uint) colorBlendState.ColorTargetBlendStates.Length;
|
||||
refreshGraphicsPipelineCreateInfo.colorBlendState.blendConstants[0] = colorBlendState.BlendConstants.R;
|
||||
refreshGraphicsPipelineCreateInfo.colorBlendState.blendConstants[1] = colorBlendState.BlendConstants.G;
|
||||
refreshGraphicsPipelineCreateInfo.colorBlendState.blendConstants[2] = colorBlendState.BlendConstants.B;
|
||||
refreshGraphicsPipelineCreateInfo.colorBlendState.blendConstants[3] = colorBlendState.BlendConstants.A;
|
||||
refreshGraphicsPipelineCreateInfo.colorBlendState.logicOpEnable = Conversions.BoolToByte(colorBlendState.LogicOpEnable);
|
||||
refreshGraphicsPipelineCreateInfo.colorBlendState.logicOp = (Refresh.LogicOp) colorBlendState.LogicOp;
|
||||
refreshGraphicsPipelineCreateInfo.colorBlendState.blendStates = (IntPtr) colorTargetBlendStates;
|
||||
refreshGraphicsPipelineCreateInfo.colorBlendState.blendStateCount = (uint) colorBlendState.ColorTargetBlendStates.Length;
|
||||
refreshGraphicsPipelineCreateInfo.colorBlendState.blendConstants[0] = colorBlendState.BlendConstants.R;
|
||||
refreshGraphicsPipelineCreateInfo.colorBlendState.blendConstants[1] = colorBlendState.BlendConstants.G;
|
||||
refreshGraphicsPipelineCreateInfo.colorBlendState.blendConstants[2] = colorBlendState.BlendConstants.B;
|
||||
refreshGraphicsPipelineCreateInfo.colorBlendState.blendConstants[3] = colorBlendState.BlendConstants.A;
|
||||
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.backStencilState = depthStencilState.BackStencilState.ToRefresh();
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.compareOp = (Refresh.CompareOp) depthStencilState.CompareOp;
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.depthBoundsTestEnable = Conversions.BoolToByte(depthStencilState.DepthBoundsTestEnable);
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.depthTestEnable = Conversions.BoolToByte(depthStencilState.DepthTestEnable);
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.depthWriteEnable = Conversions.BoolToByte(depthStencilState.DepthWriteEnable);
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.frontStencilState = depthStencilState.FrontStencilState.ToRefresh();
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.maxDepthBounds = depthStencilState.MaxDepthBounds;
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.minDepthBounds = depthStencilState.MinDepthBounds;
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.stencilTestEnable = Conversions.BoolToByte(depthStencilState.StencilTestEnable);
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.backStencilState = depthStencilState.BackStencilState.ToRefresh();
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.compareOp = (Refresh.CompareOp) depthStencilState.CompareOp;
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.depthBoundsTestEnable = Conversions.BoolToByte(depthStencilState.DepthBoundsTestEnable);
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.depthTestEnable = Conversions.BoolToByte(depthStencilState.DepthTestEnable);
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.depthWriteEnable = Conversions.BoolToByte(depthStencilState.DepthWriteEnable);
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.frontStencilState = depthStencilState.FrontStencilState.ToRefresh();
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.maxDepthBounds = depthStencilState.MaxDepthBounds;
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.minDepthBounds = depthStencilState.MinDepthBounds;
|
||||
refreshGraphicsPipelineCreateInfo.depthStencilState.stencilTestEnable = Conversions.BoolToByte(depthStencilState.StencilTestEnable);
|
||||
|
||||
refreshGraphicsPipelineCreateInfo.vertexShaderState.entryPointName = vertexShaderState.EntryPointName;
|
||||
refreshGraphicsPipelineCreateInfo.vertexShaderState.shaderModule = vertexShaderState.ShaderModule.Handle;
|
||||
refreshGraphicsPipelineCreateInfo.vertexShaderState.uniformBufferSize = vertexShaderState.UniformBufferSize;
|
||||
refreshGraphicsPipelineCreateInfo.vertexShaderState.entryPointName = vertexShaderState.EntryPointName;
|
||||
refreshGraphicsPipelineCreateInfo.vertexShaderState.shaderModule = vertexShaderState.ShaderModule.Handle;
|
||||
refreshGraphicsPipelineCreateInfo.vertexShaderState.uniformBufferSize = vertexShaderState.UniformBufferSize;
|
||||
|
||||
refreshGraphicsPipelineCreateInfo.fragmentShaderState.entryPointName = fragmentShaderState.EntryPointName;
|
||||
refreshGraphicsPipelineCreateInfo.fragmentShaderState.shaderModule = fragmentShaderState.ShaderModule.Handle;
|
||||
refreshGraphicsPipelineCreateInfo.fragmentShaderState.uniformBufferSize = fragmentShaderState.UniformBufferSize;
|
||||
refreshGraphicsPipelineCreateInfo.fragmentShaderState.entryPointName = fragmentShaderState.EntryPointName;
|
||||
refreshGraphicsPipelineCreateInfo.fragmentShaderState.shaderModule = fragmentShaderState.ShaderModule.Handle;
|
||||
refreshGraphicsPipelineCreateInfo.fragmentShaderState.uniformBufferSize = fragmentShaderState.UniformBufferSize;
|
||||
|
||||
refreshGraphicsPipelineCreateInfo.multisampleState.multisampleCount = (Refresh.SampleCount)multisampleState.MultisampleCount;
|
||||
refreshGraphicsPipelineCreateInfo.multisampleState.sampleMask = multisampleState.SampleMask;
|
||||
refreshGraphicsPipelineCreateInfo.multisampleState.multisampleCount = (Refresh.SampleCount) multisampleState.MultisampleCount;
|
||||
refreshGraphicsPipelineCreateInfo.multisampleState.sampleMask = multisampleState.SampleMask;
|
||||
|
||||
refreshGraphicsPipelineCreateInfo.pipelineLayoutCreateInfo.vertexSamplerBindingCount = pipelineLayoutInfo.VertexSamplerBindingCount;
|
||||
refreshGraphicsPipelineCreateInfo.pipelineLayoutCreateInfo.fragmentSamplerBindingCount = pipelineLayoutInfo.FragmentSamplerBindingCount;
|
||||
refreshGraphicsPipelineCreateInfo.pipelineLayoutCreateInfo.vertexSamplerBindingCount = pipelineLayoutInfo.VertexSamplerBindingCount;
|
||||
refreshGraphicsPipelineCreateInfo.pipelineLayoutCreateInfo.fragmentSamplerBindingCount = pipelineLayoutInfo.FragmentSamplerBindingCount;
|
||||
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.cullMode = (Refresh.CullMode)rasterizerState.CullMode;
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.depthBiasClamp = rasterizerState.DepthBiasClamp;
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.depthBiasConstantFactor = rasterizerState.DepthBiasConstantFactor;
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.depthBiasEnable = Conversions.BoolToByte(rasterizerState.DepthBiasEnable);
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.depthBiasSlopeFactor = rasterizerState.DepthBiasSlopeFactor;
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.depthClampEnable = Conversions.BoolToByte(rasterizerState.DepthClampEnable);
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.fillMode = (Refresh.FillMode)rasterizerState.FillMode;
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.frontFace = (Refresh.FrontFace)rasterizerState.FrontFace;
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.lineWidth = rasterizerState.LineWidth;
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.cullMode = (Refresh.CullMode) rasterizerState.CullMode;
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.depthBiasClamp = rasterizerState.DepthBiasClamp;
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.depthBiasConstantFactor = rasterizerState.DepthBiasConstantFactor;
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.depthBiasEnable = Conversions.BoolToByte(rasterizerState.DepthBiasEnable);
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.depthBiasSlopeFactor = rasterizerState.DepthBiasSlopeFactor;
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.depthClampEnable = Conversions.BoolToByte(rasterizerState.DepthClampEnable);
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.fillMode = (Refresh.FillMode) rasterizerState.FillMode;
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.frontFace = (Refresh.FrontFace) rasterizerState.FrontFace;
|
||||
refreshGraphicsPipelineCreateInfo.rasterizerState.lineWidth = rasterizerState.LineWidth;
|
||||
|
||||
refreshGraphicsPipelineCreateInfo.vertexInputState.vertexAttributes = vertexAttributesHandle.AddrOfPinnedObject();
|
||||
refreshGraphicsPipelineCreateInfo.vertexInputState.vertexAttributeCount = (uint) vertexInputState.VertexAttributes.Length;
|
||||
refreshGraphicsPipelineCreateInfo.vertexInputState.vertexBindings = vertexBindingsHandle.AddrOfPinnedObject();
|
||||
refreshGraphicsPipelineCreateInfo.vertexInputState.vertexBindingCount = (uint) vertexInputState.VertexBindings.Length;
|
||||
refreshGraphicsPipelineCreateInfo.vertexInputState.vertexAttributes = vertexAttributesHandle.AddrOfPinnedObject();
|
||||
refreshGraphicsPipelineCreateInfo.vertexInputState.vertexAttributeCount = (uint) vertexInputState.VertexAttributes.Length;
|
||||
refreshGraphicsPipelineCreateInfo.vertexInputState.vertexBindings = vertexBindingsHandle.AddrOfPinnedObject();
|
||||
refreshGraphicsPipelineCreateInfo.vertexInputState.vertexBindingCount = (uint) vertexInputState.VertexBindings.Length;
|
||||
|
||||
refreshGraphicsPipelineCreateInfo.viewportState.viewports = viewportHandle.AddrOfPinnedObject();
|
||||
refreshGraphicsPipelineCreateInfo.viewportState.viewportCount = (uint) viewportState.Viewports.Length;
|
||||
refreshGraphicsPipelineCreateInfo.viewportState.scissors = scissorHandle.AddrOfPinnedObject();
|
||||
refreshGraphicsPipelineCreateInfo.viewportState.scissorCount = (uint) viewportState.Scissors.Length;
|
||||
refreshGraphicsPipelineCreateInfo.viewportState.viewports = viewportHandle.AddrOfPinnedObject();
|
||||
refreshGraphicsPipelineCreateInfo.viewportState.viewportCount = (uint) viewportState.Viewports.Length;
|
||||
refreshGraphicsPipelineCreateInfo.viewportState.scissors = scissorHandle.AddrOfPinnedObject();
|
||||
refreshGraphicsPipelineCreateInfo.viewportState.scissorCount = (uint) viewportState.Scissors.Length;
|
||||
|
||||
refreshGraphicsPipelineCreateInfo.primitiveType = (Refresh.PrimitiveType) primitiveType;
|
||||
refreshGraphicsPipelineCreateInfo.renderPass = renderPass.Handle;
|
||||
refreshGraphicsPipelineCreateInfo.primitiveType = (Refresh.PrimitiveType) primitiveType;
|
||||
refreshGraphicsPipelineCreateInfo.renderPass = renderPass.Handle;
|
||||
|
||||
Handle = Refresh.Refresh_CreateGraphicsPipeline(device.Handle, refreshGraphicsPipelineCreateInfo);
|
||||
Handle = Refresh.Refresh_CreateGraphicsPipeline(device.Handle, refreshGraphicsPipelineCreateInfo);
|
||||
|
||||
vertexAttributesHandle.Free();
|
||||
vertexBindingsHandle.Free();
|
||||
viewportHandle.Free();
|
||||
scissorHandle.Free();
|
||||
vertexAttributesHandle.Free();
|
||||
vertexBindingsHandle.Free();
|
||||
viewportHandle.Free();
|
||||
scissorHandle.Free();
|
||||
|
||||
VertexShaderState = vertexShaderState;
|
||||
FragmentShaderState = fragmentShaderState;
|
||||
RenderPass = renderPass;
|
||||
}
|
||||
}
|
||||
VertexShaderState = vertexShaderState;
|
||||
FragmentShaderState = fragmentShaderState;
|
||||
RenderPass = renderPass;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,57 +3,57 @@ using RefreshCS;
|
|||
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// A render pass describes the kind of render targets that will be used in rendering.
|
||||
/// </summary>
|
||||
public class RenderPass : GraphicsResource
|
||||
{
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyRenderPass;
|
||||
/// <summary>
|
||||
/// A render pass describes the kind of render targets that will be used in rendering.
|
||||
/// </summary>
|
||||
public class RenderPass : GraphicsResource
|
||||
{
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyRenderPass;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a render pass using color target descriptions.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="colorTargetDescriptions">Up to 4 color target descriptions may be provided.</param>
|
||||
public unsafe RenderPass(
|
||||
GraphicsDevice device,
|
||||
params ColorTargetDescription[] colorTargetDescriptions
|
||||
) : base(device)
|
||||
{
|
||||
fixed (ColorTargetDescription* ptr = colorTargetDescriptions)
|
||||
{
|
||||
Refresh.RenderPassCreateInfo renderPassCreateInfo;
|
||||
renderPassCreateInfo.colorTargetCount = (uint) colorTargetDescriptions.Length;
|
||||
renderPassCreateInfo.colorTargetDescriptions = (IntPtr) ptr;
|
||||
renderPassCreateInfo.depthStencilTargetDescription = IntPtr.Zero;
|
||||
/// <summary>
|
||||
/// Creates a render pass using color target descriptions.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="colorTargetDescriptions">Up to 4 color target descriptions may be provided.</param>
|
||||
public unsafe RenderPass(
|
||||
GraphicsDevice device,
|
||||
params ColorTargetDescription[] colorTargetDescriptions
|
||||
) : base(device)
|
||||
{
|
||||
fixed (ColorTargetDescription* ptr = colorTargetDescriptions)
|
||||
{
|
||||
Refresh.RenderPassCreateInfo renderPassCreateInfo;
|
||||
renderPassCreateInfo.colorTargetCount = (uint) colorTargetDescriptions.Length;
|
||||
renderPassCreateInfo.colorTargetDescriptions = (IntPtr) ptr;
|
||||
renderPassCreateInfo.depthStencilTargetDescription = IntPtr.Zero;
|
||||
|
||||
Handle = Refresh.Refresh_CreateRenderPass(device.Handle, renderPassCreateInfo);
|
||||
}
|
||||
}
|
||||
Handle = Refresh.Refresh_CreateRenderPass(device.Handle, renderPassCreateInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a render pass using a depth/stencil target description and optional color target descriptions.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="depthStencilTargetDescription">A depth/stencil target description.</param>
|
||||
/// <param name="colorTargetDescriptions">Up to 4 color target descriptions may be provided.</param>
|
||||
public unsafe RenderPass(
|
||||
GraphicsDevice device,
|
||||
in DepthStencilTargetDescription depthStencilTargetDescription,
|
||||
params ColorTargetDescription[] colorTargetDescriptions
|
||||
) : base(device)
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a render pass using a depth/stencil target description and optional color target descriptions.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="depthStencilTargetDescription">A depth/stencil target description.</param>
|
||||
/// <param name="colorTargetDescriptions">Up to 4 color target descriptions may be provided.</param>
|
||||
public unsafe RenderPass(
|
||||
GraphicsDevice device,
|
||||
in DepthStencilTargetDescription depthStencilTargetDescription,
|
||||
params ColorTargetDescription[] colorTargetDescriptions
|
||||
) : base(device)
|
||||
{
|
||||
|
||||
fixed (DepthStencilTargetDescription* depthStencilPtr = &depthStencilTargetDescription)
|
||||
fixed (ColorTargetDescription* colorPtr = colorTargetDescriptions)
|
||||
{
|
||||
Refresh.RenderPassCreateInfo renderPassCreateInfo;
|
||||
renderPassCreateInfo.colorTargetCount = (uint)colorTargetDescriptions.Length;
|
||||
renderPassCreateInfo.colorTargetDescriptions = (IntPtr)colorPtr;
|
||||
renderPassCreateInfo.depthStencilTargetDescription = (IntPtr) depthStencilPtr;
|
||||
fixed (DepthStencilTargetDescription* depthStencilPtr = &depthStencilTargetDescription)
|
||||
fixed (ColorTargetDescription* colorPtr = colorTargetDescriptions)
|
||||
{
|
||||
Refresh.RenderPassCreateInfo renderPassCreateInfo;
|
||||
renderPassCreateInfo.colorTargetCount = (uint) colorTargetDescriptions.Length;
|
||||
renderPassCreateInfo.colorTargetDescriptions = (IntPtr) colorPtr;
|
||||
renderPassCreateInfo.depthStencilTargetDescription = (IntPtr) depthStencilPtr;
|
||||
|
||||
Handle = Refresh.Refresh_CreateRenderPass(device.Handle, renderPassCreateInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
Handle = Refresh.Refresh_CreateRenderPass(device.Handle, renderPassCreateInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,87 +3,89 @@ using RefreshCS;
|
|||
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// A render target is a structure that wraps a texture so that it can be rendered to.
|
||||
/// </summary>
|
||||
public class RenderTarget : GraphicsResource
|
||||
{
|
||||
public TextureSlice TextureSlice { get; }
|
||||
public TextureFormat Format => TextureSlice.Texture.Format;
|
||||
/// <summary>
|
||||
/// A render target is a structure that wraps a texture so that it can be rendered to.
|
||||
/// </summary>
|
||||
public class RenderTarget : GraphicsResource
|
||||
{
|
||||
public TextureSlice TextureSlice { get; }
|
||||
public TextureFormat Format => TextureSlice.Texture.Format;
|
||||
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyRenderTarget;
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyRenderTarget;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a render target backed by a texture.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="width">The width of the render target.</param>
|
||||
/// <param name="height">The height of the render target.</param>
|
||||
/// <param name="format">The format of the render target.</param>
|
||||
/// <param name="canBeSampled">Whether the render target can be used by a sampler.</param>
|
||||
/// <param name="sampleCount">The multisample count of the render target.</param>
|
||||
/// <param name="levelCount">The mip level of the render target.</param>
|
||||
/// <returns></returns>
|
||||
public static RenderTarget CreateBackedRenderTarget(
|
||||
GraphicsDevice device,
|
||||
uint width,
|
||||
uint height,
|
||||
TextureFormat format,
|
||||
bool canBeSampled,
|
||||
SampleCount sampleCount = SampleCount.One,
|
||||
uint levelCount = 1
|
||||
) {
|
||||
TextureUsageFlags flags = 0;
|
||||
/// <summary>
|
||||
/// Creates a render target backed by a texture.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="width">The width of the render target.</param>
|
||||
/// <param name="height">The height of the render target.</param>
|
||||
/// <param name="format">The format of the render target.</param>
|
||||
/// <param name="canBeSampled">Whether the render target can be used by a sampler.</param>
|
||||
/// <param name="sampleCount">The multisample count of the render target.</param>
|
||||
/// <param name="levelCount">The mip level of the render target.</param>
|
||||
/// <returns></returns>
|
||||
public static RenderTarget CreateBackedRenderTarget(
|
||||
GraphicsDevice device,
|
||||
uint width,
|
||||
uint height,
|
||||
TextureFormat format,
|
||||
bool canBeSampled,
|
||||
SampleCount sampleCount = SampleCount.One,
|
||||
uint levelCount = 1
|
||||
)
|
||||
{
|
||||
TextureUsageFlags flags = 0;
|
||||
|
||||
if (
|
||||
format == TextureFormat.D16 ||
|
||||
format == TextureFormat.D32 ||
|
||||
format == TextureFormat.D16S8 ||
|
||||
format == TextureFormat.D32S8
|
||||
) {
|
||||
flags |= TextureUsageFlags.DepthStencilTarget;
|
||||
}
|
||||
else
|
||||
{
|
||||
flags |= TextureUsageFlags.ColorTarget;
|
||||
}
|
||||
if (
|
||||
format == TextureFormat.D16 ||
|
||||
format == TextureFormat.D32 ||
|
||||
format == TextureFormat.D16S8 ||
|
||||
format == TextureFormat.D32S8
|
||||
)
|
||||
{
|
||||
flags |= TextureUsageFlags.DepthStencilTarget;
|
||||
}
|
||||
else
|
||||
{
|
||||
flags |= TextureUsageFlags.ColorTarget;
|
||||
}
|
||||
|
||||
if (canBeSampled)
|
||||
{
|
||||
flags |= TextureUsageFlags.Sampler;
|
||||
}
|
||||
if (canBeSampled)
|
||||
{
|
||||
flags |= TextureUsageFlags.Sampler;
|
||||
}
|
||||
|
||||
var texture = Texture.CreateTexture2D(
|
||||
device,
|
||||
width,
|
||||
height,
|
||||
format,
|
||||
flags,
|
||||
sampleCount,
|
||||
levelCount
|
||||
);
|
||||
var texture = Texture.CreateTexture2D(
|
||||
device,
|
||||
width,
|
||||
height,
|
||||
format,
|
||||
flags,
|
||||
sampleCount,
|
||||
levelCount
|
||||
);
|
||||
|
||||
return new RenderTarget(device, new TextureSlice(texture), sampleCount);
|
||||
}
|
||||
return new RenderTarget(device, new TextureSlice(texture), sampleCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a render target using a texture slice and an optional sample count.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="textureSlice">The texture slice that will be rendered to.</param>
|
||||
/// <param name="sampleCount">The desired multisample count of the render target.</param>
|
||||
public RenderTarget(
|
||||
GraphicsDevice device,
|
||||
in TextureSlice textureSlice,
|
||||
SampleCount sampleCount = SampleCount.One
|
||||
) : base(device)
|
||||
{
|
||||
Handle = Refresh.Refresh_CreateRenderTarget(
|
||||
device.Handle,
|
||||
textureSlice.ToRefreshTextureSlice(),
|
||||
(Refresh.SampleCount) sampleCount
|
||||
);
|
||||
TextureSlice = textureSlice;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a render target using a texture slice and an optional sample count.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="textureSlice">The texture slice that will be rendered to.</param>
|
||||
/// <param name="sampleCount">The desired multisample count of the render target.</param>
|
||||
public RenderTarget(
|
||||
GraphicsDevice device,
|
||||
in TextureSlice textureSlice,
|
||||
SampleCount sampleCount = SampleCount.One
|
||||
) : base(device)
|
||||
{
|
||||
Handle = Refresh.Refresh_CreateRenderTarget(
|
||||
device.Handle,
|
||||
textureSlice.ToRefreshTextureSlice(),
|
||||
(Refresh.SampleCount) sampleCount
|
||||
);
|
||||
TextureSlice = textureSlice;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
using System;
|
||||
using System;
|
||||
using RefreshCS;
|
||||
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// A sampler specifies how a texture will be sampled in a shader.
|
||||
/// </summary>
|
||||
public class Sampler : GraphicsResource
|
||||
{
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroySampler;
|
||||
/// <summary>
|
||||
/// A sampler specifies how a texture will be sampled in a shader.
|
||||
/// </summary>
|
||||
public class Sampler : GraphicsResource
|
||||
{
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroySampler;
|
||||
|
||||
public Sampler(
|
||||
GraphicsDevice device,
|
||||
in SamplerCreateInfo samplerCreateInfo
|
||||
) : base(device)
|
||||
{
|
||||
Handle = Refresh.Refresh_CreateSampler(
|
||||
device.Handle,
|
||||
samplerCreateInfo.ToRefreshSamplerStateCreateInfo()
|
||||
);
|
||||
}
|
||||
}
|
||||
public Sampler(
|
||||
GraphicsDevice device,
|
||||
in SamplerCreateInfo samplerCreateInfo
|
||||
) : base(device)
|
||||
{
|
||||
Handle = Refresh.Refresh_CreateSampler(
|
||||
device.Handle,
|
||||
samplerCreateInfo.ToRefreshSamplerStateCreateInfo()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,25 +3,25 @@ using System;
|
|||
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Shader modules expect input in SPIR-V bytecode format.
|
||||
/// </summary>
|
||||
public class ShaderModule : GraphicsResource
|
||||
{
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyShaderModule;
|
||||
/// <summary>
|
||||
/// Shader modules expect input in SPIR-V bytecode format.
|
||||
/// </summary>
|
||||
public class ShaderModule : GraphicsResource
|
||||
{
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyShaderModule;
|
||||
|
||||
public unsafe ShaderModule(GraphicsDevice device, string filePath) : base(device)
|
||||
{
|
||||
var bytecode = Bytecode.ReadBytecodeAsUInt32(filePath);
|
||||
public unsafe ShaderModule(GraphicsDevice device, string filePath) : base(device)
|
||||
{
|
||||
var bytecode = Bytecode.ReadBytecodeAsUInt32(filePath);
|
||||
|
||||
fixed (uint* ptr = bytecode)
|
||||
{
|
||||
Refresh.ShaderModuleCreateInfo shaderModuleCreateInfo;
|
||||
shaderModuleCreateInfo.codeSize = (UIntPtr) (bytecode.Length * sizeof(uint));
|
||||
shaderModuleCreateInfo.byteCode = (IntPtr) ptr;
|
||||
fixed (uint* ptr = bytecode)
|
||||
{
|
||||
Refresh.ShaderModuleCreateInfo shaderModuleCreateInfo;
|
||||
shaderModuleCreateInfo.codeSize = (UIntPtr) (bytecode.Length * sizeof(uint));
|
||||
shaderModuleCreateInfo.byteCode = (IntPtr) ptr;
|
||||
|
||||
Handle = Refresh.Refresh_CreateShaderModule(device.Handle, shaderModuleCreateInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
Handle = Refresh.Refresh_CreateShaderModule(device.Handle, shaderModuleCreateInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,193 +3,196 @@ using RefreshCS;
|
|||
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// A container for pixel data.
|
||||
/// </summary>
|
||||
public class Texture : GraphicsResource
|
||||
{
|
||||
public uint Width { get; }
|
||||
public uint Height { get; }
|
||||
public uint Depth { get; }
|
||||
public TextureFormat Format { get; }
|
||||
public bool IsCube { get; }
|
||||
public uint LevelCount { get; }
|
||||
public SampleCount SampleCount { get; }
|
||||
public TextureUsageFlags UsageFlags { get; }
|
||||
/// <summary>
|
||||
/// A container for pixel data.
|
||||
/// </summary>
|
||||
public class Texture : GraphicsResource
|
||||
{
|
||||
public uint Width { get; }
|
||||
public uint Height { get; }
|
||||
public uint Depth { get; }
|
||||
public TextureFormat Format { get; }
|
||||
public bool IsCube { get; }
|
||||
public uint LevelCount { get; }
|
||||
public SampleCount SampleCount { get; }
|
||||
public TextureUsageFlags UsageFlags { get; }
|
||||
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyTexture;
|
||||
protected override Action<IntPtr, IntPtr, IntPtr> QueueDestroyFunction => Refresh.Refresh_QueueDestroyTexture;
|
||||
|
||||
/// <summary>
|
||||
/// Loads a PNG from a file path.
|
||||
/// NOTE: You can queue as many of these as you want on to a command buffer but it MUST be submitted!
|
||||
/// </summary>
|
||||
/// <param name="device"></param>
|
||||
/// <param name="commandBuffer"></param>
|
||||
/// <param name="filePath"></param>
|
||||
/// <returns></returns>
|
||||
public static Texture LoadPNG(GraphicsDevice device, CommandBuffer commandBuffer, string filePath)
|
||||
{
|
||||
var pixels = Refresh.Refresh_Image_Load(
|
||||
filePath,
|
||||
out var width,
|
||||
out var height,
|
||||
out var channels
|
||||
);
|
||||
/// <summary>
|
||||
/// Loads a PNG from a file path.
|
||||
/// NOTE: You can queue as many of these as you want on to a command buffer but it MUST be submitted!
|
||||
/// </summary>
|
||||
/// <param name="device"></param>
|
||||
/// <param name="commandBuffer"></param>
|
||||
/// <param name="filePath"></param>
|
||||
/// <returns></returns>
|
||||
public static Texture LoadPNG(GraphicsDevice device, CommandBuffer commandBuffer, string filePath)
|
||||
{
|
||||
var pixels = Refresh.Refresh_Image_Load(
|
||||
filePath,
|
||||
out var width,
|
||||
out var height,
|
||||
out var channels
|
||||
);
|
||||
|
||||
var byteCount = (uint)(width * height * channels);
|
||||
var byteCount = (uint) (width * height * channels);
|
||||
|
||||
TextureCreateInfo textureCreateInfo;
|
||||
textureCreateInfo.Width = (uint)width;
|
||||
textureCreateInfo.Height = (uint)height;
|
||||
textureCreateInfo.Depth = 1;
|
||||
textureCreateInfo.Format = TextureFormat.R8G8B8A8;
|
||||
textureCreateInfo.IsCube = false;
|
||||
textureCreateInfo.LevelCount = 1;
|
||||
textureCreateInfo.SampleCount = SampleCount.One;
|
||||
textureCreateInfo.UsageFlags = TextureUsageFlags.Sampler;
|
||||
TextureCreateInfo textureCreateInfo;
|
||||
textureCreateInfo.Width = (uint) width;
|
||||
textureCreateInfo.Height = (uint) height;
|
||||
textureCreateInfo.Depth = 1;
|
||||
textureCreateInfo.Format = TextureFormat.R8G8B8A8;
|
||||
textureCreateInfo.IsCube = false;
|
||||
textureCreateInfo.LevelCount = 1;
|
||||
textureCreateInfo.SampleCount = SampleCount.One;
|
||||
textureCreateInfo.UsageFlags = TextureUsageFlags.Sampler;
|
||||
|
||||
var texture = new Texture(device, textureCreateInfo);
|
||||
commandBuffer.SetTextureData(texture, pixels, byteCount);
|
||||
var texture = new Texture(device, textureCreateInfo);
|
||||
commandBuffer.SetTextureData(texture, pixels, byteCount);
|
||||
|
||||
Refresh.Refresh_Image_Free(pixels);
|
||||
Refresh.Refresh_Image_Free(pixels);
|
||||
|
||||
return texture;
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
|
||||
public unsafe static void SavePNG(string path, int width, int height, byte[] pixels)
|
||||
{
|
||||
fixed (byte* ptr = &pixels[0])
|
||||
{
|
||||
Refresh.Refresh_Image_SavePNG(path, width, height, (IntPtr) ptr);
|
||||
}
|
||||
}
|
||||
public unsafe static void SavePNG(string path, int width, int height, byte[] pixels)
|
||||
{
|
||||
fixed (byte* ptr = &pixels[0])
|
||||
{
|
||||
Refresh.Refresh_Image_SavePNG(path, width, height, (IntPtr) ptr);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a 2D texture.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="format">The format of the texture.</param>
|
||||
/// <param name="usageFlags">Specifies how the texture will be used.</param>
|
||||
/// <param name="sampleCount">Specifies the multisample count.</param>
|
||||
/// <param name="levelCount">Specifies the number of mip levels.</param>
|
||||
public static Texture CreateTexture2D(
|
||||
GraphicsDevice device,
|
||||
uint width,
|
||||
uint height,
|
||||
TextureFormat format,
|
||||
TextureUsageFlags usageFlags,
|
||||
SampleCount sampleCount = SampleCount.One,
|
||||
uint levelCount = 1
|
||||
) {
|
||||
var textureCreateInfo = new TextureCreateInfo
|
||||
{
|
||||
Width = width,
|
||||
Height = height,
|
||||
Depth = 1,
|
||||
IsCube = false,
|
||||
SampleCount = sampleCount,
|
||||
LevelCount = levelCount,
|
||||
Format = format,
|
||||
UsageFlags = usageFlags
|
||||
};
|
||||
/// <summary>
|
||||
/// Creates a 2D texture.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="format">The format of the texture.</param>
|
||||
/// <param name="usageFlags">Specifies how the texture will be used.</param>
|
||||
/// <param name="sampleCount">Specifies the multisample count.</param>
|
||||
/// <param name="levelCount">Specifies the number of mip levels.</param>
|
||||
public static Texture CreateTexture2D(
|
||||
GraphicsDevice device,
|
||||
uint width,
|
||||
uint height,
|
||||
TextureFormat format,
|
||||
TextureUsageFlags usageFlags,
|
||||
SampleCount sampleCount = SampleCount.One,
|
||||
uint levelCount = 1
|
||||
)
|
||||
{
|
||||
var textureCreateInfo = new TextureCreateInfo
|
||||
{
|
||||
Width = width,
|
||||
Height = height,
|
||||
Depth = 1,
|
||||
IsCube = false,
|
||||
SampleCount = sampleCount,
|
||||
LevelCount = levelCount,
|
||||
Format = format,
|
||||
UsageFlags = usageFlags
|
||||
};
|
||||
|
||||
return new Texture(device, textureCreateInfo);
|
||||
}
|
||||
return new Texture(device, textureCreateInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a 3D texture.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="depth">The depth of the texture.</param>
|
||||
/// <param name="format">The format of the texture.</param>
|
||||
/// <param name="usageFlags">Specifies how the texture will be used.</param>
|
||||
/// <param name="sampleCount">Specifies the multisample count.</param>
|
||||
/// <param name="levelCount">Specifies the number of mip levels.</param>
|
||||
public static Texture CreateTexture3D(
|
||||
GraphicsDevice device,
|
||||
uint width,
|
||||
uint height,
|
||||
uint depth,
|
||||
TextureFormat format,
|
||||
TextureUsageFlags usageFlags,
|
||||
SampleCount sampleCount = SampleCount.One,
|
||||
uint levelCount = 1
|
||||
) {
|
||||
var textureCreateInfo = new TextureCreateInfo
|
||||
{
|
||||
Width = width,
|
||||
Height = height,
|
||||
Depth = depth,
|
||||
IsCube = false,
|
||||
SampleCount = sampleCount,
|
||||
LevelCount = levelCount,
|
||||
Format = format,
|
||||
UsageFlags = usageFlags
|
||||
};
|
||||
/// <summary>
|
||||
/// Creates a 3D texture.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="width">The width of the texture.</param>
|
||||
/// <param name="height">The height of the texture.</param>
|
||||
/// <param name="depth">The depth of the texture.</param>
|
||||
/// <param name="format">The format of the texture.</param>
|
||||
/// <param name="usageFlags">Specifies how the texture will be used.</param>
|
||||
/// <param name="sampleCount">Specifies the multisample count.</param>
|
||||
/// <param name="levelCount">Specifies the number of mip levels.</param>
|
||||
public static Texture CreateTexture3D(
|
||||
GraphicsDevice device,
|
||||
uint width,
|
||||
uint height,
|
||||
uint depth,
|
||||
TextureFormat format,
|
||||
TextureUsageFlags usageFlags,
|
||||
SampleCount sampleCount = SampleCount.One,
|
||||
uint levelCount = 1
|
||||
)
|
||||
{
|
||||
var textureCreateInfo = new TextureCreateInfo
|
||||
{
|
||||
Width = width,
|
||||
Height = height,
|
||||
Depth = depth,
|
||||
IsCube = false,
|
||||
SampleCount = sampleCount,
|
||||
LevelCount = levelCount,
|
||||
Format = format,
|
||||
UsageFlags = usageFlags
|
||||
};
|
||||
|
||||
return new Texture(device, textureCreateInfo);
|
||||
}
|
||||
return new Texture(device, textureCreateInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a cube texture.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="size">The length of one side of the cube.</param>
|
||||
/// <param name="format">The format of the texture.</param>
|
||||
/// <param name="usageFlags">Specifies how the texture will be used.</param>
|
||||
/// <param name="sampleCount">Specifies the multisample count.</param>
|
||||
/// <param name="levelCount">Specifies the number of mip levels.</param>
|
||||
public static Texture CreateTextureCube(
|
||||
GraphicsDevice device,
|
||||
uint size,
|
||||
TextureFormat format,
|
||||
TextureUsageFlags usageFlags,
|
||||
SampleCount sampleCount = SampleCount.One,
|
||||
uint levelCount = 1
|
||||
) {
|
||||
var textureCreateInfo = new TextureCreateInfo
|
||||
{
|
||||
Width = size,
|
||||
Height = size,
|
||||
Depth = 1,
|
||||
IsCube = true,
|
||||
SampleCount = sampleCount,
|
||||
LevelCount = levelCount,
|
||||
Format = format,
|
||||
UsageFlags = usageFlags
|
||||
};
|
||||
/// <summary>
|
||||
/// Creates a cube texture.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="size">The length of one side of the cube.</param>
|
||||
/// <param name="format">The format of the texture.</param>
|
||||
/// <param name="usageFlags">Specifies how the texture will be used.</param>
|
||||
/// <param name="sampleCount">Specifies the multisample count.</param>
|
||||
/// <param name="levelCount">Specifies the number of mip levels.</param>
|
||||
public static Texture CreateTextureCube(
|
||||
GraphicsDevice device,
|
||||
uint size,
|
||||
TextureFormat format,
|
||||
TextureUsageFlags usageFlags,
|
||||
SampleCount sampleCount = SampleCount.One,
|
||||
uint levelCount = 1
|
||||
)
|
||||
{
|
||||
var textureCreateInfo = new TextureCreateInfo
|
||||
{
|
||||
Width = size,
|
||||
Height = size,
|
||||
Depth = 1,
|
||||
IsCube = true,
|
||||
SampleCount = sampleCount,
|
||||
LevelCount = levelCount,
|
||||
Format = format,
|
||||
UsageFlags = usageFlags
|
||||
};
|
||||
|
||||
return new Texture(device, textureCreateInfo);
|
||||
}
|
||||
return new Texture(device, textureCreateInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new texture using a TextureCreateInfo struct.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="textureCreateInfo">The parameters to use when creating the texture.</param>
|
||||
public Texture(
|
||||
GraphicsDevice device,
|
||||
in TextureCreateInfo textureCreateInfo
|
||||
) : base(device)
|
||||
{
|
||||
Handle = Refresh.Refresh_CreateTexture(
|
||||
device.Handle,
|
||||
textureCreateInfo.ToRefreshTextureCreateInfo()
|
||||
);
|
||||
/// <summary>
|
||||
/// Creates a new texture using a TextureCreateInfo struct.
|
||||
/// </summary>
|
||||
/// <param name="device">An initialized GraphicsDevice.</param>
|
||||
/// <param name="textureCreateInfo">The parameters to use when creating the texture.</param>
|
||||
public Texture(
|
||||
GraphicsDevice device,
|
||||
in TextureCreateInfo textureCreateInfo
|
||||
) : base(device)
|
||||
{
|
||||
Handle = Refresh.Refresh_CreateTexture(
|
||||
device.Handle,
|
||||
textureCreateInfo.ToRefreshTextureCreateInfo()
|
||||
);
|
||||
|
||||
Format = textureCreateInfo.Format;
|
||||
Width = textureCreateInfo.Width;
|
||||
Height = textureCreateInfo.Height;
|
||||
Depth = textureCreateInfo.Depth;
|
||||
IsCube = textureCreateInfo.IsCube;
|
||||
SampleCount = textureCreateInfo.SampleCount;
|
||||
LevelCount = textureCreateInfo.LevelCount;
|
||||
SampleCount = textureCreateInfo.SampleCount;
|
||||
UsageFlags = textureCreateInfo.UsageFlags;
|
||||
}
|
||||
}
|
||||
Format = textureCreateInfo.Format;
|
||||
Width = textureCreateInfo.Width;
|
||||
Height = textureCreateInfo.Height;
|
||||
Depth = textureCreateInfo.Depth;
|
||||
IsCube = textureCreateInfo.IsCube;
|
||||
SampleCount = textureCreateInfo.SampleCount;
|
||||
LevelCount = textureCreateInfo.LevelCount;
|
||||
SampleCount = textureCreateInfo.SampleCount;
|
||||
UsageFlags = textureCreateInfo.UsageFlags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
namespace MoonWorks.Graphics
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes how the graphics pipeline will blend colors.
|
||||
/// You must provide one ColorTargetBlendState per color target in the pipeline.
|
||||
/// </summary>
|
||||
public unsafe struct ColorBlendState
|
||||
{
|
||||
public bool LogicOpEnable;
|
||||
public LogicOp LogicOp;
|
||||
public BlendConstants BlendConstants;
|
||||
public ColorTargetBlendState[] ColorTargetBlendStates;
|
||||
}
|
||||
/// <summary>
|
||||
/// Describes how the graphics pipeline will blend colors.
|
||||
/// You must provide one ColorTargetBlendState per color target in the pipeline.
|
||||
/// </summary>
|
||||
public unsafe struct ColorBlendState
|
||||
{
|
||||
public bool LogicOpEnable;
|
||||
public LogicOp LogicOp;
|
||||
public BlendConstants BlendConstants;
|
||||
public ColorTargetBlendState[] ColorTargetBlendStates;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,120 +2,120 @@
|
|||
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
public struct ColorTargetBlendState
|
||||
{
|
||||
/// <summary>
|
||||
/// If disabled, no blending will occur.
|
||||
/// </summary>
|
||||
public bool BlendEnable;
|
||||
public struct ColorTargetBlendState
|
||||
{
|
||||
/// <summary>
|
||||
/// If disabled, no blending will occur.
|
||||
/// </summary>
|
||||
public bool BlendEnable;
|
||||
|
||||
/// <summary>
|
||||
/// Selects which blend operation to use with alpha values.
|
||||
/// </summary>
|
||||
public BlendOp AlphaBlendOp;
|
||||
/// <summary>
|
||||
/// Selects which blend operation to use with color values.
|
||||
/// </summary>
|
||||
public BlendOp ColorBlendOp;
|
||||
/// <summary>
|
||||
/// Selects which blend operation to use with alpha values.
|
||||
/// </summary>
|
||||
public BlendOp AlphaBlendOp;
|
||||
/// <summary>
|
||||
/// Selects which blend operation to use with color values.
|
||||
/// </summary>
|
||||
public BlendOp ColorBlendOp;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies which of the RGBA components are enabled for writing.
|
||||
/// </summary>
|
||||
public ColorComponentFlags ColorWriteMask;
|
||||
/// <summary>
|
||||
/// Specifies which of the RGBA components are enabled for writing.
|
||||
/// </summary>
|
||||
public ColorComponentFlags ColorWriteMask;
|
||||
|
||||
/// <summary>
|
||||
/// Selects which blend factor is used to determine the alpha destination factor.
|
||||
/// </summary>
|
||||
public BlendFactor DestinationAlphaBlendFactor;
|
||||
/// <summary>
|
||||
/// Selects which blend factor is used to determine the alpha destination factor.
|
||||
/// </summary>
|
||||
public BlendFactor DestinationAlphaBlendFactor;
|
||||
|
||||
/// <summary>
|
||||
/// Selects which blend factor is used to determine the color destination factor.
|
||||
/// </summary>
|
||||
public BlendFactor DestinationColorBlendFactor;
|
||||
/// <summary>
|
||||
/// Selects which blend factor is used to determine the color destination factor.
|
||||
/// </summary>
|
||||
public BlendFactor DestinationColorBlendFactor;
|
||||
|
||||
/// <summary>
|
||||
/// Selects which blend factor is used to determine the alpha source factor.
|
||||
/// </summary>
|
||||
public BlendFactor SourceAlphaBlendFactor;
|
||||
/// <summary>
|
||||
/// Selects which blend factor is used to determine the alpha source factor.
|
||||
/// </summary>
|
||||
public BlendFactor SourceAlphaBlendFactor;
|
||||
|
||||
/// <summary>
|
||||
/// Selects which blend factor is used to determine the color source factor.
|
||||
/// </summary>
|
||||
public BlendFactor SourceColorBlendFactor;
|
||||
/// <summary>
|
||||
/// Selects which blend factor is used to determine the color source factor.
|
||||
/// </summary>
|
||||
public BlendFactor SourceColorBlendFactor;
|
||||
|
||||
public static readonly ColorTargetBlendState Additive = new ColorTargetBlendState
|
||||
{
|
||||
BlendEnable = true,
|
||||
AlphaBlendOp = BlendOp.Add,
|
||||
ColorBlendOp = BlendOp.Add,
|
||||
ColorWriteMask = ColorComponentFlags.RGBA,
|
||||
SourceColorBlendFactor = BlendFactor.SourceAlpha,
|
||||
SourceAlphaBlendFactor = BlendFactor.SourceAlpha,
|
||||
DestinationColorBlendFactor = BlendFactor.One,
|
||||
DestinationAlphaBlendFactor = BlendFactor.One
|
||||
};
|
||||
public static readonly ColorTargetBlendState Additive = new ColorTargetBlendState
|
||||
{
|
||||
BlendEnable = true,
|
||||
AlphaBlendOp = BlendOp.Add,
|
||||
ColorBlendOp = BlendOp.Add,
|
||||
ColorWriteMask = ColorComponentFlags.RGBA,
|
||||
SourceColorBlendFactor = BlendFactor.SourceAlpha,
|
||||
SourceAlphaBlendFactor = BlendFactor.SourceAlpha,
|
||||
DestinationColorBlendFactor = BlendFactor.One,
|
||||
DestinationAlphaBlendFactor = BlendFactor.One
|
||||
};
|
||||
|
||||
public static readonly ColorTargetBlendState AlphaBlend = new ColorTargetBlendState
|
||||
{
|
||||
BlendEnable = true,
|
||||
AlphaBlendOp = BlendOp.Add,
|
||||
ColorBlendOp = BlendOp.Add,
|
||||
ColorWriteMask = ColorComponentFlags.RGBA,
|
||||
SourceColorBlendFactor = BlendFactor.One,
|
||||
SourceAlphaBlendFactor = BlendFactor.One,
|
||||
DestinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha,
|
||||
DestinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha
|
||||
};
|
||||
public static readonly ColorTargetBlendState AlphaBlend = new ColorTargetBlendState
|
||||
{
|
||||
BlendEnable = true,
|
||||
AlphaBlendOp = BlendOp.Add,
|
||||
ColorBlendOp = BlendOp.Add,
|
||||
ColorWriteMask = ColorComponentFlags.RGBA,
|
||||
SourceColorBlendFactor = BlendFactor.One,
|
||||
SourceAlphaBlendFactor = BlendFactor.One,
|
||||
DestinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha,
|
||||
DestinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha
|
||||
};
|
||||
|
||||
public static readonly ColorTargetBlendState NonPremultiplied = new ColorTargetBlendState
|
||||
{
|
||||
BlendEnable = true,
|
||||
AlphaBlendOp = BlendOp.Add,
|
||||
ColorBlendOp = BlendOp.Add,
|
||||
ColorWriteMask = ColorComponentFlags.RGBA,
|
||||
SourceColorBlendFactor = BlendFactor.SourceAlpha,
|
||||
SourceAlphaBlendFactor = BlendFactor.SourceAlpha,
|
||||
DestinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha,
|
||||
DestinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha
|
||||
};
|
||||
public static readonly ColorTargetBlendState NonPremultiplied = new ColorTargetBlendState
|
||||
{
|
||||
BlendEnable = true,
|
||||
AlphaBlendOp = BlendOp.Add,
|
||||
ColorBlendOp = BlendOp.Add,
|
||||
ColorWriteMask = ColorComponentFlags.RGBA,
|
||||
SourceColorBlendFactor = BlendFactor.SourceAlpha,
|
||||
SourceAlphaBlendFactor = BlendFactor.SourceAlpha,
|
||||
DestinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha,
|
||||
DestinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha
|
||||
};
|
||||
|
||||
public static readonly ColorTargetBlendState Opaque = new ColorTargetBlendState
|
||||
{
|
||||
BlendEnable = true,
|
||||
AlphaBlendOp = BlendOp.Add,
|
||||
ColorBlendOp = BlendOp.Add,
|
||||
ColorWriteMask = ColorComponentFlags.RGBA,
|
||||
SourceColorBlendFactor = BlendFactor.One,
|
||||
SourceAlphaBlendFactor = BlendFactor.One,
|
||||
DestinationColorBlendFactor = BlendFactor.Zero,
|
||||
DestinationAlphaBlendFactor = BlendFactor.Zero
|
||||
};
|
||||
public static readonly ColorTargetBlendState Opaque = new ColorTargetBlendState
|
||||
{
|
||||
BlendEnable = true,
|
||||
AlphaBlendOp = BlendOp.Add,
|
||||
ColorBlendOp = BlendOp.Add,
|
||||
ColorWriteMask = ColorComponentFlags.RGBA,
|
||||
SourceColorBlendFactor = BlendFactor.One,
|
||||
SourceAlphaBlendFactor = BlendFactor.One,
|
||||
DestinationColorBlendFactor = BlendFactor.Zero,
|
||||
DestinationAlphaBlendFactor = BlendFactor.Zero
|
||||
};
|
||||
|
||||
public static readonly ColorTargetBlendState None = new ColorTargetBlendState
|
||||
{
|
||||
BlendEnable = false,
|
||||
ColorWriteMask = ColorComponentFlags.RGBA
|
||||
};
|
||||
public static readonly ColorTargetBlendState None = new ColorTargetBlendState
|
||||
{
|
||||
BlendEnable = false,
|
||||
ColorWriteMask = ColorComponentFlags.RGBA
|
||||
};
|
||||
|
||||
public static readonly ColorTargetBlendState Disable = new ColorTargetBlendState
|
||||
{
|
||||
BlendEnable = false,
|
||||
ColorWriteMask = ColorComponentFlags.None
|
||||
};
|
||||
public static readonly ColorTargetBlendState Disable = new ColorTargetBlendState
|
||||
{
|
||||
BlendEnable = false,
|
||||
ColorWriteMask = ColorComponentFlags.None
|
||||
};
|
||||
|
||||
public Refresh.ColorTargetBlendState ToRefreshColorTargetBlendState()
|
||||
{
|
||||
return new Refresh.ColorTargetBlendState
|
||||
{
|
||||
blendEnable = Conversions.BoolToByte(BlendEnable),
|
||||
alphaBlendOp = (Refresh.BlendOp)AlphaBlendOp,
|
||||
colorBlendOp = (Refresh.BlendOp)ColorBlendOp,
|
||||
colorWriteMask = (Refresh.ColorComponentFlags)ColorWriteMask,
|
||||
destinationAlphaBlendFactor = (Refresh.BlendFactor)DestinationAlphaBlendFactor,
|
||||
destinationColorBlendFactor = (Refresh.BlendFactor)DestinationColorBlendFactor,
|
||||
sourceAlphaBlendFactor = (Refresh.BlendFactor)SourceAlphaBlendFactor,
|
||||
sourceColorBlendFactor = (Refresh.BlendFactor)SourceColorBlendFactor
|
||||
};
|
||||
}
|
||||
}
|
||||
public Refresh.ColorTargetBlendState ToRefreshColorTargetBlendState()
|
||||
{
|
||||
return new Refresh.ColorTargetBlendState
|
||||
{
|
||||
blendEnable = Conversions.BoolToByte(BlendEnable),
|
||||
alphaBlendOp = (Refresh.BlendOp) AlphaBlendOp,
|
||||
colorBlendOp = (Refresh.BlendOp) ColorBlendOp,
|
||||
colorWriteMask = (Refresh.ColorComponentFlags) ColorWriteMask,
|
||||
destinationAlphaBlendFactor = (Refresh.BlendFactor) DestinationAlphaBlendFactor,
|
||||
destinationColorBlendFactor = (Refresh.BlendFactor) DestinationColorBlendFactor,
|
||||
sourceAlphaBlendFactor = (Refresh.BlendFactor) SourceAlphaBlendFactor,
|
||||
sourceColorBlendFactor = (Refresh.BlendFactor) SourceColorBlendFactor
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,79 +1,79 @@
|
|||
namespace MoonWorks.Graphics
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines how data is written to and read from the depth/stencil buffer.
|
||||
/// </summary>
|
||||
public struct DepthStencilState
|
||||
{
|
||||
/// <summary>
|
||||
/// If disabled, no depth culling will occur.
|
||||
/// </summary>
|
||||
public bool DepthTestEnable;
|
||||
/// <summary>
|
||||
/// Determines how data is written to and read from the depth/stencil buffer.
|
||||
/// </summary>
|
||||
public struct DepthStencilState
|
||||
{
|
||||
/// <summary>
|
||||
/// If disabled, no depth culling will occur.
|
||||
/// </summary>
|
||||
public bool DepthTestEnable;
|
||||
|
||||
/// <summary>
|
||||
/// Describes the stencil operation for back-facing primitives.
|
||||
/// </summary>
|
||||
public StencilOpState BackStencilState;
|
||||
/// <summary>
|
||||
/// Describes the stencil operation for back-facing primitives.
|
||||
/// </summary>
|
||||
public StencilOpState BackStencilState;
|
||||
|
||||
/// <summary>
|
||||
/// Describes the stencil operation for front-facing primitives.
|
||||
/// </summary>
|
||||
public StencilOpState FrontStencilState;
|
||||
/// <summary>
|
||||
/// Describes the stencil operation for front-facing primitives.
|
||||
/// </summary>
|
||||
public StencilOpState FrontStencilState;
|
||||
|
||||
/// <summary>
|
||||
/// The comparison operator used in the depth test.
|
||||
/// </summary>
|
||||
public CompareOp CompareOp;
|
||||
/// <summary>
|
||||
/// The comparison operator used in the depth test.
|
||||
/// </summary>
|
||||
public CompareOp CompareOp;
|
||||
|
||||
/// <summary>
|
||||
/// If depth lies outside of these bounds the pixel will be culled.
|
||||
/// </summary>
|
||||
public bool DepthBoundsTestEnable;
|
||||
/// <summary>
|
||||
/// If depth lies outside of these bounds the pixel will be culled.
|
||||
/// </summary>
|
||||
public bool DepthBoundsTestEnable;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether depth values will be written to the buffer during rendering.
|
||||
/// </summary>
|
||||
public bool DepthWriteEnable;
|
||||
/// <summary>
|
||||
/// Specifies whether depth values will be written to the buffer during rendering.
|
||||
/// </summary>
|
||||
public bool DepthWriteEnable;
|
||||
|
||||
/// <summary>
|
||||
/// The minimum depth value in the depth bounds test.
|
||||
/// </summary>
|
||||
public float MinDepthBounds;
|
||||
/// <summary>
|
||||
/// The minimum depth value in the depth bounds test.
|
||||
/// </summary>
|
||||
public float MinDepthBounds;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum depth value in the depth bounds test.
|
||||
/// </summary>
|
||||
public float MaxDepthBounds;
|
||||
/// <summary>
|
||||
/// The maximum depth value in the depth bounds test.
|
||||
/// </summary>
|
||||
public float MaxDepthBounds;
|
||||
|
||||
/// <summary>
|
||||
/// If disabled, no stencil culling will occur.
|
||||
/// </summary>
|
||||
public bool StencilTestEnable;
|
||||
/// <summary>
|
||||
/// If disabled, no stencil culling will occur.
|
||||
/// </summary>
|
||||
public bool StencilTestEnable;
|
||||
|
||||
public static readonly DepthStencilState DepthReadWrite = new DepthStencilState
|
||||
{
|
||||
DepthTestEnable = true,
|
||||
DepthWriteEnable = true,
|
||||
DepthBoundsTestEnable = false,
|
||||
StencilTestEnable = false,
|
||||
CompareOp = CompareOp.LessOrEqual
|
||||
};
|
||||
public static readonly DepthStencilState DepthReadWrite = new DepthStencilState
|
||||
{
|
||||
DepthTestEnable = true,
|
||||
DepthWriteEnable = true,
|
||||
DepthBoundsTestEnable = false,
|
||||
StencilTestEnable = false,
|
||||
CompareOp = CompareOp.LessOrEqual
|
||||
};
|
||||
|
||||
public static readonly DepthStencilState DepthRead = new DepthStencilState
|
||||
{
|
||||
DepthTestEnable = true,
|
||||
DepthWriteEnable = false,
|
||||
DepthBoundsTestEnable = false,
|
||||
StencilTestEnable = false,
|
||||
CompareOp = CompareOp.LessOrEqual
|
||||
};
|
||||
public static readonly DepthStencilState DepthRead = new DepthStencilState
|
||||
{
|
||||
DepthTestEnable = true,
|
||||
DepthWriteEnable = false,
|
||||
DepthBoundsTestEnable = false,
|
||||
StencilTestEnable = false,
|
||||
CompareOp = CompareOp.LessOrEqual
|
||||
};
|
||||
|
||||
public static readonly DepthStencilState Disable = new DepthStencilState
|
||||
{
|
||||
DepthTestEnable = false,
|
||||
DepthWriteEnable = false,
|
||||
DepthBoundsTestEnable = false,
|
||||
StencilTestEnable = false
|
||||
};
|
||||
}
|
||||
public static readonly DepthStencilState Disable = new DepthStencilState
|
||||
{
|
||||
DepthTestEnable = false,
|
||||
DepthWriteEnable = false,
|
||||
DepthBoundsTestEnable = false,
|
||||
StencilTestEnable = false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
namespace MoonWorks.Graphics
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
public struct GraphicsPipelineCreateInfo
|
||||
{
|
||||
public ColorBlendState ColorBlendState;
|
||||
public DepthStencilState DepthStencilState;
|
||||
public ShaderStageState VertexShaderState;
|
||||
public ShaderStageState FragmentShaderState;
|
||||
public MultisampleState MultisampleState;
|
||||
public GraphicsPipelineLayoutInfo PipelineLayoutInfo;
|
||||
public RasterizerState RasterizerState;
|
||||
public PrimitiveType PrimitiveType;
|
||||
public VertexInputState VertexInputState;
|
||||
public ViewportState ViewportState;
|
||||
public RenderPass RenderPass;
|
||||
}
|
||||
public struct GraphicsPipelineCreateInfo
|
||||
{
|
||||
public ColorBlendState ColorBlendState;
|
||||
public DepthStencilState DepthStencilState;
|
||||
public ShaderStageState VertexShaderState;
|
||||
public ShaderStageState FragmentShaderState;
|
||||
public MultisampleState MultisampleState;
|
||||
public GraphicsPipelineLayoutInfo PipelineLayoutInfo;
|
||||
public RasterizerState RasterizerState;
|
||||
public PrimitiveType PrimitiveType;
|
||||
public VertexInputState VertexInputState;
|
||||
public ViewportState ViewportState;
|
||||
public RenderPass RenderPass;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
namespace MoonWorks.Graphics
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes how many samplers will be used in each shader stage.
|
||||
/// </summary>
|
||||
public struct GraphicsPipelineLayoutInfo
|
||||
{
|
||||
public uint VertexSamplerBindingCount;
|
||||
public uint FragmentSamplerBindingCount;
|
||||
}
|
||||
/// <summary>
|
||||
/// Describes how many samplers will be used in each shader stage.
|
||||
/// </summary>
|
||||
public struct GraphicsPipelineLayoutInfo
|
||||
{
|
||||
public uint VertexSamplerBindingCount;
|
||||
public uint FragmentSamplerBindingCount;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
namespace MoonWorks.Graphics
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies how many samples should be used in rasterization.
|
||||
/// </summary>
|
||||
public struct MultisampleState
|
||||
{
|
||||
public SampleCount MultisampleCount;
|
||||
public uint SampleMask;
|
||||
/// <summary>
|
||||
/// Specifies how many samples should be used in rasterization.
|
||||
/// </summary>
|
||||
public struct MultisampleState
|
||||
{
|
||||
public SampleCount MultisampleCount;
|
||||
public uint SampleMask;
|
||||
|
||||
public static readonly MultisampleState None = new MultisampleState
|
||||
{
|
||||
MultisampleCount = SampleCount.One,
|
||||
SampleMask = uint.MaxValue
|
||||
};
|
||||
}
|
||||
public static readonly MultisampleState None = new MultisampleState
|
||||
{
|
||||
MultisampleCount = SampleCount.One,
|
||||
SampleMask = uint.MaxValue
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,121 +1,121 @@
|
|||
namespace MoonWorks.Graphics
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies how the rasterizer should be configured for a graphics pipeline.
|
||||
/// </summary>
|
||||
public struct RasterizerState
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies whether front faces, back faces, none, or both should be culled.
|
||||
/// </summary>
|
||||
public CullMode CullMode;
|
||||
/// <summary>
|
||||
/// Specifies how the rasterizer should be configured for a graphics pipeline.
|
||||
/// </summary>
|
||||
public struct RasterizerState
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies whether front faces, back faces, none, or both should be culled.
|
||||
/// </summary>
|
||||
public CullMode CullMode;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies maximum depth bias of a fragment. Only applies if depth biasing is enabled.
|
||||
/// </summary>
|
||||
public float DepthBiasClamp;
|
||||
/// <summary>
|
||||
/// Specifies maximum depth bias of a fragment. Only applies if depth biasing is enabled.
|
||||
/// </summary>
|
||||
public float DepthBiasClamp;
|
||||
|
||||
/// <summary>
|
||||
/// The constant depth value added to each fragment. Only applies if depth biasing is enabled.
|
||||
/// </summary>
|
||||
public float DepthBiasConstantFactor;
|
||||
/// <summary>
|
||||
/// The constant depth value added to each fragment. Only applies if depth biasing is enabled.
|
||||
/// </summary>
|
||||
public float DepthBiasConstantFactor;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether depth biasing is enabled. Only applies if depth biasing is enabled.
|
||||
/// </summary>
|
||||
public bool DepthBiasEnable;
|
||||
/// <summary>
|
||||
/// Specifies whether depth biasing is enabled. Only applies if depth biasing is enabled.
|
||||
/// </summary>
|
||||
public bool DepthBiasEnable;
|
||||
|
||||
/// <summary>
|
||||
/// Factor applied to a fragment's slope in depth bias calculations. Only applies if depth biasing is enabled.
|
||||
/// </summary>
|
||||
public float DepthBiasSlopeFactor;
|
||||
public bool DepthClampEnable;
|
||||
/// <summary>
|
||||
/// Factor applied to a fragment's slope in depth bias calculations. Only applies if depth biasing is enabled.
|
||||
/// </summary>
|
||||
public float DepthBiasSlopeFactor;
|
||||
public bool DepthClampEnable;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies how triangles should be drawn.
|
||||
/// </summary>
|
||||
public FillMode FillMode;
|
||||
/// <summary>
|
||||
/// Specifies how triangles should be drawn.
|
||||
/// </summary>
|
||||
public FillMode FillMode;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies which triangle winding order is designated as front-facing.
|
||||
/// </summary>
|
||||
public FrontFace FrontFace;
|
||||
/// <summary>
|
||||
/// Specifies which triangle winding order is designated as front-facing.
|
||||
/// </summary>
|
||||
public FrontFace FrontFace;
|
||||
|
||||
/// <summary>
|
||||
/// Describes the width of the line rendering in terms of pixels.
|
||||
/// </summary>
|
||||
public float LineWidth;
|
||||
/// <summary>
|
||||
/// Describes the width of the line rendering in terms of pixels.
|
||||
/// </summary>
|
||||
public float LineWidth;
|
||||
|
||||
public static readonly RasterizerState CW_CullFront = new RasterizerState
|
||||
{
|
||||
CullMode = CullMode.Front,
|
||||
FrontFace = FrontFace.Clockwise,
|
||||
FillMode = FillMode.Fill,
|
||||
DepthBiasEnable = false,
|
||||
LineWidth = 1f
|
||||
};
|
||||
public static readonly RasterizerState CW_CullFront = new RasterizerState
|
||||
{
|
||||
CullMode = CullMode.Front,
|
||||
FrontFace = FrontFace.Clockwise,
|
||||
FillMode = FillMode.Fill,
|
||||
DepthBiasEnable = false,
|
||||
LineWidth = 1f
|
||||
};
|
||||
|
||||
public static readonly RasterizerState CW_CullBack = new RasterizerState
|
||||
{
|
||||
CullMode = CullMode.Back,
|
||||
FrontFace = FrontFace.Clockwise,
|
||||
FillMode = FillMode.Fill,
|
||||
DepthBiasEnable = false,
|
||||
LineWidth = 1f
|
||||
};
|
||||
public static readonly RasterizerState CW_CullBack = new RasterizerState
|
||||
{
|
||||
CullMode = CullMode.Back,
|
||||
FrontFace = FrontFace.Clockwise,
|
||||
FillMode = FillMode.Fill,
|
||||
DepthBiasEnable = false,
|
||||
LineWidth = 1f
|
||||
};
|
||||
|
||||
public static readonly RasterizerState CW_CullNone = new RasterizerState
|
||||
{
|
||||
CullMode = CullMode.None,
|
||||
FrontFace = FrontFace.Clockwise,
|
||||
FillMode = FillMode.Fill,
|
||||
DepthBiasEnable = false,
|
||||
LineWidth = 1f
|
||||
};
|
||||
public static readonly RasterizerState CW_CullNone = new RasterizerState
|
||||
{
|
||||
CullMode = CullMode.None,
|
||||
FrontFace = FrontFace.Clockwise,
|
||||
FillMode = FillMode.Fill,
|
||||
DepthBiasEnable = false,
|
||||
LineWidth = 1f
|
||||
};
|
||||
|
||||
public static readonly RasterizerState CW_Wireframe = new RasterizerState
|
||||
{
|
||||
CullMode = CullMode.None,
|
||||
FrontFace = FrontFace.Clockwise,
|
||||
FillMode = FillMode.Fill,
|
||||
DepthBiasEnable = false,
|
||||
LineWidth = 1f
|
||||
};
|
||||
public static readonly RasterizerState CW_Wireframe = new RasterizerState
|
||||
{
|
||||
CullMode = CullMode.None,
|
||||
FrontFace = FrontFace.Clockwise,
|
||||
FillMode = FillMode.Fill,
|
||||
DepthBiasEnable = false,
|
||||
LineWidth = 1f
|
||||
};
|
||||
|
||||
public static readonly RasterizerState CCW_CullFront = new RasterizerState
|
||||
{
|
||||
CullMode = CullMode.Front,
|
||||
FrontFace = FrontFace.CounterClockwise,
|
||||
FillMode = FillMode.Fill,
|
||||
DepthBiasEnable = false,
|
||||
LineWidth = 1f
|
||||
};
|
||||
public static readonly RasterizerState CCW_CullFront = new RasterizerState
|
||||
{
|
||||
CullMode = CullMode.Front,
|
||||
FrontFace = FrontFace.CounterClockwise,
|
||||
FillMode = FillMode.Fill,
|
||||
DepthBiasEnable = false,
|
||||
LineWidth = 1f
|
||||
};
|
||||
|
||||
public static readonly RasterizerState CCW_CullBack = new RasterizerState
|
||||
{
|
||||
CullMode = CullMode.Back,
|
||||
FrontFace = FrontFace.CounterClockwise,
|
||||
FillMode = FillMode.Fill,
|
||||
DepthBiasEnable = false,
|
||||
LineWidth = 1f
|
||||
};
|
||||
public static readonly RasterizerState CCW_CullBack = new RasterizerState
|
||||
{
|
||||
CullMode = CullMode.Back,
|
||||
FrontFace = FrontFace.CounterClockwise,
|
||||
FillMode = FillMode.Fill,
|
||||
DepthBiasEnable = false,
|
||||
LineWidth = 1f
|
||||
};
|
||||
|
||||
public static readonly RasterizerState CCW_CullNone = new RasterizerState
|
||||
{
|
||||
CullMode = CullMode.None,
|
||||
FrontFace = FrontFace.CounterClockwise,
|
||||
FillMode = FillMode.Fill,
|
||||
DepthBiasEnable = false,
|
||||
LineWidth = 1f
|
||||
};
|
||||
public static readonly RasterizerState CCW_CullNone = new RasterizerState
|
||||
{
|
||||
CullMode = CullMode.None,
|
||||
FrontFace = FrontFace.CounterClockwise,
|
||||
FillMode = FillMode.Fill,
|
||||
DepthBiasEnable = false,
|
||||
LineWidth = 1f
|
||||
};
|
||||
|
||||
public static readonly RasterizerState CCW_Wireframe = new RasterizerState
|
||||
{
|
||||
CullMode = CullMode.None,
|
||||
FrontFace = FrontFace.CounterClockwise,
|
||||
FillMode = FillMode.Fill,
|
||||
DepthBiasEnable = false,
|
||||
LineWidth = 1f
|
||||
};
|
||||
}
|
||||
public static readonly RasterizerState CCW_Wireframe = new RasterizerState
|
||||
{
|
||||
CullMode = CullMode.None,
|
||||
FrontFace = FrontFace.CounterClockwise,
|
||||
FillMode = FillMode.Fill,
|
||||
DepthBiasEnable = false,
|
||||
LineWidth = 1f
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,134 +2,134 @@
|
|||
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
public struct SamplerCreateInfo
|
||||
{
|
||||
public Filter MinFilter;
|
||||
public Filter MagFilter;
|
||||
public SamplerMipmapMode MipmapMode;
|
||||
public SamplerAddressMode AddressModeU;
|
||||
public SamplerAddressMode AddressModeV;
|
||||
public SamplerAddressMode AddressModeW;
|
||||
public float MipLodBias;
|
||||
public bool AnisotropyEnable;
|
||||
public float MaxAnisotropy;
|
||||
public bool CompareEnable;
|
||||
public CompareOp CompareOp;
|
||||
public float MinLod;
|
||||
public float MaxLod;
|
||||
public BorderColor BorderColor;
|
||||
public struct SamplerCreateInfo
|
||||
{
|
||||
public Filter MinFilter;
|
||||
public Filter MagFilter;
|
||||
public SamplerMipmapMode MipmapMode;
|
||||
public SamplerAddressMode AddressModeU;
|
||||
public SamplerAddressMode AddressModeV;
|
||||
public SamplerAddressMode AddressModeW;
|
||||
public float MipLodBias;
|
||||
public bool AnisotropyEnable;
|
||||
public float MaxAnisotropy;
|
||||
public bool CompareEnable;
|
||||
public CompareOp CompareOp;
|
||||
public float MinLod;
|
||||
public float MaxLod;
|
||||
public BorderColor BorderColor;
|
||||
|
||||
public static readonly SamplerCreateInfo AnisotropicClamp = new SamplerCreateInfo
|
||||
{
|
||||
MinFilter = Filter.Linear,
|
||||
MagFilter = Filter.Linear,
|
||||
MipmapMode = SamplerMipmapMode.Linear,
|
||||
AddressModeU = SamplerAddressMode.ClampToEdge,
|
||||
AddressModeV = SamplerAddressMode.ClampToEdge,
|
||||
AddressModeW = SamplerAddressMode.ClampToEdge,
|
||||
CompareEnable = false,
|
||||
AnisotropyEnable = true,
|
||||
MaxAnisotropy = 4,
|
||||
MipLodBias = 0f,
|
||||
MinLod = 0,
|
||||
MaxLod = 1000 /* VK_LOD_CLAMP_NONE */
|
||||
};
|
||||
public static readonly SamplerCreateInfo AnisotropicClamp = new SamplerCreateInfo
|
||||
{
|
||||
MinFilter = Filter.Linear,
|
||||
MagFilter = Filter.Linear,
|
||||
MipmapMode = SamplerMipmapMode.Linear,
|
||||
AddressModeU = SamplerAddressMode.ClampToEdge,
|
||||
AddressModeV = SamplerAddressMode.ClampToEdge,
|
||||
AddressModeW = SamplerAddressMode.ClampToEdge,
|
||||
CompareEnable = false,
|
||||
AnisotropyEnable = true,
|
||||
MaxAnisotropy = 4,
|
||||
MipLodBias = 0f,
|
||||
MinLod = 0,
|
||||
MaxLod = 1000 /* VK_LOD_CLAMP_NONE */
|
||||
};
|
||||
|
||||
public static readonly SamplerCreateInfo AnisotropicWrap = new SamplerCreateInfo
|
||||
{
|
||||
MinFilter = Filter.Linear,
|
||||
MagFilter = Filter.Linear,
|
||||
MipmapMode = SamplerMipmapMode.Linear,
|
||||
AddressModeU = SamplerAddressMode.Repeat,
|
||||
AddressModeV = SamplerAddressMode.Repeat,
|
||||
AddressModeW = SamplerAddressMode.Repeat,
|
||||
CompareEnable = false,
|
||||
AnisotropyEnable = true,
|
||||
MaxAnisotropy = 4,
|
||||
MipLodBias = 0f,
|
||||
MinLod = 0,
|
||||
MaxLod = 1000 /* VK_LOD_CLAMP_NONE */
|
||||
};
|
||||
public static readonly SamplerCreateInfo AnisotropicWrap = new SamplerCreateInfo
|
||||
{
|
||||
MinFilter = Filter.Linear,
|
||||
MagFilter = Filter.Linear,
|
||||
MipmapMode = SamplerMipmapMode.Linear,
|
||||
AddressModeU = SamplerAddressMode.Repeat,
|
||||
AddressModeV = SamplerAddressMode.Repeat,
|
||||
AddressModeW = SamplerAddressMode.Repeat,
|
||||
CompareEnable = false,
|
||||
AnisotropyEnable = true,
|
||||
MaxAnisotropy = 4,
|
||||
MipLodBias = 0f,
|
||||
MinLod = 0,
|
||||
MaxLod = 1000 /* VK_LOD_CLAMP_NONE */
|
||||
};
|
||||
|
||||
public static readonly SamplerCreateInfo LinearClamp = new SamplerCreateInfo
|
||||
{
|
||||
MinFilter = Filter.Linear,
|
||||
MagFilter = Filter.Linear,
|
||||
MipmapMode = SamplerMipmapMode.Linear,
|
||||
AddressModeU = SamplerAddressMode.ClampToEdge,
|
||||
AddressModeV = SamplerAddressMode.ClampToEdge,
|
||||
AddressModeW = SamplerAddressMode.ClampToEdge,
|
||||
CompareEnable = false,
|
||||
AnisotropyEnable = false,
|
||||
MipLodBias = 0f,
|
||||
MinLod = 0,
|
||||
MaxLod = 1000
|
||||
};
|
||||
public static readonly SamplerCreateInfo LinearClamp = new SamplerCreateInfo
|
||||
{
|
||||
MinFilter = Filter.Linear,
|
||||
MagFilter = Filter.Linear,
|
||||
MipmapMode = SamplerMipmapMode.Linear,
|
||||
AddressModeU = SamplerAddressMode.ClampToEdge,
|
||||
AddressModeV = SamplerAddressMode.ClampToEdge,
|
||||
AddressModeW = SamplerAddressMode.ClampToEdge,
|
||||
CompareEnable = false,
|
||||
AnisotropyEnable = false,
|
||||
MipLodBias = 0f,
|
||||
MinLod = 0,
|
||||
MaxLod = 1000
|
||||
};
|
||||
|
||||
public static readonly SamplerCreateInfo LinearWrap = new SamplerCreateInfo
|
||||
{
|
||||
MinFilter = Filter.Linear,
|
||||
MagFilter = Filter.Linear,
|
||||
MipmapMode = SamplerMipmapMode.Linear,
|
||||
AddressModeU = SamplerAddressMode.Repeat,
|
||||
AddressModeV = SamplerAddressMode.Repeat,
|
||||
AddressModeW = SamplerAddressMode.Repeat,
|
||||
CompareEnable = false,
|
||||
AnisotropyEnable = false,
|
||||
MipLodBias = 0f,
|
||||
MinLod = 0,
|
||||
MaxLod = 1000
|
||||
};
|
||||
public static readonly SamplerCreateInfo LinearWrap = new SamplerCreateInfo
|
||||
{
|
||||
MinFilter = Filter.Linear,
|
||||
MagFilter = Filter.Linear,
|
||||
MipmapMode = SamplerMipmapMode.Linear,
|
||||
AddressModeU = SamplerAddressMode.Repeat,
|
||||
AddressModeV = SamplerAddressMode.Repeat,
|
||||
AddressModeW = SamplerAddressMode.Repeat,
|
||||
CompareEnable = false,
|
||||
AnisotropyEnable = false,
|
||||
MipLodBias = 0f,
|
||||
MinLod = 0,
|
||||
MaxLod = 1000
|
||||
};
|
||||
|
||||
public static readonly SamplerCreateInfo PointClamp = new SamplerCreateInfo
|
||||
{
|
||||
MinFilter = Filter.Nearest,
|
||||
MagFilter = Filter.Nearest,
|
||||
MipmapMode = SamplerMipmapMode.Nearest,
|
||||
AddressModeU = SamplerAddressMode.ClampToEdge,
|
||||
AddressModeV = SamplerAddressMode.ClampToEdge,
|
||||
AddressModeW = SamplerAddressMode.ClampToEdge,
|
||||
CompareEnable = false,
|
||||
AnisotropyEnable = false,
|
||||
MipLodBias = 0f,
|
||||
MinLod = 0,
|
||||
MaxLod = 1000
|
||||
};
|
||||
public static readonly SamplerCreateInfo PointClamp = new SamplerCreateInfo
|
||||
{
|
||||
MinFilter = Filter.Nearest,
|
||||
MagFilter = Filter.Nearest,
|
||||
MipmapMode = SamplerMipmapMode.Nearest,
|
||||
AddressModeU = SamplerAddressMode.ClampToEdge,
|
||||
AddressModeV = SamplerAddressMode.ClampToEdge,
|
||||
AddressModeW = SamplerAddressMode.ClampToEdge,
|
||||
CompareEnable = false,
|
||||
AnisotropyEnable = false,
|
||||
MipLodBias = 0f,
|
||||
MinLod = 0,
|
||||
MaxLod = 1000
|
||||
};
|
||||
|
||||
public static readonly SamplerCreateInfo PointWrap = new SamplerCreateInfo
|
||||
{
|
||||
MinFilter = Filter.Nearest,
|
||||
MagFilter = Filter.Nearest,
|
||||
MipmapMode = SamplerMipmapMode.Nearest,
|
||||
AddressModeU = SamplerAddressMode.Repeat,
|
||||
AddressModeV = SamplerAddressMode.Repeat,
|
||||
AddressModeW = SamplerAddressMode.Repeat,
|
||||
CompareEnable = false,
|
||||
AnisotropyEnable = false,
|
||||
MipLodBias = 0f,
|
||||
MinLod = 0,
|
||||
MaxLod = 1000
|
||||
};
|
||||
public static readonly SamplerCreateInfo PointWrap = new SamplerCreateInfo
|
||||
{
|
||||
MinFilter = Filter.Nearest,
|
||||
MagFilter = Filter.Nearest,
|
||||
MipmapMode = SamplerMipmapMode.Nearest,
|
||||
AddressModeU = SamplerAddressMode.Repeat,
|
||||
AddressModeV = SamplerAddressMode.Repeat,
|
||||
AddressModeW = SamplerAddressMode.Repeat,
|
||||
CompareEnable = false,
|
||||
AnisotropyEnable = false,
|
||||
MipLodBias = 0f,
|
||||
MinLod = 0,
|
||||
MaxLod = 1000
|
||||
};
|
||||
|
||||
public Refresh.SamplerStateCreateInfo ToRefreshSamplerStateCreateInfo()
|
||||
{
|
||||
return new Refresh.SamplerStateCreateInfo
|
||||
{
|
||||
minFilter = (Refresh.Filter)MinFilter,
|
||||
magFilter = (Refresh.Filter)MagFilter,
|
||||
mipmapMode = (Refresh.SamplerMipmapMode)MipmapMode,
|
||||
addressModeU = (Refresh.SamplerAddressMode)AddressModeU,
|
||||
addressModeV = (Refresh.SamplerAddressMode)AddressModeV,
|
||||
addressModeW = (Refresh.SamplerAddressMode)AddressModeW,
|
||||
mipLodBias = MipLodBias,
|
||||
anisotropyEnable = Conversions.BoolToByte(AnisotropyEnable),
|
||||
maxAnisotropy = MaxAnisotropy,
|
||||
compareEnable = Conversions.BoolToByte(CompareEnable),
|
||||
compareOp = (Refresh.CompareOp)CompareOp,
|
||||
minLod = MinLod,
|
||||
maxLod = MaxLod,
|
||||
borderColor = (Refresh.BorderColor)BorderColor
|
||||
};
|
||||
}
|
||||
}
|
||||
public Refresh.SamplerStateCreateInfo ToRefreshSamplerStateCreateInfo()
|
||||
{
|
||||
return new Refresh.SamplerStateCreateInfo
|
||||
{
|
||||
minFilter = (Refresh.Filter) MinFilter,
|
||||
magFilter = (Refresh.Filter) MagFilter,
|
||||
mipmapMode = (Refresh.SamplerMipmapMode) MipmapMode,
|
||||
addressModeU = (Refresh.SamplerAddressMode) AddressModeU,
|
||||
addressModeV = (Refresh.SamplerAddressMode) AddressModeV,
|
||||
addressModeW = (Refresh.SamplerAddressMode) AddressModeW,
|
||||
mipLodBias = MipLodBias,
|
||||
anisotropyEnable = Conversions.BoolToByte(AnisotropyEnable),
|
||||
maxAnisotropy = MaxAnisotropy,
|
||||
compareEnable = Conversions.BoolToByte(CompareEnable),
|
||||
compareOp = (Refresh.CompareOp) CompareOp,
|
||||
minLod = MinLod,
|
||||
maxLod = MaxLod,
|
||||
borderColor = (Refresh.BorderColor) BorderColor
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
namespace MoonWorks.Graphics
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies how the graphics pipeline will make use of a shader.
|
||||
/// </summary>
|
||||
public struct ShaderStageState
|
||||
{
|
||||
public ShaderModule ShaderModule;
|
||||
public string EntryPointName;
|
||||
public uint UniformBufferSize;
|
||||
}
|
||||
/// <summary>
|
||||
/// Specifies how the graphics pipeline will make use of a shader.
|
||||
/// </summary>
|
||||
public struct ShaderStageState
|
||||
{
|
||||
public ShaderModule ShaderModule;
|
||||
public string EntryPointName;
|
||||
public uint UniformBufferSize;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,30 +2,30 @@
|
|||
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
public struct TextureCreateInfo
|
||||
{
|
||||
public uint Width;
|
||||
public uint Height;
|
||||
public uint Depth;
|
||||
public bool IsCube;
|
||||
public SampleCount SampleCount;
|
||||
public uint LevelCount;
|
||||
public TextureFormat Format;
|
||||
public TextureUsageFlags UsageFlags;
|
||||
public struct TextureCreateInfo
|
||||
{
|
||||
public uint Width;
|
||||
public uint Height;
|
||||
public uint Depth;
|
||||
public bool IsCube;
|
||||
public SampleCount SampleCount;
|
||||
public uint LevelCount;
|
||||
public TextureFormat Format;
|
||||
public TextureUsageFlags UsageFlags;
|
||||
|
||||
public Refresh.TextureCreateInfo ToRefreshTextureCreateInfo()
|
||||
{
|
||||
return new Refresh.TextureCreateInfo
|
||||
{
|
||||
width = Width,
|
||||
height = Height,
|
||||
depth = Depth,
|
||||
isCube = Conversions.BoolToByte(IsCube),
|
||||
sampleCount = (Refresh.SampleCount) SampleCount,
|
||||
levelCount = LevelCount,
|
||||
format = (Refresh.TextureFormat) Format,
|
||||
usageFlags = (Refresh.TextureUsageFlags) UsageFlags
|
||||
};
|
||||
}
|
||||
}
|
||||
public Refresh.TextureCreateInfo ToRefreshTextureCreateInfo()
|
||||
{
|
||||
return new Refresh.TextureCreateInfo
|
||||
{
|
||||
width = Width,
|
||||
height = Height,
|
||||
depth = Depth,
|
||||
isCube = Conversions.BoolToByte(IsCube),
|
||||
sampleCount = (Refresh.SampleCount) SampleCount,
|
||||
levelCount = LevelCount,
|
||||
format = (Refresh.TextureFormat) Format,
|
||||
usageFlags = (Refresh.TextureUsageFlags) UsageFlags
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
namespace MoonWorks.Graphics
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies how to interpet vertex data in a buffer to be passed to the vertex shader.
|
||||
/// </summary>
|
||||
public struct VertexInputState
|
||||
{
|
||||
public VertexBinding[] VertexBindings;
|
||||
public VertexAttribute[] VertexAttributes;
|
||||
}
|
||||
/// <summary>
|
||||
/// Specifies how to interpet vertex data in a buffer to be passed to the vertex shader.
|
||||
/// </summary>
|
||||
public struct VertexInputState
|
||||
{
|
||||
public VertexBinding[] VertexBindings;
|
||||
public VertexAttribute[] VertexAttributes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
namespace MoonWorks.Graphics
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// Describes the dimensions of viewports and scissor areas.
|
||||
/// </summary>
|
||||
public struct ViewportState
|
||||
{
|
||||
public Viewport[] Viewports;
|
||||
public Rect[] Scissors;
|
||||
}
|
||||
/// <summary>
|
||||
/// Describes the dimensions of viewports and scissor areas.
|
||||
/// </summary>
|
||||
public struct ViewportState
|
||||
{
|
||||
public Viewport[] Viewports;
|
||||
public Rect[] Scissors;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
namespace MoonWorks.Graphics
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
public struct BlendConstants
|
||||
{
|
||||
public float R;
|
||||
public float G;
|
||||
public float B;
|
||||
public float A;
|
||||
}
|
||||
public struct BlendConstants
|
||||
{
|
||||
public float R;
|
||||
public float G;
|
||||
public float B;
|
||||
public float A;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,54 +2,54 @@
|
|||
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
/// <summary>
|
||||
/// A texture slice specifies a subregion of a texture.
|
||||
/// Many operations can use texture slices in place of textures for the sake of convenience.
|
||||
/// </summary>
|
||||
public struct TextureSlice
|
||||
{
|
||||
public Texture Texture { get; }
|
||||
public Rect Rectangle { get; }
|
||||
public uint Depth { get; }
|
||||
public uint Layer { get; }
|
||||
public uint Level { get; }
|
||||
/// <summary>
|
||||
/// A texture slice specifies a subregion of a texture.
|
||||
/// Many operations can use texture slices in place of textures for the sake of convenience.
|
||||
/// </summary>
|
||||
public struct TextureSlice
|
||||
{
|
||||
public Texture Texture { get; }
|
||||
public Rect Rectangle { get; }
|
||||
public uint Depth { get; }
|
||||
public uint Layer { get; }
|
||||
public uint Level { get; }
|
||||
|
||||
public TextureSlice(Texture texture)
|
||||
{
|
||||
Texture = texture;
|
||||
Rectangle = new Rect
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
W = (int) texture.Width,
|
||||
H = (int) texture.Height
|
||||
};
|
||||
Depth = 0;
|
||||
Layer = 0;
|
||||
Level = 0;
|
||||
}
|
||||
public TextureSlice(Texture texture)
|
||||
{
|
||||
Texture = texture;
|
||||
Rectangle = new Rect
|
||||
{
|
||||
X = 0,
|
||||
Y = 0,
|
||||
W = (int) texture.Width,
|
||||
H = (int) texture.Height
|
||||
};
|
||||
Depth = 0;
|
||||
Layer = 0;
|
||||
Level = 0;
|
||||
}
|
||||
|
||||
public TextureSlice(Texture texture, Rect rectangle, uint depth = 0, uint layer = 0, uint level = 0)
|
||||
{
|
||||
Texture = texture;
|
||||
Rectangle = rectangle;
|
||||
Depth = depth;
|
||||
Layer = layer;
|
||||
Level = level;
|
||||
}
|
||||
public TextureSlice(Texture texture, Rect rectangle, uint depth = 0, uint layer = 0, uint level = 0)
|
||||
{
|
||||
Texture = texture;
|
||||
Rectangle = rectangle;
|
||||
Depth = depth;
|
||||
Layer = layer;
|
||||
Level = level;
|
||||
}
|
||||
|
||||
public Refresh.TextureSlice ToRefreshTextureSlice()
|
||||
{
|
||||
Refresh.TextureSlice textureSlice = new Refresh.TextureSlice
|
||||
{
|
||||
texture = Texture.Handle,
|
||||
rectangle = Rectangle.ToRefresh(),
|
||||
depth = Depth,
|
||||
layer = Layer,
|
||||
level = Level
|
||||
};
|
||||
public Refresh.TextureSlice ToRefreshTextureSlice()
|
||||
{
|
||||
Refresh.TextureSlice textureSlice = new Refresh.TextureSlice
|
||||
{
|
||||
texture = Texture.Handle,
|
||||
rectangle = Rectangle.ToRefresh(),
|
||||
depth = Depth,
|
||||
layer = Layer,
|
||||
level = Level
|
||||
};
|
||||
|
||||
return textureSlice;
|
||||
}
|
||||
}
|
||||
return textureSlice;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,32 +2,32 @@
|
|||
|
||||
namespace MoonWorks.Graphics
|
||||
{
|
||||
public static class Bytecode
|
||||
{
|
||||
public static uint[] ReadBytecodeAsUInt32(string filePath)
|
||||
{
|
||||
byte[] data;
|
||||
int size;
|
||||
using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
size = (int)stream.Length;
|
||||
data = new byte[size];
|
||||
stream.Read(data, 0, size);
|
||||
}
|
||||
public static class Bytecode
|
||||
{
|
||||
public static uint[] ReadBytecodeAsUInt32(string filePath)
|
||||
{
|
||||
byte[] data;
|
||||
int size;
|
||||
using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
size = (int) stream.Length;
|
||||
data = new byte[size];
|
||||
stream.Read(data, 0, size);
|
||||
}
|
||||
|
||||
uint[] uintData = new uint[size / 4];
|
||||
using (var memoryStream = new MemoryStream(data))
|
||||
{
|
||||
using (var reader = new BinaryReader(memoryStream))
|
||||
{
|
||||
for (int i = 0; i < size / 4; i++)
|
||||
{
|
||||
uintData[i] = reader.ReadUInt32();
|
||||
}
|
||||
}
|
||||
}
|
||||
uint[] uintData = new uint[size / 4];
|
||||
using (var memoryStream = new MemoryStream(data))
|
||||
{
|
||||
using (var reader = new BinaryReader(memoryStream))
|
||||
{
|
||||
for (int i = 0; i < size / 4; i++)
|
||||
{
|
||||
uintData[i] = reader.ReadUInt32();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return uintData;
|
||||
}
|
||||
}
|
||||
return uintData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
namespace MoonWorks
|
||||
namespace MoonWorks
|
||||
{
|
||||
public static class Conversions
|
||||
{
|
||||
public static byte BoolToByte(bool b)
|
||||
{
|
||||
return (byte)(b ? 1 : 0);
|
||||
}
|
||||
public static class Conversions
|
||||
{
|
||||
public static byte BoolToByte(bool b)
|
||||
{
|
||||
return (byte) (b ? 1 : 0);
|
||||
}
|
||||
|
||||
public static bool ByteToBool(byte b)
|
||||
{
|
||||
return b == 0 ? false : true;
|
||||
}
|
||||
}
|
||||
public static bool ByteToBool(byte b)
|
||||
{
|
||||
return b == 0 ? false : true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,31 @@
|
|||
namespace MoonWorks.Input
|
||||
namespace MoonWorks.Input
|
||||
{
|
||||
public class ButtonState
|
||||
{
|
||||
private ButtonStatus ButtonStatus { get; set; }
|
||||
public class ButtonState
|
||||
{
|
||||
private ButtonStatus ButtonStatus { get; set; }
|
||||
|
||||
public bool IsPressed => ButtonStatus == ButtonStatus.Pressed;
|
||||
public bool IsHeld => ButtonStatus == ButtonStatus.Held;
|
||||
public bool IsDown => ButtonStatus == ButtonStatus.Pressed || ButtonStatus == ButtonStatus.Held;
|
||||
public bool IsReleased => ButtonStatus == ButtonStatus.Released;
|
||||
public bool IsPressed => ButtonStatus == ButtonStatus.Pressed;
|
||||
public bool IsHeld => ButtonStatus == ButtonStatus.Held;
|
||||
public bool IsDown => ButtonStatus == ButtonStatus.Pressed || ButtonStatus == ButtonStatus.Held;
|
||||
public bool IsReleased => ButtonStatus == ButtonStatus.Released;
|
||||
|
||||
internal void Update(bool isPressed)
|
||||
{
|
||||
if (isPressed)
|
||||
{
|
||||
if (ButtonStatus == ButtonStatus.Pressed)
|
||||
{
|
||||
ButtonStatus = ButtonStatus.Held;
|
||||
}
|
||||
else if (ButtonStatus == ButtonStatus.Released)
|
||||
{
|
||||
ButtonStatus = ButtonStatus.Pressed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ButtonStatus = ButtonStatus.Released;
|
||||
}
|
||||
}
|
||||
}
|
||||
internal void Update(bool isPressed)
|
||||
{
|
||||
if (isPressed)
|
||||
{
|
||||
if (ButtonStatus == ButtonStatus.Pressed)
|
||||
{
|
||||
ButtonStatus = ButtonStatus.Held;
|
||||
}
|
||||
else if (ButtonStatus == ButtonStatus.Released)
|
||||
{
|
||||
ButtonStatus = ButtonStatus.Pressed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ButtonStatus = ButtonStatus.Released;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
namespace MoonWorks.Input
|
||||
namespace MoonWorks.Input
|
||||
{
|
||||
internal enum ButtonStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates that the input is not pressed.
|
||||
/// </summary>
|
||||
Released,
|
||||
/// <summary>
|
||||
/// Indicates that the input was pressed this frame.
|
||||
/// </summary>
|
||||
Pressed,
|
||||
/// <summary>
|
||||
/// Indicates that the input has been held for multiple frames.
|
||||
/// </summary>
|
||||
Held
|
||||
}
|
||||
internal enum ButtonStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates that the input is not pressed.
|
||||
/// </summary>
|
||||
Released,
|
||||
/// <summary>
|
||||
/// Indicates that the input was pressed this frame.
|
||||
/// </summary>
|
||||
Pressed,
|
||||
/// <summary>
|
||||
/// Indicates that the input has been held for multiple frames.
|
||||
/// </summary>
|
||||
Held
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,98 +1,98 @@
|
|||
using System;
|
||||
using System;
|
||||
using MoonWorks.Math;
|
||||
using SDL2;
|
||||
|
||||
namespace MoonWorks.Input
|
||||
{
|
||||
public class Gamepad
|
||||
{
|
||||
internal IntPtr Handle;
|
||||
public class Gamepad
|
||||
{
|
||||
internal IntPtr Handle;
|
||||
|
||||
public ButtonState A { get; } = new ButtonState();
|
||||
public ButtonState B { get; } = new ButtonState();
|
||||
public ButtonState X { get; } = new ButtonState();
|
||||
public ButtonState Y { get; } = new ButtonState();
|
||||
public ButtonState Back { get; } = new ButtonState();
|
||||
public ButtonState Guide { get; } = new ButtonState();
|
||||
public ButtonState Start { get; } = new ButtonState();
|
||||
public ButtonState LeftStick { get; } = new ButtonState();
|
||||
public ButtonState RightStick { get; } = new ButtonState();
|
||||
public ButtonState LeftShoulder { get; } = new ButtonState();
|
||||
public ButtonState RightShoulder { get; } = new ButtonState();
|
||||
public ButtonState DpadUp { get; } = new ButtonState();
|
||||
public ButtonState DpadDown { get; } = new ButtonState();
|
||||
public ButtonState DpadLeft { get; } = new ButtonState();
|
||||
public ButtonState DpadRight { get; } = new ButtonState();
|
||||
public ButtonState A { get; } = new ButtonState();
|
||||
public ButtonState B { get; } = new ButtonState();
|
||||
public ButtonState X { get; } = new ButtonState();
|
||||
public ButtonState Y { get; } = new ButtonState();
|
||||
public ButtonState Back { get; } = new ButtonState();
|
||||
public ButtonState Guide { get; } = new ButtonState();
|
||||
public ButtonState Start { get; } = new ButtonState();
|
||||
public ButtonState LeftStick { get; } = new ButtonState();
|
||||
public ButtonState RightStick { get; } = new ButtonState();
|
||||
public ButtonState LeftShoulder { get; } = new ButtonState();
|
||||
public ButtonState RightShoulder { get; } = new ButtonState();
|
||||
public ButtonState DpadUp { get; } = new ButtonState();
|
||||
public ButtonState DpadDown { get; } = new ButtonState();
|
||||
public ButtonState DpadLeft { get; } = new ButtonState();
|
||||
public ButtonState DpadRight { get; } = new ButtonState();
|
||||
|
||||
public float LeftX { get; private set; }
|
||||
public float LeftY { get; private set; }
|
||||
public float RightX { get; private set; }
|
||||
public float RightY { get; private set; }
|
||||
public float TriggerLeft { get; private set; }
|
||||
public float TriggerRight { get; private set; }
|
||||
public float LeftX { get; private set; }
|
||||
public float LeftY { get; private set; }
|
||||
public float RightX { get; private set; }
|
||||
public float RightY { get; private set; }
|
||||
public float TriggerLeft { get; private set; }
|
||||
public float TriggerRight { get; private set; }
|
||||
|
||||
internal Gamepad(IntPtr handle)
|
||||
{
|
||||
Handle = handle;
|
||||
}
|
||||
internal Gamepad(IntPtr handle)
|
||||
{
|
||||
Handle = handle;
|
||||
}
|
||||
|
||||
public bool SetVibration(float leftMotor, float rightMotor, uint durationInMilliseconds)
|
||||
{
|
||||
return SDL.SDL_GameControllerRumble(
|
||||
Handle,
|
||||
(ushort)(MathHelper.Clamp(leftMotor, 0f, 1f) * 0xFFFF),
|
||||
(ushort)(MathHelper.Clamp(rightMotor, 0f, 1f) * 0xFFFF),
|
||||
durationInMilliseconds
|
||||
) == 0;
|
||||
}
|
||||
public bool SetVibration(float leftMotor, float rightMotor, uint durationInMilliseconds)
|
||||
{
|
||||
return SDL.SDL_GameControllerRumble(
|
||||
Handle,
|
||||
(ushort) (MathHelper.Clamp(leftMotor, 0f, 1f) * 0xFFFF),
|
||||
(ushort) (MathHelper.Clamp(rightMotor, 0f, 1f) * 0xFFFF),
|
||||
durationInMilliseconds
|
||||
) == 0;
|
||||
}
|
||||
|
||||
internal void Update()
|
||||
{
|
||||
A.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_A));
|
||||
B.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_B));
|
||||
X.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_X));
|
||||
Y.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_Y));
|
||||
Back.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_BACK));
|
||||
Guide.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_GUIDE));
|
||||
Start.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_START));
|
||||
LeftStick.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSTICK));
|
||||
RightStick.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSTICK));
|
||||
LeftShoulder.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSHOULDER));
|
||||
RightShoulder.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSHOULDER));
|
||||
DpadUp.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_UP));
|
||||
DpadDown.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_DOWN));
|
||||
DpadLeft.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_LEFT));
|
||||
DpadRight.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_RIGHT));
|
||||
internal void Update()
|
||||
{
|
||||
A.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_A));
|
||||
B.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_B));
|
||||
X.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_X));
|
||||
Y.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_Y));
|
||||
Back.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_BACK));
|
||||
Guide.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_GUIDE));
|
||||
Start.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_START));
|
||||
LeftStick.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSTICK));
|
||||
RightStick.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSTICK));
|
||||
LeftShoulder.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_LEFTSHOULDER));
|
||||
RightShoulder.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_RIGHTSHOULDER));
|
||||
DpadUp.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_UP));
|
||||
DpadDown.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_DOWN));
|
||||
DpadLeft.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_LEFT));
|
||||
DpadRight.Update(IsPressed(SDL.SDL_GameControllerButton.SDL_CONTROLLER_BUTTON_DPAD_RIGHT));
|
||||
|
||||
LeftX = UpdateAxis(SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTX);
|
||||
LeftY = UpdateAxis(SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTY);
|
||||
RightX = UpdateAxis(SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTX);
|
||||
RightY = UpdateAxis(SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTY);
|
||||
TriggerLeft = UpdateTrigger(SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERLEFT);
|
||||
TriggerRight = UpdateTrigger(SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERRIGHT);
|
||||
}
|
||||
LeftX = UpdateAxis(SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTX);
|
||||
LeftY = UpdateAxis(SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_LEFTY);
|
||||
RightX = UpdateAxis(SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTX);
|
||||
RightY = UpdateAxis(SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_RIGHTY);
|
||||
TriggerLeft = UpdateTrigger(SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERLEFT);
|
||||
TriggerRight = UpdateTrigger(SDL.SDL_GameControllerAxis.SDL_CONTROLLER_AXIS_TRIGGERRIGHT);
|
||||
}
|
||||
|
||||
private bool IsPressed(SDL.SDL_GameControllerButton button)
|
||||
{
|
||||
return MoonWorks.Conversions.ByteToBool(SDL.SDL_GameControllerGetButton(Handle, button));
|
||||
}
|
||||
private bool IsPressed(SDL.SDL_GameControllerButton button)
|
||||
{
|
||||
return MoonWorks.Conversions.ByteToBool(SDL.SDL_GameControllerGetButton(Handle, button));
|
||||
}
|
||||
|
||||
private float UpdateAxis(SDL.SDL_GameControllerAxis axis)
|
||||
{
|
||||
var axisValue = SDL.SDL_GameControllerGetAxis(Handle, axis);
|
||||
return Normalize(axisValue, short.MinValue, short.MaxValue, -1, 1);
|
||||
}
|
||||
private float UpdateAxis(SDL.SDL_GameControllerAxis axis)
|
||||
{
|
||||
var axisValue = SDL.SDL_GameControllerGetAxis(Handle, axis);
|
||||
return Normalize(axisValue, short.MinValue, short.MaxValue, -1, 1);
|
||||
}
|
||||
|
||||
// Triggers only go from 0 to short.MaxValue
|
||||
private float UpdateTrigger(SDL.SDL_GameControllerAxis trigger)
|
||||
{
|
||||
var triggerValue = SDL.SDL_GameControllerGetAxis(Handle, trigger);
|
||||
return Normalize(triggerValue, 0, short.MaxValue, 0, 1);
|
||||
}
|
||||
// Triggers only go from 0 to short.MaxValue
|
||||
private float UpdateTrigger(SDL.SDL_GameControllerAxis trigger)
|
||||
{
|
||||
var triggerValue = SDL.SDL_GameControllerGetAxis(Handle, trigger);
|
||||
return Normalize(triggerValue, 0, short.MaxValue, 0, 1);
|
||||
}
|
||||
|
||||
private float Normalize(float value, short min, short max, short newMin, short newMax)
|
||||
{
|
||||
return ((value - min) * (newMax - newMin)) / (max - min) + newMin;
|
||||
}
|
||||
}
|
||||
private float Normalize(float value, short min, short max, short newMin, short newMax)
|
||||
{
|
||||
return ((value - min) * (newMax - newMin)) / (max - min) + newMin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,60 +1,60 @@
|
|||
using SDL2;
|
||||
using SDL2;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MoonWorks.Input
|
||||
{
|
||||
public class Inputs
|
||||
{
|
||||
public Keyboard Keyboard { get; }
|
||||
public Mouse Mouse { get; }
|
||||
public class Inputs
|
||||
{
|
||||
public Keyboard Keyboard { get; }
|
||||
public Mouse Mouse { get; }
|
||||
|
||||
List<Gamepad> gamepads = new List<Gamepad>();
|
||||
List<Gamepad> gamepads = new List<Gamepad>();
|
||||
|
||||
public static event Action<char> TextInput;
|
||||
public static event Action<char> TextInput;
|
||||
|
||||
internal Inputs()
|
||||
{
|
||||
Keyboard = new Keyboard();
|
||||
Mouse = new Mouse();
|
||||
internal Inputs()
|
||||
{
|
||||
Keyboard = new Keyboard();
|
||||
Mouse = new Mouse();
|
||||
|
||||
for (int i = 0; i < SDL.SDL_NumJoysticks(); i++)
|
||||
{
|
||||
if (SDL.SDL_IsGameController(i) == SDL.SDL_bool.SDL_TRUE)
|
||||
{
|
||||
gamepads.Add(new Gamepad(SDL.SDL_GameControllerOpen(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < SDL.SDL_NumJoysticks(); i++)
|
||||
{
|
||||
if (SDL.SDL_IsGameController(i) == SDL.SDL_bool.SDL_TRUE)
|
||||
{
|
||||
gamepads.Add(new Gamepad(SDL.SDL_GameControllerOpen(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Assumes that SDL_PumpEvents has been called!
|
||||
internal void Update()
|
||||
{
|
||||
Keyboard.Update();
|
||||
Mouse.Update();
|
||||
// Assumes that SDL_PumpEvents has been called!
|
||||
internal void Update()
|
||||
{
|
||||
Keyboard.Update();
|
||||
Mouse.Update();
|
||||
|
||||
foreach (var gamepad in gamepads)
|
||||
{
|
||||
gamepad.Update();
|
||||
}
|
||||
}
|
||||
foreach (var gamepad in gamepads)
|
||||
{
|
||||
gamepad.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public bool GamepadExists(int slot)
|
||||
{
|
||||
return slot < gamepads.Count;
|
||||
}
|
||||
public bool GamepadExists(int slot)
|
||||
{
|
||||
return slot < gamepads.Count;
|
||||
}
|
||||
|
||||
public Gamepad GetGamepad(int slot)
|
||||
{
|
||||
return gamepads[slot];
|
||||
}
|
||||
public Gamepad GetGamepad(int slot)
|
||||
{
|
||||
return gamepads[slot];
|
||||
}
|
||||
|
||||
internal static void OnTextInput(char c)
|
||||
{
|
||||
if (TextInput != null)
|
||||
{
|
||||
TextInput(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
internal static void OnTextInput(char c)
|
||||
{
|
||||
if (TextInput != null)
|
||||
{
|
||||
TextInput(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using SDL2;
|
||||
|
||||
namespace MoonWorks.Input
|
||||
{
|
||||
public class Keyboard
|
||||
{
|
||||
private ButtonState[] Keys { get; }
|
||||
private int numKeys;
|
||||
public class Keyboard
|
||||
{
|
||||
private ButtonState[] Keys { get; }
|
||||
private int numKeys;
|
||||
|
||||
private static readonly char[] TextInputCharacters = new char[]
|
||||
{
|
||||
|
@ -21,69 +21,69 @@ namespace MoonWorks.Input
|
|||
(char) 22 // Ctrl+V (Paste)
|
||||
};
|
||||
|
||||
private static readonly Dictionary<Keycode, int> TextInputBindings = new Dictionary<Keycode, int>()
|
||||
private static readonly Dictionary<Keycode, int> TextInputBindings = new Dictionary<Keycode, int>()
|
||||
{
|
||||
{ Keycode.Home, 0 },
|
||||
{ Keycode.End, 1 },
|
||||
{ Keycode.Backspace, 2 },
|
||||
{ Keycode.Tab, 3 },
|
||||
{ Keycode.Return, 4 },
|
||||
{ Keycode.Delete, 5 }
|
||||
{ Keycode.Home, 0 },
|
||||
{ Keycode.End, 1 },
|
||||
{ Keycode.Backspace, 2 },
|
||||
{ Keycode.Tab, 3 },
|
||||
{ Keycode.Return, 4 },
|
||||
{ Keycode.Delete, 5 }
|
||||
// Ctrl+V is special!
|
||||
};
|
||||
|
||||
internal Keyboard()
|
||||
{
|
||||
SDL.SDL_GetKeyboardState(out numKeys);
|
||||
internal Keyboard()
|
||||
{
|
||||
SDL.SDL_GetKeyboardState(out numKeys);
|
||||
|
||||
Keys = new ButtonState[numKeys];
|
||||
foreach (Keycode keycode in Enum.GetValues(typeof(Keycode)))
|
||||
{
|
||||
Keys[(int)keycode] = new ButtonState();
|
||||
}
|
||||
}
|
||||
Keys = new ButtonState[numKeys];
|
||||
foreach (Keycode keycode in Enum.GetValues(typeof(Keycode)))
|
||||
{
|
||||
Keys[(int) keycode] = new ButtonState();
|
||||
}
|
||||
}
|
||||
|
||||
internal void Update()
|
||||
{
|
||||
IntPtr keyboardState = SDL.SDL_GetKeyboardState(out _);
|
||||
internal void Update()
|
||||
{
|
||||
IntPtr keyboardState = SDL.SDL_GetKeyboardState(out _);
|
||||
|
||||
foreach (int keycode in Enum.GetValues(typeof(Keycode)))
|
||||
{
|
||||
var keyDown = Marshal.ReadByte(keyboardState, keycode);
|
||||
Keys[keycode].Update(Conversions.ByteToBool(keyDown));
|
||||
foreach (int keycode in Enum.GetValues(typeof(Keycode)))
|
||||
{
|
||||
var keyDown = Marshal.ReadByte(keyboardState, keycode);
|
||||
Keys[keycode].Update(Conversions.ByteToBool(keyDown));
|
||||
|
||||
if (Conversions.ByteToBool(keyDown))
|
||||
{
|
||||
if (TextInputBindings.TryGetValue((Keycode)keycode, out var textIndex))
|
||||
{
|
||||
Inputs.OnTextInput(TextInputCharacters[(textIndex)]);
|
||||
}
|
||||
else if (IsDown(Keycode.LeftControl) && (Keycode)keycode == Keycode.V)
|
||||
{
|
||||
Inputs.OnTextInput(TextInputCharacters[6]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Conversions.ByteToBool(keyDown))
|
||||
{
|
||||
if (TextInputBindings.TryGetValue((Keycode) keycode, out var textIndex))
|
||||
{
|
||||
Inputs.OnTextInput(TextInputCharacters[(textIndex)]);
|
||||
}
|
||||
else if (IsDown(Keycode.LeftControl) && (Keycode) keycode == Keycode.V)
|
||||
{
|
||||
Inputs.OnTextInput(TextInputCharacters[6]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDown(Keycode keycode)
|
||||
{
|
||||
return Keys[(int)keycode].IsDown;
|
||||
}
|
||||
public bool IsDown(Keycode keycode)
|
||||
{
|
||||
return Keys[(int) keycode].IsDown;
|
||||
}
|
||||
|
||||
public bool IsPressed(Keycode keycode)
|
||||
{
|
||||
return Keys[(int)keycode].IsPressed;
|
||||
}
|
||||
public bool IsPressed(Keycode keycode)
|
||||
{
|
||||
return Keys[(int) keycode].IsPressed;
|
||||
}
|
||||
|
||||
public bool IsHeld(Keycode keycode)
|
||||
{
|
||||
return Keys[(int)keycode].IsHeld;
|
||||
}
|
||||
public bool IsHeld(Keycode keycode)
|
||||
{
|
||||
return Keys[(int) keycode].IsHeld;
|
||||
}
|
||||
|
||||
public bool IsReleased(Keycode keycode)
|
||||
{
|
||||
return Keys[(int)keycode].IsReleased;
|
||||
}
|
||||
}
|
||||
public bool IsReleased(Keycode keycode)
|
||||
{
|
||||
return Keys[(int) keycode].IsReleased;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,113 +1,113 @@
|
|||
namespace MoonWorks.Input
|
||||
namespace MoonWorks.Input
|
||||
{
|
||||
// Enum values are equivalent to the SDL Scancode value.
|
||||
public enum Keycode : int
|
||||
{
|
||||
Unknown = 0,
|
||||
A = 4,
|
||||
B = 5,
|
||||
C = 6,
|
||||
D = 7,
|
||||
E = 8,
|
||||
F = 9,
|
||||
G = 10,
|
||||
H = 11,
|
||||
I = 12,
|
||||
J = 13,
|
||||
K = 14,
|
||||
L = 15,
|
||||
M = 16,
|
||||
N = 17,
|
||||
O = 18,
|
||||
P = 19,
|
||||
Q = 20,
|
||||
R = 21,
|
||||
S = 22,
|
||||
T = 23,
|
||||
U = 24,
|
||||
V = 25,
|
||||
W = 26,
|
||||
X = 27,
|
||||
Y = 28,
|
||||
Z = 29,
|
||||
D1 = 30,
|
||||
D2 = 31,
|
||||
D3 = 32,
|
||||
D4 = 33,
|
||||
D5 = 34,
|
||||
D6 = 35,
|
||||
D7 = 36,
|
||||
D8 = 37,
|
||||
D9 = 38,
|
||||
D0 = 39,
|
||||
Return = 40,
|
||||
Escape = 41,
|
||||
Backspace = 42,
|
||||
Tab = 43,
|
||||
Space = 44,
|
||||
Minus = 45,
|
||||
Equals = 46,
|
||||
LeftBracket = 47,
|
||||
RightBracket = 48,
|
||||
Backslash = 49,
|
||||
NonUSHash = 50,
|
||||
Semicolon = 51,
|
||||
Apostrophe = 52,
|
||||
Grave = 53,
|
||||
Comma = 54,
|
||||
Period = 55,
|
||||
Slash = 56,
|
||||
CapsLock = 57,
|
||||
F1 = 58,
|
||||
F2 = 59,
|
||||
F3 = 60,
|
||||
F4 = 61,
|
||||
F5 = 62,
|
||||
F6 = 63,
|
||||
F7 = 64,
|
||||
F8 = 65,
|
||||
F9 = 66,
|
||||
F10 = 67,
|
||||
F11 = 68,
|
||||
F12 = 69,
|
||||
PrintScreen = 70,
|
||||
ScrollLock = 71,
|
||||
Pause = 72,
|
||||
Insert = 73,
|
||||
Home = 74,
|
||||
PageUp = 75,
|
||||
Delete = 76,
|
||||
End = 77,
|
||||
PageDown = 78,
|
||||
Right = 79,
|
||||
Left = 80,
|
||||
Down = 81,
|
||||
Up = 82,
|
||||
NumLockClear = 83,
|
||||
KeypadDivide = 84,
|
||||
KeypadMultiply = 85,
|
||||
KeypadMinus = 86,
|
||||
KeypadPlus = 87,
|
||||
KeypadEnter = 88,
|
||||
Keypad1 = 89,
|
||||
Keypad2 = 90,
|
||||
Keypad3 = 91,
|
||||
Keypad4 = 92,
|
||||
Keypad5 = 93,
|
||||
Keypad6 = 94,
|
||||
Keypad7 = 95,
|
||||
Keypad8 = 96,
|
||||
Keypad9 = 97,
|
||||
Keypad0 = 98,
|
||||
KeypadPeriod = 99,
|
||||
NonUSBackslash = 100,
|
||||
LeftControl = 224,
|
||||
LeftShift = 225,
|
||||
LeftAlt = 226,
|
||||
LeftMeta = 227, // Windows, Command, Meta
|
||||
RightControl = 228,
|
||||
RightShift = 229,
|
||||
RightAlt = 230,
|
||||
RightMeta = 231 // Windows, Command, Meta
|
||||
}
|
||||
// Enum values are equivalent to the SDL Scancode value.
|
||||
public enum Keycode : int
|
||||
{
|
||||
Unknown = 0,
|
||||
A = 4,
|
||||
B = 5,
|
||||
C = 6,
|
||||
D = 7,
|
||||
E = 8,
|
||||
F = 9,
|
||||
G = 10,
|
||||
H = 11,
|
||||
I = 12,
|
||||
J = 13,
|
||||
K = 14,
|
||||
L = 15,
|
||||
M = 16,
|
||||
N = 17,
|
||||
O = 18,
|
||||
P = 19,
|
||||
Q = 20,
|
||||
R = 21,
|
||||
S = 22,
|
||||
T = 23,
|
||||
U = 24,
|
||||
V = 25,
|
||||
W = 26,
|
||||
X = 27,
|
||||
Y = 28,
|
||||
Z = 29,
|
||||
D1 = 30,
|
||||
D2 = 31,
|
||||
D3 = 32,
|
||||
D4 = 33,
|
||||
D5 = 34,
|
||||
D6 = 35,
|
||||
D7 = 36,
|
||||
D8 = 37,
|
||||
D9 = 38,
|
||||
D0 = 39,
|
||||
Return = 40,
|
||||
Escape = 41,
|
||||
Backspace = 42,
|
||||
Tab = 43,
|
||||
Space = 44,
|
||||
Minus = 45,
|
||||
Equals = 46,
|
||||
LeftBracket = 47,
|
||||
RightBracket = 48,
|
||||
Backslash = 49,
|
||||
NonUSHash = 50,
|
||||
Semicolon = 51,
|
||||
Apostrophe = 52,
|
||||
Grave = 53,
|
||||
Comma = 54,
|
||||
Period = 55,
|
||||
Slash = 56,
|
||||
CapsLock = 57,
|
||||
F1 = 58,
|
||||
F2 = 59,
|
||||
F3 = 60,
|
||||
F4 = 61,
|
||||
F5 = 62,
|
||||
F6 = 63,
|
||||
F7 = 64,
|
||||
F8 = 65,
|
||||
F9 = 66,
|
||||
F10 = 67,
|
||||
F11 = 68,
|
||||
F12 = 69,
|
||||
PrintScreen = 70,
|
||||
ScrollLock = 71,
|
||||
Pause = 72,
|
||||
Insert = 73,
|
||||
Home = 74,
|
||||
PageUp = 75,
|
||||
Delete = 76,
|
||||
End = 77,
|
||||
PageDown = 78,
|
||||
Right = 79,
|
||||
Left = 80,
|
||||
Down = 81,
|
||||
Up = 82,
|
||||
NumLockClear = 83,
|
||||
KeypadDivide = 84,
|
||||
KeypadMultiply = 85,
|
||||
KeypadMinus = 86,
|
||||
KeypadPlus = 87,
|
||||
KeypadEnter = 88,
|
||||
Keypad1 = 89,
|
||||
Keypad2 = 90,
|
||||
Keypad3 = 91,
|
||||
Keypad4 = 92,
|
||||
Keypad5 = 93,
|
||||
Keypad6 = 94,
|
||||
Keypad7 = 95,
|
||||
Keypad8 = 96,
|
||||
Keypad9 = 97,
|
||||
Keypad0 = 98,
|
||||
KeypadPeriod = 99,
|
||||
NonUSBackslash = 100,
|
||||
LeftControl = 224,
|
||||
LeftShift = 225,
|
||||
LeftAlt = 226,
|
||||
LeftMeta = 227, // Windows, Command, Meta
|
||||
RightControl = 228,
|
||||
RightShift = 229,
|
||||
RightAlt = 230,
|
||||
RightMeta = 231 // Windows, Command, Meta
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,52 +2,52 @@
|
|||
|
||||
namespace MoonWorks.Input
|
||||
{
|
||||
public class Mouse
|
||||
{
|
||||
public ButtonState LeftButton { get; } = new ButtonState();
|
||||
public ButtonState MiddleButton { get; } = new ButtonState();
|
||||
public ButtonState RightButton { get; } = new ButtonState();
|
||||
public class Mouse
|
||||
{
|
||||
public ButtonState LeftButton { get; } = new ButtonState();
|
||||
public ButtonState MiddleButton { get; } = new ButtonState();
|
||||
public ButtonState RightButton { get; } = new ButtonState();
|
||||
|
||||
public int X { get; private set; }
|
||||
public int Y { get; private set; }
|
||||
public int DeltaX { get; private set; }
|
||||
public int DeltaY { get; private set; }
|
||||
public int X { get; private set; }
|
||||
public int Y { get; private set; }
|
||||
public int DeltaX { get; private set; }
|
||||
public int DeltaY { get; private set; }
|
||||
|
||||
public int Wheel { get; internal set; }
|
||||
public int Wheel { get; internal set; }
|
||||
|
||||
private bool relativeMode;
|
||||
public bool RelativeMode
|
||||
{
|
||||
get => relativeMode;
|
||||
set
|
||||
{
|
||||
relativeMode = value;
|
||||
SDL.SDL_SetRelativeMouseMode(
|
||||
relativeMode ?
|
||||
SDL.SDL_bool.SDL_TRUE :
|
||||
SDL.SDL_bool.SDL_FALSE
|
||||
);
|
||||
}
|
||||
}
|
||||
private bool relativeMode;
|
||||
public bool RelativeMode
|
||||
{
|
||||
get => relativeMode;
|
||||
set
|
||||
{
|
||||
relativeMode = value;
|
||||
SDL.SDL_SetRelativeMouseMode(
|
||||
relativeMode ?
|
||||
SDL.SDL_bool.SDL_TRUE :
|
||||
SDL.SDL_bool.SDL_FALSE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
internal void Update()
|
||||
{
|
||||
var buttonMask = SDL.SDL_GetMouseState(out var x, out var y);
|
||||
var _ = SDL.SDL_GetRelativeMouseState(out var deltaX, out var deltaY);
|
||||
internal void Update()
|
||||
{
|
||||
var buttonMask = SDL.SDL_GetMouseState(out var x, out var y);
|
||||
var _ = SDL.SDL_GetRelativeMouseState(out var deltaX, out var deltaY);
|
||||
|
||||
X = x;
|
||||
Y = y;
|
||||
DeltaX = deltaX;
|
||||
DeltaY = deltaY;
|
||||
X = x;
|
||||
Y = y;
|
||||
DeltaX = deltaX;
|
||||
DeltaY = deltaY;
|
||||
|
||||
LeftButton.Update(IsPressed(buttonMask, SDL.SDL_BUTTON_LMASK));
|
||||
MiddleButton.Update(IsPressed(buttonMask, SDL.SDL_BUTTON_MMASK));
|
||||
RightButton.Update(IsPressed(buttonMask, SDL.SDL_BUTTON_RMASK));
|
||||
}
|
||||
LeftButton.Update(IsPressed(buttonMask, SDL.SDL_BUTTON_LMASK));
|
||||
MiddleButton.Update(IsPressed(buttonMask, SDL.SDL_BUTTON_MMASK));
|
||||
RightButton.Update(IsPressed(buttonMask, SDL.SDL_BUTTON_RMASK));
|
||||
}
|
||||
|
||||
private bool IsPressed(uint buttonMask, uint buttonFlag)
|
||||
{
|
||||
return (buttonMask & buttonFlag) != 0;
|
||||
}
|
||||
}
|
||||
private bool IsPressed(uint buttonMask, uint buttonFlag)
|
||||
{
|
||||
return (buttonMask & buttonFlag) != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
110
src/Logger.cs
110
src/Logger.cs
|
@ -1,69 +1,69 @@
|
|||
using System;
|
||||
using System;
|
||||
using RefreshCS;
|
||||
|
||||
namespace MoonWorks
|
||||
{
|
||||
public static class Logger
|
||||
{
|
||||
public static Action<string> LogInfo;
|
||||
public static Action<string> LogWarn;
|
||||
public static Action<string> LogError;
|
||||
public static class Logger
|
||||
{
|
||||
public static Action<string> LogInfo;
|
||||
public static Action<string> LogWarn;
|
||||
public static Action<string> LogError;
|
||||
|
||||
private static RefreshCS.Refresh.Refresh_LogFunc LogInfoFunc = RefreshLogInfo;
|
||||
private static RefreshCS.Refresh.Refresh_LogFunc LogWarnFunc = RefreshLogWarn;
|
||||
private static RefreshCS.Refresh.Refresh_LogFunc LogErrorFunc = RefreshLogError;
|
||||
private static RefreshCS.Refresh.Refresh_LogFunc LogInfoFunc = RefreshLogInfo;
|
||||
private static RefreshCS.Refresh.Refresh_LogFunc LogWarnFunc = RefreshLogWarn;
|
||||
private static RefreshCS.Refresh.Refresh_LogFunc LogErrorFunc = RefreshLogError;
|
||||
|
||||
internal static void Initialize()
|
||||
{
|
||||
if (Logger.LogInfo == null)
|
||||
{
|
||||
Logger.LogInfo = Console.WriteLine;
|
||||
}
|
||||
if (Logger.LogWarn == null)
|
||||
{
|
||||
Logger.LogWarn = Console.WriteLine;
|
||||
}
|
||||
if (Logger.LogError == null)
|
||||
{
|
||||
Logger.LogError = Console.WriteLine;
|
||||
}
|
||||
internal static void Initialize()
|
||||
{
|
||||
if (Logger.LogInfo == null)
|
||||
{
|
||||
Logger.LogInfo = Console.WriteLine;
|
||||
}
|
||||
if (Logger.LogWarn == null)
|
||||
{
|
||||
Logger.LogWarn = Console.WriteLine;
|
||||
}
|
||||
if (Logger.LogError == null)
|
||||
{
|
||||
Logger.LogError = Console.WriteLine;
|
||||
}
|
||||
|
||||
Refresh.Refresh_HookLogFunctions(
|
||||
LogInfoFunc,
|
||||
LogWarnFunc,
|
||||
LogErrorFunc
|
||||
);
|
||||
}
|
||||
Refresh.Refresh_HookLogFunctions(
|
||||
LogInfoFunc,
|
||||
LogWarnFunc,
|
||||
LogErrorFunc
|
||||
);
|
||||
}
|
||||
|
||||
private static void RefreshLogInfo(IntPtr msg)
|
||||
{
|
||||
LogInfo(UTF8_ToManaged(msg));
|
||||
}
|
||||
private static void RefreshLogInfo(IntPtr msg)
|
||||
{
|
||||
LogInfo(UTF8_ToManaged(msg));
|
||||
}
|
||||
|
||||
private static void RefreshLogWarn(IntPtr msg)
|
||||
{
|
||||
LogWarn(UTF8_ToManaged(msg));
|
||||
}
|
||||
private static void RefreshLogWarn(IntPtr msg)
|
||||
{
|
||||
LogWarn(UTF8_ToManaged(msg));
|
||||
}
|
||||
|
||||
private static void RefreshLogError(IntPtr msg)
|
||||
{
|
||||
LogError(UTF8_ToManaged(msg));
|
||||
}
|
||||
private static void RefreshLogError(IntPtr msg)
|
||||
{
|
||||
LogError(UTF8_ToManaged(msg));
|
||||
}
|
||||
|
||||
private unsafe static string UTF8_ToManaged(IntPtr s)
|
||||
{
|
||||
byte* ptr = (byte*) s;
|
||||
while (*ptr != 0)
|
||||
{
|
||||
ptr += 1;
|
||||
}
|
||||
private unsafe static string UTF8_ToManaged(IntPtr s)
|
||||
{
|
||||
byte* ptr = (byte*) s;
|
||||
while (*ptr != 0)
|
||||
{
|
||||
ptr += 1;
|
||||
}
|
||||
|
||||
string result = System.Text.Encoding.UTF8.GetString(
|
||||
(byte*) s,
|
||||
(int) (ptr - (byte*) s)
|
||||
);
|
||||
string result = System.Text.Encoding.UTF8.GetString(
|
||||
(byte*) s,
|
||||
(int) (ptr - (byte*) s)
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
@ -91,23 +91,23 @@ namespace MoonWorks.Math
|
|||
public ContainmentType Contains(BoundingBox box)
|
||||
{
|
||||
// Test if all corner is in the same side of a face by just checking min and max
|
||||
if ( box.Max.X < Min.X ||
|
||||
if (box.Max.X < Min.X ||
|
||||
box.Min.X > Max.X ||
|
||||
box.Max.Y < Min.Y ||
|
||||
box.Min.Y > Max.Y ||
|
||||
box.Max.Z < Min.Z ||
|
||||
box.Min.Z > Max.Z )
|
||||
box.Min.Z > Max.Z)
|
||||
{
|
||||
return ContainmentType.Disjoint;
|
||||
}
|
||||
|
||||
|
||||
if ( box.Min.X >= Min.X &&
|
||||
if (box.Min.X >= Min.X &&
|
||||
box.Max.X <= Max.X &&
|
||||
box.Min.Y >= Min.Y &&
|
||||
box.Max.Y <= Max.Y &&
|
||||
box.Min.Z >= Min.Z &&
|
||||
box.Max.Z <= Max.Z )
|
||||
box.Max.Z <= Max.Z)
|
||||
{
|
||||
return ContainmentType.Contains;
|
||||
}
|
||||
|
@ -172,12 +172,12 @@ namespace MoonWorks.Math
|
|||
|
||||
public ContainmentType Contains(BoundingSphere sphere)
|
||||
{
|
||||
if ( sphere.Center.X - Min.X >= sphere.Radius &&
|
||||
if (sphere.Center.X - Min.X >= sphere.Radius &&
|
||||
sphere.Center.Y - Min.Y >= sphere.Radius &&
|
||||
sphere.Center.Z - Min.Z >= sphere.Radius &&
|
||||
Max.X - sphere.Center.X >= sphere.Radius &&
|
||||
Max.Y - sphere.Center.Y >= sphere.Radius &&
|
||||
Max.Z - sphere.Center.Z >= sphere.Radius )
|
||||
Max.Z - sphere.Center.Z >= sphere.Radius)
|
||||
{
|
||||
return ContainmentType.Contains;
|
||||
}
|
||||
|
@ -261,12 +261,12 @@ namespace MoonWorks.Math
|
|||
public void Contains(ref Vector3 point, out ContainmentType result)
|
||||
{
|
||||
// Determine if point is outside of this box.
|
||||
if ( point.X < this.Min.X ||
|
||||
if (point.X < this.Min.X ||
|
||||
point.X > this.Max.X ||
|
||||
point.Y < this.Min.Y ||
|
||||
point.Y > this.Max.Y ||
|
||||
point.Z < this.Min.Z ||
|
||||
point.Z > this.Max.Z )
|
||||
point.Z > this.Max.Z)
|
||||
{
|
||||
result = ContainmentType.Disjoint;
|
||||
}
|
||||
|
@ -380,12 +380,12 @@ namespace MoonWorks.Math
|
|||
|
||||
public bool Intersects(BoundingSphere sphere)
|
||||
{
|
||||
if ( sphere.Center.X - Min.X > sphere.Radius &&
|
||||
if (sphere.Center.X - Min.X > sphere.Radius &&
|
||||
sphere.Center.Y - Min.Y > sphere.Radius &&
|
||||
sphere.Center.Z - Min.Z > sphere.Radius &&
|
||||
Max.X - sphere.Center.X > sphere.Radius &&
|
||||
Max.Y - sphere.Center.Y > sphere.Radius &&
|
||||
Max.Z - sphere.Center.Z > sphere.Radius )
|
||||
Max.Z - sphere.Center.Z > sphere.Radius)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
@ -230,12 +230,12 @@ namespace MoonWorks.Math
|
|||
box.Intersects(ref this.planes[i], out planeIntersectionType);
|
||||
switch (planeIntersectionType)
|
||||
{
|
||||
case PlaneIntersectionType.Front:
|
||||
result = ContainmentType.Disjoint;
|
||||
return;
|
||||
case PlaneIntersectionType.Intersecting:
|
||||
intersects = true;
|
||||
break;
|
||||
case PlaneIntersectionType.Front:
|
||||
result = ContainmentType.Disjoint;
|
||||
return;
|
||||
case PlaneIntersectionType.Intersecting:
|
||||
intersects = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
result = intersects ? ContainmentType.Intersects : ContainmentType.Contains;
|
||||
|
@ -269,12 +269,12 @@ namespace MoonWorks.Math
|
|||
sphere.Intersects(ref this.planes[i], out planeIntersectionType);
|
||||
switch (planeIntersectionType)
|
||||
{
|
||||
case PlaneIntersectionType.Front:
|
||||
result = ContainmentType.Disjoint;
|
||||
return;
|
||||
case PlaneIntersectionType.Intersecting:
|
||||
intersects = true;
|
||||
break;
|
||||
case PlaneIntersectionType.Front:
|
||||
result = ContainmentType.Disjoint;
|
||||
return;
|
||||
case PlaneIntersectionType.Intersecting:
|
||||
intersects = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
result = intersects ? ContainmentType.Intersects : ContainmentType.Contains;
|
||||
|
@ -597,7 +597,8 @@ namespace MoonWorks.Math
|
|||
ref Plane b,
|
||||
ref Plane c,
|
||||
out Vector3 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
/* Formula used
|
||||
* d1 ( N2 * N3 ) + d2 ( N3 * N1 ) + d3 ( N1 * N2 )
|
||||
* P = -------------------------------------------------------------------
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
@ -297,8 +297,8 @@ namespace MoonWorks.Math
|
|||
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
|
||||
public bool Equals(BoundingSphere other)
|
||||
{
|
||||
return ( Center == other.Center &&
|
||||
Radius == other.Radius );
|
||||
return (Center == other.Center &&
|
||||
Radius == other.Radius);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -474,7 +474,8 @@ namespace MoonWorks.Math
|
|||
ref BoundingSphere original,
|
||||
ref BoundingSphere additional,
|
||||
out BoundingSphere result
|
||||
) {
|
||||
)
|
||||
{
|
||||
Vector3 ocenterToaCenter = Vector3.Subtract(additional.Center, original.Center);
|
||||
float distance = ocenterToaCenter.Length();
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
@ -98,7 +98,8 @@ namespace MoonWorks.Math
|
|||
float value3,
|
||||
float amount1,
|
||||
float amount2
|
||||
) {
|
||||
)
|
||||
{
|
||||
return value1 + (value2 - value1) * amount1 + (value3 - value1) * amount2;
|
||||
}
|
||||
|
||||
|
@ -117,7 +118,8 @@ namespace MoonWorks.Math
|
|||
float value3,
|
||||
float value4,
|
||||
float amount
|
||||
) {
|
||||
)
|
||||
{
|
||||
/* Using formula from http://www.mvps.org/directx/articles/catmull/
|
||||
* Internally using doubles not to lose precision.
|
||||
*/
|
||||
|
@ -184,7 +186,8 @@ namespace MoonWorks.Math
|
|||
float value2,
|
||||
float tangent2,
|
||||
float amount
|
||||
) {
|
||||
)
|
||||
{
|
||||
/* All transformed to double not to lose precision
|
||||
* Otherwise, for high numbers of param:amount the result is NaN instead
|
||||
* of Infinity.
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
@ -316,7 +316,8 @@ namespace MoonWorks.Math
|
|||
float m21, float m22, float m23, float m24,
|
||||
float m31, float m32, float m33, float m34,
|
||||
float m41, float m42, float m43, float m44
|
||||
) {
|
||||
)
|
||||
{
|
||||
M11 = m11;
|
||||
M12 = m12;
|
||||
M13 = m13;
|
||||
|
@ -350,7 +351,8 @@ namespace MoonWorks.Math
|
|||
out Vector3 scale,
|
||||
out Quaternion rotation,
|
||||
out Vector3 translation
|
||||
) {
|
||||
)
|
||||
{
|
||||
translation.X = M41;
|
||||
translation.Y = M42;
|
||||
translation.Z = M43;
|
||||
|
@ -363,9 +365,9 @@ namespace MoonWorks.Math
|
|||
scale.Y = ys * (float) System.Math.Sqrt(M21 * M21 + M22 * M22 + M23 * M23);
|
||||
scale.Z = zs * (float) System.Math.Sqrt(M31 * M31 + M32 * M32 + M33 * M33);
|
||||
|
||||
if ( MathHelper.WithinEpsilon(scale.X, 0.0f) ||
|
||||
if (MathHelper.WithinEpsilon(scale.X, 0.0f) ||
|
||||
MathHelper.WithinEpsilon(scale.Y, 0.0f) ||
|
||||
MathHelper.WithinEpsilon(scale.Z, 0.0f) )
|
||||
MathHelper.WithinEpsilon(scale.Z, 0.0f))
|
||||
{
|
||||
rotation = Quaternion.Identity;
|
||||
return false;
|
||||
|
@ -413,7 +415,7 @@ namespace MoonWorks.Math
|
|||
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
|
||||
public bool Equals(Matrix4x4 other)
|
||||
{
|
||||
return ( M11 == other.M11 &&
|
||||
return (M11 == other.M11 &&
|
||||
M12 == other.M12 &&
|
||||
M13 == other.M13 &&
|
||||
M14 == other.M14 &&
|
||||
|
@ -428,7 +430,7 @@ namespace MoonWorks.Math
|
|||
M41 == other.M41 &&
|
||||
M42 == other.M42 &&
|
||||
M43 == other.M43 &&
|
||||
M44 == other.M44 );
|
||||
M44 == other.M44);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -555,7 +557,8 @@ namespace MoonWorks.Math
|
|||
Vector3 cameraPosition,
|
||||
Vector3 cameraUpVector,
|
||||
Nullable<Vector3> cameraForwardVector
|
||||
) {
|
||||
)
|
||||
{
|
||||
Matrix4x4 result;
|
||||
|
||||
// Delegate to the other overload of the function to do the work
|
||||
|
@ -584,7 +587,8 @@ namespace MoonWorks.Math
|
|||
ref Vector3 cameraUpVector,
|
||||
Vector3? cameraForwardVector,
|
||||
out Matrix4x4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
Vector3 vector;
|
||||
Vector3 vector2;
|
||||
Vector3 vector3;
|
||||
|
@ -642,7 +646,8 @@ namespace MoonWorks.Math
|
|||
Vector3 rotateAxis,
|
||||
Nullable<Vector3> cameraForwardVector,
|
||||
Nullable<Vector3> objectForwardVector
|
||||
) {
|
||||
)
|
||||
{
|
||||
Matrix4x4 result;
|
||||
CreateConstrainedBillboard(
|
||||
ref objectPosition,
|
||||
|
@ -671,7 +676,8 @@ namespace MoonWorks.Math
|
|||
Vector3? cameraForwardVector,
|
||||
Vector3? objectForwardVector,
|
||||
out Matrix4x4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
float num;
|
||||
Vector3 vector;
|
||||
Vector3 vector2;
|
||||
|
@ -777,7 +783,8 @@ namespace MoonWorks.Math
|
|||
ref Vector3 axis,
|
||||
float angle,
|
||||
out Matrix4x4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
float x = axis.X;
|
||||
float y = axis.Y;
|
||||
float z = axis.Z;
|
||||
|
@ -883,7 +890,8 @@ namespace MoonWorks.Math
|
|||
float pitch,
|
||||
float roll,
|
||||
out Matrix4x4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
Quaternion quaternion;
|
||||
Quaternion.CreateFromYawPitchRoll(yaw, pitch, roll, out quaternion);
|
||||
CreateFromQuaternion(ref quaternion, out result);
|
||||
|
@ -900,7 +908,8 @@ namespace MoonWorks.Math
|
|||
Vector3 cameraPosition,
|
||||
Vector3 cameraTarget,
|
||||
Vector3 cameraUpVector
|
||||
) {
|
||||
)
|
||||
{
|
||||
Matrix4x4 matrix;
|
||||
CreateLookAt(ref cameraPosition, ref cameraTarget, ref cameraUpVector, out matrix);
|
||||
return matrix;
|
||||
|
@ -918,7 +927,8 @@ namespace MoonWorks.Math
|
|||
ref Vector3 cameraTarget,
|
||||
ref Vector3 cameraUpVector,
|
||||
out Matrix4x4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
Vector3 vectorA = Vector3.Normalize(cameraPosition - cameraTarget);
|
||||
Vector3 vectorB = Vector3.Normalize(Vector3.Cross(cameraUpVector, vectorA));
|
||||
Vector3 vectorC = Vector3.Cross(vectorA, vectorB);
|
||||
|
@ -953,7 +963,8 @@ namespace MoonWorks.Math
|
|||
float height,
|
||||
float zNearPlane,
|
||||
float zFarPlane
|
||||
) {
|
||||
)
|
||||
{
|
||||
Matrix4x4 matrix;
|
||||
CreateOrthographic(width, height, zNearPlane, zFarPlane, out matrix);
|
||||
return matrix;
|
||||
|
@ -973,7 +984,8 @@ namespace MoonWorks.Math
|
|||
float zNearPlane,
|
||||
float zFarPlane,
|
||||
out Matrix4x4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.M11 = 2f / width;
|
||||
result.M12 = result.M13 = result.M14 = 0f;
|
||||
result.M22 = 2f / height;
|
||||
|
@ -1002,7 +1014,8 @@ namespace MoonWorks.Math
|
|||
float top,
|
||||
float zNearPlane,
|
||||
float zFarPlane
|
||||
) {
|
||||
)
|
||||
{
|
||||
Matrix4x4 matrix;
|
||||
CreateOrthographicOffCenter(
|
||||
left,
|
||||
|
@ -1034,7 +1047,8 @@ namespace MoonWorks.Math
|
|||
float zNearPlane,
|
||||
float zFarPlane,
|
||||
out Matrix4x4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.M11 = (float) (2.0 / ((double) right - (double) left));
|
||||
result.M12 = 0.0f;
|
||||
result.M13 = 0.0f;
|
||||
|
@ -1075,7 +1089,8 @@ namespace MoonWorks.Math
|
|||
float height,
|
||||
float nearPlaneDistance,
|
||||
float farPlaneDistance
|
||||
) {
|
||||
)
|
||||
{
|
||||
Matrix4x4 matrix;
|
||||
CreatePerspective(width, height, nearPlaneDistance, farPlaneDistance, out matrix);
|
||||
return matrix;
|
||||
|
@ -1095,7 +1110,8 @@ namespace MoonWorks.Math
|
|||
float nearPlaneDistance,
|
||||
float farPlaneDistance,
|
||||
out Matrix4x4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
if (nearPlaneDistance <= 0f)
|
||||
{
|
||||
throw new ArgumentException("nearPlaneDistance <= 0");
|
||||
|
@ -1135,7 +1151,8 @@ namespace MoonWorks.Math
|
|||
float aspectRatio,
|
||||
float nearPlaneDistance,
|
||||
float farPlaneDistance
|
||||
) {
|
||||
)
|
||||
{
|
||||
Matrix4x4 result;
|
||||
CreatePerspectiveFieldOfView(
|
||||
fieldOfView,
|
||||
|
@ -1161,7 +1178,8 @@ namespace MoonWorks.Math
|
|||
float nearPlaneDistance,
|
||||
float farPlaneDistance,
|
||||
out Matrix4x4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
if ((fieldOfView <= 0f) || (fieldOfView >= 3.141593f))
|
||||
{
|
||||
throw new ArgumentException("fieldOfView <= 0 or >= PI");
|
||||
|
@ -1210,7 +1228,8 @@ namespace MoonWorks.Math
|
|||
float top,
|
||||
float nearPlaneDistance,
|
||||
float farPlaneDistance
|
||||
) {
|
||||
)
|
||||
{
|
||||
Matrix4x4 result;
|
||||
CreatePerspectiveOffCenter(
|
||||
left,
|
||||
|
@ -1242,7 +1261,8 @@ namespace MoonWorks.Math
|
|||
float nearPlaneDistance,
|
||||
float farPlaneDistance,
|
||||
out Matrix4x4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
if (nearPlaneDistance <= 0f)
|
||||
{
|
||||
throw new ArgumentException("nearPlaneDistance <= 0");
|
||||
|
@ -1408,7 +1428,8 @@ namespace MoonWorks.Math
|
|||
float yScale,
|
||||
float zScale,
|
||||
out Matrix4x4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.M11 = xScale;
|
||||
result.M12 = 0;
|
||||
result.M13 = 0;
|
||||
|
@ -1527,7 +1548,8 @@ namespace MoonWorks.Math
|
|||
float xPosition,
|
||||
float yPosition,
|
||||
float zPosition
|
||||
) {
|
||||
)
|
||||
{
|
||||
Matrix4x4 result;
|
||||
CreateTranslation(xPosition, yPosition, zPosition, out result);
|
||||
return result;
|
||||
|
@ -1582,7 +1604,8 @@ namespace MoonWorks.Math
|
|||
float yPosition,
|
||||
float zPosition,
|
||||
out Matrix4x4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.M11 = 1;
|
||||
result.M12 = 0;
|
||||
result.M13 = 0;
|
||||
|
@ -1672,7 +1695,8 @@ namespace MoonWorks.Math
|
|||
ref Vector3 forward,
|
||||
ref Vector3 up,
|
||||
out Matrix4x4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
Vector3 x, y, z;
|
||||
Vector3.Normalize(ref forward, out z);
|
||||
Vector3.Cross(ref forward, ref up, out x);
|
||||
|
@ -2069,7 +2093,8 @@ namespace MoonWorks.Math
|
|||
ref Matrix4x4 matrix2,
|
||||
float amount,
|
||||
out Matrix4x4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.M11 = matrix1.M11 + ((matrix2.M11 - matrix1.M11) * amount);
|
||||
result.M12 = matrix1.M12 + ((matrix2.M12 - matrix1.M12) * amount);
|
||||
result.M13 = matrix1.M13 + ((matrix2.M13 - matrix1.M13) * amount);
|
||||
|
@ -2097,7 +2122,8 @@ namespace MoonWorks.Math
|
|||
public static Matrix4x4 Multiply(
|
||||
Matrix4x4 matrix1,
|
||||
Matrix4x4 matrix2
|
||||
) {
|
||||
)
|
||||
{
|
||||
float m11 = (
|
||||
(matrix1.M11 * matrix2.M11) +
|
||||
(matrix1.M12 * matrix2.M21) +
|
||||
|
@ -2548,7 +2574,8 @@ namespace MoonWorks.Math
|
|||
ref Matrix4x4 value,
|
||||
ref Quaternion rotation,
|
||||
out Matrix4x4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
Matrix4x4 rotMatrix = CreateFromQuaternion(rotation);
|
||||
Multiply(ref value, ref rotMatrix, out result);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
@ -233,7 +233,8 @@ namespace MoonWorks.Math
|
|||
ref Plane plane,
|
||||
ref Matrix4x4 matrix,
|
||||
out Plane result
|
||||
) {
|
||||
)
|
||||
{
|
||||
/* See "Transforming Normals" in
|
||||
* http://www.glprogramming.com/red/appendixf.html
|
||||
* for an explanation of how this works.
|
||||
|
@ -277,7 +278,8 @@ namespace MoonWorks.Math
|
|||
ref Plane plane,
|
||||
ref Quaternion rotation,
|
||||
out Plane result
|
||||
) {
|
||||
)
|
||||
{
|
||||
Vector3.Transform(
|
||||
ref plane.Normal,
|
||||
ref rotation,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
@ -157,10 +157,10 @@ namespace MoonWorks.Math
|
|||
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
|
||||
public bool Equals(Quaternion other)
|
||||
{
|
||||
return ( X == other.X &&
|
||||
return (X == other.X &&
|
||||
Y == other.Y &&
|
||||
Z == other.Z &&
|
||||
W == other.W );
|
||||
W == other.W);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -266,7 +266,8 @@ namespace MoonWorks.Math
|
|||
ref Quaternion quaternion1,
|
||||
ref Quaternion quaternion2,
|
||||
out Quaternion result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = quaternion1.X + quaternion2.X;
|
||||
result.Y = quaternion1.Y + quaternion2.Y;
|
||||
result.Z = quaternion1.Z + quaternion2.Z;
|
||||
|
@ -296,7 +297,8 @@ namespace MoonWorks.Math
|
|||
ref Quaternion value1,
|
||||
ref Quaternion value2,
|
||||
out Quaternion result
|
||||
) {
|
||||
)
|
||||
{
|
||||
float x1 = value1.X;
|
||||
float y1 = value1.Y;
|
||||
float z1 = value1.Z;
|
||||
|
@ -359,7 +361,8 @@ namespace MoonWorks.Math
|
|||
ref Vector3 axis,
|
||||
float angle,
|
||||
out Quaternion result
|
||||
) {
|
||||
)
|
||||
{
|
||||
float half = angle * 0.5f;
|
||||
float sin = (float) System.Math.Sin((double) half);
|
||||
float cos = (float) System.Math.Cos((double) half);
|
||||
|
@ -415,12 +418,12 @@ namespace MoonWorks.Math
|
|||
else if (matrix.M22 > matrix.M33)
|
||||
{
|
||||
sqrt = (float) System.Math.Sqrt(1.0f + matrix.M22 - matrix.M11 - matrix.M33);
|
||||
half = 0.5f/sqrt;
|
||||
half = 0.5f / sqrt;
|
||||
|
||||
result.X = (matrix.M21 + matrix.M12)*half;
|
||||
result.Y = 0.5f*sqrt;
|
||||
result.Z = (matrix.M32 + matrix.M23)*half;
|
||||
result.W = (matrix.M31 - matrix.M13)*half;
|
||||
result.X = (matrix.M21 + matrix.M12) * half;
|
||||
result.Y = 0.5f * sqrt;
|
||||
result.Z = (matrix.M32 + matrix.M23) * half;
|
||||
result.W = (matrix.M31 - matrix.M13) * half;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -499,7 +502,8 @@ namespace MoonWorks.Math
|
|||
ref Quaternion quaternion1,
|
||||
ref Quaternion quaternion2,
|
||||
out Quaternion result
|
||||
) {
|
||||
)
|
||||
{
|
||||
float x = quaternion1.X;
|
||||
float y = quaternion1.Y;
|
||||
float z = quaternion1.Z;
|
||||
|
@ -551,7 +555,8 @@ namespace MoonWorks.Math
|
|||
ref Quaternion quaternion1,
|
||||
ref Quaternion quaternion2,
|
||||
out float result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result = (
|
||||
(quaternion1.X * quaternion2.X) +
|
||||
(quaternion1.Y * quaternion2.Y) +
|
||||
|
@ -603,7 +608,8 @@ namespace MoonWorks.Math
|
|||
Quaternion quaternion1,
|
||||
Quaternion quaternion2,
|
||||
float amount
|
||||
) {
|
||||
)
|
||||
{
|
||||
Quaternion quaternion;
|
||||
Lerp(ref quaternion1, ref quaternion2, amount, out quaternion);
|
||||
return quaternion;
|
||||
|
@ -621,7 +627,8 @@ namespace MoonWorks.Math
|
|||
ref Quaternion quaternion2,
|
||||
float amount,
|
||||
out Quaternion result
|
||||
) {
|
||||
)
|
||||
{
|
||||
float num = amount;
|
||||
float num2 = 1f - num;
|
||||
float num5 = (
|
||||
|
@ -668,7 +675,8 @@ namespace MoonWorks.Math
|
|||
Quaternion quaternion1,
|
||||
Quaternion quaternion2,
|
||||
float amount
|
||||
) {
|
||||
)
|
||||
{
|
||||
Quaternion quaternion;
|
||||
Slerp(ref quaternion1, ref quaternion2, amount, out quaternion);
|
||||
return quaternion;
|
||||
|
@ -686,7 +694,8 @@ namespace MoonWorks.Math
|
|||
ref Quaternion quaternion2,
|
||||
float amount,
|
||||
out Quaternion result
|
||||
) {
|
||||
)
|
||||
{
|
||||
float num2;
|
||||
float num3;
|
||||
float num = amount;
|
||||
|
@ -743,7 +752,8 @@ namespace MoonWorks.Math
|
|||
ref Quaternion quaternion1,
|
||||
ref Quaternion quaternion2,
|
||||
out Quaternion result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = quaternion1.X - quaternion2.X;
|
||||
result.Y = quaternion1.Y - quaternion2.Y;
|
||||
result.Z = quaternion1.Z - quaternion2.Z;
|
||||
|
@ -786,7 +796,8 @@ namespace MoonWorks.Math
|
|||
ref Quaternion quaternion1,
|
||||
ref Quaternion quaternion2,
|
||||
out Quaternion result
|
||||
) {
|
||||
)
|
||||
{
|
||||
float x = quaternion1.X;
|
||||
float y = quaternion1.Y;
|
||||
float z = quaternion1.Z;
|
||||
|
@ -815,7 +826,8 @@ namespace MoonWorks.Math
|
|||
ref Quaternion quaternion1,
|
||||
float scaleFactor,
|
||||
out Quaternion result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = quaternion1.X * scaleFactor;
|
||||
result.Y = quaternion1.Y * scaleFactor;
|
||||
result.Z = quaternion1.Z * scaleFactor;
|
||||
|
@ -881,15 +893,15 @@ namespace MoonWorks.Math
|
|||
result.W = quaternion.W * num;
|
||||
}
|
||||
|
||||
public static Quaternion LookAt(in Vector3 forward, in Vector3 up)
|
||||
{
|
||||
Matrix4x4 orientation = Matrix4x4.Identity;
|
||||
orientation.Forward = forward;
|
||||
orientation.Right = Vector3.Normalize(Vector3.Cross(forward, up));
|
||||
orientation.Up = Vector3.Cross(orientation.Right, forward);
|
||||
public static Quaternion LookAt(in Vector3 forward, in Vector3 up)
|
||||
{
|
||||
Matrix4x4 orientation = Matrix4x4.Identity;
|
||||
orientation.Forward = forward;
|
||||
orientation.Right = Vector3.Normalize(Vector3.Cross(forward, up));
|
||||
orientation.Up = Vector3.Cross(orientation.Right, forward);
|
||||
|
||||
return Quaternion.CreateFromRotationMatrix(orientation);
|
||||
}
|
||||
return Quaternion.CreateFromRotationMatrix(orientation);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
@ -70,8 +70,8 @@ namespace MoonWorks.Math
|
|||
|
||||
public bool Equals(Ray other)
|
||||
{
|
||||
return ( this.Position.Equals(other.Position) &&
|
||||
this.Direction.Equals(other.Direction) );
|
||||
return (this.Position.Equals(other.Position) &&
|
||||
this.Direction.Equals(other.Direction));
|
||||
}
|
||||
|
||||
|
||||
|
@ -124,8 +124,8 @@ namespace MoonWorks.Math
|
|||
tMaxY = temp;
|
||||
}
|
||||
|
||||
if ( (tMin.HasValue && tMin > tMaxY) ||
|
||||
(tMax.HasValue && tMinY > tMax) )
|
||||
if ((tMin.HasValue && tMin > tMaxY) ||
|
||||
(tMax.HasValue && tMinY > tMax))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -153,8 +153,8 @@ namespace MoonWorks.Math
|
|||
tMaxZ = temp;
|
||||
}
|
||||
|
||||
if ( (tMin.HasValue && tMin > tMaxZ) ||
|
||||
(tMax.HasValue && tMinZ > tMax) )
|
||||
if ((tMin.HasValue && tMin > tMaxZ) ||
|
||||
(tMax.HasValue && tMinZ > tMax))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
@ -117,10 +117,10 @@ namespace MoonWorks.Math
|
|||
{
|
||||
get
|
||||
{
|
||||
return ( (Width == 0) &&
|
||||
return ((Width == 0) &&
|
||||
(Height == 0) &&
|
||||
(X == 0) &&
|
||||
(Y == 0) );
|
||||
(Y == 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,10 +218,10 @@ namespace MoonWorks.Math
|
|||
/// <returns><c>true</c> if the provided coordinates lie inside this <see cref="Rectangle"/>. <c>false</c> otherwise.</returns>
|
||||
public bool Contains(int x, int y)
|
||||
{
|
||||
return ( (this.X <= x) &&
|
||||
return ((this.X <= x) &&
|
||||
(x < (this.X + this.Width)) &&
|
||||
(this.Y <= y) &&
|
||||
(y < (this.Y + this.Height)) );
|
||||
(y < (this.Y + this.Height)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -231,10 +231,10 @@ namespace MoonWorks.Math
|
|||
/// <returns><c>true</c> if the provided <see cref="Point"/> lies inside this <see cref="Rectangle"/>. <c>false</c> otherwise.</returns>
|
||||
public bool Contains(Point value)
|
||||
{
|
||||
return ( (this.X <= value.X) &&
|
||||
return ((this.X <= value.X) &&
|
||||
(value.X < (this.X + this.Width)) &&
|
||||
(this.Y <= value.Y) &&
|
||||
(value.Y < (this.Y + this.Height)) );
|
||||
(value.Y < (this.Y + this.Height)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -244,26 +244,26 @@ namespace MoonWorks.Math
|
|||
/// <returns><c>true</c> if the provided <see cref="Rectangle"/>'s bounds lie entirely inside this <see cref="Rectangle"/>. <c>false</c> otherwise.</returns>
|
||||
public bool Contains(Rectangle value)
|
||||
{
|
||||
return ( (this.X <= value.X) &&
|
||||
return ((this.X <= value.X) &&
|
||||
((value.X + value.Width) <= (this.X + this.Width)) &&
|
||||
(this.Y <= value.Y) &&
|
||||
((value.Y + value.Height) <= (this.Y + this.Height)) );
|
||||
((value.Y + value.Height) <= (this.Y + this.Height)));
|
||||
}
|
||||
|
||||
public void Contains(ref Point value, out bool result)
|
||||
{
|
||||
result = ( (this.X <= value.X) &&
|
||||
result = ((this.X <= value.X) &&
|
||||
(value.X < (this.X + this.Width)) &&
|
||||
(this.Y <= value.Y) &&
|
||||
(value.Y < (this.Y + this.Height)) );
|
||||
(value.Y < (this.Y + this.Height)));
|
||||
}
|
||||
|
||||
public void Contains(ref Rectangle value, out bool result)
|
||||
{
|
||||
result = ( (this.X <= value.X) &&
|
||||
result = ((this.X <= value.X) &&
|
||||
((value.X + value.Width) <= (this.X + this.Width)) &&
|
||||
(this.Y <= value.Y) &&
|
||||
((value.Y + value.Height) <= (this.Y + this.Height)) );
|
||||
((value.Y + value.Height) <= (this.Y + this.Height)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -349,10 +349,10 @@ namespace MoonWorks.Math
|
|||
/// <returns><c>true</c> if other <see cref="Rectangle"/> intersects with this rectangle; <c>false</c> otherwise.</returns>
|
||||
public bool Intersects(Rectangle value)
|
||||
{
|
||||
return ( value.Left < Right &&
|
||||
return (value.Left < Right &&
|
||||
Left < value.Right &&
|
||||
value.Top < Bottom &&
|
||||
Top < value.Bottom );
|
||||
Top < value.Bottom);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -362,10 +362,10 @@ namespace MoonWorks.Math
|
|||
/// <param name="result"><c>true</c> if other <see cref="Rectangle"/> intersects with this rectangle; <c>false</c> otherwise. As an output parameter.</param>
|
||||
public void Intersects(ref Rectangle value, out bool result)
|
||||
{
|
||||
result = ( value.Left < Right &&
|
||||
result = (value.Left < Right &&
|
||||
Left < value.Right &&
|
||||
value.Top < Bottom &&
|
||||
Top < value.Bottom );
|
||||
Top < value.Bottom);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -374,10 +374,10 @@ namespace MoonWorks.Math
|
|||
|
||||
public static bool operator ==(Rectangle a, Rectangle b)
|
||||
{
|
||||
return ( (a.X == b.X) &&
|
||||
return ((a.X == b.X) &&
|
||||
(a.Y == b.Y) &&
|
||||
(a.Width == b.Width) &&
|
||||
(a.Height == b.Height) );
|
||||
(a.Height == b.Height));
|
||||
}
|
||||
|
||||
public static bool operator !=(Rectangle a, Rectangle b)
|
||||
|
@ -396,7 +396,8 @@ namespace MoonWorks.Math
|
|||
ref Rectangle value1,
|
||||
ref Rectangle value2,
|
||||
out Rectangle result
|
||||
) {
|
||||
)
|
||||
{
|
||||
if (value1.Intersects(value2))
|
||||
{
|
||||
int right_side = System.Math.Min(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
@ -163,8 +163,8 @@ namespace MoonWorks.Math
|
|||
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
|
||||
public bool Equals(Vector2 other)
|
||||
{
|
||||
return ( X == other.X &&
|
||||
Y == other.Y );
|
||||
return (X == other.X &&
|
||||
Y == other.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -264,7 +264,8 @@ namespace MoonWorks.Math
|
|||
Vector2 value3,
|
||||
float amount1,
|
||||
float amount2
|
||||
) {
|
||||
)
|
||||
{
|
||||
return new Vector2(
|
||||
MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2),
|
||||
MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2)
|
||||
|
@ -287,7 +288,8 @@ namespace MoonWorks.Math
|
|||
float amount1,
|
||||
float amount2,
|
||||
out Vector2 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2);
|
||||
result.Y = MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2);
|
||||
}
|
||||
|
@ -307,7 +309,8 @@ namespace MoonWorks.Math
|
|||
Vector2 value3,
|
||||
Vector2 value4,
|
||||
float amount
|
||||
) {
|
||||
)
|
||||
{
|
||||
return new Vector2(
|
||||
MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount),
|
||||
MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount)
|
||||
|
@ -330,7 +333,8 @@ namespace MoonWorks.Math
|
|||
ref Vector2 value4,
|
||||
float amount,
|
||||
out Vector2 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount);
|
||||
result.Y = MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount);
|
||||
}
|
||||
|
@ -362,7 +366,8 @@ namespace MoonWorks.Math
|
|||
ref Vector2 min,
|
||||
ref Vector2 max,
|
||||
out Vector2 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = MathHelper.Clamp(value1.X, min.X, max.X);
|
||||
result.Y = MathHelper.Clamp(value1.Y, min.Y, max.Y);
|
||||
}
|
||||
|
@ -413,7 +418,8 @@ namespace MoonWorks.Math
|
|||
ref Vector2 value1,
|
||||
ref Vector2 value2,
|
||||
out float result
|
||||
) {
|
||||
)
|
||||
{
|
||||
float v1 = value1.X - value2.X, v2 = value1.Y - value2.Y;
|
||||
result = (v1 * v1) + (v2 * v2);
|
||||
}
|
||||
|
@ -507,7 +513,8 @@ namespace MoonWorks.Math
|
|||
Vector2 value2,
|
||||
Vector2 tangent2,
|
||||
float amount
|
||||
) {
|
||||
)
|
||||
{
|
||||
Vector2 result = new Vector2();
|
||||
Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result);
|
||||
return result;
|
||||
|
@ -529,7 +536,8 @@ namespace MoonWorks.Math
|
|||
ref Vector2 tangent2,
|
||||
float amount,
|
||||
out Vector2 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount);
|
||||
result.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount);
|
||||
}
|
||||
|
@ -561,7 +569,8 @@ namespace MoonWorks.Math
|
|||
ref Vector2 value2,
|
||||
float amount,
|
||||
out Vector2 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = MathHelper.Lerp(value1.X, value2.X, amount);
|
||||
result.Y = MathHelper.Lerp(value1.Y, value2.Y, amount);
|
||||
}
|
||||
|
@ -773,7 +782,8 @@ namespace MoonWorks.Math
|
|||
ref Vector2 value2,
|
||||
float amount,
|
||||
out Vector2 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = MathHelper.SmoothStep(value1.X, value2.X, amount);
|
||||
result.Y = MathHelper.SmoothStep(value1.Y, value2.Y, amount);
|
||||
}
|
||||
|
@ -827,7 +837,8 @@ namespace MoonWorks.Math
|
|||
ref Vector2 position,
|
||||
ref Matrix4x4 matrix,
|
||||
out Vector2 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
float x = (position.X * matrix.M11) + (position.Y * matrix.M21) + matrix.M41;
|
||||
float y = (position.X * matrix.M12) + (position.Y * matrix.M22) + matrix.M42;
|
||||
result.X = x;
|
||||
|
@ -856,7 +867,8 @@ namespace MoonWorks.Math
|
|||
ref Vector2 value,
|
||||
ref Quaternion rotation,
|
||||
out Vector2 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
float x = 2 * -(rotation.Z * value.Y);
|
||||
float y = 2 * (rotation.Z * value.X);
|
||||
float z = 2 * (rotation.X * value.Y - rotation.Y * value.X);
|
||||
|
@ -875,7 +887,8 @@ namespace MoonWorks.Math
|
|||
Vector2[] sourceArray,
|
||||
ref Matrix4x4 matrix,
|
||||
Vector2[] destinationArray
|
||||
) {
|
||||
)
|
||||
{
|
||||
Transform(sourceArray, 0, ref matrix, destinationArray, 0, sourceArray.Length);
|
||||
}
|
||||
|
||||
|
@ -895,7 +908,8 @@ namespace MoonWorks.Math
|
|||
Vector2[] destinationArray,
|
||||
int destinationIndex,
|
||||
int length
|
||||
) {
|
||||
)
|
||||
{
|
||||
for (int x = 0; x < length; x += 1)
|
||||
{
|
||||
Vector2 position = sourceArray[sourceIndex + x];
|
||||
|
@ -918,7 +932,8 @@ namespace MoonWorks.Math
|
|||
Vector2[] sourceArray,
|
||||
ref Quaternion rotation,
|
||||
Vector2[] destinationArray
|
||||
) {
|
||||
)
|
||||
{
|
||||
Transform(
|
||||
sourceArray,
|
||||
0,
|
||||
|
@ -945,7 +960,8 @@ namespace MoonWorks.Math
|
|||
Vector2[] destinationArray,
|
||||
int destinationIndex,
|
||||
int length
|
||||
) {
|
||||
)
|
||||
{
|
||||
for (int i = 0; i < length; i += 1)
|
||||
{
|
||||
Vector2 position = sourceArray[sourceIndex + i];
|
||||
|
@ -979,7 +995,8 @@ namespace MoonWorks.Math
|
|||
ref Vector2 normal,
|
||||
ref Matrix4x4 matrix,
|
||||
out Vector2 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
float x = (normal.X * matrix.M11) + (normal.Y * matrix.M21);
|
||||
float y = (normal.X * matrix.M12) + (normal.Y * matrix.M22);
|
||||
result.X = x;
|
||||
|
@ -996,7 +1013,8 @@ namespace MoonWorks.Math
|
|||
Vector2[] sourceArray,
|
||||
ref Matrix4x4 matrix,
|
||||
Vector2[] destinationArray
|
||||
) {
|
||||
)
|
||||
{
|
||||
TransformNormal(
|
||||
sourceArray,
|
||||
0,
|
||||
|
@ -1023,7 +1041,8 @@ namespace MoonWorks.Math
|
|||
Vector2[] destinationArray,
|
||||
int destinationIndex,
|
||||
int length
|
||||
) {
|
||||
)
|
||||
{
|
||||
for (int i = 0; i < length; i += 1)
|
||||
{
|
||||
Vector2 position = sourceArray[sourceIndex + i];
|
||||
|
@ -1058,8 +1077,8 @@ namespace MoonWorks.Math
|
|||
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
|
||||
public static bool operator ==(Vector2 value1, Vector2 value2)
|
||||
{
|
||||
return ( value1.X == value2.X &&
|
||||
value1.Y == value2.Y );
|
||||
return (value1.X == value2.X &&
|
||||
value1.Y == value2.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
@ -270,9 +270,9 @@ namespace MoonWorks.Math
|
|||
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
|
||||
public bool Equals(Vector3 other)
|
||||
{
|
||||
return ( X == other.X &&
|
||||
return (X == other.X &&
|
||||
Y == other.Y &&
|
||||
Z == other.Z );
|
||||
Z == other.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -383,7 +383,8 @@ namespace MoonWorks.Math
|
|||
Vector3 value3,
|
||||
float amount1,
|
||||
float amount2
|
||||
) {
|
||||
)
|
||||
{
|
||||
return new Vector3(
|
||||
MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2),
|
||||
MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2),
|
||||
|
@ -407,7 +408,8 @@ namespace MoonWorks.Math
|
|||
float amount1,
|
||||
float amount2,
|
||||
out Vector3 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2);
|
||||
result.Y = MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2);
|
||||
result.Z = MathHelper.Barycentric(value1.Z, value2.Z, value3.Z, amount1, amount2);
|
||||
|
@ -428,7 +430,8 @@ namespace MoonWorks.Math
|
|||
Vector3 value3,
|
||||
Vector3 value4,
|
||||
float amount
|
||||
) {
|
||||
)
|
||||
{
|
||||
return new Vector3(
|
||||
MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount),
|
||||
MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount),
|
||||
|
@ -452,7 +455,8 @@ namespace MoonWorks.Math
|
|||
ref Vector3 value4,
|
||||
float amount,
|
||||
out Vector3 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount);
|
||||
result.Y = MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount);
|
||||
result.Z = MathHelper.CatmullRom(value1.Z, value2.Z, value3.Z, value4.Z, amount);
|
||||
|
@ -486,24 +490,26 @@ namespace MoonWorks.Math
|
|||
ref Vector3 min,
|
||||
ref Vector3 max,
|
||||
out Vector3 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = MathHelper.Clamp(value1.X, min.X, max.X);
|
||||
result.Y = MathHelper.Clamp(value1.Y, min.Y, max.Y);
|
||||
result.Z = MathHelper.Clamp(value1.Z, min.Z, max.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clamps the magnitude of the specified vector.
|
||||
/// </summary>
|
||||
/// <param name="value">The vector to clamp.</param>
|
||||
/// <param name="maxLength">The maximum length of the vector.</param>
|
||||
/// <returns></returns>
|
||||
/// Clamps the magnitude of the specified vector.
|
||||
/// </summary>
|
||||
/// <param name="value">The vector to clamp.</param>
|
||||
/// <param name="maxLength">The maximum length of the vector.</param>
|
||||
/// <returns></returns>
|
||||
public static Vector3 ClampMagnitude(
|
||||
Vector3 value,
|
||||
float maxLength
|
||||
) {
|
||||
return (value.LengthSquared() > maxLength * maxLength) ? (Vector3.Normalize(value) * maxLength) : value;
|
||||
}
|
||||
)
|
||||
{
|
||||
return (value.LengthSquared() > maxLength * maxLength) ? (Vector3.Normalize(value) * maxLength) : value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the cross product of two vectors.
|
||||
|
@ -583,7 +589,8 @@ namespace MoonWorks.Math
|
|||
ref Vector3 value1,
|
||||
ref Vector3 value2,
|
||||
out float result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result = (
|
||||
(value1.X - value2.X) * (value1.X - value2.X) +
|
||||
(value1.Y - value2.Y) * (value1.Y - value2.Y) +
|
||||
|
@ -688,7 +695,8 @@ namespace MoonWorks.Math
|
|||
Vector3 value2,
|
||||
Vector3 tangent2,
|
||||
float amount
|
||||
) {
|
||||
)
|
||||
{
|
||||
Vector3 result = new Vector3();
|
||||
Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result);
|
||||
return result;
|
||||
|
@ -710,7 +718,8 @@ namespace MoonWorks.Math
|
|||
ref Vector3 tangent2,
|
||||
float amount,
|
||||
out Vector3 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount);
|
||||
result.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount);
|
||||
result.Z = MathHelper.Hermite(value1.Z, tangent1.Z, value2.Z, tangent2.Z, amount);
|
||||
|
@ -744,7 +753,8 @@ namespace MoonWorks.Math
|
|||
ref Vector3 value2,
|
||||
float amount,
|
||||
out Vector3 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = MathHelper.Lerp(value1.X, value2.X, amount);
|
||||
result.Y = MathHelper.Lerp(value1.Y, value2.Y, amount);
|
||||
result.Z = MathHelper.Lerp(value1.Z, value2.Z, amount);
|
||||
|
@ -992,7 +1002,8 @@ namespace MoonWorks.Math
|
|||
ref Vector3 value2,
|
||||
float amount,
|
||||
out Vector3 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = MathHelper.SmoothStep(value1.X, value2.X, amount);
|
||||
result.Y = MathHelper.SmoothStep(value1.Y, value2.Y, amount);
|
||||
result.Z = MathHelper.SmoothStep(value1.Z, value2.Z, amount);
|
||||
|
@ -1047,7 +1058,8 @@ namespace MoonWorks.Math
|
|||
ref Vector3 position,
|
||||
ref Matrix4x4 matrix,
|
||||
out Vector3 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
float x = (
|
||||
(position.X * matrix.M11) +
|
||||
(position.Y * matrix.M21) +
|
||||
|
@ -1081,7 +1093,8 @@ namespace MoonWorks.Math
|
|||
Vector3[] sourceArray,
|
||||
ref Matrix4x4 matrix,
|
||||
Vector3[] destinationArray
|
||||
) {
|
||||
)
|
||||
{
|
||||
Debug.Assert(
|
||||
destinationArray.Length >= sourceArray.Length,
|
||||
"The destination array is smaller than the source array."
|
||||
|
@ -1121,7 +1134,8 @@ namespace MoonWorks.Math
|
|||
Vector3[] destinationArray,
|
||||
int destinationIndex,
|
||||
int length
|
||||
) {
|
||||
)
|
||||
{
|
||||
Debug.Assert(
|
||||
sourceArray.Length - sourceIndex >= length,
|
||||
"The source array is too small for the given sourceIndex and length."
|
||||
|
@ -1173,7 +1187,8 @@ namespace MoonWorks.Math
|
|||
ref Vector3 value,
|
||||
ref Quaternion rotation,
|
||||
out Vector3 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
float x = 2 * (rotation.Y * value.Z - rotation.Z * value.Y);
|
||||
float y = 2 * (rotation.Z * value.X - rotation.X * value.Z);
|
||||
float z = 2 * (rotation.X * value.Y - rotation.Y * value.X);
|
||||
|
@ -1193,7 +1208,8 @@ namespace MoonWorks.Math
|
|||
Vector3[] sourceArray,
|
||||
ref Quaternion rotation,
|
||||
Vector3[] destinationArray
|
||||
) {
|
||||
)
|
||||
{
|
||||
Debug.Assert(
|
||||
destinationArray.Length >= sourceArray.Length,
|
||||
"The destination array is smaller than the source array."
|
||||
|
@ -1236,7 +1252,8 @@ namespace MoonWorks.Math
|
|||
Vector3[] destinationArray,
|
||||
int destinationIndex,
|
||||
int length
|
||||
) {
|
||||
)
|
||||
{
|
||||
Debug.Assert(
|
||||
sourceArray.Length - sourceIndex >= length,
|
||||
"The source array is too small for the given sourceIndex and length."
|
||||
|
@ -1289,7 +1306,8 @@ namespace MoonWorks.Math
|
|||
ref Vector3 normal,
|
||||
ref Matrix4x4 matrix,
|
||||
out Vector3 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
float x = (normal.X * matrix.M11) + (normal.Y * matrix.M21) + (normal.Z * matrix.M31);
|
||||
float y = (normal.X * matrix.M12) + (normal.Y * matrix.M22) + (normal.Z * matrix.M32);
|
||||
float z = (normal.X * matrix.M13) + (normal.Y * matrix.M23) + (normal.Z * matrix.M33);
|
||||
|
@ -1308,7 +1326,8 @@ namespace MoonWorks.Math
|
|||
Vector3[] sourceArray,
|
||||
ref Matrix4x4 matrix,
|
||||
Vector3[] destinationArray
|
||||
) {
|
||||
)
|
||||
{
|
||||
Debug.Assert(
|
||||
destinationArray.Length >= sourceArray.Length,
|
||||
"The destination array is smaller than the source array."
|
||||
|
@ -1339,7 +1358,8 @@ namespace MoonWorks.Math
|
|||
Vector3[] destinationArray,
|
||||
int destinationIndex,
|
||||
int length
|
||||
) {
|
||||
)
|
||||
{
|
||||
if (sourceArray == null)
|
||||
{
|
||||
throw new ArgumentNullException("sourceArray");
|
||||
|
@ -1396,9 +1416,9 @@ namespace MoonWorks.Math
|
|||
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
|
||||
public static bool operator ==(Vector3 value1, Vector3 value2)
|
||||
{
|
||||
return ( value1.X == value2.X &&
|
||||
return (value1.X == value2.X &&
|
||||
value1.Y == value2.Y &&
|
||||
value1.Z == value2.Z );
|
||||
value1.Z == value2.Z);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
@ -234,10 +234,10 @@ namespace MoonWorks.Math
|
|||
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
|
||||
public bool Equals(Vector4 other)
|
||||
{
|
||||
return ( X == other.X &&
|
||||
return (X == other.X &&
|
||||
Y == other.Y &&
|
||||
Z == other.Z &&
|
||||
W == other.W );
|
||||
W == other.W);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -344,7 +344,8 @@ namespace MoonWorks.Math
|
|||
Vector4 value3,
|
||||
float amount1,
|
||||
float amount2
|
||||
) {
|
||||
)
|
||||
{
|
||||
return new Vector4(
|
||||
MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2),
|
||||
MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2),
|
||||
|
@ -369,7 +370,8 @@ namespace MoonWorks.Math
|
|||
float amount1,
|
||||
float amount2,
|
||||
out Vector4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2);
|
||||
result.Y = MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2);
|
||||
result.Z = MathHelper.Barycentric(value1.Z, value2.Z, value3.Z, amount1, amount2);
|
||||
|
@ -391,7 +393,8 @@ namespace MoonWorks.Math
|
|||
Vector4 value3,
|
||||
Vector4 value4,
|
||||
float amount
|
||||
) {
|
||||
)
|
||||
{
|
||||
return new Vector4(
|
||||
MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount),
|
||||
MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount),
|
||||
|
@ -416,7 +419,8 @@ namespace MoonWorks.Math
|
|||
ref Vector4 value4,
|
||||
float amount,
|
||||
out Vector4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount);
|
||||
result.Y = MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount);
|
||||
result.Z = MathHelper.CatmullRom(value1.Z, value2.Z, value3.Z, value4.Z, amount);
|
||||
|
@ -452,7 +456,8 @@ namespace MoonWorks.Math
|
|||
ref Vector4 min,
|
||||
ref Vector4 max,
|
||||
out Vector4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = MathHelper.Clamp(value1.X, min.X, max.X);
|
||||
result.Y = MathHelper.Clamp(value1.Y, min.Y, max.Y);
|
||||
result.Z = MathHelper.Clamp(value1.Z, min.Z, max.Z);
|
||||
|
@ -507,7 +512,8 @@ namespace MoonWorks.Math
|
|||
ref Vector4 value1,
|
||||
ref Vector4 value2,
|
||||
out float result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result = (
|
||||
(value1.W - value2.W) * (value1.W - value2.W) +
|
||||
(value1.X - value2.X) * (value1.X - value2.X) +
|
||||
|
@ -572,7 +578,8 @@ namespace MoonWorks.Math
|
|||
ref Vector4 value1,
|
||||
ref Vector4 value2,
|
||||
out Vector4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.W = value1.W / value2.W;
|
||||
result.X = value1.X / value2.X;
|
||||
result.Y = value1.Y / value2.Y;
|
||||
|
@ -626,7 +633,8 @@ namespace MoonWorks.Math
|
|||
Vector4 value2,
|
||||
Vector4 tangent2,
|
||||
float amount
|
||||
) {
|
||||
)
|
||||
{
|
||||
return new Vector4(
|
||||
MathHelper.Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount),
|
||||
MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount),
|
||||
|
@ -651,7 +659,8 @@ namespace MoonWorks.Math
|
|||
ref Vector4 tangent2,
|
||||
float amount,
|
||||
out Vector4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.W = MathHelper.Hermite(value1.W, tangent1.W, value2.W, tangent2.W, amount);
|
||||
result.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount);
|
||||
result.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount);
|
||||
|
@ -687,7 +696,8 @@ namespace MoonWorks.Math
|
|||
ref Vector4 value2,
|
||||
float amount,
|
||||
out Vector4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = MathHelper.Lerp(value1.X, value2.X, amount);
|
||||
result.Y = MathHelper.Lerp(value1.Y, value2.Y, amount);
|
||||
result.Z = MathHelper.Lerp(value1.Z, value2.Z, amount);
|
||||
|
@ -905,7 +915,8 @@ namespace MoonWorks.Math
|
|||
ref Vector4 value2,
|
||||
float amount,
|
||||
out Vector4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
result.X = MathHelper.SmoothStep(value1.X, value2.X, amount);
|
||||
result.Y = MathHelper.SmoothStep(value1.Y, value2.Y, amount);
|
||||
result.Z = MathHelper.SmoothStep(value1.Z, value2.Z, amount);
|
||||
|
@ -1081,7 +1092,8 @@ namespace MoonWorks.Math
|
|||
Vector4[] sourceArray,
|
||||
ref Matrix4x4 matrix,
|
||||
Vector4[] destinationArray
|
||||
) {
|
||||
)
|
||||
{
|
||||
if (sourceArray == null)
|
||||
{
|
||||
throw new ArgumentNullException("sourceArray");
|
||||
|
@ -1122,7 +1134,8 @@ namespace MoonWorks.Math
|
|||
Vector4[] destinationArray,
|
||||
int destinationIndex,
|
||||
int length
|
||||
) {
|
||||
)
|
||||
{
|
||||
if (sourceArray == null)
|
||||
{
|
||||
throw new ArgumentNullException("sourceArray");
|
||||
|
@ -1202,7 +1215,8 @@ namespace MoonWorks.Math
|
|||
ref Vector2 value,
|
||||
ref Quaternion rotation,
|
||||
out Vector4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
double xx = rotation.X + rotation.X;
|
||||
double yy = rotation.Y + rotation.Y;
|
||||
double zz = rotation.Z + rotation.Z;
|
||||
|
@ -1240,7 +1254,8 @@ namespace MoonWorks.Math
|
|||
ref Vector3 value,
|
||||
ref Quaternion rotation,
|
||||
out Vector4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
double xx = rotation.X + rotation.X;
|
||||
double yy = rotation.Y + rotation.Y;
|
||||
double zz = rotation.Z + rotation.Z;
|
||||
|
@ -1281,7 +1296,8 @@ namespace MoonWorks.Math
|
|||
ref Vector4 value,
|
||||
ref Quaternion rotation,
|
||||
out Vector4 result
|
||||
) {
|
||||
)
|
||||
{
|
||||
double xx = rotation.X + rotation.X;
|
||||
double yy = rotation.Y + rotation.Y;
|
||||
double zz = rotation.Z + rotation.Z;
|
||||
|
@ -1322,7 +1338,8 @@ namespace MoonWorks.Math
|
|||
Vector4[] sourceArray,
|
||||
ref Quaternion rotation,
|
||||
Vector4[] destinationArray
|
||||
) {
|
||||
)
|
||||
{
|
||||
if (sourceArray == null)
|
||||
{
|
||||
throw new ArgumentException("sourceArray");
|
||||
|
@ -1363,7 +1380,8 @@ namespace MoonWorks.Math
|
|||
Vector4[] destinationArray,
|
||||
int destinationIndex,
|
||||
int length
|
||||
) {
|
||||
)
|
||||
{
|
||||
if (sourceArray == null)
|
||||
{
|
||||
throw new ArgumentException("sourceArray");
|
||||
|
@ -1405,10 +1423,10 @@ namespace MoonWorks.Math
|
|||
|
||||
public static bool operator ==(Vector4 value1, Vector4 value2)
|
||||
{
|
||||
return ( value1.X == value2.X &&
|
||||
return (value1.X == value2.X &&
|
||||
value1.Y == value2.Y &&
|
||||
value1.Z == value2.Z &&
|
||||
value1.W == value2.W );
|
||||
value1.W == value2.W);
|
||||
}
|
||||
|
||||
public static bool operator !=(Vector4 value1, Vector4 value2)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#region License
|
||||
#region License
|
||||
|
||||
/* MoonWorks - Game Development Framework
|
||||
* Copyright 2021 Evan Hemsley
|
||||
|
@ -42,7 +42,7 @@ namespace MoonWorks
|
|||
}
|
||||
else if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
return "osx";
|
||||
return "osx";
|
||||
}
|
||||
else if (OperatingSystem.IsLinux())
|
||||
{
|
||||
|
@ -67,7 +67,8 @@ namespace MoonWorks
|
|||
string libraryName,
|
||||
Assembly assembly,
|
||||
DllImportSearchPath? dllImportSearchPath
|
||||
) {
|
||||
)
|
||||
{
|
||||
string mappedName;
|
||||
if (!mapDictionary.TryGetValue(libraryName, out mappedName))
|
||||
{
|
||||
|
|
|
@ -1,66 +1,66 @@
|
|||
using System;
|
||||
using System;
|
||||
using SDL2;
|
||||
|
||||
namespace MoonWorks.Window
|
||||
{
|
||||
public class OSWindow : IDisposable
|
||||
{
|
||||
public class OSWindow : IDisposable
|
||||
{
|
||||
internal IntPtr Handle { get; }
|
||||
public ScreenMode ScreenMode { get; }
|
||||
public ScreenMode ScreenMode { get; }
|
||||
|
||||
private bool IsDisposed;
|
||||
|
||||
public OSWindow(WindowCreateInfo windowCreateInfo)
|
||||
{
|
||||
var windowFlags = SDL.SDL_WindowFlags.SDL_WINDOW_VULKAN;
|
||||
public OSWindow(WindowCreateInfo windowCreateInfo)
|
||||
{
|
||||
var windowFlags = SDL.SDL_WindowFlags.SDL_WINDOW_VULKAN;
|
||||
|
||||
if (windowCreateInfo.ScreenMode == ScreenMode.Fullscreen)
|
||||
{
|
||||
windowFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
|
||||
}
|
||||
else if (windowCreateInfo.ScreenMode == ScreenMode.BorderlessWindow)
|
||||
{
|
||||
windowFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
}
|
||||
if (windowCreateInfo.ScreenMode == ScreenMode.Fullscreen)
|
||||
{
|
||||
windowFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
|
||||
}
|
||||
else if (windowCreateInfo.ScreenMode == ScreenMode.BorderlessWindow)
|
||||
{
|
||||
windowFlags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
}
|
||||
|
||||
ScreenMode = windowCreateInfo.ScreenMode;
|
||||
ScreenMode = windowCreateInfo.ScreenMode;
|
||||
|
||||
Handle = SDL.SDL_CreateWindow(
|
||||
windowCreateInfo.WindowTitle,
|
||||
SDL.SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL.SDL_WINDOWPOS_UNDEFINED,
|
||||
(int)windowCreateInfo.WindowWidth,
|
||||
(int)windowCreateInfo.WindowHeight,
|
||||
windowFlags
|
||||
);
|
||||
}
|
||||
Handle = SDL.SDL_CreateWindow(
|
||||
windowCreateInfo.WindowTitle,
|
||||
SDL.SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL.SDL_WINDOWPOS_UNDEFINED,
|
||||
(int) windowCreateInfo.WindowWidth,
|
||||
(int) windowCreateInfo.WindowHeight,
|
||||
windowFlags
|
||||
);
|
||||
}
|
||||
|
||||
public void ChangeScreenMode(ScreenMode screenMode)
|
||||
{
|
||||
SDL.SDL_WindowFlags windowFlag = 0;
|
||||
public void ChangeScreenMode(ScreenMode screenMode)
|
||||
{
|
||||
SDL.SDL_WindowFlags windowFlag = 0;
|
||||
|
||||
if (screenMode == ScreenMode.Fullscreen)
|
||||
{
|
||||
windowFlag = SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
|
||||
}
|
||||
else if (screenMode == ScreenMode.BorderlessWindow)
|
||||
{
|
||||
windowFlag = SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
}
|
||||
if (screenMode == ScreenMode.Fullscreen)
|
||||
{
|
||||
windowFlag = SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
|
||||
}
|
||||
else if (screenMode == ScreenMode.BorderlessWindow)
|
||||
{
|
||||
windowFlag = SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||
}
|
||||
|
||||
SDL.SDL_SetWindowFullscreen(Handle, (uint) windowFlag);
|
||||
}
|
||||
SDL.SDL_SetWindowFullscreen(Handle, (uint) windowFlag);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes the window.
|
||||
/// 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>
|
||||
/// <param name="height"></param>
|
||||
public void SetWindowSize(uint width, uint height)
|
||||
{
|
||||
SDL.SDL_SetWindowSize(Handle, (int)width, (int)height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Resizes the window.
|
||||
/// 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>
|
||||
/// <param name="height"></param>
|
||||
public void SetWindowSize(uint width, uint height)
|
||||
{
|
||||
SDL.SDL_SetWindowSize(Handle, (int) width, (int) height);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
|
@ -79,8 +79,8 @@ namespace MoonWorks.Window
|
|||
|
||||
~OSWindow()
|
||||
{
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: false);
|
||||
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
namespace MoonWorks.Window
|
||||
namespace MoonWorks.Window
|
||||
{
|
||||
public enum ScreenMode
|
||||
{
|
||||
Fullscreen,
|
||||
BorderlessWindow,
|
||||
Windowed
|
||||
}
|
||||
public enum ScreenMode
|
||||
{
|
||||
Fullscreen,
|
||||
BorderlessWindow,
|
||||
Windowed
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
namespace MoonWorks.Window
|
||||
namespace MoonWorks.Window
|
||||
{
|
||||
public struct WindowCreateInfo
|
||||
{
|
||||
public string WindowTitle;
|
||||
public uint WindowWidth;
|
||||
public uint WindowHeight;
|
||||
public ScreenMode ScreenMode;
|
||||
}
|
||||
public struct WindowCreateInfo
|
||||
{
|
||||
public string WindowTitle;
|
||||
public uint WindowWidth;
|
||||
public uint WindowHeight;
|
||||
public ScreenMode ScreenMode;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue